Improve configuration handling
This commit is contained in:
@@ -57,9 +57,9 @@ handlePressedKeyInGame _ w = Just w
|
||||
handlePressedKey :: Bool -> Scancode -> World -> Maybe World
|
||||
handlePressedKey True _ w = Just w
|
||||
handlePressedKey _ scode w
|
||||
| _menuState w == InGame
|
||||
| _menuLayers w == []
|
||||
= handlePressedKeyInGame scode w
|
||||
| otherwise = handlePressedKeyInMenu (_menuState w) scode w
|
||||
| otherwise = handlePressedKeyInMenu (head $ _menuLayers w) scode w
|
||||
handlePressedKey _ _ w = Just w
|
||||
|
||||
debugKey :: Scancode -> World -> Maybe World
|
||||
@@ -70,7 +70,6 @@ debugKey scancode w
|
||||
| scancode == ScancodeF6 = Just $ dropLight' w
|
||||
debugKey _ w = Just w
|
||||
|
||||
|
||||
spaceAction :: World -> World
|
||||
spaceAction w = case listToMaybe $ _closeActiveObjects w of
|
||||
Just (Left flit) -> pickUpItem' flit w
|
||||
@@ -78,7 +77,7 @@ spaceAction w = case listToMaybe $ _closeActiveObjects w of
|
||||
Nothing -> w
|
||||
|
||||
pauseGame :: World -> World
|
||||
pauseGame w = w {_menuState = PauseMenu}
|
||||
pauseGame w = w {_menuLayers = [PauseMenu]}
|
||||
|
||||
toggleMap w = w & carteDisplay %~ not
|
||||
escapeMap w = w & carteDisplay .~ False
|
||||
|
||||
+19
-4
@@ -7,24 +7,25 @@ import Dodge.Rooms
|
||||
import Dodge.Floor
|
||||
import Dodge.Initialisation
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.LoadConfig
|
||||
|
||||
import Data.Maybe
|
||||
import qualified Data.Set as S
|
||||
|
||||
import Control.Lens
|
||||
|
||||
import SDL
|
||||
|
||||
handlePressedKeyInMenu :: MenuState -> Scancode -> World -> Maybe World
|
||||
handlePressedKeyInMenu :: MenuLayer -> Scancode -> World -> Maybe World
|
||||
handlePressedKeyInMenu mState scode w = case mState of
|
||||
LevelMenu _ -> case scode of
|
||||
ScancodeEscape -> Nothing
|
||||
ScancodeO -> goToOptionMenu w
|
||||
_ -> startLevel w
|
||||
PauseMenu -> case scode of
|
||||
ScancodeEscape -> Nothing
|
||||
ScancodeR -> return $ fromMaybe w $ _storedLevel w
|
||||
ScancodeN -> Just $ putSound $ generateLevel 1
|
||||
$ initialWorld {_randGen = _randGen w}
|
||||
ScancodeO -> goToOptionMenu w
|
||||
_ -> unpause w
|
||||
GameOverMenu -> case scode of
|
||||
ScancodeEscape -> Nothing
|
||||
@@ -32,13 +33,27 @@ handlePressedKeyInMenu mState scode w = case mState of
|
||||
ScancodeN -> Just $ putSound $ generateLevel 1
|
||||
$ initialWorld
|
||||
{_randGen = _randGen w}
|
||||
ScancodeO -> goToOptionMenu w
|
||||
_ -> Just w
|
||||
OptionMenu -> case scode of
|
||||
ScancodeY -> Just $ w & config . volume_master %~ dec
|
||||
ScancodeU -> Just $ w & config . volume_master %~ inc
|
||||
ScancodeH -> Just $ w & config . volume_sound %~ dec
|
||||
ScancodeJ -> Just $ w & config . volume_sound %~ inc
|
||||
ScancodeN -> Just $ w & config . volume_music %~ dec
|
||||
ScancodeM -> Just $ w & config . volume_music %~ inc
|
||||
_ -> Just $ w & menuLayers %~ (ConfigSaveScreen 1:) . tail
|
||||
& configNeedsUpdate .~ False
|
||||
_ -> Just w
|
||||
where
|
||||
unpause w' = Just . resumeSound $
|
||||
w' {_menuState = InGame}
|
||||
w' {_menuLayers = []}
|
||||
startLevel = unpause . storeLevel
|
||||
putSound = id -- set loadedSounds (_loadedSounds w)
|
||||
dec x = max 0 (x - 0.1)
|
||||
inc x = min 1 (x + 0.1)
|
||||
goToOptionMenu w = Just $ w & menuLayers %~ (OptionMenu :)
|
||||
& configNeedsUpdate .~ True
|
||||
|
||||
storeLevel :: World -> World
|
||||
storeLevel w = case _storedLevel w of
|
||||
|
||||
Reference in New Issue
Block a user