Allow selection of noncontiguous items using shift

This commit is contained in:
2024-11-25 18:18:34 +00:00
parent 669f9667f1
commit 887ae2477c
3 changed files with 11 additions and 4 deletions
+1 -1
View File
@@ -1 +1 @@
All good (594 modules, at 17:16:08)
All good (594 modules, at 18:13:44)
-1
View File
@@ -17,7 +17,6 @@ import qualified IntMapHelp as IM
import Dodge.Data.World
import Control.Monad
-- can be specialised for when we know that item i is selected
swapInvItems ::
(Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) ->
Int ->
+10 -2
View File
@@ -139,16 +139,22 @@ updateMouseReleaseInGame w = case w ^. input . mouseContext of
OverInvDrag k mpos _ _ ->
input . mouseContext .~ MouseInGame $
fromMaybe w $ tryDropSelected mpos w <|> tryPickupSelected k mpos w
OverInvDragSelect ssel mesel | ScancodeLShift `M.member` (w ^. input . pressedKeys)
-> w & input . mouseContext .~ MouseInGame
& hud . hudElement . diSelection . _Just . _3 %~ getuniques
(maybe mempty (h ssel) (mesel ^? _Just . _2))
-- note this assumes that mesel isn't outside the first
-- selection, this should perhaps just be made impossible by
-- removing the first part of the tuple
OverInvDragSelect _ Nothing ->
w & input . mouseContext .~ MouseInGame
& hud . hudElement . diSelection . _Just . _3 %~ const mempty
OverInvDragSelect ssel (Just esel) ->
w & input . mouseContext .~ MouseInGame
-- & hud . hudElement . diSelectionExtra
-- .~ h ssel (snd esel) -- IM.keysSet [min (snd ssel) (snd esel) + 1 .. max (snd ssel) (snd esel)]
& augInvDirectSelect (f (min ssel esel) (h ssel (snd esel)))
_ -> w
where
getuniques x y = IS.union x y IS.\\ IS.intersection x y
f (x,y) z = (x,y,z)
h (k,i) j = fold $ do
sss <- w ^? hud . hudElement . diSections . ix k . ssItems
@@ -164,6 +170,8 @@ updateMouseClickInGame cfig w = case w ^. input . mouseContext of
return $
w & input . mouseContext
.~ OverInvDragSelect ysel Nothing
OverInvSelect x | ScancodeLShift `M.member` (w ^. input . pressedKeys )
-> w & input . mouseContext .~ OverInvDragSelect x (Just x)
OverInvSelect x -> startDrag x cfig w
OverTerminalReturn tmid -> terminalReturnEffect tmid w
OverTerminalEscape ->