From 45aea607b2c10d0ca60f86449d5b0b537d5a566a Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Tue, 21 Jan 2020 22:20:01 -0500 Subject: [PATCH 1/6] added title screen logic branch --- src/Mtlstats/Control.hs | 2 ++ src/Mtlstats/Control/TitleScreen.hs | 27 +++++++++++++++++++++++++++ src/Mtlstats/Types.hs | 6 ++++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/Mtlstats/Control/TitleScreen.hs diff --git a/src/Mtlstats/Control.hs b/src/Mtlstats/Control.hs index b3016a1..b4964d6 100644 --- a/src/Mtlstats/Control.hs +++ b/src/Mtlstats/Control.hs @@ -29,6 +29,7 @@ import Lens.Micro.Extras (view) import qualified UI.NCurses as C import Mtlstats.Actions +import Mtlstats.Control.TitleScreen import Mtlstats.Control.EditGoalie import Mtlstats.Control.EditPlayer import Mtlstats.Control.EditStandings @@ -42,6 +43,7 @@ import Mtlstats.Types -- run dispatch :: ProgState -> Controller dispatch s = case s^.progMode of + TitleScreen -> titleScreenC MainMenu -> mainMenuC NewSeason flag -> newSeasonC flag NewGame gs -> newGameC gs diff --git a/src/Mtlstats/Control/TitleScreen.hs b/src/Mtlstats/Control/TitleScreen.hs new file mode 100644 index 0000000..1c958d5 --- /dev/null +++ b/src/Mtlstats/Control/TitleScreen.hs @@ -0,0 +1,27 @@ +{- | + +mtlstats +Copyright (C) 1984, 1985, 2019, 2020 Rhéal Lamothe + + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or (at +your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +-} + +module Mtlstats.Control.TitleScreen (titleScreenC) where + +import Mtlstats.Types + +titleScreenC :: Controller +titleScreenC = undefined diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 454d267..54c79db 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -236,7 +236,8 @@ data ProgState = ProgState -- | The program mode data ProgMode - = MainMenu + = TitleScreen + | MainMenu | NewSeason Bool | NewGame GameState | EditMenu @@ -247,6 +248,7 @@ data ProgMode | EditStandings EditStandingsMode instance Show ProgMode where + show TitleScreen = "TitleScreen" show MainMenu = "MainMenu" show (NewSeason _) = "NewSeason" show (NewGame _) = "NewGame" @@ -760,7 +762,7 @@ esmSubModeL = lens newProgState :: ProgState newProgState = ProgState { _database = newDatabase - , _progMode = MainMenu + , _progMode = TitleScreen , _inputBuffer = "" , _scrollOffset = 0 } From a9d4d3351f12bb303769374778a79f5c0bd5109f Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Tue, 21 Jan 2020 22:55:22 -0500 Subject: [PATCH 2/6] implemented title screen controller --- src/Mtlstats/Control/TitleScreen.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Mtlstats/Control/TitleScreen.hs b/src/Mtlstats/Control/TitleScreen.hs index 1c958d5..c764054 100644 --- a/src/Mtlstats/Control/TitleScreen.hs +++ b/src/Mtlstats/Control/TitleScreen.hs @@ -19,9 +19,23 @@ along with this program. If not, see . -} +{-# LANGUAGE LambdaCase #-} + module Mtlstats.Control.TitleScreen (titleScreenC) where +import Control.Monad.Trans.State (modify) +import qualified UI.NCurses as C + +import Mtlstats.Actions import Mtlstats.Types titleScreenC :: Controller -titleScreenC = undefined +titleScreenC = Controller + { drawController = const $ do + C.drawString "Press any key to continue..." + return C.CursorInvisible + , handleController = \case + C.EventCharacter _ -> modify backHome >> return True + C.EventSpecialKey _ -> modify backHome >> return True + _ -> return True + } From abad72ce01cf9ded5d31d28cc9de6d332514a6de Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 22 Jan 2020 00:39:06 -0500 Subject: [PATCH 3/6] built basic title screen --- src/Mtlstats/Control/TitleScreen.hs | 84 ++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/src/Mtlstats/Control/TitleScreen.hs b/src/Mtlstats/Control/TitleScreen.hs index c764054..3bc8ca6 100644 --- a/src/Mtlstats/Control/TitleScreen.hs +++ b/src/Mtlstats/Control/TitleScreen.hs @@ -24,6 +24,7 @@ along with this program. If not, see . module Mtlstats.Control.TitleScreen (titleScreenC) where import Control.Monad.Trans.State (modify) +import Data.Char (chr) import qualified UI.NCurses as C import Mtlstats.Actions @@ -32,10 +33,91 @@ import Mtlstats.Types titleScreenC :: Controller titleScreenC = Controller { drawController = const $ do - C.drawString "Press any key to continue..." + C.drawString titleText + C.drawString $ unlines + [ "" + , "Copyright (C) 1984, 1985, 2019, 2020 Rhéal Lamothe" + , "" + , "" + , "Press any key to continue..." + ] return C.CursorInvisible , handleController = \case C.EventCharacter _ -> modify backHome >> return True C.EventSpecialKey _ -> modify backHome >> return True _ -> return True } + +titleText :: String +titleText = map blockify $ unlines $ foldl joinBlocks (repeat "") + [chM, chT, chL, chS, chT, chA, chT, chS] + +blockify :: Char -> Char +blockify = \case + '#' -> chr 0x2588 + '>' -> chr 0x2590 + '<' -> chr 0x258c + ch -> ch + +joinBlocks :: [String] -> [String] -> [String] +joinBlocks = zipWith (++) + +chM :: [String] +chM = + [ "##< >##" + , ">## ##<" + , ">##< >##<" + , ">### ###<" + , ">#######<" + , ">#<###>#<" + , ">#<>#<>#<" + , "##< >##" + ] + +chT :: [String] +chT = + [ ">########<" + , ">## ## ##<" + , ">#< ## >#<" + , " ## " + , " ## " + , " ## " + , " ## " + , " >##< " + ] + +chL :: [String] +chL = + [ "### " + , ">#< " + , ">#< " + , ">#< " + , ">#< " + , ">#< ##" + , ">#< >##" + , "#######" + ] + +chS :: [String] +chS = + [ " #####< " + , ">#< ## " + , "## " + , " #####< " + , " >#<" + , " ##" + , ">#< >#<" + , " ###### " + ] + +chA :: [String] +chA = + [ " >##< " + , " ## " + , " >##< " + , " #### " + , " >#<>#< " + , " ###### " + , ">#< >#<" + , "### ###" + ] From 9c2e2291c8313c54677b0b239282112cf677b67b Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 22 Jan 2020 08:49:13 -0500 Subject: [PATCH 4/6] draw box around title --- src/Mtlstats/Control/TitleScreen.hs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Mtlstats/Control/TitleScreen.hs b/src/Mtlstats/Control/TitleScreen.hs index 3bc8ca6..22fcacf 100644 --- a/src/Mtlstats/Control/TitleScreen.hs +++ b/src/Mtlstats/Control/TitleScreen.hs @@ -33,8 +33,7 @@ import Mtlstats.Types titleScreenC :: Controller titleScreenC = Controller { drawController = const $ do - C.drawString titleText - C.drawString $ unlines + C.drawString $ unlines $ titleText ++ [ "" , "Copyright (C) 1984, 1985, 2019, 2020 Rhéal Lamothe" , "" @@ -48,10 +47,24 @@ titleScreenC = Controller _ -> return True } -titleText :: String -titleText = map blockify $ unlines $ foldl joinBlocks (repeat "") +titleText :: [String] +titleText = box $ map (map blockify) $ foldl joinBlocks (repeat "") [chM, chT, chL, chS, chT, chA, chT, chS] +box :: [String] -> [String] +box strs + = [[tl] ++ replicate width horiz ++ [tr]] + ++ map (\str -> [vert] ++ str ++ [vert]) strs + ++ [[bl] ++ replicate width horiz ++ [br]] + where + width = length $ head strs + tl = chr 0x2554 + tr = chr 0x2557 + bl = chr 0x255a + br = chr 0x255d + horiz = chr 0x2550 + vert = chr 0x2551 + blockify :: Char -> Char blockify = \case '#' -> chr 0x2588 From f2b2ff3fef4e835e6e44680ee67ac6a07dc039f5 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 22 Jan 2020 13:43:58 -0500 Subject: [PATCH 5/6] centred title screen --- src/Mtlstats/Control/TitleScreen.hs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Mtlstats/Control/TitleScreen.hs b/src/Mtlstats/Control/TitleScreen.hs index 22fcacf..938b6f7 100644 --- a/src/Mtlstats/Control/TitleScreen.hs +++ b/src/Mtlstats/Control/TitleScreen.hs @@ -28,18 +28,21 @@ import Data.Char (chr) import qualified UI.NCurses as C import Mtlstats.Actions +import Mtlstats.Format import Mtlstats.Types titleScreenC :: Controller titleScreenC = Controller { drawController = const $ do - C.drawString $ unlines $ titleText ++ - [ "" - , "Copyright (C) 1984, 1985, 2019, 2020 Rhéal Lamothe" - , "" - , "" - , "Press any key to continue..." - ] + (_, cols) <- C.windowSize + C.drawString $ unlines $ map (centre $ fromIntegral $ pred cols) + $ titleText + ++ [ "" + , "Copyright (C) 1984, 1985, 2019, 2020 Rhéal Lamothe" + , "" + , "" + , "Press any key to continue..." + ] return C.CursorInvisible , handleController = \case C.EventCharacter _ -> modify backHome >> return True From 179a864cfa5a6af0c546fa88458072b8b1bac1a6 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 22 Jan 2020 13:48:34 -0500 Subject: [PATCH 6/6] added header to title page --- src/Mtlstats/Control/TitleScreen.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Mtlstats/Control/TitleScreen.hs b/src/Mtlstats/Control/TitleScreen.hs index 938b6f7..d1a96cd 100644 --- a/src/Mtlstats/Control/TitleScreen.hs +++ b/src/Mtlstats/Control/TitleScreen.hs @@ -36,7 +36,10 @@ titleScreenC = Controller { drawController = const $ do (_, cols) <- C.windowSize C.drawString $ unlines $ map (centre $ fromIntegral $ pred cols) - $ titleText + $ [ "" + , "MONTREAL CANADIENS STATISTICS" + ] + ++ titleText ++ [ "" , "Copyright (C) 1984, 1985, 2019, 2020 Rhéal Lamothe" , ""