From 0194f6899678fbabe68e6b145b24d47dcf21460e Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 1 Nov 2019 05:24:18 -0400 Subject: [PATCH] implement player edit menu --- src/Mtlstats/Control/EditPlayer.hs | 18 +++++++++++++++++- src/Mtlstats/Menu.hs | 21 ++++++++++++++++++++- src/Mtlstats/Types.hs | 5 +++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/Mtlstats/Control/EditPlayer.hs b/src/Mtlstats/Control/EditPlayer.hs index 7255842..61404da 100644 --- a/src/Mtlstats/Control/EditPlayer.hs +++ b/src/Mtlstats/Control/EditPlayer.hs @@ -21,10 +21,14 @@ along with this program. If not, see . module Mtlstats.Control.EditPlayer (editPlayerC) where +import Data.Maybe (fromMaybe) import Lens.Micro ((^.)) +import qualified UI.NCurses as C +import Mtlstats.Menu import Mtlstats.Prompt import Mtlstats.Types +import Mtlstats.Util -- | Dispatcher/controller for the player edit mode editPlayerC :: EditPlayerState -> Controller @@ -51,7 +55,19 @@ selectPlayerC = Controller } menuC :: Controller -menuC = undefined +menuC = Controller + { drawController = \s -> do + let + header = fromMaybe "" $ do + pid <- s^.progMode.editPlayerStateL.epsSelectedPlayer + p <- nth pid $ s^.database.dbPlayers + Just $ playerDetails p ++ "\n" + C.drawString header + drawMenu editPlayerMenu + , handleController = \e -> do + menuHandler editPlayerMenu e + return True + } numberC :: Controller numberC = undefined diff --git a/src/Mtlstats/Menu.hs b/src/Mtlstats/Menu.hs index 96a8d6e..b365078 100644 --- a/src/Mtlstats/Menu.hs +++ b/src/Mtlstats/Menu.hs @@ -27,7 +27,8 @@ module Mtlstats.Menu ( mainMenu, newSeasonMenu, gameMonthMenu, - gameTypeMenu + gameTypeMenu, + editPlayerMenu ) where import Control.Monad.IO.Class (liftIO) @@ -123,3 +124,21 @@ gameTypeMenu = Menu "Game type:" () , MenuItem '2' "Away Game" $ modify $ progMode.gameStateL.gameType ?~ AwayGame ] + +-- | The player edit menu +editPlayerMenu :: Menu () +editPlayerMenu = Menu "*** EDIT PLAYER ***" () $ map + (\(ch, label, mode) -> MenuItem ch label $ case mode of + Nothing -> modify $ progMode .~ MainMenu + Just m -> modify $ progMode.editPlayerStateL.epsMode .~ m) + [ ( '1', "Change number", Just EPNumber ) + , ( '2', "Change name", Just EPName ) + , ( '3', "Change position", Just EPPosition ) + , ( '4', "YTD goals", Just EPYtdGoals ) + , ( '5', "YTD assists", Just EPYtdAssists ) + , ( '6', "YTD penalty mins", Just EPYtdPMin ) + , ( '7', "Lifetime goals", Just EPLtGoals ) + , ( '8', "Lifetime assists", Just EPLtAssists ) + , ( '9', "Lifetime penalty mins", Just EPLtPMin ) + , ( '0', "Finished editing", Nothing ) + ] diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index cdcd60d..54ce9bd 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -153,6 +153,7 @@ module Mtlstats.Types ( playerSearchExact, modifyPlayer, playerSummary, + playerDetails, playerIsActive, -- ** PlayerStats Helpers psPoints, @@ -860,6 +861,10 @@ playerSummary :: Player -> String playerSummary p = p^.pName ++ " (" ++ show (p^.pNumber) ++ ") " ++ p^.pPosition +-- | Provides a detailed string describing a 'Player' +playerDetails :: Player -> String +playerDetails = undefined + -- | Determines whether or not a player has been active in the current -- season/year playerIsActive :: Player -> Bool