Work on mouse selection in menus

This commit is contained in:
2022-11-03 14:16:28 +00:00
parent e6e5427f44
commit 6e7cd14f49
7 changed files with 133 additions and 96 deletions
+3 -41
View File
@@ -4,6 +4,7 @@ module Dodge.Render.MenuScreen (
menuScreen',
) where
import Dodge.Menu.Option
import Dodge.Data.CardinalPoint
import Dodge.Render.List
import Dodge.Data.SelectionList
@@ -75,8 +76,8 @@ drawOptions ::
Picture
drawOptions u title ops off mselpos footer =
pictures $
[ darkenBackground cfig
, drawTitle cfig title
[ --darkenBackground cfig
drawTitle cfig title
, drawFooterText cfig red footer
, drawSelectionList cfig (makeOptionsSelectionList mselpos u ops)
]
@@ -112,18 +113,6 @@ defaultSelectionItem = SelectionItem
, _siOffX = 0
}
makeOptionsSelectionList :: Maybe Int -> Universe -> [MenuOption] -> SelectionList
makeOptionsSelectionList mselpos u mos = SelectionList
{ _slPosX = 50
, _slPosY = 50
, _slOffset = 0
, _slScale = 2
, _slVerticalGap = 30
, _slItems = optionsToSelections u mos
, _slSelPos = mselpos
, _slCursorType = BorderCursor (Set.fromList [North,South,West])
, _slWidth = FixedSelectionWidth 15
}
colStrToSelItem :: (Color,String) -> SelectionItem
colStrToSelItem (col,str) = SelectionItem
{ _siPictures = [color col $ text str]
@@ -133,19 +122,6 @@ colStrToSelItem (col,str) = SelectionItem
, _siOffX = 0
}
optionsToSelections :: Universe -> [MenuOption] -> [SelectionItem]
optionsToSelections u ops = map colStrToSelItem colstrs
where
maxOptionLength = 3 + maximum (0 : map (optionValueOffset u) visibleops)
colstrs = map (menuOptionToString u maxOptionLength) visibleops
visibleops = filter notInvisible ops
notInvisible InvisibleToggle{} = False
notInvisible _ = True
optionValueOffset :: Universe -> MenuOption -> Int
optionValueOffset u mo = case _moString mo u of
MODStringOption s _ -> length s
_ -> 0
darkenBackground :: Configuration -> Picture
darkenBackground = color (withAlpha 0.5 black) . polygon . reverse . screenBox
@@ -184,17 +160,3 @@ drawFooterText cfig col = color col . placeString (- hw + 30) (- hh + 10) 0.1
hh = halfHeight cfig
hw = halfWidth cfig
menuOptionToString :: Universe -> Int -> MenuOption -> (Color, String)
menuOptionToString w padAmount mo = (thecol, theKeys ++ optionText)
where
thecol = case _moString mo w of
MODBlockedString{} -> greyN 0.5
_ -> white
optionText = case _moString mo w of
MODStringOption s t -> rightPad padAmount '.' s ++ t
x -> _modString x
theKeys = case mo of
Toggle{_moKey = k} -> stc k : ":"
Toggle2{_moKey1 = k1, _moKey2 = k2} -> stc k1 : '/' : stc k2 : ":"
_ -> undefined
stc = scodeToChar