Tweak inventory manipulation

This commit is contained in:
2026-04-06 18:07:35 +01:00
parent 262463c52d
commit 9d7c9f1db2
5 changed files with 164 additions and 156 deletions
+15 -5
View File
@@ -144,7 +144,7 @@ doDrag cfig n k mmouseover w = fromMaybe w $ do
guard (n /= 0)
ss <- w ^? hud . diSections . ix k . ssItems
x <- mmouseover
is <- w ^? hud . diSelection . _Just . slSet
is <- selectionSet w
return $
if concurrentIS is
then shiftInvItems cfig n k x is ss w
@@ -154,15 +154,24 @@ tryDropSelected :: Maybe (Int, Int) -> World -> Maybe World
tryDropSelected mpos w = do
guard $ maybe True (\(i, _) -> i == 3) mpos
cr <- w ^? cWorld . lWorld . creatures . ix 0
Sel 0 _ xs <- w ^? hud . diSelection . _Just
return . foldl' (flip $ dropItem cr) w . IS.toDescList $ xs
0 <- w ^? hud . diSelection . _Just . slSec
xs <- selectionSet w
return
. (hud . diSelection ?~ Sel 3 0 (IS.fromDistinctAscList [0..IS.size xs - 1]))
. foldl' (flip $ dropItem cr) w . IS.toDescList $ xs
selectionSet :: World -> Maybe IS.IntSet
selectionSet w = case w ^? hud . diSelection . _Just . slSet of
Just is' | not $ IS.null is' -> Just is'
_ -> IS.singleton <$> w ^? hud . diSelection . _Just . slInt
tryPickupSelected :: Int -> Maybe (Int, Int) -> World -> Maybe World
tryPickupSelected k mpos w = do
guard $ k == 3
guard $ maybe True (\(i, _) -> i == 0 || i == 1) mpos
cr <- w ^? cWorld . lWorld . creatures . ix 0
xs <- w ^? hud . diSelection . _Just . slSet
xs <- selectionSet w
let nfreeslots = crNumFreeSlots (w ^. cWorld . lWorld . items) cr
itmstopickup = mapMaybe g $ IS.toList xs
slotsneeded = alaf Sum foldMap itInvHeight itmstopickup
@@ -299,7 +308,8 @@ endCombineRegex w = ssSetCursor (ssLookupDown 0 j) sss
startDrag :: (Int, Int) -> World -> World
startDrag (a, b) w = setcontext $ case w ^? hud . diSelection . _Just of
Just (Sel i _ xs) | i == a && b `IS.member` xs -> w
_ -> invSetSelection (Sel a b (IS.singleton b)) w
-- _ -> invSetSelection (Sel a b (IS.singleton b)) w
_ -> invSetSelection (Sel a b mempty) w
where
setcontext = input . mouseContext .~ OverInvDrag a (Just (a, b))