Cleanup, delete hotkeys when deleting item from inventory

This commit is contained in:
2025-01-01 14:04:25 +00:00
parent 0915e04b56
commit 7dd379d4bc
12 changed files with 497 additions and 492 deletions
+2 -9
View File
@@ -13,14 +13,12 @@ import Dodge.Data.World
import Dodge.DoubleTree import Dodge.DoubleTree
import Dodge.Euse import Dodge.Euse
import Dodge.HeldUse import Dodge.HeldUse
--import Dodge.Hotkey
import Dodge.Inventory import Dodge.Inventory
import Dodge.Item.Grammar import Dodge.Item.Grammar
--import Dodge.Item.Location
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
useItem :: Int -> PressType -> World -> World useItem :: Int -> PressType -> World -> Maybe World
useItem invid pt w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w $ do useItem invid pt w = fmap (worldEventFlags . at InventoryChange ?~ ()) $ do
cr <- w ^? cWorld . lWorld . creatures . ix 0 cr <- w ^? cWorld . lWorld . creatures . ix 0
itmloc <- allInvLocs (_crInv cr) ^? ix invid . _2 itmloc <- allInvLocs (_crInv cr) ^? ix invid . _2
let usedloc = useLocation itmloc let usedloc = useLocation itmloc
@@ -90,7 +88,6 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
& crpoint . crEquipment . at newp ?~ invid & crpoint . crEquipment . at newp ?~ invid
& crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp & crpoint . crInv . ix invid . itLocation . ilEquipSite ?~ newp
& onequip itm cr & onequip itm cr
-- & cWorld . lWorld %~ assignNewHotkey invid
MoveEquipment{_allocNewPos = newp, _allocOldPos = oldp} -> MoveEquipment{_allocNewPos = newp, _allocOldPos = oldp} ->
w w
& crpoint . crEquipment . at newp ?~ invid & crpoint . crEquipment . at newp ?~ invid
@@ -109,16 +106,12 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
& crpoint . crInv . ix rid . itLocation . ilEquipSite .~ Nothing & crpoint . crInv . ix rid . itLocation . ilEquipSite .~ Nothing
& onremove (itmat rid) cr & onremove (itmat rid) cr
& onequip itm cr & onequip itm cr
-- & cWorld . lWorld %~ removeHotkey rid
-- & cWorld . lWorld %~ assignNewHotkey invid
RemoveEquipment{_allocOldPos = oldp} -> RemoveEquipment{_allocOldPos = oldp} ->
w w
& crpoint . crEquipment . at oldp .~ Nothing & crpoint . crEquipment . at oldp .~ Nothing
& crpoint . crInv . ix invid . itLocation . ilEquipSite .~ Nothing & crpoint . crInv . ix invid . itLocation . ilEquipSite .~ Nothing
& onremove itm cr & onremove itm cr
where where
-- & cWorld . lWorld %~ removeHotkey invid
crpoint = cWorld . lWorld . creatures . ix (_crID cr) crpoint = cWorld . lWorld . creatures . ix (_crID cr)
itmat i = _crInv cr IM.! i itmat i = _crInv cr IM.! i
itm = itmat itRef itm = itmat itRef
+25 -32
View File
@@ -2,7 +2,7 @@ module Dodge.Creature.YourControl (
yourControl, yourControl,
) where ) where
import Dodge.Inventory import Control.Monad
import Data.Foldable import Data.Foldable
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
import Data.Maybe import Data.Maybe
@@ -12,6 +12,7 @@ import Dodge.Creature.Impulse.UseItem
import Dodge.Data.World import Dodge.Data.World
import Dodge.Hotkey import Dodge.Hotkey
import Dodge.InputFocus import Dodge.InputFocus
import Dodge.Inventory
import Dodge.WASD import Dodge.WASD
import Geometry import Geometry
import LensHelp import LensHelp
@@ -25,8 +26,8 @@ yourControl _ w
| Just NoSubInventory{} <- w ^? hud . hudElement . subInventory = | Just NoSubInventory{} <- w ^? hud . hudElement . subInventory =
w w
& cWorld . lWorld . creatures . ix 0 & cWorld . lWorld . creatures . ix 0
%~ (wasdWithAiming w . mouseActionsCr pkeys) %~ (wasdWithAiming w . setCrPosture pkeys)
& pressedMBEffectsTopInventory pkeys & tryClickUse pkeys
& handleHotkeys & handleHotkeys
| otherwise = | otherwise =
w & cWorld . lWorld . creatures . ix 0 %~ wasdWithAiming w w & cWorld . lWorld . creatures . ix 0 %~ wasdWithAiming w
@@ -36,17 +37,17 @@ yourControl _ w
handleHotkeys :: World -> World handleHotkeys :: World -> World
handleHotkeys w handleHotkeys w
| SDL.ScancodeLShift `M.member` _pressedKeys (_input w) | SDL.ScancodeLShift `M.member` _pressedKeys (_input w)
|| SDL.ScancodeRShift `M.member` _pressedKeys (_input w) = fromMaybe w $ do || SDL.ScancodeRShift `M.member` _pressedKeys (_input w)
let hks = mapMaybe scancodeToHotkey $ M.keys $ w ^. input . pressedKeys , hks <- mapMaybe scancodeToHotkey $ M.keys $ w ^. input . pressedKeys
invid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imSelectedItem , Just invid <- lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem
itid <- w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix invid . itID , Just itid <- lw ^? creatures . ix 0 . crInv . ix invid . itID =
return $ w & cWorld . lWorld %~ \lw -> foldl' (flip $ assignHotkey itid) lw hks w & cWorld . lWorld %~ \lw' -> foldl' (flip $ assignHotkey itid) lw' hks
| SDL.ScancodeLCtrl `M.member` _pressedKeys (_input w) | SDL.ScancodeLCtrl `M.member` _pressedKeys (_input w)
|| SDL.ScancodeRCtrl `M.member` _pressedKeys (_input w) = fromMaybe w $ do || SDL.ScancodeRCtrl `M.member` _pressedKeys (_input w)
hk <- listToMaybe . mapMaybe scancodeToHotkey $ M.keys $ w ^. input . pressedKeys , Just hk <- listToMaybe . mapMaybe scancodeToHotkey . M.keys $ w ^. input . pressedKeys
itid <- w ^? cWorld . lWorld . hotkeys . ix hk . unNInt , Just itid <- w ^? cWorld . lWorld . hotkeys . ix hk . unNInt
invid <- w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID , Just invid <- w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID =
return $ w & augInvDirectSelect (0,invid,mempty) w & augInvDirectSelect (0, invid, mempty)
| otherwise = | otherwise =
M.foldl' M.foldl'
useHotkey useHotkey
@@ -54,11 +55,12 @@ handleHotkeys w
(M.intersectionWith (,) thehotkeys (w ^. input . pressedKeys)) (M.intersectionWith (,) thehotkeys (w ^. input . pressedKeys))
where where
thehotkeys = M.mapKeys hotkeyToScancode $ w ^. cWorld . lWorld . hotkeys thehotkeys = M.mapKeys hotkeyToScancode $ w ^. cWorld . lWorld . hotkeys
lw = w ^. cWorld . lWorld
useHotkey :: World -> (NewInt ItmInt, PressType) -> World useHotkey :: World -> (NewInt ItmInt, PressType) -> World
useHotkey w (NInt itid, pt) = fromMaybe w $ do useHotkey w (NInt itid, pt) = fromMaybe w $ do
invid <- w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID invid <- w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID
return $ useItem invid pt w useItem invid pt w
hotkeyToScancode :: Hotkey -> SDL.Scancode hotkeyToScancode :: Hotkey -> SDL.Scancode
hotkeyToScancode x = case x of hotkeyToScancode x = case x of
@@ -152,34 +154,25 @@ aimTurn a cr = creatureTurnTowardDir a (x * 0.2) cr
{- | Set posture according to mouse presses. {- | Set posture according to mouse presses.
(should you be aiming without a selected item?) (should you be aiming without a selected item?)
-} -}
mouseActionsCr :: M.Map SDL.MouseButton Int -> Creature -> Creature setCrPosture :: M.Map SDL.MouseButton Int -> Creature -> Creature
mouseActionsCr pkeys setCrPosture pkeys
| SDL.ButtonRight `M.member` pkeys = crStance . posture .~ Aiming | SDL.ButtonRight `M.member` pkeys = crStance . posture .~ Aiming
| otherwise = crStance . posture .~ AtEase | otherwise = crStance . posture .~ AtEase
-- where tryClickUse :: M.Map SDL.MouseButton Int -> World -> World
-- noaction = fromMaybe True $ do tryClickUse pkeys w = fromMaybe w $ do
-- theaction <- cr ^? crManipulation . manObject . inInventory . iselAction ltime <- pkeys ^? ix SDL.ButtonLeft
-- return $ theaction == NoInvSelAction rtime <- pkeys ^? ix SDL.ButtonRight
guard $ ltime <= rtime && inTopInv
pressedMBEffectsTopInventory :: M.Map SDL.MouseButton Int -> World -> World invid <- w
pressedMBEffectsTopInventory pkeys w
| Just ltime <- pkeys ^? ix SDL.ButtonLeft
, Just rtime <- pkeys ^? ix SDL.ButtonRight
, ltime <= rtime && inTopInv =
fromMaybe w $ do
invid <-
w
^? cWorld . lWorld . creatures . ix 0 ^? cWorld . lWorld . creatures . ix 0
. crManipulation . crManipulation
. manObject . manObject
. imSelectedItem . imSelectedItem
return $ useItem invid (f ltime) w useItem invid (f ltime) w
| otherwise = w
where where
f 0 = InitialPress f 0 = InitialPress
f _ = ShortPress f _ = ShortPress
-- youhammerdown = set (cWorld . lWorld . creatures . ix 0 . crHammerPosition) HammerDown
inTopInv = case w ^. hud . hudElement of inTopInv = case w ^. hud . hudElement of
DisplayInventory{_subInventory = NoSubInventory{}} -> True DisplayInventory{_subInventory = NoSubInventory{}} -> True
_ -> False _ -> False
+1
View File
@@ -21,6 +21,7 @@ data ItemType
| TARGETING {_ibtTargeting :: TargetingType} | TARGETING {_ibtTargeting :: TargetingType}
| BULLETMOD {_ibtBulletMod :: BulletMod} | BULLETMOD {_ibtBulletMod :: BulletMod}
| STICKYMOD | STICKYMOD
| ITEMSCANNER
deriving (Eq, Ord, Show, Read) deriving (Eq, Ord, Show, Read)
data CraftType data CraftType
+7 -1
View File
@@ -1,6 +1,5 @@
--{-# LANGUAGE TupleSections #-} --{-# LANGUAGE TupleSections #-}
module Dodge.Inventory ( module Dodge.Inventory (
checkInvSlotsYou,
rmInvItem, rmInvItem,
destroyInvItem, destroyInvItem,
updateCloseObjects, updateCloseObjects,
@@ -46,10 +45,17 @@ destroyInvItem ::
World -> World ->
World World
destroyInvItem cid invid w = rmInvItem cid invid w & removeitloc destroyInvItem cid invid w = rmInvItem cid invid w & removeitloc
& removeithotkey
where where
removeitloc = fromMaybe id $ do removeitloc = fromMaybe id $ do
itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid . itID . unNInt itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid . itID . unNInt
return $ cWorld . lWorld . itemLocations . at itid .~ Nothing return $ cWorld . lWorld . itemLocations . at itid .~ Nothing
removeithotkey = fromMaybe id $ do
itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid . itID . unNInt
hk <- w ^? cWorld . lWorld . imHotkeys . unNIntMap . ix itid
return $
(cWorld . lWorld . imHotkeys . unNIntMap . at itid .~ Nothing)
. ( cWorld . lWorld . hotkeys . at hk .~ Nothing)
-- | after this the item at the inventory position will no longer exist -- | after this the item at the inventory position will no longer exist
rmInvItem :: rmInvItem ::
-22
View File
@@ -34,7 +34,6 @@ swapInvItems f i w = fromMaybe w $ do
& swapAnyExtraSelection i k & swapAnyExtraSelection i k
& checkConnection InventorySound disconnectItemS i k & checkConnection InventorySound disconnectItemS i k
& cWorld . lWorld . creatures . ix 0 %~ updatecreature k & cWorld . lWorld . creatures . ix 0 %~ updatecreature k
--x & swaphotkeys k
& updateselection & updateselection
& worldEventFlags . at InventoryChange ?~ () & worldEventFlags . at InventoryChange ?~ ()
& cWorld . lWorld %~ crUpdateItemLocations 0 & cWorld . lWorld %~ crUpdateItemLocations 0
@@ -43,35 +42,15 @@ swapInvItems f i w = fromMaybe w $ do
-- a rethink is maybe in order -- a rethink is maybe in order
& checkConnection InventoryConnectSound connectItemS i k & checkConnection InventoryConnectSound connectItemS i k
where where
-- & checkconnect k InventoryConnectSound connectItemS
-- cpos = fromMaybe 0 $ w ^? cWorld . lWorld . creatures . ix 0 . crPos
-- checkconnect k stype s w'
-- | p (i+1) || p (i-1)
-- || p (k+1) || p (k-1) = soundStart stype cpos s Nothing w'
-- | otherwise = w'
-- where
-- p j = maybe False not $ w' ^? cWorld . lWorld . creatures . ix 0 . crInv . ix j . itLocation . ilIsRoot
updatecreature k = updatecreature k =
(crInv %~ IM.safeSwapKeys i k) (crInv %~ IM.safeSwapKeys i k)
. (crManipulation . manObject . imSelectedItem .~ k) . (crManipulation . manObject . imSelectedItem .~ k)
-- . (crInvEquipped %~ IM.safeSwapKeys i k)
. swapSite i k . swapSite i k
. swapSite k i . swapSite k i
-- . (crInvHotkeys %~ IM.safeSwapKeys i k)
--x swaphotkeys k =
--x swapSite' i k
--x . swapSite' k i
--x . (cWorld . lWorld . imHotkeys %~ IM.safeSwapKeys i k)
cr = you w cr = you w
--swapSite a b = case cr ^? crInvEquipped . ix a of
swapSite a b = case cr ^? crInv . ix a . itLocation . ilEquipSite . _Just of swapSite a b = case cr ^? crInv . ix a . itLocation . ilEquipSite . _Just of
Just epos -> crEquipment . ix epos .~ b Just epos -> crEquipment . ix epos .~ b
Nothing -> id Nothing -> id
--swapSite' a b = case cr ^? crInvHotkeys . ix a of
--x swapSite' a b = case w ^? cWorld . lWorld . imHotkeys . ix a of
--x Just epos -> cWorld . lWorld . hotkeys . ix epos .~ b
--x Nothing -> id
swapAnyExtraSelection :: Int -> Int -> World -> World swapAnyExtraSelection :: Int -> Int -> World -> World
swapAnyExtraSelection i k w = fromMaybe w $ do swapAnyExtraSelection i k w = fromMaybe w $ do
@@ -98,4 +77,3 @@ isConnected x = case x ^. locLdtContext of
not (null $ x ^. locLDT . ldtRight) not (null $ x ^. locLDT . ldtRight)
|| not (null $ x ^. locLDT . ldtLeft) || not (null $ x ^. locLDT . ldtLeft)
_ -> True _ -> True
+1
View File
@@ -25,6 +25,7 @@ itemFromBase = \case
TARGETING tt -> targetingScope tt TARGETING tt -> targetingScope tt
BULLETMOD bm -> bulletModule bm BULLETMOD bm -> bulletModule bm
STICKYMOD -> stickyMod STICKYMOD -> stickyMod
ITEMSCANNER -> itemScanner
itemFromAmmoMag :: AmmoMagType -> Item itemFromAmmoMag :: AmmoMagType -> Item
itemFromAmmoMag at = case at of itemFromAmmoMag at = case at of
+1
View File
@@ -66,6 +66,7 @@ itemBaseName = \case
BULLETMOD (BulletModPayload btt) -> show btt BULLETMOD (BulletModPayload btt) -> show btt
BULLETMOD (BulletModEffect btt) -> show btt BULLETMOD (BulletModEffect btt) -> show btt
STICKYMOD -> "STICKYMOD" STICKYMOD -> "STICKYMOD"
ITEMSCANNER -> "ITEMSCANNER"
showAttachItem :: AttachType -> String showAttachItem :: AttachType -> String
showAttachItem t = case t of showAttachItem t = case t of
+1
View File
@@ -41,6 +41,7 @@ itemSPic it = case it ^. itType of
TARGETING{} -> defSPic TARGETING{} -> defSPic
BULLETMOD{} -> defSPic BULLETMOD{} -> defSPic
STICKYMOD -> defSPic STICKYMOD -> defSPic
ITEMSCANNER -> defSPic
craftItemSPic :: CraftType -> Shape craftItemSPic :: CraftType -> Shape
craftItemSPic = \case craftItemSPic = \case
+8 -1
View File
@@ -15,6 +15,7 @@ module Dodge.Item.Scope (
bulletModule, bulletModule,
bulletPayloadModule, bulletPayloadModule,
smokeReducer, smokeReducer,
itemScanner,
) where ) where
import Dodge.Item.Attach import Dodge.Item.Attach
@@ -46,6 +47,12 @@ stickyMod =
& itType .~ STICKYMOD & itType .~ STICKYMOD
& itUse .~ UseNothing & itUse .~ UseNothing
itemScanner :: Item
itemScanner =
defaultHeldItem
& itType .~ ITEMSCANNER
& itUse .~ UseNothing
bulletModule :: BulletMod -> Item bulletModule :: BulletMod -> Item
bulletModule bm = bulletModule bm =
@@ -80,7 +87,7 @@ remoteDetonator = makeAttach REMOTEDETONATOR
joystick :: Item joystick :: Item
joystick = makeAttach JOYSTICK joystick = makeAttach JOYSTICK
-- & itUse . uaParams .~ APLinkProjectile Nothing -- & itUse . uaParams .~ APLinkProjectile Nothing
--
gimbal :: Item gimbal :: Item
gimbal = makeAttach GIMBAL gimbal = makeAttach GIMBAL
+25 -24
View File
@@ -14,17 +14,13 @@ import Dodge.Base
import Dodge.Creature.Test import Dodge.Creature.Test
import Dodge.Data.Config import Dodge.Data.Config
import Dodge.Data.World import Dodge.Data.World
--import Dodge.Equipment
--import Dodge.InputFocus
import Dodge.SmoothScroll import Dodge.SmoothScroll
import Dodge.Viewpoints import Dodge.Viewpoints
import Dodge.WASD import Dodge.WASD
import Dodge.Zoning.Wall import Dodge.Zoning.Wall
import Geometry import Geometry
--import qualified IntMapHelp as IM
import LensHelp import LensHelp
import SDL (MouseButton (..)) import SDL (MouseButton (..))
--import qualified SDL
{- Update the screen camera rotation and position, including any in rold scope/remote camera modifiers; {- Update the screen camera rotation and position, including any in rold scope/remote camera modifiers;
update where your avatar's view is from. -} update where your avatar's view is from. -}
@@ -62,15 +58,19 @@ translateFloatingCamera theinput cam = fromMaybe cam $ do
return $ cam & camRot -~ angleBetween (theinput ^. mousePos) a return $ cam & camRot -~ angleBetween (theinput ^. mousePos) a
translateFloatingCameraKeys :: Input -> Camera -> Camera translateFloatingCameraKeys :: Input -> Camera -> Camera
translateFloatingCameraKeys theinput = (camCenter -~ thetran) . (camViewFrom -~ thetran) translateFloatingCameraKeys theinput cam =
cam
& camCenter -~ thetran
& camViewFrom -~ thetran
where where
thetran = 10 *.* wasdDir theinput thetran = rotateV (cam ^. camRot) $ negate 10 *.* wasdDir theinput
zoomFloatingCamera :: Input -> Camera -> Camera zoomFloatingCamera :: Input -> Camera -> Camera
zoomFloatingCamera theinput zoomFloatingCamera theinput
| ButtonRight `M.member` (theinput ^. mouseButtons) = | ButtonRight `M.member` (theinput ^. mouseButtons) =
camZoom *~ ((39 / 40) ^^ negate (getSmoothScrollValue theinput)) camZoom *~ ((39 / 40) ^^ negate (getSmoothScrollValue theinput))
| otherwise = id | otherwise = id
-- the 39/40 is taken from zoomSpeed -- the 39/40 is taken from zoomSpeed
updateInGameCamera :: Configuration -> World -> World updateInGameCamera :: Configuration -> World -> World
@@ -78,7 +78,6 @@ updateInGameCamera cfig w =
w w
& updateBounds cfig & updateBounds cfig
& wCam %~ moveZoomCamera cfig (w ^. input) (you w) w & wCam %~ moveZoomCamera cfig (w ^. input) (you w) w
-- & updateScopeZoom
& rotateCamera cfig & rotateCamera cfig
& over wCam (setViewDistance cfig) -- I think this should be updated after the zoom? & over wCam (setViewDistance cfig) -- I think this should be updated after the zoom?
@@ -101,7 +100,8 @@ moveZoomCamera cfig theinput cr w campos =
guard (SDL.ButtonRight `M.member` _mouseButtons theinput) guard (SDL.ButtonRight `M.member` _mouseButtons theinput)
i <- cr ^? crManipulation . manObject . imSelectedItem i <- cr ^? crManipulation . manObject . imSelectedItem
fmap docamrot (cr ^? crInv . ix i . itUse . uScope . opticPos) fmap docamrot (cr ^? crInv . ix i . itUse . uScope . opticPos)
noscopeoffset = docamrot $ noscopeoffset =
docamrot $
((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos theinput ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos theinput
newzoom = fromMaybe (newDefaultZoom * newItemZoom) $ do newzoom = fromMaybe (newDefaultZoom * newItemZoom) $ do
i <- cr ^? crManipulation . manObject . imSelectedItem i <- cr ^? crManipulation . manObject . imSelectedItem
@@ -135,6 +135,21 @@ moveZoomCamera cfig theinput cr w campos =
viewDistanceFromItems :: Creature -> Float viewDistanceFromItems :: Creature -> Float
viewDistanceFromItems _ = 1 viewDistanceFromItems _ = 1
rotateCamera :: Configuration -> World -> World
rotateCamera cfig w
| Just ltime <- pkeys ^? ix SDL.ButtonLeft
, Just rtime <- pkeys ^? ix SDL.ButtonRight
, ltime > rtime =
w & wCam . camRot -~ rotation
| otherwise = ifConfigWallRotate cfig (w ^. input . mouseButtons) w
where
pkeys = w ^. input . mouseButtons
rotation =
maybe
0
(angleBetween $ w ^. input . mousePos)
(w ^. input . heldPos . at SDL.ButtonRight)
ifConfigWallRotate :: Configuration -> M.Map MouseButton Int -> World -> World ifConfigWallRotate :: Configuration -> M.Map MouseButton Int -> World -> World
ifConfigWallRotate cfig mbs ifConfigWallRotate cfig mbs
| _gameplay_rotate_to_wall cfig && not (SDL.ButtonRight `M.member` mbs) = | _gameplay_rotate_to_wall cfig && not (SDL.ButtonRight `M.member` mbs) =
@@ -163,21 +178,6 @@ doWallRotate wl w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl) - (w ^. wC
b = a * (4 / pi) b = a * (4 / pi)
b' = fromIntegral (round b :: Int) b' = fromIntegral (round b :: Int)
rotateCamera :: Configuration -> World -> World
rotateCamera cfig w
| Just ltime <- pkeys ^? ix SDL.ButtonLeft
, Just rtime <- pkeys ^? ix SDL.ButtonRight
, ltime > rtime = w & wCam . camRot -~ rotation
| otherwise = ifConfigWallRotate cfig (w ^. input . mouseButtons) w
where
pkeys = w ^. input . mouseButtons
rotation =
maybe
0
(angleBetween $ w ^. input . mousePos)
(w ^. input . heldPos . at SDL.ButtonRight)
zoomFromItem :: ItZoom -> Float zoomFromItem :: ItZoom -> Float
zoomFromItem ItZoom{_izMax = zMax, _izMin = zMin, _izFac = zFac} = zoomFromItem ItZoom{_izMax = zMax, _izMin = zMin, _izFac = zFac} =
min zMax $ max zMin zFac min zMax $ max zMin zFac
@@ -214,7 +214,8 @@ findBoundDists cfig w
-- though I'm not sure how often it should be updated -- though I'm not sure how often it should be updated
updateBounds :: Configuration -> World -> World updateBounds :: Configuration -> World -> World
updateBounds cfig w = case (w ^. cWorld . cClock) `mod` 5 of updateBounds cfig w = case (w ^. cWorld . cClock) `mod` 5 of
0 -> w 0 ->
w
& wCam . camBoundDist .~ bdists & wCam . camBoundDist .~ bdists
& wCam . camBoundBox & wCam . camBoundBox
.~ map ((+.+ w ^. wCam . camCenter) . rotateV (w ^. wCam . camRot)) (rectNSWE n s w' e) .~ map ((+.+ w ^. wCam . camCenter) . rotateV (w ^. wCam . camRot)) (rectNSWE n s w' e)
+77 -52
View File
@@ -1,13 +1,10 @@
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
module Dodge.Update.Input.InGame ( module Dodge.Update.Input.InGame (
updateUseInputInGame, updateUseInputInGame,
updateMouseInGame, updateMouseInGame,
) where ) where
import Dodge.Update.Input.DebugTest
import Dodge.Item.InvSize
import Data.Monoid
import NewInt
import Control.Applicative import Control.Applicative
import Control.Monad import Control.Monad
import Data.Foldable import Data.Foldable
@@ -16,6 +13,7 @@ import qualified Data.IntSet as IS
import Data.List (sort) import Data.List (sort)
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
import Data.Maybe import Data.Maybe
import Data.Monoid
import Dodge.Button.Event import Dodge.Button.Event
import Dodge.Camera import Dodge.Camera
import Dodge.Creature.Action import Dodge.Creature.Action
@@ -25,16 +23,19 @@ import Dodge.DisplayInventory
import Dodge.Event.Test import Dodge.Event.Test
import Dodge.Inventory import Dodge.Inventory
import Dodge.Inventory.Add import Dodge.Inventory.Add
import Dodge.Item.InvSize
import Dodge.ListDisplayParams import Dodge.ListDisplayParams
import Dodge.Menu import Dodge.Menu
import Dodge.Save import Dodge.Save
import Dodge.SelectionSections import Dodge.SelectionSections
import Dodge.SoundLogic import Dodge.SoundLogic
import Dodge.Terminal import Dodge.Terminal
import Dodge.Update.Input.DebugTest
import Dodge.Update.Input.Text import Dodge.Update.Input.Text
import Dodge.WorldPos import Dodge.WorldPos
import Geometry import Geometry
import LensHelp import LensHelp
import NewInt
import SDL import SDL
updateUseInputInGame :: Universe -> Universe updateUseInputInGame :: Universe -> Universe
@@ -47,13 +48,17 @@ updateUseInputInGame u = updateFunctionKeys $ case u ^. uvWorld . hud . hudEleme
& uvWorld . hud . hudElement . subInventory & uvWorld . hud . hudElement . subInventory
%~ docombineregexinput sss msel %~ docombineregexinput sss msel
& uvWorld . worldEventFlags . at CombineInventoryChange ?~ () & uvWorld . worldEventFlags . at CombineInventoryChange ?~ ()
_ | disel ^? _Just . _1 == Just (-1) -> _
u & uvWorld . hud . hudElement | disel ^? _Just . _1 == Just (-1) ->
u
& uvWorld . hud . hudElement
%~ dodisplayregexinput diInvFilter diInvFilter (-1) %~ dodisplayregexinput diInvFilter diInvFilter (-1)
& uvWorld . worldEventFlags . at InventoryChange ?~ () & uvWorld . worldEventFlags . at InventoryChange ?~ ()
& uvWorld %~ setInvPosFromSS & uvWorld %~ setInvPosFromSS
_ | disel ^? _Just . _1 == Just 2 -> _
u & uvWorld . hud . hudElement | disel ^? _Just . _1 == Just 2 ->
u
& uvWorld . hud . hudElement
%~ dodisplayregexinput diCloseFilter diCloseFilter 2 %~ dodisplayregexinput diCloseFilter diCloseFilter 2
& uvWorld . worldEventFlags . at InventoryChange ?~ () & uvWorld . worldEventFlags . at InventoryChange ?~ ()
& uvWorld %~ setInvPosFromSS & uvWorld %~ setInvPosFromSS
@@ -78,12 +83,14 @@ updateUseInputInGame u = updateFunctionKeys $ case u ^. uvWorld . hud . hudEleme
& ciFilter .~ filts' & ciFilter .~ filts'
updateMouseInGame :: Configuration -> World -> World updateMouseInGame :: Configuration -> World -> World
updateMouseInGame cfig w = case w ^? input . mouseButtons . ix ButtonLeft of updateMouseInGame cfig w
Just 0 -> updateMouseClickInGame cfig w | Just 0 <- lbpress = updateMouseClickInGame cfig w
Just _ -> updateMouseHeldInGame cfig w | Just _ <- lbpress = updateMouseHeldInGame cfig w
Nothing -> case w ^? input . mouseButtonsReleased . ix ButtonLeft of | Just 0 <- lbrelease = updateMouseReleaseInGame w
Just 0 -> updateMouseReleaseInGame w | otherwise = w
_ -> w where
lbpress = w ^? input . mouseButtons . ix ButtonLeft
lbrelease = w ^? input . mouseButtonsReleased . ix ButtonLeft
updateMouseHeldInGame :: Configuration -> World -> World updateMouseHeldInGame :: Configuration -> World -> World
updateMouseHeldInGame cfig w = case w ^. input . mouseContext of updateMouseHeldInGame cfig w = case w ^. input . mouseContext of
@@ -95,20 +102,21 @@ updateMouseHeldInGame cfig w = case w ^. input . mouseContext of
OverInvDrag k mmouseover ab bn -> doDrag 30 k mmouseover ab bn w OverInvDrag k mmouseover ab bn -> doDrag 30 k mmouseover ab bn w
_ -> w _ -> w
doDrag ::
doDrag :: Int Int ->
-> Int Int ->
-> Maybe (Int, Int) Maybe (Int, Int) ->
-> Maybe (Int, Int) Maybe (Int, Int) ->
-> Maybe (Int, Int) Maybe (Int, Int) ->
-> World World ->
-> World World
doDrag 0 _ _ _ _ w = w doDrag 0 _ _ _ _ w = w
doDrag n k mmouseover ab bn w = fromMaybe w $ do doDrag n k mmouseover ab bn w = fromMaybe w $ do
ss <- w ^? hud . hudElement . diSections . ix k . ssItems ss <- w ^? hud . hudElement . diSections . ix k . ssItems
x <- mmouseover x <- mmouseover
is <- w ^? hud . hudElement . diSelection . _Just . _3 is <- w ^? hud . hudElement . diSelection . _Just . _3
return $ if concurrentIS is return $
if concurrentIS is
then shiftInvItems n k x ab bn is ss w then shiftInvItems n k x ab bn is ss w
else collectInvItems k is w else collectInvItems k is w
@@ -130,10 +138,15 @@ tryPickupSelected k mpos w = do
let slotsneeded = alaf Sum foldMap (itInvHeight . _flIt) itmstopickup let slotsneeded = alaf Sum foldMap (itInvHeight . _flIt) itmstopickup
guard $ nfreeslots >= slotsneeded guard $ nfreeslots >= slotsneeded
return $ case mpos of return $ case mpos of
Just (0,j) -> foldr (pickUpItemAt j 0) w itmstopickup Just (0, j) ->
& hud . hudElement . diSelection ?~ (0,j foldr (pickUpItemAt j 0) w itmstopickup
, IS.fromDistinctAscList [j..j+IS.size xs-1]) & hud . hudElement . diSelection
_ -> foldl' (flip $ pickUpItem 0) w itmstopickup ?~ ( 0
, j
, IS.fromDistinctAscList [j .. j + IS.size xs -1]
)
_ ->
foldl' (flip $ pickUpItem 0) w itmstopickup
& hud . hudElement . diSelection . _Just . _3 %~ const mempty & hud . hudElement . diSelection . _Just . _3 %~ const mempty
where where
g i = do g i = do
@@ -145,12 +158,18 @@ updateMouseReleaseInGame w = case w ^. input . mouseContext of
OverInvDrag k mpos _ _ -> OverInvDrag k mpos _ _ ->
input . mouseContext .~ MouseInGame $ input . mouseContext .~ MouseInGame $
fromMaybe w $ tryDropSelected mpos w <|> tryPickupSelected k mpos w fromMaybe w $ tryDropSelected mpos w <|> tryPickupSelected k mpos w
OverInvDragSelect ssel mesel | ScancodeLShift `M.member` (w ^. input . pressedKeys) OverInvDragSelect ssel mesel
-> w & input . mouseContext .~ MouseInGame | ScancodeLShift `M.member` (w ^. input . pressedKeys) ->
& hud . hudElement . diSelection . _Just . _3 %~ getuniques w & input . mouseContext .~ MouseInGame
(maybe mempty (h ssel) & hud . hudElement . diSelection . _Just . _3
%~ getuniques
( maybe
mempty
(h ssel)
( guard (ssel ^? _1 == w ^? hud . hudElement . diSelection . _Just . _1) ( guard (ssel ^? _1 == w ^? hud . hudElement . diSelection . _Just . _1)
>> mesel ^? _Just)) >> mesel ^? _Just
)
)
OverInvDragSelect _ Nothing -> OverInvDragSelect _ Nothing ->
w & input . mouseContext .~ MouseInGame w & input . mouseContext .~ MouseInGame
& hud . hudElement . diSelection . _Just . _3 %~ const mempty & hud . hudElement . diSelection . _Just . _3 %~ const mempty
@@ -182,14 +201,18 @@ updateMouseClickInGame cfig w = case w ^. input . mouseContext of
return $ return $
w & input . mouseContext w & input . mouseContext
.~ OverInvDragSelect ysel Nothing .~ OverInvDragSelect ysel Nothing
OverInvSelect (-1,_) | selsec == Just (-1) -> w OverInvSelect (-1, _)
| selsec == Just (-1) ->
w
& hud . hudElement . diSelection %~ endRegex (-1) w & hud . hudElement . diSelection %~ endRegex (-1) w
& hud . hudElement . diInvFilter .~ Nothing & hud . hudElement . diInvFilter .~ Nothing
OverInvSelect (2,_) | selsec == Just 2 -> w OverInvSelect (2, _)
| selsec == Just 2 ->
w
& hud . hudElement . diSelection %~ endRegex 2 w & hud . hudElement . diSelection %~ endRegex 2 w
& hud . hudElement . diCloseFilter .~ Nothing & hud . hudElement . diCloseFilter .~ Nothing
OverInvSelect x | ScancodeLShift `M.member` (w ^. input . pressedKeys ) OverInvSelect x | ScancodeLShift `M.member` (w ^. input . pressedKeys) ->
-> fromMaybe w $ do fromMaybe w $ do
guard (isGroupSelectableSection $ fst x) guard (isGroupSelectableSection $ fst x)
return $ w & input . mouseContext .~ OverInvDragSelect x (Just $ snd x) return $ w & input . mouseContext .~ OverInvDragSelect x (Just $ snd x)
OverInvSelect x -> startDrag x cfig w OverInvSelect x -> startDrag x cfig w
@@ -232,9 +255,11 @@ updateMouseClickInGame cfig w = case w ^. input . mouseContext of
f (x, y) = (x, y, mempty) f (x, y) = (x, y, mempty)
selsec = w ^? hud . hudElement . diSelection . _Just . _1 selsec = w ^? hud . hudElement . diSelection . _Just . _1
endRegex :: Int -> World endRegex ::
-> Maybe (Int,Int,IS.IntSet) Int ->
-> Maybe (Int,Int,IS.IntSet) World ->
Maybe (Int, Int, IS.IntSet) ->
Maybe (Int, Int, IS.IntSet)
endRegex i w = fromMaybe id $ do endRegex i w = fromMaybe id $ do
sss <- w ^? hud . hudElement . diSections sss <- w ^? hud . hudElement . diSections
let j = fromMaybe 0 $ do let j = fromMaybe 0 $ do
@@ -243,9 +268,10 @@ endRegex i w = fromMaybe id $ do
return k return k
return $ ssSetCursor (ssLookupDown i j) sss return $ ssSetCursor (ssLookupDown i j) sss
endCombineRegex ::World endCombineRegex ::
-> Maybe (Int,Int,IS.IntSet) World ->
-> Maybe (Int,Int,IS.IntSet) Maybe (Int, Int, IS.IntSet) ->
Maybe (Int, Int, IS.IntSet)
endCombineRegex w = fromMaybe id $ do endCombineRegex w = fromMaybe id $ do
sss <- w ^? hud . hudElement . subInventory . ciSections sss <- w ^? hud . hudElement . subInventory . ciSections
let j = fromMaybe 0 $ do let j = fromMaybe 0 $ do
@@ -256,7 +282,8 @@ endCombineRegex w = fromMaybe id $ do
startDrag :: (Int, Int) -> Configuration -> World -> World startDrag :: (Int, Int) -> Configuration -> World -> World
startDrag (a, b) cfig w = setcontext startDrag (a, b) cfig w = setcontext
. fromMaybe (augInvDirectSelect (a, b, IS.singleton b) w) $ do . fromMaybe (augInvDirectSelect (a, b, IS.singleton b) w)
$ do
(i, _, xs) <- w ^? hud . hudElement . diSelection . _Just (i, _, xs) <- w ^? hud . hudElement . diSelection . _Just
guard $ i == a && b `IS.member` xs guard $ i == a && b `IS.member` xs
return w return w
@@ -518,11 +545,14 @@ spaceAction w = case w ^. hud . hudElement of
DisplayInventory{_subInventory = NoSubInventory{}} -> fromMaybe w $ do DisplayInventory{_subInventory = NoSubInventory{}} -> fromMaybe w $ do
cobj <- selCloseObj w cobj <- selCloseObj w
return $ case cobj of return $ case cobj of
(Left flit) -> pickUpItem 0 flit w (Left flit) ->
pickUpItem 0 flit w
& worldEventFlags . at InventoryChange ?~ () & worldEventFlags . at InventoryChange ?~ ()
(Right but) -> doButtonEvent (_btEvent but) but w (Right but) ->
doButtonEvent (_btEvent but) but w
& worldEventFlags . at InventoryChange ?~ () & worldEventFlags . at InventoryChange ?~ ()
DisplayInventory{_subInventory = DisplayTerminal{}} -> w DisplayInventory{_subInventory = DisplayTerminal{}} ->
w
& hud . hudElement . subInventory .~ NoSubInventory & hud . hudElement . subInventory .~ NoSubInventory
& worldEventFlags . at InventoryChange ?~ () & worldEventFlags . at InventoryChange ?~ ()
_ -> w & hud . hudElement . subInventory .~ NoSubInventory _ -> w & hud . hudElement . subInventory .~ NoSubInventory
@@ -575,17 +605,13 @@ toggleTweakInv w = case w ^? hud . hudElement . subInventory of
where where
thepointer = hud . hudElement . subInventory thepointer = hud . hudElement . subInventory
tryCombine :: tryCombine :: (Int, Int) -> World -> World
(Int, Int) ->
World ->
World
tryCombine (i, j) w = fromMaybe w $ do tryCombine (i, j) w = fromMaybe w $ do
sss <- w ^? hud . hudElement . subInventory . ciSections sss <- w ^? hud . hudElement . subInventory . ciSections
CombinableItem is it <- sss ^? ix i . ssItems . ix j . siPayload CombinableItem is it <- sss ^? ix i . ssItems . ix j . siPayload
p <- w ^? cWorld . lWorld . creatures . ix 0 . crPos p <- w ^? cWorld . lWorld . creatures . ix 0 . crPos
return $ return $
snd (createItemYou it (foldr (destroyInvItem 0) w (sort is))) snd (createItemYou it (foldr (destroyInvItem 0) w (sort is)))
-- & cWorld . lWorld . creatures . ix 0 . crHammerPosition .~ HammerDown
& soundStart InventorySound p wrench1S Nothing & soundStart InventorySound p wrench1S Nothing
& hud . hudElement . diSelection . _Just . _3 .~ mempty & hud . hudElement . diSelection . _Just . _3 .~ mempty
@@ -594,4 +620,3 @@ maybeExitCombine w
| ButtonRight `M.member` (w ^. input . mouseButtons) = w | ButtonRight `M.member` (w ^. input . mouseButtons) = w
| otherwise = | otherwise =
w & hud . hudElement . subInventory .~ NoSubInventory w & hud . hudElement . subInventory .~ NoSubInventory
+288 -290
View File
File diff suppressed because it is too large Load Diff