From 0eb56cda81ff1a195bf9d91edd9e2f576dec139f Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Sat, 24 Aug 2019 19:02:29 -0400 Subject: [PATCH] implemented homeScorePrompt --- src/Mtlstats/Events.hs | 9 +++++++-- src/Mtlstats/Prompt.hs | 8 +++++++- src/Mtlstats/Types.hs | 12 ++++++++---- src/Mtlstats/UI.hs | 6 ++++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Mtlstats/Events.hs b/src/Mtlstats/Events.hs index bebbc02..602a8c9 100644 --- a/src/Mtlstats/Events.hs +++ b/src/Mtlstats/Events.hs @@ -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 diff --git a/src/Mtlstats/Prompt.hs b/src/Mtlstats/Prompt.hs index 822e8d8..a70eed9 100644 --- a/src/Mtlstats/Prompt.hs +++ b/src/Mtlstats/Prompt.hs @@ -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 ?~) diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 9dece99..2184303 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -38,6 +38,7 @@ module Mtlstats.Types ( -- ** ProgState Lenses database, progMode, + inputBuffer, -- ** GameState Lenses gameType, homeScore, @@ -110,10 +111,12 @@ type Action a = StateT ProgState Curses a -- | Represents the program state data ProgState = ProgState - { _database :: Database + { _database :: Database -- ^ The data to be saved - , _progMode :: ProgMode + , _progMode :: ProgMode -- ^ The program's mode + , _inputBuffer :: String + -- ^ Buffer for user input } deriving (Eq, Show) -- | The game state @@ -359,8 +362,9 @@ awayScoreL = lens -- | Constructor for a 'ProgState' newProgState :: ProgState newProgState = ProgState - { _database = newDatabase - , _progMode = MainMenu + { _database = newDatabase + , _progMode = MainMenu + , _inputBuffer = "" } -- | Constructor for a 'GameState' diff --git a/src/Mtlstats/UI.hs b/src/Mtlstats/UI.hs index 7e6ecc8..bf9de7c 100644 --- a/src/Mtlstats/UI.hs +++ b/src/Mtlstats/UI.hs @@ -26,6 +26,7 @@ import Lens.Micro ((^.)) import qualified UI.NCurses as C import Mtlstats.Menu +import Mtlstats.Prompt import Mtlstats.Types -- | Drawing function @@ -39,7 +40,8 @@ draw s = do MainMenu -> drawMenu mainMenu NewSeason -> drawMenu newSeasonMenu NewGame gs - | null $ gs ^. gameType -> drawMenu gameTypeMenu - | otherwise ->undefined + | null $ gs ^. gameType -> drawMenu gameTypeMenu + | null $ gs ^. homeScore -> drawPrompt homeScorePrompt s + | otherwise -> undefined C.render void $ C.setCursorMode cm