Tweak close item usage code

This commit is contained in:
2023-02-17 19:14:10 +00:00
parent 90370e5487
commit 56f2dc04cf
3 changed files with 20 additions and 62 deletions
+14 -58
View File
@@ -8,28 +8,26 @@ module Dodge.Inventory (
firstPosSelectionSections, firstPosSelectionSections,
checkInvSlotsYou, checkInvSlotsYou,
rmSelectedInvItem, rmSelectedInvItem,
invSelSize, --invSelSize,
selNumPos, selNumPos,
selNumTextEndPos, selNumTextEndPos,
selNumCol, selSecSelCol,
selNumEndMidHeight, selNumEndMidHeight,
augmentedInvSizes,
rmInvItem, rmInvItem,
updateCloseObjects, updateCloseObjects,
updateRBList, updateRBList,
updateTerminal, updateTerminal,
closeObjScrollDir, closeObjScrollDir,
closeObjectCol,
changeSwapInvSel, changeSwapInvSel,
changeAugInvSel, changeAugInvSel,
crNumFreeSlots, crNumFreeSlots,
crInvSize, crInvSize,
selectedCloseObject, selectedCloseObject,
invDimColor, invDimColor,
trimapAugmentInv,
setInvPosFromSS, setInvPosFromSS,
) where ) where
import Control.Applicative
import Dodge.Data.SelectionList import Dodge.Data.SelectionList
import Color import Color
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
@@ -41,7 +39,6 @@ import Dodge.Euse
import Dodge.Inventory.CheckSlots import Dodge.Inventory.CheckSlots
import Dodge.Inventory.CloseObject import Dodge.Inventory.CloseObject
import Dodge.Inventory.Color import Dodge.Inventory.Color
import Dodge.Inventory.ItemSpace
import Dodge.ItEffect import Dodge.ItEffect
import Dodge.Reloading import Dodge.Reloading
import Geometry import Geometry
@@ -112,42 +109,9 @@ rmSelectedInvItem cid w = case w ^? cWorld . lWorld . creatures . ix cid . crMan
Just i -> rmInvItem cid i w Just i -> rmInvItem cid i w
Nothing -> w Nothing -> w
augmentedInvSizes :: World -> IM.IntMap Int
augmentedInvSizes = trimapAugmentInv itSlotsTaken 1 closeObjectSize
trimapAugmentInv :: (Item -> a) -> a -> (Either FloorItem Button -> a) -> World -> IM.IntMap a
{-# INLINE trimapAugmentInv #-}
trimapAugmentInv f x g w =
IM.insert n x $
IM.union
(f <$> yourInv w)
(IM.fromAscList $ zip [n + 1 ..] $ map g $ w ^. hud . closeObjects)
where
n = length $ yourInv w
selSecSelSize :: Int -> Int -> SelectionSections a -> Maybe Int selSecSelSize :: Int -> Int -> SelectionSections a -> Maybe Int
selSecSelSize i j sss = fmap length $ sss ^? sssSections . ix i . ssItems . ix j . siPictures selSecSelSize i j sss = fmap length $ sss ^? sssSections . ix i . ssItems . ix j . siPictures
invSelSize :: ManipulatedObject -> World -> Int
invSelSize mo w = case mo of
InInventory (SelItem i _) -> fromMaybe 1 $ fmap itSlotsTaken
$ w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix i
InNearby (SelCloseObject i) -> fromMaybe 1 $ fmap closeObjectSize
$ w ^? hud . closeObjects . ix i
InInventory SortInventory -> 1
InNearby SortNearby -> 1
SelNothing -> 1
closeObjectSize :: Either FloorItem Button -> Int
closeObjectSize e = case e of
Left flit -> itSlotsTaken $ _flIt flit
Right _ -> 1
closeObjectCol :: Either FloorItem Button -> Color
closeObjectCol e = case e of
Left flit -> _itInvColor $ _flIt flit
Right _ -> yellow
selSecSelPos :: Int -> Int -> SelectionSections a -> Maybe Int selSecSelPos :: Int -> Int -> SelectionSections a -> Maybe Int
selSecSelPos i j sss = do selSecSelPos i j sss = do
ss <- sss ^? sssSections . ix i ss <- sss ^? sssSections . ix i
@@ -192,11 +156,8 @@ selNumEndMidHeight cfig ldp sss i j = do
hh = halfHeight cfig hh = halfHeight cfig
hw = halfWidth cfig hw = halfWidth cfig
selNumCol :: Int -> World -> Color selSecSelCol :: Int -> Int -> SelectionSections a -> Maybe Color
selNumCol i w = fromMaybe white $ trimapAugmentInv _itInvColor invDimColor closeObjectCol w IM.!? i selSecSelCol i j sss = sss ^? sssSections . ix i . ssItems . ix j . siColor
--invSelPos :: World -> Int
--invSelPos w = sum . fst $ IM.split (yourInvSel w) (augmentedInvSizes w)
updateTerminal :: World -> World updateTerminal :: World -> World
updateTerminal = checkTermDist updateTerminal = checkTermDist
@@ -219,7 +180,10 @@ updateCloseObjects w =
newcloseobjects = unionBy closeObjEq oldCloseFiltered currentClose newcloseobjects = unionBy closeObjEq oldCloseFiltered currentClose
updatecursorposifnecessary updatecursorposifnecessary
= case w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject. inNearby . ispCloseObject of = case w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject. inNearby . ispCloseObject of
Just i | i >= length newcloseobjects -> changeAugInvSel 1 Just i
| i >= length newcloseobjects -> changeAugInvSel 1
| isNothing (w ^? hud . hudElement . diSections . sssSections . ix 3 . ssItems . ix i)
-> changeAugInvSel (-1)
_ -> id _ -> id
filt = filter $ \obj -> dist ypos (closeObjPos obj) < 40 && hasButtonLOS ypos (closeObjPos obj) w filt = filter $ \obj -> dist ypos (closeObjPos obj) < 40 && hasButtonLOS ypos (closeObjPos obj) w
ypos = _crPos $ you w ypos = _crPos $ you w
@@ -533,17 +497,9 @@ ssLookupGE' i sss = do
-- where -- where
-- ninv = length (yourInv w) -- ninv = length (yourInv w)
bestCloseObjectIndex :: World -> Maybe Int selectedCloseObject :: World -> Maybe (Either FloorItem Button)
bestCloseObjectIndex w = findIndex f $ w ^. hud . closeObjects selectedCloseObject w = do
where i <- you w ^? crManipulation . manObject . inNearby . ispCloseObject
f (Right _) = True <|> fmap fst (IM.lookupMin =<< w ^? hud . hudElement . diSections . sssSections . ix 3 . ssItems)
f (Left flit) = itSlotsTaken (_flIt flit) <= _crInvCapacity ycr - crInvSize ycr w ^? hud . closeObjects . ix i
ycr = you w
selectedCloseObject :: World -> Maybe (Int, Either FloorItem Button)
selectedCloseObject w = case you w ^? crManipulation . manObject . inNearby . ispCloseObject of
Just i -> selectNthCloseObject w i
Nothing -> selectNthCloseObject w =<< bestCloseObjectIndex w
selectNthCloseObject :: World -> Int -> Maybe (Int, Either FloorItem Button)
selectNthCloseObject w n = (length (yourInv w) + n + 1,) <$> (_closeObjects (_hud w) !? n)
+4 -2
View File
@@ -303,7 +303,8 @@ combineCounts cfig w = winScale cfig . foldMap f . group
_ <- yourInv w ^? ix i . itUse . useAmount _ <- yourInv w ^? ix i . itUse . useAmount
sss <- w ^? hud . hudElement . diSections sss <- w ^? hud . hudElement . diSections
p <- selNumTextEndPos cfig (invDisplayParams w) sss 0 i p <- selNumTextEndPos cfig (invDisplayParams w) sss 0 i
return $ color (selNumCol i w) $ uncurryV translate p . scale 0.1 0.1 . text $ ('-' : show (length is + 1)) col <- selSecSelCol 0 i sss
return $ color col $ uncurryV translate p . scale 0.1 0.1 . text $ ('-' : show (length is + 1))
f _ = mempty f _ = mempty
lnkMidPosInvSelsCol :: Configuration -> World -> Int -> Color -> [Int] -> Picture lnkMidPosInvSelsCol :: Configuration -> World -> Int -> Color -> [Int] -> Picture
@@ -313,7 +314,8 @@ lnkMidPosInvSelsCol cfig w i col = winScale cfig
f j = fromMaybe mempty $ do f j = fromMaybe mempty $ do
sss <- w ^? hud . hudElement . diSections sss <- w ^? hud . hudElement . diSections
h <- selNumEndMidHeight cfig (invDisplayParams w) sss 0 j h <- selNumEndMidHeight cfig (invDisplayParams w) sss 0 j
return $ zConnectCol rp (V2 18 0 + h) col white white (selNumCol j w) invcol <- selSecSelCol 0 j sss
return $ zConnectCol rp (V2 18 0 + h) col white white invcol
rp = V2 (190 - hw) (hh - (20 * fromIntegral i + 77.5)) rp = V2 (190 - hw) (hh - (20 * fromIntegral i + 77.5))
hh = halfHeight cfig hh = halfHeight cfig
hw = halfWidth cfig hw = halfWidth cfig
+2 -2
View File
@@ -242,8 +242,8 @@ spaceAction :: World -> World
spaceAction w = case w ^?! hud . hudElement of spaceAction w = case w ^?! hud . hudElement of
DisplayCarte -> w & hud . carteCenter .~ theLoc DisplayCarte -> w & hud . carteCenter .~ theLoc
DisplayInventory{_subInventory = NoSubInventory} -> case selectedCloseObject w of DisplayInventory{_subInventory = NoSubInventory} -> case selectedCloseObject w of
Just (_, Left flit) -> pickUpItem 0 flit w Just (Left flit) -> pickUpItem 0 flit w
Just (_, Right but) -> doButtonEvent (_btEvent but) but w Just (Right but) -> doButtonEvent (_btEvent but) but w
_ -> w _ -> w
DisplayInventory{_subInventory = DisplayTerminal{}} -> DisplayInventory{_subInventory = DisplayTerminal{}} ->
w & hud . hudElement . subInventory .~ NoSubInventory w & hud . hudElement . subInventory .~ NoSubInventory