Decouple selection section inventory position

This commit is contained in:
2024-10-24 14:55:51 +01:00
parent 81f4f38166
commit 388064895f
17 changed files with 304 additions and 261 deletions
+10 -8
View File
@@ -166,7 +166,7 @@ changeSwapClose f i w = fromMaybe w $ do
& cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . ispCloseObject
.~ k
& hud . closeObjects %~ swapIndices i k
& hud . hudElement . diSections . sssExtra . sssSelPos . _Just . _2 .~ k
& hud . hudElement . diSelection . _Just . _2 .~ k
& worldEventFlags . at InventoryChange ?~ ()
-- can be specialised for when we know that item i is selected
@@ -178,9 +178,9 @@ swapInvItems ::
swapInvItems f i w = fromMaybe w $ do
ss <- w ^? hud . hudElement . diSections . sssSections . ix 0 . ssItems
k <- f i ss
let updateselection = case w ^? hud . hudElement . diSections . sssExtra . sssSelPos . _Just of
Just (0, j) | j == k -> hud . hudElement . diSections . sssExtra . sssSelPos . _Just . _2 .~ i
Just (0, j) | j == i -> hud . hudElement . diSections . sssExtra . sssSelPos . _Just . _2 .~ k
let updateselection = case w ^? hud . hudElement . diSelection . _Just of
Just (0, j) | j == k -> hud . hudElement . diSelection . _Just . _2 .~ i
Just (0, j) | j == i -> hud . hudElement . diSelection . _Just . _2 .~ k
_ -> id
return $
w & cWorld . lWorld . creatures . ix 0 %~ updatecreature k
@@ -209,7 +209,7 @@ swapInvItems f i w = fromMaybe w $ do
Nothing -> id
changeSwapWith :: (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) -> World -> World
changeSwapWith f w = case w ^? hud . hudElement . diSections . sssExtra . sssSelPos . _Just of
changeSwapWith f w = case w ^? hud . hudElement . diSelection . _Just of
Just (0, i) -> w & swapInvItems f i
Just (3, i) -> w & changeSwapClose f i
_ -> w
@@ -217,7 +217,7 @@ changeSwapWith f w = case w ^? hud . hudElement . diSections . sssExtra . sssSel
augInvDirectSelect :: (Int, Int) -> World -> World
augInvDirectSelect (i, j) w =
w
& hud . hudElement . diSections . sssExtra . sssSelPos .~ Just (i, j)
& hud . hudElement . diSelection .~ Just (i, j)
& worldEventFlags . at InventoryChange ?~ ()
& setInvPosFromSS
& cWorld . lWorld %~ crUpdateItemLocations 0
@@ -226,12 +226,14 @@ scrollAugInvSel :: Int -> World -> World
scrollAugInvSel yi w
| yi == 0 = w
| otherwise =
w & hud . hudElement . diSections %~ doscroll
w & hud . hudElement %~ doscroll
& worldEventFlags . at InventoryChange ?~ ()
& setInvPosFromSS
& cWorld . lWorld %~ crUpdateItemLocations 0
where
doscroll sss = sss & sssExtra . sssSelPos %~ scrollSelectionSections yi sss
doscroll he = fromMaybe he $ do
sss <- he ^? diSections
return $ he & diSelection %~ scrollSelectionSections yi sss
selectedCloseObject :: World -> Maybe (Either FloorItem Button)
selectedCloseObject w = do