Skip to content

Commit

Permalink
WIP UI controls
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Feb 19, 2023
1 parent f9acda0 commit dde6002
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/Swarm/Game/Scenario/Launch/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ handleLaunchOptionsEvent ::
BrickEvent Name AppEvent ->
EventM Name AppState ()
handleLaunchOptionsEvent siPair = \case
CharKey '\t' -> do
Key V.KBackTab ->
uiState . uiLaunchConfig . scenarioConfigFocusRing %= focusPrev
Key V.KUp ->
uiState . uiLaunchConfig . scenarioConfigFocusRing %= focusPrev
CharKey '\t' ->
uiState . uiLaunchConfig . scenarioConfigFocusRing %= focusNext
Key V.KDown ->
uiState . uiLaunchConfig . scenarioConfigFocusRing %= focusNext

Key V.KEnter -> do
fr <- use $ uiState . uiLaunchConfig . scenarioConfigFocusRing
case focusGetCurrent fr of
Expand Down Expand Up @@ -54,4 +61,8 @@ handleLaunchOptionsEvent siPair = \case
StartGameButton -> return ()
_ -> return ()
where
closeModal = uiState . uiLaunchConfig . isDisplayedFor .= Nothing
closeModal = do
fb <- use $ uiState . uiLaunchConfig . fileBrowser
if null fb
then uiState . uiLaunchConfig . isDisplayedFor .= Nothing
else uiState . uiLaunchConfig . fileBrowser .= Nothing
17 changes: 13 additions & 4 deletions src/Swarm/Game/Scenario/Launch/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ drawLaunchConfigPanel (LaunchOptions maybeFileBrowser seedEditor ring _isDisplay
Just (ScenarioConfigControl (ScenarioConfigPanelControl SeedSelector)) -> True
_ -> False

highlightIfFocused x = if focusGetCurrent ring == Just (ScenarioConfigControl (ScenarioConfigPanelControl x))
then withAttr highlightAttr
else id

mkButton name label = highlightIfFocused name $ str label

panelWidget =
centerLayer $
borderWithLabel (str "Configure scenario") $
hLimit 50 $
vBox
[ padAll 1 $ txt "Hello there!"
, overrideAttr E.editFocusedAttr customEditFocusedAttr $
renderEditor (txt . mconcat) seedEditorHasFocus seedEditor
, hCenter $ str "Select script"
, hCenter $ str "Launch"
, hBox [
mkButton SeedSelector "Seed: "
, overrideAttr E.editFocusedAttr customEditFocusedAttr $
renderEditor (txt . mconcat) seedEditorHasFocus seedEditor
]
, hCenter $ mkButton ScriptSelector ">> Select script <<"
, hCenter $ mkButton StartGameButton ">> Launch with these settings <<"
]

0 comments on commit dde6002

Please sign in to comment.