Refactor control list display

This commit is contained in:
2021-09-13 01:39:53 +01:00
parent d11d19c9e8
commit b27c174d93
6 changed files with 79 additions and 52 deletions
+1
View File
@@ -113,6 +113,7 @@ data ScreenLayer
, _scDefaultEff :: World -> Maybe World , _scDefaultEff :: World -> Maybe World
, _scOptionFlag :: OptionScreenFlag , _scOptionFlag :: OptionScreenFlag
} }
| ColumnsScreen String [(String,String)]
| InputScreen String | InputScreen String
| TerminalScreen Int [(Int,String)] | TerminalScreen Int [(Int,String)]
| WaitScreen | WaitScreen
+1 -3
View File
@@ -1,6 +1,4 @@
{- | {- | Deals with keyboard events. -}
Deals with keyboard events.
-}
module Dodge.Event.Keyboard module Dodge.Event.Keyboard
( handleKeyboardEvent ( handleKeyboardEvent
) )
+1
View File
@@ -15,6 +15,7 @@ handlePressedKeyInMenu mState scode = case mState of
OptionScreen { _scOptions = mos, _scDefaultEff = defeff} OptionScreen { _scOptions = mos, _scDefaultEff = defeff}
-> optionListToEffects mos defeff scode -> optionListToEffects mos defeff scode
DisplayScreen {} -> popScreen DisplayScreen {} -> popScreen
ColumnsScreen {} -> popScreen
WaitScreen {} -> Just WaitScreen {} -> Just
TerminalScreen 0 _ -> popScreen TerminalScreen 0 _ -> popScreen
TerminalScreen _ m -> Just . ( menuLayers %~ ( (TerminalScreen 0 m : ) . tail) ) TerminalScreen _ m -> Just . ( menuLayers %~ ( (TerminalScreen 0 m : ) . tail) )
+36 -43
View File
@@ -1,4 +1,10 @@
module Dodge.Menu module Dodge.Menu
( scodeToChar
, popScreen
, pushScreen
, pauseMenu
, gameOverMenu
)
where where
import Dodge.Data import Dodge.Data
import Dodge.Save import Dodge.Save
@@ -12,7 +18,7 @@ import Dodge.Initialisation
import Preload.Update import Preload.Update
import Dodge.Base.Window import Dodge.Base.Window
import Dodge.SoundLogic import Dodge.SoundLogic
import Picture --import Picture
import Control.Lens import Control.Lens
optionMenu :: ScreenLayer optionMenu :: ScreenLayer
@@ -28,12 +34,12 @@ optionsOptions =
, Toggle ScancodeG (pushScreen graphicsMenu) (const "GRAPHICS") , Toggle ScancodeG (pushScreen graphicsMenu) (const "GRAPHICS")
, Toggle ScancodeP (pushScreen gameplayOptionsMenu) (const "GAMEPLAY") , Toggle ScancodeP (pushScreen gameplayOptionsMenu) (const "GAMEPLAY")
] ]
levelMenuOptions :: [MenuOption] --levelMenuOptions :: [MenuOption]
levelMenuOptions = --levelMenuOptions =
[ InvisibleToggle ScancodeEscape (const Nothing) -- [ InvisibleToggle ScancodeEscape (const Nothing)
, InvisibleToggle ScancodeO (pushScreen optionMenu) -- , InvisibleToggle ScancodeO (pushScreen optionMenu)
, InvisibleToggle ScancodeC (pushScreen displayControls) -- , InvisibleToggle ScancodeC (pushScreen displayControls)
] -- ]
gameplayOptionsMenu :: ScreenLayer gameplayOptionsMenu :: ScreenLayer
gameplayOptionsMenu = OptionScreen gameplayOptionsMenu = OptionScreen
{ _scTitle = const "OPTIONS:GAMEPLAY" { _scTitle = const "OPTIONS:GAMEPLAY"
@@ -151,8 +157,8 @@ startNewGame w = Just $ w
scodeToChar :: Scancode -> Char scodeToChar :: Scancode -> Char
scodeToChar = toEnum . (+ 61) . fromIntegral . toNumber scodeToChar = toEnum . (+ 61) . fromIntegral . toNumber
charToScode :: Char -> Scancode --charToScode :: Char -> Scancode
charToScode = Scancode . fromIntegral . (\x -> x - 61) . fromEnum --charToScode = Scancode . fromIntegral . (\x -> x - 61) . fromEnum
updateFramebufferSize :: World -> World updateFramebufferSize :: World -> World
updateFramebufferSize w = w & sideEffects %~ up updateFramebufferSize w = w & sideEffects %~ up
@@ -164,43 +170,30 @@ updateFramebufferSize w = w & sideEffects %~ up
pdata <- pdataResizeUpdate (x `div` divRes) (y `div` divRes) x y (_preloadData w') pdata <- pdataResizeUpdate (x `div` divRes) (y `div` divRes) x y (_preloadData w')
f $ w' & preloadData .~ pdata f $ w' & preloadData .~ pdata
levelMenu :: Int -> ScreenLayer --levelMenu :: Int -> ScreenLayer
levelMenu x = OptionScreen --levelMenu x = OptionScreen
{ _scTitle = const $ "LEVEL "++ show x -- { _scTitle = const $ "LEVEL "++ show x
, _scOptions = levelMenuOptions -- , _scOptions = levelMenuOptions
, _scDefaultEff = unpause . storeLevel -- , _scDefaultEff = unpause . storeLevel
, _scOptionFlag = NormalOptions -- , _scOptionFlag = NormalOptions
} -- }
unpause :: World -> Maybe World unpause :: World -> Maybe World
unpause w = Just . resumeSound $ w {_menuLayers = []} unpause w = Just . resumeSound $ w {_menuLayers = []}
displayControls :: ScreenLayer displayControls :: ScreenLayer
displayControls = DisplayScreen displayControls = ColumnsScreen "CONTROLS" listControls
{_scDisplay = \w -> pictures
[color (withAlpha 0.5 black) $ polygon $ screenBox w
,tst (-100) 100 0.4 "CONTROLS"
,controlsList
]
}
where
tst x y sc t = translate x y $ scale sc sc $ color white $ text t
controlsList :: Picture listControls :: [(String,String)]
controlsList = pictures $ concat $ zipWith butAndEff listControls =
[("wasd", "movement") [("wasd", "MOVEMENT")
,("[rmb]", "aim") ,("[rmb]", "AIM")
,("[rmb+lmb]", "shoot or use item") ,("[rmb+lmb]", "SHOOT OR USE ITEM")
,("[wheelscroll]" , "select item" ) ,("[wheelscroll]" , "SELECT ITEM" )
,("[space]" , "pickup item" ) ,("[space]" , "PICKUP ITEM" )
,("m" , "display map" ) ,("m" , "DISPLAY MAP" )
,("f" , "drop item" ) ,("f" , "DROP ITEM" )
,("c[esc]" , "pause" ) ,("c[esc]" , "PAUSE" )
,("qe" , "rotate camera") ,("qe" , "ROTATE CAMERA")
,("F5" , "QUICKSAVE")
,("F9" , "QUICKLOAD")
] ]
[60,30..]
where
butAndEff (btext,etext) y =
[translate (-250) y $ scale 0.15 0.15 $ color white $ text btext
,translate 0 y $ scale 0.15 0.15 $ color white $ text etext
]
+34 -4
View File
@@ -11,6 +11,7 @@ import Dodge.Data
import Dodge.Base.Window import Dodge.Base.Window
import Picture import Picture
import Dodge.Menu import Dodge.Menu
import Padding
menuScreen menuScreen
:: World :: World
@@ -23,6 +24,7 @@ menuScreen w screen = case screen of
(InputScreen s) -> drawOptions w ('>':s) [] (InputScreen s) -> drawOptions w ('>':s) []
(TerminalScreen t xs ) -> displayStringList w $ map snd $ filter (( > t) . fst) xs (TerminalScreen t xs ) -> displayStringList w $ map snd $ filter (( > t) . fst) xs
(DisplayScreen sd ) -> sd w (DisplayScreen sd ) -> sd w
(ColumnsScreen title pairs) -> drawTwoColumnsScreen w title pairs
displayStringList :: World -> [String] -> Picture displayStringList :: World -> [String] -> Picture
displayStringList w ss = pictures displayStringList w ss = pictures
@@ -33,6 +35,26 @@ displayStringList w ss = pictures
hw = halfWidth w hw = halfWidth w
ys = [0,22..] ys = [0,22..]
f y s = translate (10-hw) y . scale 0.15 0.15 $ text s f y s = translate (10-hw) y . scale 0.15 0.15 $ text s
drawTwoColumnsScreen
:: World
-> String
-> [(String,String)]
-> Picture
drawTwoColumnsScreen w title lps = pictures
[darkenBackground w
,drawTitle w title
,drawTwoColumns w lps
]
drawTwoColumns :: World -> [(String,String)] -> Picture
drawTwoColumns w lps = pictures $ zipWith f [hh-100,hh-130..] lps
where
f y (s1,s2) = translate (50-hw) y $ sc $ rightPad ln '.' s1 ++ s2
sc = scale 0.15 0.15 . color white . text
hh = halfHeight w
hw = halfWidth w
ln = maximum (map (length . fst) lps) + 3
drawOptions drawOptions
:: World :: World
@@ -40,8 +62,8 @@ drawOptions
-> [MenuOption] -- ^ Options -> [MenuOption] -- ^ Options
-> Picture -> Picture
drawOptions w title ops = pictures $ drawOptions w title ops = pictures $
[darkenBackground [darkenBackground w
,theTitle] ,drawTitle w title]
++ ++
zipWith (\ s vpos -> placeString (-hw + 50) vpos 0.2 s) (map (menuOptionToString w) ops') [hh-100,hh-150 ..] zipWith (\ s vpos -> placeString (-hw + 50) vpos 0.2 s) (map (menuOptionToString w) ops') [hh-100,hh-150 ..]
where where
@@ -49,8 +71,16 @@ drawOptions w title ops = pictures $
notInvisible InvisibleToggle {} = False notInvisible InvisibleToggle {} = False
notInvisible _ = True notInvisible _ = True
placeString x y sc t = translate x y $ scale sc sc $ color white $ text t placeString x y sc t = translate x y $ scale sc sc $ color white $ text t
darkenBackground = color (withAlpha 0.5 black) $ polygon $ screenBox w hh = halfHeight w
theTitle = placeString (-hw + 30) (hh - 50) 0.4 title hw = halfWidth w
darkenBackground :: World -> Picture
darkenBackground = color (withAlpha 0.5 black) . polygon . screenBox
drawTitle :: World -> String -> Picture
drawTitle w = placeString (-hw + 30) (hh - 50) 0.4
where
placeString x y sc t = translate x y $ scale sc sc $ color white $ text t
hh = halfHeight w hh = halfHeight w
hw = halfWidth w hw = halfWidth w
+6 -2
View File
@@ -1,5 +1,9 @@
module Dodge.Save module Dodge.Save
where ( storeLevel
, loadStoredLevel
, doQuicksave
)
where
import Dodge.Data import Dodge.Data
import Data.Maybe import Data.Maybe
@@ -12,7 +16,7 @@ storeLevel w = case _storedLevel w of
_ -> w _ -> w
loadStoredLevel :: World -> World loadStoredLevel :: World -> World
loadStoredLevel w = fromMaybe w $ _storedLevel w loadStoredLevel w = fromMaybe w $ _storedLevel w <&> quicksaveLevel .~ _quicksaveLevel w
doQuicksave :: World -> World doQuicksave :: World -> World
doQuicksave w = w & quicksaveLevel ?~ clearKeys w doQuicksave w = w & quicksaveLevel ?~ clearKeys w