Move mouse button imputs to your input
This commit is contained in:
+1
-31
@@ -68,7 +68,7 @@ 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 ?~ False)
|
||||
Pressed -> mouseButtons . at thebutton ?~ False
|
||||
where
|
||||
thebutton = mouseButtonEventButton mbev
|
||||
|
||||
@@ -94,36 +94,6 @@ handleResizeEvent sev u = return . Just $ u
|
||||
V2 x' y' = windowSizeChangedEventSize sev
|
||||
divRes = resFactorNum $ u ^. config . graphics_resolution_factor
|
||||
|
||||
handlePressedMouseButton :: MouseButton -> World -> World
|
||||
handlePressedMouseButton but w = case (_hudElement (_hud w), but) of
|
||||
(DisplayCarte,_) -> w & clickMousePos .~ _mousePos w
|
||||
(_,ButtonMiddle) -> w & clickMousePos .~ _mousePos w
|
||||
( DisplayInventory (DisplayTerminal tmid) , ButtonLeft)
|
||||
| inTermFocus w -> doTerminalEffectLB (w ^?! terminals . ix tmid) w
|
||||
| otherwise -> w & terminals . ix tmid . tmInput . tiFocus %~ const True
|
||||
( DisplayInventory (CombineInventory mi) , ButtonLeft)
|
||||
-> maybeexitcombine $ maybe id doCombine mi w
|
||||
_ -> w
|
||||
where
|
||||
maybeexitcombine
|
||||
| ButtonRight `M.member` _mouseButtons w = id
|
||||
| otherwise = hud . hudElement .~ DisplayInventory NoSubInventory
|
||||
|
||||
-- note "sort" on the inventory indices; otherwise
|
||||
-- lower items may be shifted up and items below these removed instead
|
||||
doCombine :: Int -> World -> World
|
||||
doCombine i w = case combineItemListYou w !? i of
|
||||
Nothing -> w
|
||||
Just (is,it) -> -- set (hud . hudElement) (DisplayInventory NoSubInventory)
|
||||
selectinv --enterCombineInv
|
||||
. createPutItem it
|
||||
$ foldr (rmInvItem yid) w (sort is)
|
||||
where
|
||||
yid = _yourID w
|
||||
selectinv (Just i', w') = w' & creatures . ix yid . crInvSel .~ InvSel i' NoInvSelAction
|
||||
selectinv (Nothing, w') = w'
|
||||
|
||||
|
||||
handleMouseWheelEvent :: MouseWheelEventData -> Universe -> Maybe Universe
|
||||
handleMouseWheelEvent mwev w = case _menuLayers w of
|
||||
[] -> case mouseWheelEventPos mwev of
|
||||
|
||||
@@ -5,8 +5,14 @@ module Dodge.Update.UsingInput
|
||||
import Dodge.Data
|
||||
import Dodge.Base.You
|
||||
import Dodge.Creature.Impulse.UseItem
|
||||
import Dodge.Terminal
|
||||
import Dodge.InputFocus
|
||||
import Dodge.Combine
|
||||
import Dodge.Inventory
|
||||
import Dodge.Inventory.Add
|
||||
import Geometry
|
||||
|
||||
import ListHelp
|
||||
import SDL
|
||||
--import qualified Data.Set as S
|
||||
import qualified Data.Map.Strict as M
|
||||
@@ -14,21 +20,35 @@ import Control.Lens
|
||||
|
||||
updateUsingInput :: World -> World
|
||||
updateUsingInput w = case _hudElement $ _hud w of
|
||||
DisplayInventory {} -> updatePressedButtons (_mouseButtons w) w
|
||||
DisplayCarte -> updatePressedButtonsCarte (_mouseButtons w) w
|
||||
DisplayInventory subinv
|
||||
-> updatePressedButtons subinv (_mouseButtons w) w
|
||||
DisplayCarte
|
||||
-> updatePressedButtonsCarte (_mouseButtons w) w
|
||||
|
||||
-- ugly check for subinventory inventory hammer, this should change
|
||||
updatePressedButtons :: M.Map MouseButton Bool -> World -> World
|
||||
updatePressedButtons pkeys w
|
||||
| ButtonLeft `M.member` pkeys &&
|
||||
(inSubInv || w ^?! hammers . ix SubInvHam /= HammerUp)
|
||||
= undefined --w & hammers . ix SubInvHam .~ HammerDown
|
||||
| otherwise = updatePressedButtons' pkeys w
|
||||
updatePressedButtons :: SubInventory -> M.Map MouseButton Bool -> World -> World
|
||||
updatePressedButtons subinv pkeys w = case subinv of
|
||||
NoSubInventory
|
||||
| ButtonLeft `M.member` pkeys && w ^?! hammers . ix SubInvHam /= HammerUp
|
||||
-> w & hammers . ix SubInvHam .~ HammerDown
|
||||
| otherwise -> updatePressedButtons' pkeys w
|
||||
CombineInventory mi
|
||||
| pkeys ^? ix ButtonLeft == Just False
|
||||
-> (maybeexitcombine $ maybe id doCombine mi w) & hammers . ix SubInvHam .~ HammerDown
|
||||
DisplayTerminal tmid
|
||||
| pkeys ^? ix ButtonLeft == Just False && inTermFocus w
|
||||
-> doTerminalEffectLB (w ^?! terminals . ix tmid) w
|
||||
& hammers . ix SubInvHam .~ HammerDown
|
||||
| pkeys ^? ix ButtonLeft == Just False
|
||||
-> w & terminals . ix tmid . tmInput . tiFocus %~ const True
|
||||
& hammers . ix SubInvHam .~ HammerDown
|
||||
_ | ButtonLeft `M.member` pkeys
|
||||
-> w & hammers . ix SubInvHam .~ HammerDown
|
||||
_ -> w
|
||||
where
|
||||
inSubInv = case _hudElement (_hud w) of
|
||||
DisplayInventory NoSubInventory -> False
|
||||
DisplayInventory _ -> True
|
||||
_ -> False
|
||||
maybeexitcombine
|
||||
| ButtonRight `M.member` _mouseButtons w = id
|
||||
| otherwise = hud . hudElement .~ DisplayInventory NoSubInventory
|
||||
|
||||
updatePressedButtons' :: M.Map MouseButton Bool -> World -> World
|
||||
updatePressedButtons' pkeys w
|
||||
@@ -52,6 +72,22 @@ updatePressedButtons' pkeys w
|
||||
isDown but = but `M.member` pkeys
|
||||
rotation = angleBetween (_mousePos w) (_clickMousePos w)
|
||||
|
||||
|
||||
-- note "sort" on the inventory indices; otherwise
|
||||
-- lower items may be shifted up and items below these removed instead
|
||||
doCombine :: Int -> World -> World
|
||||
doCombine i w = case combineItemListYou w ^? ix i of
|
||||
Nothing -> w
|
||||
Just (is,it) -> -- set (hud . hudElement) (DisplayInventory NoSubInventory)
|
||||
selectinv --enterCombineInv
|
||||
. createPutItem it
|
||||
$ foldr (rmInvItem yid) w (sort is)
|
||||
where
|
||||
yid = _yourID w
|
||||
selectinv (Just i', w') = w' & creatures . ix yid . crInvSel .~ InvSel i' NoInvSelAction
|
||||
selectinv (Nothing, w') = w'
|
||||
|
||||
|
||||
updatePressedButtonsCarte :: M.Map MouseButton Bool -> World -> World
|
||||
updatePressedButtonsCarte pkeys w
|
||||
| isDown ButtonRight = w
|
||||
|
||||
Reference in New Issue
Block a user