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
+20 -6
View File
@@ -1,11 +1,12 @@
{-# LANGUAGE TupleSections #-}
module Dodge.DisplayInventory (
enterCombineInv,
toggleCombineInv,
updatePositionHUD,
updateInventorySectionItems,
) where
import Dodge.ListDisplayParams
import ListHelp
import Dodge.Data.Combine
import Control.Monad
@@ -19,7 +20,6 @@ import Dodge.Data.Universe
import Dodge.Inventory.CheckSlots
import Dodge.Inventory.Color
import Dodge.Inventory.SelectionList
import Dodge.Render.HUD
import Dodge.SelectionList
import LensHelp
import Picture.Base
@@ -28,8 +28,7 @@ import Regex
-- this should ONLY change the shownitems
updatePositionHUD :: Universe -> Universe
updatePositionHUD u = case u ^? uvWorld . hud . hudElement . subInventory of
Just NoSubInventory -> u & uvWorld . hud . hudElement . diSections
%~ updateDisplayInventory (_uvWorld u) (_uvConfig u)
Just NoSubInventory -> u & updateDisplayInventory
Just CombineInventory {} -> u & uvWorld . hud . hudElement . subInventory . ciSections
%~ updateCombineInventory (_uvWorld u) (_uvConfig u)
_ -> u
@@ -84,8 +83,12 @@ orRegex f x str = case words str of
[] -> True
xs -> any (f x) xs
updateDisplayInventory :: World -> Configuration -> SelectionSections () -> SelectionSections ()
updateDisplayInventory w cfig sss =
updateDisplayInventory :: Universe -> Universe
updateDisplayInventory u = u & uvWorld . hud . hudElement . diSections
%~ updateDisplaySections (_uvWorld u) (_uvConfig u)
updateDisplaySections :: World -> Configuration -> SelectionSections () -> SelectionSections ()
updateDisplaySections w cfig sss =
sss & sssSections
%~ updateSectionsPositioning
mselpos
@@ -129,6 +132,17 @@ updateDisplayInventory w cfig sss =
return $ IM.filter (plainRegex str) itms
numfiltitems = " " ++ show (length itms - length itms') ++ " FILTERED"
-- it is annoying that this is necessary
updateInventorySectionItems :: World -> World
updateInventorySectionItems w = w
& hud . hudElement . diSections . sssSections . ix 0 . ssItems %~ f
where
f olditems = fromMaybe olditems $ do
cr <- w ^? cWorld . lWorld . creatures . ix 0
invitms <- cr ^? crInv
str <- w ^? hud . hudElement . diSections . sssExtra . sssFilters . ix (-1) . _Just
return $ IM.filter (plainRegex str) $ IM.mapWithKey (invSelectionItem' cr) invitms
plainRegex :: String -> SelectionItem a -> Bool
plainRegex = flip $ andOrRegex (\si str -> regexList str (_siPictures si))