Fix equipment equipping/moving with right click

This commit is contained in:
2024-11-04 20:41:20 +00:00
parent 489ff21e12
commit 38ab6a35da
9 changed files with 124 additions and 118 deletions
+32 -27
View File
@@ -5,63 +5,67 @@ module Dodge.Creature.Impulse.UseItem (
useItemHotkey,
) where
import Dodge.Luse
import Dodge.SelectUse
import Dodge.Item.Grammar
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Control.Lens
import Control.Monad
import Data.Maybe
import Dodge.Cuse
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Dodge.Data.World
import Dodge.Euse
import Dodge.HeldUse
import Dodge.Hotkey
import Dodge.Inventory
import Dodge.Item.Grammar
import Dodge.Item.Location
import Dodge.Luse
import Dodge.SelectUse
import qualified IntMapHelp as IM
useRootItem :: Int -> World -> World
useRootItem crid w = fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix crid
itRef <- cr ^? crManipulation . manObject . imRootItem
it <- invRootTrees (_crInv cr) ^? ix itRef
return $
itemUseEffect' cr it w
& worldEventFlags . at InventoryChange ?~ ()
cr <- w ^? cWorld . lWorld . creatures . ix crid
itRef <- cr ^? crManipulation . manObject . imRootItem
it <- invRootTrees (_crInv cr) ^? ix itRef
return $
itemUseEffect' cr it w
& worldEventFlags . at InventoryChange ?~ ()
itemUseEffect' :: Creature -> LabelDoubleTree ItemLink ComposedItem -> World -> World
itemUseEffect' cr itmtree w = case itmtree ^. ldtValue . cItemFunction of
WeaponPlatformSF -> heldEffect (bimap _iatType _cItem itmtree) cr w
itemUseEffect' cr itmtree w = case itmtree ^. ldtValue . cItemFunction of
WeaponPlatformSF ->
heldEffect (bimap _iatType _cItem itmtree) cr w
& pointerToItem itm . itUse . heldHammer .~ HammerDown
EquipmentPlatformSF -> doequipmentchange
_ -> w
-- UseHotkey{} -> doequipmentchange
-- UseEquip{} -> doequipmentchange
-- (UseConsume eff) -> useC eff (_ldtValue itmtree) cr w
-- UseCraft{} -> w
-- UseAttach{} -> selectUse itmtree cr w
-- UseAmmoMag{} -> w
-- UseScope{} -> w
-- UseBulletMod{} -> w
where
-- UseHotkey{} -> doequipmentchange
-- UseEquip{} -> doequipmentchange
-- (UseConsume eff) -> useC eff (_ldtValue itmtree) cr w
-- UseCraft{} -> w
-- UseAttach{} -> selectUse itmtree cr w
-- UseAmmoMag{} -> w
-- UseScope{} -> w
-- UseBulletMod{} -> w
itm :: Item
itm = itmtree ^. ldtValue . cItem
-- doequipmentchange = fromMaybe w $ do
-- guard (_crHammerPosition cr == HammerUp)
-- invid <- itm ^? itLocation . ilInvID
-- return $ toggleEquipmentAt invid cr w
doequipmentchange = fromMaybe w $ do
guard (_crHammerPosition cr == HammerUp)
invid <- itm ^? itLocation . ilInvID
return $ toggleEquipmentAt invid cr w
itemUseEffect :: Creature -> LabelDoubleTree ComposeLinkType Item -> World -> World
itemUseEffect cr itmtree w = case itmtree ^. ldtValue . itUse of
UseHeld{} -> heldEffect itmtree cr w
UseHeld{} ->
heldEffect itmtree cr w
& pointerToItem itm . itUse . heldHammer .~ HammerDown
UseHotkey{} -> doequipmentchange
UseEquip{} -> doequipmentchange
(UseConsume eff) -> useC eff (_ldtValue itmtree) cr w
UseCraft{} -> w
UseAttach{} -> selectUse itmtree cr w
UseAttach{} -> selectUse itmtree cr w
UseAmmoMag{} -> w
UseScope{} -> w
UseBulletMod{} -> w
@@ -138,6 +142,7 @@ useItemLeftClick' cr' w = fromMaybe w $ do
return $
itemUseEffect cr it w
& worldEventFlags . at InventoryChange ?~ ()
-- & f
-- where
-- f = cWorld . lWorld . creatures . ix (_crID cr') . crHammerPosition .~ HammerDown
+1
View File
@@ -28,6 +28,7 @@ data ComposeLinkType
data ItemStructuralFunction
= WeaponPlatformSF
| EquipmentPlatformSF
| WeaponScopeSF
| WeaponTargetingSF
| AugmentedHUDSF
+2 -2
View File
@@ -200,10 +200,10 @@ locToTop loc = maybe loc locToTop $ locUp loc
--locToTop = fix $ \x -> fromMaybe x $ locUp x
locLeftmost :: LocationLDT b a -> LocationLDT b a
locLeftmost loc = maybe loc locLeftmost $ alaf Last foldMap Just $ locGoLeft loc
locLeftmost loc = maybe loc locLeftmost $ alaf First foldMap Just $ locGoLeft loc
locRightmost :: LocationLDT b a -> LocationLDT b a
locRightmost loc = maybe loc locRightmost $ alaf First foldMap Just $ locGoRight loc
locRightmost loc = maybe loc locRightmost $ alaf Last foldMap Just $ locGoRight loc
-- should probably do tests for these
locGoLeft :: LocationLDT b a -> [LocationLDT b a]
+2
View File
@@ -89,6 +89,8 @@ itemToFunction itm = case itm ^. itType of
BULLETMOD BulletModPayload{} -> AmmoPayloadSF BulletAmmo
BULLETMOD BulletModEffect{} -> AmmoEffectSF BulletAmmo
TARGETING{} -> WeaponTargetingSF
LEFT {} -> EquipmentPlatformSF
EQUIP {} -> EquipmentPlatformSF
_ -> UncomposableIsolateSF
pciToCI :: PartiallyComposedItem -> ComposedItem
+1
View File
@@ -11,6 +11,7 @@ import Dodge.Data.ComposedItem
itemInvColor :: ComposedItem -> Color
itemInvColor ci = case ci ^. cItemFunction of
WeaponPlatformSF -> white
EquipmentPlatformSF -> yellow
WeaponScopeSF -> chartreuse
WeaponTargetingSF -> green
AugmentedHUDSF -> rose
+1 -1
View File
@@ -91,7 +91,7 @@ drawRootCursor w sss msel ldp cfig = fromMaybe mempty $ do
inv <- w ^? cWorld . lWorld . creatures . ix 0 . crInv
(x,y) <- getRootItemBounds j inv
return $ drawSSMultiCursor sss (Just (0,x)) (Just (y- x)) ldp
(BoundaryCursor [minBound .. maxBound]) cfig
(BoundaryCursor [minBound ..]) cfig
getRootItemBounds :: Int -> IM.IntMap Item -> Maybe (Int,Int)
getRootItemBounds i inv = do
+6 -9
View File
@@ -36,11 +36,12 @@ updateUseInputInGame u = case u ^. uvWorld . hud . hudElement of
DisplayCarte -> over uvWorld updatePressedButtonsCarte u
DisplayInventory{_subInventory = si} -> case si of
DisplayTerminal tmid
| lbinitialpress && inTermFocus w ->
over uvWorld (doTerminalEffectLB (w ^?! cWorld . lWorld . terminals . ix tmid)) u
| lbinitialpress && inTermFocus w -> u & uvWorld
%~ doTerminalEffectLB (w ^?! cWorld . lWorld . terminals . ix tmid)
| inTermFocus (_uvWorld u) -> updateKeysInTerminal tmid u
| lbinitialpress ->
u & uvWorld . cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const True
u & uvWorld . cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus
%~ const True
CombineInventory{_ciSections = sss, _ciSelection = msel}
| lbinitialpress -> u & uvWorld %~ updateCombineInvClick msel sss
| inSubInvRegex (u ^. uvWorld) ->
@@ -48,15 +49,11 @@ updateUseInputInGame u = case u ^. uvWorld . hud . hudElement of
& uvWorld . hud . hudElement . subInventory
%~ docombineregexinput sss msel
& uvWorld . worldEventFlags . at CombineInventoryChange ?~ ()
_
| inInvRegex (u ^. uvWorld) ->
_ | inInvRegex (u ^. uvWorld) ->
u & uvWorld . hud . hudElement %~ dodisplayregexinput (-1)
-- . diSections %~ doRegexInput (u ^. uvWorld . input) (-1)
& uvWorld . worldEventFlags . at InventoryChange ?~ ()
& uvWorld %~ setInvPosFromSS
_
| inCloseRegex (u ^. uvWorld) ->
--u & uvWorld . hud . hudElement . diSections %~ doRegexInput (u ^. uvWorld . input) 2
_ | inCloseRegex (u ^. uvWorld) ->
u & uvWorld . hud . hudElement %~ dodisplayregexinput' 2
& uvWorld . worldEventFlags . at InventoryChange ?~ ()
& uvWorld %~ setInvPosFromSS