Allow for indentation of individual selection items

This commit is contained in:
2024-09-12 10:21:35 +01:00
parent eddb313ea1
commit 891fd0079c
8 changed files with 213 additions and 181 deletions
+9 -22
View File
@@ -9,6 +9,7 @@ module Dodge.DisplayInventory (
updateCombinePositioning,
) where
import Dodge.Data.DoubleTree
import Control.Monad
import qualified Data.IntMap.Strict as IM
import qualified Data.IntMap.Merge.Strict as MIM
@@ -113,11 +114,12 @@ updateDisplaySections w cfig sss =
coitems' =
IM.fromDistinctAscList . zip [0 ..] $
map closeObjectToSelectionItem (w ^. hud . closeObjects)
invitems' = MIM.merge MIM.dropMissing MIM.dropMissing (MIM.zipWithMatched $ const addindent) indents $ IM.mapWithKey (invSelectionItem cr) inv
--invitems' = MIM.merge MIM.dropMissing MIM.dropMissing (MIM.zipWithMatched $ const addindent) indents $ IM.mapWithKey (invSelectionItem cr) inv
invitems' = IM.mapWithKey (invSelectionItem cr) inv
addindent x y = y & siPictures %~ map (x ++)
cr = you w
inv = _crInv (you w)
indents = indentInv inv
--indents = indentInv inv
--inv = indentInv $ _crInv (you w)
nfreeslots = crNumFreeSlots cr
filtpair i itms filtdescription =
@@ -231,7 +233,6 @@ updateSection sis mcsel availablelines ss =
length allstrings - availablelines
_ -> oldoffset
tweakfirst (x : xs)
-- -- a| offset > 0 = xtra "<<<" : map h xs
| offset > 0 =
translate 0 (-100) (color moreupcolor $ text (theindent ++ replicate 15 '^')) :
map h xs
@@ -241,38 +242,24 @@ updateSection sis mcsel availablelines ss =
shownitems
| length shownstrings > availablelines =
tweakfirst (take (availablelines - 1) shownstrings)
-- ++ [xtra ">>>"]
++ [translate 0 100 . color moredowncolor . textVMirror $ theindent ++ replicate 15 '^']
| otherwise = tweakfirst shownstrings
moredowncolor = fromMaybe white $ allstrings ^? ix (offset + availablelines - 1) . _1
allstrings :: [(Color, Picture)]
-- 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
displaySelectionSection :: SelectionSection a -> Picture
displaySelectionSection ss = undefined
listSelectionColorPicture :: Foldable t => t (SelectionItem a) -> [(Color,Picture)]
listSelectionColorPicture = foldMap f
where
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)
indent = 100 * fromIntegral (_siOffX si)
g str = (_siColor si,translate indent 0 . color (_siColor si) $ text str)
enterCombineInv :: Configuration -> World -> World
enterCombineInv cfig w =