Unify menu event handling and display

This commit is contained in:
2021-09-03 13:48:52 +01:00
parent 6a2df15d0d
commit 111b86d2df
3 changed files with 104 additions and 100 deletions
+10 -31
View File
@@ -23,34 +23,12 @@ menuScreen
-> [MenuLayer]
-> Picture
menuScreen w cfig hw hh mLays = case mLays of
(LevelMenu x:_) -> optionsList hw hh ("LEVEL"++show x) []
(LevelMenu x:_) -> optionsFromList w hw hh ("LEVEL"++show x) levelMenuOptions
(PauseMenu : _) -> optionsFromList w hw hh "PAUSED" pauseMenuOptions
-- (PauseMenu:_) -> optionsList hw hh "PAUSED"
-- ["N - NEW LEVEL"
-- ,"R - RESTART"
-- ,"O - OPTIONS"
-- ,"C - CONTROLS"
-- ]
(GameOverMenu:_) -> optionsList hw hh "GAME OVER"
["N - NEW LEVEL"
,"R - RESTART"
,"O - OPTIONS"
,"C - CONTROLS"
]
(GameOverMenu : _) -> optionsFromList w hw hh "GAME OVER" pauseMenuOptions
(OptionMenu : _) -> optionsFromList w hw hh "OPTIONS" optionsOptions
-- (OptionMenu : _) -> optionsList hw hh "OPTIONS"
-- ["V - VOLUME"
-- ,"G - GRAPHICS"
-- ]
(SoundOptionMenu : _) -> optionsList hw hh "OPTIONS:VOLUME"
["Y - MASTER VOLUME + U : " ++ mavol
,"H - SOUND VOLUME + J : " ++ snvol
,"N - MUSIC VOLUME + M : " ++ muvol
]
(GraphicsOptionMenu : _) -> optionsList hw hh "OPTIONS:GRAPHICS"
["W - WALL TEXTURES:" ++ show (_wall_textured cfig)
,"S - RESOLUTION: 1/" ++ show (_resolution_factor cfig)
]
(SoundOptionMenu : _) -> optionsFromList w hw hh "OPTIONS:VOLUME" soundMenuOptions
(GraphicsOptionMenu : _) -> optionsFromList w hw hh "OPTIONS:GRAPHICS" graphicsMenuOptions
(ControlList : _) -> pictures
[color (withAlpha 0.5 black) $ polygon $ screenBox hw hh
,tst (-100) 100 0.4 "CONTROLS"
@@ -62,10 +40,6 @@ menuScreen w cfig hw hh mLays = case mLays of
_ -> blank
where
tst x y sc t = translate x y $ scale sc sc $ color white $ text t
mavol = f $ _volume_master cfig
snvol = f $ _volume_sound cfig
muvol = f $ _volume_music cfig
f x = show (round $ 10 * x :: Int)
displayStringList :: Float -> Float -> [String] -> Picture
displayStringList hw hh ss = pictures
@@ -96,7 +70,12 @@ optionsFromList w hw hh tit ops = pictures $
darkenBackground = color (withAlpha 0.5 black) $ polygon $ screenBox hw hh
theTitle = placeString (-hw + 30) (hh - 50) 0.4 tit
menuOptionToString :: World -> MenuOption -> String
menuOptionToString w mo = (scodeToChar $ _moKey mo) : ':' : _moString mo w
menuOptionToString w mo@(Toggle{})
= (scodeToChar $ _moKey mo) : ':' : _moString mo w
menuOptionToString w mo@(Toggle2{})
= (scodeToChar $ _moKey1 mo) : '/' : (scodeToChar $ _moKey2 mo) : ':' : _moString mo w
menuOptionToString _ _ = "undefined option string"
optionsList
:: Float -- ^ Half screen width