Move scroll smoothing to central location
This commit is contained in:
@@ -22,7 +22,7 @@ data Scope
|
|||||||
| ZoomScope
|
| ZoomScope
|
||||||
{ -- | a camera offset
|
{ -- | a camera offset
|
||||||
_scopePos :: Point2
|
_scopePos :: Point2
|
||||||
, _scopeZoomChange :: Int
|
-- , _scopeZoomChange :: Int
|
||||||
, _scopeZoom :: Float
|
, _scopeZoom :: Float
|
||||||
, _scopeDefaultZoom :: Float
|
, _scopeDefaultZoom :: Float
|
||||||
, -- | if the camera offset is also the center of vision
|
, -- | if the camera offset is also the center of vision
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import Control.Lens hiding ((<|), (|>))
|
|||||||
import Data.Sequence
|
import Data.Sequence
|
||||||
import Dodge.Data.Creature
|
import Dodge.Data.Creature
|
||||||
import Dodge.Data.World
|
import Dodge.Data.World
|
||||||
import Dodge.Item.Weapon.ZoomScope
|
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
--import LensHelp hiding ((|>), (<|))
|
--import LensHelp hiding ((|>), (<|))
|
||||||
-- should be able to just import data.item
|
-- should be able to just import data.item
|
||||||
@@ -15,7 +14,7 @@ import Data.Maybe
|
|||||||
doHeldScroll :: HeldScroll -> Float -> Creature -> World -> World
|
doHeldScroll :: HeldScroll -> Float -> Creature -> World -> World
|
||||||
doHeldScroll hs = case hs of
|
doHeldScroll hs = case hs of
|
||||||
HeldScrollDoNothing -> const . const id
|
HeldScrollDoNothing -> const . const id
|
||||||
HeldScrollZoom -> overYourItem (const . setZoomScopeChange)
|
HeldScrollZoom -> const . const id
|
||||||
HeldScrollCharMode{} -> overYourItem $ \x _ -> itUse . heldScroll . hsCharMode %~ cycleSignum x
|
HeldScrollCharMode{} -> overYourItem $ \x _ -> itUse . heldScroll . hsCharMode %~ cycleSignum x
|
||||||
where
|
where
|
||||||
overYourItem f x cr w = fromMaybe w $ do
|
overYourItem f x cr w = fromMaybe w $ do
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ sniperRifle =
|
|||||||
& itParams . gunBarrels .~ SingleBarrel 0
|
& itParams . gunBarrels .~ SingleBarrel 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 (V2 0 0) 0 1 0.5 False
|
& itScope .~ ZoomScope (V2 0 0) 1 0.5 False
|
||||||
& itUse . useTargeting ?~ TargetLaser
|
& itUse . useTargeting ?~ TargetLaser
|
||||||
|
|
||||||
machineGun :: Item
|
machineGun :: Item
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ latchkey _ =
|
|||||||
binoculars :: Item
|
binoculars :: Item
|
||||||
binoculars =
|
binoculars =
|
||||||
defaultHeldItem
|
defaultHeldItem
|
||||||
& itScope .~ ZoomScope (V2 0 0) 0 1 0.5 False
|
& itScope .~ ZoomScope (V2 0 0) 1 0.5 False
|
||||||
& itType . iyBase .~ HELD BINOCULARS
|
& itType . iyBase .~ HELD BINOCULARS
|
||||||
& itUse . heldAim . aimHandlePos .~ 5
|
& itUse . heldAim . aimHandlePos .~ 5
|
||||||
& itUse . heldAim . aimMuzPos .~ 10
|
& itUse . heldAim . aimMuzPos .~ 10
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
module Dodge.Item.Weapon.ZoomScope where
|
|
||||||
|
|
||||||
import Dodge.Data.Item
|
|
||||||
import LensHelp
|
|
||||||
-- should be possible without the creature
|
|
||||||
|
|
||||||
setZoomScopeChange :: Float -> Item -> Item
|
|
||||||
setZoomScopeChange x
|
|
||||||
| x > 0 = itScope . scopeZoomChange %~ (max 0 . (+ xi))
|
|
||||||
| x < 0 = itScope . scopeZoomChange %~ (min 0 . (+ xi))
|
|
||||||
| otherwise = id
|
|
||||||
where
|
|
||||||
xi | x > 2 = 20
|
|
||||||
| x > 1 = 10
|
|
||||||
| x > 0 = 1
|
|
||||||
| x < -2 = - 20
|
|
||||||
| x < -1 = - 10
|
|
||||||
| x < -0 = - 1
|
|
||||||
| otherwise = 0
|
|
||||||
@@ -128,31 +128,25 @@ updateScopeZoom w = fromMaybe w $ do
|
|||||||
|
|
||||||
updateScopeZoom' :: Int -> World -> World
|
updateScopeZoom' :: Int -> World -> World
|
||||||
updateScopeZoom' i w
|
updateScopeZoom' i w
|
||||||
| SDL.ButtonRight `M.member` _mouseButtons (_input w) = w & wppointer %~ doScopeZoom mp
|
| SDL.ButtonRight `M.member` _mouseButtons (_input w)
|
||||||
|
= 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 . itScope
|
||||||
resetscope (ZoomScope _ _ _ defz bl) = ZoomScope (V2 0 0) 0 defz defz bl
|
resetscope (ZoomScope _ _ defz bl) = ZoomScope (V2 0 0) defz defz bl
|
||||||
resetscope otherAtt = otherAtt
|
resetscope otherAtt = otherAtt
|
||||||
mp = rotateV (w ^. wCam . camRot) $ _mousePos (_input w)
|
mp = rotateV (w ^. wCam . camRot) $ _mousePos (_input w)
|
||||||
|
|
||||||
doScopeZoom :: Point2 -> Scope -> Scope
|
doScopeZoom :: Int -> Point2 -> Scope -> Scope
|
||||||
doScopeZoom mp sc = case sc ^? scopeZoomChange of
|
doScopeZoom scrollamount mp sc = case scrollamount of
|
||||||
Just x
|
x
|
||||||
| x > 10 -> (zoomInLongGun mp . zoomInLongGun mp . zoomInLongGun mp) $ sc
|
| x > 10 -> (zoomInLongGun mp . zoomInLongGun mp . zoomInLongGun mp) $ sc
|
||||||
& scopeZoomChange -~ 2
|
|
||||||
| x > 5 -> (zoomInLongGun mp . zoomInLongGun mp) $ sc
|
| x > 5 -> (zoomInLongGun mp . zoomInLongGun mp) $ sc
|
||||||
& scopeZoomChange -~ 1
|
|
||||||
| x > 0 -> zoomInLongGun mp $ sc
|
| x > 0 -> zoomInLongGun mp $ sc
|
||||||
& scopeZoomChange -~ 1
|
|
||||||
| x < -10 -> (zoomOutLongGun . zoomOutLongGun . zoomOutLongGun) $ sc
|
| x < -10 -> (zoomOutLongGun . zoomOutLongGun . zoomOutLongGun) $ sc
|
||||||
& scopeZoomChange +~ 2
|
|
||||||
| x < -5 -> (zoomOutLongGun . zoomOutLongGun) $ sc
|
| x < -5 -> (zoomOutLongGun . zoomOutLongGun) $ sc
|
||||||
& scopeZoomChange +~ 1
|
|
||||||
| x < 0 -> zoomOutLongGun $ sc
|
| x < 0 -> zoomOutLongGun $ sc
|
||||||
& scopeZoomChange +~ 1
|
|
||||||
| otherwise -> sc
|
| otherwise -> sc
|
||||||
_ -> sc
|
|
||||||
|
|
||||||
zoomSpeed :: Float
|
zoomSpeed :: Float
|
||||||
zoomSpeed = 39 / 40
|
zoomSpeed = 39 / 40
|
||||||
@@ -163,7 +157,7 @@ zoomInLongGun mousep sc
|
|||||||
sc
|
sc
|
||||||
& scopePos .+.+~ (1 - zoomSpeed) / newzoom *.* mousep
|
& scopePos .+.+~ (1 - zoomSpeed) / newzoom *.* mousep
|
||||||
& scopeZoom %~ (/ zoomSpeed)
|
& scopeZoom %~ (/ zoomSpeed)
|
||||||
| otherwise = sc & scopeZoomChange .~ 0
|
| otherwise = sc
|
||||||
where
|
where
|
||||||
Just currentZoom = sc ^? scopeZoom
|
Just currentZoom = sc ^? scopeZoom
|
||||||
newzoom = (sc ^?! scopeZoom) / zoomSpeed
|
newzoom = (sc ^?! scopeZoom) / zoomSpeed
|
||||||
@@ -175,7 +169,7 @@ zoomOutLongGun sc
|
|||||||
& scopePos %~ (\p -> p +.+ (zoomSpeed-1) / currentzoom *.* p)
|
& scopePos %~ (\p -> p +.+ (zoomSpeed-1) / currentzoom *.* p)
|
||||||
-- & scopePos .*.*~ 1 - ((newzoom * 2) ** zoomSpeed)
|
-- & scopePos .*.*~ 1 - ((newzoom * 2) ** zoomSpeed)
|
||||||
& scopeZoom *~ zoomSpeed
|
& scopeZoom *~ zoomSpeed
|
||||||
| otherwise = sc & scopeZoomChange .~ 0
|
| otherwise = sc
|
||||||
& scopePos .~ V2 0 0
|
& scopePos .~ V2 0 0
|
||||||
where
|
where
|
||||||
Just currentzoom = sc ^? scopeZoom
|
Just currentzoom = sc ^? scopeZoom
|
||||||
|
|||||||
Reference in New Issue
Block a user