Move SSSExtra out of SelectionSections

This commit is contained in:
2024-10-25 21:55:09 +01:00
parent 069392bd33
commit a20fc48eaa
8 changed files with 207 additions and 181 deletions
+25 -17
View File
@@ -69,17 +69,21 @@ updateUseInputInGame u = case u ^. uvWorld . hud . hudElement of
docombineregexinput ci = fromMaybe ci $ do
sss <- ci ^? ciSections
msel <- ci ^? ciSelection
let (sss', msel') = doRegexInput (u ^. uvWorld . input) (-1) sss msel
filts <- ci ^? ciFilters
let (sss', msel',filts') = doRegexInput (u ^. uvWorld . input) (-1) sss msel filts
return $
ci & ciSections .~ sss'
& ciSelection .~ msel'
& ciFilters .~ filts'
dodisplayregexinput x di = fromMaybe di $ do
sss <- di ^? diSections
msel <- di ^? diSelection
let (sss', msel') = doRegexInput (u ^. uvWorld . input) x sss msel
filts <- di ^? diFilters
let (sss', msel',filts') = doRegexInput (u ^. uvWorld . input) x sss msel filts
return $
di & diSections .~ sss'
& diSelection .~ msel'
& diFilters .~ filts'
updatePressedButtonsCarte :: World -> World
updatePressedButtonsCarte w = updatePressedButtonsCarte' (_mouseButtons (_input w)) w
@@ -154,19 +158,22 @@ doRegexInput ::
Int ->
SelectionSections a ->
Maybe (Int, Int) ->
(SelectionSections a, Maybe (Int, Int))
doRegexInput inp i sss msel
IM.IntMap (Maybe String) ->
(SelectionSections a, Maybe (Int, Int), IM.IntMap (Maybe String))
doRegexInput inp i sss msel filts
| backspacetonothing || escapekey = endregex i 0
| endkeys || endmouse = endregex (i + 1) (j -1)
| otherwise =
( sss & doTextInputOver inp (sssExtra . sssFilters . ix i . _Just)
( sss
, msel
, filts & doTextInputOver inp (ix i . _Just)
)
where
endregex a b =
( sss & sssExtra . sssFilters . ix i .~ Nothing
( sss
& sssSections . ix i . ssItems .~ mempty
, msel & ssSetCursor (ssLookupDown a b) sss
, filts & ix i .~ Nothing
)
j = fromMaybe 0 $ do
itms <- sss ^? sssSections . ix (i + 1) . ssItems
@@ -178,7 +185,7 @@ doRegexInput inp i sss msel
[ScancodeReturn, ScancodeSlash]
endmouse = (Just 0 ==) $ inp ^? mouseButtons . ix ButtonLeft
backspacetonothing =
sss ^? sssExtra . sssFilters . ix i . _Just == Just ""
filts ^? ix i . _Just == Just ""
&& ScancodeBackspace `M.lookup` pkeys == Just InitialPress
pkeys = inp ^. pressedKeys
@@ -202,20 +209,20 @@ updateBackspaceRegex w = case di ^? subInventory of
return $ i == a || i == b
trybackspace x he = fromMaybe he $ do
sss <- he ^? diSections
str <- sss ^? sssExtra . sssFilters . ix x . _Just
str <- he ^? diFilters . ix x . _Just
return $ case str of
(_ : _) ->
he & diSections . sssExtra . sssFilters . ix x . _Just %~ init
he & diFilters . ix x . _Just %~ init
& diSelection ?~ (x, 0)
[] -> he & diSections . sssExtra . sssFilters . ix x .~ Nothing
[] -> he & diFilters . ix x .~ Nothing
trybackspace' x ci = fromMaybe ci $ do
sss <- ci ^? ciSections
str <- sss ^? sssExtra . sssFilters . ix x . _Just
str <- ci ^? ciFilters . ix x . _Just
return $ case str of
(_ : _) ->
ci & ciSections . sssExtra . sssFilters . ix x . _Just %~ init
ci & ciFilters . ix x . _Just %~ init
& ciSelection ?~ (x, 0)
[] -> ci & ciSections . sssExtra . sssFilters . ix x .~ Nothing
[] -> ci & ciFilters . ix x .~ Nothing
di = w ^. hud . hudElement
updateEnterRegex :: World -> World
@@ -223,13 +230,13 @@ updateEnterRegex w = case w ^? hud . hudElement . subInventory of
Just NoSubInventory{}
| secfocus (-1) 0 ->
w & hud . hudElement . diSelection ?~ (-1, 0)
& hud . hudElement . diSections %~ enterregex (-1)
& hud . hudElement . diFilters %~ enterregex (-1)
Just NoSubInventory{}
| secfocus 2 3 ->
w & hud . hudElement . diSelection ?~ (2, 0)
& hud . hudElement . diSections %~ enterregex 2
& hud . hudElement . diFilters %~ enterregex 2
Just CombineInventory{} ->
w & hud . hudElement . subInventory . ciSections %~ enterregex (-1)
w & hud . hudElement . subInventory . ciFilters %~ enterregex (-1)
& hud . hudElement . subInventory . ciSelection ?~ (-1, 0)
_ -> w
where
@@ -237,7 +244,7 @@ updateEnterRegex w = case w ^? hud . hudElement . subInventory of
secfocus a b = fromMaybe False $ do
i <- di ^? diSelection . _Just . _1
return $ i == a || i == b
enterregex x = sssExtra . sssFilters . ix x %~ (<|> Just "")
enterregex x = ix x %~ (<|> Just "")
pauseGame :: Universe -> Universe
pauseGame u = u & uvScreenLayers .~ [pauseMenu u]
@@ -275,6 +282,7 @@ toggleMap u = case u ^. uvWorld . hud . hudElement of
, _diSections = defaultInvSections
, _diSelection = Nothing
, _diSelectionExtra = 0
, _diFilters = IM.fromList [(-1, mempty), (2, mempty)]
}
_ -> u & uvWorld . hud . hudElement .~ DisplayCarte