diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 9a47a4ca1d..586c31752e 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -90,7 +90,7 @@ stats.destroyed = Buildings Destroyed stats.deconstructed = Buildings Deconstructed stats.playtime = Time Played -globalitems = [accent]Total Items +globalitems = [accent]Planet Items map.delete = Are you sure you want to delete the map "[accent]{0}[]"? level.highscore = High Score: [accent]{0} level.select = Level Select diff --git a/core/src/mindustry/content/TechTree.java b/core/src/mindustry/content/TechTree.java index aef00856f5..933f0e6c45 100644 --- a/core/src/mindustry/content/TechTree.java +++ b/core/src/mindustry/content/TechTree.java @@ -93,6 +93,8 @@ public class TechTree{ public Seq objectives = new Seq<>(); /** Nodes that depend on this node. */ public final Seq children = new Seq<>(); + /** Planet associated with this tech node. Null to auto-detect, or use Serpulo if no associated planet is found. */ + public @Nullable Planet planet; public TechNode(@Nullable TechNode parent, UnlockableContent content, ItemStack[] requirements){ if(parent != null){ diff --git a/core/src/mindustry/game/Universe.java b/core/src/mindustry/game/Universe.java index eba7987876..8993da4929 100644 --- a/core/src/mindustry/game/Universe.java +++ b/core/src/mindustry/game/Universe.java @@ -278,21 +278,6 @@ public class Universe{ save(); } - /** This method is expensive to call; only do so sparingly. */ - public ItemSeq getGlobalResources(){ - ItemSeq count = new ItemSeq(); - - for(Planet planet : content.planets()){ - for(Sector sector : planet.sectors){ - if(sector.hasSave()){ - count.add(sector.items()); - } - } - } - - return count; - } - public void updateNetSeconds(int value){ netSeconds = value; } diff --git a/core/src/mindustry/ui/dialogs/ResearchDialog.java b/core/src/mindustry/ui/dialogs/ResearchDialog.java index 698789b849..b22315dfc5 100644 --- a/core/src/mindustry/ui/dialogs/ResearchDialog.java +++ b/core/src/mindustry/ui/dialogs/ResearchDialog.java @@ -116,60 +116,7 @@ public class ResearchDialog extends BaseDialog{ if(currPlanet != null && currPlanet.techTree != null){ switchTree(currPlanet.techTree); } - - items = new ItemSeq(){ - //store sector item amounts for modifications - ObjectMap cache = new ObjectMap<>(); - - { - //add global counts of each sector - for(Planet planet : content.planets()){ - for(Sector sector : planet.sectors){ - if(sector.hasBase()){ - ItemSeq cached = sector.items(); - cache.put(sector, cached); - cached.each((item, amount) -> { - values[item.id] += Math.max(amount, 0); - total += Math.max(amount, 0); - }); - } - } - } - } - - //this is the only method that actually modifies the sequence itself. - @Override - public void add(Item item, int amount){ - //only have custom removal logic for when the sequence gets items taken out of it (e.g. research) - if(amount < 0){ - //remove items from each sector's storage, one by one - - //negate amount since it's being *removed* - this makes it positive - amount = -amount; - - //% that gets removed from each sector - double percentage = (double)amount / get(item); - int[] counter = {amount}; - cache.each((sector, seq) -> { - if(counter[0] == 0) return; - - //amount that will be removed - int toRemove = Math.min((int)Math.ceil(percentage * seq.get(item)), counter[0]); - - //actually remove it from the sector - sector.removeItem(item, toRemove); - seq.remove(item, toRemove); - - counter[0] -= toRemove; - }); - - //negate again to display correct number - amount = -amount; - } - - super.add(item, amount); - } - }; + rebuildItems(); checkNodes(root); treeLayout(); @@ -240,6 +187,68 @@ public class ResearchDialog extends BaseDialog{ }); } + public void rebuildItems(){ + items = new ItemSeq(){ + //store sector item amounts for modifications + ObjectMap cache = new ObjectMap<>(); + + { + //first, find a planet associated with the current tech tree + Planet rootPlanet = lastNode.planet != null ? lastNode.planet : content.planets().find(p -> p.techTree == lastNode); + + //if there is no root, fall back to serpulo + if(rootPlanet == null) rootPlanet = Planets.serpulo; + + //add global counts of each sector + for(Sector sector : rootPlanet.sectors){ + if(sector.hasBase()){ + ItemSeq cached = sector.items(); + cache.put(sector, cached); + cached.each((item, amount) -> { + values[item.id] += Math.max(amount, 0); + total += Math.max(amount, 0); + }); + } + } + } + + //this is the only method that actually modifies the sequence itself. + @Override + public void add(Item item, int amount){ + //only have custom removal logic for when the sequence gets items taken out of it (e.g. research) + if(amount < 0){ + //remove items from each sector's storage, one by one + + //negate amount since it's being *removed* - this makes it positive + amount = -amount; + + //% that gets removed from each sector + double percentage = (double)amount / get(item); + int[] counter = {amount}; + cache.each((sector, seq) -> { + if(counter[0] == 0) return; + + //amount that will be removed + int toRemove = Math.min((int)Math.ceil(percentage * seq.get(item)), counter[0]); + + //actually remove it from the sector + sector.removeItem(item, toRemove); + seq.remove(item, toRemove); + + counter[0] -= toRemove; + }); + + //negate again to display correct number + amount = -amount; + } + + super.add(item, amount); + } + }; + + itemDisplay.rebuild(items); + } + public @Nullable TechNode getPrefRoot(){ Planet currPlanet = ui.planet.isShown() ? ui.planet.state.planet : @@ -253,6 +262,8 @@ public class ResearchDialog extends BaseDialog{ root = new TechTreeNode(node, null); lastNode = node; view.rebuildAll(); + + rebuildItems(); } public void rebuildTree(TechNode node){