Move towards selection section inventory management

This commit is contained in:
2023-02-14 23:25:09 +00:00
parent 9dd4c53316
commit ff5fa6321a
6 changed files with 252 additions and 66 deletions
+37 -18
View File
@@ -4,6 +4,7 @@ module Dodge.DisplayInventory
, defaultDisplaySections
) where
import Regex
import Data.Maybe
import Picture.Base
import Dodge.Render.HUD
@@ -66,11 +67,27 @@ updateSections allavailablelines (i,j) ((k,(x,y)):xs) = IM.insert k ss
| otherwise = updateSection Nothing y availablelines x
availablelines = allavailablelines - sum (map (_ssMinSize . fst . snd) xs)
defaultSS :: SelectionSection ()
defaultSS = SelectionSection
{ _ssItems = mempty
, _ssCursor = Nothing
, _ssRegex = EmptyRegex
, _ssMinSize = 5
, _ssOffset = 0
, _ssShownItems = []
, _ssIndent = 0
, _ssDescriptor = ""
}
defaultCOSection :: SelectionSection ()
defaultCOSection = SelectionSection mempty Nothing 5 0 [] 2 "CLOSE OBJECTS"
defaultCOSection = defaultSS
& ssIndent .~ 2
& ssDescriptor .~ "CLOSE OBJECTS"
defaultInvSection :: SelectionSection ()
defaultInvSection = SelectionSection mempty Nothing 5 0 [] 0 "INVENTORY ITEMS"
defaultInvSection = defaultSS
& ssDescriptor .~ "INVENTORY ITEMS"
updateSection
:: Maybe Int
@@ -78,16 +95,24 @@ updateSection
-> Int
-> SelectionSection a
-> SelectionSection a
updateSection mspos sis availablelines ss = ss
updateSection mspos sis' availablelines ss = ss
{ _ssItems = sis
, _ssCursor = scurs
, _ssOffset = offset
-- , _ssRegex = ""
-- , _ssRegexInput = False
, _ssMinSize = 5
, _ssShownItems = shownitems
}
where
sis = case _ssRegex ss of
Regex str -> IM.insert (-1) (f str) $ IM.filter (regexList str . _siPictures) sis'
_ -> sis'
f str = SelectionRegex
{ _siPictures = ["FILTER: " ++ str]
, _siHeight = 1
, _siIsSelectable = True
, _siColor = white
, _siOffX = 0
}
oldoffset = ss ^. ssOffset
scurs = do
csel <- mspos
@@ -95,7 +120,7 @@ updateSection mspos sis availablelines ss = ss
let cpos = sum (fmap (length . _siPictures) . fst . IM.split csel $ sis)
csize = length $ _siPictures si
ccolor = _siColor si
return $ SectionCursor (cpos - offset) csize ccolor
return $ SectionCursor csel (cpos - offset) csize ccolor
mcpos = do
csel <- mspos
return . sum $ fmap (length . _siPictures) . fst . IM.split csel $ sis
@@ -136,15 +161,9 @@ updateSection mspos sis availablelines ss = ss
return . length $ _siPictures si
yousec :: SelectionSection ()
yousec = SelectionSection
{ _ssItems = mempty
, _ssCursor = Just $ SectionCursor 0 1 invDimColor
, _ssOffset = 0
, _ssIndent = 2
-- , _ssRegex = ""
-- , _ssRegexInput = False
, _ssMinSize = 1
-- , _ssOffset = 0
, _ssShownItems = mempty
, _ssDescriptor = "YOUR STATUS"
}
yousec = defaultSS
& ssCursor ?~ SectionCursor 0 0 1 invDimColor
& ssRegex .~ UnavailableRegex
& ssIndent .~ 2
& ssMinSize .~ 1
& ssDescriptor .~ "YOUR STATUS"