module UI.MainMenu (State (..), drawUI, handleEvent, theMap) where
import Brick
import Brick.Widgets.Border
import Brick.Widgets.Border.Style
import Brick.Widgets.Center
import Control.Monad.IO.Class
import Lens.Micro.Platform
import Runners
import Settings
import States
import StateManagement
import UI.Attributes
import UI.BrickHelpers
import qualified Graphics.Vty as V
import qualified Brick.Widgets.List as L
title :: Widget Name
title :: Widget Name
title = AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
withAttr AttrName
titleAttr (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
String -> Widget Name
forall n. String -> Widget n
str String
"┬ ┬┌─┐┌─┐┌─┐┌─┐┬─┐┌┬┐" Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<=>
String -> Widget Name
forall n. String -> Widget n
str String
"├─┤├─┤└─┐│ ├─┤├┬┘ ││" Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<=>
String -> Widget Name
forall n. String -> Widget n
str String
"┴ ┴┴ ┴└─┘└─┘┴ ┴┴└──┴┘"
drawUI :: MMS -> [Widget Name]
drawUI :: MMS -> [Widget Name]
drawUI MMS
s =
[ MMS -> Widget Name
drawMenu MMS
s ]
drawMenu :: MMS -> Widget Name
MMS
s =
Widget Name -> Widget Name
forall n. Widget n -> Widget n
joinBorders (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
Widget Name -> Widget Name
forall n. Widget n -> Widget n
center (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
BorderStyle -> Widget Name -> Widget Name
forall n. BorderStyle -> Widget n -> Widget n
withBorderStyle BorderStyle
unicodeRounded (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
Widget Name -> Widget Name
forall n. Widget n -> Widget n
border (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
Int -> Widget Name -> Widget Name
forall n. Int -> Widget n -> Widget n
hLimit Int
40 (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
Widget Name -> Widget Name
forall n. Widget n -> Widget n
hCenter Widget Name
title Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<=>
Widget Name
forall n. Widget n
hBorder Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<=>
MMS -> Widget Name
drawList MMS
s
drawList :: MMS -> Widget Name
drawList :: MMS -> Widget Name
drawList MMS
s = Int -> Widget Name -> Widget Name
forall n. Int -> Widget n -> Widget n
vLimit Int
4 (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
(Bool -> String -> Widget Name)
-> Bool -> List Name String -> Widget Name
forall (t :: * -> *) n e.
(Traversable t, Splittable t, Ord n, Show n) =>
(Bool -> e -> Widget n) -> Bool -> GenericList n t e -> Widget n
L.renderList Bool -> String -> Widget Name
drawListElement Bool
True (MMS
sMMS
-> Getting (List Name String) MMS (List Name String)
-> List Name String
forall s a. s -> Getting a s a -> a
^.Getting (List Name String) MMS (List Name String)
Lens' MMS (List Name String)
l)
drawListElement :: Bool -> String -> Widget Name
drawListElement :: Bool -> String -> Widget Name
drawListElement Bool
selected = (Widget Name -> Widget Name) -> String -> Widget Name
forall n. (Widget n -> Widget n) -> String -> Widget n
hCenteredStrWrapWithAttr Widget Name -> Widget Name
forall n. Widget n -> Widget n
attr
where attr :: Widget n -> Widget n
attr = if Bool
selected then AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withAttr AttrName
selectedAttr else Widget n -> Widget n
forall a. a -> a
id
handleEvent :: BrickEvent Name Event -> EventM Name GlobalState ()
handleEvent :: BrickEvent Name () -> EventM Name GlobalState ()
handleEvent (VtyEvent Event
e) = case Event
e of
V.EvKey Key
V.KEsc [] -> EventM Name GlobalState ()
forall n s. EventM n s ()
halt
V.EvKey (V.KChar Char
'q') [] -> EventM Name GlobalState ()
forall n s. EventM n s ()
halt
V.EvKey Key
V.KEnter [] -> do
List Name String
list <- Getting (List Name String) GlobalState (List Name String)
-> EventM Name GlobalState (List Name String)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((MMS -> Const (List Name String) MMS)
-> GlobalState -> Const (List Name String) GlobalState
Lens' GlobalState MMS
mms((MMS -> Const (List Name String) MMS)
-> GlobalState -> Const (List Name String) GlobalState)
-> Getting (List Name String) MMS (List Name String)
-> Getting (List Name String) GlobalState (List Name String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Getting (List Name String) MMS (List Name String)
Lens' MMS (List Name String)
l)
case List Name String -> Maybe Int
forall n (t :: * -> *) e. GenericList n t e -> Maybe Int
L.listSelected List Name String
list of
Just Int
0 -> State -> EventM Name GlobalState ()
forall (m :: * -> *). MonadState GlobalState m => State -> m ()
goToState (State -> EventM Name GlobalState ())
-> EventM Name GlobalState State -> EventM Name GlobalState ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO State -> EventM Name GlobalState State
forall a. IO a -> EventM Name GlobalState a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO State
cardSelectorState
Just Int
1 -> State -> EventM Name GlobalState ()
forall (m :: * -> *). MonadState GlobalState m => State -> m ()
goToState State
infoState
Just Int
2 -> State -> EventM Name GlobalState ()
forall (m :: * -> *). MonadState GlobalState m => State -> m ()
goToState (State -> EventM Name GlobalState ())
-> EventM Name GlobalState State -> EventM Name GlobalState ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO State -> EventM Name GlobalState State
forall a. IO a -> EventM Name GlobalState a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO State
settingsState
Just Int
3 -> EventM Name GlobalState ()
forall n s. EventM n s ()
halt
Maybe Int
_ -> EventM Name GlobalState ()
forall a. HasCallStack => a
undefined
Event
ev -> LensLike'
(Zoomed (EventM Name (List Name String)) ())
GlobalState
(List Name String)
-> EventM Name (List Name String) () -> EventM Name GlobalState ()
forall c.
LensLike'
(Zoomed (EventM Name (List Name String)) c)
GlobalState
(List Name String)
-> EventM Name (List Name String) c -> EventM Name GlobalState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom ((MMS -> Focusing (StateT (EventState Name) IO) () MMS)
-> GlobalState
-> Focusing (StateT (EventState Name) IO) () GlobalState
Lens' GlobalState MMS
mms((MMS -> Focusing (StateT (EventState Name) IO) () MMS)
-> GlobalState
-> Focusing (StateT (EventState Name) IO) () GlobalState)
-> ((List Name String
-> Focusing (StateT (EventState Name) IO) () (List Name String))
-> MMS -> Focusing (StateT (EventState Name) IO) () MMS)
-> (List Name String
-> Focusing (StateT (EventState Name) IO) () (List Name String))
-> GlobalState
-> Focusing (StateT (EventState Name) IO) () GlobalState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(List Name String
-> Focusing (StateT (EventState Name) IO) () (List Name String))
-> MMS -> Focusing (StateT (EventState Name) IO) () MMS
Lens' MMS (List Name String)
l) (EventM Name (List Name String) () -> EventM Name GlobalState ())
-> EventM Name (List Name String) () -> EventM Name GlobalState ()
forall a b. (a -> b) -> a -> b
$ (Event -> EventM Name (List Name String) ())
-> Event -> EventM Name (List Name String) ()
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
(Event -> EventM n (GenericList n t e) ())
-> Event -> EventM n (GenericList n t e) ()
L.handleListEventVi Event -> EventM Name (List Name String) ()
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
Event -> EventM n (GenericList n t e) ()
L.handleListEvent Event
ev
handleEvent BrickEvent Name ()
_ = () -> EventM Name GlobalState ()
forall a. a -> EventM Name GlobalState a
forall (m :: * -> *) a. Monad m => a -> m a
return ()