Work on inventory selection list

This commit is contained in:
2022-12-25 19:00:19 +00:00
parent b01a9f89e6
commit 2ae7f2bbc1
5 changed files with 74 additions and 65 deletions
+24 -19
View File
@@ -8,7 +8,6 @@ module Dodge.Inventory (
selNumPos,
selNumTextPos,
selNumCol,
selNumSlots,
selNumMidHeight,
augmentedInvSizes,
rmInvItem,
@@ -23,6 +22,7 @@ module Dodge.Inventory (
crNumFreeSlots,
crInvSize,
selectedCloseObject,
invDimColor,
) where
import Color
@@ -96,13 +96,16 @@ rmSelectedInvItem :: Int -> World -> World
rmSelectedInvItem cid w = rmInvItem cid (crSel (w ^?! cWorld . lWorld . creatures . ix cid)) w
augmentedInvSizes :: World -> IM.IntMap Int
augmentedInvSizes = bimapAugmentInv itSlotsTaken closeObjectSize
augmentedInvSizes = trimapAugmentInv itSlotsTaken 1 closeObjectSize
bimapAugmentInv :: (Item -> a) -> (Either FloorItem Button -> a) -> World -> IM.IntMap a
bimapAugmentInv f g w =
trimapAugmentInv :: (Item -> a) -> a -> (Either FloorItem Button -> a) -> World -> IM.IntMap a
trimapAugmentInv f x g w =
IM.insert n x $
IM.union
(f <$> yourInv w)
(IM.fromAscList $ zip [length (yourInv w) ..] $ map g $ w ^. cWorld . lWorld . closeObjects)
(IM.fromAscList $ zip [n + 1 ..] $ map g $ w ^. cWorld . lWorld . closeObjects)
where
n = length $ yourInv w
invSelSize :: Int -> World -> Int
invSelSize i w = fromMaybe 1 $ augmentedInvSizes w IM.!? i
@@ -117,15 +120,12 @@ closeObjectCol e = case e of
Left flit -> _itInvColor $ _flIt flit
Right _ -> yellow
selNumSlots :: Int -> World -> Int
selNumSlots i w = fromMaybe 1 $ augmentedInvSizes w IM.!? i
selNumPos :: Int -> World -> Int
selNumPos i w = splitgap + (foldl' (+) 0 . fst $ IM.split i (augmentedInvSizes w))
where
splitgap
| i < length (yourInv w) = 0
| otherwise = 1
splitgap = 0
-- | i < length (yourInv w) = 0
-- | otherwise = 1
selNumTextPos :: Configuration -> World -> Int -> Point2
selNumTextPos cfig w i = V2 (150 - hw) (hh - (20 * fromIntegral ipos + 20))
@@ -140,18 +140,22 @@ selNumMidHeight cfig w i = V2 (150 - hw) (hh + bump - (20 * fromIntegral ipos +
hh = halfHeight cfig
hw = halfWidth cfig
ipos = selNumPos i w
bump = negate $ 10 * fromIntegral (selNumSlots i w)
bump = negate $ 10 * fromIntegral (invSelSize i w)
selNumCol :: Int -> World -> Color
selNumCol i w = fromMaybe white $ bimapAugmentInv _itInvColor closeObjectCol w IM.!? i
selNumCol i w = fromMaybe white $ trimapAugmentInv _itInvColor invDimColor closeObjectCol w IM.!? i
invDimColor :: Color
invDimColor = greyN 0.7
invSelPos :: World -> Int
invSelPos w = splitgap + (foldl' (+) 0 . fst $ IM.split invsel (augmentedInvSizes w))
where
invsel = yourInvSel w
splitgap
| invsel < length (yourInv w) = 0
| otherwise = 1
splitgap = 0
-- splitgap
-- | invsel < length (yourInv w) = 0
-- | otherwise = 1
updateTerminal :: World -> World
updateTerminal = checkTermDist
@@ -172,7 +176,8 @@ updateCloseObjects w =
& cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ updateinvsel
where
updateinvsel curinvsel
| length (augmentedInvSizes w) <= curinvsel = max 0 $ length (augmentedInvSizes w) - 1
-- | length (augmentedInvSizes w) <= curinvsel = max 0 $ length (augmentedInvSizes w) - 1
| length (augmentedInvSizes w) <= curinvsel = max 0 $ length (augmentedInvSizes w)
| otherwise = curinvsel
filt = filter $ \obj -> dist ypos (closeObjPos obj) < 40 && hasButtonLOS ypos (closeObjPos obj) w
ypos = _crPos $ you w
@@ -371,7 +376,7 @@ changeAugInvSel i w
& cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ (`mod` n) . subtract i
& cWorld . lWorld . creatures . ix 0 . crInvSel . iselAction .~ NoInvSelAction
where
n = length (yourInv w) + length (w ^. cWorld . lWorld . closeObjects)
n = length (yourInv w) + length (w ^. cWorld . lWorld . closeObjects) + 1
bestCloseObjectIndex :: World -> Maybe Int
bestCloseObjectIndex w = findIndex f $ w ^. cWorld . lWorld . closeObjects
@@ -382,7 +387,7 @@ bestCloseObjectIndex w = findIndex f $ w ^. cWorld . lWorld . closeObjects
selectedCloseObject :: World -> Maybe (Int, Either FloorItem Button)
selectedCloseObject w
| invsel >= length inv = selectNthCloseObject w (invsel - length inv)
| invsel >= (length inv + 1) = selectNthCloseObject w (invsel - (length inv + 1))
| otherwise = selectNthCloseObject w =<< bestCloseObjectIndex w
where
invsel = crSel cr