Fix cursor selection when dropping filtered items

This commit is contained in:
2023-02-23 09:38:06 +00:00
parent 88eb94abaa
commit da49d7003e
6 changed files with 46 additions and 384 deletions
+10 -5
View File
@@ -22,6 +22,7 @@ module Dodge.Inventory (
setInvPosFromSS,
) where
import Dodge.DisplayInventory
import Dodge.SelectionSections
import Control.Applicative
import Dodge.Data.SelectionList
@@ -43,6 +44,7 @@ import LensHelp
import ListHelp
import Padding
-- TODO check what happens to selection index when dropping non-selected items
-- | after this the item at the inventory position will no longer exist
rmInvItem ::
-- | Creature id
@@ -55,8 +57,8 @@ rmInvItem cid invid w = case w ^? getcid . crInv . ix invid . itUse . useAmount
Just x | x > 1 -> w & pointcid . crInv . ix invid . itUse . useAmount -~ 1
_ ->
w
& pointcid . crInv %~ f
& pointcid %~ crCancelReloading
& pointcid . crInv %~ f
& pointcid . crLeftInvSel . lisMPos %~ g'
& removeAnySlotEquipment
& dounequipfunction
@@ -71,7 +73,7 @@ rmInvItem cid invid w = case w ^? getcid . crInv . ix invid . itUse . useAmount
updateselection
| cid == 0 && cr ^? crManipulation . manObject . inInventory . ispItem == Just invid
= scrollAugInvSel (-1) . scrollAugInvSel 1
= scrollAugInvSel (-1) . scrollAugInvSel 1 . updateInventorySectionItems
| otherwise
= pointcid . crManipulation . manObject . inInventory . ispItem %~ g
@@ -83,9 +85,12 @@ rmInvItem cid invid w = case w ^? getcid . crInv . ix invid . itUse . useAmount
doanyitemeffect = fromMaybe id $ do
rmf <- itm ^? itEffect . ieOnDrop
return $ doInvEffect rmf itm cr
removeAnySlotEquipment = case w ^? cWorld . lWorld . creatures . ix cid . crInvEquipped . ix invid of
Just epos -> pointcid . crEquipment . at epos .~ Nothing
Nothing -> id
--removeAnySlotEquipment = case w ^? cWorld . lWorld . creatures . ix cid . crInvEquipped . ix invid of
-- Just epos -> pointcid . crEquipment . at epos .~ Nothing
-- Nothing -> id
removeAnySlotEquipment = fromMaybe id $ do
epos <- w ^? cWorld . lWorld . creatures . ix cid . crInvEquipped . ix invid
return $ pointcid . crEquipment . at epos .~ Nothing
maxk = fmap fst $ IM.lookupMax $ cr ^. crInv
f inv =
let (xs, ys) = IM.split invid inv