diff --git a/src/Mtlstats/Actions/GoalieInput.hs b/src/Mtlstats/Actions/GoalieInput.hs
index c8280a9..bef227f 100644
--- a/src/Mtlstats/Actions/GoalieInput.hs
+++ b/src/Mtlstats/Actions/GoalieInput.hs
@@ -22,6 +22,7 @@ along with this program. If not, see .
module Mtlstats.Actions.GoalieInput
( finishGoalieEntry
, recordGoalieStats
+ , setGameGoalie
) where
import qualified Data.Map as M
@@ -72,3 +73,11 @@ recordGoalieStats s = fromMaybe s $ do
& gYtd %~ bumpStats
& gLifetime %~ bumpStats)
& tryFinish
+
+-- | Records the win, loss, or tie to a specific 'Goalie'
+setGameGoalie
+ :: Int
+ -- ^ The goalie's index
+ -> ProgState
+ -> ProgState
+setGameGoalie = undefined
diff --git a/src/Mtlstats/Control.hs b/src/Mtlstats/Control.hs
index 412568c..1e45218 100644
--- a/src/Mtlstats/Control.hs
+++ b/src/Mtlstats/Control.hs
@@ -60,7 +60,7 @@ dispatch s = case s^.progMode of
| fromJust (unaccountedPoints gs) -> goalInput gs
| isJust $ gs^.gameSelectedPlayer -> getPMinsC
| not $ gs^.gamePMinsRecorded -> pMinPlayerC
- | not $ gs^.gameGoalieAssigned -> goalieInput gs
+ | not $ gs^.gameGoalieAssigned -> goalieInput s
| otherwise -> reportC
CreatePlayer cps
| null $ cps^.cpsNumber -> getPlayerNumC
diff --git a/src/Mtlstats/Control/GoalieInput.hs b/src/Mtlstats/Control/GoalieInput.hs
index 722a38a..2718c15 100644
--- a/src/Mtlstats/Control/GoalieInput.hs
+++ b/src/Mtlstats/Control/GoalieInput.hs
@@ -26,18 +26,23 @@ import Lens.Micro ((^.))
import qualified UI.NCurses as C
import Mtlstats.Format
+import Mtlstats.Menu
import Mtlstats.Prompt
import Mtlstats.Prompt.GoalieInput
import Mtlstats.Types
import Mtlstats.Util
-- | The dispatcher for handling goalie input
-goalieInput :: GameState -> Controller
-goalieInput gs
- | gs^.gameGoaliesRecorded = selectGameGoalieC
- | null $ gs^.gameSelectedGoalie = selectGoalieC
- | null $ gs^.gameGoalieMinsPlayed = minsPlayedC
- | otherwise = goalsAllowedC
+goalieInput :: ProgState -> Controller
+goalieInput s = let
+ gs = s^.progMode.gameStateL
+ in if gs^.gameGoaliesRecorded
+ then selectGameGoalieC s
+ else if null $ gs^.gameSelectedGoalie
+ then selectGoalieC
+ else if null $ gs^.gameGoalieMinsPlayed
+ then minsPlayedC
+ else goalsAllowedC
selectGoalieC :: Controller
selectGoalieC = promptController selectGameGoaliePrompt
@@ -48,8 +53,8 @@ minsPlayedC = promptControllerWith header goalieMinsPlayedPrompt
goalsAllowedC :: Controller
goalsAllowedC = promptControllerWith header goalsAllowedPrompt
-selectGameGoalieC :: Controller
-selectGameGoalieC = undefined
+selectGameGoalieC :: ProgState -> Controller
+selectGameGoalieC = menuController . gameGoalieMenu
header :: ProgState -> C.Update ()
header s = C.drawString $ unlines
diff --git a/src/Mtlstats/Menu.hs b/src/Mtlstats/Menu.hs
index b365078..0bce690 100644
--- a/src/Mtlstats/Menu.hs
+++ b/src/Mtlstats/Menu.hs
@@ -21,6 +21,7 @@ along with this program. If not, see .
module Mtlstats.Menu (
-- * Menu Functions
+ menuController,
drawMenu,
menuHandler,
-- * Menus
@@ -28,13 +29,16 @@ module Mtlstats.Menu (
newSeasonMenu,
gameMonthMenu,
gameTypeMenu,
- editPlayerMenu
+ editPlayerMenu,
+ gameGoalieMenu
) where
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.State (gets, modify)
import Data.Aeson (encodeFile)
import Data.Char (toUpper)
+import qualified Data.Map as M
+import Data.Maybe (mapMaybe)
import Lens.Micro ((^.), (.~), (?~))
import Lens.Micro.Extras (view)
import System.EasyFile
@@ -45,9 +49,20 @@ import System.EasyFile
import qualified UI.NCurses as C
import Mtlstats.Actions
+import qualified Mtlstats.Actions.GoalieInput as GI
import Mtlstats.Config
import Mtlstats.Types
import Mtlstats.Types.Menu
+import Mtlstats.Util
+
+-- | Generates a simple 'Controller' for a Menu
+menuController :: Menu () -> Controller
+menuController menu = Controller
+ { drawController = const $ drawMenu menu
+ , handleController = \e -> do
+ menuHandler menu e
+ return True
+ }
-- | The draw function for a 'Menu'
drawMenu :: Menu a -> C.Update C.CursorMode
@@ -142,3 +157,18 @@ editPlayerMenu = Menu "*** EDIT PLAYER ***" () $ map
, ( '9', "Lifetime penalty mins", Just EPLtPMin )
, ( '0', "Finished editing", Nothing )
]
+
+-- | Game goalie selection menu
+gameGoalieMenu :: ProgState -> Menu ()
+gameGoalieMenu s = let
+ title = "Which goalie should get credit for the game?"
+ gids = map fst $ M.toList $ s^.progMode.gameStateL.gameGoalieStats
+ goalies = mapMaybe
+ (\n -> do
+ goalie <- nth n $ s^.database.dbGoalies
+ Just (n, goalie))
+ gids
+ in Menu title () $ map
+ (\(ch, (gid, goalie)) -> MenuItem ch (goalieSummary goalie) $
+ modify $ GI.setGameGoalie gid) $
+ zip ['1'..] goalies