Fix dragging over items larger than the selection group

There is still a further choice/improvement to be made here,
but at least dragging shouldn't glitch out as it currently stands
This commit is contained in:
2024-11-25 11:09:58 +00:00
parent 905be15a33
commit 2c6037d852
6 changed files with 170 additions and 140 deletions
+26 -14
View File
@@ -93,12 +93,12 @@ updateMouseHeldInGame cfig w = case w ^. input . mouseContext of
let msel = inverseSelNumPos cfig ldp sss (w ^. input . mousePos)
guard $ Just (fst sstart) == fmap fst msel || isNothing msel
return $ w & input . mouseContext . mcoSelEnd .~ msel
OverInvDrag k mmouseover -> fromMaybe w $ do
OverInvDrag k mmouseover ab bn -> fromMaybe w $ do
ss <- w ^? hud . hudElement . diSections . ix k . ssItems
x <- mmouseover
is <- w ^? hud . hudElement . diSelectionExtra
return $ if concurrentIS is
then shiftInvItems k x is ss w
then shiftInvItems k x ab bn is ss w
else collectInvItems is w
-- let mpos = w ^. input . mousePos
-- return $ w & dragInvItems k xs cfig mpos ldp sss
@@ -127,8 +127,7 @@ tryPickupSelected mpos w = do
updateMouseReleaseInGame :: World -> World
updateMouseReleaseInGame w = case w ^. input . mouseContext of
--OverInvDrag i mpos ->
OverInvDrag _ mpos ->
OverInvDrag _ mpos _ _ ->
input . mouseContext .~ MouseInGame $
fromMaybe w $ tryDropSelected mpos w <|> tryPickupSelected mpos w
-- OverInvDrag i mpos -> fromMaybe (dropSelected w & input . mouseContext .~ MouseInGame) $ do
@@ -159,7 +158,7 @@ updateMouseClickInGame cfig w = case w ^. input . mouseContext of
return $
w & input . mouseContext
.~ OverInvDragSelect ysel Nothing
OverInvSelect x -> startDrag x w
OverInvSelect x -> startDrag x cfig w
OverTerminalReturn tmid -> terminalReturnEffect tmid w
OverTerminalEscape ->
w
@@ -198,17 +197,26 @@ updateMouseClickInGame cfig w = case w ^. input . mouseContext of
ldp = invDisplayParams w
mpos = w ^. input . mousePos
startDrag :: (Int, Int) -> World -> World
startDrag (a, b) w = fromMaybe (augInvDirectSelect (a, b) $ setmichosen mempty w) $ do
--(i, j) <- w ^? hud . hudElement . diSelection . _Just
startDrag :: (Int, Int) -> Configuration -> World -> World
startDrag (a, b) cfig w = fromMaybe (augInvDirectSelect (a, b) $ setmichosen mempty w) $ do
(i, _) <- w ^? hud . hudElement . diSelection . _Just
xs <- w ^? hud . hudElement . diSelectionExtra
guard $ i == a && b `IS.member` xs
return $ setmichosen xs w
where
setmichosen :: IS.IntSet -> World -> World
setmichosen x =
(input . mouseContext .~ OverInvDrag a (Just (a, b)))
(input . mouseContext .~ OverInvDrag a (Just (a, b)) above bneath)
. (hud . hudElement . diSelectionExtra .~ x)
above :: Maybe (Int,Int)
above = do
sss <- w ^? hud . hudElement . diSections
inverseSelSecYint (yint - 1) sss
bneath :: Maybe (Int,Int)
bneath = do
sss <- w ^? hud . hudElement . diSections
inverseSelSecYint (yint + 1) sss
yint = posSelSecYint cfig (invDisplayParams w) (w ^. input . mousePos . _y)
concurrentIS :: IS.IntSet -> Bool
concurrentIS = go . IS.minView
@@ -228,19 +236,23 @@ collectInvItems is w = fromMaybe w $ do
return . h (j + 1) ks $ swapInvItems (\_ _ -> Just (j + 1)) k w'
shiftInvItems ::
Int ->
(Int,Int) ->
Int -> -- section where drag started
(Int,Int) -> -- selection item mouse is over
Maybe (Int,Int) -> -- selection item "above" mouse position (can be same as over)
Maybe (Int,Int) -> -- selection item "below" mouse position (can be same as over)
IS.IntSet ->
IM.IntMap (SelectionItem a) ->
World ->
World
shiftInvItems k x xs ss w = fromMaybe w $ do
shiftInvItems k x ab bn xs ss w = fromMaybe w $ do
(maxi,_) <- IS.maxView xs
(mini,_) <- IS.minView xs
if x < (k,mini)
then do
minss <- IM.lookupMin ss
guard (mini > fst minss)
above <- ss ^? ix (mini - 1)
guard $ Just (k,mini-1) /= ab
-- minss <- IM.lookupMin ss
-- guard (mini > fst minss)
return $ shiftInvItemsUp k xs w
else do
guard $ x > (k,maxi)