Cleanup inventory management, tweak dragging start

This commit is contained in:
2026-05-15 10:35:17 +01:00
parent 17f8707f62
commit e56a953c9b
23 changed files with 70 additions and 180 deletions
+9 -19
View File
@@ -81,6 +81,7 @@ destroyItem itid w = case w ^? cWorld . lWorld . items . ix itid . itLocation of
-- note rmInvItem does not fully destroy the item, other updates to the item
-- location are required
-- note if this gets called ssInvPosFromSS might be necessary elsewhere
rmInvItem :: Int -> NewInt InvInt -> World -> World
rmInvItem cid invid w =
w
@@ -89,20 +90,15 @@ rmInvItem cid invid w =
& removeAnySlotEquipment
& cWorld . lWorld . items . ix itid . itLocation . ilEquipSite .~ Nothing
& updateselection
-- & uprootitem
--revise1 & pointcid %~ updateRootItemID (w ^. cWorld . lWorld . items)
& worldEventFlags . at InventoryChange ?~ ()
where
-- uprootitem w' = updateRootItemID (w ^. cWorld . lWorld . items) (w'^?!cWorld.lWorld.creatures.ix 0) w'
pointcid = cWorld . lWorld . creatures . ix cid
updateselection
| cid == 0 && (w ^? hud .diSelection._Just) == Just (Sel 0 (invid^.unNInt)) =
--revise2 | cid == 0 && w ^? hud . manObject . imSelectedItem == Just invid =
scrollAugInvSel (-1) . scrollAugInvSel 1
| otherwise = id -- hud . manObject . imSelectedItem %~ g
--revise2 | otherwise = hud . manObject . imSelectedItem %~ g
| otherwise = id
cr = w ^?! cWorld . lWorld . creatures . ix cid
itid = _crInv cr ^?! ix invid
itid = cr ^?! crInv . ix invid
itm = w ^?! cWorld . lWorld . items . ix itid
dounequipfunction = effectOnRemove itm cr
removeAnySlotEquipment = fromMaybe id $ do
@@ -235,13 +231,11 @@ multiSelScroll' f w = fromMaybe w $ do
& hud . diSelection . _Just . slInt .~ k
changeSwapOther ::
--revise3 ((Int -> Identity Int) -> ManipulatedObject -> Identity ManipulatedObject) ->
Int ->
(Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) ->
Int ->
World ->
World
--revise3 changeSwapOther manlens n f i w = fromMaybe w $ do
changeSwapOther n f i w = fromMaybe w $ do
ss <- w ^? hud . diSections . ix n . ssItems
k <- f i ss
@@ -252,8 +246,6 @@ changeSwapOther n f i w = fromMaybe w $ do
return $
w
& swapAnyExtraSelection 3 i k
-- &hud. manObject . manlens %~ doswap
--revise1 & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . manlens %~ doswap
& hud . closeItems %~ swapIndices i k
& hud . diSelection . _Just . slInt %~ doswap
& worldEventFlags . at InventoryChange ?~ ()
@@ -267,8 +259,6 @@ swapItemWith f (j, i) = case j of
0 -> swapInvItems f i
3 -> changeSwapOther 3 f i
5 -> changeSwapOther 5 f i
--revise3 3 -> changeSwapOther ispCloseItem 3 f i
--revise3 5 -> changeSwapOther ispCloseButton 5 f i
_ -> id
changeSwapWith :: (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) -> World -> World
@@ -281,9 +271,9 @@ invSetSelection sel w =
w
& hud . diSelection ?~ sel
& worldEventFlags . at InventoryChange ?~ ()
& crUpdateItemLocations
& setInvPosFromSS -- is this necessary here?
& crUpdateItemLocations 0
--revise1 & cWorld . lWorld %~ crUpdateItemLocations 0
& crUpdateItemLocations
invSetSelectionPos :: Int -> Int -> World -> World
invSetSelectionPos i j = invSetSelection (Sel i j)
@@ -295,9 +285,9 @@ scrollAugInvSel yi w
w
& hud %~ doscroll
& worldEventFlags . at InventoryChange ?~ ()
& crUpdateItemLocations
& setInvPosFromSS
& crUpdateItemLocations 0
--revise1 & cWorld . lWorld %~ crUpdateItemLocations 0
& crUpdateItemLocations
where
doscroll he = fromMaybe he $ do
sss <- he ^? diSections
@@ -308,9 +298,9 @@ scrollAugNextInSection w =
w
& hud %~ doscroll
& worldEventFlags . at InventoryChange ?~ ()
& crUpdateItemLocations
& setInvPosFromSS
& crUpdateItemLocations 0
--revise1 & cWorld . lWorld %~ crUpdateItemLocations 0
& crUpdateItemLocations
where
doscroll he = fromMaybe he $ do
sss <- he ^? diSections