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

@@ -33,6 +33,7 @@ stat.delivered = Resources Launched:
stat.rank = Final Rank: [accent]{0} stat.rank = Final Rank: [accent]{0}
launcheditems = [accent]Launched Items launcheditems = [accent]Launched Items
launchinfo = [unlaunched][[LAUNCH] your core to obtain the items indicated in blue.
map.delete = Are you sure you want to delete the map "[accent]{0}[]"? map.delete = Are you sure you want to delete the map "[accent]{0}[]"?
level.highscore = High Score: [accent]{0} level.highscore = High Score: [accent]{0}
level.select = Level Select level.select = Level Select

View File

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

View File

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

View File

@@ -15,6 +15,7 @@ public class SaveMeta{
public int wave; public int wave;
public Rules rules; public Rules rules;
public StringMap tags; public StringMap tags;
public String[] mods;
public SaveMeta(int version, long timestamp, long timePlayed, int build, String map, int wave, Rules rules, StringMap tags){ public SaveMeta(int version, long timestamp, long timePlayed, int build, String map, int wave, Rules rules, StringMap tags){
this.version = version; this.version = version;
@@ -25,5 +26,6 @@ public class SaveMeta{
this.wave = wave; this.wave = wave;
this.rules = rules; this.rules = rules;
this.tags = tags; 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, "wavetime", state.wavetime,
"stats", JsonIO.write(state.stats), "stats", JsonIO.write(state.stats),
"rules", JsonIO.write(state.rules), "rules", JsonIO.write(state.rules),
"mods", JsonIO.write(mods.getModNames().toArray(String.class)),
"width", world.width(), "width", world.width(),
"height", world.height() "height", world.height()
).merge(tags)); ).merge(tags));
@@ -80,6 +81,7 @@ public abstract class SaveVersion extends SaveFileReader{
state.rules = JsonIO.read(Rules.class, map.get("rules", "{}")); state.rules = JsonIO.read(Rules.class, map.get("rules", "{}"));
if(state.rules.spawns.isEmpty()) state.rules.spawns = defaultWaves.get(); if(state.rules.spawns.isEmpty()) state.rules.spawns = defaultWaves.get();
lastReadBuild = map.getInt("build", -1); lastReadBuild = map.getInt("build", -1);
String[] mods = JsonIO.read(String[].class, map.get("mods", "[]"));
Map worldmap = maps.byName(map.get("mapname", "\\\\\\")); Map worldmap = maps.byName(map.get("mapname", "\\\\\\"));
world.setMap(worldmap == null ? new Map(StringMap.of( world.setMap(worldmap == null ? new Map(StringMap.of(

View File

@@ -118,7 +118,7 @@ public class LegacyTypeTable{
public static Supplier[] getTable(int build){ public static Supplier[] getTable(int build){
if(build == -1 || build == 81){ 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; return build81Table;
}else if(build == 80){ }else if(build == 80){
return build80Table; return build80Table;

View File

@@ -217,6 +217,11 @@ public class Mods implements Loadable{
return loaded; 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. */ /** @return a list of mods and versions, in the format name:version. */
public Array<String> getModStrings(){ public Array<String> getModStrings(){
return loaded.select(l -> !l.meta.hidden).map(l -> l.name + ":" + l.meta.version); 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; package io.anuke.mindustry.ui;
import io.anuke.arc.collection.ObjectIntMap; import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.Color; import io.anuke.arc.scene.ui.layout.*;
import io.anuke.arc.scene.ui.layout.Table; import io.anuke.mindustry.core.GameState.*;
import io.anuke.mindustry.gen.*; 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.Item.Icon;
import io.anuke.mindustry.type.ItemType;
import java.text.NumberFormat; import java.text.*;
import java.util.Locale; import java.util.*;
import static io.anuke.mindustry.Vars.content; import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.data;
/** Displays a list of items, e.g. launched items.*/ /** Displays a list of items, e.g. launched items.*/
public class ItemsDisplay extends Table{ public class ItemsDisplay extends Table{
private static final NumberFormat format = NumberFormat.getNumberInstance(Locale.getDefault()); private static final NumberFormat format = NumberFormat.getNumberInstance(Locale.getDefault());
private StringBuilder builder = new StringBuilder();
public ItemsDisplay(){ public ItemsDisplay(){
rebuild(); rebuild();
@@ -29,12 +28,13 @@ public class ItemsDisplay extends Table{
table(Tex.button,t -> { table(Tex.button,t -> {
t.margin(10).marginLeft(15).marginTop(15f); 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(); t.row();
ObjectIntMap<Item> items = data.items();
for(Item item : content.items()){ for(Item item : content.items()){
if(item.type == ItemType.material && data.isUnlocked(item)){ 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.addImage(item.icon(Icon.medium)).size(8 * 3).padLeft(4).padRight(4);
t.add(item.localizedName()).color(Color.lightGray).left(); t.add(item.localizedName()).color(Color.lightGray).left();
t.row(); 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();
}
} }