Simplify selection menu, remove overlapping

This commit is contained in:
2024-09-11 16:39:56 +01:00
parent c72278f728
commit eddb313ea1
9 changed files with 167 additions and 169 deletions
+27 -19
View File
@@ -55,14 +55,14 @@ updateCombineSections w cfig sss =
invitms <- w ^? hud . hudElement . diSections . sssSections . ix 0 . ssItems
return $ IM.filter (flip (andOrRegex $ regexCombs invitms) str) allcombs
showncombs
| null filtcombs = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0 0
| null filtcombs = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0
| otherwise = filtcombs
filtinv = fromMaybe mempty $ do
str <- mstr
return $
IM.singleton
0
(SelectionInfo ["COMBINATIONS FILTER: " ++ str, numfiltitems] 2 True white 0 0)
(SelectionInfo ["COMBINATIONS FILTER: " ++ str, numfiltitems] 2 True white 0)
mstr = w ^? hud . hudElement . subInventory . ciSections . sssExtra . sssFilters . ix (-1) . _Just
numfiltitems = " " ++ show (length allcombs - length filtcombs) ++ " FILTERED"
@@ -107,7 +107,7 @@ updateDisplaySections w cfig sss =
(filtinv, invx) = filtpair (-1) invitems' "INV. "
(filtclose, closex) = filtpair 2 coitems' "NEARBY "
youx = (1, youitems)
youitems = IM.singleton 0 $ SelectionItem [thetext] 1 True invDimColor 2 0 ()
youitems = IM.singleton 0 $ SelectionItem [thetext] 1 True invDimColor 2 ()
thetext = displayFreeSlots nfreeslots
availablelines = getAvailableListLines (invDisplayParams w) cfig
coitems' =
@@ -131,7 +131,7 @@ updateDisplaySections w cfig sss =
return $
IM.singleton
0
(SelectionInfo [filtdescription ++ "FILTER: " ++ str, numfiltitems] 2 True white 0 0)
(SelectionInfo [filtdescription ++ "FILTER: " ++ str, numfiltitems] 2 True white 0)
itms' = fromMaybe itms $ do
str <- mstr
return $ IM.filter (plainRegex str) itms
@@ -246,25 +246,33 @@ updateSection sis mcsel availablelines ss =
| otherwise = tweakfirst shownstrings
moredowncolor = fromMaybe white $ allstrings ^? ix (offset + availablelines - 1) . _1
allstrings :: [(Color, Picture)]
allstrings = IM.elems $ overlapSelectionItems $ IM.elems sis
-- allstrings = IM.elems $ overlapSelectionItems $ IM.elems sis
allstrings = listSelectionColorPicture sis
shownstrings = drop offset allstrings
h (_, str) = translate (fromIntegral (_ssIndent ss) * 100) 0 str
theindent = replicate (_ssIndent ss) ' '
--xtra str = color white . text $ theindent ++ str ++ " MORE " ++ _ssDescriptor ss
overlapSelectionItems :: [SelectionItem a] -> IM.IntMap (Color, Picture)
overlapSelectionItems = go 0
listSelectionColorPicture :: Foldable t => t (SelectionItem a) -> [(Color,Picture)]
listSelectionColorPicture = foldMap f
where
go _ [] = mempty
go i (si : xs) = doinsert $ go (i + _siHeight si) xs
where
thecol = _siColor si
doinsert m =
ifoldr
(\j str -> IM.insertWith ihelp (i + j + _siOffY si) (thecol,color thecol (text str)))
m
(_siPictures si)
ihelp (_,x) (col,y) = ( col, x<>y)
f si = map g (_siPictures si)
where
g str = (_siColor si,color (_siColor si) $ text str)
--overlapSelectionItems :: [SelectionItem a] -> IM.IntMap (Color, Picture)
--overlapSelectionItems = go 0
-- where
-- go _ [] = mempty
-- go i (si : xs) = doinsert $ go (i + _siHeight si) xs
-- where
-- thecol = _siColor si
-- doinsert m =
-- ifoldr
-- (\j str -> IM.insertWith ihelp (i + j) (thecol,color thecol (text str)))
-- m
-- (_siPictures si)
-- ihelp (_,x) (col,y) = ( col, x<>y)
enterCombineInv :: Configuration -> World -> World
enterCombineInv cfig w =
@@ -275,7 +283,7 @@ enterCombineInv cfig w =
where
cm' = IM.fromAscList $ zip [0 ..] $ combineList' w
cm
| null cm' = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0 0
| null cm' = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0
| otherwise = cm'
sss =
SelectionSections
@@ -292,7 +300,7 @@ enterCombineInv cfig w =
availablelines = getAvailableListLines secondColumnParams cfig
filtsection =
SelectionSection
{ _ssItems = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0 0
{ _ssItems = IM.singleton 0 $ SelectionInfo ["No possible combinations"] 1 False white 0
, _ssCursor = Nothing
, _ssMinSize = 0
, _ssOffset = 0