Tweak main inventory display, have not solved space leak

This commit is contained in:
2025-01-05 15:48:30 +00:00
parent 51297d0cb2
commit 2f30163c2f
8 changed files with 804835 additions and 853615 deletions
+1
View File
@@ -30,6 +30,7 @@ data SelectionSection a = SelectionSection
{ _ssItems :: IntMap (SelectionItem a)
, _ssOffset :: Int
, _ssShownItems :: [Picture]
, _ssShownLength :: Int
, _ssIndent :: Int
}
+15 -9
View File
@@ -1,6 +1,7 @@
-- {-# OPTIONS_GHC -fno-full-laziness #-}
--{-# LANGUAGE TupleSections #-}
{-# LANGUAGE LambdaCase #-}
--{-# LANGUAGE BangPatterns #-}
module Dodge.DisplayInventory (
updateInventoryPositioning,
@@ -8,6 +9,7 @@ module Dodge.DisplayInventory (
toggleCombineInv,
) where
--import StrictHelp
import qualified Data.Strict.Tuple as STup
import Control.Applicative
import Control.Lens
@@ -272,6 +274,7 @@ updateSectionsPositioning f h mselpos allavailablelines lsss sss =
IM.intersectionWithKey (\k -> updateSection (h k) (m k)) ls ssizes `g` offsets
where
offsets = fmap _ssOffset sss
--offsets = mempty
m k = do
(k', i, _) <- mselpos
guard $ k == k'
@@ -296,23 +299,26 @@ updateSection indent mcsel sis availablelines oldoffset =
, _ssShownItems =
tweakfirst . tweaklast . map (^. _2) $
take availablelines shownstrings
, _ssShownLength = length shownitems
, _ssIndent = indent
}
where
oldoffsetbounded = max 0 . min oldoffset $ length allstrings - availablelines
shownitems =
tweakfirst . tweaklast . map (^. _2) $
take availablelines shownstrings
oldoffsetbounded = max 0 . min oldoffset $ aslength - availablelines
offset = fromMaybe oldoffsetbounded $ do
csel <- mcsel
maxcsel <- fst <$> IM.lookupMax sis
xselsize <- fmap length $ sis ^? ix csel . siPictures
return $ case sum $ fmap (length . _siPictures) . fst . IM.split csel $ sis of
pos | pos == 0 || length allstrings <= availablelines -> 0
pos | pos == 0 || aslength <= availablelines -> 0
pos | pos - 1 < oldoffset -> pos - 1
pos | maxcsel == csel -> pos - availablelines + xselsize
pos | pos + 1 + xselsize - availablelines > oldoffset ->
pos - availablelines + 1 + xselsize
-- _ | length allstrings - oldoffset < availablelines ->
_ | length allstrings - availablelines < oldoffset ->
length allstrings - availablelines
_ | aslength - availablelines < oldoffset ->
aslength - availablelines
_ -> oldoffsetbounded
tweakfirst
| offset > 0 = ix 0 .~ color moreupcolor (text (replicate 15 (toEnum 30)))
@@ -324,12 +330,11 @@ updateSection indent mcsel sis availablelines oldoffset =
.~ color moredowncolor (text . replicate 15 $ toEnum 31)
| otherwise = id
moredowncolor = fromMaybe white $ allstrings ^? ix (offset + availablelines - 1) . _1
allstrings = foldMap listSelectionColorPicture sis
(allstrings,Sum aslength) = foldMap listSelectionColorPicture sis
shownstrings = drop offset allstrings
listSelectionColorPicture :: SelectionItem a -> [STup.Pair Color Picture]
--listSelectionColorPicture si = []
listSelectionColorPicture si = g <$> _siPictures si
listSelectionColorPicture :: SelectionItem a -> ([STup.Pair Color Picture], Sum Int)
listSelectionColorPicture si = (g <$> _siPictures si, Sum $ _siHeight si)
where
g str =
_siColor si STup.:!:
@@ -370,6 +375,7 @@ enterCombineInv cfig w =
{ _ssItems = mempty
, _ssOffset = 0
, _ssShownItems = mempty
, _ssShownLength = 0
, _ssIndent = 0
}
combsection =
+2 -1
View File
@@ -26,7 +26,8 @@ drawSelectionSections sss ldp cfig =
(_ldpScale ldp)
0
(foldMap
(\ss -> translate (100*fromIntegral (_ssIndent ss)) 0 <$> _ssShownItems ss) sss)
(\ss -> translate (100*fromIntegral (_ssIndent ss)) 0 <$>
(_ssShownItems ss)) sss)
drawSSCursor ::
IM.IntMap (SelectionSection a) ->
+1
View File
@@ -15,6 +15,7 @@ import Dodge.Zoning.Wall
import Geometry
colCrsWalls :: Universe -> Universe
--colCrsWalls uv = uv
colCrsWalls uv = uv & uvWorld . cWorld . lWorld . creatures %~ fmap (noclipCheck (_uvConfig uv) (_uvWorld uv))
noclipCheck :: Configuration -> World -> Creature -> Creature