Move optic zoom scrolling to item scrolling function
Zoom scrolling behaviour has slightly changed, I'm not sure how I want it to work yet though
This commit is contained in:
@@ -64,15 +64,16 @@ translateFloatingCameraKeys theinput = (camCenter -~ thetran) . (camViewFrom -~
|
||||
zoomFloatingCamera :: Input -> Camera -> Camera
|
||||
zoomFloatingCamera theinput
|
||||
| ButtonRight `M.member` (theinput ^. mouseButtons) =
|
||||
camZoom *~ (zoomSpeed ^^ negate (getSmoothScrollValue theinput))
|
||||
camZoom *~ (39/40 ^^ negate (getSmoothScrollValue theinput))
|
||||
| otherwise = id
|
||||
-- the 39/40 is taken from zoomSpeed
|
||||
|
||||
updateInGameCamera :: Configuration -> World -> World
|
||||
updateInGameCamera cfig w =
|
||||
w
|
||||
& updateBounds cfig
|
||||
& wCam %~ moveZoomCamera cfig (w ^. input) (you w) w
|
||||
& updateScopeZoom
|
||||
-- & updateScopeZoom
|
||||
& rotateCamera cfig
|
||||
& over wCam (setViewDistance cfig) -- I think this should be updated after the zoom?
|
||||
|
||||
@@ -128,52 +129,6 @@ moveZoomCamera cfig theinput cr w campos =
|
||||
viewDistanceFromItems :: Creature -> Float
|
||||
viewDistanceFromItems _ = 1
|
||||
|
||||
-- note that your _crInvLock does not apply to this TODO check that this is what
|
||||
-- is wanted
|
||||
updateScopeZoom :: World -> World
|
||||
updateScopeZoom w = fromMaybe w $ do
|
||||
i <- you w ^? crManipulation . manObject . imSelectedItem
|
||||
return $ updateScopeZoom' i w
|
||||
|
||||
updateScopeZoom' :: Int -> World -> World
|
||||
updateScopeZoom' i w
|
||||
| SDL.ButtonRight `M.member` _mouseButtons (_input w) =
|
||||
w & wppointer %~ doScopeZoom (w ^. input . smoothScrollAmount) (w ^. input . mousePos)
|
||||
| otherwise = w & wppointer %~ resetscope
|
||||
where
|
||||
wppointer = cWorld . lWorld . creatures . ix 0 . crInv . ix i . itUse . uScope
|
||||
resetscope (OpticScope _ _ defz) = OpticScope (V2 0 0) defz defz
|
||||
|
||||
doScopeZoom :: Int -> Point2 -> Scope -> Scope
|
||||
doScopeZoom scrollamount mp sc = case scrollamount of
|
||||
x
|
||||
| x > 10 -> (zoomInLongGun mp . zoomInLongGun mp . zoomInLongGun mp) sc
|
||||
| x > 5 -> (zoomInLongGun mp . zoomInLongGun mp) sc
|
||||
| x > 0 -> zoomInLongGun mp sc
|
||||
| x < -10 -> (zoomOutLongGun . zoomOutLongGun . zoomOutLongGun) sc
|
||||
| x < -5 -> (zoomOutLongGun . zoomOutLongGun) sc
|
||||
| x < 0 -> zoomOutLongGun sc
|
||||
| otherwise -> sc
|
||||
|
||||
zoomSpeed :: Float
|
||||
zoomSpeed = 39 / 40
|
||||
|
||||
zoomInLongGun :: Point2 -> Scope -> Scope
|
||||
zoomInLongGun mousep sc = fromMaybe sc $ do
|
||||
curzoom <- sc ^? opticZoom
|
||||
guard $ curzoom < 8
|
||||
return $
|
||||
sc & opticPos .+.+~ (1 - zoomSpeed) * zoomSpeed / curzoom *.* mousep
|
||||
& opticZoom %~ (/ zoomSpeed)
|
||||
|
||||
zoomOutLongGun :: Scope -> Scope
|
||||
zoomOutLongGun sc = fromMaybe sc $ do
|
||||
curzoom <- sc ^? opticZoom
|
||||
guard $ curzoom > 0.5
|
||||
return $
|
||||
sc & opticPos %~ (\p -> p +.+ (zoomSpeed - 1) / curzoom *.* p)
|
||||
& opticZoom *~ zoomSpeed
|
||||
|
||||
ifConfigWallRotate :: Configuration -> M.Map MouseButton Int -> World -> World
|
||||
ifConfigWallRotate cfig mbs
|
||||
| _gameplay_rotate_to_wall cfig && not (SDL.ButtonRight `M.member` mbs) =
|
||||
|
||||
@@ -2,6 +2,8 @@ module Dodge.Update.Scroll (
|
||||
updateWheelEvent,
|
||||
) where
|
||||
|
||||
import Control.Monad
|
||||
import Geometry
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Dodge.Base
|
||||
@@ -31,7 +33,7 @@ updateWheelEvent yi w = case w ^. hud . hudElement of
|
||||
-- (Just (invid,hs), _) -> doHeldScroll invid hs y w
|
||||
| bdown ButtonRight -> case _rbOptions w of
|
||||
EquipOptions{} -> w & rbOptions . opSel %~ scrollRBOption yi rbscrollmax
|
||||
NoRightButtonOptions -> w
|
||||
NoRightButtonOptions -> selectedItemScroll yi w
|
||||
| bdown ButtonLeft -> w & wCam . camZoom +~ y
|
||||
| invKeyDown -> changeSwapSel yi w
|
||||
| otherwise -> scrollAugInvSel yi w
|
||||
@@ -55,6 +57,64 @@ updateWheelEvent yi w = case w ^. hud . hudElement of
|
||||
bdown b = b `M.member` _mouseButtons (_input w)
|
||||
invKeyDown = ScancodeCapsLock `M.member` _pressedKeys (_input w)
|
||||
|
||||
selectedItemScroll :: Int -> World -> World
|
||||
selectedItemScroll scrollamount w = fromMaybe w $ do
|
||||
i <- you w ^? crManipulation . manObject . imSelectedItem
|
||||
itm <- you w ^? crInv . ix i
|
||||
return $ itemScroll scrollamount itm w
|
||||
|
||||
itemScroll :: Int -> Item -> World -> World
|
||||
itemScroll yi itm w = case itm ^. itType of
|
||||
ATTACH ZOOMSCOPE -> updateScopeZoom w
|
||||
_ -> w
|
||||
|
||||
-- note that your _crInvLock does not apply to this TODO check that this is what
|
||||
-- is wanted
|
||||
updateScopeZoom :: World -> World
|
||||
updateScopeZoom w = fromMaybe w $ do
|
||||
i <- you w ^? crManipulation . manObject . imSelectedItem
|
||||
return $ updateScopeZoom' i w
|
||||
|
||||
updateScopeZoom' :: Int -> World -> World
|
||||
updateScopeZoom' i w
|
||||
| SDL.ButtonRight `M.member` _mouseButtons (_input w) =
|
||||
w & wppointer %~ doScopeZoom (w ^. input . smoothScrollAmount) (w ^. input . mousePos)
|
||||
| otherwise = w & wppointer %~ resetscope
|
||||
where
|
||||
wppointer = cWorld . lWorld . creatures . ix 0 . crInv . ix i . itUse . uScope
|
||||
resetscope (OpticScope _ _ defz) = OpticScope (V2 0 0) defz defz
|
||||
|
||||
doScopeZoom :: Int -> Point2 -> Scope -> Scope
|
||||
doScopeZoom scrollamount mp sc = case scrollamount of
|
||||
x
|
||||
| x > 10 -> (zoomInLongGun mp . zoomInLongGun mp . zoomInLongGun mp) sc
|
||||
| x > 5 -> (zoomInLongGun mp . zoomInLongGun mp) sc
|
||||
| x > 0 -> zoomInLongGun mp sc
|
||||
| x < -10 -> (zoomOutLongGun . zoomOutLongGun . zoomOutLongGun) sc
|
||||
| x < -5 -> (zoomOutLongGun . zoomOutLongGun) sc
|
||||
| x < 0 -> zoomOutLongGun sc
|
||||
| otherwise -> sc
|
||||
|
||||
zoomSpeed :: Float
|
||||
zoomSpeed = 39 / 40
|
||||
|
||||
zoomInLongGun :: Point2 -> Scope -> Scope
|
||||
zoomInLongGun mousep sc = fromMaybe sc $ do
|
||||
curzoom <- sc ^? opticZoom
|
||||
guard $ curzoom < 8
|
||||
return $
|
||||
sc & opticPos .+.+~ (1 - zoomSpeed) * zoomSpeed / curzoom *.* mousep
|
||||
& opticZoom %~ (/ zoomSpeed)
|
||||
|
||||
zoomOutLongGun :: Scope -> Scope
|
||||
zoomOutLongGun sc = fromMaybe sc $ do
|
||||
curzoom <- sc ^? opticZoom
|
||||
guard $ curzoom > 0.5
|
||||
return $
|
||||
sc & opticPos %~ (\p -> p +.+ (zoomSpeed - 1) / curzoom *.* p)
|
||||
& opticZoom *~ zoomSpeed
|
||||
|
||||
|
||||
moveCombineSel :: Int -> World -> World
|
||||
moveCombineSel yi =
|
||||
( hud . hudElement . subInventory %~ doscroll
|
||||
|
||||
Reference in New Issue
Block a user