implemented homeScorePrompt

This commit is contained in:
Jonathan Lamothe 2019-08-24 19:02:29 -04:00
parent bd561bb7a8
commit 0eb56cda81
4 changed files with 26 additions and 9 deletions

View File

@ -30,6 +30,7 @@ import qualified UI.NCurses as C
import Mtlstats.Actions
import Mtlstats.Menu
import Mtlstats.Prompt
import Mtlstats.Types
-- | Event handler
@ -41,6 +42,10 @@ handleEvent e = gets (view progMode) >>= \case
MainMenu -> menuHandler mainMenu e
NewSeason -> menuHandler newSeasonMenu e >> return True
NewGame gs
| null $ gs ^. gameType ->
menuHandler gameTypeMenu e >> return True
| null $ gs ^. gameType -> do
menuHandler gameTypeMenu e
return True
| null $ gs ^. homeScore -> do
promptHandler homeScorePrompt e
return True
| otherwise -> undefined

View File

@ -23,7 +23,9 @@ module Mtlstats.Prompt (
-- * Prompt Functions
drawPrompt,
promptHandler,
numPrompt
numPrompt,
-- * Individual prompts
homeScorePrompt
) where
import Control.Monad (when)
@ -73,3 +75,7 @@ numPrompt pStr act = Prompt
, promptAction = \inStr -> forM_ (readMaybe inStr) act
, promptFunctionKey = const $ return ()
}
homeScorePrompt :: Prompt
homeScorePrompt = numPrompt "Home score: " $
modify . (progMode . homeScoreL ?~)

View File

@ -38,6 +38,7 @@ module Mtlstats.Types (
-- ** ProgState Lenses
database,
progMode,
inputBuffer,
-- ** GameState Lenses
gameType,
homeScore,
@ -114,6 +115,8 @@ data ProgState = ProgState
-- ^ The data to be saved
, _progMode :: ProgMode
-- ^ The program's mode
, _inputBuffer :: String
-- ^ Buffer for user input
} deriving (Eq, Show)
-- | The game state
@ -361,6 +364,7 @@ newProgState :: ProgState
newProgState = ProgState
{ _database = newDatabase
, _progMode = MainMenu
, _inputBuffer = ""
}
-- | Constructor for a 'GameState'

View File

@ -26,6 +26,7 @@ import Lens.Micro ((^.))
import qualified UI.NCurses as C
import Mtlstats.Menu
import Mtlstats.Prompt
import Mtlstats.Types
-- | Drawing function
@ -40,6 +41,7 @@ draw s = do
NewSeason -> drawMenu newSeasonMenu
NewGame gs
| null $ gs ^. gameType -> drawMenu gameTypeMenu
| null $ gs ^. homeScore -> drawPrompt homeScorePrompt s
| otherwise -> undefined
C.render
void $ C.setCursorMode cm