From 45427a050e7da9f5c97fb9977fff4a2e6f66dcf3 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 29 Aug 2019 00:29:30 -0400 Subject: [PATCH] prompt user if game went into overtime when necessary --- src/Mtlstats/Events.hs | 11 +++++++++++ src/Mtlstats/UI.hs | 16 +++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Mtlstats/Events.hs b/src/Mtlstats/Events.hs index 3c591e9..6dfd6a8 100644 --- a/src/Mtlstats/Events.hs +++ b/src/Mtlstats/Events.hs @@ -24,6 +24,7 @@ along with this program. If not, see . module Mtlstats.Events (handleEvent) where import Control.Monad.Trans.State (gets, modify) +import Data.Char (toUpper) import Lens.Micro ((^.), (.~)) import Lens.Micro.Extras (view) import qualified UI.NCurses as C @@ -55,4 +56,14 @@ handleEvent e = gets (view progMode) >>= \case promptHandler awayScorePrompt e modify overtimeCheck return True + | null $ gs ^. overtimeFlag -> do + overtimePrompt e + >>= modify . (progMode.gameStateL.overtimeFlag .~) + return True | otherwise -> undefined + +overtimePrompt :: C.Event -> Action (Maybe Bool) +overtimePrompt (C.EventCharacter c) = case toUpper c of + 'Y' -> return (Just True) + 'N' -> return (Just False) + _ -> return Nothing diff --git a/src/Mtlstats/UI.hs b/src/Mtlstats/UI.hs index 95940f2..160ca5d 100644 --- a/src/Mtlstats/UI.hs +++ b/src/Mtlstats/UI.hs @@ -40,10 +40,16 @@ draw s = do MainMenu -> drawMenu mainMenu NewSeason -> drawMenu newSeasonMenu NewGame gs - | null $ gs ^. gameType -> drawMenu gameTypeMenu - | null $ gs ^. otherTeam -> drawPrompt otherTeamPrompt s - | null $ gs ^. homeScore -> drawPrompt homeScorePrompt s - | null $ gs ^. awayScore -> drawPrompt awayScorePrompt s - | otherwise -> undefined + | null $ gs^.gameType -> drawMenu gameTypeMenu + | null $ gs^.otherTeam -> drawPrompt otherTeamPrompt s + | null $ gs^.homeScore -> drawPrompt homeScorePrompt s + | null $ gs^.awayScore -> drawPrompt awayScorePrompt s + | null $ gs^.overtimeFlag -> overtimePrompt + | otherwise -> undefined C.render void $ C.setCursorMode cm + +overtimePrompt :: C.Update C.CursorMode +overtimePrompt = do + C.drawString "Did the game go into overtime? (Y/N)" + return C.CursorInvisible