Move towards displaying tree links in inventory

This commit is contained in:
2024-09-13 12:02:28 +01:00
parent c81fd5490d
commit bd681a577c
8 changed files with 85 additions and 45 deletions
+1 -1
View File
@@ -1 +1 @@
All good (615 modules, at 09:43:40)
All good (615 modules, at 12:01:46)
-2
View File
@@ -18,8 +18,6 @@ import Dodge.Data.Universe
import Dodge.Item.Display
import Dodge.Item.InventoryColor
import Dodge.Item.SlotsTaken
--import Dodge.Data.World
--import Dodge.Item.Amount
import Dodge.Module
import qualified IntMapHelp as IM
import SimpleTrie
+13
View File
@@ -1,6 +1,7 @@
module Dodge.DoubleTree where
import Dodge.Data.DoubleTree
import qualified Data.IntMap.Strict as IM
ldtToDT :: LabelDoubleTree b a -> DoubleTree a
ldtToDT (LDT x l r) = DT x (map (ldtToDT . snd) l) (map (ldtToDT . snd) r)
@@ -18,6 +19,18 @@ dtIL nt (DT x l r) = map doindent (concat (headMap (dtIL DTBottomNode) (dtIL DTM
where
doindent (a,b,c) = (a,b+1,c)
dtToAdjacency :: (a -> Int) -> DoubleTree a -> IM.IntMap [Int]
dtToAdjacency f (DT x l r) = IM.insert (f x) (map g l <> map g r)
. IM.unions $ map (dtToAdjacency f) $ l <> r
where
g = f . _dtValue
dtToUpDownAdj :: (a -> Int) -> DoubleTree a -> IM.IntMap ([Int],[Int])
dtToUpDownAdj f (DT x l r) = IM.insert (f x) (map g l , map g r)
. IM.unions $ map (dtToUpDownAdj f) $ l <> r
where
g = f . _dtValue
ldtToIndentList :: LabelDoubleTree b a -> [(a,Int,LabelDoubleTreeNodeType b)]
ldtToIndentList = ldtIL LDTRootNode
+5 -2
View File
@@ -84,8 +84,11 @@ invLDT :: IM.IntMap Item -> [LabelDoubleTree ComposeLinkType ComposedItemStructu
invLDT = joinItemsInList (leftRightCombine leftIsParentCombine rightIsParentCombine) . IM.elems .
fmap (singleLDT . baseCIS)
invIndentIM' :: IM.IntMap Item -> IM.IntMap (Item,Int, ())
invIndentIM' = fmap (\x -> (x,0,()))
invAdj :: IM.IntMap Item -> IM.IntMap ([Int],[Int])
invAdj = IM.unions . fmap (dtToUpDownAdj getid . ldtToDT) . invLDT
where
getid (itm, _,_,_) = fromMaybe (error "invAdj attempt to find item not in inventory") $
itm ^? itLocation . ipInvID
invIndentIM :: IM.IntMap Item -> IM.IntMap (Item,Int, LabelDoubleTreeNodeType ComposeLinkType )
invIndentIM = IM.fromAscList . zip [0..] . reverse . map (over _1 cisToItem) . concatMap ldtToIndentList . invLDT
+11
View File
@@ -2,9 +2,13 @@ module Dodge.Render.Connectors
( zConnect
, zConnectCol
, lConnect
, lConnectMulti
) where
import FoldableHelp
import Picture
import Geometry
import Control.Lens
import Linear.V2
zConnect :: Point2 -> Point2 -> Picture
zConnect (V2 x y) (V2 a b) = line $ map toV2
@@ -29,3 +33,10 @@ lConnect sp@(V2 _ y) ep@(V2 x _) = line
, V2 x y
, ep
]
lConnectMulti :: [Point2] -> Point2 -> Picture
lConnectMulti sps (V2 x y) = line [V2 x ymin,V2 x ymax] <>
foldMap f sps
where
(Just ymin,Just ymax) = minAndMax $ y : map (^._y) sps
f (V2 x' y') = line [V2 x' y',V2 x y']
+10 -1
View File
@@ -3,6 +3,7 @@ module Dodge.Render.HUD (
drawHUD,
) where
import Dodge.Item.Grammar
import Dodge.Inventory.RBList
import Control.Lens
import Control.Monad
@@ -56,7 +57,12 @@ drawHP cfig =
. (^?! cWorld . lWorld . creatures . ix 0 . crHP)
drawInventory :: SelectionSections () -> World -> Configuration -> Picture
drawInventory sss = drawSelectionSections sss . invDisplayParams
drawInventory sss w cfig = drawSelectionSections sss (invDisplayParams w) cfig
<> iextra
where
iextra = fromMaybe mempty $ do
inv <- w ^? cWorld . lWorld . creatures . ix 0 . crInv
return $ inventoryExtra cfig (invAdj inv) (fmap (^._2) $ invIndentIM inv)
drawSubInventory :: SubInventory -> Configuration -> World -> Picture
drawSubInventory subinv cfig w = case subinv of
@@ -177,6 +183,9 @@ examineInventoryExtra mtweaki cfig = fromMaybe mempty $ do
translate subInvX (-71) $
listCursorChooseBorderScale 0 1 [North, South, West] tweaki 0 white 10 1
inventoryExtra :: Configuration -> IM.IntMap ([Int],[Int]) -> IM.IntMap Int -> Picture
inventoryExtra = undefined
combineInventoryExtra :: SelectionSections CombinableItem -> Configuration -> World -> Picture
combineInventoryExtra sss cfig w = fromMaybe mempty $ do
(i, j) <- sss ^? sssExtra . sssSelPos . _Just
+3
View File
@@ -10,6 +10,7 @@ module FoldableHelp
, ssfold
, minOn
, module Data.Foldable
, minAndMax
)
where
import Data.Foldable
@@ -105,3 +106,5 @@ ssfold :: Foldable t => (a -> Bool) -> (a -> b -> a) -> a -> t b -> a
{-# INLINABLE ssfold #-}
ssfold p f a0 xs = foldr (\x g a -> if p a then a else g (f a x)) id xs a0
minAndMax :: (Foldable t,Ord a) => t a -> (Maybe a,Maybe a)
minAndMax = L.fold ((,) <$> L.minimum <*> L.maximum)
+42 -39
View File
@@ -4739,8 +4739,8 @@ clockCycle src/Dodge/Clock.hs 9;" f
closeObjEq src/Dodge/Inventory/CloseObject.hs 12;" f
closeObjPos src/Dodge/Inventory/CloseObject.hs 7;" f
closeObjectInfo src/Dodge/Render/HUD.hs 105;" f
closeObjectToSelectionItem src/Dodge/Inventory/SelectionList.hs 68;" f
closeObjectToTextPictures src/Dodge/Inventory/SelectionList.hs 83;" f
closeObjectToSelectionItem src/Dodge/Inventory/SelectionList.hs 66;" f
closeObjectToTextPictures src/Dodge/Inventory/SelectionList.hs 81;" f
closestCreatureID src/Dodge/Debug.hs 91;" f
closestPointOnLine src/Geometry/Intersect.hs 251;" f
closestPointOnLineParam src/Geometry/Intersect.hs 267;" f
@@ -4754,7 +4754,7 @@ clsNearRect src/Dodge/Zoning/Cloud.hs 15;" f
clsNearSeg src/Dodge/Zoning/Cloud.hs 12;" f
clusterFormatting src/Dodge/Combine/Graph.hs 113;" f
clusterFunc src/Dodge/Combine/Graph.hs 107;" f
cmm src/Dodge/Combine.hs 102;" f
cmm src/Dodge/Combine.hs 63;" f
cogRaised src/Dodge/Creature/Perception.hs 101;" f
colCrWall src/Dodge/WallCreatureCollisions.hs 26;" f
colCrsWalls src/Dodge/WallCreatureCollisions.hs 17;" f
@@ -4784,15 +4784,14 @@ combineBeamBeams src/Dodge/Update.hs 475;" f
combineBeams src/Dodge/Update.hs 466;" f
combineFloors src/Dodge/Room/Procedural.hs 171;" f
combineInventoryExtra src/Dodge/Render/HUD.hs 180;" f
combineItemListYouX src/Dodge/Combine.hs 70;" f
combineList src/Dodge/Combine.hs 78;" f
combineList' src/Dodge/Combine.hs 83;" f
combineListInfo src/Dodge/Combine.hs 96;" f
combineModuleMaps src/Dodge/Combine.hs 107;" f
combineItemListYouX src/Dodge/Combine.hs 41;" f
combineList src/Dodge/Combine.hs 44;" f
combineListInfo src/Dodge/Combine.hs 57;" f
combineModuleMaps src/Dodge/Combine.hs 68;" f
combineRooms src/Dodge/Room/Procedural.hs 151;" f
combineS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 344;" f
combineTree src/Dodge/Tree/Compose.hs 66;" f
combineTwoModuleMaps src/Dodge/Combine.hs 113;" f
combineTwoModuleMaps src/Dodge/Combine.hs 74;" f
commandColor src/Dodge/Terminal.hs 130;" f
commandFutureLines src/Dodge/Terminal.hs 252;" f
commandsCommand src/Dodge/Terminal.hs 91;" f
@@ -5266,7 +5265,7 @@ doubleLampCover src/Dodge/LightSources/Lamp.hs 89;" f
doubleLampCover src/Dodge/Placement/Instance/LightSource/Cover.hs 28;" f
doublePair src/Geometry.hs 149;" f
doublePairSet src/Geometry.hs 153;" f
doubleTreeToIndentList src/Dodge/DoubleTree.hs 11;" f
doubleTreeToIndentList src/Dodge/DoubleTree.hs 12;" f
doubleV2 src/Geometry.hs 156;" f
downSize src/Dodge/DownscaleSize.hs 3;" f
drawAllShadows src/Dodge/Shadows.hs 5;" f
@@ -5385,7 +5384,9 @@ dropExcept src/Dodge/Creature/Action.hs 178;" f
dropItem src/Dodge/Creature/Action.hs 183;" f
dropItemKey src/Dodge/Config/KeyConfig.hs 24;" f
drumMag src/Dodge/Item/Ammo.hs 31;" f
dtIL src/Dodge/DoubleTree.hs 14;" f
dtIL src/Dodge/DoubleTree.hs 15;" f
dtToAdjacency src/Dodge/DoubleTree.hs 22;" f
dtToUpDownAdj src/Dodge/DoubleTree.hs 28;" f
dualBeam src/Dodge/Item/Held/BatteryGuns.hs 136;" f
dualBeamPic src/Dodge/Item/Draw/SPic.hs 472;" f
dualRayAt src/Dodge/Item/Weapon/BatteryGuns.hs 144;" f
@@ -5411,7 +5412,7 @@ encircleCloseP src/Dodge/Creature/Boid.hs 35;" f
encircleDistP src/Dodge/Creature/Boid.hs 21;" f
encircleP src/Dodge/Creature/Boid.hs 27;" f
energyBallCraft src/Dodge/Item/Craftable.hs 18;" f
enterCombineInv src/Dodge/DisplayInventory.hs 259;" f
enterCombineInv src/Dodge/DisplayInventory.hs 254;" f
eqConstr src/SameConstr.hs 17;" f
eqPosText src/Dodge/Equipment/Text.hs 6;" f
equipAimSpeed src/Dodge/Creature/Action/Movement.hs 109;" f
@@ -5469,7 +5470,7 @@ fallSmallBounceDamage src/Dodge/Prop/Moving.hs 11;" f
farWallDistDirection src/Dodge/Update/Camera.hs 247;" f
feet src/Dodge/Creature/Picture.hs 51;" f
ffoldM src/Framebuffer/Update.hs 79;" f
filter3 src/FoldableHelp.hs 75;" f
filter3 src/FoldableHelp.hs 76;" f
findBlips src/Dodge/RadarSweep.hs 43;" f
findBoundDists src/Dodge/Update/Camera.hs 256;" f
findClosePoint src/Dodge/LevelGen/StaticWalls.hs 155;" f
@@ -5506,7 +5507,7 @@ flamerPic src/Dodge/Item/Draw/SPic.hs 416;" f
flareCircleAt src/Dodge/WorldEvent/Flash.hs 46;" f
flatCombinationsTrie src/Dodge/Combine/Trie.hs 10;" f
flatItemCombinations src/Dodge/Combine/Combinations.hs 49;" f
flatLookupItems src/Dodge/Combine.hs 61;" f
flatLookupItems src/Dodge/Combine.hs 36;" f
flatShield src/Dodge/Item/Held/Utility.hs 9;" f
flatShieldEquipSPic src/Dodge/Item/Draw/SPic.hs 489;" f
flatV2 src/Picture/Data.hs 65;" f
@@ -5570,7 +5571,7 @@ fromV3 src/Geometry/Data.hs 43;" f
frontArmour src/Dodge/Item/Equipment.hs 43;" f
fstV2 src/Geometry/Data.hs 50;" f
fuelPack src/Dodge/Item/Equipment.hs 66;" f
fullModuleName src/Dodge/Combine.hs 132;" f
fullModuleName src/Dodge/Combine.hs 93;" f
functionalUpdate src/Dodge/Update.hs 230;" f
fuseFunc src/Dodge/Path.hs 150;" f
fusePairs src/Dodge/Path.hs 153;" f
@@ -5661,7 +5662,7 @@ gridPoints src/Grid.hs 67;" f
gridPoints' src/Grid.hs 79;" f
gridPoints'' src/Grid.hs 74;" f
gridPointsOff src/Grid.hs 62;" f
groupSplitItemAmounts src/Dodge/Combine.hs 48;" f
groupSplitItemAmounts src/Dodge/Combine.hs 31;" f
gruntS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 484;" f
guardDisconnectedID src/Dodge/Update/Scroll.hs 67;" f
gut1S src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 516;" f
@@ -5699,7 +5700,7 @@ hatCombinations src/Dodge/Combine/Combinations.hs 33;" f
head src/DoubleStack.hs 14;" f
headLamp src/Dodge/Item/Equipment.hs 118;" f
headLampShape src/Dodge/Item/Draw/SPic.hs 495;" f
headMap src/Dodge/DoubleTree.hs 45;" f
headMap src/Dodge/DoubleTree.hs 58;" f
heal src/Dodge/Item/Consumable.hs 17;" f
heal25 src/Dodge/Item/Consumable.hs 14;" f
healS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 354;" f
@@ -5731,7 +5732,7 @@ holsterWeaponSound src/Dodge/SoundLogic/Synonyms.hs 4;" f
homingLaunchers src/Dodge/Combine/Combinations.hs 224;" f
horPipe src/Dodge/Placement/Instance/Pipe.hs 9;" f
hotkeyToScancode src/Dodge/Creature/YourControl.hs 55;" f
hotkeyToString src/Dodge/Inventory/SelectionList.hs 53;" f
hotkeyToString src/Dodge/Inventory/SelectionList.hs 51;" f
humanoidAIList src/Dodge/Humanoid.hs 181;" f
hvBulDams src/Dodge/Particle/Damage.hs 13;" f
hvBulHitCr src/Dodge/Particle/Bullet/HitEffect.hs 17;" f
@@ -5822,12 +5823,12 @@ intersectSegsSeg src/Geometry/Intersect.hs 232;" f
intervalList src/Geometry.hs 315;" f
interweave src/Justify.hs 17;" f
intsToPos src/Dodge/Room/Modify/Girder.hs 160;" f
invAdj src/Dodge/Item/Grammar.hs 87;" f
invDimColor src/Dodge/DisplayInventory.hs 140;" f
invDimColor src/Dodge/Inventory/Color.hs 4;" f
invDisplayParams src/Dodge/ListDisplayParams.hs 29;" f
invHead src/Dodge/Render/HUD.hs 275;" f
invIndentIM src/Dodge/Item/Grammar.hs 90;" f
invIndentIM' src/Dodge/Item/Grammar.hs 87;" f
invIndentIM src/Dodge/Item/Grammar.hs 93;" f
invLDT src/Dodge/Item/Grammar.hs 83;" f
invSelectionItem src/Dodge/Inventory/SelectionList.hs 35;" f
invSelectionItem' src/Dodge/Inventory/SelectionList.hs 17;" f
@@ -5838,7 +5839,7 @@ inventoryX src/Dodge/Creature.hs 115;" f
inverseShockwaveAt src/Dodge/WorldEvent/Shockwave.hs 43;" f
invertEncircleDistP src/Dodge/Creature/Boid.hs 13;" f
invertIntMap src/Multiset.hs 61;" f
invertInventoryToMap src/Dodge/Combine.hs 37;" f
invertInventoryToMap src/Dodge/Combine.hs 25;" f
invisibleChaseCrit src/Dodge/Creature/ChaseCrit.hs 25;" f
invisibleWall src/Dodge/Placement/Instance/Wall.hs 16;" f
isAnimate src/Dodge/Creature/Test.hs 138;" f
@@ -5937,7 +5938,8 @@ killBulletUpdate src/Dodge/WorldEvent/HitEffect.hs 30;" f
killParticleUpdate src/Dodge/Particle/Update.hs 9;" f
knifeS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 456;" f
knifeSound src/Dodge/SoundLogic/Synonyms.hs 4;" f
lConnect src/Dodge/Render/Connectors.hs 26;" f
lConnect src/Dodge/Render/Connectors.hs 30;" f
lConnectMulti src/Dodge/Render/Connectors.hs 37;" f
lShape src/Dodge/Placement/Instance/LightSource.hs 77;" f
lShape src/Dodge/Placements/LightSource.hs 35;" f
lamp src/Dodge/Creature/Lamp.hs 22;" f
@@ -5961,7 +5963,7 @@ lasTurret src/Dodge/Placement/Instance/Turret.hs 23;" f
lasTurret src/Dodge/Placements/Turret.hs 29;" f
lasWide src/Dodge/Item/Held/BatteryGuns.hs 97;" f
lasWideRate src/Dodge/HeldUse.hs 353;" f
lastMap src/Dodge/DoubleTree.hs 49;" f
lastMap src/Dodge/DoubleTree.hs 62;" f
latchkey src/Dodge/Item/Held/Utility.hs 23;" f
latchkey src/Dodge/Item/PassKey.hs 14;" f
launcher src/Dodge/Item/Held/Launcher.hs 10;" f
@@ -5972,9 +5974,9 @@ launcherX src/Dodge/Item/Held/Launcher.hs 39;" f
layerNum src/Picture/Data.hs 31;" f
layoutLevelFromSeed src/Dodge/LevelGen.hs 47;" f
ldpVerticalSelection src/Dodge/Update/Input/ScreenLayer.hs 90;" f
ldtIL src/Dodge/DoubleTree.hs 24;" f
ldtToDT src/Dodge/DoubleTree.hs 5;" f
ldtToIndentList src/Dodge/DoubleTree.hs 21;" f
ldtIL src/Dodge/DoubleTree.hs 37;" f
ldtToDT src/Dodge/DoubleTree.hs 6;" f
ldtToIndentList src/Dodge/DoubleTree.hs 34;" f
left src/DoubleStack.hs 16;" f
leftInfo src/Dodge/Item/Info.hs 110;" f
leftIsParentCombine src/Dodge/Item/Grammar.hs 49;" f
@@ -6012,7 +6014,7 @@ listConfig src/Dodge/Menu.hs 199;" f
listControls src/Dodge/Menu.hs 212;" f
listCursorChooseBorderScale src/Dodge/Render/List.hs 105;" f
listGuard src/Dodge/Creature/ReaderUpdate.hs 188;" f
listSelectionColorPicture src/Dodge/DisplayInventory.hs 251;" f
listSelectionColorPicture src/Dodge/DisplayInventory.hs 246;" f
litCorridor90 src/Dodge/Room/RoadBlock.hs 26;" f
lmt src/MatrixHelper.hs 43;" f
lnkBothAnd src/Dodge/Room/Procedural.hs 120;" f
@@ -6213,8 +6215,9 @@ midPad src/Padding.hs 30;" f
midPadL src/Padding.hs 36;" f
midPoint src/Geometry.hs 86;" f
midWall src/Dodge/Placement/Instance/Wall.hs 27;" f
minAndMax src/FoldableHelp.hs 109;" f
minCrIXOn src/Dodge/Zoning/Creature.hs 45;" f
minOn src/FoldableHelp.hs 34;" f
minOn src/FoldableHelp.hs 35;" f
minStreamOn src/StreamingHelp.hs 14;" f
mini1S src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 322;" f
miniGunCrit src/Dodge/Creature.hs 62;" f
@@ -6631,8 +6634,8 @@ prependTwo src/Geometry.hs 165;" f
pressedMBEffects src/Dodge/Update/UsingInput.hs 27;" f
pressedMBEffectsNoInventory src/Dodge/Update/UsingInput.hs 40;" f
pressedMBEffectsTopInventory src/Dodge/Creature/YourControl.hs 206;" f
prettyDT src/Dodge/DoubleTree.hs 54;" f
prettyLDT src/Dodge/DoubleTree.hs 58;" f
prettyDT src/Dodge/DoubleTree.hs 67;" f
prettyLDT src/Dodge/DoubleTree.hs 71;" f
primeS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 422;" f
printColumnTitles src/Dodge/Tree/Shift.hs 142;" f
printColumns src/Dodge/Tree/Shift.hs 132;" f
@@ -6954,11 +6957,11 @@ sPS src/Dodge/LevelGen/PlacementHelper.hs 27;" f
safeAngleVV src/Geometry/Vector.hs 68;" f
safeArgV src/Geometry/Vector.hs 87;" f
safeHead src/ListHelp.hs 66;" f
safeMinMaybeL src/FoldableHelp.hs 47;" f
safeMinimumOn src/FoldableHelp.hs 25;" f
safeMinimumOnMaybe src/FoldableHelp.hs 66;" f
safeMinimumOnMaybeF src/FoldableHelp.hs 38;" f
safeMinimumOnMaybeL src/FoldableHelp.hs 56;" f
safeMinMaybeL src/FoldableHelp.hs 48;" f
safeMinimumOn src/FoldableHelp.hs 26;" f
safeMinimumOnMaybe src/FoldableHelp.hs 67;" f
safeMinimumOnMaybeF src/FoldableHelp.hs 39;" f
safeMinimumOnMaybeL src/FoldableHelp.hs 57;" f
safeNormalizeV src/Geometry/Vector.hs 153;" f
safeSwapKeys src/IntMapHelp.hs 76;" f
safeUncons src/ListHelp.hs 70;" f
@@ -7312,7 +7315,7 @@ ssLookupUp src/Dodge/SelectionSections.hs 69;" f
ssScrollUsing src/Dodge/SelectionSections.hs 28;" f
ssScrollUsing' src/Dodge/SelectionSections.hs 38;" f
ssSetCursor src/Dodge/SelectionSections.hs 52;" f
ssfold src/FoldableHelp.hs 104;" f
ssfold src/FoldableHelp.hs 105;" f
stackPicturesAt src/Dodge/Render/List.hs 81;" f
stackPicturesAtOff src/Dodge/Render/List.hs 84;" f
stackText src/Picture/Base.hs 188;" f
@@ -7379,7 +7382,7 @@ takeOneMore src/Dodge/RandomHelp.hs 26;" f
takeOneMore src/RandomHelp.hs 31;" f
takeOneWeighted src/Dodge/RandomHelp.hs 18;" f
takeOneWeighted src/RandomHelp.hs 23;" f
takeUntil src/FoldableHelp.hs 98;" f
takeUntil src/FoldableHelp.hs 99;" f
takeWhileArb src/ListHelp.hs 97;" f
takeWhileArb' src/ListHelp.hs 105;" f
tankShape src/Dodge/Placement/Instance/Tank.hs 22;" f
@@ -7985,8 +7988,8 @@ yourItem src/Dodge/Base/You.hs 20;" f
yourScopeInvID src/Dodge/Base/You.hs 33;" f
yourScrollAttachment src/Dodge/Base/You.hs 25;" f
yourStatsInfo src/Dodge/Creature/Info.hs 25;" f
zConnect src/Dodge/Render/Connectors.hs 9;" f
zConnectCol src/Dodge/Render/Connectors.hs 16;" f
zConnect src/Dodge/Render/Connectors.hs 13;" f
zConnectCol src/Dodge/Render/Connectors.hs 20;" f
zeroZ src/Geometry/Vector.hs 8;" f
zipArcs src/Dodge/Tesla/Arc.hs 96;" f
zipCount src/Dodge/Tree/Shift.hs 129;" f