From 56f2dc04cf941a05addfb7e4001c9e2081d0a5f0 Mon Sep 17 00:00:00 2001 From: justin Date: Fri, 17 Feb 2023 19:14:10 +0000 Subject: [PATCH] Tweak close item usage code --- src/Dodge/Inventory.hs | 72 ++++++++------------------------------- src/Dodge/Render/HUD.hs | 6 ++-- src/Dodge/Update/Input.hs | 4 +-- 3 files changed, 20 insertions(+), 62 deletions(-) diff --git a/src/Dodge/Inventory.hs b/src/Dodge/Inventory.hs index c920641ca..cea5e26cd 100644 --- a/src/Dodge/Inventory.hs +++ b/src/Dodge/Inventory.hs @@ -8,28 +8,26 @@ module Dodge.Inventory ( firstPosSelectionSections, checkInvSlotsYou, rmSelectedInvItem, - invSelSize, + --invSelSize, selNumPos, selNumTextEndPos, - selNumCol, + selSecSelCol, selNumEndMidHeight, - augmentedInvSizes, rmInvItem, updateCloseObjects, updateRBList, updateTerminal, closeObjScrollDir, - closeObjectCol, changeSwapInvSel, changeAugInvSel, crNumFreeSlots, crInvSize, selectedCloseObject, invDimColor, - trimapAugmentInv, setInvPosFromSS, ) where +import Control.Applicative import Dodge.Data.SelectionList import Color import qualified Data.Map.Strict as M @@ -41,7 +39,6 @@ import Dodge.Euse import Dodge.Inventory.CheckSlots import Dodge.Inventory.CloseObject import Dodge.Inventory.Color -import Dodge.Inventory.ItemSpace import Dodge.ItEffect import Dodge.Reloading import Geometry @@ -112,42 +109,9 @@ rmSelectedInvItem cid w = case w ^? cWorld . lWorld . creatures . ix cid . crMan Just i -> rmInvItem cid i 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 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 i j sss = do ss <- sss ^? sssSections . ix i @@ -192,11 +156,8 @@ selNumEndMidHeight cfig ldp sss i j = do hh = halfHeight cfig hw = halfWidth cfig -selNumCol :: Int -> World -> Color -selNumCol i w = fromMaybe white $ trimapAugmentInv _itInvColor invDimColor closeObjectCol w IM.!? i - ---invSelPos :: World -> Int ---invSelPos w = sum . fst $ IM.split (yourInvSel w) (augmentedInvSizes w) +selSecSelCol :: Int -> Int -> SelectionSections a -> Maybe Color +selSecSelCol i j sss = sss ^? sssSections . ix i . ssItems . ix j . siColor updateTerminal :: World -> World updateTerminal = checkTermDist @@ -219,7 +180,10 @@ updateCloseObjects w = newcloseobjects = unionBy closeObjEq oldCloseFiltered currentClose updatecursorposifnecessary = 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 filt = filter $ \obj -> dist ypos (closeObjPos obj) < 40 && hasButtonLOS ypos (closeObjPos obj) w ypos = _crPos $ you w @@ -533,17 +497,9 @@ ssLookupGE' i sss = do -- where -- ninv = length (yourInv w) -bestCloseObjectIndex :: World -> Maybe Int -bestCloseObjectIndex w = findIndex f $ w ^. hud . closeObjects - where - f (Right _) = True - f (Left flit) = itSlotsTaken (_flIt flit) <= _crInvCapacity ycr - crInvSize ycr - ycr = you w +selectedCloseObject :: World -> Maybe (Either FloorItem Button) +selectedCloseObject w = do + i <- you w ^? crManipulation . manObject . inNearby . ispCloseObject + <|> fmap fst (IM.lookupMin =<< w ^? hud . hudElement . diSections . sssSections . ix 3 . ssItems) + w ^? hud . closeObjects . ix i -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) diff --git a/src/Dodge/Render/HUD.hs b/src/Dodge/Render/HUD.hs index ddc72cc7d..d429d5a91 100644 --- a/src/Dodge/Render/HUD.hs +++ b/src/Dodge/Render/HUD.hs @@ -303,7 +303,8 @@ combineCounts cfig w = winScale cfig . foldMap f . group _ <- yourInv w ^? ix i . itUse . useAmount sss <- w ^? hud . hudElement . diSections 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 lnkMidPosInvSelsCol :: Configuration -> World -> Int -> Color -> [Int] -> Picture @@ -313,7 +314,8 @@ lnkMidPosInvSelsCol cfig w i col = winScale cfig f j = fromMaybe mempty $ do sss <- w ^? hud . hudElement . diSections 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)) hh = halfHeight cfig hw = halfWidth cfig diff --git a/src/Dodge/Update/Input.hs b/src/Dodge/Update/Input.hs index a6237a3aa..bc50f111b 100644 --- a/src/Dodge/Update/Input.hs +++ b/src/Dodge/Update/Input.hs @@ -242,8 +242,8 @@ spaceAction :: World -> World spaceAction w = case w ^?! hud . hudElement of DisplayCarte -> w & hud . carteCenter .~ theLoc DisplayInventory{_subInventory = NoSubInventory} -> case selectedCloseObject w of - Just (_, Left flit) -> pickUpItem 0 flit w - Just (_, Right but) -> doButtonEvent (_btEvent but) but w + Just (Left flit) -> pickUpItem 0 flit w + Just (Right but) -> doButtonEvent (_btEvent but) but w _ -> w DisplayInventory{_subInventory = DisplayTerminal{}} -> w & hud . hudElement . subInventory .~ NoSubInventory