Color scroll lines in inventory display

This commit is contained in:
2023-05-10 18:01:14 +01:00
parent 69fbf5926a
commit 312f342e09
4 changed files with 32 additions and 16 deletions
+21 -11
View File
@@ -1,4 +1,5 @@
{-# LANGUAGE TupleSections #-} {-# LANGUAGE TupleSections #-}
--{-# OPTIONS_GHC -fno-full-laziness #-} --{-# OPTIONS_GHC -fno-full-laziness #-}
module Dodge.DisplayInventory ( module Dodge.DisplayInventory (
@@ -8,21 +9,21 @@ module Dodge.DisplayInventory (
updateCombinePositioning, updateCombinePositioning,
) where ) where
import Dodge.ListDisplayParams
import ListHelp
import Dodge.Data.Combine
import Control.Monad import Control.Monad
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
import Data.Maybe import Data.Maybe
import Dodge.Base.You import Dodge.Base.You
import Dodge.Combine import Dodge.Combine
import Dodge.Data.Combine
import Dodge.Data.Config import Dodge.Data.Config
import Dodge.Data.SelectionList import Dodge.Data.SelectionList
import Dodge.Data.Universe import Dodge.Data.Universe
import Dodge.Inventory.CheckSlots import Dodge.Inventory.CheckSlots
import Dodge.Inventory.SelectionList import Dodge.Inventory.SelectionList
import Dodge.ListDisplayParams
import Dodge.SelectionList import Dodge.SelectionList
import LensHelp import LensHelp
import ListHelp
import Picture.Base import Picture.Base
import Regex import Regex
@@ -32,7 +33,8 @@ toggleCombineInv uv = case uv ^? uvWorld . hud . hudElement . subInventory of
_ -> uv & uvWorld %~ enterCombineInv (uv ^. uvConfig) _ -> uv & uvWorld %~ enterCombineInv (uv ^. uvConfig)
updateCombinePositioning :: Universe -> Universe updateCombinePositioning :: Universe -> Universe
updateCombinePositioning u = u & uvWorld . hud . hudElement . subInventory . ciSections updateCombinePositioning u =
u & uvWorld . hud . hudElement . subInventory . ciSections
%~ updateCombineSections (_uvWorld u) (_uvConfig u) %~ updateCombineSections (_uvWorld u) (_uvConfig u)
updateCombineSections :: World -> Configuration -> SelectionSections CombinableItem -> SelectionSections CombinableItem updateCombineSections :: World -> Configuration -> SelectionSections CombinableItem -> SelectionSections CombinableItem
@@ -64,7 +66,7 @@ updateCombineSections w cfig sss =
regexCombs :: IM.IntMap (SelectionItem ()) -> SelectionItem CombinableItem -> String -> Bool regexCombs :: IM.IntMap (SelectionItem ()) -> SelectionItem CombinableItem -> String -> Bool
regexCombs inv ci str = case str of regexCombs inv ci str = case str of
'<':str' -> f str' ci '<' : str' -> f str' ci
_ -> (regexList str . _siPictures) ci _ -> (regexList str . _siPictures) ci
where where
f str' si = any (g str') (_ciInvIDs $ _siPayload si) f str' si = any (g str') (_ciInvIDs $ _siPayload si)
@@ -81,7 +83,8 @@ orRegex f x str = case words str of
xs -> any (f x) xs xs -> any (f x) xs
updateInventoryPositioning :: Universe -> Universe updateInventoryPositioning :: Universe -> Universe
updateInventoryPositioning u = u & uvWorld . hud . hudElement . diSections updateInventoryPositioning u =
u & uvWorld . hud . hudElement . diSections
%~ updateDisplaySections (_uvWorld u) (_uvConfig u) %~ updateDisplaySections (_uvWorld u) (_uvConfig u)
updateDisplaySections :: World -> Configuration -> SelectionSections () -> SelectionSections () updateDisplaySections :: World -> Configuration -> SelectionSections () -> SelectionSections ()
@@ -129,13 +132,13 @@ updateDisplaySections w cfig sss =
return $ IM.filter (plainRegex str) itms return $ IM.filter (plainRegex str) itms
numfiltitems = " " ++ show (length itms - length itms') ++ " FILTERED" numfiltitems = " " ++ show (length itms - length itms') ++ " FILTERED"
invDimColor :: Color invDimColor :: Color
invDimColor = greyN 0.7 invDimColor = greyN 0.7
-- it is annoying that this is necessary -- it is annoying that this is necessary
updateInventorySectionItems :: World -> World updateInventorySectionItems :: World -> World
updateInventorySectionItems w = w updateInventorySectionItems w =
w
& hud . hudElement . diSections . sssSections . ix 0 . ssItems %~ f & hud . hudElement . diSections . sssSections . ix 0 . ssItems %~ f
where where
f olditems = fromMaybe olditems $ do f olditems = fromMaybe olditems $ do
@@ -197,7 +200,8 @@ updateSection sis mcsel availablelines ss =
csize = length $ _siPictures si csize = length $ _siPictures si
ccolor = _siColor si ccolor = _siColor si
return $ SectionCursor (cpos - offset) csize ccolor return $ SectionCursor (cpos - offset) csize ccolor
nocursoroffset = if length allstrings - oldoffset <= availablelines nocursoroffset =
if length allstrings - oldoffset <= availablelines
then max 0 (length allstrings - availablelines) then max 0 (length allstrings - availablelines)
else oldoffset else oldoffset
offset = fromMaybe nocursoroffset $ do offset = fromMaybe nocursoroffset $ do
@@ -223,14 +227,20 @@ updateSection sis mcsel availablelines ss =
length allstrings - availablelines length allstrings - availablelines
_ -> oldoffset _ -> oldoffset
tweakfirst (x : xs) tweakfirst (x : xs)
| offset > 0 = xtra "<<<" : map h xs -- -- a| offset > 0 = xtra "<<<" : map h xs
| offset > 0 =
translate 0 (-100) (color moreupcolor $ text (theindent ++ replicate 15 '^')) :
map h xs
| otherwise = map h (x : xs) | otherwise = map h (x : xs)
tweakfirst [] = [] tweakfirst [] = []
moreupcolor = fromMaybe white $ allstrings ^? ix offset . _1
shownitems shownitems
| length shownstrings > availablelines = | length shownstrings > availablelines =
tweakfirst (take (availablelines - 1) shownstrings) tweakfirst (take (availablelines - 1) shownstrings)
++ [xtra ">>>"] -- ++ [xtra ">>>"]
++ [translate 0 100 . color moredowncolor . vMirrorText $ theindent ++ replicate 15 '^']
| otherwise = tweakfirst shownstrings | otherwise = tweakfirst shownstrings
moredowncolor = fromMaybe white $ allstrings ^? ix (offset + availablelines - 1) . _1
allstrings :: [(Color, String)] allstrings :: [(Color, String)]
allstrings = foldMap g sis allstrings = foldMap g sis
shownstrings = drop offset allstrings shownstrings = drop offset allstrings
+1 -1
View File
@@ -71,6 +71,6 @@ optionListDisplayParams =
& ldpPos . spPixelOff .~ V2 11 (-70) & ldpPos . spPixelOff .~ V2 11 (-70)
& ldpScale .~ 2 & ldpScale .~ 2
& ldpVerticalGap .~ 0 & ldpVerticalGap .~ 0
& ldpWidth .~ FixedSelectionWidth 25 & ldpWidth .~ FixedSelectionWidth 50
& ldpCursorSides .~ [North, South, West] & ldpCursorSides .~ [North, South, West]
+2 -1
View File
@@ -236,7 +236,8 @@ tweakString tp = rightPad 12 ' ' (show $ _tweakType tp) ++ " " ++ showTweak tp
invHead :: Configuration -> String -> Picture invHead :: Configuration -> String -> Picture
invHead cfig = invHead cfig =
translate (- halfWidth cfig + subInvX + 20) (halfHeight cfig - 40) translateScreenPos cfig (fromTopLeft (V2 (subInvX + 20) 80))
-- (- halfWidth cfig + subInvX + 20) (halfHeight cfig - 80)
. dShadCol white . dShadCol white
. scale 0.4 0.4 . scale 0.4 0.4
. text . text
+5
View File
@@ -45,6 +45,7 @@ module Picture.Base (
mirrorxz, mirrorxz,
overPos, overPos,
picMap, picMap,
vMirrorText,
) where ) where
import Color import Color
@@ -205,6 +206,10 @@ text :: String -> Picture
text = drawText 0 text = drawText 0
--text = drawText (-10) --text = drawText (-10)
vMirrorText :: String -> Picture
{-# INLINE vMirrorText #-}
vMirrorText = translate 0 200 . scale 1 (-1) . text
drawText :: Float -> String -> [Verx] drawText :: Float -> String -> [Verx]
{-# INLINE drawText #-} {-# INLINE drawText #-}
drawText gap = map f . stringToList gap drawText gap = map f . stringToList gap