Move inventory filter to different section of selection list

This commit is contained in:
2023-02-17 10:35:59 +00:00
parent 4afc216b25
commit 93dfc2a67c
8 changed files with 111 additions and 102 deletions
+34 -19
View File
@@ -23,23 +23,30 @@ import Dodge.Data.World
updateDisplayInventory :: World -> Configuration -> SelectionSections () -> SelectionSections ()
updateDisplayInventory w cfig sss = case cr ^? crManipulation . manObject of
Just (InInventory SortInventory) -> sss
{ _sssSections = updateSections availablelines ((-1),0) [filtinv,invx ,youx, closex]
, _sssSelPos = Just (-1)
}
Just (InInventory (SelItem i _)) -> sss
{ _sssSections = updateSections availablelines (0,i) [invx ,youx, closex]
{ _sssSections = updateSections availablelines (0,i) [filtinv,invx ,youx, closex]
, _sssSelPos = Just 0
}
Just SelNothing -> sss
{ _sssSections = updateSections availablelines (1,0) [invx ,youx, closex]
{ _sssSections = updateSections availablelines (1,0) [filtinv,invx ,youx, closex]
, _sssSelPos = Just 1
}
Just (SelCloseObject i) -> sss
{ _sssSections = updateSections availablelines (2,i) [closex, invx ,youx]
{ _sssSections = updateSections availablelines (2,i) [filtinv,closex, invx ,youx]
, _sssSelPos = Just 2
}
_ -> error "error when getting cr inv sel"
where
filtinv = (-1,(filtinvsec,filtinvitems))
filtinvsec = undefined
filtinvitems = undefined
filtinvsec = fromMaybe defaultFiltSection $ sss ^? sssSections . ix (-1)
filtinvitems = case cr ^? crManipulation . invRegex . _Just of
Just str -> IM.singleton 0 (SelectionRegex ["INV. FILTER: " ++ str,numfiltitems] 2 True white 0)
Nothing -> mempty
numfiltitems = " " ++ show numfiltitems' ++ " FILTERED"
numfiltitems' = length invitems' - length invitems
invx = (0,(invsec, invitems))
youx = (1,(yousec, youitems))
closex = (2,(cosec, coitems))
@@ -50,7 +57,10 @@ updateDisplayInventory w cfig sss = case cr ^? crManipulation . manObject of
invsec = fromMaybe defaultInvSection $ sss ^? sssSections . ix 0
coitems = IM.fromDistinctAscList . zip [0..]
$ map (closeObjectToSelectionItem nfreeslots) (w ^. hud . closeObjects)
invitems = IM.mapWithKey (invSelectionItem' cr) inv
invitems' = IM.mapWithKey (invSelectionItem' cr) inv
invitems = case cr ^? crManipulation . invRegex . _Just of
Just str -> IM.filter (regexList str . _siPictures) invitems'
Nothing -> invitems'
cr = you w
inv = _crInv (you w)
nfreeslots = crNumFreeSlots cr
@@ -75,7 +85,6 @@ defaultSS :: SelectionSection ()
defaultSS = SelectionSection
{ _ssItems = mempty
, _ssCursor = Nothing
, _ssRegex = EmptyRegex
, _ssMinSize = 5
, _ssOffset = 0
, _ssShownItems = []
@@ -89,6 +98,12 @@ defaultCOSection = defaultSS
& ssIndent .~ 2
& ssDescriptor .~ "CLOSE OBJECTS"
defaultFiltSection :: SelectionSection ()
defaultFiltSection = defaultSS
& ssIndent .~ 0
& ssDescriptor .~ "INV"
& ssMinSize .~ 0
defaultInvSection :: SelectionSection ()
defaultInvSection = defaultSS
& ssDescriptor .~ "INVENTORY ITEMS"
@@ -103,20 +118,20 @@ updateSection mspos sis' availablelines ss = ss
{ _ssItems = sis
, _ssCursor = scurs
, _ssOffset = offset
, _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
}
sis = 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
@@ -167,7 +182,7 @@ updateSection mspos sis' availablelines ss = ss
yousec :: SelectionSection ()
yousec = defaultSS
& ssCursor ?~ SectionCursor 0 0 1 invDimColor
& ssRegex .~ UnavailableRegex
-- & ssRegex .~ UnavailableRegex
& ssIndent .~ 2
& ssMinSize .~ 1
& ssDescriptor .~ "YOUR STATUS"