This commit is contained in:
2023-02-11 13:42:08 +00:00
parent 24825728f5
commit b5db7a3420
9 changed files with 49 additions and 92 deletions
+29 -64
View File
@@ -5,8 +5,6 @@ module Dodge.DisplayInventory
) where
import Data.Maybe
--import Picture.Text
--import Dodge.Inventory.ItemSpace
import Picture.Base
import Dodge.Render.HUD
import Dodge.SelectionList
@@ -22,41 +20,27 @@ import Dodge.Data.SelectionList
import Dodge.Data.World
updateDisplayInventory :: World -> Configuration -> SelectionSections () -> SelectionSections ()
updateDisplayInventory w cfig sss = sss
--{ _sssSections = restrictsections
{ _sssSections = sections
, _sssSelPos = mspos
, _sssMaxSize = availablelines
}
updateDisplayInventory w cfig sss = case cr ^? crInvSel . isel of
Just (SelItem i _) -> sss
{ _sssSections = updateSections availablelines (0,i) [invx ,youx, closex]
, _sssSelPos = Just 0
}
Just SelNothing -> sss
{ _sssSections = updateSections availablelines (1,0) [invx ,youx, closex]
, _sssSelPos = Just 1
}
Just (SelCloseObject i) -> sss
{ _sssSections = updateSections availablelines (2,i) [closex, invx ,youx]
, _sssSelPos = Just 2
}
_ -> error "error when getting cr inv sel"
where
sections = case cr ^? crInvSel . isel of
Just (SelItem i _) -> updateSections availablelines (0,i) [invx ,youx, closex]
Just SelNothing -> updateSections availablelines (1,0) [invx ,youx, closex]
Just (SelCloseObject i) -> updateSections availablelines (2,i) [closex, invx ,youx]
_ -> error "wat"
invx = (0,(invsec, invitems))
youx = (1,(makeYouSection w, youitems))
youx = (1,(yousec, youitems))
closex = (2,(cosec, coitems))
youitems = IM.singleton 0 $ SelectionItem [thetext] 1 True (length thetext) invDimColor 2 ()
thetext = case nfreeslots of
0 -> " INVENTORY FULL"
1 -> " +1 FREE SLOT"
x -> " +" ++ show x ++ " FREE SLOTS"
mspos = do
mo <- cr ^? crInvSel . isel
case mo of
SelItem {} -> Just 0
SelNothing -> Just 1
SelCloseObject {} -> Just 2
youitems = IM.singleton 0 $ SelectionItem [thetext] 1 True invDimColor 2 ()
thetext = displayFreeSlots nfreeslots
availablelines = getAvailableListLines (invDisplayParams w) cfig
iavailablelines = availablelines - 6
invsection = updateSection invpos invitems iavailablelines invsec
invsectionlines = length $ _ssShownItems invsection
restrictsections = IM.fromList
[ (0, invsection )
, (1, makeYouSection w)
, (2, updateSection copos coitems (availablelines - invsectionlines - 1) cosec)
]
cosec = fromMaybe defaultCOSection $ sss ^? sssSections . ix 2
invsec = fromMaybe defaultInvSection $ sss ^? sssSections . ix 0
coitems = IM.fromDistinctAscList . zip [0..]
@@ -65,18 +49,12 @@ updateDisplayInventory w cfig sss = sss
cr = you w
inv = _crInv (you w)
nfreeslots = crNumFreeSlots cr
invpos = do
mo <- cr ^? crInvSel . isel
case mo of
SelItem i _ -> Just i
SelNothing -> Nothing
SelCloseObject {} -> Nothing
copos = do
mo <- cr ^? crInvSel . isel
case mo of
SelItem {} -> Nothing
SelNothing -> Nothing
SelCloseObject i -> Just i
displayFreeSlots :: Int -> String
displayFreeSlots x = case x of
0 -> " INVENTORY FULL"
1 -> " +1 FREE SLOT"
_ -> " +" ++ show x ++ " FREE SLOTS"
updateSections :: Int -> (Int, Int) -> [(Int,(SelectionSection a,IM.IntMap (SelectionItem a)))]
-> IM.IntMap (SelectionSection a)
@@ -89,23 +67,20 @@ updateSections allavailablelines (i,j) ((k,(x,y)):xs) = IM.insert k ss
availablelines = allavailablelines - sum (map (_ssMinSize . fst . snd) xs)
defaultCOSection :: SelectionSection ()
defaultCOSection = SelectionSection mempty Nothing 5 1 0 NoSSRestriction [] 2 "CLOSE OBJECTS"
defaultCOSection = SelectionSection mempty Nothing 5 0 [] 2 "CLOSE OBJECTS"
defaultInvSection :: SelectionSection ()
defaultInvSection = SelectionSection mempty Nothing 5 0 0 NoSSRestriction [] 0 "INVENTORY ITEMS"
defaultInvSection = SelectionSection mempty Nothing 5 0 [] 0 "INVENTORY ITEMS"
updateSection
:: Maybe Int
-> IM.IntMap (SelectionItem a)
-> Int
-- -> World
-> SelectionSection a
-> SelectionSection a
updateSection mspos sis availablelines ss = ss
{ _ssItems = sis
, _ssCursor = scurs
, _ssRestriction = NoSSRestriction
, _ssPriority = 0
, _ssOffset = offset
-- , _ssRegex = ""
-- , _ssRegexInput = False
@@ -160,26 +135,16 @@ updateSection mspos sis availablelines ss = ss
si <- sis ^? ix i
return . length $ _siPictures si
makeYouSection :: World -> SelectionSection ()
makeYouSection w = SelectionSection
{ _ssItems = IM.singleton 0 $ SelectionItem [thetext] 1 True (length thetext) invDimColor 2 ()
yousec :: SelectionSection ()
yousec = SelectionSection
{ _ssItems = mempty
, _ssCursor = Just $ SectionCursor 0 1 invDimColor
, _ssOffset = 0
, _ssPriority = 1
, _ssRestriction = NoSSRestriction
, _ssIndent = 2
-- , _ssRegex = ""
-- , _ssRegexInput = False
, _ssMinSize = 1
-- , _ssOffset = 0
, _ssShownItems = [color invDimColor $ text thetext]
, _ssShownItems = mempty
, _ssDescriptor = "YOUR STATUS"
}
where
cr = you w
nfreeslots = crNumFreeSlots cr
thetext = case nfreeslots of
0 -> " INVENTORY FULL"
1 -> " +1 FREE SLOT"
x -> " +" ++ show x ++ " FREE SLOTS"