From f26d380c1b01b25eed80392d890e1d04389b8274 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 8 Nov 2023 18:39:38 +0000 Subject: [PATCH] Start implementing attachable scroll items --- src/Dodge/Base/You.hs | 10 +++++++ src/Dodge/Creature/Test.hs | 10 +++++++ src/Dodge/Creature/YourControl.hs | 3 +- src/Dodge/Data/Item/HeldScroll.hs | 21 ------------- src/Dodge/Data/Item/Scope.hs | 20 ++++++------- src/Dodge/Data/Item/Use.hs | 22 ++++++++++---- src/Dodge/Data/Item/Use/Consumption.hs | 2 ++ src/Dodge/Default/Item/Use.hs | 1 - src/Dodge/HeldScroll.hs | 22 +++++--------- src/Dodge/Inventory.hs | 14 ++++----- src/Dodge/Item/Ammo.hs | 2 +- src/Dodge/Item/Display.hs | 2 +- src/Dodge/Item/Held/Launcher.hs | 2 +- src/Dodge/Item/Held/Rod.hs | 12 ++++---- src/Dodge/Item/Held/Utility.hs | 12 ++++---- src/Dodge/Item/Weapon/Remote.hs | 13 +------- src/Dodge/Item/Weapon/TriggerType.hs | 12 ++++++-- src/Dodge/Projectile/Update.hs | 2 +- src/Dodge/Update/Camera.hs | 41 +++++++++++++------------- src/Dodge/Update/Scroll.hs | 12 +++++--- 20 files changed, 119 insertions(+), 116 deletions(-) delete mode 100644 src/Dodge/Data/Item/HeldScroll.hs diff --git a/src/Dodge/Base/You.hs b/src/Dodge/Base/You.hs index cdecca576..be3559485 100644 --- a/src/Dodge/Base/You.hs +++ b/src/Dodge/Base/You.hs @@ -1,8 +1,10 @@ module Dodge.Base.You where import Dodge.Data.World +import Dodge.HeldScroll import qualified IntMapHelp as IM import Control.Lens +import Control.Monad you :: World -> Creature you w = w ^?! cWorld . lWorld . creatures . ix 0 @@ -15,6 +17,14 @@ yourItem w = do i <- you w ^? crManipulation . manObject . inInventory . ispItem _crInv (you w) IM.!? i +yourScrollAttachment :: World -> Maybe (Int,ScrollAttachParams) +yourScrollAttachment w = do + i <- you w ^? crManipulation . manObject . inInventory . ispItem + itm <- _crInv (you w) IM.!? i + atparams <- you w ^? crInv . ix (i - 1) . itUse . attachParams . scrollAttachParams + guard (canHeldScrollAttach itm atparams) + return (i - 1, atparams) + yourInv :: World -> IM.IntMap Item yourInv = _crInv . you diff --git a/src/Dodge/Creature/Test.hs b/src/Dodge/Creature/Test.hs index 32a385bf0..9f93d892e 100644 --- a/src/Dodge/Creature/Test.hs +++ b/src/Dodge/Creature/Test.hs @@ -25,6 +25,7 @@ module Dodge.Creature.Test ( ) where --import MaybeHelp +--import Control.Applicative import Control.Lens import Data.List (find) import Data.Maybe @@ -46,6 +47,15 @@ crWeaponReady cr = fromMaybe False $ do AboveSource -> do x <- cr ^? crInv . ix (i - 1) . itUse . equipEffect . eeUse . euseAmmoAmount return (x > 0) + BelowSource -> do + x <- cr ^? crInv . ix (i + 1) . itUse . equipEffect . eeUse . euseAmmoAmount + return (x > 0) + EitherSource -> return $ + justIsPositive (cr ^? crInv . ix (i - 1) . itUse . equipEffect . eeUse . euseAmmoAmount) + || justIsPositive (cr ^? crInv . ix (i + 1) . itUse . equipEffect . eeUse . euseAmmoAmount) + where + justIsPositive Nothing = False + justIsPositive (Just x) = x > 0 crCanSeeCr :: Creature -> (World, Creature) -> Bool crCanSeeCr tcr (w, cr) = hasLOS (_crPos cr) (_crPos tcr) w diff --git a/src/Dodge/Creature/YourControl.hs b/src/Dodge/Creature/YourControl.hs index 5ef57c135..ecc3811b2 100644 --- a/src/Dodge/Creature/YourControl.hs +++ b/src/Dodge/Creature/YourControl.hs @@ -137,7 +137,8 @@ wasdWithAiming w speed cr (argV (_mousePos (_input w)) + (w ^. wCam . camRot)) $ do itRef <- cr ^? crManipulation . manObject . inInventory . ispItem - _ <- cr ^? crInv . ix itRef . itScope . scopePos +-- _ <- cr ^? crInv . ix itRef . itScope . scopePos + _ <- cr ^? crInv . ix itRef . itScope . remotePos return . argV $ mouseWorldPos (w ^. input) (w ^. wCam) -.- _crPos cr aimTurn :: Float -> Creature -> Creature diff --git a/src/Dodge/Data/Item/HeldScroll.hs b/src/Dodge/Data/Item/HeldScroll.hs deleted file mode 100644 index 0c8367aec..000000000 --- a/src/Dodge/Data/Item/HeldScroll.hs +++ /dev/null @@ -1,21 +0,0 @@ -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE StrictData #-} -{-# LANGUAGE TemplateHaskell #-} - -module Dodge.Data.Item.HeldScroll where - -import Control.Lens -import Data.Aeson -import Data.Aeson.TH -import qualified Data.Sequence as Seq - -data HeldScroll - = HeldScrollDoNothing - | HeldScrollZoom - | HeldScrollCharMode - {_hsCharMode :: Seq.Seq Char} - deriving (Eq, Ord, Show, Read) --Generic, Flat) - -makeLenses ''HeldScroll -deriveJSON defaultOptions ''HeldScroll diff --git a/src/Dodge/Data/Item/Scope.hs b/src/Dodge/Data/Item/Scope.hs index f8e2a63a4..8a8b599a5 100644 --- a/src/Dodge/Data/Item/Scope.hs +++ b/src/Dodge/Data/Item/Scope.hs @@ -14,18 +14,16 @@ data Scope = NoScope | RemoteScope { -- | a camera offset - _scopePos :: Point2 - , _scopeZoom :: Float - , -- | if the camera offset is also the center of vision - _scopeIsCamera :: Bool - } - | ZoomScope - { -- | a camera offset - _scopePos :: Point2 --- , _scopeZoomChange :: Int - , _scopeZoom :: Float - , _scopeDefaultZoom :: Float + _remotePos :: Point2 + , _remoteZoom :: Float } +-- | ZoomScope +-- { -- | a camera offset +-- _scopePos :: Point2 +---- , _scopeZoomChange :: Int +-- , _scopeZoom :: Float +-- , _scopeDefaultZoom :: Float +-- } deriving (Eq, Show, Read) --Generic, Flat) makeLenses ''Scope diff --git a/src/Dodge/Data/Item/Use.hs b/src/Dodge/Data/Item/Use.hs index ba357d3ed..412f721c1 100644 --- a/src/Dodge/Data/Item/Use.hs +++ b/src/Dodge/Data/Item/Use.hs @@ -7,19 +7,18 @@ module Dodge.Data.Item.Use ( module Dodge.Data.Item.Use, module Dodge.Data.Item.Use.Equipment, module Dodge.Data.Item.HeldUse, - module Dodge.Data.Item.HeldScroll, module Dodge.Data.Item.HeldDelay, module Dodge.Data.Item.Use.Consumption, module Dodge.Data.Hammer, module Dodge.Data.Item.Targeting, ) where -import Linear +import Geometry.Data import Control.Lens import Data.Aeson import Data.Aeson.TH +import qualified Data.Sequence as Seq import Dodge.Data.Hammer -import Dodge.Data.Item.HeldScroll import Dodge.Data.Item.HeldUse import Dodge.Data.Item.Use.Consumption import Dodge.Data.Item.Use.Equipment @@ -33,7 +32,6 @@ data ItemUse , _heldMods :: HeldMod , _heldHammer :: HammerPosition , _heldAim :: AimParams - , _heldScroll :: HeldScroll , _heldConsumption :: HeldConsumption -- , _useTargeting :: Maybe TargetType } @@ -59,9 +57,20 @@ data ItemUse --deriving (Eq, Show, Read) --Generic, Flat) data AttachParams - = ZoomScopeParams + = ScrollAttachParams {_scrollAttachParams :: ScrollAttachParams} | AmmoAttachParams +data ScrollAttachParams + = ZoomScrollParams + { -- | a camera offset + _opticPos :: Point2 +-- , _scopeZoomChange :: Int + , _opticZoom :: Float + , _opticDefaultZoom :: Float + } + | CharScrollParams + { _scrollChar :: Seq.Seq Char} + data ItemUse' = ItemHeld HeldUse' | ItemEquip EquipUse' @@ -110,8 +119,11 @@ makeLenses ''ItemUse makeLenses ''AimParams makeLenses ''ItZoom makeLenses ''Muzzle +makeLenses ''AttachParams +makeLenses ''ScrollAttachParams deriveJSON defaultOptions ''Muzzle deriveJSON defaultOptions ''AimStance +deriveJSON defaultOptions ''ScrollAttachParams deriveJSON defaultOptions ''AttachParams deriveJSON defaultOptions ''ItZoom deriveJSON defaultOptions ''AimParams diff --git a/src/Dodge/Data/Item/Use/Consumption.hs b/src/Dodge/Data/Item/Use/Consumption.hs index 95e13f008..dbebf05eb 100644 --- a/src/Dodge/Data/Item/Use/Consumption.hs +++ b/src/Dodge/Data/Item/Use/Consumption.hs @@ -29,6 +29,8 @@ data HeldConsumption data AmmoSource = InternalSource InternalAmmo | AboveSource + | BelowSource + | EitherSource deriving (Eq, Show, Read) --Generic, Flat) data ExternalSourceType = BulletClip diff --git a/src/Dodge/Default/Item/Use.hs b/src/Dodge/Default/Item/Use.hs index f86bf9246..a4a64da19 100644 --- a/src/Dodge/Default/Item/Use.hs +++ b/src/Dodge/Default/Item/Use.hs @@ -34,6 +34,5 @@ defaultHeldUse = , _heldMods = HeldModNothing , _heldHammer = HammerUp , _heldAim = defaultAimParams - , _heldScroll = HeldScrollDoNothing , _heldConsumption = defaultLoadable } diff --git a/src/Dodge/HeldScroll.hs b/src/Dodge/HeldScroll.hs index bd21fd4ad..944568a73 100644 --- a/src/Dodge/HeldScroll.hs +++ b/src/Dodge/HeldScroll.hs @@ -1,25 +1,16 @@ module Dodge.HeldScroll ( doHeldScroll, + canHeldScrollAttach, ) where ---import Dodge.Base.You import Control.Lens hiding ((<|), (|>)) import Data.Sequence -import Dodge.Data.Creature import Dodge.Data.World -import Data.Maybe ---import LensHelp hiding ((|>), (<|)) --- should be able to just import data.item -doHeldScroll :: HeldScroll -> Float -> Creature -> World -> World -doHeldScroll hs = case hs of - HeldScrollDoNothing -> const . const id - HeldScrollZoom -> const . const id - HeldScrollCharMode{} -> overYourItem $ \x _ -> itUse . heldScroll . hsCharMode %~ cycleSignum x - where - overYourItem f x cr w = fromMaybe w $ do - i <- cr ^? crManipulation . manObject . inInventory . ispItem - return $ w & cWorld . lWorld . creatures . ix 0 . crInv . ix i %~ f x cr +doHeldScroll :: Int -> ScrollAttachParams -> Float -> World -> World +doHeldScroll invid hs x w = case hs of + ZoomScrollParams{}-> w + CharScrollParams{} -> w & cWorld . lWorld . creatures . ix 0 . crInv . ix invid . itUse . attachParams . scrollAttachParams . scrollChar %~ cycleSignum x cycleSignum :: Float -> Seq a -> Seq a cycleSignum x @@ -31,3 +22,6 @@ cycleL (x :<| xs) = xs |> x cycleL xs = xs cycleR (xs :|> x) = x <| xs cycleR xs = xs + +canHeldScrollAttach :: Item -> ScrollAttachParams -> Bool +canHeldScrollAttach _ _ = True diff --git a/src/Dodge/Inventory.hs b/src/Dodge/Inventory.hs index e6b438668..971807d55 100644 --- a/src/Dodge/Inventory.hs +++ b/src/Dodge/Inventory.hs @@ -4,7 +4,7 @@ module Dodge.Inventory ( rmSelectedInvItem, rmInvItem, updateCloseObjects, - closeObjScrollDir, + --closeObjScrollDir, changeSwapSel, scrollAugInvSel, crNumFreeSlots, @@ -31,7 +31,7 @@ import Geometry import qualified IntMapHelp as IM import LensHelp import ListHelp -import Padding +--import Padding -- TODO check what happens to selection index when dropping non-selected items @@ -134,11 +134,11 @@ updateCloseObjects w = updatebyid (Right btid) = fmap Right $ w ^? cWorld . lWorld . buttons . ix (_btID btid) -closeObjScrollDir :: Float -> World -> World -closeObjScrollDir x - | x > 0 = over (hud . closeObjects) rotU - | x < 0 = over (hud . closeObjects) rotD - | otherwise = id +--closeObjScrollDir :: Float -> World -> World +--closeObjScrollDir x +-- | x > 0 = over (hud . closeObjects) rotU +-- | x < 0 = over (hud . closeObjects) rotD +-- | otherwise = id changeSwapSel :: Int -> World -> World changeSwapSel yi w diff --git a/src/Dodge/Item/Ammo.hs b/src/Dodge/Item/Ammo.hs index 92350829e..3b62ab83e 100644 --- a/src/Dodge/Item/Ammo.hs +++ b/src/Dodge/Item/Ammo.hs @@ -17,5 +17,5 @@ beltMag = tinMag & itType . iyBase .~ AMMO BULLETBELT zoomScope :: Item zoomScope = tinMag & itType . iyBase .~ ATTACH ZOOMSCOPE - & itUse .~ AttachUse ZoomScopeParams + & itUse .~ AttachUse (ScrollAttachParams (ZoomScrollParams {_opticPos = 0, _opticZoom = 1, _opticDefaultZoom = 0.5})) diff --git a/src/Dodge/Item/Display.hs b/src/Dodge/Item/Display.hs index 189f1e3b4..93131ea3c 100644 --- a/src/Dodge/Item/Display.hs +++ b/src/Dodge/Item/Display.hs @@ -155,7 +155,7 @@ showReloadProgress cr itm = case ic ^? laSource of Just (InternalSource ia) -> case ia ^? iaProgress . _Just . ix 0 of Nothing -> maybe "" show $ ic ^? laSource . _InternalSource . iaLoaded Just la -> showLoadActionType la (_laSource ic) - Just AboveSource -> fromMaybe "||||" $ do + Just AboveSource -> fromMaybe "^^^^" $ do i <- fmap (subtract 1) $ itm ^? itLocation . ipInvID _ <- cr ^? crInv . ix i . itUse . equipEffect . eeUse . euseAmmoAmount return "" diff --git a/src/Dodge/Item/Held/Launcher.hs b/src/Dodge/Item/Held/Launcher.hs index 1b2d438aa..aa01e9dd0 100644 --- a/src/Dodge/Item/Held/Launcher.hs +++ b/src/Dodge/Item/Held/Launcher.hs @@ -59,7 +59,7 @@ remoteLauncher = launcher & itType . iyBase .~ HELD REMOTELAUNCHER & itUse . heldUse .~ HeldFireRemoteShell --fireRemoteShell - & itScope .~ RemoteScope (V2 0 0) 1 True + & itScope .~ RemoteScope (V2 0 0) 1 & itUse . heldConsumption . laAmmoType . amPjDraw .~ DrawRemoteShell basicAmPjMoves :: IM.IntMap TweakParam diff --git a/src/Dodge/Item/Held/Rod.hs b/src/Dodge/Item/Held/Rod.hs index 14d0d73d9..bd40ab2da 100644 --- a/src/Dodge/Item/Held/Rod.hs +++ b/src/Dodge/Item/Held/Rod.hs @@ -68,12 +68,12 @@ sniperRifle = & itType . iyBase .~ HELD SNIPERRIFLE & itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0 & itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5,_izFac = 1} - & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun - & itScope .~ ZoomScope - { _scopePos = (V2 0 0) - , _scopeZoom = 1 - , _scopeDefaultZoom = 0.5 - } +-- & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun +-- & itScope .~ ZoomScope +-- { _scopePos = (V2 0 0) +-- , _scopeZoom = 1 +-- , _scopeDefaultZoom = 0.5 +-- } & itType . iyModules . at ModTarget ?~ TARGET TargetLaser -- & itUse . useTargeting ?~ TargetLaser diff --git a/src/Dodge/Item/Held/Utility.hs b/src/Dodge/Item/Held/Utility.hs index 1aaaa0875..38e13460c 100644 --- a/src/Dodge/Item/Held/Utility.hs +++ b/src/Dodge/Item/Held/Utility.hs @@ -26,16 +26,16 @@ latchkey _ = defaultHeldItem binoculars :: Item binoculars = defaultHeldItem - & itScope .~ ZoomScope - { _scopePos = (V2 0 0) - , _scopeZoom = 1 - , _scopeDefaultZoom = 0.5 - } +-- & itScope .~ ZoomScope +-- { _scopePos = (V2 0 0) +-- , _scopeZoom = 1 +-- , _scopeDefaultZoom = 0.5 +-- } & itType . iyBase .~ HELD BINOCULARS -- & itUse . heldAim . aimHandlePos .~ 5 -- & itUse . heldAim . aimMuzPos .~ 10 & itUse . heldAim . aimStance .~ TwoHandFlat - & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun +-- & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun & itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5, _izFac = 1} diff --git a/src/Dodge/Item/Weapon/Remote.hs b/src/Dodge/Item/Weapon/Remote.hs index 16c7635fe..fa7d277d9 100644 --- a/src/Dodge/Item/Weapon/Remote.hs +++ b/src/Dodge/Item/Weapon/Remote.hs @@ -1,6 +1,5 @@ module Dodge.Item.Weapon.Remote ( setRemoteScope, - setRemoteBombScope, ) where import Control.Lens @@ -8,22 +7,12 @@ import Dodge.Data.World import Dodge.Default import Geometry -setRemoteBombScope :: Int -> Prop -> World -> World -setRemoteBombScope itid pj w = case w ^?! cWorld . lWorld . itemLocations . ix itid of - InInv cid invid -> - w - & cWorld . lWorld . creatures . ix cid . crInv . ix invid . itScope - . scopePos - .~ (_prPos pj -.- (w ^?! cWorld . lWorld . creatures . ix cid . crPos)) - & cWorld . lWorld . creatures . ix cid . crInv . ix invid . itUse . heldAim . aimZoom - .~ (defaultItZoom{_izMax = 0.5, _izMin = 0.5}) - _ -> w setRemoteScope :: Int -> Point2 -> World -> World setRemoteScope itid pos w = case w ^? cWorld . lWorld . itemLocations . ix itid of Just (InInv cid' invid) -> w & cWorld . lWorld . creatures . ix cid' . crInv . ix invid . itScope - . scopePos + . remotePos .~ (pos -.- (w ^?! cWorld . lWorld . creatures . ix cid' . crPos)) _ -> w diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 72abc8eb7..9f727cb37 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -361,7 +361,7 @@ useAmmoUpTo amAmount eff item cr = useAmmoAmount :: Int -> ChainEffect useAmmoAmount amAmount eff item cr = eff item cr - . (cWorld . lWorld . creatures . ix (_crID cr) . crInv %~ useAmmoAmount' itref amAmount) -- . _InternalSource . iaLoaded -~ amAmount) + . (cWorld . lWorld . creatures . ix (_crID cr) . crInv %~ useAmmoAmount' itref amAmount) where itref = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change @@ -371,6 +371,12 @@ useAmmoAmount' itref x inv = case inv ^? ix itref . itUse . heldConsumption . la inv & ix itref . itUse . heldConsumption . laSource . _InternalSource . iaLoaded -~ x Just AboveSource -> inv & ix (itref - 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x + Just BelowSource -> + inv & ix (itref + 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x + Just EitherSource -> case inv ^? ix (itref - 1) . itUse . equipEffect . eeUse . euseAmmoAmount of + Just amamount | amamount > 0 -> + inv & ix (itref - 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x + _ -> inv & ix (itref + 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x _ -> inv -- . crInv . ix itRef . itUse . heldConsumption . laSource @@ -615,8 +621,8 @@ withTorqueAfter feff item cr w (rot, g) = randomR (- torque, torque) $ _randGen w torque = fromMaybe 0 $ item ^? itParams . torqueAfter - --rotateScope = cWorld . lWorld . creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0)) - rotateScope = pointerYourItem . itScope . scopePos %~ rotateV rot + rotateScope = id +-- rotateScope = pointerYourItem . itScope . scopePos %~ rotateV rot sideEffectOnFrame :: Int -> diff --git a/src/Dodge/Projectile/Update.hs b/src/Dodge/Projectile/Update.hs index d8fc52d9c..ba4e46141 100644 --- a/src/Dodge/Projectile/Update.hs +++ b/src/Dodge/Projectile/Update.hs @@ -83,7 +83,7 @@ retireRemoteProj :: Int -> Int -> World -> World retireRemoteProj itid pjid w = w & pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix itid) - %~ ( (itScope . scopePos .~ V2 0 0) + %~ ( (itScope . remotePos .~ V2 0 0) . (itUse . heldUse .~ HeldFireRemoteShell) ) & cWorld . lWorld . props %~ IM.delete pjid diff --git a/src/Dodge/Update/Camera.hs b/src/Dodge/Update/Camera.hs index b013b5533..31eca8bf6 100644 --- a/src/Dodge/Update/Camera.hs +++ b/src/Dodge/Update/Camera.hs @@ -93,23 +93,21 @@ moveZoomCamera cfig theinput cr campos = cr ^? crInv . ix i newvf = cpos +.+ fromMaybe (V2 0 0) vfoffset vfoffset = do - iscam <- mitm ^? _Just . itScope . scopeIsCamera - guard iscam guard (SDL.ButtonRight `M.member` _mouseButtons theinput) - mitm ^? _Just . itScope . scopePos + mitm ^? _Just . itScope . remotePos mscopeoffset = do guard (SDL.ButtonRight `M.member` _mouseButtons theinput) - mitm ^? _Just . itScope . scopePos + mitm ^? _Just . itScope . remotePos newcen = cpos +.+ fromMaybe (V2 0 0) mscopeoffset +.+ offset offset = rotateV (campos ^. camRot) $ ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos theinput newzoom = case mitm ^? _Just . itScope of - Just zs@ZoomScope{} -> _scopeZoom zs +-- Just zs@ZoomScope{} -> _scopeZoom zs _ -> newDefaultZoom * newItemZoom idealDefaultZoom = clipZoom wallZoom newDefaultZoom = case mitm ^? _Just . itScope of - Just zs@ZoomScope{} -> _scopeZoom zs +-- Just zs@ZoomScope{} -> _scopeZoom zs _ -> changeZoom (campos ^. camDefaultZoom) idealDefaultZoom idealItemZoom = fromMaybe 1 $ do guard $ crIsAiming cr @@ -140,13 +138,12 @@ updateScopeZoom' i w w & wppointer %~ doScopeZoom (w ^. input . smoothScrollAmount) mp | otherwise = w & wppointer %~ resetscope where - wppointer = cWorld . lWorld . creatures . ix 0 . crInv . ix i . itScope - --resetscope (ZoomScope _ _ defz bl) = ZoomScope (V2 0 0) defz defz bl - resetscope (ZoomScope _ _ defz) = ZoomScope (V2 0 0) defz defz + wppointer = cWorld . lWorld . creatures . ix 0 . crInv . ix (i - 1) . itUse . attachParams . scrollAttachParams + resetscope (ZoomScrollParams _ _ defz) = ZoomScrollParams (V2 0 0) defz defz resetscope otherAtt = otherAtt mp = rotateV (w ^. wCam . camRot) $ _mousePos (_input w) -doScopeZoom :: Int -> Point2 -> Scope -> Scope +doScopeZoom :: Int -> Point2 -> ScrollAttachParams -> ScrollAttachParams doScopeZoom scrollamount mp sc = case scrollamount of x | x > 10 -> (zoomInLongGun mp . zoomInLongGun mp . zoomInLongGun mp) sc @@ -160,21 +157,21 @@ doScopeZoom scrollamount mp sc = case scrollamount of zoomSpeed :: Float zoomSpeed = 39 / 40 -zoomInLongGun :: Point2 -> Scope -> Scope +zoomInLongGun :: Point2 -> ScrollAttachParams -> ScrollAttachParams zoomInLongGun mousep sc = fromMaybe sc $ do - curzoom <- sc ^? scopeZoom + curzoom <- sc ^? opticZoom guard $ curzoom < 8 return $ - sc & scopePos .+.+~ (1 - zoomSpeed) * zoomSpeed / curzoom *.* mousep - & scopeZoom %~ (/ zoomSpeed) + sc & opticPos .+.+~ (1 - zoomSpeed) * zoomSpeed / curzoom *.* mousep + & opticZoom %~ (/ zoomSpeed) -zoomOutLongGun :: Scope -> Scope +zoomOutLongGun :: ScrollAttachParams -> ScrollAttachParams zoomOutLongGun sc = fromMaybe sc $ do - curzoom <- sc ^? scopeZoom + curzoom <- sc ^? opticZoom guard $ curzoom > 0.5 return $ - sc & scopePos %~ (\p -> p +.+ (zoomSpeed - 1) / curzoom *.* p) - & scopeZoom *~ zoomSpeed + sc & opticPos %~ (\p -> p +.+ (zoomSpeed - 1) / curzoom *.* p) + & opticZoom *~ zoomSpeed ifConfigWallRotate :: Configuration -> World -> World ifConfigWallRotate cfig w @@ -213,9 +210,11 @@ rotateCameraBy x w = rotateanyscope = fromMaybe id $ do i <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inInventory . ispItem return $ - lWorld . creatures . ix 0 . crInv . ix i - . itScope - . scopePos + lWorld . creatures . ix 0 . crInv . ix (i - 1) + . itUse + . attachParams + . scrollAttachParams + . opticPos %~ rotateV x rotateCamera :: Configuration -> World -> World diff --git a/src/Dodge/Update/Scroll.hs b/src/Dodge/Update/Scroll.hs index 94fb9a3db..3af04cbe2 100644 --- a/src/Dodge/Update/Scroll.hs +++ b/src/Dodge/Update/Scroll.hs @@ -26,10 +26,14 @@ updateWheelEvent yi w = case w ^. hud . hudElement of -- functions that modify the inventory should be centralised so that -- this lock can be sensibly applied, perhaps | w ^?! cWorld . lWorld . creatures . ix 0 . crInvLock -> w - | rbDown -> case (yourItem w ^? _Just . itUse . heldScroll, _rbOptions w) of - (_, EquipOptions{}) -> w & rbOptions . opSel %~ scrollRBOption yi rbscrollmax - (Nothing, _) -> closeObjScrollDir y w - (Just f, _) -> doHeldScroll f y (you w) w +-- | rbDown -> case (yourItem w ^? _Just . itUse . heldScroll, _rbOptions w) of +-- (_, EquipOptions{}) -> w & rbOptions . opSel %~ scrollRBOption yi rbscrollmax +-- (Nothing, _) -> closeObjScrollDir y w +-- (Just f, _) -> doHeldScroll f y (you w) w + | rbDown -> case (yourScrollAttachment w, _rbOptions w) of + (_,EquipOptions{}) -> w & rbOptions . opSel %~ scrollRBOption yi rbscrollmax + (Nothing, _) -> w -- closeObjScrollDir y w + (Just (invid,hs), _) -> doHeldScroll invid hs y w | lbDown -> w & wCam . camZoom +~ y | invKeyDown -> changeSwapSel yi w | otherwise -> stopSoundFrom (CrReloadSound 0) $ scrollAugInvSel yi w