Skip to content

Commit

Permalink
Add "OK" modal
Browse files Browse the repository at this point in the history
  • Loading branch information
grancalavera committed Jan 11, 2019
1 parent 3436b7c commit 3773f42
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 2 additions & 4 deletions lib/Labyrinth/Store/Event/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Labyrinth.UI.Screen.Setup ( submitPlayer
, firstPlayer
)
import Labyrinth.UI.Widget ( playerAttr )
import Labyrinth.UI.Modal ( mkModal )
import Labyrinth.UI.Modal ( mkOkModal )
import qualified Labyrinth.Game.Configuration as Conf
import Labyrinth.Game.Configuration ( PlayOrder(..) )

Expand All @@ -47,14 +47,12 @@ play :: RegistrationEventHandler e
play s store _ = if hasEnoughPlayers s then start else continue store
where
start = maybe (continue store) promptToStart (firstPlayer s)
promptToStart p = showModal store $ mkModal
promptToStart p = showModal store $ mkOkModal
"start"
(txt "The next player is " <+> playerAttr
p
(padLeft (Pad 1) $ padRight (Pad 1) $ txt $ p ^. Conf.name)
)
(0, [("OK", True)])
halt
halt

processInput :: RegistrationEventHandler e
Expand Down
8 changes: 4 additions & 4 deletions lib/Labyrinth/Store/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Labyrinth.Store.Internal
)
where

import Data.Maybe (listToMaybe)
import Data.Maybe ( listToMaybe )
import Brick
import Lens.Micro.TH ( makeLenses )
import Lens.Micro ( (&)
Expand Down Expand Up @@ -46,8 +46,8 @@ showModal store m = continue $ store & modal %~ (m :)

hideModal :: Store e -> EventM Name (Next (Store e))
hideModal store = continue $ store & modal %~ \case
[] -> []
(_:ms) -> ms
[] -> []
(_ : ms) -> ms

nextModal :: Store e -> Maybe (Modal Store e)
nextModal = listToMaybe . (^.modal)
nextModal = listToMaybe . (^. modal)
4 changes: 4 additions & 0 deletions lib/Labyrinth/UI/Modal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Labyrinth.UI.Modal
, onTrue
, onFalse
, mkModal
, mkOkModal
)
where

Expand Down Expand Up @@ -57,3 +58,6 @@ mkModal desc body options onT onF = Modal
, _onFalse = onF
, _description = desc
}

mkOkModal :: String -> Widget Name -> ModalCallback s e -> Modal s e
mkOkModal desc body onOk = mkModal desc body (0, [("OK", True)]) onOk onOk

0 comments on commit 3773f42

Please sign in to comment.