This commit is contained in:
2022-12-27 14:46:13 +00:00
parent 85738adff1
commit 9ada489993
4 changed files with 62 additions and 56 deletions
+41 -28
View File
@@ -1,4 +1,6 @@
module Dodge.Update.Scroll where
module Dodge.Update.Scroll (
updateWheelEvent,
) where
import qualified Data.Map.Strict as M
import Data.Maybe
@@ -26,7 +28,7 @@ updateWheelEvent yi w = case w ^. cWorld . lWorld . hud . hudElement of
-- 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{}) -> scrollRBOption y w
(_, EquipOptions{}) -> scrollRBOption yi w
(Nothing, _) -> closeObjScrollDir y w
(Just f, _) -> doHeldScroll f y (you w) w
| lbDown -> w & cWorld . camPos . camZoom +~ y
@@ -37,19 +39,41 @@ updateWheelEvent yi w = case w ^. cWorld . lWorld . hud . hudElement of
| invKeyDown -> stopSoundFrom (CrReloadSound 0) $ changeInvSel yi w
| rbDown -> w & changeTweakParam mi yi
| otherwise -> w & moveTweakSel yi
DisplayInventory CombineInventory{} ->
w
& cWorld . lWorld . hud . hudElement . subInventory . combineInvSel . _Just %~ ((`mod` numcombs) . subtract yi)
DisplayInventory (DisplayTerminal tmid)
| rbDown && inTermFocus w ->
guardDisconnectedID tmid w $
w
& cWorld . lWorld . terminals . ix tmid %~ updatetermsubsel
| inTermFocus w ->
w
& cWorld . lWorld . terminals . ix tmid %~ updatetermsel
DisplayInventory CombineInventory{} -> w & moveCombineSel yi
DisplayInventory (DisplayTerminal tmid) -> terminalWheelEvent yi tmid w
_ -> w
where
y = fromIntegral yi
numLocs = (fst . IM.findMax $ (w ^. cWorld . lWorld . seenLocations)) + 1
rbDown = ButtonRight `M.member` _mouseButtons (_input w)
lbDown = ButtonLeft `M.member` _mouseButtons (_input w)
invKeyDown = ScancodeCapsLock `M.member` _pressedKeys (_input w)
moveCombineSel :: Int -> World -> World
moveCombineSel yi w = moveSubSel yi (length $ combineItemListYou w) w
moveSubSel :: Int -> Int -> World -> World
moveSubSel yi maxyi =
cWorld . lWorld . hud . hudElement . subInventory . subInvSel . _Just
%~ ((`mod` maxyi) . subtract yi)
guardDisconnectedID :: Int -> World -> World -> World
guardDisconnectedID tmid w w' = case w ^? cWorld . lWorld . terminals . ix tmid . tmStatus of
Just TerminalReady -> w'
_ -> w
terminalWheelEvent :: Int -> Int -> World -> World
terminalWheelEvent yi tmid w
| rbDown && inTermFocus w =
guardDisconnectedID tmid w $
w
& cWorld . lWorld . terminals . ix tmid %~ updatetermsubsel
| inTermFocus w =
w
& cWorld . lWorld . terminals . ix tmid %~ updatetermsel
| otherwise = w
where
rbDown = ButtonRight `M.member` _mouseButtons (_input w)
updatetermsel tm = case tm ^? tmInput . tiSel of
Nothing -> tm & tmInput . tiSel .~ (0, 0)
Just (i, _) ->
@@ -67,27 +91,16 @@ updateWheelEvent yi w = case w ^. cWorld . lWorld . hud . hudElement of
where
tc = scrollCommands tm !! i
arg = getArguments' tc tm w' !! j
numcombs = length $ combineItemListYou w
y = fromIntegral yi
numLocs = (fst . IM.findMax $ (w ^. cWorld . lWorld . seenLocations)) + 1
rbDown = ButtonRight `M.member` _mouseButtons (_input w)
lbDown = ButtonLeft `M.member` _mouseButtons (_input w)
invKeyDown = ScancodeCapsLock `M.member` _pressedKeys (_input w)
guardDisconnectedID :: Int -> World -> World -> World
guardDisconnectedID tmid w w' = case w ^? cWorld . lWorld . terminals . ix tmid . tmStatus of
Just TerminalReady -> w'
_ -> w
scrollRBOption :: Float -> World -> World
scrollRBOption :: Int -> World -> World
scrollRBOption y w
| y < 0 = w & rbOptions . opSel %~ (min (length (_opEquip (_rbOptions w)) -1) . (+ 1))
| y > 0 = w & rbOptions . opSel %~ (max 0 . subtract 1)
| y < 0 = w & rbOptions . opSel %~ (min (length (_opEquip (_rbOptions w)) -1) . (+ y))
| y > 0 = w & rbOptions . opSel %~ (max 0 . subtract y)
| otherwise = w
moveTweakSel :: Int -> World -> World
moveTweakSel i w = case yourItem w ^? _Just . itTweaks . tweakParams of
Just l -> w & cWorld . lWorld . hud . hudElement . subInventory . examineInvSel . _Just %~ (`mod` length l) . subtract i
Just l -> moveSubSel i (length l) w
_ -> w
changeTweakParam :: Maybe Int -> Int -> World -> World