Unify option menu display and effects

This commit is contained in:
2021-09-03 12:38:56 +01:00
parent 083000c103
commit 6a2df15d0d
5 changed files with 117 additions and 39 deletions
+38 -12
View File
@@ -6,37 +6,42 @@ module Dodge.Render.MenuScreen
)
where
import Dodge.Data.Menu
import Dodge.Data
--import Dodge.Config.Update
import Dodge.Config.Data
--import Dodge.Base (halfWidth,halfHeight)
import Picture
import Geometry
import Dodge.Menu
--import Geometry.Data
menuScreen
:: Configuration
:: World
-> Configuration
-> Float -- Half width of screen
-> Float -- Half height of screen
-> [MenuLayer]
-> Picture
menuScreen cfig hw hh mLays = case mLays of
menuScreen w cfig hw hh mLays = case mLays of
(LevelMenu x:_) -> optionsList hw hh ("LEVEL"++show x) []
(PauseMenu:_) -> optionsList hw hh "PAUSED"
["N - NEW LEVEL"
,"R - RESTART"
,"O - OPTIONS"
,"C - CONTROLS"
]
(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"
]
(OptionMenu : _) -> optionsList hw hh "OPTIONS"
["V - VOLUME"
,"G - GRAPHICS"
]
(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
@@ -71,6 +76,27 @@ displayStringList hw hh ss = pictures
ys = [0,22..]
f y s = translate (10-hw) y . scale 0.15 0.15 $ text s
optionsFromList
:: World
-> Float -- ^ Half screen width
-> Float -- ^ Half screen height
-> String -- ^ Title
-> [MenuOption] -- ^ Options
-> Picture
optionsFromList w hw hh tit ops = pictures $
[darkenBackground
,theTitle]
++
zipWith (\ s vpos -> placeString (-hw + 50) vpos 0.2 s) (map (menuOptionToString w) ops') [hh-100,hh-150 ..]
where
ops' = filter notInvisible ops
notInvisible InvisibleToggle {} = False
notInvisible _ = True
placeString x y sc t = translate x y $ scale sc sc $ color white $ text t
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
optionsList
:: Float -- ^ Half screen width