Separate selection list items from display parameters
This commit is contained in:
+35
-26
@@ -49,34 +49,40 @@ drawInGameHUD subinv uv =
|
||||
w = _uvWorld uv
|
||||
cfig = _uvConfig uv
|
||||
|
||||
defaultListDisplayParams :: ListDisplayParams
|
||||
defaultListDisplayParams = ListDisplayParams
|
||||
{ _ldpVerticalGap = 10
|
||||
, _ldpScale = 1
|
||||
, _ldpPosX = 0
|
||||
, _ldpPosY = 0
|
||||
, _ldpCursorType = NoCursor
|
||||
, _ldpWidth = FixedSelectionWidth 15
|
||||
, _ldpSizeRestriction = NoSelectionSizeRestriction
|
||||
}
|
||||
|
||||
defaultSelectionList :: SelectionList
|
||||
defaultSelectionList = SelectionList
|
||||
{ _slVerticalGap = 10
|
||||
, _slScale = 1
|
||||
, _slPosX = 0
|
||||
, _slPosY = 0
|
||||
, _slItems = []
|
||||
, _slShownItems = []
|
||||
{_slItems = []
|
||||
, _slSelPos = Nothing
|
||||
, _slCursorType = NoCursor
|
||||
, _slWidth = FixedSelectionWidth 15
|
||||
, _slLength = 0
|
||||
, _slSizeRestriction = NoSelectionSizeRestriction
|
||||
}
|
||||
|
||||
subInvListDisplayParams :: ListDisplayParams
|
||||
subInvListDisplayParams = ListDisplayParams
|
||||
{ _ldpVerticalGap = 10
|
||||
, _ldpScale = 1
|
||||
, _ldpPosX = subInvX
|
||||
, _ldpPosY = 60
|
||||
, _ldpCursorType = NoCursor
|
||||
, _ldpWidth = FixedSelectionWidth 15
|
||||
, _ldpSizeRestriction = NoSelectionSizeRestriction
|
||||
}
|
||||
|
||||
subInvSelectionList :: SelectionList
|
||||
subInvSelectionList = SelectionList
|
||||
{ _slVerticalGap = 10
|
||||
, _slScale = 1
|
||||
, _slPosX = subInvX
|
||||
, _slPosY = 60
|
||||
, _slItems = []
|
||||
, _slShownItems = []
|
||||
{ _slItems = []
|
||||
, _slSelPos = Nothing
|
||||
, _slCursorType = NoCursor
|
||||
, _slWidth = FixedSelectionWidth 15
|
||||
, _slLength = 0
|
||||
, _slSizeRestriction = NoSelectionSizeRestriction
|
||||
}
|
||||
|
||||
inventorySelectionList :: World -> [SelectionItem]
|
||||
@@ -98,18 +104,21 @@ inventoryCursorPos subinv w = case subinv of
|
||||
CombineInventory {} -> Nothing
|
||||
_ -> Just $ yourInvSel w
|
||||
|
||||
inventoryDisplay :: SubInventory -> Configuration -> World -> Picture
|
||||
inventoryDisplay subinv cfig w = drawSelectionList cfig $
|
||||
defaultSelectionList & slItems .~ inventorySelectionList w
|
||||
& slWidth .~ FixedSelectionWidth topInvW
|
||||
& slCursorType .~ BorderCursor (Set.fromList selcursortype)
|
||||
& slSelPos .~ inventoryCursorPos subinv w
|
||||
& slWidth .~ FixedSelectionWidth (determineInvSelCursorWidth w)
|
||||
invDisplayParams :: World -> ListDisplayParams
|
||||
invDisplayParams w = defaultListDisplayParams
|
||||
& ldpWidth .~ FixedSelectionWidth topInvW
|
||||
& ldpCursorType .~ BorderCursor (Set.fromList selcursortype)
|
||||
& ldpWidth .~ FixedSelectionWidth (determineInvSelCursorWidth w)
|
||||
where
|
||||
selcursortype
|
||||
| ButtonRight `M.member` _mouseButtons (_input w) = [North,South,East,West]
|
||||
| otherwise = [North,South,West]
|
||||
|
||||
inventoryDisplay :: SubInventory -> Configuration -> World -> Picture
|
||||
inventoryDisplay subinv cfig w = drawSelectionList (invDisplayParams w) cfig $
|
||||
defaultSelectionList & slItems .~ inventorySelectionList w
|
||||
& slSelPos .~ inventoryCursorPos subinv w
|
||||
|
||||
drawSubInventory :: SubInventory -> Configuration -> World -> Picture
|
||||
drawSubInventory subinv cfig w = case subinv of
|
||||
LockedInventory -> mempty -- topInvCursor col cursPos cfig w
|
||||
@@ -160,7 +169,7 @@ drawSubInventory subinv cfig w = case subinv of
|
||||
]
|
||||
where
|
||||
titledSub subtitle subitems extrapics = pictures $ [invHead cfig subtitle
|
||||
,drawSelectionList cfig subitems] <>
|
||||
,drawSelectionList subInvListDisplayParams cfig subitems] <>
|
||||
extrapics
|
||||
closeobjectcursor = case selectedCloseObject w of
|
||||
Nothing -> mempty
|
||||
|
||||
+17
-16
@@ -15,36 +15,37 @@ import ListHelp
|
||||
import Picture
|
||||
import LensHelp
|
||||
|
||||
drawSelectionList :: Configuration -> SelectionList -> Picture
|
||||
drawSelectionList cfig sl =
|
||||
drawSelectionList :: ListDisplayParams -> Configuration -> SelectionList -> Picture
|
||||
drawSelectionList ldps cfig sl =
|
||||
listPicturesAtScaleOff
|
||||
(_slVerticalGap sl)
|
||||
(_slScale sl)
|
||||
(_slPosX sl)
|
||||
(_slPosY sl)
|
||||
(_ldpVerticalGap ldps)
|
||||
(_ldpScale ldps)
|
||||
(_ldpPosX ldps)
|
||||
(_ldpPosY ldps)
|
||||
cfig
|
||||
0 --(_slOffset sl)
|
||||
(makeSelectionListPictures sl)
|
||||
<> drawSelectionCursor cfig sl
|
||||
<> drawSelectionCursor ldps cfig sl
|
||||
|
||||
makeSelectionListPictures :: SelectionList -> [Picture]
|
||||
makeSelectionListPictures sl = case sl ^. slSizeRestriction of
|
||||
SelectionSizeRestriction {} -> concatMap (_siPictures . fst) $ _slShownItems sl
|
||||
_ -> concatMap _siPictures $ _slItems sl
|
||||
makeSelectionListPictures sl = concatMap _siPictures $ _slItems sl
|
||||
--case sl ^. slSizeRestriction of
|
||||
-- SelectionSizeRestriction {} -> concatMap (_siPictures . fst) $ _slShownItems sl
|
||||
-- _ -> concatMap _siPictures $ _slItems sl
|
||||
|
||||
drawSelectionCursor :: Configuration -> SelectionList -> Picture
|
||||
drawSelectionCursor cfig sl = fromMaybe mempty $ do
|
||||
drawSelectionCursor :: ListDisplayParams -> Configuration -> SelectionList -> Picture
|
||||
drawSelectionCursor ldps cfig sl = fromMaybe mempty $ do
|
||||
i <- _slSelPos sl
|
||||
selit <- filter _siIsSelectable lis !? i
|
||||
f <- case _slCursorType sl of
|
||||
BorderCursor cps -> Just $ listCursorChooseBorderScale (_slVerticalGap sl) (_slScale sl) cps
|
||||
f <- case _ldpCursorType ldps of
|
||||
BorderCursor cps -> Just $ listCursorChooseBorderScale (_ldpVerticalGap ldps) (_ldpScale ldps) cps
|
||||
NoCursor -> Nothing
|
||||
let j = sum . map _siHeight $ takeWhileArb (<= i) (\x itsel -> x + if _siIsSelectable itsel then 1 else 0) 0 lis
|
||||
col = _siColor selit
|
||||
return $ f (_slPosX sl + (9 * fromIntegral (_siOffX selit))) (_slPosY sl) cfig j col wdth (_siHeight selit)
|
||||
return $ f (_ldpPosX ldps + (9 * fromIntegral (_siOffX selit))) (_ldpPosY ldps) cfig j col wdth (_siHeight selit)
|
||||
where
|
||||
lis = _slItems sl
|
||||
wdth = case _slWidth sl of
|
||||
wdth = case _ldpWidth ldps of
|
||||
FixedSelectionWidth x -> x
|
||||
_ -> 1
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ import Picture
|
||||
|
||||
drawMenuScreen :: Configuration -> ScreenLayer -> Picture
|
||||
drawMenuScreen cfig screen = case screen of
|
||||
OptionScreen{_scTitle = titf, _scSelectionList = selpos} ->
|
||||
drawOptions cfig titf selpos "Use keys to navigate the menu"
|
||||
OptionScreen{_scTitle = titf, _scSelectionList = selpos, _scListDisplayParams = ldps} ->
|
||||
drawOptions ldps cfig titf selpos "Use keys to navigate the menu"
|
||||
-- (WaitScreen sf _) -> drawOptions w (sf w) [] 0 ""
|
||||
(InputScreen inputstr help) -> drawInputMenu cfig ('>' : T.unpack inputstr) help
|
||||
-- (DisplayScreen sd) -> sd w
|
||||
@@ -77,6 +77,7 @@ drawInputMenu cfig title footer =
|
||||
]
|
||||
|
||||
drawOptions ::
|
||||
ListDisplayParams ->
|
||||
Configuration ->
|
||||
-- | Title
|
||||
String ->
|
||||
@@ -85,12 +86,12 @@ drawOptions ::
|
||||
-- | Help Text
|
||||
String ->
|
||||
Picture
|
||||
drawOptions cfig title sl footer =
|
||||
drawOptions ldps cfig title sl footer =
|
||||
pictures
|
||||
[ darkenBackground cfig
|
||||
, drawTitle cfig title
|
||||
, drawFooterText cfig red footer
|
||||
, drawSelectionList cfig sl
|
||||
, drawSelectionList ldps cfig sl
|
||||
]
|
||||
|
||||
darkenBackground :: Configuration -> Picture
|
||||
|
||||
Reference in New Issue
Block a user