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