Display more launch info / Store mod list in saves

This commit is contained in:
Anuken
2019-09-29 23:40:23 -04:00
parent 7fccd18910
commit 7cd220fe8c
8 changed files with 38 additions and 13 deletions

View File

@@ -109,6 +109,7 @@ public class UI implements ApplicationListener, Loadable{
ClickListener.clicked = () -> Sounds.press.play();
Colors.put("accent", Pal.accent);
Colors.put("unlaunched", Color.valueOf("8982ed"));
Colors.put("highlight", Pal.accent.cpy().lerp(Color.white, 0.3f));
Colors.put("stat", Pal.stat);
loadExtraCursors();

View File

@@ -262,6 +262,10 @@ public class Saves{
Core.settings.save();
}
public String[] getMods(){
return meta.mods;
}
public Zone getZone(){
return meta == null || meta.rules == null ? null : meta.rules.zone;
}

View File

@@ -15,6 +15,7 @@ public class SaveMeta{
public int wave;
public Rules rules;
public StringMap tags;
public String[] mods;
public SaveMeta(int version, long timestamp, long timePlayed, int build, String map, int wave, Rules rules, StringMap tags){
this.version = version;
@@ -25,5 +26,6 @@ public class SaveMeta{
this.wave = wave;
this.rules = rules;
this.tags = tags;
this.mods = JsonIO.read(String[].class, tags.get("mods", "[]"));
}
}

View File

@@ -66,6 +66,7 @@ public abstract class SaveVersion extends SaveFileReader{
"wavetime", state.wavetime,
"stats", JsonIO.write(state.stats),
"rules", JsonIO.write(state.rules),
"mods", JsonIO.write(mods.getModNames().toArray(String.class)),
"width", world.width(),
"height", world.height()
).merge(tags));
@@ -80,6 +81,7 @@ public abstract class SaveVersion extends SaveFileReader{
state.rules = JsonIO.read(Rules.class, map.get("rules", "{}"));
if(state.rules.spawns.isEmpty()) state.rules.spawns = defaultWaves.get();
lastReadBuild = map.getInt("build", -1);
String[] mods = JsonIO.read(String[].class, map.get("mods", "[]"));
Map worldmap = maps.byName(map.get("mapname", "\\\\\\"));
world.setMap(worldmap == null ? new Map(StringMap.of(

View File

@@ -118,7 +118,7 @@ public class LegacyTypeTable{
public static Supplier[] getTable(int build){
if(build == -1 || build == 81){
//return most recent one since that's probably is; not guaranteed
//return most recent one since that's probably it; not guaranteed
return build81Table;
}else if(build == 80){
return build80Table;

View File

@@ -217,6 +217,11 @@ public class Mods implements Loadable{
return loaded;
}
/** @return a list of mod names only, without versions. */
public Array<String> getModNames(){
return loaded.select(l -> !l.meta.hidden).map(l -> l.name + ":" + l.meta.version);
}
/** @return a list of mods and versions, in the format name:version. */
public Array<String> getModStrings(){
return loaded.select(l -> !l.meta.hidden).map(l -> l.name + ":" + l.meta.version);

View File

@@ -1,22 +1,21 @@
package io.anuke.mindustry.ui;
import io.anuke.arc.collection.ObjectIntMap;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.arc.graphics.*;
import io.anuke.arc.scene.ui.layout.*;
import io.anuke.mindustry.core.GameState.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.*;
import io.anuke.mindustry.type.Item.Icon;
import io.anuke.mindustry.type.ItemType;
import java.text.NumberFormat;
import java.util.Locale;
import java.text.*;
import java.util.*;
import static io.anuke.mindustry.Vars.content;
import static io.anuke.mindustry.Vars.data;
import static io.anuke.mindustry.Vars.*;
/** Displays a list of items, e.g. launched items.*/
public class ItemsDisplay extends Table{
private static final NumberFormat format = NumberFormat.getNumberInstance(Locale.getDefault());
private StringBuilder builder = new StringBuilder();
public ItemsDisplay(){
rebuild();
@@ -29,12 +28,13 @@ public class ItemsDisplay extends Table{
table(Tex.button,t -> {
t.margin(10).marginLeft(15).marginTop(15f);
t.add("$launcheditems").colspan(3).left().padBottom(5);
t.add("$launcheditems").colspan(3).left();
t.row();
t.label(() -> state.is(State.menu) ? "" : "$launchinfo").colspan(3).width(210f).wrap().padBottom(4).left();
t.row();
ObjectIntMap<Item> items = data.items();
for(Item item : content.items()){
if(item.type == ItemType.material && data.isUnlocked(item)){
t.label(() -> format.format(items.get(item, 0))).left();
t.label(() -> format(item)).left();
t.addImage(item.icon(Icon.medium)).size(8 * 3).padLeft(4).padRight(4);
t.add(item.localizedName()).color(Color.lightGray).left();
t.row();
@@ -42,4 +42,14 @@ public class ItemsDisplay extends Table{
}
});
}
private String format(Item item){
builder.setLength(0);
builder.append(ui.formatAmount(data.items().get(item, 0)));
if(!state.teams.get(player.getTeam()).cores.isEmpty() && state.teams.get(player.getTeam()).cores.first().entity != null){
builder.append(" [unlaunched]+ ");
builder.append(ui.formatAmount(state.teams.get(player.getTeam()).cores.first().entity.items.get(item)));
}
return builder.toString();
}
}