Partial inventory display update

This commit is contained in:
2023-01-27 22:47:45 +00:00
parent ce25157738
commit 5f7d662454
6 changed files with 179 additions and 16 deletions
+102
View File
@@ -0,0 +1,102 @@
module Dodge.DisplayInventory where
import Picture.Base
import Dodge.Render.HUD
import Dodge.SelectionList
import LensHelp
import Dodge.Inventory.CheckSlots
import Dodge.Inventory.Color
import Dodge.Base.You
import Dodge.Inventory.SelectionList
import qualified Data.IntMap.Strict as IM
import Dodge.Data.Config
import Dodge.Default.World
import Dodge.Data.SelectionList
import Dodge.Data.World
makeDisplayInventory :: World -> Configuration -> SelectionSections ()
makeDisplayInventory w cfig = defaultDisplaySections
{ _sssSections = restrictsections
, _sssSelPos = Just 0
, _sssMaxSize = availablelines
}
where
initialsections = IM.fromList
[ (0, inventorysection)
, (1, makeYouSection w)
, (2, closesection)
]
inventorysection = makeInventorySection w
closesection = makeCloseObjectsSection w
itotallength = length . foldMap _siPictures $ _ssItems inventorysection
ctotallength = length . foldMap _siPictures $ _ssItems closesection
availablelines = getAvailableListLines (invDisplayParams w) cfig
iavailablelines = availablelines - 6
minlengths = sum $ fmap _ssMinSize initialsections
sections | itotallength + 1 + ctotallength > availablelines = restrictsections
| otherwise = initialsections
ioffset = 1
restrictsections = IM.fromList
[ (0, makeInventorySection w & ssShownItems %~ (take iavailablelines . drop ioffset))
, (1, makeYouSection w)
, (2, makeCloseObjectsSection w)
]
makeInventorySection :: World -> SelectionSection ()
makeInventorySection w = SelectionSection
{ _ssItems = map (invSelectionItem cr ) (IM.toList inv)
, _ssSelPos = Just 0
, _ssRestriction = NoSSRestriction
, _ssPriority = 0
, _ssOffset = 0
-- , _ssRegex = ""
-- , _ssRegexInput = False
, _ssMinSize = 5
-- , _ssOffset = 0
, _ssShownItems = foldMap (f . invSelectionItem cr ) (IM.toList inv)
}
where
cr = you w
inv = _crInv cr
f si = map (color (_siColor si) . text) $ _siPictures si
makeYouSection :: World -> SelectionSection ()
makeYouSection w = SelectionSection
{ _ssItems = [SelectionItem [thetext] 1 True (length thetext) invDimColor 2 ()]
, _ssSelPos = Nothing
, _ssOffset = 0
, _ssPriority = 1
, _ssRestriction = NoSSRestriction
-- , _ssRegex = ""
-- , _ssRegexInput = False
, _ssMinSize = 1
-- , _ssOffset = 0
, _ssShownItems = [color invDimColor $ text thetext]
}
where
cr = you w
nfreeslots = crNumFreeSlots cr
thetext = case nfreeslots of
0 -> " INVENTORY FULL"
1 -> " +1 FREE SLOT"
x -> " +" ++ show x ++ " FREE SLOTS"
makeCloseObjectsSection :: World -> SelectionSection ()
makeCloseObjectsSection w = SelectionSection
{ _ssItems = map (closeObjectToSelectionItem nfreeslots) (w ^. hud . closeObjects)
, _ssSelPos = Just 0
, _ssPriority = 1
, _ssOffset = 0
, _ssRestriction = NoSSRestriction
-- , _ssRegex = ""
-- , _ssRegexInput = False
, _ssMinSize = 5
-- , _ssOffset = 0
, _ssShownItems = foldMap (f . closeObjectToSelectionItem nfreeslots) (w ^. hud . closeObjects)
}
where
f si = map (color (_siColor si) . text) $ _siPictures si
cr = you w
nfreeslots = crNumFreeSlots cr