Commit towards merge
This commit is contained in:
+30
-29
@@ -9,59 +9,60 @@ We cannot handle multiple keys held down at once here,
|
||||
because these are separate events.
|
||||
Instead we store the events in a set, and deal with the combinations in
|
||||
"Dodge.Update". -}
|
||||
module Dodge.Event
|
||||
module Dodge.Event
|
||||
( handleEvent
|
||||
) where
|
||||
import Dodge.Event.Keyboard
|
||||
import Dodge.Combine
|
||||
import Dodge.Combine
|
||||
import Dodge.Event.Keyboard
|
||||
--import Dodge.Event.Menu
|
||||
import Dodge.Data
|
||||
import Dodge.Base
|
||||
import Dodge.Base
|
||||
import Dodge.Data
|
||||
--import Dodge.Base.Window
|
||||
import Dodge.PreloadData
|
||||
import Dodge.PreloadData
|
||||
--import Dodge.Creature.Action
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.Inventory
|
||||
import Dodge.Inventory.Add
|
||||
import Dodge.Inventory
|
||||
import Dodge.Inventory.Add
|
||||
import Dodge.SoundLogic
|
||||
--import Geometry
|
||||
--import Preload.Update
|
||||
import qualified IntMapHelp as IM
|
||||
import ListHelp
|
||||
import Dodge.FloorItem
|
||||
import Dodge.FloorItem
|
||||
import qualified IntMapHelp as IM
|
||||
import ListHelp
|
||||
|
||||
--import Data.Monoid
|
||||
import Data.Maybe
|
||||
import Control.Lens
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
--import Data.Maybe
|
||||
--import Data.Char
|
||||
--import Data.List
|
||||
--import Data.Function (on)
|
||||
import qualified Data.Set as S
|
||||
import SDL
|
||||
import qualified Data.Set as S
|
||||
import SDL
|
||||
|
||||
handleEvent :: Event -> Universe -> IO (Maybe Universe)
|
||||
handleEvent e = case eventPayload e of
|
||||
KeyboardEvent kev -> handleKeyboardEvent kev
|
||||
MouseMotionEvent mmev -> return . handleMouseMotionEvent mmev
|
||||
MouseButtonEvent mbev -> return . handleMouseButtonEvent mbev
|
||||
MouseWheelEvent mwev -> return . handleMouseWheelEvent mwev
|
||||
WindowSizeChangedEvent sev -> handleResizeEvent sev
|
||||
WindowMovedEvent mev -> return . handleWindowMoveEvent mev
|
||||
_ -> return . Just
|
||||
TextInputEvent tev -> handleTextInputEvent tev
|
||||
KeyboardEvent kev -> handleKeyboardEvent kev
|
||||
MouseMotionEvent mmev -> return . handleMouseMotionEvent mmev
|
||||
MouseButtonEvent mbev -> return . handleMouseButtonEvent mbev
|
||||
MouseWheelEvent mwev -> return . handleMouseWheelEvent mwev
|
||||
WindowSizeChangedEvent sev -> handleResizeEvent sev
|
||||
WindowMovedEvent mev -> return . handleWindowMoveEvent mev
|
||||
_ -> return . Just
|
||||
|
||||
handleMouseMotionEvent :: MouseMotionEventData -> Universe -> Maybe Universe
|
||||
handleMouseMotionEvent mmev u = Just $ u & uvWorld . mousePos .~ V2
|
||||
(fromIntegral x - 0.5*_windowX cfig)
|
||||
(0.5*_windowY cfig - fromIntegral y)
|
||||
where
|
||||
where
|
||||
cfig = _config u
|
||||
P (V2 x y) = mouseMotionEventPos mmev
|
||||
|
||||
handleMouseButtonEvent :: MouseButtonEventData -> Universe -> Maybe Universe
|
||||
handleMouseButtonEvent mbev = case mouseButtonEventMotion mbev of
|
||||
Released -> Just . updateButtons S.delete
|
||||
Pressed -> handlePressedMouseButton thebutton . updateButtons S.insert
|
||||
where
|
||||
Pressed -> handlePressedMouseButton thebutton . updateButtons S.insert
|
||||
where
|
||||
thebutton = mouseButtonEventButton mbev
|
||||
updateButtons f = uvWorld . mouseButtons %~ f thebutton
|
||||
|
||||
@@ -81,7 +82,7 @@ handleResizeEvent sev u = return . Just $ u
|
||||
& config . windowX .~ fromIntegral x
|
||||
& config . windowY .~ fromIntegral y
|
||||
& uvWorld . sideEffects %~ sideEffectUpdatePreload divRes x y
|
||||
where
|
||||
where
|
||||
x = fromIntegral x'
|
||||
y = fromIntegral y'
|
||||
V2 x' y' = windowSizeChangedEventSize sev
|
||||
@@ -136,7 +137,7 @@ wheelEvent y w = case _hudElement $ _hud w of
|
||||
| invKeyDown -> stopSoundFrom (CrReloadSound 0) $ changeInvSel yi w
|
||||
| rbDown -> w & changeTweakParam yi
|
||||
| otherwise -> w & moveTweakSel yi
|
||||
DisplayInventory (CombineInventory _) -> w
|
||||
DisplayInventory (CombineInventory _) -> w
|
||||
& hud . hudElement . subInventory . combineInvSel . _Just %~ ((`mod` numcombs) . subtract yi)
|
||||
_ -> w
|
||||
where
|
||||
@@ -165,7 +166,7 @@ moveTweakSel i w = case yourItem w ^? _Just . itTweaks . tweakParams of
|
||||
. itTweaks . tweakSel %~ (`mod` length l) . subtract i
|
||||
_ -> w
|
||||
changeTweakParam :: Int -> World -> World
|
||||
changeTweakParam i w = w
|
||||
changeTweakParam i w = w
|
||||
& creatures . ix (_yourID w) . crInv . ix (_crInvSel (you w)) %~
|
||||
( (itTweaks . tweakParams . ix paramid . curTweak .~ x)
|
||||
. _doTweak params x)
|
||||
|
||||
Reference in New Issue
Block a user