mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-05 07:47:48 +07:00
Finished saving dialogs
This commit is contained in:
@ -94,6 +94,14 @@ public class SaveIO{
|
||||
put(enemyIDs.get(value), value);
|
||||
}};
|
||||
|
||||
public static void saveToSlot(int slot){
|
||||
write(fileFor(slot));
|
||||
}
|
||||
|
||||
public static void loadFromSlot(int slot){
|
||||
load(fileFor(slot));
|
||||
}
|
||||
|
||||
public static boolean isSaveValid(int slot){
|
||||
try(DataInputStream stream = new DataInputStream(fileFor(slot).read())){
|
||||
return stream.readInt() == fileVersionID;
|
||||
|
53
core/src/io/anuke/mindustry/ui/LoadDialog.java
Normal file
53
core/src/io/anuke/mindustry/ui/LoadDialog.java
Normal file
@ -0,0 +1,53 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.ucore.scene.ui.Dialog;
|
||||
import io.anuke.ucore.scene.ui.TextButton;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class LoadDialog extends Dialog{
|
||||
|
||||
public LoadDialog() {
|
||||
super("Load Game");
|
||||
setup();
|
||||
|
||||
shown(()->{
|
||||
setup();
|
||||
});
|
||||
|
||||
getButtonTable().addButton("Back", ()->{
|
||||
hide();
|
||||
}).pad(8).size(180, 60);
|
||||
}
|
||||
|
||||
private void setup(){
|
||||
content().clear();
|
||||
|
||||
content().add("Select a save slot.").padBottom(4);
|
||||
content().row();
|
||||
|
||||
for(int i = 0; i < Vars.saveSlots; i ++){
|
||||
final int slot = i;
|
||||
|
||||
TextButton button = new TextButton("[yellow]Slot " + i);
|
||||
button.getLabelCell().top().left().growX();
|
||||
button.row();
|
||||
button.pad(12);
|
||||
button.add("[gray]" + (!SaveIO.isSaveValid(i) ? "<empty>" : "Last Saved: " + SaveIO.getTimeString(i)));
|
||||
button.getLabel().setFontScale(1f);
|
||||
button.setDisabled(!SaveIO.isSaveValid(i) );
|
||||
|
||||
button.clicked(()->{
|
||||
if(!button.isDisabled()){
|
||||
SaveIO.loadFromSlot(slot);
|
||||
hide();
|
||||
}
|
||||
});
|
||||
|
||||
content().add(button).size(400, 100).units(Unit.dp).pad(10);
|
||||
content().row();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class MenuDialog extends Dialog{
|
||||
private SaveDialog save = new SaveDialog();
|
||||
private LoadDialog load = new LoadDialog();
|
||||
|
||||
public MenuDialog(){
|
||||
super("Paused", "dialog");
|
||||
@ -44,7 +45,7 @@ public class MenuDialog extends Dialog{
|
||||
|
||||
content().row();
|
||||
content().addButton("Load Game", ()->{
|
||||
|
||||
load.show();
|
||||
});
|
||||
|
||||
content().row();
|
||||
|
@ -2,8 +2,10 @@ package io.anuke.mindustry.ui;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.ucore.scene.ui.ConfirmDialog;
|
||||
import io.anuke.ucore.scene.ui.Dialog;
|
||||
import io.anuke.ucore.scene.ui.TextButton;
|
||||
import io.anuke.ucore.scene.ui.layout.Cell;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class SaveDialog extends Dialog{
|
||||
@ -11,6 +13,14 @@ public class SaveDialog extends Dialog{
|
||||
public SaveDialog() {
|
||||
super("Save Game");
|
||||
setup();
|
||||
|
||||
shown(()->{
|
||||
setup();
|
||||
});
|
||||
|
||||
getButtonTable().addButton("Back", ()->{
|
||||
hide();
|
||||
}).pad(8).size(180, 60);
|
||||
}
|
||||
|
||||
private void setup(){
|
||||
@ -20,6 +30,8 @@ public class SaveDialog extends Dialog{
|
||||
content().row();
|
||||
|
||||
for(int i = 0; i < Vars.saveSlots; i ++){
|
||||
final int slot = i;
|
||||
|
||||
TextButton button = new TextButton("[yellow]Slot " + i);
|
||||
button.getLabelCell().top().left().growX();
|
||||
button.row();
|
||||
@ -28,7 +40,19 @@ public class SaveDialog extends Dialog{
|
||||
button.getLabel().setFontScale(1f);
|
||||
|
||||
button.clicked(()->{
|
||||
|
||||
if(SaveIO.isSaveValid(slot)){
|
||||
new ConfirmDialog("Overwrite", "Are you sure you want to overwrite\nthis save slot?", ()->{
|
||||
SaveIO.saveToSlot(slot);
|
||||
hide();
|
||||
}){{
|
||||
content().pad(16);
|
||||
for(Cell<?> cell : getButtonTable().getCells())
|
||||
cell.size(110, 45).pad(4);
|
||||
}}.show();
|
||||
}else{
|
||||
SaveIO.saveToSlot(slot);
|
||||
hide();
|
||||
}
|
||||
});
|
||||
|
||||
content().add(button).size(400, 100).units(Unit.dp).pad(10);
|
||||
|
5
core/src/io/anuke/ucore/function/SegmentConsumer.java
Normal file
5
core/src/io/anuke/ucore/function/SegmentConsumer.java
Normal file
@ -0,0 +1,5 @@
|
||||
package io.anuke.ucore.function;
|
||||
|
||||
public interface SegmentConsumer{
|
||||
public void accept(int x, int y, int x2, int y2);
|
||||
}
|
BIN
desktop/mindustry-saves/0.mins
Normal file
BIN
desktop/mindustry-saves/0.mins
Normal file
Binary file not shown.
Reference in New Issue
Block a user