Allow use of items while examine subinventory shows

Still not sure what to do with right click scrolling, item swapping
This commit is contained in:
2025-01-01 21:58:07 +00:00
parent ff5c4db3ae
commit adc0878a28
15 changed files with 343 additions and 311 deletions
+45 -45
View File
@@ -32,15 +32,15 @@ import Dodge.SoundLogic
import Dodge.Terminal
import Dodge.Update.Input.DebugTest
import Dodge.Update.Input.Text
import Dodge.WorldPos
import Geometry
--import Dodge.WorldPos
--import Geometry
import LensHelp
import NewInt
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, _, _))} ->
@@ -389,30 +389,30 @@ updateFunctionKey uv ScancodeF3 _ = doDebugTest uv
updateFunctionKey uv ScancodeF4 _ = doDebugTest2 uv
updateFunctionKey uv _ _ = uv
updatePressedButtonsCarte :: World -> World
updatePressedButtonsCarte w = updatePressedButtonsCarte' (_mouseButtons (_input w)) w
--updatePressedButtonsCarte :: World -> World
--updatePressedButtonsCarte w = updatePressedButtonsCarte' (_mouseButtons (_input w)) w
updatePressedButtonsCarte' :: M.Map MouseButton Int -> World -> World
updatePressedButtonsCarte' pkeys w
| isDown ButtonRight =
w & hud . carteCenter %~ (-.- trans)
| isDown ButtonLeft =
w
& hud . carteRot -~ rot
& hud . carteZoom *~ czoom
| otherwise = w
where
isDown but = but `M.member` pkeys
mbutpos but = theinput ^. heldPos . at but
rot = maybe 0 (angleBetween (_mousePos (_input w))) $ mbutpos SDL.ButtonLeft
czoom = fromMaybe 1 $ do
p <- mbutpos SDL.ButtonLeft
return $ magV (_mousePos theinput) / magV p
theinput = w ^. input
trans = fromMaybe 0 $ do
p <- mbutpos SDL.ButtonRight
return . rotateV (w ^. hud . carteRot) $
1 / (w ^. hud . carteZoom) *.* (_mousePos (_input w) -.- p)
--updatePressedButtonsCarte' :: M.Map MouseButton Int -> World -> World
--updatePressedButtonsCarte' pkeys w
-- | isDown ButtonRight =
-- w & hud . carteCenter %~ (-.- trans)
-- | isDown ButtonLeft =
-- w
-- & hud . carteRot -~ rot
-- & hud . carteZoom *~ czoom
-- | otherwise = w
-- where
-- isDown but = but `M.member` pkeys
-- mbutpos but = theinput ^. heldPos . at but
-- rot = maybe 0 (angleBetween (_mousePos (_input w))) $ mbutpos SDL.ButtonLeft
-- czoom = fromMaybe 1 $ do
-- p <- mbutpos SDL.ButtonLeft
-- return $ magV (_mousePos theinput) / magV p
-- theinput = w ^. input
-- trans = fromMaybe 0 $ do
-- p <- mbutpos SDL.ButtonRight
-- return . rotateV (w ^. hud . carteRot) $
-- 1 / (w ^. hud . carteZoom) *.* (_mousePos (_input w) -.- p)
updateKeysInTerminal :: Int -> Universe -> Universe
updateKeysInTerminal tmid u =
@@ -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,7 +538,7 @@ pauseGame u = u & uvScreenLayers .~ [pauseMenu u]
spaceAction :: World -> World
spaceAction w = case w ^. hud . hudElement of
DisplayCarte -> w & hud . carteCenter .~ theLoc
-- DisplayCarte -> w & hud . carteCenter .~ theLoc
DisplayInventory{_subInventory = NoSubInventory{}} -> fromMaybe w $ do
cobj <- selCloseObj w
return $ case cobj of
@@ -553,11 +553,11 @@ spaceAction w = case w ^. hud . hudElement of
& 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
-- 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
@@ -580,18 +580,18 @@ selCloseObj w = selobj <|> firstcitem <|> firstcbut
k <- w ^? hud . closeButtons . ix 0
fmap Right $ w ^? cWorld . lWorld . buttons . ix k
toggleMap :: Universe -> Universe
toggleMap u = case u ^. uvWorld . hud . hudElement of
DisplayCarte ->
u & uvWorld . hud . hudElement
.~ DisplayInventory
{ _subInventory = NoSubInventory
, _diSections = mempty
, _diSelection = Nothing
, _diInvFilter = mempty
, _diCloseFilter = mempty
}
_ -> u & uvWorld . hud . hudElement .~ DisplayCarte
--toggleMap :: Universe -> Universe
--toggleMap u = case u ^. uvWorld . hud . hudElement of
-- DisplayCarte ->
-- u & uvWorld . hud . hudElement
-- .~ DisplayInventory
-- { _subInventory = NoSubInventory
-- , _diSections = mempty
-- , _diSelection = Nothing
-- , _diInvFilter = mempty
-- , _diCloseFilter = mempty
-- }
-- _ -> u & uvWorld . hud . hudElement .~ DisplayCarte
tryCombine :: (Int, Int) -> World -> World
tryCombine (i, j) w = fromMaybe w $ do