refactored main menu
This commit is contained in:
parent
d6c51e6854
commit
7cffac245c
|
@ -27,6 +27,7 @@ import Lens.Micro.Extras (view)
|
|||
import qualified UI.NCurses as C
|
||||
|
||||
import Mtlstats.Actions
|
||||
import Mtlstats.Menu
|
||||
import Mtlstats.Types
|
||||
|
||||
-- | Event handler
|
||||
|
@ -37,18 +38,10 @@ handleEvent
|
|||
handleEvent e = do
|
||||
m <- gets $ view progMode
|
||||
case m of
|
||||
MainMenu -> mainMenu e
|
||||
MainMenu -> menuHandler mainMenu e
|
||||
NewSeason -> newSeason e >> return True
|
||||
NewGame -> newGame e >> return True
|
||||
|
||||
mainMenu :: C.Event -> StateT ProgState C.Curses Bool
|
||||
mainMenu (C.EventCharacter c) = case c of
|
||||
'1' -> modify startNewSeason >> return True
|
||||
'2' -> modify startNewGame >> return True
|
||||
'3' -> return False
|
||||
_ -> return True
|
||||
mainMenu _ = return True
|
||||
|
||||
newSeason :: C.Event -> StateT ProgState C.Curses ()
|
||||
newSeason (C.EventCharacter c) = case c of
|
||||
'1' -> modify $ resetYtd . startNewGame
|
||||
|
|
|
@ -20,14 +20,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
-}
|
||||
|
||||
module Mtlstats.Menu (
|
||||
-- * Menu Functions
|
||||
drawMenu,
|
||||
menuHandler,
|
||||
-- * Menus
|
||||
mainMenu
|
||||
) where
|
||||
|
||||
import Control.Monad.Trans.State (StateT)
|
||||
import Control.Monad.Trans.State (StateT, modify)
|
||||
import Lens.Micro ((^.))
|
||||
import qualified UI.NCurses as C
|
||||
|
||||
import Mtlstats.Actions
|
||||
import Mtlstats.Types
|
||||
import Mtlstats.Types.Menu
|
||||
|
||||
|
@ -42,3 +46,13 @@ menuHandler m (C.EventCharacter c) =
|
|||
i:_ -> i ^. miAction
|
||||
[] -> return $ m ^. menuDefault
|
||||
menuHandler m _ = return $ m ^. menuDefault
|
||||
|
||||
mainMenu :: Menu Bool
|
||||
mainMenu = Menu "*** MAIN MENU ***" True
|
||||
[ MenuItem '1' "New Season" $
|
||||
modify startNewSeason >> return True
|
||||
, MenuItem '2' "New Game" $
|
||||
modify startNewGame >> return True
|
||||
, MenuItem '3' "Exit" $
|
||||
return False
|
||||
]
|
||||
|
|
|
@ -24,6 +24,7 @@ module Mtlstats.UI (draw) where
|
|||
import Lens.Micro ((^.))
|
||||
import qualified UI.NCurses as C
|
||||
|
||||
import Mtlstats.Menu
|
||||
import Mtlstats.Types
|
||||
|
||||
-- | Drawing function
|
||||
|
@ -33,19 +34,11 @@ draw s = do
|
|||
C.updateWindow w $ do
|
||||
C.clear
|
||||
case s ^. progMode of
|
||||
MainMenu -> mainMenu
|
||||
MainMenu -> drawMenu mainMenu
|
||||
NewSeason -> newSeason
|
||||
NewGame -> newGame
|
||||
C.render
|
||||
|
||||
mainMenu :: C.Update ()
|
||||
mainMenu = C.drawString $ unlines
|
||||
[ "*** MAIN MENU ***"
|
||||
, "1) New Season"
|
||||
, "2) New Game"
|
||||
, "3) Exit"
|
||||
]
|
||||
|
||||
newSeason :: C.Update ()
|
||||
newSeason = C.drawString $ unlines
|
||||
[ "*** SEASON TYPE ***"
|
||||
|
|
Loading…
Reference in New Issue
Block a user