From 67fb9f6a9434a48eb81f13f5e53fbd7244986e89 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 12 Jun 2024 21:07:54 -0400 Subject: [PATCH] Core database tabs --- core/assets/bundles/bundle.properties | 1 + core/src/mindustry/content/Blocks.java | 12 +++++ core/src/mindustry/content/TechTree.java | 5 ++ .../mindustry/ctype/UnlockableContent.java | 6 ++- core/src/mindustry/type/Planet.java | 4 ++ core/src/mindustry/type/StatusEffect.java | 2 + core/src/mindustry/type/UnitType.java | 2 + .../mindustry/ui/dialogs/DatabaseDialog.java | 53 ++++++++++++++++++- core/src/mindustry/world/Block.java | 2 + 9 files changed, 83 insertions(+), 4 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 97d7e72411..f78bf1406b 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -502,6 +502,7 @@ wavemode.counts = counts wavemode.totals = totals wavemode.health = health +all = All editor.default = [lightgray] details = Details... edit = Edit diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index dfd856d56a..912e1ecb09 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -5755,43 +5755,51 @@ public class Blocks{ requirements(Category.power, BuildVisibility.sandboxOnly, with()); powerProduction = 1000000f / 60f; alwaysUnlocked = true; + allDatabaseTabs = true; }}; powerVoid = new PowerVoid("power-void"){{ requirements(Category.power, BuildVisibility.sandboxOnly, with()); alwaysUnlocked = true; + allDatabaseTabs = true; }}; itemSource = new ItemSource("item-source"){{ requirements(Category.distribution, BuildVisibility.sandboxOnly, with()); alwaysUnlocked = true; + allDatabaseTabs = true; }}; itemVoid = new ItemVoid("item-void"){{ requirements(Category.distribution, BuildVisibility.sandboxOnly, with()); alwaysUnlocked = true; + allDatabaseTabs = true; }}; liquidSource = new LiquidSource("liquid-source"){{ requirements(Category.liquid, BuildVisibility.sandboxOnly, with()); alwaysUnlocked = true; + allDatabaseTabs = true; }}; liquidVoid = new LiquidVoid("liquid-void"){{ requirements(Category.liquid, BuildVisibility.sandboxOnly, with()); alwaysUnlocked = true; + allDatabaseTabs = true; }}; payloadSource = new PayloadSource("payload-source"){{ requirements(Category.units, BuildVisibility.sandboxOnly, with()); size = 5; alwaysUnlocked = true; + allDatabaseTabs = true; }}; payloadVoid = new PayloadVoid("payload-void"){{ requirements(Category.units, BuildVisibility.sandboxOnly, with()); size = 5; alwaysUnlocked = true; + allDatabaseTabs = true; }}; heatSource = new HeatProducer("heat-source"){{ @@ -5945,6 +5953,7 @@ public class Blocks{ size = 1; maxInstructionsPerTick = 1000; range = Float.MAX_VALUE; + allDatabaseTabs = true; }}; worldCell = new MemoryBlock("world-cell"){{ @@ -5954,6 +5963,7 @@ public class Blocks{ privileged = true; memoryCapacity = 128; forceDark = true; + allDatabaseTabs = true; }}; worldMessage = new MessageBlock("world-message"){{ @@ -5961,6 +5971,7 @@ public class Blocks{ targetable = false; privileged = true; + allDatabaseTabs = true; }}; worldSwitch = new SwitchBlock("world-switch"){{ @@ -5968,6 +5979,7 @@ public class Blocks{ targetable = false; privileged = true; + allDatabaseTabs = true; }}; //endregion diff --git a/core/src/mindustry/content/TechTree.java b/core/src/mindustry/content/TechTree.java index b782b8204d..e169c82845 100644 --- a/core/src/mindustry/content/TechTree.java +++ b/core/src/mindustry/content/TechTree.java @@ -139,6 +139,11 @@ public class TechTree{ } } + /** Adds the specified tab to all the content in this tree. */ + public void addDatabaseTab(UnlockableContent tab){ + each(node -> node.content.databaseTabs.add(tab)); + } + public Drawable icon(){ return icon == null ? new TextureRegionDrawable(content.uiIcon) : icon; } diff --git a/core/src/mindustry/ctype/UnlockableContent.java b/core/src/mindustry/ctype/UnlockableContent.java index c8eacc4f6a..55628afe0c 100644 --- a/core/src/mindustry/ctype/UnlockableContent.java +++ b/core/src/mindustry/ctype/UnlockableContent.java @@ -35,8 +35,6 @@ public abstract class UnlockableContent extends MappableContent{ public boolean hideDetails = true; /** If false, all icon generation is disabled for this content; createIcons is not called. */ public boolean generateIcons = true; - /** Special logic icon ID. */ - public int iconId = 0; /** How big the content appears in certain selection menus */ public float selectionSize = 24f; /** Icon of the content to use in UI. */ @@ -45,6 +43,10 @@ public abstract class UnlockableContent extends MappableContent{ public TextureRegion fullIcon; /** Override for the full icon. Useful for mod content with duplicate icons. Overrides any other full icon.*/ public String fullOverride = ""; + /** If true, this content will appear in all database tabs. */ + public boolean allDatabaseTabs = false; + /** Content - usually a planet - that dictates which database tab(s) this content will appear in. If nothing is defined, Serpulo is considered to be the "default" tab. */ + public ObjectSet databaseTabs = new ObjectSet<>(); /** The tech tree node for this content, if applicable. Null if not part of a tech tree. */ public @Nullable TechNode techNode; /** Tech nodes for all trees that this content is part of. */ diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index c25852881f..b8bd7e0646 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -338,6 +338,10 @@ public class Planet extends UnlockableContent{ techTree = TechTree.roots.find(n -> n.planet == this); } + if(techTree != null){ + techTree.addDatabaseTab(this); + } + for(Sector sector : sectors){ sector.loadInfo(); } diff --git a/core/src/mindustry/type/StatusEffect.java b/core/src/mindustry/type/StatusEffect.java index 79d0177b41..0e36616cd4 100644 --- a/core/src/mindustry/type/StatusEffect.java +++ b/core/src/mindustry/type/StatusEffect.java @@ -68,10 +68,12 @@ public class StatusEffect extends UnlockableContent{ public StatusEffect(String name){ super(name); + allDatabaseTabs = true; } @Override public void init(){ + super.init(); if(initblock != null){ initblock.run(); } diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index 3408948807..15ed66ce9c 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -675,6 +675,8 @@ public class UnitType extends UnlockableContent implements Senseable{ @CallSuper @Override public void init(){ + super.init(); + if(constructor == null) throw new IllegalArgumentException("no constructor set up for unit '" + name + "'"); Unit example = constructor.get(); diff --git a/core/src/mindustry/ui/dialogs/DatabaseDialog.java b/core/src/mindustry/ui/dialogs/DatabaseDialog.java index 9fdefa9e1c..a8ca315826 100644 --- a/core/src/mindustry/ui/dialogs/DatabaseDialog.java +++ b/core/src/mindustry/ui/dialogs/DatabaseDialog.java @@ -5,11 +5,13 @@ import arc.graphics.*; import arc.input.*; import arc.math.*; import arc.scene.event.*; +import arc.scene.style.*; import arc.scene.ui.*; import arc.scene.ui.layout.*; import arc.struct.*; import arc.util.*; import mindustry.*; +import mindustry.content.*; import mindustry.ctype.*; import mindustry.gen.*; import mindustry.graphics.*; @@ -24,16 +26,30 @@ public class DatabaseDialog extends BaseDialog{ private TextField search; private Table all = new Table(); + private @Nullable Seq allTabs; + //sun means "all content" + private UnlockableContent tab = Planets.sun; + public DatabaseDialog(){ super("@database"); shouldPause = true; addCloseButton(); - shown(this::rebuild); + shown(() -> { + checkTabList(); + if(state.isCampaign() && allTabs.contains(state.getPlanet())){ + tab = state.getPlanet(); + }else if(state.isGame() && state.rules.planet != null && allTabs.contains(state.rules.planet)){ + tab = state.rules.planet; + } + + rebuild(); + }); onResize(this::rebuild); all.margin(20).marginTop(0f); + cont.top(); cont.table(s -> { s.image(Icon.zoom).padRight(8); search = s.field(null, text -> rebuild()).growX().get(); @@ -43,18 +59,51 @@ public class DatabaseDialog extends BaseDialog{ cont.pane(all).scrollX(false); } + void checkTabList(){ + if(allTabs == null){ + Seq[] allContent = Vars.content.getContentMap(); + ObjectSet all = new ObjectSet<>(); + for(var contents : allContent){ + for(var content : contents){ + if(content instanceof UnlockableContent u){ + all.addAll(u.databaseTabs); + } + } + } + allTabs = all.toSeq().sort(); + allTabs.insert(0, Planets.sun); + } + } + void rebuild(){ + checkTabList(); + all.clear(); var text = search.getText().toLowerCase(); Seq[] allContent = Vars.content.getContentMap(); + all.table(t -> { + int i = 0; + for(var content : allTabs){ + t.button(content == Planets.sun ? Icon.eyeSmall : content instanceof Planet ? Icon.planet : new TextureRegionDrawable(content.uiIcon), Styles.clearNoneTogglei, iconMed, () -> { + tab = content; + rebuild(); + }).size(50f).checked(b -> tab == content).tooltip(content == Planets.sun ? "@all" : content.localizedName).with(but -> { + but.getStyle().imageUpColor = content instanceof Planet p ? p.iconColor : Color.white.cpy(); + }); + + if(++i % 10 == 0) t.row(); + } + }).row();; + for(int j = 0; j < allContent.length; j++){ ContentType type = ContentType.all[j]; Seq array = allContent[j] - .select(c -> c instanceof UnlockableContent u && !u.isHidden() && + .select(c -> c instanceof UnlockableContent u && !u.isHidden() && (tab == Planets.sun || u.allDatabaseTabs || (u.databaseTabs.isEmpty() && tab == Planets.serpulo) || u.databaseTabs.contains(tab)) && (text.isEmpty() || u.localizedName.toLowerCase().contains(text))).as(); + if(array.size == 0) continue; all.add("@content." + type.name() + ".name").growX().left().color(Pal.accent); diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 1576cfb162..11cd6fee57 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -1168,6 +1168,8 @@ public class Block extends UnlockableContent implements Senseable{ @Override @CallSuper public void init(){ + super.init(); + //disable standard shadow if(customShadow){ hasShadow = false;