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
import Control.Monad (void)
import Control.Monad.Extra (whenM)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.State (StateT, get)
@ -33,7 +34,10 @@ import Mtlstats.UI
-- | Initializes the progran
initState :: C.Curses ProgState
initState = return newProgState
initState = do
C.setEcho False
void $ C.setCursorMode C.CursorInvisible
return newProgState
-- | Main program loop
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
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 Mtlstats.Types
@ -31,4 +33,21 @@ handleEvent
:: C.Event
-- ^ The even being handled
-> 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 (
-- * Types
ProgState (..),
ProgMode (..),
Database (..),
Player (..),
PlayerStats (..),
@ -32,6 +33,7 @@ module Mtlstats.Types (
-- * Lenses
-- ** ProgState Lenses
database,
progMode,
-- ** Database Lenses
dbPlayers,
dbGoalies,
@ -86,10 +88,14 @@ import Lens.Micro ((^.))
import Lens.Micro.TH (makeLenses)
-- | Represents the program state
newtype ProgState = ProgState
data ProgState = ProgState
{ _database :: Database
, _progMode :: ProgMode
} deriving (Eq, Show)
-- | The program mode
data ProgMode = MainMenu | NewSeason deriving (Eq, Show)
-- | Represents the database
data Database = Database
{ _dbPlayers :: [Player]
@ -271,6 +277,7 @@ makeLenses ''GoalieStats
newProgState :: ProgState
newProgState = ProgState
{ _database = newDatabase
, _progMode = MainMenu
}
-- | 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
import Lens.Micro ((^.))
import qualified UI.NCurses as C
import Mtlstats.Types
-- | Drawing function
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 ()