Allow mouse click interaction for nearby objects

This commit is contained in:
2025-01-02 00:32:45 +00:00
parent 3b60ad6023
commit 03b25565f1
4 changed files with 106 additions and 167 deletions
+7 -30
View File
@@ -5,6 +5,7 @@ module Dodge.Update.Input.InGame (
updateMouseInGame,
) where
import Dodge.SelectedClose
import Control.Applicative
import Control.Monad
import Data.Foldable
@@ -14,7 +15,6 @@ import Data.List (sort)
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Monoid
import Dodge.Button.Event
import Dodge.Camera
import Dodge.Creature.Action
import Dodge.Data.Combine
@@ -40,7 +40,7 @@ import SDL
updateUseInputInGame :: Universe -> Universe
updateUseInputInGame u = updateFunctionKeys $ case u ^. uvWorld . hud . hudElement of
-- DisplayCarte -> over uvWorld updatePressedButtonsCarte u
-- DisplayCarte -> over uvWorld updatePressedButtonsCarte u
DisplayInventory{_subInventory = si, _diSelection = disel} -> case si of
DisplayTerminal tmid -> updateKeysInTerminal tmid u
CombineInventory{_ciSections = sss, _ciSelection = msel@(Just (-1, _, _))} ->
@@ -437,7 +437,7 @@ updateInitialPressInGame uv sc = case sc of
ScancodeSpace -> over uvWorld spaceAction uv
ScancodeP -> pauseGame uv
ScancodeF -> over uvWorld youDropItem uv
-- ScancodeM -> toggleMap uv
-- ScancodeM -> toggleMap uv
ScancodeT -> over uvWorld testEvent uv
ScancodeC -> toggleCombineInv uv
-- the following should be put in a more sensible place
@@ -538,40 +538,17 @@ pauseGame u = u & uvScreenLayers .~ [pauseMenu u]
spaceAction :: World -> World
spaceAction w = case w ^. hud . hudElement of
-- DisplayCarte -> w & hud . carteCenter .~ theLoc
DisplayInventory{_subInventory = NoSubInventory{}} -> fromMaybe w $ do
cobj <- selCloseObj w
return $ case cobj of
(Left flit) ->
pickUpItem 0 flit w
& worldEventFlags . at InventoryChange ?~ ()
(Right but) ->
doButtonEvent (_btEvent but) but w
& worldEventFlags . at InventoryChange ?~ ()
DisplayInventory{_subInventory = NoSubInventory{}} ->
maybe id interactWithCloseObj (getCloseObj w) w
DisplayInventory{_subInventory = DisplayTerminal{}} ->
w
& hud . hudElement . subInventory .~ NoSubInventory
& worldEventFlags . at InventoryChange ?~ ()
_ -> w & hud . hudElement . subInventory .~ NoSubInventory
-- where
-- theLoc =
-- doWorldPos
-- (w ^?! cWorld . lWorld . seenLocations . ix (w ^. cWorld . lWorld . selLocation) . _1)
-- w
selCloseObj :: World -> Maybe (Either FloorItem Button)
selCloseObj w = selobj <|> firstcitem <|> firstcbut
getCloseObj :: World -> Maybe (Either FloorItem Button)
getCloseObj w = getSelectedCloseObj w <|> firstcitem <|> firstcbut
where
selobj = do
(i, j, _) <- w ^? hud . hudElement . diSelection . _Just
case i of
3 -> do
NInt k <- w ^? hud . closeItems . ix j
fmap Left $ w ^? cWorld . lWorld . floorItems . unNIntMap . ix k
5 -> do
k <- w ^? hud . closeButtons . ix j
fmap Right $ w ^? cWorld . lWorld . buttons . ix k
_ -> Nothing
firstcitem = do
k' <- (w ^? hud . hudElement . diSections . ix 3 . ssItems) >>= (fmap fst . IM.lookupMin)
NInt k <- w ^? hud . closeItems . ix k'