implemented main menu

This commit is contained in:
Jonathan Lamothe 2019-08-20 01:40:59 -04:00
parent 3fab328e17
commit 1662705e4d
4 changed files with 53 additions and 5 deletions

View File

@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats (initState, mainLoop) where module Mtlstats (initState, mainLoop) where
import Control.Monad (void)
import Control.Monad.Extra (whenM) import Control.Monad.Extra (whenM)
import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.State (StateT, get) import Control.Monad.Trans.State (StateT, get)
@ -33,7 +34,10 @@ import Mtlstats.UI
-- | Initializes the progran -- | Initializes the progran
initState :: C.Curses ProgState initState :: C.Curses ProgState
initState = return newProgState initState = do
C.setEcho False
void $ C.setCursorMode C.CursorInvisible
return newProgState
-- | Main program loop -- | Main program loop
mainLoop :: StateT ProgState C.Curses () mainLoop :: StateT ProgState C.Curses ()

View File

@ -21,7 +21,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Events (handleEvent) where module Mtlstats.Events (handleEvent) where
import Control.Monad.Trans.State (StateT) import Control.Monad.Trans.State (StateT, gets, modify)
import Lens.Micro ((.~))
import Lens.Micro.Extras (view)
import qualified UI.NCurses as C import qualified UI.NCurses as C
import Mtlstats.Types import Mtlstats.Types
@ -31,4 +33,21 @@ handleEvent
:: C.Event :: C.Event
-- ^ The even being handled -- ^ The even being handled
-> StateT ProgState C.Curses Bool -> StateT ProgState C.Curses Bool
handleEvent _ = return False handleEvent e = do
m <- gets $ view progMode
case m of
MainMenu -> mainMenu e
NewSeason -> newSeason e >> return False
mainMenu :: C.Event -> StateT ProgState C.Curses Bool
mainMenu (C.EventCharacter c) = case c of
'1' -> startNewSeason >> return True
'2' -> return False
_ -> return True
mainMenu _ = return True
newSeason :: C.Event -> StateT ProgState C.Curses ()
newSeason = undefined
startNewSeason :: StateT ProgState C.Curses ()
startNewSeason = modify $ progMode .~ NewSeason

View File

@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Types ( module Mtlstats.Types (
-- * Types -- * Types
ProgState (..), ProgState (..),
ProgMode (..),
Database (..), Database (..),
Player (..), Player (..),
PlayerStats (..), PlayerStats (..),
@ -32,6 +33,7 @@ module Mtlstats.Types (
-- * Lenses -- * Lenses
-- ** ProgState Lenses -- ** ProgState Lenses
database, database,
progMode,
-- ** Database Lenses -- ** Database Lenses
dbPlayers, dbPlayers,
dbGoalies, dbGoalies,
@ -86,10 +88,14 @@ import Lens.Micro ((^.))
import Lens.Micro.TH (makeLenses) import Lens.Micro.TH (makeLenses)
-- | Represents the program state -- | Represents the program state
newtype ProgState = ProgState data ProgState = ProgState
{ _database :: Database { _database :: Database
, _progMode :: ProgMode
} deriving (Eq, Show) } deriving (Eq, Show)
-- | The program mode
data ProgMode = MainMenu | NewSeason deriving (Eq, Show)
-- | Represents the database -- | Represents the database
data Database = Database data Database = Database
{ _dbPlayers :: [Player] { _dbPlayers :: [Player]
@ -271,6 +277,7 @@ makeLenses ''GoalieStats
newProgState :: ProgState newProgState :: ProgState
newProgState = ProgState newProgState = ProgState
{ _database = newDatabase { _database = newDatabase
, _progMode = MainMenu
} }
-- | Constructor for a 'Database' -- | Constructor for a 'Database'

View File

@ -21,10 +21,28 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.UI (draw) where module Mtlstats.UI (draw) where
import Lens.Micro ((^.))
import qualified UI.NCurses as C import qualified UI.NCurses as C
import Mtlstats.Types import Mtlstats.Types
-- | Drawing function -- | Drawing function
draw :: ProgState -> C.Curses () draw :: ProgState -> C.Curses ()
draw _ = return () draw s = do
w <- C.defaultWindow
C.updateWindow w $ do
C.clear
case s ^. progMode of
MainMenu -> mainMenu
NewSeason -> newSeason
C.render
mainMenu :: C.Update ()
mainMenu = C.drawString $ unlines
[ "*** MAIN MENU ***"
, "1) New Season"
, "2) Exit"
]
newSeason :: C.Update ()
newSeason = return ()