Allow filtering of combinations with mouse click on inventory

This commit is contained in:
2024-11-04 00:07:37 +00:00
parent adca54c1ef
commit fafef1275b
11 changed files with 125 additions and 80 deletions
+48 -27
View File
@@ -2,7 +2,7 @@ module Dodge.Update.Input.InGame (
updateUseInputInGame,
) where
import Dodge.SoundLogic
import Control.Monad
import Control.Applicative
import qualified Data.IntMap.Strict as IM
import Data.List (sort)
@@ -23,6 +23,7 @@ import Dodge.Inventory.Add
import Dodge.Menu
import Dodge.Save
import Dodge.SelectionSections
import Dodge.SoundLogic
import Dodge.Terminal.LeftButton
import Dodge.Update.Input.Text
import Dodge.WorldPos
@@ -40,16 +41,13 @@ updateUseInputInGame u = case u ^. uvWorld . hud . hudElement of
| inTermFocus (_uvWorld u) -> updateKeysInTerminal tmid u
| lbinitialpress ->
u & uvWorld . cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const True
CombineInventory{_ciSections = sss, _ciSelection = msel}
CombineInventory{_ciSections = sss, _ciSelection = msel}
| lbinitialpress -> u & uvWorld %~ updateCombineInvClick msel sss
| inSubInvRegex (u ^. uvWorld) ->
u
& uvWorld . hud . hudElement . subInventory
%~ docombineregexinput
%~ docombineregexinput sss msel
& uvWorld . worldEventFlags . at CombineInventoryChange ?~ ()
| lbinitialpress ->
(uvWorld . worldEventFlags . at InventoryChange ?~ ()) . maybeExitCombine $
over uvWorld (tryCombine sss msel) u
& uvWorld . worldEventFlags . at CombineInventoryChange ?~ ()
_
| inInvRegex (u ^. uvWorld) ->
u & uvWorld . hud . hudElement %~ dodisplayregexinput (-1)
@@ -67,15 +65,6 @@ updateUseInputInGame u = case u ^. uvWorld . hud . hudElement of
w = u ^. uvWorld
pkeys = u ^. uvWorld . input . pressedKeys
lbinitialpress = u ^? uvWorld . input . mouseButtons . ix ButtonLeft == Just 0
docombineregexinput ci = fromMaybe ci $ do
sss <- ci ^? ciSections
msel <- ci ^? ciSelection
filts <- ci ^? ciFilter
let (sss', msel', filts') = doRegexInput (u ^. uvWorld . input) (-1) sss msel filts
return $
ci & ciSections .~ sss'
& ciSelection .~ msel'
& ciFilter .~ filts'
dodisplayregexinput x di = fromMaybe di $ do
sss <- di ^? diSections
msel <- di ^? diSelection
@@ -94,6 +83,37 @@ updateUseInputInGame u = case u ^. uvWorld . hud . hudElement of
di & diSections .~ sss'
& diSelection .~ msel'
& diCloseFilter .~ filts'
docombineregexinput sss msel ci = fromMaybe ci $ do
filts <- ci ^? ciFilter
let (sss', msel', filts') = doRegexInput (u ^. uvWorld . input) (-1) sss msel filts
return $
ci & ciSections .~ sss'
& ciSelection .~ msel'
& ciFilter .~ filts'
updateCombineInvClick ::
Maybe (Int, Int) ->
IM.IntMap (SelectionSection CombinableItem) ->
World ->
World
updateCombineInvClick msel sss w = fromMaybe trydocombination $ do
(i,j) <- w ^? hud . hudElement . diMouseOver . _Just
guard $ i == 0
str <- fmap (take 5) $ w ^? hud . hudElement . diSections . ix i . ssItems . ix j . siPictures . ix 0
return . (worldEventFlags . at CombineInventoryChange ?~ ()) $ case w ^? hud . hudElement . subInventory . ciFilter . _Just of
Just (_:xs) | str == xs -> w
& hud . hudElement . subInventory . ciFilter .~ Nothing
_ -> w & hud . hudElement . subInventory . ciFilter ?~ ("<" ++ str)
where
trydocombination =
(worldEventFlags . at InventoryChange ?~ ()) . maybeExitCombine $
tryCombine sss msel w
& worldEventFlags . at CombineInventoryChange ?~ ()
--checkCombineSelectionExists :: SubInventory -> SubInventory
--checkCombineSelectionExists x@CombineInventory{_ciSections=sss,_ciSelection=msel}
-- = x & ciSelection %~ ssSetCursor (ssTryLookup msel) sss
--checkCombineSelectionExists x = x
updatePressedButtonsCarte :: World -> World
updatePressedButtonsCarte w = updatePressedButtonsCarte' (_mouseButtons (_input w)) w
@@ -276,11 +296,11 @@ spaceAction w = case w ^. hud . hudElement of
_ -> w
DisplayInventory{_subInventory = DisplayTerminal{}} ->
w & hud . hudElement . subInventory
.~ NoSubInventory MouseInvNothing Nothing
.~ NoSubInventory MouseInvNothing
& worldEventFlags . at InventoryChange ?~ ()
_ ->
w & hud . hudElement . subInventory
.~ NoSubInventory MouseInvNothing Nothing
.~ NoSubInventory MouseInvNothing
where
theLoc =
doWorldPos
@@ -292,13 +312,14 @@ toggleMap u = case u ^. uvWorld . hud . hudElement of
DisplayCarte ->
u & uvWorld . hud . hudElement
.~ DisplayInventory
{ _subInventory = NoSubInventory MouseInvNothing Nothing
{ _subInventory = NoSubInventory MouseInvNothing
, _diSections = defaultInvSections
, _diSelection = Nothing
, _diSelectionExtra = 0
-- , _diFilters = IM.fromList [(-1, mempty), (2, mempty)]
, _diInvFilter = mempty
, -- , _diFilters = IM.fromList [(-1, mempty), (2, mempty)]
_diInvFilter = mempty
, _diCloseFilter = mempty
, _diMouseOver = Nothing
}
_ -> u & uvWorld . hud . hudElement .~ DisplayCarte
@@ -306,7 +327,7 @@ toggleTweakInv :: World -> World
toggleTweakInv w = case w ^? hud . hudElement . subInventory of
Just ExamineInventory{} ->
w
& thepointer .~ NoSubInventory MouseInvNothing Nothing
& thepointer .~ NoSubInventory MouseInvNothing
_ -> w & thepointer .~ ExamineInventory -- mi
where
thepointer = hud . hudElement . subInventory
@@ -325,9 +346,9 @@ tryCombine sss msel w = fromMaybe w $ do
& cWorld . lWorld . creatures . ix 0 . crHammerPosition .~ HammerDown
& soundStart InventorySound p wrench1S Nothing
maybeExitCombine :: Universe -> Universe
maybeExitCombine u
| ButtonRight `M.member` (u ^. uvWorld . input . mouseButtons) = u
maybeExitCombine :: World -> World
maybeExitCombine w
| ButtonRight `M.member` (w ^. input . mouseButtons) = w
| otherwise =
u & uvWorld . hud . hudElement . subInventory
.~ NoSubInventory MouseInvNothing Nothing
w & hud . hudElement . subInventory
.~ NoSubInventory MouseInvNothing