mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-19 00:37:20 +07:00
Added shownPlanets for content
This commit is contained in:
parent
e1fb13847b
commit
2dbd9e5ea9
@ -139,11 +139,16 @@ public class TechTree{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds the specified tab to all the content in this tree. */
|
/** Adds the specified database tab to all the content in this tree. */
|
||||||
public void addDatabaseTab(UnlockableContent tab){
|
public void addDatabaseTab(UnlockableContent tab){
|
||||||
each(node -> node.content.databaseTabs.add(tab));
|
each(node -> node.content.databaseTabs.add(tab));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Adds the specified planet to the shownPlanets of all the content in this tree. */
|
||||||
|
public void addPlanet(Planet planet){
|
||||||
|
each(node -> node.content.shownPlanets.add(planet));
|
||||||
|
}
|
||||||
|
|
||||||
public Drawable icon(){
|
public Drawable icon(){
|
||||||
return icon == null ? new TextureRegionDrawable(content.uiIcon) : icon;
|
return icon == null ? new TextureRegionDrawable(content.uiIcon) : icon;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import arc.scene.ui.layout.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
|
import mindustry.content.*;
|
||||||
import mindustry.content.TechTree.*;
|
import mindustry.content.TechTree.*;
|
||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
@ -45,14 +46,25 @@ public abstract class UnlockableContent extends MappableContent{
|
|||||||
public String fullOverride = "";
|
public String fullOverride = "";
|
||||||
/** If true, this content will appear in all database tabs. */
|
/** If true, this content will appear in all database tabs. */
|
||||||
public boolean allDatabaseTabs = false;
|
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. */
|
/**
|
||||||
|
* Planets that this content is made for. If empty, it is shown on all planets.
|
||||||
|
* Currently, this is only meaningful for blocks.
|
||||||
|
* */
|
||||||
|
public ObjectSet<Planet> shownPlanets = new ObjectSet<>();
|
||||||
|
/**
|
||||||
|
* Content - usually a planet - that dictates which database tab(s) this content will appear in.
|
||||||
|
* If nothing is defined, it will use the values in shownPlanets.
|
||||||
|
* If shownPlanets is also empty, it will use Serpulo as the "default" tab.
|
||||||
|
* Note: When reading, use {@link #getDatabaseTabs} instead.
|
||||||
|
* */
|
||||||
public ObjectSet<UnlockableContent> databaseTabs = new ObjectSet<>();
|
public ObjectSet<UnlockableContent> databaseTabs = new ObjectSet<>();
|
||||||
/** The tech tree node for this content, if applicable. Null if not part of a tech tree. */
|
/** The tech tree node for this content, if applicable. Null if not part of a tech tree. */
|
||||||
public @Nullable TechNode techNode;
|
public @Nullable TechNode techNode;
|
||||||
/** Tech nodes for all trees that this content is part of. */
|
/** Tech nodes for all trees that this content is part of. */
|
||||||
public Seq<TechNode> techNodes = new Seq<>();
|
public Seq<TechNode> techNodes = new Seq<>();
|
||||||
/** Unlock state. Loaded from settings. Do not modify outside of the constructor. */
|
/** Unlock state. Loaded from settings. Do not modify outside the constructor. */
|
||||||
protected boolean unlocked;
|
protected boolean unlocked;
|
||||||
|
private boolean initializedDatabaseTabs;
|
||||||
|
|
||||||
public UnlockableContent(String name){
|
public UnlockableContent(String name){
|
||||||
super(name);
|
super(name);
|
||||||
@ -63,6 +75,20 @@ public abstract class UnlockableContent extends MappableContent{
|
|||||||
this.unlocked = Core.settings != null && Core.settings.getBool(this.name + "-unlocked", false);
|
this.unlocked = Core.settings != null && Core.settings.getBool(this.name + "-unlocked", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObjectSet<UnlockableContent> getDatabaseTabs(){
|
||||||
|
//the problem here is that the planet hasn't initialized yet in init(), which means it hasn't assigned the shownPlanets yet.
|
||||||
|
//initialization has to be deferred to a getter
|
||||||
|
if(!initializedDatabaseTabs){
|
||||||
|
initializedDatabaseTabs = true;
|
||||||
|
|
||||||
|
databaseTabs.addAll(shownPlanets);
|
||||||
|
if(databaseTabs.isEmpty()){
|
||||||
|
databaseTabs.add(Planets.serpulo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return databaseTabs;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadIcon(){
|
public void loadIcon(){
|
||||||
fullIcon =
|
fullIcon =
|
||||||
|
@ -1097,29 +1097,41 @@ public class ContentParser{
|
|||||||
}
|
}
|
||||||
Field field = metadata.field;
|
Field field = metadata.field;
|
||||||
try{
|
try{
|
||||||
boolean isMap = ObjectMap.class.isAssignableFrom(field.getType()) || ObjectIntMap.class.isAssignableFrom(field.getType()) || ObjectFloatMap.class.isAssignableFrom(field.getType());
|
if(child.isObject() && child.has("add") && (Seq.class.isAssignableFrom(field.getType()) || ObjectSet.class.isAssignableFrom(field.getType()))){
|
||||||
boolean mergeMap = isMap && child.has("add") && child.get("add").isBoolean() && child.getBoolean("add", false);
|
Object readField = parser.readValue(field.getType(), metadata.elementType, child.get("add"), metadata.keyType);
|
||||||
|
Object fieldObj = field.get(object);
|
||||||
|
|
||||||
if(mergeMap){
|
if(fieldObj instanceof ObjectSet set){
|
||||||
child.remove("add");
|
set.addAll((ObjectSet)fieldObj);
|
||||||
}
|
}else if(fieldObj instanceof Seq seq){
|
||||||
|
seq.addAll((Seq)fieldObj);
|
||||||
Object readField = parser.readValue(field.getType(), metadata.elementType, child, metadata.keyType);
|
}else{
|
||||||
Object fieldObj = field.get(object);
|
throw new SerializationException("This should be impossible");
|
||||||
|
|
||||||
//if a map has add: true, add its contents to the map instead
|
|
||||||
if(mergeMap && (fieldObj instanceof ObjectMap<?,?> || fieldObj instanceof ObjectIntMap<?> || fieldObj instanceof ObjectFloatMap<?>)){
|
|
||||||
if(field.get(object) instanceof ObjectMap<?,?> baseMap){
|
|
||||||
baseMap.putAll((ObjectMap)readField);
|
|
||||||
}else if(field.get(object) instanceof ObjectIntMap<?> baseMap){
|
|
||||||
baseMap.putAll((ObjectIntMap)readField);
|
|
||||||
}else if(field.get(object) instanceof ObjectFloatMap<?> baseMap){
|
|
||||||
baseMap.putAll((ObjectFloatMap)readField);
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
field.set(object, readField);
|
boolean isMap = ObjectMap.class.isAssignableFrom(field.getType()) || ObjectIntMap.class.isAssignableFrom(field.getType()) || ObjectFloatMap.class.isAssignableFrom(field.getType());
|
||||||
}
|
boolean mergeMap = isMap && child.has("add") && child.get("add").isBoolean() && child.getBoolean("add", false);
|
||||||
|
|
||||||
|
if(mergeMap){
|
||||||
|
child.remove("add");
|
||||||
|
}
|
||||||
|
|
||||||
|
Object readField = parser.readValue(field.getType(), metadata.elementType, child, metadata.keyType);
|
||||||
|
Object fieldObj = field.get(object);
|
||||||
|
|
||||||
|
//if a map has add: true, add its contents to the map instead
|
||||||
|
if(mergeMap && (fieldObj instanceof ObjectMap<?,?> || fieldObj instanceof ObjectIntMap<?> || fieldObj instanceof ObjectFloatMap<?>)){
|
||||||
|
if(field.get(object) instanceof ObjectMap<?,?> baseMap){
|
||||||
|
baseMap.putAll((ObjectMap)readField);
|
||||||
|
}else if(field.get(object) instanceof ObjectIntMap<?> baseMap){
|
||||||
|
baseMap.putAll((ObjectIntMap)readField);
|
||||||
|
}else if(field.get(object) instanceof ObjectFloatMap<?> baseMap){
|
||||||
|
baseMap.putAll((ObjectFloatMap)readField);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
field.set(object, readField);
|
||||||
|
}
|
||||||
|
}
|
||||||
}catch(IllegalAccessException ex){
|
}catch(IllegalAccessException ex){
|
||||||
throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex);
|
throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex);
|
||||||
}catch(SerializationException ex){
|
}catch(SerializationException ex){
|
||||||
|
@ -150,6 +150,8 @@ public class Planet extends UnlockableContent{
|
|||||||
public Seq<Item> hiddenItems = new Seq<>();
|
public Seq<Item> hiddenItems = new Seq<>();
|
||||||
/** The only items available on this planet, if defined. */
|
/** The only items available on this planet, if defined. */
|
||||||
public Seq<Item> itemWhitelist = new Seq<>();
|
public Seq<Item> itemWhitelist = new Seq<>();
|
||||||
|
/** If true, all content in this planet's tech tree will be assigned this planet in their shownPlanets. */
|
||||||
|
public boolean autoAssignPlanet = true;
|
||||||
/** Content (usually planet-specific) that is unlocked upon landing here. */
|
/** Content (usually planet-specific) that is unlocked upon landing here. */
|
||||||
public Seq<UnlockableContent> unlockedOnLand = new Seq<>();
|
public Seq<UnlockableContent> unlockedOnLand = new Seq<>();
|
||||||
/** Loads the mesh. Clientside only. Defaults to a boring sphere mesh. */
|
/** Loads the mesh. Clientside only. Defaults to a boring sphere mesh. */
|
||||||
@ -340,6 +342,10 @@ public class Planet extends UnlockableContent{
|
|||||||
|
|
||||||
if(techTree != null){
|
if(techTree != null){
|
||||||
techTree.addDatabaseTab(this);
|
techTree.addDatabaseTab(this);
|
||||||
|
|
||||||
|
if(autoAssignPlanet){
|
||||||
|
techTree.addPlanet(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Sector sector : sectors){
|
for(Sector sector : sectors){
|
||||||
|
@ -66,7 +66,7 @@ public class DatabaseDialog extends BaseDialog{
|
|||||||
for(var contents : allContent){
|
for(var contents : allContent){
|
||||||
for(var content : contents){
|
for(var content : contents){
|
||||||
if(content instanceof UnlockableContent u){
|
if(content instanceof UnlockableContent u){
|
||||||
all.addAll(u.databaseTabs);
|
all.addAll(u.getDatabaseTabs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ public class DatabaseDialog extends BaseDialog{
|
|||||||
ContentType type = ContentType.all[j];
|
ContentType type = ContentType.all[j];
|
||||||
|
|
||||||
Seq<UnlockableContent> array = allContent[j]
|
Seq<UnlockableContent> array = allContent[j]
|
||||||
.select(c -> c instanceof UnlockableContent u && !u.isHidden() && (tab == Planets.sun || u.allDatabaseTabs || (u.databaseTabs.isEmpty() && tab == Planets.serpulo) || u.databaseTabs.contains(tab)) &&
|
.select(c -> c instanceof UnlockableContent u && !u.isHidden() && (tab == Planets.sun || u.allDatabaseTabs || u.getDatabaseTabs().contains(tab)) &&
|
||||||
(text.isEmpty() || u.localizedName.toLowerCase().contains(text))).as();
|
(text.isEmpty() || u.localizedName.toLowerCase().contains(text))).as();
|
||||||
|
|
||||||
if(array.size == 0) continue;
|
if(array.size == 0) continue;
|
||||||
|
@ -900,7 +900,7 @@ public class Block extends UnlockableContent implements Senseable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVisibleOn(Planet planet){
|
public boolean isVisibleOn(Planet planet){
|
||||||
return !Structs.contains(requirements, i -> planet.hiddenItems.contains(i.item));
|
return !Structs.contains(requirements, i -> planet.hiddenItems.contains(i.item)) && (shownPlanets.isEmpty() || shownPlanets.contains(planet));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlaceable(){
|
public boolean isPlaceable(){
|
||||||
@ -948,7 +948,9 @@ public class Block extends UnlockableContent implements Senseable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean environmentBuildable(){
|
public boolean environmentBuildable(){
|
||||||
return (state.rules.hiddenBuildItems.isEmpty() || !Structs.contains(requirements, i -> state.rules.hiddenBuildItems.contains(i.item)));
|
return
|
||||||
|
(state.rules.hiddenBuildItems.isEmpty() || !Structs.contains(requirements, i -> state.rules.hiddenBuildItems.contains(i.item))) &&
|
||||||
|
(state.getPlanet() == null || shownPlanets.isEmpty() || shownPlanets.contains(state.getPlanet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStatic(){
|
public boolean isStatic(){
|
||||||
|
Loading…
Reference in New Issue
Block a user