From 35d169b585652f06e77e48f7b62966cb29b43fef Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 6 Apr 2026 19:01:57 +0100 Subject: [PATCH] Improve drag inventory selection --- src/Dodge/SelectionSections.hs | 16 ++++++++++++---- src/Dodge/TestString.hs | 10 ++++++++-- src/Dodge/Update.hs | 7 ++++--- src/Dodge/Update/Input/InGame.hs | 10 ++++++++-- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/Dodge/SelectionSections.hs b/src/Dodge/SelectionSections.hs index e32d4a467..7fbbce2a2 100644 --- a/src/Dodge/SelectionSections.hs +++ b/src/Dodge/SelectionSections.hs @@ -190,16 +190,24 @@ inverseSelSecYint yint sss return $ NonInf (i, j) inverseSelSecYintXPosCheck :: - Config -> LDParams -> Float -> Int -> IMSS a -> Maybe (Int, Int) + Config -> LDParams -> Float -> Int -> IMSS a -> Maybe (XInfinity (Int, Int)) inverseSelSecYintXPosCheck cfig ldp x yint sss = do - (i, j) <- inverseSelSecYint yint sss ^? nonInf + let sel = inverseSelSecYint yint sss + (i,j) <- case sel of + NonInf v -> Just v + NegInf -> do + (i',j',_) <- ssLookupMin sss + return (i',j') + PosInf -> do + (i',j',_) <- ssLookupMax sss + return (i',j') let V2 x0 _ = screenPosAbs cfig (ldp ^. ldpPos) sindent <- sss ^? ix i . ssIndent itindent <- sss ^? ix i . ssItems . ix j . siOffX let x1 = x0 + _ldpScale ldp * 10 * (fromIntegral (sindent + itindent) - 0.5) guard $ x - x1 < 160 && x > x1 - return (i, j) + return sel -inverseSelNumPos :: Config -> LDParams -> Point2 -> IMSS a -> Maybe (Int, Int) +inverseSelNumPos :: Config -> LDParams -> Point2 -> IMSS a -> Maybe (XInfinity (Int, Int)) inverseSelNumPos cfig ldp (V2 x y) = inverseSelSecYintXPosCheck cfig ldp x (posSelSecYint cfig ldp y) diff --git a/src/Dodge/TestString.hs b/src/Dodge/TestString.hs index 2649fc552..26dba9a89 100644 --- a/src/Dodge/TestString.hs +++ b/src/Dodge/TestString.hs @@ -41,8 +41,14 @@ tocrs :: (IM.IntMap Creature tocrs = uvWorld . cWorld . lWorld . creatures testStringInit :: Universe -> [String] -testStringInit u = u ^.. tocrs . each . crStance . carriage . to show - <> u ^.. tocrs . each . crPos . _z . to show +testStringInit u = + [ show $ inverseSelNumPos (u ^. uvConfig) invDP + (u ^. uvWorld . input . mousePos) (u ^. uvWorld . hud . diSections) + , show $ do + (i',xs) <- IM.lookupMax (u ^. uvWorld . hud . diSections) + (j',_) <- xs ^. ssItems . to IM.lookupMax + return (i',j') + ] -- where -- tocr = uvWorld . cWorld . lWorld . creatures . ix 0 diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 8d46ac4f5..66c3e3241 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -3,6 +3,7 @@ module Dodge.Update (updateUniverse) where +import Dodge.Data.CardinalPoint import Dodge.Data.ScreenPos import Bound import Color @@ -409,7 +410,7 @@ updateMouseContext cfig u = case u ^? uvScreenLayers . ix 0 of updateMouseContextGame :: Config -> Universe -> MouseContext -> MouseContext updateMouseContextGame cfig u = \case - OverInvDrag i _ -> OverInvDrag i (inverseSelNumPos cfig invDP mpos disss) + OverInvDrag i _ -> OverInvDrag i (inverseSelNumPos cfig invDP mpos disss ^? _Just . nonInf) x@OverInvDragSelect{} -> x MouseGameRotate x | ButtonRight `M.member` (w ^. input . mouseButtons) -> MouseGameRotate x @@ -424,7 +425,7 @@ updateMouseContextGame cfig u = \case mpos = w ^. input . mousePos disss = w ^. hud . diSections overinv = do - selpos@(i, j) <- inverseSelNumPos cfig invDP mpos disss + selpos@(i, j) <- inverseSelNumPos cfig invDP mpos disss ^? _Just . nonInf case w ^? hud . subInventory . ciSelection of Just _ | i == 0 -> return $ OverCombFiltInv selpos Just _ -> Nothing @@ -436,7 +437,7 @@ updateMouseContextGame cfig u = \case sss <- w ^? hud . subInventory . ciSections Sel xl xr _ <- w ^? hud . subInventory . ciSelection . _Just let msel = (xl, xr) - let mpossel = inverseSelNumPos cfig secondColumnLDP (w ^. input . mousePos) sss + let mpossel = inverseSelNumPos cfig secondColumnLDP (w ^. input . mousePos) sss ^? _Just . nonInf return $ case mpossel of Nothing -> OverCombEscape Just (-1, i) | (-1, i) == msel -> OverCombFilter diff --git a/src/Dodge/Update/Input/InGame.hs b/src/Dodge/Update/Input/InGame.hs index 1bad81eb7..958f0eb68 100644 --- a/src/Dodge/Update/Input/InGame.hs +++ b/src/Dodge/Update/Input/InGame.hs @@ -106,10 +106,16 @@ updateMouseHeldInGame cfig w = case w ^. input . mouseContext of let sss = w ^. hud . diSections in case inverseSelNumPos cfig invDP (w ^. input . mousePos) sss of Nothing -> w & input . mouseContext . mcoSelEnd .~ Nothing - Just (i, j) + Just (NonInf (i, j)) | i == fst sstart -> w & input . mouseContext . mcoSelEnd ?~ j | i < fst sstart -> w & input . mouseContext . mcoSelEnd ?~ 0 - | otherwise -> + | otherwise -> w + & input . mouseContext . mcoSelEnd + .~ fmap + fst + (IM.lookupMax =<< sss ^? ix (fst sstart) . ssItems) + Just NegInf -> w & input . mouseContext . mcoSelEnd ?~ 0 + Just PosInf -> w & input . mouseContext . mcoSelEnd .~ fmap fst