mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-04-27 16:00:51 -07:00
Made game autosave when quitting
This commit is contained in:
parent
af64e4f021
commit
efd53b6180
3 changed files with 29 additions and 0 deletions
|
|
@ -37,6 +37,10 @@ public class Saves {
|
|||
}
|
||||
}
|
||||
|
||||
public SaveSlot getCurrent() {
|
||||
return current;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(!GameState.is(State.menu) && !GameState.is(State.dead) && current != null && current.isAutosave()){
|
||||
time += Timers.delta();
|
||||
|
|
|
|||
|
|
@ -2,15 +2,19 @@ package io.anuke.mindustry.ui;
|
|||
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
import io.anuke.ucore.scene.builders.build;
|
||||
import io.anuke.ucore.scene.builders.imagebutton;
|
||||
import io.anuke.ucore.scene.ui.ConfirmDialog;
|
||||
import io.anuke.ucore.scene.ui.ImageButton;
|
||||
import io.anuke.ucore.scene.ui.layout.Cell;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
public class MenuDialog extends FloatingDialog{
|
||||
private SaveDialog save = new SaveDialog();
|
||||
|
|
@ -57,6 +61,7 @@ public class MenuDialog extends FloatingDialog{
|
|||
content().row();
|
||||
content().addButton("$text.quit", () -> {
|
||||
new ConfirmDialog("$text.confirm", "$text.quit.confirm", () -> {
|
||||
runSave();
|
||||
hide();
|
||||
GameState.set(State.menu);
|
||||
}){
|
||||
|
|
@ -89,6 +94,7 @@ public class MenuDialog extends FloatingDialog{
|
|||
|
||||
new imagebutton("icon-quit", isize, () -> {
|
||||
new ConfirmDialog("$text.confirm", "$text.quit.confirm", () -> {
|
||||
runSave();
|
||||
hide();
|
||||
GameState.set(State.menu);
|
||||
}){{
|
||||
|
|
@ -106,4 +112,22 @@ public class MenuDialog extends FloatingDialog{
|
|||
build.end();
|
||||
}
|
||||
}
|
||||
|
||||
private void runSave(){
|
||||
if(Vars.control.getSaves().getCurrent() == null ||
|
||||
!Vars.control.getSaves().getCurrent().isAutosave()) return;
|
||||
|
||||
Vars.ui.showLoading("$text.saveload");
|
||||
|
||||
Timers.runTask(5f, () -> {
|
||||
Vars.ui.hideLoading();
|
||||
try{
|
||||
Vars.control.getSaves().getCurrent().save();
|
||||
}catch(Throwable e){
|
||||
e = (e.getCause() == null ? e : e.getCause());
|
||||
|
||||
Vars.ui.showError("[orange]"+ Bundles.get("text.savefail")+"\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ public class SaveDialog extends LoadDialog{
|
|||
}
|
||||
|
||||
void save(SaveSlot slot){
|
||||
|
||||
Vars.ui.showLoading("$text.saveload");
|
||||
|
||||
Timers.runTask(5f, () -> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue