From 7f4db06422cc5f967eb320b6255d0f5fab45954e Mon Sep 17 00:00:00 2001 From: Tristan de Cacqueray Date: Mon, 20 Jun 2022 19:16:44 +0000 Subject: [PATCH] Handle mouse click event for robot inventory (#448) This change makes inventory click select the inventory item. Fixes #446 --- src/Swarm/TUI/Controller.hs | 7 ++++++- src/Swarm/TUI/Model.hs | 4 +++- src/Swarm/TUI/View.hs | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Swarm/TUI/Controller.hs b/src/Swarm/TUI/Controller.hs index 9add43d8..e52da905 100644 --- a/src/Swarm/TUI/Controller.hs +++ b/src/Swarm/TUI/Controller.hs @@ -224,12 +224,17 @@ handleMainEvent s = \case continueWithoutRedraw s _ -> continueWithoutRedraw (s & uiState . uiWorldCursor .~ Nothing) MouseUp n _ _mouseLoc -> do - setFocus s $ case n of + let s' = + s & case n of + InventoryListItem pos -> uiState . uiInventory . traverse . _2 %~ BL.listMoveTo pos + _ -> id + setFocus s' $ case n of -- Adapt click event origin to their right panel. -- For the REPL and the World view, using 'Brick.Widgets.Core.clickable' correctly set the origin. -- However this does not seems to work for the robot and info panel. -- Thus we force the destination focus here. InventoryList -> RobotPanel + InventoryListItem _ -> RobotPanel InfoViewport -> InfoPanel _ -> n -- dispatch any other events to the focused panel handler diff --git a/src/Swarm/TUI/Model.hs b/src/Swarm/TUI/Model.hs index 9a66fd5d..876b81b5 100644 --- a/src/Swarm/TUI/Model.hs +++ b/src/Swarm/TUI/Model.hs @@ -176,13 +176,15 @@ data Name | -- | The list of inventory items for the currently -- focused robot. InventoryList + | -- | The inventory item position in the InventoryList. + InventoryListItem Int | -- | The list of main menu choices. MenuList | -- | The list of scenario choices. ScenarioList | -- | The scrollable viewport for the info panel. InfoViewport - deriving (Eq, Ord, Show, Read, Enum, Bounded) + deriving (Eq, Ord, Show, Read) infoScroll :: ViewportScroll Name infoScroll = viewportScroll InfoViewport diff --git a/src/Swarm/TUI/View.hs b/src/Swarm/TUI/View.hs index 2602e5a7..e7e9640b 100644 --- a/src/Swarm/TUI/View.hs +++ b/src/Swarm/TUI/View.hs @@ -500,6 +500,7 @@ drawRobotPanel :: AppState -> Widget Name drawRobotPanel s = case (s ^. gameState . to focusedRobot, s ^. uiState . uiInventory) of (Just r, Just (_, lst)) -> let V2 x y = r ^. robotLocation + drawClickableItem pos selb = clickable (InventoryListItem pos) . drawItem (lst ^. BL.listSelectedL) pos selb in padBottom Max $ vBox [ hCenter $ @@ -508,7 +509,7 @@ drawRobotPanel s = case (s ^. gameState . to focusedRobot, s ^. uiState . uiInve , padLeft (Pad 2) $ str (printf "(%d, %d)" x y) , padLeft (Pad 2) $ displayEntity (r ^. robotEntity) ] - , padAll 1 (BL.renderListWithIndex (drawItem (lst ^. BL.listSelectedL)) True lst) + , padAll 1 (BL.renderListWithIndex drawClickableItem True lst) ] _ -> padRight Max . padBottom Max $ str " "