Allow to pick up item under cursor when in inventory

This commit is contained in:
2026-05-18 09:14:56 +01:00
parent 794d733c83
commit 3ee29f30f3
2 changed files with 11 additions and 0 deletions
+7
View File
@@ -1,15 +1,22 @@
module Dodge.SelectedClose (getSelectedCloseObj, interactWithCloseObj) where
import Dodge.Inventory
import Control.Lens
import Dodge.Button.Event
import Dodge.Data.World
import Dodge.Inventory.Add
import NewInt
import Data.Maybe
import qualified Data.Map.Strict as M
import qualified SDL
-- assumes that, for picking up, you are selecting the item
interactWithCloseObj :: Either (NewInt ItmInt) Button -> World -> World
interactWithCloseObj e w = worldEventFlags . at InventoryChange ?~ () $ case e of
(Left flit)
| SDL.ScancodeCapsLock `M.member` (w ^. input . pressedKeys)
, Just (Sel 0 j) <- w ^. hud . diSelection
-> scrollAugInvSel 1 $ pickUpItemAt j (i,_unNInt flit) w
(Left flit) -> pickUpItem i (_unNInt flit) w
(Right but) -> doButtonEvent (but ^. btEvent) but w
where
+4
View File
@@ -536,6 +536,10 @@ pauseGame u = u & uvScreenLayers .~ [pauseMenu u] & pauseSound
spaceAction :: World -> World
spaceAction w = case w ^. hud . subInventory of
NoSubInventory
| ScancodeCapsLock `M.member` (w ^. input . pressedKeys)
, Just (Sel 0 j) <- w ^. hud . diSelection
-> maybe id interactWithCloseObj (getCloseObj w) w
NoSubInventory -> maybe id interactWithCloseObj (getCloseObj w) w
_ -> w & hud . subInventory .~ NoSubInventory