diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 66c96aef0..8d3e55041 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -10,6 +10,8 @@ circular imports are probably not a good idea. {-# LANGUAGE DerivingStrategies #-} module Dodge.Data ( module Dodge.Data + , module Dodge.Data.Item.HeldScroll + , module Dodge.Data.Item.Consumption , module Dodge.Data.Gas , module Dodge.Data.Ammo , module Dodge.Data.Payload @@ -56,6 +58,8 @@ module Dodge.Data , module Dodge.Data.RadarBlip , module Dodge.Data.PathGraph ) where +import Dodge.Data.Item.HeldScroll +import Dodge.Data.Item.Consumption import Dodge.Data.Gas import Dodge.Data.Ammo import Dodge.Data.Payload @@ -401,7 +405,7 @@ data ItemUse , _useMods :: [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World] , _useHammer :: HammerPosition , _useAim :: AimParams - , _heldScroll :: Float -> Creature -> Item -> Item + , _heldScroll :: HeldScroll --Float -> Creature -> Item -> Item } | LeftUse { _lUse :: Item -> Creature -> World -> World @@ -428,29 +432,6 @@ data Equipment = Equipment _itUseAimStance :: Item -> AimStance _itUseAimStance = _aimStance . _useAim . _itUse -data ItemConsumption - = LoadableAmmo - { _laAmmoType :: AmmoType - , _laMax :: Int - , _laLoaded :: Int - , _laPrimed :: Bool - , _laCycle :: [LoadAction] - , _laProgress :: Maybe [LoadAction] - } - | AutoRecharging - { _arLoaded :: Int - , _arMax :: Int - , _arTime :: Int - , _arProgress :: Int - } - | ChargeableAmmo - { _wpMaxCharge :: Int - , _wpCharge :: Int - } - | ItemItselfConsumable - { _icAmount :: IcAmount - } - | NoConsumption data Item = Item { _itConsumption :: ItemConsumption , _itUse :: ItemUse @@ -1279,7 +1260,6 @@ makeLenses ''Item makeLenses ''ItemUse makeLenses ''ItEffect makeLenses ''FloorItem -makeLenses ''ItemConsumption makeLenses ''TweakParam makeLenses ''Prop makeLenses ''Proj diff --git a/src/Dodge/Data/Item/Consumption.hs b/src/Dodge/Data/Item/Consumption.hs index cfa3aa6d1..a6edd5cd1 100644 --- a/src/Dodge/Data/Item/Consumption.hs +++ b/src/Dodge/Data/Item/Consumption.hs @@ -2,3 +2,30 @@ {-# LANGUAGE StrictData #-} module Dodge.Data.Item.Consumption where import Control.Lens +import Dodge.Data.Ammo +import Dodge.Data.LoadAction +import Dodge.Data.ItemAmount +data ItemConsumption + = LoadableAmmo + { _laAmmoType :: AmmoType + , _laMax :: Int + , _laLoaded :: Int + , _laPrimed :: Bool + , _laCycle :: [LoadAction] + , _laProgress :: Maybe [LoadAction] + } + | AutoRecharging + { _arLoaded :: Int + , _arMax :: Int + , _arTime :: Int + , _arProgress :: Int + } + | ChargeableAmmo + { _wpMaxCharge :: Int + , _wpCharge :: Int + } + | ItemItselfConsumable + { _icAmount :: IcAmount + } + | NoConsumption +makeLenses ''ItemConsumption diff --git a/src/Dodge/Data/Item/HeldScroll.hs b/src/Dodge/Data/Item/HeldScroll.hs new file mode 100644 index 000000000..3cd2c254b --- /dev/null +++ b/src/Dodge/Data/Item/HeldScroll.hs @@ -0,0 +1,4 @@ +--{-# LANGUAGE StrictData #-} +module Dodge.Data.Item.HeldScroll where + +data HeldScroll = HeldScrollDoNothing | HeldScrollZoom | HeldScrollCharMode diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index d279f026a..87c879afb 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -65,7 +65,7 @@ defaultrUse = RightUse , _useMods = [] , _useHammer = HammerUp , _useAim = defaultAimParams - , _heldScroll = \_ _ -> id + , _heldScroll = HeldScrollDoNothing } defaultlUse :: ItemUse defaultlUse = LeftUse diff --git a/src/Dodge/Event.hs b/src/Dodge/Event.hs index 631c58671..c92aa5617 100644 --- a/src/Dodge/Event.hs +++ b/src/Dodge/Event.hs @@ -14,6 +14,7 @@ the simulation step; in particular see 'updatePressedButtons'. module Dodge.Event ( handleEvent ) where +import Dodge.HeldScroll import Dodge.InputFocus import Dodge.Combine import Dodge.Event.Keyboard @@ -110,7 +111,7 @@ wheelEvent y w = case _hudElement $ _hud w of | rbDown -> case (yourItem w ^? _Just . itUse . heldScroll,_rbOptions w) of (_,EquipOptions{}) -> scrollRBOption y w (Nothing,_) -> closeObjScrollDir y w - (Just f,_) -> w & creatures . ix 0 . crInv . ix (crSel $ you w) %~ f y (you w) + (Just f,_) -> w & creatures . ix 0 . crInv . ix (crSel $ you w) %~ doHeldScroll f y (you w) | lbDown -> w & cameraZoom +~ y | invKeyDown -> changeSwapInvSel yi w | otherwise -> stopSoundFrom (CrReloadSound 0) $ changeAugInvSel yi w diff --git a/src/Dodge/HeldScroll.hs b/src/Dodge/HeldScroll.hs new file mode 100644 index 000000000..a39568dc0 --- /dev/null +++ b/src/Dodge/HeldScroll.hs @@ -0,0 +1,37 @@ +module Dodge.HeldScroll + ( doHeldScroll + ) where +import Dodge.Data +import Dodge.Item.Weapon.ZoomScope +import Control.Lens hiding ((|>),(<|)) +import Data.Sequence + +doHeldScroll :: HeldScroll -> Float -> Creature -> Item -> Item +doHeldScroll hs = case hs of + HeldScrollDoNothing -> const . const id + HeldScrollZoom -> zoomLongGun + HeldScrollCharMode -> scrollCharMode +scrollCharMode + :: Float -- ^ Amount scrolled + -> Creature + -> Item + -> Item +scrollCharMode x _ + | x > 0 = incCharMode + | x < 0 = decCharMode + | otherwise = id + +incCharMode + :: Item + -> Item +incCharMode = itAttachment . atCharMode %~ cycleL + where + cycleL (x :<| xs) = xs |> x + cycleL xs = xs +decCharMode + :: Item + -> Item +decCharMode = itAttachment . atCharMode %~ cycleR + where + cycleR (xs :|> x) = x <| xs + cycleR xs = xs diff --git a/src/Dodge/Item/Attachment.hs b/src/Dodge/Item/Attachment.hs index b4ce1f0aa..57dfd7626 100644 --- a/src/Dodge/Item/Attachment.hs +++ b/src/Dodge/Item/Attachment.hs @@ -1,6 +1,5 @@ module Dodge.Item.Attachment ( charFiringStratI - , scrollCharMode , changeFuse ) where import Dodge.Data @@ -13,32 +12,6 @@ import Data.Maybe import qualified Data.IntMap.Strict as IM -scrollCharMode - :: Float -- ^ Amount scrolled - -> Creature - -> Item - -> Item -scrollCharMode x _ - | x > 0 = incCharMode - | x < 0 = decCharMode - | otherwise = id - -incCharMode - :: Item - -> Item -incCharMode = itAttachment . atCharMode %~ cycleL - where - cycleL (x :<| xs) = xs |> x - cycleL xs = xs - -decCharMode - :: Item - -> Item -decCharMode = itAttachment . atCharMode %~ cycleR - where - cycleR (xs :|> x) = x <| xs - cycleR xs = xs - charFiringStratI :: [(Char, ChainEffect)] -- ^ Different firing effects for different characters -> ChainEffect diff --git a/src/Dodge/Item/Equipment.hs b/src/Dodge/Item/Equipment.hs index 656b4c644..097de34fd 100644 --- a/src/Dodge/Item/Equipment.hs +++ b/src/Dodge/Item/Equipment.hs @@ -140,7 +140,6 @@ flatShield = defaultWeapon , _aimHandlePos = 0 , _aimMuzPos = 0 } - , _heldScroll = \_ _ -> id } & itInvSize .~ 3 & itType . iyBase .~ HELD FLATSHIELD diff --git a/src/Dodge/Item/Weapon/BulletGun/Rod.hs b/src/Dodge/Item/Weapon/BulletGun/Rod.hs index 77033af1a..d02f36a1f 100644 --- a/src/Dodge/Item/Weapon/BulletGun/Rod.hs +++ b/src/Dodge/Item/Weapon/BulletGun/Rod.hs @@ -11,7 +11,7 @@ import Dodge.Reloading.Action import Dodge.Default.Weapon import Dodge.Item.Weapon.Bullet import Dodge.Default -import Dodge.Item.Weapon.ZoomScope +--import Dodge.Item.Weapon.ZoomScope import Dodge.Item.Weapon.ExtraEffect import Dodge.Item.Weapon.TriggerType import Dodge.SoundLogic.LoadSound @@ -91,7 +91,7 @@ sniperRifle = elephantGun & itType . iyBase .~ HELD SNIPERRIFLE & itParams . gunBarrels .~ SingleBarrel 0 & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5} - & itUse . heldScroll .~ zoomLongGun + & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun & itScope .~ ZoomScope (V2 0 0) 0 1 0.5 False & itTargeting .~ targetLaser & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1} diff --git a/src/Dodge/Item/Weapon/BulletGuns.hs b/src/Dodge/Item/Weapon/BulletGuns.hs index 01aa0d24d..217147cb7 100644 --- a/src/Dodge/Item/Weapon/BulletGuns.hs +++ b/src/Dodge/Item/Weapon/BulletGuns.hs @@ -77,7 +77,7 @@ autoGun = defaultAutoGun & itUse . useAim . aimRange .~ 1 & itUse . useAim . aimStance .~ TwoHandTwist & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5} - & itUse . heldScroll .~ scrollCharMode + & itUse . heldScroll .~ HeldScrollCharMode & itType . iyBase .~ HELD AUTOGUN autoGunPic :: Item -> SPic autoGunPic it = noPic $