mirror of
https://github.com/swarm-game/swarm.git
synced 2024-10-27 10:04:12 +03:00
Handle mouse click event for robot inventory (#448)
This change makes inventory click select the inventory item. Fixes #446
This commit is contained in:
parent
8b8c16a71b
commit
7f4db06422
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 " "
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user