Improve drag inventory selection

This commit is contained in:
2026-04-06 19:01:57 +01:00
parent 608de9f2ed
commit 35d169b585
4 changed files with 32 additions and 11 deletions
+12 -4
View File
@@ -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)
+8 -2
View File
@@ -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
+4 -3
View File
@@ -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
+8 -2
View File
@@ -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