Saves / Paused dialog cleanup / Zone rule save

This commit is contained in:
Anuken
2019-01-16 23:25:43 -05:00
parent 836a4eb892
commit 58e83c11f0
66 changed files with 996 additions and 965 deletions

View File

@@ -116,6 +116,12 @@ public class Control implements ApplicationListener{
//todo high scores for custom maps, as well as other statistics
Events.on(GameOverEvent.class, event -> {
if(state.rules.zone != -1){
//remove zone save on game over
if(saves.getZoneSlot() != null){
saves.getZoneSlot().delete();
}
}
Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y);
//the restart dialog can show info for any number of scenarios
Call.onGameOver(event.winner);

View File

@@ -192,6 +192,10 @@ public class World implements ApplicationListener{
return generating;
}
public boolean isZone(){
return state.rules.zone != -1;
}
public void playZone(Zone zone){
ui.loadAnd(() -> {
logic.reset();
@@ -202,6 +206,8 @@ public class World implements ApplicationListener{
core.entity.items.add(stack.item, stack.amount);
}
}
state.rules.zone = zone.id;
control.saves.zoneSave();
logic.play();
});
}

View File

@@ -24,4 +24,6 @@ public class Rules{
public float respawnTime = 60 * 4;
/**Time between waves in ticks.*/
public float waveSpacing = 60 * 60;
/**Zone ID, -1 for invalid zone.*/
public byte zone = -1;
}

View File

@@ -13,6 +13,8 @@ import io.anuke.mindustry.game.EventType.StateChangeEvent;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.io.SaveMeta;
import io.anuke.mindustry.maps.Map;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.Zone;
import java.io.IOException;
import java.text.SimpleDateFormat;
@@ -105,6 +107,16 @@ public class Saves{
return saving;
}
public void zoneSave(){
SaveSlot slot = new SaveSlot(-1);
slot.setName("zone");
saves.remove(s -> s.index == -1);
saves.add(slot);
saveMap.put(slot.index, slot);
slot.save();
saveSlots();
}
public SaveSlot addSave(String name){
SaveSlot slot = new SaveSlot(nextSlot);
nextSlot++;
@@ -129,6 +141,11 @@ public class Saves{
return slot;
}
public SaveSlot getZoneSlot(){
SaveSlot slot = getByID(-1);
return slot == null || slot.getZone() == null ? null : slot;
}
public SaveSlot getByID(int id){
return saveMap.get(id);
}
@@ -203,6 +220,10 @@ public class Saves{
Core.settings.save();
}
public Zone getZone(){
return content.getByID(ContentType.zone, meta.rules.zone);
}
public int getBuild(){
return meta.build;
}
@@ -211,10 +232,6 @@ public class Saves{
return meta.wave;
}
public Difficulty getDifficulty(){
return meta.difficulty;
}
public boolean isAutosave(){
return Core.settings.getBool("save-" + index + "-autosave", true);
}

View File

@@ -8,10 +8,8 @@ import io.anuke.arc.util.Pack;
import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.entities.traits.SaveTrait;
import io.anuke.mindustry.entities.traits.TypeTrait;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.MappableContent;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.gen.Serialization;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.BlockPart;
@@ -33,11 +31,11 @@ public abstract class SaveFileVersion{
long time = stream.readLong();
long playtime = stream.readLong();
int build = stream.readInt();
byte mode = stream.readByte();
Rules rules = Serialization.readRules(stream);
String map = stream.readUTF();
int wave = stream.readInt();
byte difficulty = stream.readByte();
return new SaveMeta(version, time, playtime, build, mode, map, wave, Difficulty.values()[difficulty]);
return new SaveMeta(version, time, playtime, build, map, wave, rules);
}
public void writeMap(DataOutputStream stream) throws IOException{

View File

@@ -1,6 +1,6 @@
package io.anuke.mindustry.io;
import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.Rules;
import io.anuke.mindustry.maps.Map;
import static io.anuke.mindustry.Vars.world;
@@ -12,15 +12,15 @@ public class SaveMeta{
public long timePlayed;
public Map map;
public int wave;
public Difficulty difficulty;
public Rules rules;
public SaveMeta(int version, long timestamp, long timePlayed, int build, int mode, String map, int wave, Difficulty difficulty){
public SaveMeta(int version, long timestamp, long timePlayed, int build, String map, int wave, Rules rules){
this.version = version;
this.build = build;
this.timestamp = timestamp;
this.timePlayed = timePlayed;
this.map = world.maps.getByName(map);
this.wave = wave;
this.difficulty = difficulty;
this.rules = rules;
}
}

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.ui.dialogs;
import io.anuke.arc.Core;
import io.anuke.arc.collection.ObjectIntMap;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.mindustry.Vars;
@@ -39,24 +40,30 @@ public class DeployDialog extends FloatingDialog{
}}, new Table(){{
for(Zone zone : Vars.content.zones()){
if(data.isUnlocked(zone)){
table(t -> {
t.addButton(zone.localizedName(), () -> {
data.removeItems(zone.deployCost);
hide();
world.playZone(zone);
}).size(150f)/*.disabled(b -> !data.hasItems(zone.deployCost))*/;
t.row();
t.table(req -> {
req.left();
for(ItemStack stack : zone.deployCost){
req.addImage(stack.item.region).size(8*3);
req.add(stack.amount + "").left();
}
}).pad(3).growX();
}).pad(3);
if(control.saves.getZoneSlot() == null){
for(Zone zone : Vars.content.zones()){
if(data.isUnlocked(zone)){
table(t -> {
t.addButton(zone.localizedName(), () -> {
data.removeItems(zone.deployCost);
hide();
world.playZone(zone);
}).size(150f).disabled(b -> !data.hasItems(zone.deployCost));
t.row();
t.table(req -> {
req.left();
for(ItemStack stack : zone.deployCost){
req.addImage(stack.item.region).size(8 * 3);
req.add(stack.amount + "").left();
}
}).pad(3).growX();
}).pad(3);
}
}
}else{
addButton(Core.bundle.format("resume", control.saves.getZoneSlot().getZone().localizedName()), () -> control.saves.getZoneSlot().load())
.size(200f);
}
}}).grow();
}

View File

@@ -116,8 +116,6 @@ public class LoadDialog extends FloatingDialog{
button.row();
button.add(Core.bundle.format("save.wave", color + slot.getWave()));
button.row();
button.add(Core.bundle.format("save.difficulty", color + slot.getDifficulty()));
button.row();
button.label(() -> Core.bundle.format("save.autosave", color + Core.bundle.get(slot.isAutosave() ? "on" : "off")));
button.row();
button.label(() -> Core.bundle.format("save.playtime", color + slot.getPlayTime()));

View File

@@ -2,8 +2,6 @@ package io.anuke.mindustry.ui.dialogs;
import io.anuke.arc.Core;
import io.anuke.arc.input.KeyCode;
import io.anuke.arc.scene.style.Drawable;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.net.Net;
@@ -12,12 +10,10 @@ import static io.anuke.mindustry.Vars.*;
public class PausedDialog extends FloatingDialog{
private SaveDialog save = new SaveDialog();
private LoadDialog load = new LoadDialog();
private Table missionTable;
public PausedDialog(){
super("$menu");
shouldPause = true;
setup();
shown(this::rebuild);
@@ -29,20 +25,14 @@ public class PausedDialog extends FloatingDialog{
}
void rebuild(){
missionTable.clear();
missionTable.background((Drawable) null);
}
cont.clear();
void setup(){
update(() -> {
if(state.is(State.menu) && isShown()){
hide();
}
});
cont.table(t -> missionTable = t).colspan(mobile ? 3 : 2);
cont.row();
if(!mobile){
float dw = 210f;
cont.defaults().width(dw).height(50).pad(5f);
@@ -53,9 +43,11 @@ public class PausedDialog extends FloatingDialog{
cont.addButton("$unlocks", ui.unlocks::show);
cont.addButton("$settings", ui.settings::show);
cont.row();
cont.addButton("$savegame", save::show);
cont.addButton("$loadgame", load::show).disabled(b -> Net.active());
if(!world.isZone()){
cont.row();
cont.addButton("$savegame", save::show);
cont.addButton("$loadgame", load::show).disabled(b -> Net.active());
}
cont.row();
@@ -77,11 +69,15 @@ public class PausedDialog extends FloatingDialog{
cont.addRowImageTextButton("$back", "icon-play-2", isize, this::hide);
cont.addRowImageTextButton("$settings", "icon-tools", isize, ui.settings::show);
cont.addRowImageTextButton("$save", "icon-save", isize, save::show);
cont.row();
if(!world.isZone()){
cont.addRowImageTextButton("$save", "icon-save", isize, save::show);
cont.row();
cont.addRowImageTextButton("$load", "icon-load", isize, load::show).disabled(b -> Net.active());
}
cont.addRowImageTextButton("$load", "icon-load", isize, load::show).disabled(b -> Net.active());
cont.addRowImageTextButton("$hostserver.mobile", "icon-host", isize, ui.host::show).disabled(b -> Net.active());
cont.addRowImageTextButton("$quit", "icon-quit", isize, () -> {
ui.showConfirm("$confirm", "$quit.confirm", () -> {