@@ -34,7 +34,7 @@ import Brick.Widgets.Dialog
34
34
import Brick.Widgets.Edit (Editor , applyEdit , editContentsL , handleEditorEvent )
35
35
import Brick.Widgets.List (handleListEvent , listElements )
36
36
import Brick.Widgets.List qualified as BL
37
- import Brick.Widgets.TabularList.Mixed
37
+ import Brick.Widgets.TabularList.Grid qualified as BG
38
38
import Control.Applicative ((<|>) )
39
39
import Control.Category ((>>>) )
40
40
import Control.Lens as Lens
@@ -108,7 +108,7 @@ import Swarm.TUI.Model.StateUpdate
108
108
import Swarm.TUI.Model.UI
109
109
import Swarm.TUI.Model.UI.Gameplay
110
110
import Swarm.TUI.View.Popup (startPopupAnimation )
111
- import Swarm.TUI.View.Robot ( getList )
111
+ import Swarm.TUI.View.Robot
112
112
import Swarm.TUI.View.Robot.Type
113
113
import Swarm.Util hiding (both , (<<.=) )
114
114
@@ -296,8 +296,7 @@ handleNewGameMenuEvent scenarioStack@(curMenu :| rest) = \case
296
296
invalidateCache
297
297
let remaining = getScenariosAfterSelection curMenu pos
298
298
startGame (siPair :| remaining) Nothing
299
- SICollection _ c -> do
300
- uiState . uiMenu .= NewGameMenu (NE. cons (mkScenarioList c) scenarioStack)
299
+ SICollection _ c -> uiState . uiMenu .= NewGameMenu (NE. cons (mkScenarioList c) scenarioStack)
301
300
CharKey ' o' -> showLaunchDialog
302
301
CharKey ' O' -> showLaunchDialog
303
302
Key V. KEsc -> exitNewGameMenu scenarioStack
@@ -318,7 +317,7 @@ handleNewGameMenuEvent scenarioStack@(curMenu :| rest) = \case
318
317
exitNewGameMenu ::
319
318
NonEmpty (BL. List Name (ScenarioItem ScenarioPath )) ->
320
319
EventM Name AppState ()
321
- exitNewGameMenu stk = do
320
+ exitNewGameMenu stk =
322
321
uiState
323
322
. uiMenu
324
323
.= case snd (NE. uncons stk) of
@@ -445,7 +444,7 @@ closeModal m = do
445
444
safeAutoUnpause
446
445
uiGameplay . uiDialogs . uiModal .= Nothing
447
446
-- message modal is not autopaused, so update notifications when leaving it
448
- when (( m ^. modalType) == MidScenarioModal MessagesModal ) $ do
447
+ when (m ^. modalType == MidScenarioModal MessagesModal ) $ do
449
448
t <- use $ gameState . temporal . ticks
450
449
gameState . messageInfo . lastSeenMessageTime .= t
451
450
@@ -458,11 +457,11 @@ handleModalEvent = \case
458
457
Just (MidScenarioModal RobotsModal ) -> do
459
458
robotDialog <- use $ playState . scenarioState . uiGameplay . uiDialogs . uiRobot
460
459
unless (robotDialog ^. isDetailsOpened) $ do
461
- let widget = robotDialog ^. robotListContent . robotsListWidget
462
- forM_ ( BL. listSelectedElement $ getList widget) $ \ x -> do
463
- Brick. zoom (playState . scenarioState . uiGameplay . uiDialogs . uiRobot) $ do
464
- isDetailsOpened .= True
465
- updateRobotDetailsPane $ snd x
460
+ g <- use $ playState . scenarioState . gameState
461
+ let widget = robotDialog ^. robotsGridList
462
+ forM_ (getSelectedRobot g widget) $ \ rob -> Brick. zoom (playState . scenarioState . uiGameplay . uiDialogs . uiRobot) $ do
463
+ isDetailsOpened .= True
464
+ Brick. zoom robotDetailsPaneState $ updateRobotDetailsPane rob
466
465
_ -> do
467
466
menu <- use $ uiState . uiMenu
468
467
@@ -490,8 +489,7 @@ handleModalEvent = \case
490
489
case modal of
491
490
Just (MidScenarioModal TerrainPaletteModal ) ->
492
491
refreshList $ uiGameplay . uiWorldEditor . terrainList
493
- Just (MidScenarioModal EntityPaletteModal ) -> do
494
- refreshList $ uiGameplay . uiWorldEditor . entityPaintList
492
+ Just (MidScenarioModal EntityPaletteModal ) -> refreshList $ uiGameplay . uiWorldEditor . entityPaintList
495
493
Just (MidScenarioModal GoalModal ) -> case ev of
496
494
V. EvKey (V. KChar ' \t ' ) [] -> uiGameplay . uiDialogs . uiGoal . focus %= focusNext
497
495
_ -> do
@@ -514,19 +512,20 @@ handleModalEvent = \case
514
512
refreshList $ uiGameplay . uiDialogs . uiStructure . structurePanelListWidget
515
513
StructureSummary -> handleInfoPanelEvent modalScroll (VtyEvent ev)
516
514
_ -> handleInfoPanelEvent modalScroll (VtyEvent ev)
517
- Just (MidScenarioModal RobotsModal ) -> Brick. zoom (uiGameplay . uiDialogs . uiRobot) $ case ev of
518
- V. EvKey (V. KChar ' \t ' ) [] -> robotDetailsFocus %= focusNext
519
- _ -> do
520
- isInDetailsMode <- use isDetailsOpened
521
- if isInDetailsMode
522
- then Brick. zoom (robotListContent . robotDetailsPaneState . logsList) $ handleListEvent ev
523
- else do
524
- Brick. zoom (robotListContent . robotsListWidget) $
525
- handleMixedListEvent ev
526
-
527
- -- Ensure list widget content is updated immediately
528
- widget <- use $ robotListContent . robotsListWidget
529
- forM_ (BL. listSelectedElement $ getList widget) $ updateRobotDetailsPane . snd
515
+ Just (MidScenarioModal RobotsModal ) -> do
516
+ uiGame <- use uiGameplay
517
+ g <- use gameState
518
+ Brick. zoom (uiGameplay . uiDialogs . uiRobot) $ case ev of
519
+ V. EvKey (V. KChar ' \t ' ) [] -> robotDetailsPaneState . detailFocus %= focusNext
520
+ _ -> do
521
+ isInDetailsMode <- use isDetailsOpened
522
+ if isInDetailsMode
523
+ then Brick. zoom (robotDetailsPaneState . logsList) $ handleListEvent ev
524
+ else do
525
+ Brick. zoom robotsGridList $ BG. handleGridListEvent (robotGridRenderers uiGame g) ev
526
+ -- Ensure list widget content is updated immediately
527
+ mRob <- use $ robotsGridList . to (getSelectedRobot g)
528
+ forM_ mRob $ Brick. zoom robotDetailsPaneState . updateRobotDetailsPane
530
529
_ -> handleInfoPanelEvent modalScroll (VtyEvent ev)
531
530
where
532
531
refreshGoalList lw = nestEventM' lw $ handleListEventWithSeparators ev shouldSkipSelection
@@ -651,7 +650,7 @@ runBaseWebCode uinput ureply = do
651
650
if s ^. gameState . gameControls . replWorking
652
651
then liftIO . ureply $ Rejected AlreadyRunning
653
652
else do
654
- gameState . gameControls . replListener .= ( ureply . Complete . T. unpack)
653
+ gameState . gameControls . replListener .= ureply . Complete . T. unpack
655
654
runBaseCode uinput
656
655
>>= liftIO . ureply . \ case
657
656
Left err -> Rejected . ParseError $ T. unpack err
@@ -847,9 +846,7 @@ tabComplete CompletionContext {..} names em theRepl = case theRepl ^. replPrompt
847
846
FunctionName -> (possibleWords, isIdentChar)
848
847
849
848
possibleWords =
850
- names <> case ctxCreativeMode of
851
- True -> S. toList reservedWords
852
- False -> S. toList $ reservedWords `S.difference` creativeWords
849
+ names <> (if ctxCreativeMode then S. toList reservedWords else S. toList $ reservedWords `S.difference` creativeWords)
853
850
854
851
entityNames = M. keys $ entitiesByName em
855
852
@@ -904,7 +901,7 @@ adjReplHistIndex d s =
904
901
newREPL :: REPLState
905
902
newREPL = theRepl & replHistory %~ moveReplHistIndex d oldEntry
906
903
907
- saveLastEntry = replLast .~ ( theRepl ^. replPromptText)
904
+ saveLastEntry = replLast .~ theRepl ^. replPromptText
908
905
showNewEntry = (replPromptEditor .~ newREPLEditor newEntry) . (replPromptType .~ CmdPrompt [] )
909
906
-- get REPL data
910
907
getCurrEntry = fromMaybe (theRepl ^. replLast) . getCurrentItemText . view replHistory
0 commit comments