Cleanup item swapping

This commit is contained in:
2026-05-18 08:59:41 +01:00
parent 75734d06af
commit 794d733c83
5 changed files with 11 additions and 28 deletions
+1 -2
View File
@@ -17,8 +17,7 @@ data MouseContext
| MouseInGame
| MouseMenu {_mcoMenuClick :: Maybe Int}
| OverInvDrag {_mcoDragSection :: Int }
-- | OverInvDrag {_mcoDragSection :: Int , _mcoMaybeSelect :: Maybe (Int,Int) }
| OverInvDragSelect { _mcoSecSelStart :: XInfinity (Int,Int) } --, _mcoSelEnd :: Maybe (XInfinity (Int,Int)) }
| OverInvDragSelect { _mcoSecSelStart :: XInfinity (Int,Int) }
| OverInvSelect { _mcoInvSelect :: (Int,Int)}
| OverCombFiltInv { _mcoInvFilt :: (Int,Int)}
| OverCombSelect { _mcoCombSelect :: (Int,Int)}
+1 -1
View File
@@ -233,7 +233,7 @@ changeSwapOther n f i w = fromMaybe w $ do
| otherwise = j
return $
w
& swapAnyExtraSelection 3 i k
& hud . diSections . ix 3 . ssSet %~ swapInIntSet i k
& hud . closeItems %~ swapIndices i k
& hud . diSelection . _Just . slInt %~ doswap
& worldEventFlags . at InventoryChange ?~ ()
+4 -15
View File
@@ -1,6 +1,6 @@
module Dodge.Inventory.Swap (
swapInvItems,
swapAnyExtraSelection
swapInIntSet,
) where
import Linear
@@ -34,7 +34,7 @@ swapInvItems f i w = fromMaybe w $ do
_ -> id
return $
w
& swapAnyExtraSelection 0 i k
& hud . diSections . ix 0 . ssSet %~ swapInIntSet i k
& checkConnection InventorySound disconnectItemS i k
& cWorld . lWorld . creatures . ix 0 %~ updatecreature k
& updateselection
@@ -54,22 +54,11 @@ swapInvItems f i w = fromMaybe w $ do
Just epos -> crEquipment . ix epos .~ NInt b
Nothing -> id
swapAnyExtraSelection :: Int -> Int -> Int -> World -> World
swapAnyExtraSelection seci i k w = w
& hud . diSections . ix seci . ssSet %~ f
where
f is
swapInIntSet :: Int -> Int -> IS.IntSet -> IS.IntSet
swapInIntSet i k is
| i `IS.member` is && not (k `IS.member` is) = IS.insert k $ IS.delete i is
| k `IS.member` is && not (i `IS.member` is) = IS.insert i $ IS.delete k is
| otherwise = is
-- fromMaybe w $ do
-- is <- w ^? hud . diSelection . _Just . slSet
-- let f = if i `IS.member` is then IS.insert k else id
-- g = if k `IS.member` is then IS.insert i else id
-- return $
-- w & hud . diSelection . _Just . slSet
-- %~ (f . g . IS.delete i . IS.delete k)
checkConnection :: SoundOrigin -> SoundID -> Int -> Int -> World -> World
checkConnection so s i j w = fromMaybe w $ do
-1
View File
@@ -450,7 +450,6 @@ updateMouseContextGame cfig u = \case
return $ OverInvSelect selpos
overcomb = do
sss <- w ^? hud . subInventory . ciSections
-- Sel xl xr _ <- w ^? hud . subInventory . ciSelection . _Just
Sel xl xr <- w ^? hud . subInventory . ciSelection . _Just
let msel = (xl, xr)
let mpossel = inverseSelNumPos cfig secondColumnLDP (w ^. input . mousePos) sss ^? _Just . nonInf
+5 -9
View File
@@ -72,10 +72,8 @@ updateUseInputInGame u = updateFunctionKeys $ case u ^. uvWorld . hud . subInven
& filterlens .~ filts'
docombineregexinput sss msel ci = fromMaybe ci $ do
filts <- ci ^? ciFilter
--let (sss', msel', filts') = doRegexInput (u ^. uvWorld . input) (-1) sss msel filts
let ( msel', filts') = doRegexInput (u ^. uvWorld . input) (-1) sss msel filts
return $ ci
-- & ciSections .~ sss'
& ciSelection .~ msel'
& ciFilter .~ filts'
@@ -219,6 +217,9 @@ mouseInvPos u = inverseSelNumPos
updateMouseClickInGame :: Universe -> Universe
updateMouseClickInGame u = case w ^. input . mouseContext of
MouseInGame -> u & uvWorld . input . mouseContext .~ OverInvDragSelect (mouseInvHeight u)
OverInvSelect x
| ScancodeLShift `M.member` (w ^. input . pressedKeys) ->
u & uvWorld . input . mouseContext .~ OverInvDragSelect (NonInf x)
OverInvSelect (-1, _)
| selsec == Just (-1) ->
u
@@ -233,9 +234,6 @@ updateMouseClickInGame u = case w ^. input . mouseContext of
k <- w ^? hud . closeButtons . ix j
but <- w ^? cWorld . lWorld . buttons . ix k
return $ u & uvWorld %~ doButtonEvent (but ^. btEvent) but
OverInvSelect x
| ScancodeLShift `M.member` (w ^. input . pressedKeys) ->
u & uvWorld . input . mouseContext .~ OverInvDragSelect (NonInf x)
OverInvSelect x -> u & uvWorld %~ startDrag x
OverTerminal tmid TerminalTextInput{} -> u & uvWorld %~ terminalReturnEffect tmid
OverTerminal tmid TerminalPressTo{} -> u & uvWorld %~ continueTerminal tmid
@@ -460,14 +458,12 @@ doRegexInput inp i sss msel filts
| backspacetonothing || escapekey = endregex i 0
| endkeys = endregex (i + 1) (j - 1)
| otherwise =
(-- sss ,
msel
( msel
, filts & doTextInputOver inp _Just
)
where
endregex a b =
(-- sss ,
msel & ssSetCursor (ssLookupDown a b) sss
( msel & ssSetCursor (ssLookupDown a b) sss
, Nothing
)
j = fromMaybe 0 $ do