Tweak combine inventory regex

This commit is contained in:
2023-02-13 21:18:11 +00:00
parent b5db7a3420
commit 8b39a99194
12 changed files with 78 additions and 88 deletions
+15 -6
View File
@@ -46,17 +46,21 @@ backspaceInputted u = case u ^. uvWorld . input . pressedKeys . at ScancodeBacks
doSubInvRegexInput :: Universe -> Universe
doSubInvRegexInput u
| endkeys || backspacetonothing || endmouse
= u & uvWorld . hud . hudElement . subInventory . subInvMap . smRegexInput .~ False
| backspacetonothing
= u & uvWorld . hud . hudElement . subInventory . subInvMap . smRegex %~ const NoSMRegex
& uvWorld . hud . hudElement . subInventory . subInvMap %~ initialSelPos
| otherwise = u & doTextInputOver (uvWorld . hud . hudElement . subInventory . subInvMap . smRegex)
& uvWorld . hud . hudElement . subInventory . subInvMap %~ setShownIntMap
| endkeys || endmouse
= u & uvWorld . hud . hudElement . subInventory . subInvMap . smRegex . smrInput %~ const False
& uvWorld . hud . hudElement . subInventory . subInvMap %~ initialSelPos
| otherwise = u & doTextInputOver (uvWorld . hud . hudElement . subInventory . subInvMap . smRegex. smrString)
& uvWorld . hud . hudElement . subInventory . subInvMap %~ setShownIntMap
where
endkeys = any
( (== Just InitialPress) . (`M.lookup` pkeys))
[ScancodeReturn,ScancodeEscape,ScancodeSlash]
endmouse = Just True == (u ^? uvWorld . input . mouseButtons . ix ButtonLeft)
backspacetonothing = u ^? uvWorld . hud . hudElement . subInventory . subInvMap . smRegex == Just ""
backspacetonothing = u ^? uvWorld . hud . hudElement . subInventory . subInvMap . smRegex . smrString == Just ""
&& ScancodeBackspace `M.lookup` pkeys == Just InitialPress
pkeys = u ^. uvWorld . input . pressedKeys
@@ -100,14 +104,19 @@ updateKeyInGame uv sc InitialPress = case sc of
-- the following should be put in a more sensible place
--ScancodeSlash -> set (uvWorld . hud . hudElement . subInventory . subInvRegexInput) True uv
ScancodeSlash -> uv
& uvWorld . hud . hudElement . subInventory . subInvMap . smRegexInput .~ True
& uvWorld . hud . hudElement . subInventory . subInvMap . smRegex %~ enterregex
& uvWorld . hud . hudElement . subInventory . subInvMap . smSelPos ?~ 0
ScancodeBackspace -> uv
& uvWorld . hud . hudElement . subInventory . subInvMap . smRegexInput .~ True
& uvWorld . hud . hudElement . subInventory . subInvMap . smRegex %~ enternonzeroregex
& uvWorld . hud . hudElement . subInventory . subInvMap . smSelPos ?~ 0
-- in fact the whole logic should probably be rethought, oh well
_ -> uv
where
enterregex NoSMRegex = SMRegex "" True
enterregex (SMRegex str _) = SMRegex str True
enternonzeroregex (SMRegex (x:xs) _) = SMRegex (init (x:xs)) True
enternonzeroregex smr = smr
updateKeyInGame uv sc LongPress = case sc of
ScancodeF -> over uvWorld youDropItem uv
ScancodeSpace -> over uvWorld spaceAction uv
+4 -3
View File
@@ -35,14 +35,15 @@ updateWheelEvent yi w = case w ^. hud . hudElement of
| otherwise -> stopSoundFrom (CrReloadSound 0) $ changeAugInvSel yi w
DisplayInventory {_subInventory = ExamineInventory mi}
| invKeyDown && rbDown -> w & moveTweakSel yi
| invKeyDown -> stopSoundFrom (CrReloadSound 0) $ changeInvSel yi w
| invKeyDown -> stopSoundFrom (CrReloadSound 0) $ changeAugInvSel yi w
| rbDown -> w & changeTweakParam mi yi
| otherwise -> w & moveTweakSel yi
DisplayInventory {_subInventory = CombineInventory SelectionIntMap {_smRegexInput = False}}
-> w & moveCombineSel yi
DisplayInventory {_subInventory = CombineInventory sm}
| regexnotinput $ _smRegex sm -> w & moveCombineSel yi
DisplayInventory {_subInventory = DisplayTerminal tmid} -> terminalWheelEvent yi tmid w
_ -> w
where
regexnotinput smr = not $ smr ^? smrInput == Just True
y = fromIntegral yi
numLocs = (fst . IM.findMax $ (w ^. cWorld . lWorld . seenLocations)) + 1
rbDown = ButtonRight `M.member` _mouseButtons (_input w)
+6 -4
View File
@@ -30,10 +30,11 @@ updateUsingInput w = case w ^. hud . hudElement of
pressedMBEffects :: SubInventory -> M.Map MouseButton Bool -> World -> World
pressedMBEffects subinv pkeys w = case subinv of
NoSubInventory -> pressedMBEffectsNoInventory pkeys w
CombineInventory SelectionIntMap{_smSelPos = mi, _smRegexInput = False}
| lbinitialpress -> maybeexitcombine (maybe id doCombine mi w)
CombineInventory SelectionIntMap{_smRegexInput = True}
| lbinitialpress -> w & hud . hudElement . subInventory . subInvMap . smRegexInput .~ False
CombineInventory SelectionIntMap{_smSelPos = mi, _smRegex = smr}
| lbinitialpress && regexnotinput smr -> maybeexitcombine (maybe id doCombine mi w)
CombineInventory SelectionIntMap{}
| lbinitialpress -> w & hud . hudElement . subInventory . subInvMap . smRegex. smrInput
%~ const False
DisplayTerminal tmid
| lbinitialpress && inTermFocus w ->
doTerminalEffectLB (w ^?! cWorld . lWorld . terminals . ix tmid) w
@@ -41,6 +42,7 @@ pressedMBEffects subinv pkeys w = case subinv of
w & cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const True
_ -> w
where
regexnotinput smr = not $ smr ^? smrInput == Just True
lbinitialpress = pkeys ^? ix ButtonLeft == Just False
maybeexitcombine w'
| ButtonRight `M.member` _mouseButtons (_input w) =