Start adding filters to selection lists

This commit is contained in:
2023-01-15 11:55:32 +00:00
parent 6f1162f7b9
commit 64b1c2761e
16 changed files with 128 additions and 66 deletions
+34 -18
View File
@@ -2,6 +2,7 @@ module Dodge.Update.Input (
updateKeyInGame,
updateKeysInTerminal,
doInputScreenInput,
doSubInvRegexInput,
) where
import qualified Data.Map.Strict as M
@@ -22,22 +23,15 @@ import Dodge.WorldPos
import LensHelp
import SDL
doInputScreenInput :: T.Text -> Universe -> Universe
doInputScreenInput s u =
u & uvScreenLayers . _head . scInput %~ (`T.append` T.toUpper thetext)
& checkBackspace
& checkEndStatus
doTextInputOver :: ASetter' Universe T.Text -> Universe -> Universe
doTextInputOver p u = u & p %~ (`T.append` T.toUpper thetext)
& checkBackspace
where
thetext = u ^. uvWorld . input . textInput
checkBackspace
| backspaceInputted u = uvScreenLayers . _head . scInput %~ doBackspace
| backspaceInputted u = p %~ doBackspace
| otherwise = id
pkeys = u ^. uvWorld . input . pressedKeys
checkEndStatus
| ScancodeReturn `M.member` pkeys = (uvScreenLayers %~ tail) . applyTerminalString (words $ T.unpack s)
| ScancodeEscape `M.member` pkeys = uvScreenLayers %~ tail
| otherwise = id
doBackspace :: T.Text -> T.Text
doBackspace t = case T.unsnoc t of
Nothing -> t
@@ -49,17 +43,35 @@ backspaceInputted u = case u ^. uvWorld . input . pressedKeys . at ScancodeBacks
Just LongPress -> True
_ -> False
doSubInvRegexInput :: Universe -> Universe
doSubInvRegexInput u = u
& doTextInputOver (uvWorld . hud . hudElement . subInventory . subInvRegex)
& checkEndStatus
where
pkeys = u ^. uvWorld . input . pressedKeys
checkEndStatus
| any ( (== Just InitialPress) . (`M.lookup` pkeys)) [ScancodeReturn,ScancodeEscape,ScancodeSlash]
= uvWorld . hud . hudElement . subInventory . subInvRegexInput .~ False
| otherwise = id
doInputScreenInput :: T.Text -> Universe -> Universe
doInputScreenInput s u =
u & doTextInputOver (uvScreenLayers . _head . scInput)
& checkEndStatus
where
pkeys = u ^. uvWorld . input . pressedKeys
checkEndStatus
| ScancodeReturn `M.member` pkeys = (uvScreenLayers %~ tail)
. applyTerminalString (words $ T.unpack s)
| ScancodeEscape `M.member` pkeys = uvScreenLayers %~ tail
| otherwise = id
updateKeysInTerminal :: Int -> Universe -> Universe
updateKeysInTerminal tmid u =
u & tmpoint %~ (`T.append` T.toUpper thetext)
& checkBackspace
u & doTextInputOver tmpoint
& checkEndStatus
where
tmpoint = uvWorld . cWorld . lWorld . terminals . ix tmid . tmInput . tiText
thetext = u ^. uvWorld . input . textInput
checkBackspace
| backspaceInputted u = tmpoint %~ doBackspace
| otherwise = id
pkeys = u ^. uvWorld . input . pressedKeys
checkEndStatus
| pkeys ^. at ScancodeReturn == Just InitialPress =
@@ -79,6 +91,10 @@ updateKeyInGame uv sc InitialPress = case sc of
ScancodeT -> over uvWorld testEvent uv
ScancodeX -> uv & uvWorld %~ toggleTweakInv
ScancodeC -> over uvWorld toggleCombineInv uv
-- the following should be put in a more sensible place
--ScancodeSlash -> set (uvWorld . hud . hudElement . subInventory . subInvRegexInput) True uv
ScancodeSlash -> set (uvWorld . hud . hudElement . subInventory . subInvRegexInput) True uv
-- in fact the whole logic should probably be rethought, oh well
_ -> uv
updateKeyInGame uv sc LongPress = case sc of
ScancodeF -> over uvWorld youDropItem uv
+3 -1
View File
@@ -30,9 +30,11 @@ pressedMBEffects subinv pkeys w = case subinv of
| ButtonLeft `M.member` pkeys && w ^?! input . hammers . ix SubInvHam /= HammerUp ->
w & input . hammers . ix SubInvHam .~ HammerDown
| otherwise -> pressedMBEffectsNoInventory pkeys w
CombineInventory mi
CombineInventory mi _ False
| pkeys ^? ix ButtonLeft == Just False ->
maybeexitcombine (maybe id doCombine mi w) & input . hammers . ix SubInvHam .~ HammerDown
CombineInventory _ _ True | pkeys ^? ix ButtonLeft == Just False
-> w & hud . hudElement . subInventory . subInvRegexInput .~ False
DisplayTerminal tmid
| pkeys ^? ix ButtonLeft == Just False && inTermFocus w ->
doTerminalEffectLB (w ^?! cWorld . lWorld . terminals . ix tmid) w