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