Allow selection items to have a payload

This commit is contained in:
2022-12-24 00:28:04 +00:00
parent 5356d21778
commit a97c5ec8ef
8 changed files with 65 additions and 92 deletions
+16 -15
View File
@@ -57,10 +57,9 @@ defaultListDisplayParams = ListDisplayParams
, _ldpPosY = 0
, _ldpCursorType = NoCursor
, _ldpWidth = FixedSelectionWidth 15
, _ldpSizeRestriction = NoSelectionSizeRestriction
}
defaultSelectionList :: SelectionList
defaultSelectionList :: SelectionList a
defaultSelectionList = SelectionList
{_slItems = []
, _slSelPos = Nothing
@@ -75,19 +74,18 @@ subInvListDisplayParams = ListDisplayParams
, _ldpPosY = 60
, _ldpCursorType = NoCursor
, _ldpWidth = FixedSelectionWidth 15
, _ldpSizeRestriction = NoSelectionSizeRestriction
}
subInvSelectionList :: SelectionList
subInvSelectionList :: SelectionList a
subInvSelectionList = SelectionList
{ _slItems = []
, _slSelPos = Nothing
, _slLength = 0
}
inventorySelectionList :: World -> [SelectionItem]
inventorySelectionList :: World -> [SelectionItem ()]
inventorySelectionList w = map (invSelectionItem cr) (IM.toList inv)
++ [SelectionItem displayFreeSlots 1 False (length thetext) white 0]
++ [SelectionItem displayFreeSlots 1 False (length thetext) white 0 ()]
++ map (closeObjectToSelectionItem nfreeslots) (w ^. cWorld . lWorld . closeObjects)
where
cr = you w
@@ -324,21 +322,21 @@ determineInvSelCursorWidth w = case _rbOptions w of
then 47
else topInvW
combineListSelection :: World -> SelectionList
combineListSelection :: World -> SelectionList ()
combineListSelection w = subInvSelectionList & slItems .~ combineListSelectionItems w
combineListSelectionItems :: World -> [SelectionItem]
combineListSelectionItems :: World -> [SelectionItem ()]
combineListSelectionItems w = case combineListSelectionItems' w of
[] -> [SelectionItem [text thetext] 1 False (length thetext) white 0]
[] -> [SelectionItem [text thetext] 1 False (length thetext) white 0 ()]
xs -> xs
where
thetext = "NO POSSIBLE COMBINATIONS"
combineListSelectionItems' :: World -> [SelectionItem]
combineListSelectionItems' :: World -> [SelectionItem ()]
combineListSelectionItems' w = map (picsToSelectable 15 . itemText . snd) $ combineItemListYou w
ammoTweakSelectionItems :: Maybe Item -> [SelectionItem]
ammoTweakSelectionItems :: Maybe Item -> [SelectionItem ()]
ammoTweakSelectionItems = textSelItems . ammoTweakStrings
ammoTweakStrings :: Maybe Item -> [String]
@@ -360,7 +358,7 @@ invHead cfig s =
invDimColor :: Color
invDimColor = greyN 0.7
closeObjectToSelectionItem :: Int -> Either FloorItem Button -> SelectionItem
closeObjectToSelectionItem :: Int -> Either FloorItem Button -> SelectionItem ()
closeObjectToSelectionItem n e = SelectionItem
{ _siPictures = pics
, _siHeight = length pics
@@ -368,6 +366,7 @@ closeObjectToSelectionItem n e = SelectionItem
, _siWidth = 15
, _siColor = col
, _siOffX = 2
, _siPayload = ()
}
where
(pics,col) = closeObjectToTextPictures' n e
@@ -464,7 +463,7 @@ mapWall cfig thehud wl =
mainListCursor :: Color -> Int -> Configuration -> Picture
mainListCursor c = openCursorAt 120 c 5 0
picsToSelectable :: Int -> [Picture] -> SelectionItem
picsToSelectable :: Int -> [Picture] -> SelectionItem ()
picsToSelectable wdth pics = SelectionItem
{ _siPictures = pics
, _siHeight = length pics
@@ -472,12 +471,13 @@ picsToSelectable wdth pics = SelectionItem
, _siWidth = wdth
, _siColor = white
, _siOffX = 0
, _siPayload = ()
}
textSelItems :: [String] -> [SelectionItem]
textSelItems :: [String] -> [SelectionItem ()]
textSelItems = map (picsToSelectable 15 . (:[]) . text)
invSelectionItem :: Creature -> (Int,Item) -> SelectionItem
invSelectionItem :: Creature -> (Int,Item) -> SelectionItem ()
invSelectionItem cr (i,it) = SelectionItem
{ _siPictures = pics
, _siHeight = length pics
@@ -485,6 +485,7 @@ invSelectionItem cr (i,it) = SelectionItem
, _siWidth = 15
, _siColor = col
, _siOffX = 0
, _siPayload = ()
}
where
col = _itInvColor it
+3 -3
View File
@@ -14,7 +14,7 @@ import ListHelp
import Picture
--import LensHelp
drawSelectionList :: ListDisplayParams -> Configuration -> SelectionList -> Picture
drawSelectionList :: ListDisplayParams -> Configuration -> SelectionList a -> Picture
drawSelectionList ldps cfig sl =
listPicturesAtScaleOff
(_ldpVerticalGap ldps)
@@ -26,13 +26,13 @@ drawSelectionList ldps cfig sl =
(makeSelectionListPictures sl)
<> drawSelectionCursor ldps cfig sl
makeSelectionListPictures :: SelectionList -> [Picture]
makeSelectionListPictures :: SelectionList a -> [Picture]
makeSelectionListPictures sl = concatMap _siPictures $ _slItems sl
--case sl ^. slSizeRestriction of
-- SelectionSizeRestriction {} -> concatMap (_siPictures . fst) $ _slShownItems sl
-- _ -> concatMap _siPictures $ _slItems sl
drawSelectionCursor :: ListDisplayParams -> Configuration -> SelectionList -> Picture
drawSelectionCursor :: ListDisplayParams -> Configuration -> SelectionList a -> Picture
drawSelectionCursor ldps cfig sl = fromMaybe mempty $ do
i <- _slSelPos sl
selit <- filter _siIsSelectable lis !? i
+1 -1
View File
@@ -82,7 +82,7 @@ drawOptions ::
-- | Title
String ->
-- | Select position
SelectionList ->
SelectionList a ->
-- | Help Text
String ->
Picture