mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-09 20:29:06 +07:00
Allow research dialog to be viewed on clients
This commit is contained in:
parent
5d4ece62d0
commit
e262bb8254
@ -676,7 +676,6 @@ requirement.capture = Capture {0}
|
||||
requirement.onplanet = Control Sector On {0}
|
||||
requirement.onsector = Land On Sector: {0}
|
||||
launch.text = Launch
|
||||
research.multiplayer = Only the host can research items.
|
||||
map.multiplayer = Only the host can view sectors.
|
||||
uncover = Uncover
|
||||
configure = Configure Loadout
|
||||
|
@ -27,6 +27,7 @@ import static mindustry.Vars.*;
|
||||
public class ContentLoader{
|
||||
private ObjectMap<String, MappableContent>[] contentNameMap = new ObjectMap[ContentType.all.length];
|
||||
private Seq<Content>[] contentMap = new Seq[ContentType.all.length];
|
||||
private ObjectMap<String, MappableContent> nameMap = new ObjectMap<>();
|
||||
private MappableContent[][] temporaryMapper;
|
||||
private @Nullable LoadedMod currentMod;
|
||||
private @Nullable Content lastAdded;
|
||||
@ -188,12 +189,18 @@ public class ContentLoader{
|
||||
}
|
||||
}
|
||||
contentNameMap[content.getContentType().ordinal()].put(content.name, content);
|
||||
nameMap.put(content.name, content);
|
||||
}
|
||||
|
||||
public void setTemporaryMapper(MappableContent[][] temporaryMapper){
|
||||
this.temporaryMapper = temporaryMapper;
|
||||
}
|
||||
|
||||
/** @return the last registered content with the specified name. Note that the content loader makes no attempt to resolve name conflicts. This method can be unreliable. */
|
||||
public @Nullable MappableContent byName(String name){
|
||||
return nameMap.get(name);
|
||||
}
|
||||
|
||||
public Seq<Content>[] getContentMap(){
|
||||
return contentMap;
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ public class Logic implements ApplicationListener{
|
||||
public static void researched(Content content){
|
||||
if(!(content instanceof UnlockableContent u)) return;
|
||||
|
||||
boolean was = u.unlockedNow();
|
||||
boolean was = u.unlockedNowHost();
|
||||
state.rules.researched.add(u);
|
||||
|
||||
if(!was){
|
||||
|
@ -19,14 +19,14 @@ public class Objectives{
|
||||
|
||||
@Override
|
||||
public boolean complete(){
|
||||
return content.unlocked();
|
||||
return content.unlockedHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String display(){
|
||||
return Core.bundle.format("requirement.research",
|
||||
//TODO broken for multi tech nodes.
|
||||
(content.techNode == null || content.techNode.parent == null || content.techNode.parent.content.unlocked()) ?
|
||||
(content.techNode == null || content.techNode.parent == null || content.techNode.parent.content.unlockedHost()) ?
|
||||
(content.emoji() + " " + content.localizedName) : "???");
|
||||
}
|
||||
}
|
||||
@ -42,13 +42,13 @@ public class Objectives{
|
||||
|
||||
@Override
|
||||
public boolean complete(){
|
||||
return content.unlocked();
|
||||
return content.unlockedHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String display(){
|
||||
return Core.bundle.format("requirement.produce",
|
||||
content.unlocked() ? (content.emoji() + " " + content.localizedName) : "???");
|
||||
content.unlockedHost() ? (content.emoji() + " " + content.localizedName) : "???");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,15 +261,8 @@ public class JsonIO{
|
||||
public UnlockableContent read(Json json, JsonValue jsonData, Class type){
|
||||
if(jsonData.isNull()) return null;
|
||||
String str = jsonData.asString();
|
||||
Item item = Vars.content.item(str);
|
||||
Liquid liquid = Vars.content.liquid(str);
|
||||
Block block = Vars.content.block(str);
|
||||
UnitType unit = Vars.content.unit(str);
|
||||
return
|
||||
item != null ? item :
|
||||
liquid != null ? liquid :
|
||||
block != null ? block :
|
||||
unit;
|
||||
var map = Vars.content.byName(str);
|
||||
return map instanceof UnlockableContent u ? u : null;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -47,10 +47,30 @@ public class ResearchDialog extends BaseDialog{
|
||||
public ItemSeq items;
|
||||
|
||||
private boolean showTechSelect;
|
||||
private boolean needsRebuild;
|
||||
|
||||
public ResearchDialog(){
|
||||
super("");
|
||||
|
||||
Events.on(ResetEvent.class, e -> {
|
||||
hide();
|
||||
});
|
||||
|
||||
Events.on(UnlockEvent.class, e -> {
|
||||
if(net.client() && !needsRebuild){
|
||||
needsRebuild = true;
|
||||
Core.app.post(() -> {
|
||||
needsRebuild = false;
|
||||
|
||||
checkNodes(root);
|
||||
view.hoverNode = null;
|
||||
treeLayout();
|
||||
view.rebuild();
|
||||
Core.scene.act();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
titleTable.remove();
|
||||
titleTable.clear();
|
||||
titleTable.top();
|
||||
@ -67,7 +87,7 @@ public class ResearchDialog extends BaseDialog{
|
||||
t.table(Tex.button, in -> {
|
||||
in.defaults().width(300f).height(60f);
|
||||
for(TechNode node : TechTree.roots){
|
||||
if(node.requiresUnlock && !node.content.unlocked() && node != getPrefRoot()) continue;
|
||||
if(node.requiresUnlock && !node.content.unlockedHost() && node != getPrefRoot()) continue;
|
||||
|
||||
//TODO toggle
|
||||
in.button(node.localizedName(), node.icon(), Styles.flatTogglet, iconMed, () -> {
|
||||
@ -84,10 +104,11 @@ public class ResearchDialog extends BaseDialog{
|
||||
|
||||
addCloseButton();
|
||||
}}.show();
|
||||
}).visible(() -> showTechSelect = TechTree.roots.count(node -> !(node.requiresUnlock && !node.content.unlocked())) > 1).minWidth(300f);
|
||||
}).visible(() -> showTechSelect = TechTree.roots.count(node -> !(node.requiresUnlock && !node.content.unlockedHost())) > 1).minWidth(300f);
|
||||
|
||||
margin(0f).marginBottom(8);
|
||||
cont.stack(titleTable, view = new View(), itemDisplay = new ItemsDisplay()).grow();
|
||||
itemDisplay.visible(() -> !net.client());
|
||||
|
||||
titleTable.toFront();
|
||||
|
||||
@ -177,15 +198,6 @@ public class ResearchDialog extends BaseDialog{
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog show(){
|
||||
if(net.client()){
|
||||
ui.showInfo("@research.multiplayer");
|
||||
return this;
|
||||
}
|
||||
return show(Core.scene);
|
||||
}
|
||||
|
||||
void checkMargin(){
|
||||
if(Core.graphics.isPortrait() && showTechSelect){
|
||||
itemDisplay.marginTop(60f);
|
||||
@ -361,11 +373,12 @@ public class ResearchDialog extends BaseDialog{
|
||||
}
|
||||
|
||||
boolean selectable(TechNode node){
|
||||
return node.content.unlocked() || !node.objectives.contains(i -> !i.complete());
|
||||
//there's a desync here as far as sectors go, since the client doesn't know about that, but I'm not too concerned
|
||||
return node.content.unlockedHost() || !node.objectives.contains(i -> !i.complete());
|
||||
}
|
||||
|
||||
boolean locked(TechNode node){
|
||||
return node.content.locked();
|
||||
return !node.content.unlockedHost();
|
||||
}
|
||||
|
||||
class LayoutNode extends TreeNode<LayoutNode>{
|
||||
@ -418,6 +431,7 @@ public class ResearchDialog extends BaseDialog{
|
||||
button.resizeImage(32f);
|
||||
button.getImage().setScaling(Scaling.fit);
|
||||
button.visible(() -> node.visible);
|
||||
if(!net.client()){
|
||||
button.clicked(() -> {
|
||||
if(moved) return;
|
||||
|
||||
@ -443,6 +457,8 @@ public class ResearchDialog extends BaseDialog{
|
||||
spend(node.node);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
button.hovered(() -> {
|
||||
if(!mobile && hoverNode != button && node.visible){
|
||||
hoverNode = button;
|
||||
@ -459,6 +475,7 @@ public class ResearchDialog extends BaseDialog{
|
||||
button.userObject = node.node;
|
||||
button.setSize(nodeSize);
|
||||
button.update(() -> {
|
||||
button.setDisabled(net.client() && !mobile);
|
||||
float offset = (Core.graphics.getHeight() % 2) / 2f;
|
||||
button.setPosition(node.x + panX + width / 2f, node.y + panY + height / 2f + offset, Align.center);
|
||||
button.getStyle().up = !locked(node.node) ? Tex.buttonOver : !selectable(node.node) || !canSpend(node.node) ? Tex.buttonRed : Tex.button;
|
||||
@ -498,7 +515,7 @@ public class ResearchDialog extends BaseDialog{
|
||||
}
|
||||
|
||||
boolean canSpend(TechNode node){
|
||||
if(!selectable(node)) return false;
|
||||
if(!selectable(node) || net.client()) return false;
|
||||
|
||||
if(node.requirements.length == 0) return true;
|
||||
|
||||
@ -514,6 +531,8 @@ public class ResearchDialog extends BaseDialog{
|
||||
}
|
||||
|
||||
void spend(TechNode node){
|
||||
if(net.client()) return;
|
||||
|
||||
boolean complete = true;
|
||||
|
||||
boolean[] shine = new boolean[node.requirements.length];
|
||||
@ -611,8 +630,11 @@ public class ResearchDialog extends BaseDialog{
|
||||
desc.left().defaults().left();
|
||||
desc.add(selectable ? node.content.localizedName : "[accent]???");
|
||||
desc.row();
|
||||
if(locked(node) || debugShowRequirements){
|
||||
if(locked(node) || (debugShowRequirements && !net.client())){
|
||||
|
||||
if(net.client()){
|
||||
desc.add("@locked").color(Pal.remove);
|
||||
}else{
|
||||
desc.table(t -> {
|
||||
t.left();
|
||||
if(selectable){
|
||||
@ -685,12 +707,13 @@ public class ResearchDialog extends BaseDialog{
|
||||
t.row();
|
||||
}
|
||||
});
|
||||
}
|
||||
}else{
|
||||
desc.add("@completed");
|
||||
}
|
||||
}).pad(9);
|
||||
|
||||
if(mobile && locked(node)){
|
||||
if(mobile && locked(node) && !net.client()){
|
||||
b.row();
|
||||
b.button("@research", Icon.ok, new TextButtonStyle(){{
|
||||
disabled = Tex.button;
|
||||
|
Loading…
Reference in New Issue
Block a user