From 86f185c71eca7b8163eb9fbed23950313f72dfee Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 16 Nov 2024 16:45:12 +0000 Subject: [PATCH] Determine mouse position over terminal display --- ghcidOutput | 6 +----- src/Dodge/Data/ScreenPos.hs | 3 +++ src/Dodge/Render/HUD.hs | 1 + src/Dodge/Render/List.hs | 2 +- src/Dodge/Update.hs | 38 +++++++++++++++++++++++++++++-------- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/ghcidOutput b/ghcidOutput index f3b6d246b..5eff9b673 100644 --- a/ghcidOutput +++ b/ghcidOutput @@ -1,5 +1 @@ -/home/justin/Haskell/loop/src/Dodge/Update.hs:416:9-12: warning: [-Wunused-matches] - Defined but not used: ‘tmid’ - | -416 | tmid <- w ^? hud . hudElement . subInventory . termID - | ^^^^ +All good (594 modules, at 16:39:41) diff --git a/src/Dodge/Data/ScreenPos.hs b/src/Dodge/Data/ScreenPos.hs index ea2ccf28f..a26314c74 100644 --- a/src/Dodge/Data/ScreenPos.hs +++ b/src/Dodge/Data/ScreenPos.hs @@ -6,6 +6,9 @@ module Dodge.Data.ScreenPos import Geometry.Data import Control.Lens +-- from the center. positive x goes right, positive y goes up. +-- a spScreenOff of 1 is the full length of the screen +-- for eg see fromTopLeft data ScreenPos = ScreenPos { _spScreenOff :: Point2 , _spPixelOff :: Point2 diff --git a/src/Dodge/Render/HUD.hs b/src/Dodge/Render/HUD.hs index cb34aca8c..7ce4b1882 100644 --- a/src/Dodge/Render/HUD.hs +++ b/src/Dodge/Render/HUD.hs @@ -355,6 +355,7 @@ drawTerminalDisplay tid cfig w = fromMaybe mempty $ do invHead cfig (_tmTitle tm ++ ":T" ++ show tid) <> drawSelectionList secondColumnParams cfig (thesellist tm) <> color (withAlpha 0.5 green) (drawSelectionListBackground secondColumnParams cfig 15) + -- when changing the 15, change isOverTerminalScreen <> color (dark $ _tmExternalColor tm) (drawTitleBackground cfig) where toselitm (str, col) = SelectionItem [str] 1 True col 0 () diff --git a/src/Dodge/Render/List.hs b/src/Dodge/Render/List.hs index 5ed437697..d4753557b 100644 --- a/src/Dodge/Render/List.hs +++ b/src/Dodge/Render/List.hs @@ -56,7 +56,7 @@ drawSelectionListBackground ldp cfig l = translateScreenPos cfig (ldp ^. ldpPos) polygon . reverse $ rectNSWE 5 s (-5) e where s = - (5 + fromIntegral l * (20 * ldp ^. ldpScale + ldp ^. ldpVerticalGap)) - e = 555 -- HACK + e = 555 -- HACK isOverTerminalScreen makeSelectionListPictures :: SelectionList a -> [Picture] makeSelectionListPictures = concatMap f . _slItems diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 8bb279694..d9d7a623b 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -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