Determine mouse position over terminal display
This commit is contained in:
+30
-8
@@ -6,8 +6,8 @@ Description : Simulation update
|
||||
-}
|
||||
module Dodge.Update (updateUniverse) where
|
||||
|
||||
import Control.Applicative
|
||||
import Color
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
import Data.List
|
||||
import qualified Data.Map.Strict as M
|
||||
@@ -40,6 +40,7 @@ import Dodge.Projectile.Update
|
||||
import Dodge.Prop.Update
|
||||
import Dodge.RadarBlip
|
||||
import Dodge.RadarSweep
|
||||
import Dodge.ScreenPos
|
||||
import Dodge.ScrollValue
|
||||
import Dodge.SelectionSections
|
||||
import Dodge.Shockwave.Update
|
||||
@@ -388,16 +389,19 @@ shiftInvItemsDown (_, i) x w = fromMaybe w $ do
|
||||
g i' m = fst <$> IM.lookupGT i' m
|
||||
|
||||
updateMouseContext :: Configuration -> World -> World
|
||||
updateMouseContext cfig w =
|
||||
w & input . mouseContext .~ fromMaybe aimcontext
|
||||
(overinv <|> overcomb <|> overterm)
|
||||
updateMouseContext cfig w =
|
||||
w & input . mouseContext
|
||||
.~ fromMaybe
|
||||
aimcontext
|
||||
(overinv <|> overcomb <|> overterm)
|
||||
where
|
||||
aimcontext
|
||||
| ButtonRight `M.member` (w ^. input . mouseButtons) = MouseAiming
|
||||
| otherwise = NoMouseContext
|
||||
mpos = w ^. input . mousePos
|
||||
overinv = do
|
||||
sss <- w ^? hud . hudElement . diSections
|
||||
selpos <- inverseSelNumPos cfig (invDisplayParams w) sss (w ^. input . mousePos)
|
||||
selpos <- inverseSelNumPos cfig (invDisplayParams w) sss mpos
|
||||
case w ^? hud . hudElement . subInventory . ciSelection of
|
||||
Just _ -> return $ OverInvFilt selpos
|
||||
_ -> do
|
||||
@@ -409,13 +413,31 @@ updateMouseContext cfig w =
|
||||
let mpossel = inverseSelNumPos cfig secondColumnParams sss (w ^. input . mousePos)
|
||||
return $ case mpossel of
|
||||
Nothing -> OverCombEscape
|
||||
Just (-1,_) -> OverCombFilter
|
||||
Just (-1, _) -> OverCombFilter
|
||||
Just x | x == msel -> OverCombCombine x
|
||||
Just x -> OverCombSelect x
|
||||
overterm = do
|
||||
tmid <- w ^? hud . hudElement . subInventory . termID
|
||||
guard True
|
||||
return OverTerminalReturn
|
||||
tm <- w ^? cWorld . lWorld . terminals . ix tmid
|
||||
return $
|
||||
if isOverTerminalScreen cfig tm mpos
|
||||
then OverTerminalReturn
|
||||
else OverTerminalEscape
|
||||
|
||||
isOverTerminalScreen :: Configuration -> Terminal -> Point2 -> Bool
|
||||
isOverTerminalScreen cfig _ (V2 x y) =
|
||||
x <= xmax
|
||||
&& x >= xmin - 5
|
||||
&& y <= ymax + 5
|
||||
&& y >= ymin
|
||||
where
|
||||
ldp = secondColumnParams
|
||||
V2 xmin ymax = screenPosAbs cfig (ldp ^. ldpPos)
|
||||
s = (5 + 15 * (20 * ldp ^. ldpScale + ldp ^. ldpVerticalGap))
|
||||
-- the 15 is the length of list in the terminal display, don't change
|
||||
-- without changing drawTerminalDisplay
|
||||
ymin = ymax - s
|
||||
xmax = xmin + 555 -- HACK drawSelectionListBackground
|
||||
|
||||
updateWheelEvents :: World -> World
|
||||
updateWheelEvents w
|
||||
|
||||
Reference in New Issue
Block a user