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
+3 -2
View File
@@ -47,7 +47,8 @@ combineItemListYouX = map (first $ concatMap g) . lookupItems . yourInv
combineList :: World -> [SelectionItem CombinableItem] combineList :: World -> [SelectionItem CombinableItem]
combineList w = case combineList' w of combineList w = case combineList' w of
[] -> [SelectionInfo ["No possible combinations"] 1 False 0 white 0] -- [] -> [SelectionInfo ["No possible combinations"] 1 False 0 white 0]
[] -> [SelectionInfo ["No possible combinations"] 1 False white 0]
xs -> xs xs -> xs
combineList' :: World -> [SelectionItem CombinableItem] combineList' :: World -> [SelectionItem CombinableItem]
@@ -57,7 +58,7 @@ combineList' = map f . combineListInfo
{ _siPictures = itemDisplay itm { _siPictures = itemDisplay itm
, _siHeight = length (itemDisplay itm) , _siHeight = length (itemDisplay itm)
, _siIsSelectable = True , _siIsSelectable = True
, _siWidth = maximum (map length (itemDisplay itm)) --, _siWidth = maximum (map length (itemDisplay itm))
, _siColor = _itInvColor itm , _siColor = _itInvColor itm
, _siOffX = 0 , _siOffX = 0
, _siPayload = CombinableItem is itm strs , _siPayload = CombinableItem is itm strs
+3 -12
View File
@@ -33,15 +33,8 @@ data SelectionList a = SelectionList
data SelectionSections a = SelectionSections data SelectionSections a = SelectionSections
{ _sssSections :: IntMap (SelectionSection a) { _sssSections :: IntMap (SelectionSection a)
, _sssSelPos :: Maybe Int , _sssSelPos :: Maybe Int
, _sssMaxSize :: Int
} }
data SSRestriction = NoSSRestriction
| SSRestriction
{ _ssrSize :: Int
, _ssrOffset :: Int
}
data SectionCursor = SectionCursor data SectionCursor = SectionCursor
{ _scurPos :: Int { _scurPos :: Int
, _scurSize :: Int , _scurSize :: Int
@@ -55,9 +48,8 @@ data SelectionSection a = SelectionSection
-- , _ssSelSize :: Maybe Int -- , _ssSelSize :: Maybe Int
-- , _ssSelColor :: Maybe Color -- , _ssSelColor :: Maybe Color
, _ssMinSize :: Int , _ssMinSize :: Int
, _ssPriority :: Int --, _ssPriority :: Int
, _ssOffset :: Int , _ssOffset :: Int
, _ssRestriction :: SSRestriction
, _ssShownItems :: [Picture] , _ssShownItems :: [Picture]
, _ssIndent :: Int , _ssIndent :: Int
, _ssDescriptor :: String , _ssDescriptor :: String
@@ -84,7 +76,7 @@ data SelectionItem a = SelectionItem
{ _siPictures :: [String] { _siPictures :: [String]
, _siHeight :: Int , _siHeight :: Int
, _siIsSelectable :: Bool , _siIsSelectable :: Bool
, _siWidth :: Int --, _siWidth :: Int
, _siColor :: Color , _siColor :: Color
, _siOffX :: Int , _siOffX :: Int
, _siPayload :: a , _siPayload :: a
@@ -93,7 +85,7 @@ data SelectionItem a = SelectionItem
{ _siPictures :: [String] { _siPictures :: [String]
, _siHeight :: Int , _siHeight :: Int
, _siIsSelectable :: Bool , _siIsSelectable :: Bool
, _siWidth :: Int --, _siWidth :: Int
, _siColor :: Color , _siColor :: Color
, _siOffX :: Int , _siOffX :: Int
} }
@@ -106,6 +98,5 @@ makeLenses ''SelectionIntMap
makeLenses ''SelectionSection makeLenses ''SelectionSection
makeLenses ''SelectionSections makeLenses ''SelectionSections
makeLenses ''SectionCursor makeLenses ''SectionCursor
makeLenses ''SSRestriction
--deriveJSON defaultOptions ''SelectionItem --deriveJSON defaultOptions ''SelectionItem
--deriveJSON defaultOptions ''SelectionList --deriveJSON defaultOptions ''SelectionList
-1
View File
@@ -146,7 +146,6 @@ defaultDisplaySections :: SelectionSections a
defaultDisplaySections = SelectionSections defaultDisplaySections = SelectionSections
{ _sssSections = mempty { _sssSections = mempty
, _sssSelPos = Just 0 , _sssSelPos = Just 0
, _sssMaxSize = 20
} }
defaultHUD :: HUD defaultHUD :: HUD
+29 -64
View File
@@ -5,8 +5,6 @@ module Dodge.DisplayInventory
) where ) where
import Data.Maybe import Data.Maybe
--import Picture.Text
--import Dodge.Inventory.ItemSpace
import Picture.Base import Picture.Base
import Dodge.Render.HUD import Dodge.Render.HUD
import Dodge.SelectionList import Dodge.SelectionList
@@ -22,41 +20,27 @@ import Dodge.Data.SelectionList
import Dodge.Data.World import Dodge.Data.World
updateDisplayInventory :: World -> Configuration -> SelectionSections () -> SelectionSections () updateDisplayInventory :: World -> Configuration -> SelectionSections () -> SelectionSections ()
updateDisplayInventory w cfig sss = sss updateDisplayInventory w cfig sss = case cr ^? crInvSel . isel of
--{ _sssSections = restrictsections Just (SelItem i _) -> sss
{ _sssSections = sections { _sssSections = updateSections availablelines (0,i) [invx ,youx, closex]
, _sssSelPos = mspos , _sssSelPos = Just 0
, _sssMaxSize = availablelines }
} 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 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)) invx = (0,(invsec, invitems))
youx = (1,(makeYouSection w, youitems)) youx = (1,(yousec, youitems))
closex = (2,(cosec, coitems)) closex = (2,(cosec, coitems))
youitems = IM.singleton 0 $ SelectionItem [thetext] 1 True (length thetext) invDimColor 2 () youitems = IM.singleton 0 $ SelectionItem [thetext] 1 True invDimColor 2 ()
thetext = case nfreeslots of thetext = displayFreeSlots nfreeslots
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
availablelines = getAvailableListLines (invDisplayParams w) cfig 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 cosec = fromMaybe defaultCOSection $ sss ^? sssSections . ix 2
invsec = fromMaybe defaultInvSection $ sss ^? sssSections . ix 0 invsec = fromMaybe defaultInvSection $ sss ^? sssSections . ix 0
coitems = IM.fromDistinctAscList . zip [0..] coitems = IM.fromDistinctAscList . zip [0..]
@@ -65,18 +49,12 @@ updateDisplayInventory w cfig sss = sss
cr = you w cr = you w
inv = _crInv (you w) inv = _crInv (you w)
nfreeslots = crNumFreeSlots cr nfreeslots = crNumFreeSlots cr
invpos = do
mo <- cr ^? crInvSel . isel displayFreeSlots :: Int -> String
case mo of displayFreeSlots x = case x of
SelItem i _ -> Just i 0 -> " INVENTORY FULL"
SelNothing -> Nothing 1 -> " +1 FREE SLOT"
SelCloseObject {} -> Nothing _ -> " +" ++ show x ++ " FREE SLOTS"
copos = do
mo <- cr ^? crInvSel . isel
case mo of
SelItem {} -> Nothing
SelNothing -> Nothing
SelCloseObject i -> Just i
updateSections :: Int -> (Int, Int) -> [(Int,(SelectionSection a,IM.IntMap (SelectionItem a)))] updateSections :: Int -> (Int, Int) -> [(Int,(SelectionSection a,IM.IntMap (SelectionItem a)))]
-> IM.IntMap (SelectionSection 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) availablelines = allavailablelines - sum (map (_ssMinSize . fst . snd) xs)
defaultCOSection :: SelectionSection () 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 ()
defaultInvSection = SelectionSection mempty Nothing 5 0 0 NoSSRestriction [] 0 "INVENTORY ITEMS" defaultInvSection = SelectionSection mempty Nothing 5 0 [] 0 "INVENTORY ITEMS"
updateSection updateSection
:: Maybe Int :: Maybe Int
-> IM.IntMap (SelectionItem a) -> IM.IntMap (SelectionItem a)
-> Int -> Int
-- -> World
-> SelectionSection a -> SelectionSection a
-> SelectionSection a -> SelectionSection a
updateSection mspos sis availablelines ss = ss updateSection mspos sis availablelines ss = ss
{ _ssItems = sis { _ssItems = sis
, _ssCursor = scurs , _ssCursor = scurs
, _ssRestriction = NoSSRestriction
, _ssPriority = 0
, _ssOffset = offset , _ssOffset = offset
-- , _ssRegex = "" -- , _ssRegex = ""
-- , _ssRegexInput = False -- , _ssRegexInput = False
@@ -160,26 +135,16 @@ updateSection mspos sis availablelines ss = ss
si <- sis ^? ix i si <- sis ^? ix i
return . length $ _siPictures si return . length $ _siPictures si
makeYouSection :: World -> SelectionSection () yousec :: SelectionSection ()
makeYouSection w = SelectionSection yousec = SelectionSection
{ _ssItems = IM.singleton 0 $ SelectionItem [thetext] 1 True (length thetext) invDimColor 2 () { _ssItems = mempty
, _ssCursor = Just $ SectionCursor 0 1 invDimColor , _ssCursor = Just $ SectionCursor 0 1 invDimColor
, _ssOffset = 0 , _ssOffset = 0
, _ssPriority = 1
, _ssRestriction = NoSSRestriction
, _ssIndent = 2 , _ssIndent = 2
-- , _ssRegex = "" -- , _ssRegex = ""
-- , _ssRegexInput = False -- , _ssRegexInput = False
, _ssMinSize = 1 , _ssMinSize = 1
-- , _ssOffset = 0 -- , _ssOffset = 0
, _ssShownItems = [color invDimColor $ text thetext] , _ssShownItems = mempty
, _ssDescriptor = "YOUR STATUS" , _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"
+3 -3
View File
@@ -30,7 +30,7 @@ invSelectionItem' cr i it = SelectionItem
{ _siPictures = pics { _siPictures = pics
, _siHeight = length pics , _siHeight = length pics
, _siIsSelectable = True , _siIsSelectable = True
, _siWidth = 15 --, _siWidth = 15
, _siColor = col , _siColor = col
, _siOffX = 0 , _siOffX = 0
, _siPayload = () , _siPayload = ()
@@ -46,7 +46,7 @@ invSelectionItem cr (i,it) = SelectionItem
{ _siPictures = pics { _siPictures = pics
, _siHeight = length pics , _siHeight = length pics
, _siIsSelectable = True , _siIsSelectable = True
, _siWidth = 15 --, _siWidth = 15
, _siColor = col , _siColor = col
, _siOffX = 0 , _siOffX = 0
, _siPayload = () , _siPayload = ()
@@ -63,7 +63,7 @@ closeObjectToSelectionItem n e = SelectionItem
{ _siPictures = pics { _siPictures = pics
, _siHeight = length pics , _siHeight = length pics
, _siIsSelectable = True , _siIsSelectable = True
, _siWidth = 15 --, _siWidth = 15
, _siColor = col , _siColor = col
, _siOffX = 2 , _siOffX = 2
, _siPayload = () , _siPayload = ()
+2 -2
View File
@@ -104,7 +104,7 @@ colStrToSelItem (col, str) =
{ _siPictures = [str] { _siPictures = [str]
, _siHeight = 1 , _siHeight = 1
, _siIsSelectable = True , _siIsSelectable = True
, _siWidth = length str --, _siWidth = length str
, _siColor = col , _siColor = col
, _siOffX = 0 , _siOffX = 0
, _siPayload = id , _siPayload = id
@@ -121,7 +121,7 @@ menuOptionToSelectionItem w padAmount mo =
{ _siPictures = [optionText] { _siPictures = [optionText]
, _siHeight = 1 , _siHeight = 1
, _siIsSelectable = isselectable , _siIsSelectable = isselectable
, _siWidth = length optionText --, _siWidth = length optionText
, _siColor = thecol , _siColor = thecol
, _siOffX = 0 , _siOffX = 0
, _siPayload = f , _siPayload = f
+7 -6
View File
@@ -139,7 +139,7 @@ drawExamineInventory cfig mtweaki w =
{ _siPictures = [str] { _siPictures = [str]
, _siHeight = 1 , _siHeight = 1
, _siIsSelectable = True , _siIsSelectable = True
, _siWidth = length str --, _siWidth = length str
, _siColor = white , _siColor = white
, _siOffX = 0 , _siOffX = 0
, _siPayload = () , _siPayload = ()
@@ -260,7 +260,8 @@ displayTerminal tid cfig w = fromMaybe mempty $ do
, drawSelectionList secondColumnParams cfig (thesellist tm) , drawSelectionList secondColumnParams cfig (thesellist tm)
] ]
where where
toselitm (str, col) = SelectionItem [str] 1 True (length str) col 0 () --toselitm (str, col) = SelectionItem [str] 1 True (length str) col 0 ()
toselitm (str, col) = SelectionItem [str] 1 True col 0 ()
thesellist tm = defaultSelectionList thesellist tm = defaultSelectionList
{ _slItems = thelist tm { _slItems = thelist tm
-- , _slLength = length (thelist tm) -- , _slLength = length (thelist tm)
@@ -465,15 +466,15 @@ mainListCursor :: Color -> Int -> Configuration -> Picture
mainListCursor c = openCursorAt 120 c 5 0 mainListCursor c = openCursorAt 120 c 5 0
textSelItems :: [String] -> [SelectionItem ()] textSelItems :: [String] -> [SelectionItem ()]
textSelItems = map (picsToSelectable 15 . (: [])) textSelItems = map (picsToSelectable . (: []))
picsToSelectable :: Int -> [String] -> SelectionItem () picsToSelectable :: [String] -> SelectionItem ()
picsToSelectable wdth pics = picsToSelectable pics =
SelectionItem SelectionItem
{ _siPictures = pics { _siPictures = pics
, _siHeight = length pics , _siHeight = length pics
, _siIsSelectable = True , _siIsSelectable = True
, _siWidth = wdth --, _siWidth = wdth
, _siColor = white , _siColor = white
, _siOffX = 0 , _siOffX = 0
, _siPayload = () , _siPayload = ()
+1 -1
View File
@@ -27,7 +27,7 @@ makeRegexList sl = case sl ^. slRegex of
{ _siPictures = ["FILTER: "++str] { _siPictures = ["FILTER: "++str]
, _siHeight = 1 , _siHeight = 1
, _siIsSelectable = False , _siIsSelectable = False
, _siWidth = length $ "FILTER: "++str --, _siWidth = length $ "FILTER: "++str
, _siColor = white , _siColor = white
, _siOffX = 0 , _siOffX = 0
}, Nothing) : filter (doregex str) (zip (_slItems sl) $ fmap Just [0..]) }, Nothing) : filter (doregex str) (zip (_slItems sl) $ fmap Just [0..])
+1 -1
View File
@@ -19,7 +19,7 @@ setShownIntMap sm = case sm ^. smRegex of
{ _siPictures = ["FILTER: " ++ str] { _siPictures = ["FILTER: " ++ str]
, _siHeight = 1 , _siHeight = 1
, _siIsSelectable = False , _siIsSelectable = False
, _siWidth = length ("FILTER: " ++ str) --, _siWidth = length ("FILTER: " ++ str)
, _siColor = white , _siColor = white
, _siOffX = 0 , _siOffX = 0
} }