This commit is contained in:
2025-01-04 15:43:35 +00:00
parent da641e0f47
commit b5ffeae538
+17 -19
View File
@@ -8,13 +8,13 @@ module Dodge.DisplayInventory (
toggleCombineInv,
) where
import Data.IntSet (IntSet)
import Control.Applicative
import Control.Lens
import Control.Monad
import Data.Bifunctor
import Data.IntMap.Merge.Strict
import qualified Data.IntMap.Strict as IM
import Data.IntSet (IntSet)
import Data.Maybe
import Data.Monoid
import Dodge.Base.You
@@ -86,28 +86,26 @@ updateInventoryPositioning :: Universe -> Universe
updateInventoryPositioning u =
u & uvWorld . hud . hudElement . diSections
%~ updateDisplaySections (_uvWorld u) (_uvConfig u)
& checkInventorySelectionExists
& uvWorld
%~ checkInventorySelectionExists
checkInventorySelectionExists :: Universe -> Universe
checkInventorySelectionExists u =
case u ^? uvWorld . hud . hudElement . diSections . ix i . ssItems . ix j of
Nothing -> u & uvWorld %~ scrollAugNextInSection
_ -> u
checkInventorySelectionExists :: World -> World
checkInventorySelectionExists w =
case w ^? hud . hudElement . diSections . ix i . ssItems . ix j of
Nothing -> scrollAugNextInSection w
_ -> w
where
(i, j, _) =
fromMaybe (1, -1, mempty) $
u ^? uvWorld . hud . hudElement . diSelection . _Just
(i, j, _) = fromMaybe (1, -1, mempty) $ w ^? hud . hudElement . diSelection . _Just
checkCombineSelectionExists :: SubInventory -> SubInventory
checkCombineSelectionExists u = fromMaybe u $ do
sss <- u ^? ciSections
(i, j, _) <- u ^? ciSelection . _Just <|> Just (0, 0, mempty)
Just $ case u ^? ciSections . ix i . ssItems . ix j of
Nothing ->
u & ciSelection ?~ (0, -1, mempty)
& ciSelection
%~ scrollSelectionSections (-1) sss
_ -> u
checkCombineSelectionExists si
| Just sss <- si ^? ciSections
, Just (i, j, _) <- si ^? ciSelection . _Just <|> Just (0, 0, mempty)
, isNothing $ si ^? ciSections . ix i . ssItems . ix j =
si & ciSelection ?~ (0, -1, mempty)
& ciSelection
%~ scrollSelectionSections (-1) sss
| otherwise = si
displaySectionsSizes :: Int -> Int
displaySectionsSizes 0 = 10