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 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
|
||||
|
||||
Reference in New Issue
Block a user