Continue mouse/inventory refactor

This commit is contained in:
2024-11-22 10:33:49 +00:00
parent 1250e2442a
commit bc2c9c9369
3 changed files with 40 additions and 11 deletions
+18 -3
View File
@@ -119,6 +119,21 @@ dropSelected w = fromMaybe w $ do
xs <- w ^? hud . hudElement . diSelectionExtra
return $ IS.foldr (dropItem cr) w (IS.insert j xs)
tryDropSelected :: World -> Maybe World
tryDropSelected w = do
cr <- w ^? cWorld . lWorld . creatures . ix 0
(0, j) <- w ^? hud . hudElement . diSelection . _Just
xs <- w ^? hud . hudElement . diSelectionExtra
return $ IS.foldr (dropItem cr) w (IS.insert j xs)
tryPickupSelected :: World -> Maybe World
tryPickupSelected w = do
cr <- w ^? cWorld . lWorld . creatures . ix 0
(3, j) <- w ^? hud . hudElement . diSelection . _Just
xs <- w ^? hud . hudElement . diSelectionExtra
OverInvDrag 3 x <- w ^? input . mouseContext
return $ IS.foldr (dropItem cr) w (IS.insert j xs)
updateMouseReleaseInGame :: World -> World
updateMouseReleaseInGame w = case w ^. input . mouseContext of
OverInvDrag i mpos -> fromMaybe (dropSelected w & input . mouseContext .~ MouseInGame) $ do
@@ -131,12 +146,12 @@ updateMouseReleaseInGame w = case w ^. input . mouseContext of
OverInvDragSelect ssel (Just esel) ->
w & input . mouseContext .~ MouseInGame
& hud . hudElement . diSelectionExtra
.~ h (snd ssel) (snd esel) -- IM.keysSet [min (snd ssel) (snd esel) + 1 .. max (snd ssel) (snd esel)]
.~ h ssel (snd esel) -- IM.keysSet [min (snd ssel) (snd esel) + 1 .. max (snd ssel) (snd esel)]
& augInvDirectSelect (min ssel esel)
_ -> w
where
h i j = fold $ do
sss <- w ^? hud . hudElement . diSections . ix 0 . ssItems
h (k,i) j = fold $ do
sss <- w ^? hud . hudElement . diSections . ix k . ssItems
let (_, xss) = IM.split (min i j -1) sss
(yss, _) = IM.split (max i j + 1) xss
return . IM.keysSet $ yss