Cleanup menu code, fix reloading crash for nonweapons
This commit is contained in:
+10
-13
@@ -14,17 +14,15 @@ import Dodge.Inventory
|
|||||||
import Dodge.Menu
|
import Dodge.Menu
|
||||||
import Dodge.Reloading
|
import Dodge.Reloading
|
||||||
import Dodge.Save
|
import Dodge.Save
|
||||||
|
import LensHelp
|
||||||
|
|
||||||
import Control.Lens
|
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import SDL
|
import SDL
|
||||||
import Data.Text (unpack)
|
import Data.Text (unpack)
|
||||||
|
|
||||||
handleTextInputEvent :: TextInputEventData -> Universe -> IO (Maybe Universe)
|
handleTextInputEvent :: TextInputEventData -> Universe -> IO (Maybe Universe)
|
||||||
handleTextInputEvent tev = handleTextInput text
|
handleTextInputEvent = handleTextInput . unpack . textInputEventText
|
||||||
where
|
|
||||||
text = unpack $ textInputEventText tev
|
|
||||||
|
|
||||||
handleTextInput :: String -> Universe -> IO (Maybe Universe)
|
handleTextInput :: String -> Universe -> IO (Maybe Universe)
|
||||||
handleTextInput text w
|
handleTextInput text w
|
||||||
@@ -46,13 +44,12 @@ handleKeyboardEvent kev u = case keyboardEventKeyMotion kev of
|
|||||||
|
|
||||||
handlePressedKey :: Bool -> Scancode -> Universe -> IO (Maybe Universe)
|
handlePressedKey :: Bool -> Scancode -> Universe -> IO (Maybe Universe)
|
||||||
handlePressedKey True _ w = return $ Just w
|
handlePressedKey True _ w = return $ Just w
|
||||||
handlePressedKey _ ScancodeF5 w = return . Just $ doQuicksave w
|
handlePressedKey _ scode w = case scode of
|
||||||
handlePressedKey _ ScancodeF9 w = return . Just $ loadSaveSlot QuicksaveSlot w
|
ScancodeF5 -> return . Just $ doQuicksave w
|
||||||
handlePressedKey _ ScancodeSemicolon w = return . Just $ gotoTerminal w
|
ScancodeF9 -> return . Just $ loadSaveSlot QuicksaveSlot w
|
||||||
handlePressedKey _ scode w
|
ScancodeSemicolon -> return . Just $ gotoTerminal w
|
||||||
| null (_menuLayers w) = return $ uvWorld (handlePressedKeyInGame scode) w
|
_ | null (_menuLayers w) -> return $ uvWorld (handlePressedKeyInGame scode) w
|
||||||
| otherwise = handlePressedKeyInMenu (head $ _menuLayers w) scode w
|
_ -> handlePressedKeyInMenu (head $ _menuLayers w) scode w
|
||||||
-- | otherwise = return $ Just w
|
|
||||||
|
|
||||||
handlePressedKeyInGame :: Scancode -> World -> Maybe World
|
handlePressedKeyInGame :: Scancode -> World -> Maybe World
|
||||||
handlePressedKeyInGame scode w = case scode of
|
handlePressedKeyInGame scode w = case scode of
|
||||||
@@ -80,8 +77,8 @@ toggleInspectInv he = case he of
|
|||||||
|
|
||||||
gotoTerminal :: Universe -> Universe
|
gotoTerminal :: Universe -> Universe
|
||||||
gotoTerminal w = case _menuLayers w of
|
gotoTerminal w = case _menuLayers w of
|
||||||
(InputScreen _ _ : _ ) -> w
|
(InputScreen {} : _) -> w
|
||||||
_ -> w & menuLayers %~ (InputScreen [] "Enter command" :)
|
_ -> w & menuLayers .:~ InputScreen [] "Enter command"
|
||||||
|
|
||||||
spaceAction :: World -> World
|
spaceAction :: World -> World
|
||||||
spaceAction w = case _hudElement $ _hud w of
|
spaceAction w = case _hudElement $ _hud w of
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
module Dodge.Event.Menu
|
module Dodge.Event.Menu
|
||||||
( handlePressedKeyInMenu
|
( handlePressedKeyInMenu
|
||||||
, handleTextInMenu
|
, handleTextInMenu
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
import Dodge.Debug.Terminal
|
import Dodge.Debug.Terminal
|
||||||
--import Dodge.Menu
|
--import Dodge.Menu
|
||||||
@@ -25,7 +24,7 @@ handleTextInMenu mState text = return . Just . case mState of
|
|||||||
handlePressedKeyInMenu :: ScreenLayer -> Scancode -> Universe -> IO (Maybe Universe)
|
handlePressedKeyInMenu :: ScreenLayer -> Scancode -> Universe -> IO (Maybe Universe)
|
||||||
handlePressedKeyInMenu mState scode = case mState of
|
handlePressedKeyInMenu mState scode = case mState of
|
||||||
OptionScreen { _scOptions = mos, _scDefaultEff = defeff}
|
OptionScreen { _scOptions = mos, _scDefaultEff = defeff}
|
||||||
-> optionListToEffects mos defeff scode
|
-> optionListToEffects defeff scode mos
|
||||||
DisplayScreen {} -> popScreen
|
DisplayScreen {} -> popScreen
|
||||||
ColumnsScreen {} -> popScreen
|
ColumnsScreen {} -> popScreen
|
||||||
WaitScreen {} -> return . Just
|
WaitScreen {} -> return . Just
|
||||||
@@ -41,11 +40,15 @@ handlePressedKeyInMenu mState scode = case mState of
|
|||||||
doBackspace (x:xs) = init (x:xs)
|
doBackspace (x:xs) = init (x:xs)
|
||||||
doBackspace _ = ['>']
|
doBackspace _ = ['>']
|
||||||
|
|
||||||
optionListToEffects :: [MenuOption] -> (Universe -> IO (Maybe Universe)) -> Scancode
|
optionListToEffects
|
||||||
|
:: (Universe -> IO (Maybe Universe))
|
||||||
|
-> Scancode
|
||||||
|
-> [MenuOption]
|
||||||
-> Universe -> IO (Maybe Universe)
|
-> Universe -> IO (Maybe Universe)
|
||||||
optionListToEffects mos defaulteff sc = fromMaybe defaulteff
|
optionListToEffects defaulteff sc
|
||||||
|
= fromMaybe defaulteff
|
||||||
. lookup sc
|
. lookup sc
|
||||||
$ concatMap menuOptionToEffects mos
|
. concatMap menuOptionToEffects
|
||||||
|
|
||||||
menuOptionToEffects :: MenuOption -> [(Scancode,Universe -> IO (Maybe Universe))]
|
menuOptionToEffects :: MenuOption -> [(Scancode,Universe -> IO (Maybe Universe))]
|
||||||
menuOptionToEffects Toggle {_moKey = k, _moEff = eff} = [(k,eff)]
|
menuOptionToEffects Toggle {_moKey = k, _moEff = eff} = [(k,eff)]
|
||||||
|
|||||||
@@ -15,13 +15,15 @@ startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr)
|
|||||||
icTryStartReloading
|
icTryStartReloading
|
||||||
|
|
||||||
icTryStartReloading :: Item -> Maybe Item
|
icTryStartReloading :: Item -> Maybe Item
|
||||||
icTryStartReloading it
|
icTryStartReloading it = do
|
||||||
| _ammoLoaded am < _ammoBaseMax (_itConsumption it) && _reloadState am == Nothing'
|
am <- it ^? itConsumption
|
||||||
= Just $ it & itConsumption . reloadState .~ Just' (_reloadTime am)
|
amloaded <- am ^? ammoLoaded
|
||||||
|
ammax <- am ^? ammoBaseMax
|
||||||
|
rstate <- am ^? reloadState
|
||||||
|
if amloaded < ammax && rstate == Nothing'
|
||||||
|
then Just $ it & itConsumption . reloadState .~ Just' (_reloadTime am)
|
||||||
& if _reloadType am == ActiveClear then itConsumption . ammoLoaded .~ 0 else id
|
& if _reloadType am == ActiveClear then itConsumption . ammoLoaded .~ 0 else id
|
||||||
| otherwise = Nothing
|
else Nothing
|
||||||
where
|
|
||||||
am = _itConsumption it
|
|
||||||
|
|
||||||
crStopReloading :: Creature -> Creature
|
crStopReloading :: Creature -> Creature
|
||||||
crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . reloadState .~ Nothing'
|
crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . reloadState .~ Nothing'
|
||||||
|
|||||||
Reference in New Issue
Block a user