Allow for left click to start and pause reloading when aiming

This commit is contained in:
2022-06-22 18:18:25 +01:00
parent 3609bdb4fd
commit 4d1b5d3ca8
6 changed files with 20 additions and 15 deletions
+14 -1
View File
@@ -7,6 +7,8 @@ import Dodge.Inventory
import Dodge.Reloading
import qualified Data.IntMap.Strict as IM
import qualified Data.Map.Strict as M
import qualified SDL
--import qualified Data.IntSet as IS
import Control.Lens
import Data.Maybe
@@ -22,7 +24,7 @@ useItem cr' w = fromMaybe (f w) $ do
itemEffect :: Creature -> Item -> World -> World
itemEffect cr it w = case it ^? itUse of
Just RightUse {_rUse = eff,_useMods = usemods}
-> hammerTest $ foldr ($) eff usemods it cr
-> hammerTest $ tryClickReload cr it w $ foldr ($) eff usemods it cr
Just LeftUse {} -> doequipmentchange
Just EquipUse{} -> doequipmentchange
-- ConsumeUse will cause problems if the item is not selected
@@ -37,6 +39,17 @@ itemEffect cr it w = case it ^? itUse of
doequipmentchange = setuhamdown $ hammerTest (toggleEquipmentAt (_rbOptions w) (crSel cr) cr
. activateEquipmentAt (_rbOptions w) cr)
tryClickReload :: Creature -> Item -> World -> (World -> World) -> World -> World
tryClickReload cr it w f
| _crID cr == _yourID w && itNeedsLoading it && _mouseButtons w M.!? SDL.ButtonLeft == Just False
= crToggleReloading cr
| otherwise = f
itNeedsLoading :: Item -> Bool
itNeedsLoading it = _laLoaded ic == 0 || not (_laPrimed ic)
where
ic = _itConsumption it
activateEquipmentAt :: RightButtonOptions -> Creature -> World -> World
activateEquipmentAt rbo cr = creatures . ix (_crID cr) %~ case (rbo ^? opActivateEquipment . activateEquipment, rbo ^? opActivateEquipment . deactivateEquipment) of
(Just i,_) -> crLeftInvSel ?~ i
+1 -3
View File
@@ -68,11 +68,9 @@ handleMouseMotionEvent mmev u = Just $ u & uvWorld . mousePos .~ V2
handleMouseButtonEvent :: MouseButtonEventData -> World -> World
handleMouseButtonEvent mbev = case mouseButtonEventMotion mbev of
Released -> mouseButtons . at thebutton .~ Nothing
Pressed -> handlePressedMouseButton thebutton . (mouseButtons . at thebutton %~ f)
Pressed -> handlePressedMouseButton thebutton . (mouseButtons . at thebutton ?~ False)
where
thebutton = mouseButtonEventButton mbev
f Nothing = Just False
f _ = Just True
{- | Sets window position in config. -}
handleWindowMoveEvent :: WindowMovedEventData -> Universe -> Maybe Universe
+2 -9
View File
@@ -41,12 +41,5 @@ initialWorld = defaultWorld
}
testStringInit :: World -> [String]
testStringInit = const [] -- map (show . _mcTermMID) . IM.elems . _machines
--testStringInit w = [show $ _cameraZoom w]
--testStringInit = (:[]) . show . _testFloat
--testStringInit = map (concatMap $ \(_,ct,_,_) -> show ct) . invertListInvMult . yourInv
--testStringInit w = fmap (show . _crHammerPosition) . IM.elems $ _creatures w
-- w = [show $ f $ _roomClipping w]
-- where
-- f (x:xs) = any (convexPolysOverlap x) xs || f xs
-- f [] = False
testStringInit = map show . M.toList . _mouseButtons
--testStringInit = const []
+1 -1
View File
@@ -133,7 +133,7 @@ ammoCheckI eff item cr w
-- hammer is down?
ammoHammerCheck :: ChainEffect
ammoHammerCheck eff it cr w
| _laLoaded ic <= 0 || _laPrimed ic == False = w -- fromMaybe w (startReloadingWeapon cr w)
| _laLoaded ic <= 0 || not (_laPrimed ic) = w -- fromMaybe w (startReloadingWeapon cr w)
& setHammerDown
| otherwise = case it ^? itUse . useHammer . hammerPosition of
Just HammerUp -> eff it cr $ setHammerDown w & creatures . ix (_crID cr) %~ crCancelReloading
+1 -1
View File
@@ -6,7 +6,7 @@ loadInsert :: Int -> LoadAction
loadInsert x = LoadInsert x insertS
loadPartialInsert :: Int -> Int -> LoadAction
loadPartialInsert x y = LoadAdd x insertOneS y
loadPartialInsert x = LoadAdd x insertOneS
loadEject :: Int -> LoadAction
loadEject x = LoadEject x ejectS
+1
View File
@@ -53,6 +53,7 @@ updateUniverse u = case _menuLayers u of
functionalUpdate :: Configuration -> World -> World
functionalUpdate cfig w = checkEndGame
-- . updateRandGen
. (mouseButtons . each .~ True)
. (worldClock +~ 1)
. doRewind
. (doubleMouseHammer %~ moveHammerUp)