Allow for left click to start and pause reloading when aiming
This commit is contained in:
@@ -7,6 +7,8 @@ import Dodge.Inventory
|
|||||||
import Dodge.Reloading
|
import Dodge.Reloading
|
||||||
|
|
||||||
import qualified Data.IntMap.Strict as IM
|
import qualified Data.IntMap.Strict as IM
|
||||||
|
import qualified Data.Map.Strict as M
|
||||||
|
import qualified SDL
|
||||||
--import qualified Data.IntSet as IS
|
--import qualified Data.IntSet as IS
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
@@ -22,7 +24,7 @@ useItem cr' w = fromMaybe (f w) $ do
|
|||||||
itemEffect :: Creature -> Item -> World -> World
|
itemEffect :: Creature -> Item -> World -> World
|
||||||
itemEffect cr it w = case it ^? itUse of
|
itemEffect cr it w = case it ^? itUse of
|
||||||
Just RightUse {_rUse = eff,_useMods = usemods}
|
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 LeftUse {} -> doequipmentchange
|
||||||
Just EquipUse{} -> doequipmentchange
|
Just EquipUse{} -> doequipmentchange
|
||||||
-- ConsumeUse will cause problems if the item is not selected
|
-- 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
|
doequipmentchange = setuhamdown $ hammerTest (toggleEquipmentAt (_rbOptions w) (crSel cr) cr
|
||||||
. activateEquipmentAt (_rbOptions w) 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 :: RightButtonOptions -> Creature -> World -> World
|
||||||
activateEquipmentAt rbo cr = creatures . ix (_crID cr) %~ case (rbo ^? opActivateEquipment . activateEquipment, rbo ^? opActivateEquipment . deactivateEquipment) of
|
activateEquipmentAt rbo cr = creatures . ix (_crID cr) %~ case (rbo ^? opActivateEquipment . activateEquipment, rbo ^? opActivateEquipment . deactivateEquipment) of
|
||||||
(Just i,_) -> crLeftInvSel ?~ i
|
(Just i,_) -> crLeftInvSel ?~ i
|
||||||
|
|||||||
+1
-3
@@ -68,11 +68,9 @@ handleMouseMotionEvent mmev u = Just $ u & uvWorld . mousePos .~ V2
|
|||||||
handleMouseButtonEvent :: MouseButtonEventData -> World -> World
|
handleMouseButtonEvent :: MouseButtonEventData -> World -> World
|
||||||
handleMouseButtonEvent mbev = case mouseButtonEventMotion mbev of
|
handleMouseButtonEvent mbev = case mouseButtonEventMotion mbev of
|
||||||
Released -> mouseButtons . at thebutton .~ Nothing
|
Released -> mouseButtons . at thebutton .~ Nothing
|
||||||
Pressed -> handlePressedMouseButton thebutton . (mouseButtons . at thebutton %~ f)
|
Pressed -> handlePressedMouseButton thebutton . (mouseButtons . at thebutton ?~ False)
|
||||||
where
|
where
|
||||||
thebutton = mouseButtonEventButton mbev
|
thebutton = mouseButtonEventButton mbev
|
||||||
f Nothing = Just False
|
|
||||||
f _ = Just True
|
|
||||||
|
|
||||||
{- | Sets window position in config. -}
|
{- | Sets window position in config. -}
|
||||||
handleWindowMoveEvent :: WindowMovedEventData -> Universe -> Maybe Universe
|
handleWindowMoveEvent :: WindowMovedEventData -> Universe -> Maybe Universe
|
||||||
|
|||||||
@@ -41,12 +41,5 @@ initialWorld = defaultWorld
|
|||||||
}
|
}
|
||||||
|
|
||||||
testStringInit :: World -> [String]
|
testStringInit :: World -> [String]
|
||||||
testStringInit = const [] -- map (show . _mcTermMID) . IM.elems . _machines
|
testStringInit = map show . M.toList . _mouseButtons
|
||||||
--testStringInit w = [show $ _cameraZoom w]
|
--testStringInit = const []
|
||||||
--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
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ ammoCheckI eff item cr w
|
|||||||
-- hammer is down?
|
-- hammer is down?
|
||||||
ammoHammerCheck :: ChainEffect
|
ammoHammerCheck :: ChainEffect
|
||||||
ammoHammerCheck eff it cr w
|
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
|
& setHammerDown
|
||||||
| otherwise = case it ^? itUse . useHammer . hammerPosition of
|
| otherwise = case it ^? itUse . useHammer . hammerPosition of
|
||||||
Just HammerUp -> eff it cr $ setHammerDown w & creatures . ix (_crID cr) %~ crCancelReloading
|
Just HammerUp -> eff it cr $ setHammerDown w & creatures . ix (_crID cr) %~ crCancelReloading
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ loadInsert :: Int -> LoadAction
|
|||||||
loadInsert x = LoadInsert x insertS
|
loadInsert x = LoadInsert x insertS
|
||||||
|
|
||||||
loadPartialInsert :: Int -> Int -> LoadAction
|
loadPartialInsert :: Int -> Int -> LoadAction
|
||||||
loadPartialInsert x y = LoadAdd x insertOneS y
|
loadPartialInsert x = LoadAdd x insertOneS
|
||||||
|
|
||||||
loadEject :: Int -> LoadAction
|
loadEject :: Int -> LoadAction
|
||||||
loadEject x = LoadEject x ejectS
|
loadEject x = LoadEject x ejectS
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ updateUniverse u = case _menuLayers u of
|
|||||||
functionalUpdate :: Configuration -> World -> World
|
functionalUpdate :: Configuration -> World -> World
|
||||||
functionalUpdate cfig w = checkEndGame
|
functionalUpdate cfig w = checkEndGame
|
||||||
-- . updateRandGen
|
-- . updateRandGen
|
||||||
|
. (mouseButtons . each .~ True)
|
||||||
. (worldClock +~ 1)
|
. (worldClock +~ 1)
|
||||||
. doRewind
|
. doRewind
|
||||||
. (doubleMouseHammer %~ moveHammerUp)
|
. (doubleMouseHammer %~ moveHammerUp)
|
||||||
|
|||||||
Reference in New Issue
Block a user