Start implementing attachable scroll items

This commit is contained in:
2023-11-08 18:39:38 +00:00
parent 8f0dd8cd1b
commit f26d380c1b
20 changed files with 119 additions and 116 deletions
+10
View File
@@ -1,8 +1,10 @@
module Dodge.Base.You where module Dodge.Base.You where
import Dodge.Data.World import Dodge.Data.World
import Dodge.HeldScroll
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
import Control.Lens import Control.Lens
import Control.Monad
you :: World -> Creature you :: World -> Creature
you w = w ^?! cWorld . lWorld . creatures . ix 0 you w = w ^?! cWorld . lWorld . creatures . ix 0
@@ -15,6 +17,14 @@ yourItem w = do
i <- you w ^? crManipulation . manObject . inInventory . ispItem i <- you w ^? crManipulation . manObject . inInventory . ispItem
_crInv (you w) IM.!? i _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 :: World -> IM.IntMap Item
yourInv = _crInv . you yourInv = _crInv . you
+10
View File
@@ -25,6 +25,7 @@ module Dodge.Creature.Test (
) where ) where
--import MaybeHelp --import MaybeHelp
--import Control.Applicative
import Control.Lens import Control.Lens
import Data.List (find) import Data.List (find)
import Data.Maybe import Data.Maybe
@@ -46,6 +47,15 @@ crWeaponReady cr = fromMaybe False $ do
AboveSource -> do AboveSource -> do
x <- cr ^? crInv . ix (i - 1) . itUse . equipEffect . eeUse . euseAmmoAmount x <- cr ^? crInv . ix (i - 1) . itUse . equipEffect . eeUse . euseAmmoAmount
return (x > 0) 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 :: Creature -> (World, Creature) -> Bool
crCanSeeCr tcr (w, cr) = hasLOS (_crPos cr) (_crPos tcr) w crCanSeeCr tcr (w, cr) = hasLOS (_crPos cr) (_crPos tcr) w
+2 -1
View File
@@ -137,7 +137,8 @@ wasdWithAiming w speed cr
(argV (_mousePos (_input w)) + (w ^. wCam . camRot)) (argV (_mousePos (_input w)) + (w ^. wCam . camRot))
$ do $ do
itRef <- cr ^? crManipulation . manObject . inInventory . ispItem 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 return . argV $ mouseWorldPos (w ^. input) (w ^. wCam) -.- _crPos cr
aimTurn :: Float -> Creature -> Creature aimTurn :: Float -> Creature -> Creature
-21
View File
@@ -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
+9 -11
View File
@@ -14,18 +14,16 @@ data Scope
= NoScope = NoScope
| RemoteScope | RemoteScope
{ -- | a camera offset { -- | a camera offset
_scopePos :: Point2 _remotePos :: Point2
, _scopeZoom :: Float , _remoteZoom :: 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
} }
-- | ZoomScope
-- { -- | a camera offset
-- _scopePos :: Point2
---- , _scopeZoomChange :: Int
-- , _scopeZoom :: Float
-- , _scopeDefaultZoom :: Float
-- }
deriving (Eq, Show, Read) --Generic, Flat) deriving (Eq, Show, Read) --Generic, Flat)
makeLenses ''Scope makeLenses ''Scope
+17 -5
View File
@@ -7,19 +7,18 @@ module Dodge.Data.Item.Use (
module Dodge.Data.Item.Use, module Dodge.Data.Item.Use,
module Dodge.Data.Item.Use.Equipment, module Dodge.Data.Item.Use.Equipment,
module Dodge.Data.Item.HeldUse, module Dodge.Data.Item.HeldUse,
module Dodge.Data.Item.HeldScroll,
module Dodge.Data.Item.HeldDelay, module Dodge.Data.Item.HeldDelay,
module Dodge.Data.Item.Use.Consumption, module Dodge.Data.Item.Use.Consumption,
module Dodge.Data.Hammer, module Dodge.Data.Hammer,
module Dodge.Data.Item.Targeting, module Dodge.Data.Item.Targeting,
) where ) where
import Linear import Geometry.Data
import Control.Lens import Control.Lens
import Data.Aeson import Data.Aeson
import Data.Aeson.TH import Data.Aeson.TH
import qualified Data.Sequence as Seq
import Dodge.Data.Hammer import Dodge.Data.Hammer
import Dodge.Data.Item.HeldScroll
import Dodge.Data.Item.HeldUse import Dodge.Data.Item.HeldUse
import Dodge.Data.Item.Use.Consumption import Dodge.Data.Item.Use.Consumption
import Dodge.Data.Item.Use.Equipment import Dodge.Data.Item.Use.Equipment
@@ -33,7 +32,6 @@ data ItemUse
, _heldMods :: HeldMod , _heldMods :: HeldMod
, _heldHammer :: HammerPosition , _heldHammer :: HammerPosition
, _heldAim :: AimParams , _heldAim :: AimParams
, _heldScroll :: HeldScroll
, _heldConsumption :: HeldConsumption , _heldConsumption :: HeldConsumption
-- , _useTargeting :: Maybe TargetType -- , _useTargeting :: Maybe TargetType
} }
@@ -59,9 +57,20 @@ data ItemUse
--deriving (Eq, Show, Read) --Generic, Flat) --deriving (Eq, Show, Read) --Generic, Flat)
data AttachParams data AttachParams
= ZoomScopeParams = ScrollAttachParams {_scrollAttachParams :: ScrollAttachParams}
| AmmoAttachParams | AmmoAttachParams
data ScrollAttachParams
= ZoomScrollParams
{ -- | a camera offset
_opticPos :: Point2
-- , _scopeZoomChange :: Int
, _opticZoom :: Float
, _opticDefaultZoom :: Float
}
| CharScrollParams
{ _scrollChar :: Seq.Seq Char}
data ItemUse' data ItemUse'
= ItemHeld HeldUse' = ItemHeld HeldUse'
| ItemEquip EquipUse' | ItemEquip EquipUse'
@@ -110,8 +119,11 @@ makeLenses ''ItemUse
makeLenses ''AimParams makeLenses ''AimParams
makeLenses ''ItZoom makeLenses ''ItZoom
makeLenses ''Muzzle makeLenses ''Muzzle
makeLenses ''AttachParams
makeLenses ''ScrollAttachParams
deriveJSON defaultOptions ''Muzzle deriveJSON defaultOptions ''Muzzle
deriveJSON defaultOptions ''AimStance deriveJSON defaultOptions ''AimStance
deriveJSON defaultOptions ''ScrollAttachParams
deriveJSON defaultOptions ''AttachParams deriveJSON defaultOptions ''AttachParams
deriveJSON defaultOptions ''ItZoom deriveJSON defaultOptions ''ItZoom
deriveJSON defaultOptions ''AimParams deriveJSON defaultOptions ''AimParams
+2
View File
@@ -29,6 +29,8 @@ data HeldConsumption
data AmmoSource data AmmoSource
= InternalSource InternalAmmo = InternalSource InternalAmmo
| AboveSource | AboveSource
| BelowSource
| EitherSource
deriving (Eq, Show, Read) --Generic, Flat) deriving (Eq, Show, Read) --Generic, Flat)
data ExternalSourceType = BulletClip data ExternalSourceType = BulletClip
-1
View File
@@ -34,6 +34,5 @@ defaultHeldUse =
, _heldMods = HeldModNothing , _heldMods = HeldModNothing
, _heldHammer = HammerUp , _heldHammer = HammerUp
, _heldAim = defaultAimParams , _heldAim = defaultAimParams
, _heldScroll = HeldScrollDoNothing
, _heldConsumption = defaultLoadable , _heldConsumption = defaultLoadable
} }
+8 -14
View File
@@ -1,25 +1,16 @@
module Dodge.HeldScroll ( module Dodge.HeldScroll (
doHeldScroll, doHeldScroll,
canHeldScrollAttach,
) where ) where
--import Dodge.Base.You
import Control.Lens hiding ((<|), (|>)) import Control.Lens hiding ((<|), (|>))
import Data.Sequence import Data.Sequence
import Dodge.Data.Creature
import Dodge.Data.World 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 :: Int -> ScrollAttachParams -> Float -> World -> World
doHeldScroll hs = case hs of doHeldScroll invid hs x w = case hs of
HeldScrollDoNothing -> const . const id ZoomScrollParams{}-> w
HeldScrollZoom -> const . const id CharScrollParams{} -> w & cWorld . lWorld . creatures . ix 0 . crInv . ix invid . itUse . attachParams . scrollAttachParams . scrollChar %~ cycleSignum x
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
cycleSignum :: Float -> Seq a -> Seq a cycleSignum :: Float -> Seq a -> Seq a
cycleSignum x cycleSignum x
@@ -31,3 +22,6 @@ cycleL (x :<| xs) = xs |> x
cycleL xs = xs cycleL xs = xs
cycleR (xs :|> x) = x <| xs cycleR (xs :|> x) = x <| xs
cycleR xs = xs cycleR xs = xs
canHeldScrollAttach :: Item -> ScrollAttachParams -> Bool
canHeldScrollAttach _ _ = True
+7 -7
View File
@@ -4,7 +4,7 @@ module Dodge.Inventory (
rmSelectedInvItem, rmSelectedInvItem,
rmInvItem, rmInvItem,
updateCloseObjects, updateCloseObjects,
closeObjScrollDir, --closeObjScrollDir,
changeSwapSel, changeSwapSel,
scrollAugInvSel, scrollAugInvSel,
crNumFreeSlots, crNumFreeSlots,
@@ -31,7 +31,7 @@ import Geometry
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
import LensHelp import LensHelp
import ListHelp import ListHelp
import Padding --import Padding
-- TODO check what happens to selection index when dropping non-selected items -- 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) updatebyid (Right btid) = fmap Right $ w ^? cWorld . lWorld . buttons . ix (_btID btid)
closeObjScrollDir :: Float -> World -> World --closeObjScrollDir :: Float -> World -> World
closeObjScrollDir x --closeObjScrollDir x
| x > 0 = over (hud . closeObjects) rotU -- | x > 0 = over (hud . closeObjects) rotU
| x < 0 = over (hud . closeObjects) rotD -- | x < 0 = over (hud . closeObjects) rotD
| otherwise = id -- | otherwise = id
changeSwapSel :: Int -> World -> World changeSwapSel :: Int -> World -> World
changeSwapSel yi w changeSwapSel yi w
+1 -1
View File
@@ -17,5 +17,5 @@ beltMag = tinMag & itType . iyBase .~ AMMO BULLETBELT
zoomScope :: Item zoomScope :: Item
zoomScope = tinMag zoomScope = tinMag
& itType . iyBase .~ ATTACH ZOOMSCOPE & itType . iyBase .~ ATTACH ZOOMSCOPE
& itUse .~ AttachUse ZoomScopeParams & itUse .~ AttachUse (ScrollAttachParams (ZoomScrollParams {_opticPos = 0, _opticZoom = 1, _opticDefaultZoom = 0.5}))
+1 -1
View File
@@ -155,7 +155,7 @@ showReloadProgress cr itm = case ic ^? laSource of
Just (InternalSource ia) -> case ia ^? iaProgress . _Just . ix 0 of Just (InternalSource ia) -> case ia ^? iaProgress . _Just . ix 0 of
Nothing -> maybe "" show $ ic ^? laSource . _InternalSource . iaLoaded Nothing -> maybe "" show $ ic ^? laSource . _InternalSource . iaLoaded
Just la -> showLoadActionType la (_laSource ic) Just la -> showLoadActionType la (_laSource ic)
Just AboveSource -> fromMaybe "||||" $ do Just AboveSource -> fromMaybe "^^^^" $ do
i <- fmap (subtract 1) $ itm ^? itLocation . ipInvID i <- fmap (subtract 1) $ itm ^? itLocation . ipInvID
_ <- cr ^? crInv . ix i . itUse . equipEffect . eeUse . euseAmmoAmount _ <- cr ^? crInv . ix i . itUse . equipEffect . eeUse . euseAmmoAmount
return "" return ""
+1 -1
View File
@@ -59,7 +59,7 @@ remoteLauncher =
launcher launcher
& itType . iyBase .~ HELD REMOTELAUNCHER & itType . iyBase .~ HELD REMOTELAUNCHER
& itUse . heldUse .~ HeldFireRemoteShell --fireRemoteShell & itUse . heldUse .~ HeldFireRemoteShell --fireRemoteShell
& itScope .~ RemoteScope (V2 0 0) 1 True & itScope .~ RemoteScope (V2 0 0) 1
& itUse . heldConsumption . laAmmoType . amPjDraw .~ DrawRemoteShell & itUse . heldConsumption . laAmmoType . amPjDraw .~ DrawRemoteShell
basicAmPjMoves :: IM.IntMap TweakParam basicAmPjMoves :: IM.IntMap TweakParam
+6 -6
View File
@@ -68,12 +68,12 @@ sniperRifle =
& itType . iyBase .~ HELD SNIPERRIFLE & itType . iyBase .~ HELD SNIPERRIFLE
& itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0 & itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0
& itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5,_izFac = 1} & itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5,_izFac = 1}
& itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun -- & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun
& itScope .~ ZoomScope -- & itScope .~ ZoomScope
{ _scopePos = (V2 0 0) -- { _scopePos = (V2 0 0)
, _scopeZoom = 1 -- , _scopeZoom = 1
, _scopeDefaultZoom = 0.5 -- , _scopeDefaultZoom = 0.5
} -- }
& itType . iyModules . at ModTarget ?~ TARGET TargetLaser & itType . iyModules . at ModTarget ?~ TARGET TargetLaser
-- & itUse . useTargeting ?~ TargetLaser -- & itUse . useTargeting ?~ TargetLaser
+6 -6
View File
@@ -26,16 +26,16 @@ latchkey _ = defaultHeldItem
binoculars :: Item binoculars :: Item
binoculars = binoculars =
defaultHeldItem defaultHeldItem
& itScope .~ ZoomScope -- & itScope .~ ZoomScope
{ _scopePos = (V2 0 0) -- { _scopePos = (V2 0 0)
, _scopeZoom = 1 -- , _scopeZoom = 1
, _scopeDefaultZoom = 0.5 -- , _scopeDefaultZoom = 0.5
} -- }
& itType . iyBase .~ HELD BINOCULARS & itType . iyBase .~ HELD BINOCULARS
-- & itUse . heldAim . aimHandlePos .~ 5 -- & itUse . heldAim . aimHandlePos .~ 5
-- & itUse . heldAim . aimMuzPos .~ 10 -- & itUse . heldAim . aimMuzPos .~ 10
& itUse . heldAim . aimStance .~ TwoHandFlat & itUse . heldAim . aimStance .~ TwoHandFlat
& itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun -- & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun
& itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5, _izFac = 1} & itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5, _izFac = 1}
+1 -12
View File
@@ -1,6 +1,5 @@
module Dodge.Item.Weapon.Remote ( module Dodge.Item.Weapon.Remote (
setRemoteScope, setRemoteScope,
setRemoteBombScope,
) where ) where
import Control.Lens import Control.Lens
@@ -8,22 +7,12 @@ import Dodge.Data.World
import Dodge.Default import Dodge.Default
import Geometry 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 :: Int -> Point2 -> World -> World
setRemoteScope itid pos w = case w ^? cWorld . lWorld . itemLocations . ix itid of setRemoteScope itid pos w = case w ^? cWorld . lWorld . itemLocations . ix itid of
Just (InInv cid' invid) -> Just (InInv cid' invid) ->
w w
& cWorld . lWorld . creatures . ix cid' . crInv . ix invid . itScope & cWorld . lWorld . creatures . ix cid' . crInv . ix invid . itScope
. scopePos . remotePos
.~ (pos -.- (w ^?! cWorld . lWorld . creatures . ix cid' . crPos)) .~ (pos -.- (w ^?! cWorld . lWorld . creatures . ix cid' . crPos))
_ -> w _ -> w
+9 -3
View File
@@ -361,7 +361,7 @@ useAmmoUpTo amAmount eff item cr =
useAmmoAmount :: Int -> ChainEffect useAmmoAmount :: Int -> ChainEffect
useAmmoAmount amAmount eff item cr = useAmmoAmount amAmount eff item cr =
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 where
itref = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change 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 inv & ix itref . itUse . heldConsumption . laSource . _InternalSource . iaLoaded -~ x
Just AboveSource -> Just AboveSource ->
inv & ix (itref - 1) . itUse . equipEffect . eeUse . euseAmmoAmount -~ x 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 _ -> inv
-- . crInv . ix itRef . itUse . heldConsumption . laSource -- . crInv . ix itRef . itUse . heldConsumption . laSource
@@ -615,8 +621,8 @@ withTorqueAfter feff item cr w
(rot, g) = randomR (- torque, torque) $ _randGen w (rot, g) = randomR (- torque, torque) $ _randGen w
torque = fromMaybe 0 $ item ^? itParams . torqueAfter torque = fromMaybe 0 $ item ^? itParams . torqueAfter
--rotateScope = cWorld . lWorld . creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0)) rotateScope = id
rotateScope = pointerYourItem . itScope . scopePos %~ rotateV rot -- rotateScope = pointerYourItem . itScope . scopePos %~ rotateV rot
sideEffectOnFrame :: sideEffectOnFrame ::
Int -> Int ->
+1 -1
View File
@@ -83,7 +83,7 @@ retireRemoteProj :: Int -> Int -> World -> World
retireRemoteProj itid pjid w = retireRemoteProj itid pjid w =
w w
& pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix itid) & pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix itid)
%~ ( (itScope . scopePos .~ V2 0 0) %~ ( (itScope . remotePos .~ V2 0 0)
. (itUse . heldUse .~ HeldFireRemoteShell) . (itUse . heldUse .~ HeldFireRemoteShell)
) )
& cWorld . lWorld . props %~ IM.delete pjid & cWorld . lWorld . props %~ IM.delete pjid
+20 -21
View File
@@ -93,23 +93,21 @@ moveZoomCamera cfig theinput cr campos =
cr ^? crInv . ix i cr ^? crInv . ix i
newvf = cpos +.+ fromMaybe (V2 0 0) vfoffset newvf = cpos +.+ fromMaybe (V2 0 0) vfoffset
vfoffset = do vfoffset = do
iscam <- mitm ^? _Just . itScope . scopeIsCamera
guard iscam
guard (SDL.ButtonRight `M.member` _mouseButtons theinput) guard (SDL.ButtonRight `M.member` _mouseButtons theinput)
mitm ^? _Just . itScope . scopePos mitm ^? _Just . itScope . remotePos
mscopeoffset = do mscopeoffset = do
guard (SDL.ButtonRight `M.member` _mouseButtons theinput) guard (SDL.ButtonRight `M.member` _mouseButtons theinput)
mitm ^? _Just . itScope . scopePos mitm ^? _Just . itScope . remotePos
newcen = cpos +.+ fromMaybe (V2 0 0) mscopeoffset +.+ offset newcen = cpos +.+ fromMaybe (V2 0 0) mscopeoffset +.+ offset
offset = offset =
rotateV (campos ^. camRot) $ rotateV (campos ^. camRot) $
((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos theinput ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos theinput
newzoom = case mitm ^? _Just . itScope of newzoom = case mitm ^? _Just . itScope of
Just zs@ZoomScope{} -> _scopeZoom zs -- Just zs@ZoomScope{} -> _scopeZoom zs
_ -> newDefaultZoom * newItemZoom _ -> newDefaultZoom * newItemZoom
idealDefaultZoom = clipZoom wallZoom idealDefaultZoom = clipZoom wallZoom
newDefaultZoom = case mitm ^? _Just . itScope of newDefaultZoom = case mitm ^? _Just . itScope of
Just zs@ZoomScope{} -> _scopeZoom zs -- Just zs@ZoomScope{} -> _scopeZoom zs
_ -> changeZoom (campos ^. camDefaultZoom) idealDefaultZoom _ -> changeZoom (campos ^. camDefaultZoom) idealDefaultZoom
idealItemZoom = fromMaybe 1 $ do idealItemZoom = fromMaybe 1 $ do
guard $ crIsAiming cr guard $ crIsAiming cr
@@ -140,13 +138,12 @@ updateScopeZoom' i w
w & wppointer %~ doScopeZoom (w ^. input . smoothScrollAmount) mp w & wppointer %~ doScopeZoom (w ^. input . smoothScrollAmount) mp
| otherwise = w & wppointer %~ resetscope | otherwise = w & wppointer %~ resetscope
where where
wppointer = cWorld . lWorld . creatures . ix 0 . crInv . ix i . itScope wppointer = cWorld . lWorld . creatures . ix 0 . crInv . ix (i - 1) . itUse . attachParams . scrollAttachParams
--resetscope (ZoomScope _ _ defz bl) = ZoomScope (V2 0 0) defz defz bl resetscope (ZoomScrollParams _ _ defz) = ZoomScrollParams (V2 0 0) defz defz
resetscope (ZoomScope _ _ defz) = ZoomScope (V2 0 0) defz defz
resetscope otherAtt = otherAtt resetscope otherAtt = otherAtt
mp = rotateV (w ^. wCam . camRot) $ _mousePos (_input w) 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 doScopeZoom scrollamount mp sc = case scrollamount of
x x
| x > 10 -> (zoomInLongGun mp . zoomInLongGun mp . zoomInLongGun mp) sc | x > 10 -> (zoomInLongGun mp . zoomInLongGun mp . zoomInLongGun mp) sc
@@ -160,21 +157,21 @@ doScopeZoom scrollamount mp sc = case scrollamount of
zoomSpeed :: Float zoomSpeed :: Float
zoomSpeed = 39 / 40 zoomSpeed = 39 / 40
zoomInLongGun :: Point2 -> Scope -> Scope zoomInLongGun :: Point2 -> ScrollAttachParams -> ScrollAttachParams
zoomInLongGun mousep sc = fromMaybe sc $ do zoomInLongGun mousep sc = fromMaybe sc $ do
curzoom <- sc ^? scopeZoom curzoom <- sc ^? opticZoom
guard $ curzoom < 8 guard $ curzoom < 8
return $ return $
sc & scopePos .+.+~ (1 - zoomSpeed) * zoomSpeed / curzoom *.* mousep sc & opticPos .+.+~ (1 - zoomSpeed) * zoomSpeed / curzoom *.* mousep
& scopeZoom %~ (/ zoomSpeed) & opticZoom %~ (/ zoomSpeed)
zoomOutLongGun :: Scope -> Scope zoomOutLongGun :: ScrollAttachParams -> ScrollAttachParams
zoomOutLongGun sc = fromMaybe sc $ do zoomOutLongGun sc = fromMaybe sc $ do
curzoom <- sc ^? scopeZoom curzoom <- sc ^? opticZoom
guard $ curzoom > 0.5 guard $ curzoom > 0.5
return $ return $
sc & scopePos %~ (\p -> p +.+ (zoomSpeed - 1) / curzoom *.* p) sc & opticPos %~ (\p -> p +.+ (zoomSpeed - 1) / curzoom *.* p)
& scopeZoom *~ zoomSpeed & opticZoom *~ zoomSpeed
ifConfigWallRotate :: Configuration -> World -> World ifConfigWallRotate :: Configuration -> World -> World
ifConfigWallRotate cfig w ifConfigWallRotate cfig w
@@ -213,9 +210,11 @@ rotateCameraBy x w =
rotateanyscope = fromMaybe id $ do rotateanyscope = fromMaybe id $ do
i <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inInventory . ispItem i <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inInventory . ispItem
return $ return $
lWorld . creatures . ix 0 . crInv . ix i lWorld . creatures . ix 0 . crInv . ix (i - 1)
. itScope . itUse
. scopePos . attachParams
. scrollAttachParams
. opticPos
%~ rotateV x %~ rotateV x
rotateCamera :: Configuration -> World -> World rotateCamera :: Configuration -> World -> World
+8 -4
View File
@@ -26,10 +26,14 @@ updateWheelEvent yi w = case w ^. hud . hudElement of
-- functions that modify the inventory should be centralised so that -- functions that modify the inventory should be centralised so that
-- this lock can be sensibly applied, perhaps -- this lock can be sensibly applied, perhaps
| w ^?! cWorld . lWorld . creatures . ix 0 . crInvLock -> w | w ^?! cWorld . lWorld . creatures . ix 0 . crInvLock -> w
| rbDown -> case (yourItem w ^? _Just . itUse . heldScroll, _rbOptions w) of -- | rbDown -> case (yourItem w ^? _Just . itUse . heldScroll, _rbOptions w) of
(_, EquipOptions{}) -> w & rbOptions . opSel %~ scrollRBOption yi rbscrollmax -- (_, EquipOptions{}) -> w & rbOptions . opSel %~ scrollRBOption yi rbscrollmax
(Nothing, _) -> closeObjScrollDir y w -- (Nothing, _) -> closeObjScrollDir y w
(Just f, _) -> doHeldScroll f y (you w) 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 | lbDown -> w & wCam . camZoom +~ y
| invKeyDown -> changeSwapSel yi w | invKeyDown -> changeSwapSel yi w
| otherwise -> stopSoundFrom (CrReloadSound 0) $ scrollAugInvSel yi w | otherwise -> stopSoundFrom (CrReloadSound 0) $ scrollAugInvSel yi w