implement player edit menu

This commit is contained in:
Jonathan Lamothe 2019-11-01 05:24:18 -04:00
parent 5bb4e509b8
commit 0194f68996
3 changed files with 42 additions and 2 deletions

View File

@ -21,10 +21,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
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

View File

@ -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 )
]

View File

@ -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