Cleanup. Probable leak when inventory is large enough for scrolling
This commit is contained in:
+30
-35
@@ -3,52 +3,41 @@ module Dodge.Update.Scroll (
|
||||
) where
|
||||
|
||||
import Control.Monad
|
||||
import Geometry
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Dodge.Base
|
||||
import Dodge.Data.Universe
|
||||
--import Dodge.HeldScroll
|
||||
import Dodge.Inventory
|
||||
import Dodge.SelectionSections
|
||||
--import Dodge.SoundLogic
|
||||
import Dodge.Terminal
|
||||
--import Dodge.Tweak
|
||||
--import qualified IntMapHelp as IM
|
||||
import Geometry
|
||||
import LensHelp
|
||||
import SDL
|
||||
|
||||
updateWheelEvent :: Int -> World -> World
|
||||
updateWheelEvent yi w = case w ^. hud . hudElement of
|
||||
-- DisplayCarte
|
||||
-- | bdown ButtonRight -> w & hud . carteZoom %~ min 0.75 . max 0.05 . ((1 + y * 0.1) *)
|
||||
-- | otherwise -> w & cWorld . lWorld . selLocation %~ (`mod` numLocs) . (+ yi)
|
||||
DisplayInventory{_subInventory = NoSubInventory{}}
|
||||
-- functions that modify the inventory should be centralised so that
|
||||
-- this lock can be sensibly applied, perhaps
|
||||
| w ^?! cWorld . lWorld . creatures . ix 0 . crInvLock -> w
|
||||
| bdown ButtonRight -> case _rbOptions w of
|
||||
EquipOptions{} -> w & rbOptions . opSel %~ scrollRBOption yi rbscrollmax
|
||||
NoRightButtonOptions -> selectedItemScroll yi w
|
||||
| bdown ButtonLeft -> w & wCam . camZoom +~ y
|
||||
| invKeyDown -> changeSwapSel yi w
|
||||
| otherwise -> scrollAugInvSel yi w
|
||||
DisplayInventory{_subInventory = ExamineInventory}
|
||||
-- | invKeyDown
|
||||
-> scrollAugInvSel yi w
|
||||
-- | otherwise -> w
|
||||
DisplayInventory{_subInventory = CombineInventory{}} -> w & moveCombineSel yi
|
||||
DisplayInventory{_subInventory = DisplayTerminal tmid} -> terminalWheelEvent yi tmid w
|
||||
_ -> w
|
||||
updateWheelEvent yi w = case w ^. hud . hudElement . subInventory of
|
||||
NoSubInventory -> updateBaseWheelEvent yi w
|
||||
ExamineInventory -> updateBaseWheelEvent yi w
|
||||
CombineInventory{} -> w & moveCombineSel yi
|
||||
DisplayTerminal tmid -> terminalWheelEvent yi tmid w
|
||||
|
||||
updateBaseWheelEvent :: Int -> World -> World
|
||||
updateBaseWheelEvent yi w
|
||||
| Just True <- w ^? cWorld . lWorld . creatures . ix 0 . crInvLock = w
|
||||
| bdown ButtonRight = case _rbOptions w of
|
||||
EquipOptions{} -> w & rbOptions . opSel %~ scrollRBOption yi rbscrollmax
|
||||
NoRightButtonOptions -> selectedItemScroll yi w
|
||||
| bdown ButtonLeft = w & wCam . camZoom +~ y
|
||||
| invKeyDown = changeSwapSel yi w
|
||||
| otherwise = scrollAugInvSel yi w
|
||||
where
|
||||
invKeyDown = ScancodeCapsLock `M.member` _pressedKeys (_input w)
|
||||
y = fromIntegral yi
|
||||
bdown b = b `M.member` _mouseButtons (_input w)
|
||||
rbscrollmax = fromMaybe 1 $ do
|
||||
invid <- you w ^? crManipulation . manObject . imSelectedItem
|
||||
esite <- you w ^? crInv . ix invid . itUse . uequipEffect . eeType
|
||||
return $ length $ eqSiteToPositions esite
|
||||
y = fromIntegral yi
|
||||
-- numLocs = (fst . IM.findMax $ (w ^. cWorld . lWorld . seenLocations)) + 1
|
||||
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
|
||||
@@ -58,10 +47,17 @@ selectedItemScroll scrollamount w = fromMaybe w $ do
|
||||
|
||||
itemScroll :: Int -> Int -> Item -> World -> World
|
||||
itemScroll yi invid itm w = case itm ^. itType of
|
||||
ATTACH ZOOMSCOPE -> updateScopeZoom w
|
||||
HELD ALTERIFLE | yi /= 0 -> w
|
||||
& cWorld . lWorld . creatures . ix 0 . crInv . ix invid
|
||||
. itUse . heldAim . aimMuzzles . ix 0 . mzAmmoSlot %~ ((`mod` 2) . (+1))
|
||||
ATTACH ZOOMSCOPE -> updateScopeZoom w
|
||||
HELD ALTERIFLE
|
||||
| yi /= 0 ->
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix 0 . crInv . ix invid
|
||||
. itUse
|
||||
. heldAim
|
||||
. aimMuzzles
|
||||
. ix 0
|
||||
. mzAmmoSlot
|
||||
%~ ((`mod` 2) . (+ 1))
|
||||
_ -> w
|
||||
|
||||
-- note that your _crInvLock does not apply to this TODO check that this is what
|
||||
@@ -110,7 +106,6 @@ zoomOutLongGun sc = fromMaybe sc $ do
|
||||
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