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
+7 -7
View File
@@ -84,10 +84,10 @@ mouseCursorType u = case u ^. uvWorld . input . mouseContext of
MouseMenuClick {} -> drawMenuClick 5
MouseMenuCursor -> drawMenuCursor 5
MouseInGame -> drawPlus 5
OverInvDrag 0 (Just _) -> drawDrag 5
OverInvDrag 0 Nothing -> drawDragDrop 5
OverInvDrag 3 (Just _) -> drawDrag 5
OverInvDrag 3 Nothing -> drawDragPickup 5
OverInvDrag 0 (Just (0,_)) -> drawDrag 5
OverInvDrag 0 _ -> drawDragDrop 5
OverInvDrag 3 (Just (3,_)) -> drawDrag 5
OverInvDrag 3 _ -> drawDragPickup 5
OverInvDrag _ _ -> drawEmptySet 5
OverInvDragSelect {} -> drawDragSelect 5
OverInvSelect {} -> drawSelect 5
@@ -180,9 +180,9 @@ drawDragDrop x =
drawDragPickup :: Float -> Picture
drawDragPickup x =
line (fmap (+V2 z (-x)) [V2 (-x) x,V2 0 x,V2 0 (-x)])
<> line (fmap (+V2 z (-x)) [V2 (-y) (y-x), V2 0 (-x), V2 y (y-x)])
-- <> drawSelect 5
line [V2 (-0.5 *x) 0, V2 (-z) 0, V2 (-z) z]
<> line [V2 (-(z+y)) (z-y), V2 (-z) z, V2 (y-z) (z-y)]
<> drawSelect 5
where
z = 1.5 * x
y = 0.7 * x
+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