From efef41c9e102af2d4a1be0aad02afa7543a16964 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 20 Nov 2024 19:58:24 +0000 Subject: [PATCH] Inventory: allow selection and dropping by dragging while filtering --- ghcidOutput | 2 +- src/Dodge/Combine.hs | 2 +- src/Dodge/Data/Combine.hs | 1 - src/Dodge/Render/HUD.hs | 15 ++------------- src/Dodge/Update/Input/InGame.hs | 11 +++++++++-- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/ghcidOutput b/ghcidOutput index d953b4ed1..49fd7aa01 100644 --- a/ghcidOutput +++ b/ghcidOutput @@ -1 +1 @@ -All good (594 modules, at 17:18:47) +All good (594 modules, at 19:56:08) diff --git a/src/Dodge/Combine.hs b/src/Dodge/Combine.hs index dc4d28426..dfa9cf5f7 100644 --- a/src/Dodge/Combine.hs +++ b/src/Dodge/Combine.hs @@ -27,7 +27,7 @@ combineList = map f . combineItemListYouX , _siIsSelectable = True , _siColor = itemInvColor . pciToCI $ basePCI itm , _siOffX = 0 - , _siPayload = CombinableItem is itm [] + , _siPayload = CombinableItem is itm } combineItemListYouX :: World -> [([Int], Item)] diff --git a/src/Dodge/Data/Combine.hs b/src/Dodge/Data/Combine.hs index 3338bf1e7..176f649c9 100644 --- a/src/Dodge/Data/Combine.hs +++ b/src/Dodge/Data/Combine.hs @@ -5,6 +5,5 @@ import Dodge.Data.Item data CombinableItem = CombinableItem { _ciInvIDs :: [Int] , _ciItem :: Item - , _ciInfo :: [String] } makeLenses ''CombinableItem diff --git a/src/Dodge/Render/HUD.hs b/src/Dodge/Render/HUD.hs index a8da215ab..8a97a2f2c 100644 --- a/src/Dodge/Render/HUD.hs +++ b/src/Dodge/Render/HUD.hs @@ -341,22 +341,11 @@ combineInventoryExtra :: Picture combineInventoryExtra sss msel cfig w = fromMaybe mempty $ do (i, j) <- msel - cpos <- selSecYint i j sss si <- sss ^? ix i . ssItems . ix j let col = _siColor si - mconcat - [ do - strs <- si ^? siPayload . ciInfo - return - . translate 160 0 - -- it would be better to get the width of the selection list from elsewhere - . translateScreenPos cfig (secondColumnParams ^. ldpPos) - $ drawListYoff cpos $ map (color red . text) strs - , do - lnks <- si ^? siPayload . ciInvIDs - return (lnkMidPosInvSelsCol cfig w j col lnks) + lnks <- si ^? siPayload . ciInvIDs + return (lnkMidPosInvSelsCol cfig w j col lnks) <> foldMap invcursor lnks - ] where invcursor i = do sss' <- w ^? hud . hudElement . diSections diff --git a/src/Dodge/Update/Input/InGame.hs b/src/Dodge/Update/Input/InGame.hs index aeb64a66b..b8d506ea2 100644 --- a/src/Dodge/Update/Input/InGame.hs +++ b/src/Dodge/Update/Input/InGame.hs @@ -3,6 +3,7 @@ module Dodge.Update.Input.InGame ( updateMouseInGame, ) where +import Data.Foldable import Control.Applicative import Control.Monad import qualified Data.IntMap.Strict as IM @@ -127,9 +128,15 @@ updateMouseReleaseInGame w = case w ^. input . mouseContext of OverInvDragSelect ssel (Just esel) -> w & input . mouseContext .~ MouseInGame & hud . hudElement . diSelectionExtra - .~ IS.fromAscList [min (snd ssel) (snd esel) + 1 .. max (snd ssel) (snd esel)] + .~ h (snd 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 + let (_,xss) = IM.split ((min i j)-1) sss + (yss,_) = IM.split ((max i j)+1) xss + return . IM.keysSet $ yss updateMouseClickInGame :: Configuration -> World -> World updateMouseClickInGame cfig w = case w ^. input . mouseContext of @@ -483,7 +490,7 @@ tryCombine :: World tryCombine (i, j) w = fromMaybe w $ do sss <- w ^? hud . hudElement . subInventory . ciSections - CombinableItem is it _ <- sss ^? ix i . ssItems . ix j . siPayload + CombinableItem is it <- sss ^? ix i . ssItems . ix j . siPayload p <- w ^? cWorld . lWorld . creatures . ix 0 . crPos return $ snd (createItemYou it (foldr (destroyInvItem 0) w (sort is)))