From 9ada489993b1ea1f0e6055e8b2d98512b48f8631 Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 27 Dec 2022 14:46:13 +0000 Subject: [PATCH] Cleanup --- src/Dodge/Data/HUD.hs | 4 +-- src/Dodge/Inventory.hs | 43 +++++++++++------------- src/Dodge/Update/Input.hs | 2 -- src/Dodge/Update/Scroll.hs | 69 ++++++++++++++++++++++---------------- 4 files changed, 62 insertions(+), 56 deletions(-) diff --git a/src/Dodge/Data/HUD.hs b/src/Dodge/Data/HUD.hs index 1637b5da3..06baa4318 100644 --- a/src/Dodge/Data/HUD.hs +++ b/src/Dodge/Data/HUD.hs @@ -20,8 +20,8 @@ data HUDElement data SubInventory = NoSubInventory - | ExamineInventory {_examineInvSel :: Maybe Int} - | CombineInventory {_combineInvSel :: Maybe Int} + | ExamineInventory {_subInvSel :: Maybe Int} + | CombineInventory {_subInvSel :: Maybe Int} | LockedInventory | DisplayTerminal {_termID :: Int} deriving (Eq, Ord, Show, Read) --Generic, Flat) diff --git a/src/Dodge/Inventory.hs b/src/Dodge/Inventory.hs index 67dd2cf27..142f97cae 100644 --- a/src/Dodge/Inventory.hs +++ b/src/Dodge/Inventory.hs @@ -50,22 +50,25 @@ rmInvItem :: Int -> World -> World -rmInvItem cid invid w = case w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid . itUse . useAmount of - Just x | x > 1 -> w & cWorld . lWorld . creatures . ix cid . crInv . ix invid . itUse . useAmount %~ subtract 1 +rmInvItem cid invid w = case w ^? getcid . crInv . ix invid . itUse . useAmount of + Just x | x > 1 -> w & pointcid . crInv . ix invid . itUse . useAmount %~ subtract 1 _ -> w - & cWorld . lWorld . creatures . ix cid . crInv %~ f - & cWorld . lWorld . creatures . ix cid . crInvSel %~ stopCrInvSelAction - & cWorld . lWorld . creatures . ix cid . crInvSel . iselPos %~ g - & cWorld . lWorld . creatures . ix cid . crLeftInvSel %~ g' + & pointcid . crInv %~ f + & pointcid . crInvSel %~ stopCrInvSelAction + & pointcid . crInvSel . iselPos %~ g + & pointcid . crLeftInvSel %~ g' & removeAnySlotEquipment & dounequipfunction & doanyitemeffect - & cWorld . lWorld . creatures . ix cid . crInvEquipped %~ IM.delete invid - & cWorld . lWorld . creatures . ix cid . crInvEquipped %~ IM.mapKeys g + & pointcid . crInvEquipped %~ IM.delete invid + & pointcid . crInvEquipped %~ IM.mapKeys g where -- TODO check whether this can be mapKeysMonotonic + getcid = cWorld . lWorld . creatures . ix cid + pointcid = cWorld . lWorld . creatures . ix cid + stopCrInvSelAction (InvSel i a) | i == invid = InvSel i NoInvSelAction | otherwise = InvSel i a @@ -78,9 +81,9 @@ rmInvItem cid invid w = case w ^? cWorld . lWorld . creatures . ix cid . crInv . rmf <- itm ^? itEffect . ieOnDrop return $ doInvEffect rmf itm cr removeAnySlotEquipment = case w ^? cWorld . lWorld . creatures . ix cid . crInvEquipped . ix invid of - Just epos -> cWorld . lWorld . creatures . ix cid . crEquipment . at epos .~ Nothing + Just epos -> pointcid . crEquipment . at epos .~ Nothing Nothing -> id - maxk = fmap fst $ IM.lookupMax $ w ^?! cWorld . lWorld . creatures . ix cid . crInv + maxk = fmap fst $ IM.lookupMax $ cr ^?! crInv f inv = let (xs, ys) = IM.split invid inv in xs `IM.union` IM.mapKeys (subtract 1) ys @@ -143,13 +146,7 @@ selNumCol :: Int -> World -> Color selNumCol i w = fromMaybe white $ trimapAugmentInv _itInvColor invDimColor closeObjectCol w IM.!? i invSelPos :: World -> Int -invSelPos w = splitgap + (foldl' (+) 0 . fst $ IM.split invsel (augmentedInvSizes w)) - where - invsel = yourInvSel w - splitgap = 0 --- splitgap --- | invsel < length (yourInv w) = 0 --- | otherwise = 1 +invSelPos w = sum . fst $ IM.split (yourInvSel w) (augmentedInvSizes w) updateTerminal :: World -> World updateTerminal = checkTermDist @@ -204,8 +201,6 @@ updateRBList w & setEquipActivation Nothing -> w & rbOptions .~ NoRightButtonOptions where - -- | otherwise = w & rbOptions .~ NoRightButtonOptions - curinvid = crSel cr cr = you w @@ -318,15 +313,15 @@ changeInvSel i w | n == 0 = w | yourInvSel w < n = w - & cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ (`mod` n) . subtract i - & cWorld . lWorld . creatures . ix 0 . crInvSel . iselAction .~ NoInvSelAction + & pointcrInvSel . iselPos %~ (`mod` n) . subtract i + & pointcrInvSel . iselAction .~ NoInvSelAction | otherwise = w - & cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ ((+ n) . (`mod` numCO) . subtract (i + n)) - & cWorld . lWorld . creatures . ix 0 . crInvSel . iselAction .~ NoInvSelAction + & pointcrInvSel . iselPos %~ ((+ n) . (`mod` numCO) . subtract (i + n)) + & pointcrInvSel . iselAction .~ NoInvSelAction where -- arguably this should jump the invpos into the inventory proper - + pointcrInvSel = cWorld . lWorld . creatures . ix 0 . crInvSel n = length $ w ^?! cWorld . lWorld . creatures . ix 0 . crInv numCO = length $ w ^. cWorld . lWorld . closeObjects diff --git a/src/Dodge/Update/Input.hs b/src/Dodge/Update/Input.hs index 9b66dfef7..4d46bff1d 100644 --- a/src/Dodge/Update/Input.hs +++ b/src/Dodge/Update/Input.hs @@ -4,8 +4,6 @@ module Dodge.Update.Input , doInputScreenInput ) where ---import Dodge.Inventory.SelectionList ---import Dodge.Render.HUD import Dodge.Terminal.LeftButton import Dodge.Save import Dodge.Debug.Terminal diff --git a/src/Dodge/Update/Scroll.hs b/src/Dodge/Update/Scroll.hs index 4ef1c0128..df69b0e30 100644 --- a/src/Dodge/Update/Scroll.hs +++ b/src/Dodge/Update/Scroll.hs @@ -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