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
+7 -3
View File
@@ -5,6 +5,7 @@
module Dodge.Data.HUD where
import Data.IntMap
import Control.Lens
import Dodge.Data.Button
import Dodge.Data.Combine
@@ -16,7 +17,8 @@ data HUDElement
= DisplayInventory
{ _subInventory :: SubInventory
, _diSections :: SelectionSections ()
, _diSelection :: Maybe (Int,Int)
, _diSelection :: Maybe (Int, Int)
, _diFilters :: IntMap (Maybe String)
, _diSelectionExtra :: Int
}
| DisplayCarte
@@ -33,8 +35,10 @@ data SubInventory
, _nsMouseOver :: Maybe (Int, Int)
}
| ExamineInventory
| CombineInventory {_ciSections :: SelectionSections CombinableItem
, _ciSelection :: Maybe (Int,Int)
| CombineInventory
{ _ciSections :: SelectionSections CombinableItem
, _ciSelection :: Maybe (Int, Int)
, _ciFilters :: IntMap (Maybe String)
}
| LockedInventory
| DisplayTerminal {_termID :: Int}
+1 -1
View File
@@ -35,7 +35,7 @@ data SelectionList a = SelectionList
data SelectionSections a = SelectionSections
{ _sssSections :: IntMap (SelectionSection a)
, _sssExtra :: SSSExtra
-- , _sssExtra :: SSSExtra
}
-- note that filters are arbitrary: the sssFilters point to the lower of
+7 -6
View File
@@ -168,13 +168,14 @@ defaultDisplayInventory =
, _diSections = defaultInvSections
, _diSelection = Just (1,0)
, _diSelectionExtra = 0
, _diFilters = IM.fromList [(-1, mempty), (2, mempty)]
}
defaultSSSExtra :: SSSExtra
defaultSSSExtra =
SSSExtra
{ _sssFilters = IM.fromList [(-1, mempty), (2, mempty)]
}
--defaultSSSExtra :: SSSExtra
--defaultSSSExtra =
-- SSSExtra
-- { _sssFilters = IM.fromList [(-1, mempty), (2, mempty)]
-- }
defaultInvSections :: SelectionSections ()
defaultInvSections =
@@ -190,7 +191,7 @@ defaultInvSections =
& ssDescriptor .~ "NEARBY"
, defaultCOSection
]
, _sssExtra = defaultSSSExtra
-- , _sssExtra = defaultSSSExtra
}
defaultSS :: SelectionSection a
+3 -6
View File
@@ -61,7 +61,7 @@ updateCombineSections w cfig =
IM.singleton
0
(SelectionInfo ["COMBINATIONS FILTER: " ++ str, numfiltitems] 2 True white 0)
mstr = w ^? hud . hudElement . subInventory . ciSections . sssExtra . sssFilters . ix (-1) . _Just
mstr = w ^? hud . hudElement . subInventory . ciFilters . ix (-1) . _Just
numfiltitems = " " ++ show (length allcombs - length filtcombs) ++ " FILTERED"
regexCombs :: IM.IntMap (SelectionItem ()) -> SelectionItem CombinableItem -> String -> Bool
@@ -127,7 +127,7 @@ updateDisplaySections w cfig sss =
, (i + 1, itms')
)
where
mstr = w ^? hud . hudElement . diSections . sssExtra . sssFilters . ix i . _Just
mstr = w ^? hud . hudElement . diFilters . ix i . _Just
filtsis = fromMaybe mempty $ do
str <- mstr
return $
@@ -247,6 +247,7 @@ listSelectionColorPicture = foldMap f
enterCombineInv :: Configuration -> World -> World
enterCombineInv cfig w = w & hud . hudElement . subInventory .~ CombineInventory sss selpos
(IM.singleton (-1) Nothing)
where
cm' = IM.fromDistinctAscList . zip [0 ..] $ combineList w
cm
@@ -255,10 +256,6 @@ enterCombineInv cfig w = w & hud . hudElement . subInventory .~ CombineInventory
sss =
SelectionSections
{ _sssSections = IM.fromDistinctAscList [(-1, filtsection), (0, combsection)]
, _sssExtra =
SSSExtra
{ _sssFilters = IM.singleton (-1) Nothing
}
}
selpos
| null cm' = Nothing
+37 -37
View File
@@ -5,8 +5,8 @@ module Dodge.InputFocus (
inSubInvRegex,
inputFocus,
inInputFocus,
regexScope,
regexFocus,
-- regexScope,
-- regexFocus,
) where
import Control.Monad
@@ -22,40 +22,40 @@ inTermFocus w = fromMaybe False $ do
connectionstatus <- w ^? cWorld . lWorld . terminals . ix tmid . tmStatus
return $ hasfocus && connectionstatus == TerminalReady
regexScope ::
(Applicative f) =>
World ->
Maybe ((SSSExtra -> f SSSExtra) -> HUDElement -> f HUDElement, Int)
regexScope w = case w ^? hud . hudElement . subInventory of
Just NoSubInventory{} -> case he ^? diSelection . _Just of
Just (-1, _) -> di (-1)
Just (0, _) -> di (-1)
Just (2, _) -> di 2
Just (3, _) -> di 2
_ -> Nothing
Just CombineInventory{} ->
Just (subInventory . ciSections . sssExtra, -1)
_ -> Nothing
where
di x = Just (diSections . sssExtra, x)
he = w ^. hud . hudElement
--regexScope ::
-- (Applicative f) =>
-- World ->
-- Maybe ((SSSExtra -> f SSSExtra) -> HUDElement -> f HUDElement, Int)
--regexScope w = case w ^? hud . hudElement . subInventory of
-- Just NoSubInventory{} -> case he ^? diSelection . _Just of
-- Just (-1, _) -> di (-1)
-- Just (0, _) -> di (-1)
-- Just (2, _) -> di 2
-- Just (3, _) -> di 2
-- _ -> Nothing
-- Just CombineInventory{} ->
-- Just (subInventory . ciSections . sssExtra, -1)
-- _ -> Nothing
-- where
-- di x = Just (diSections . sssExtra, x)
-- he = w ^. hud . hudElement
regexFocus ::
(Applicative f) =>
World ->
Maybe
((SSSExtra -> f SSSExtra) -> HUDElement -> f HUDElement, Int)
regexFocus w = case w ^? hud . hudElement . subInventory of
Just NoSubInventory{} -> case he ^? diSelection . _Just of
Just (-1, _) -> di (-1)
Just (2, _) -> di 2
_ -> Nothing
Just CombineInventory{} ->
Just (subInventory . ciSections . sssExtra, -1)
_ -> Nothing
where
di x = Just (diSections . sssExtra, x)
he = w ^. hud . hudElement
--regexFocus ::
-- (Applicative f) =>
-- World ->
-- Maybe
-- ((SSSExtra -> f SSSExtra) -> HUDElement -> f HUDElement, Int)
--regexFocus w = case w ^? hud . hudElement . subInventory of
-- Just NoSubInventory{} -> case he ^? diSelection . _Just of
-- Just (-1, _) -> di (-1)
-- Just (2, _) -> di 2
-- _ -> Nothing
-- Just CombineInventory{} ->
-- Just (subInventory . ciSections . sssExtra, -1)
-- _ -> Nothing
-- where
-- di x = Just (diSections . sssExtra, x)
-- he = w ^. hud . hudElement
inInputFocus :: World -> Bool
inInputFocus = isJust . inputFocusI
@@ -73,7 +73,7 @@ inputFocus w = case w ^? hud . hudElement . subInventory of
Just (2, _) -> di 2
_ -> Nothing
Just CombineInventory{} -> case he ^? subInventory . ciSelection . _Just of
Just (-1, _) -> Just $ hud . hudElement . subInventory . ciSections . sssExtra . sssFilters . ix (-1) . _Just
Just (-1, _) -> Just $ hud . hudElement . subInventory . ciFilters . ix (-1) . _Just
_ -> Nothing
Just DisplayTerminal{_termID = tmid} -> do
hasfocus <- w ^? cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus
@@ -82,7 +82,7 @@ inputFocus w = case w ^? hud . hudElement . subInventory of
return $ cWorld . lWorld . terminals . ix tmid . tmInput . tiText
_ -> Nothing
where
di x = Just $ hud . hudElement . diSections . sssExtra . sssFilters . ix x . _Just
di x = Just $ hud . hudElement . diFilters . ix x . _Just
he = w ^. hud . hudElement
inTopRegex :: Int -> World -> Bool
+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