Refactor code for initial mouse click in game

This commit is contained in:
2024-11-18 11:00:41 +00:00
parent afddcae6d1
commit 3c5e5b92b1
5 changed files with 217 additions and 139 deletions
+12 -10
View File
@@ -6,7 +6,6 @@ Description : Simulation update
-}
module Dodge.Update (updateUniverse) where
import Dodge.Update.Input.ScreenLayer
import Color
import Control.Applicative
import Control.Monad
@@ -54,6 +53,7 @@ import Dodge.TractorBeam.Update
import Dodge.Update.Camera
import Dodge.Update.Cloud
import Dodge.Update.Input.InGame
import Dodge.Update.Input.ScreenLayer
import Dodge.Update.Scroll
import Dodge.Update.WallDamage
import Dodge.WallCreatureCollisions
@@ -165,7 +165,7 @@ updateUniverseMid u = case _uvScreenLayers u of
. updateClouds
)
(sl : _) -> u & updateUseInputOnScreen sl
[] -> timeFlowUpdate $ updateUseInputInGame u
[] -> timeFlowUpdate . updateUseInputInGame $ over uvWorld updateMouseClickInGame u
timeFlowUpdate :: Universe -> Universe
timeFlowUpdate u = case u ^. uvWorld . timeFlow of
@@ -399,18 +399,19 @@ updateMouseContext cfig u =
screen <- u ^? uvScreenLayers . ix 0
return $ case screen ^. scOptions of
[] -> NoMouseContext
_ -> fromMaybe MouseMenuCursor $ do
_ -> fromMaybe MouseMenuCursor $ do
ldps <- screen ^? scListDisplayParams
let ymax = maybe 0 length $ screen ^? scSelectionList
yi <- ldpVerticalSelection (u ^. uvConfig) ldps (u ^. uvWorld . input . mousePos)
guard (yi >= 0 && yi < ymax)
return $ if isselectable yi
then MouseMenuClick yi
else NoMouseContext
return $
if isselectable yi
then MouseMenuClick yi
else NoMouseContext
isselectable yi =
fromMaybe False $
u ^? uvScreenLayers . _head . scSelectionList . ix yi . siIsSelectable
-- mmoving = u ^. uvWorld . input . mouseMoving
-- mmoving = u ^. uvWorld . input . mouseMoving
w = u ^. uvWorld
aimcontext
| ButtonRight `M.member` (w ^. input . mouseButtons) = MouseAiming
@@ -438,9 +439,10 @@ updateMouseContext cfig u =
tm <- w ^? cWorld . lWorld . terminals . ix tmid
return $
if isOverTerminalScreen cfig tm mpos
then if null $ tm ^. tmInput . tiText
then NoMouseContext
else OverTerminalReturn
then
if null $ tm ^. tmInput . tiText
then NoMouseContext
else OverTerminalReturn
else OverTerminalEscape
isOverTerminalScreen :: Configuration -> Terminal -> Point2 -> Bool