Added loading dialogs for saving

This commit is contained in:
Anuken
2017-08-08 12:20:26 -04:00
parent 6ce2f0ef25
commit eabdc3d27d
10 changed files with 71 additions and 19 deletions

View File

@@ -391,39 +391,40 @@ public class UI extends SceneModule{
//menu table //menu table
new table(){{ new table(){{
float w = Unit.dp.inPixels(200);
new table("button"){{ new table("button"){{
defaults().size(Unit.dp.inPixels(220), Unit.dp.inPixels(50));
new button("Play", () -> { new button("Play", () -> {
levels.show(); levels.show();
}).width(w); });
row(); row();
new button("Settings", () -> { new button("Settings", () -> {
prefs.show(scene); prefs.show(scene);
}).width(w); });
row(); row();
if(!android){ if(!android){
new button("Controls", () -> { new button("Controls", () -> {
keys.show(scene); keys.show(scene);
}).width(w); });
row(); row();
} }
new button("About", () -> { new button("About", () -> {
about.show(scene); about.show(scene);
}).width(w); });
row(); row();
if(Gdx.app.getType() != ApplicationType.WebGL) if(Gdx.app.getType() != ApplicationType.WebGL)
new button("Exit", () -> { new button("Exit", () -> {
Gdx.app.exit(); Gdx.app.exit();
}).width(w); });
get().pad(Unit.dp.inPixels(20)); get().pad(Unit.dp.inPixels(20));
}}; }};
@@ -452,7 +453,9 @@ public class UI extends SceneModule{
loadingtable = new table("loadDim"){{ loadingtable = new table("loadDim"){{
new table("button"){{ new table("button"){{
new label("[yellow]Loading...").scale(1).pad(10); new label("[yellow]Loading..."){{
get().setName("namelabel");
}}.scale(1).pad(10);
}}.end(); }}.end();
}}.end().get(); }}.end().get();
@@ -520,7 +523,13 @@ public class UI extends SceneModule{
} }
public void showLoading(){ public void showLoading(){
showLoading("[yellow]Loading..");
}
public void showLoading(String text){
loadingtable.<Label>find("namelabel").setText(text);
loadingtable.setVisible(true); loadingtable.setVisible(true);
loadingtable.toFront();
} }
public void hideLoading(){ public void hideLoading(){

View File

@@ -53,6 +53,10 @@ public class AndroidInput extends InputAdapter{
Tile tile = selected(); Tile tile = selected();
player.breaktime += Mathf.delta(); player.breaktime += Mathf.delta();
if(player.breaktime >= tile.block().breaktime){ if(player.breaktime >= tile.block().breaktime){
if(tile.block().drops != null){
Inventory.addItem(tile.block().drops.item, tile.block().drops.amount);
}
Effects.effect("break", tile.worldx(), tile.worldy()); Effects.effect("break", tile.worldx(), tile.worldy());
Effects.shake(3f, 1f); Effects.shake(3f, 1f);
tile.setBlock(Blocks.air); tile.setBlock(Blocks.air);

View File

@@ -86,6 +86,10 @@ public class Input{
Tile tile = cursor; Tile tile = cursor;
player.breaktime += Mathf.delta(); player.breaktime += Mathf.delta();
if(player.breaktime >= tile.block().breaktime){ if(player.breaktime >= tile.block().breaktime){
if(tile.block().drops != null){
Inventory.addItem(tile.block().drops.item, tile.block().drops.amount);
}
Effects.effect("break", tile.worldx(), tile.worldy()); Effects.effect("break", tile.worldx(), tile.worldy());
Effects.shake(3f, 1f); Effects.shake(3f, 1f);
tile.setBlock(Blocks.air); tile.setBlock(Blocks.air);

View File

@@ -1,5 +1,10 @@
package io.anuke.mindustry.ui; package io.anuke.mindustry.ui;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Timer.Task;
import io.anuke.mindustry.GameState;
import io.anuke.mindustry.GameState.State;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.io.SaveIO; import io.anuke.mindustry.io.SaveIO;
import io.anuke.ucore.scene.ui.Dialog; import io.anuke.ucore.scene.ui.Dialog;
@@ -18,7 +23,7 @@ public class LoadDialog extends Dialog{
getButtonTable().addButton("Back", ()->{ getButtonTable().addButton("Back", ()->{
hide(); hide();
}).pad(8).size(180, 60); }).pad(8).size(180, 50);
} }
private void setup(){ private void setup(){
@@ -40,12 +45,21 @@ public class LoadDialog extends Dialog{
button.clicked(()->{ button.clicked(()->{
if(!button.isDisabled()){ if(!button.isDisabled()){
SaveIO.loadFromSlot(slot); Vars.ui.showLoading();
hide();
Timer.schedule(new Task(){
public void run(){
SaveIO.loadFromSlot(slot);
Vars.ui.hideLoading();
hide();
Vars.ui.hideMenu();
GameState.set(State.playing);
}
}, 2f/60f);
} }
}); });
content().add(button).size(400, 100).units(Unit.dp).pad(10); content().add(button).size(400, 90).units(Unit.dp).pad(10);
content().row(); content().row();
} }

View File

@@ -19,7 +19,7 @@ public class MenuDialog extends Dialog{
} }
void setup(){ void setup(){
content().defaults().width(200).units(Unit.dp); content().defaults().width(220).height(50).units(Unit.dp);
content().addButton("Back", ()->{ content().addButton("Back", ()->{
hide(); hide();

View File

@@ -1,5 +1,8 @@
package io.anuke.mindustry.ui; package io.anuke.mindustry.ui;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Timer.Task;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.io.SaveIO; import io.anuke.mindustry.io.SaveIO;
import io.anuke.ucore.scene.ui.ConfirmDialog; import io.anuke.ucore.scene.ui.ConfirmDialog;
@@ -20,7 +23,7 @@ public class SaveDialog extends Dialog{
getButtonTable().addButton("Back", ()->{ getButtonTable().addButton("Back", ()->{
hide(); hide();
}).pad(8).size(180, 60); }).pad(8).size(180, 50);
} }
private void setup(){ private void setup(){
@@ -36,28 +39,39 @@ public class SaveDialog extends Dialog{
button.getLabelCell().top().left().growX(); button.getLabelCell().top().left().growX();
button.row(); button.row();
button.pad(12); button.pad(12);
button.add("[gray]" + (!SaveIO.isSaveValid(i) ? "<empty>" : "Last Saved: " + SaveIO.getTimeString(i))); button.add((!SaveIO.isSaveValid(i) ? "[gray]<empty>" : "[LIGHT_GRAY]Last Saved: " + SaveIO.getTimeString(i)));
button.getLabel().setFontScale(1f); button.getLabel().setFontScale(1f);
button.clicked(()->{ button.clicked(()->{
if(SaveIO.isSaveValid(slot)){ if(SaveIO.isSaveValid(slot)){
new ConfirmDialog("Overwrite", "Are you sure you want to overwrite\nthis save slot?", ()->{ new ConfirmDialog("Overwrite", "Are you sure you want to overwrite\nthis save slot?", ()->{
SaveIO.saveToSlot(slot); save(slot);
hide();
}){{ }){{
content().pad(16); content().pad(16);
for(Cell<?> cell : getButtonTable().getCells()) for(Cell<?> cell : getButtonTable().getCells())
cell.size(110, 45).pad(4); cell.size(110, 45).pad(4);
}}.show(); }}.show();
}else{ }else{
SaveIO.saveToSlot(slot); save(slot);
hide();
} }
}); });
content().add(button).size(400, 100).units(Unit.dp).pad(10); content().add(button).size(400, 90).units(Unit.dp).pad(8);
content().row(); content().row();
} }
} }
void save(int slot){
Vars.ui.showLoading("[yellow]Saving...");
Timer.schedule(new Task(){
@Override
public void run(){
SaveIO.saveToSlot(slot);
hide();
Vars.ui.hideLoading();
}
}, 2f/60f);
}
} }

View File

@@ -8,6 +8,7 @@ import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.World; import io.anuke.mindustry.World;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.resource.Item; import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.ucore.core.Draw; import io.anuke.ucore.core.Draw;
import io.anuke.ucore.graphics.Caches; import io.anuke.ucore.graphics.Caches;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
@@ -30,6 +31,8 @@ public class Block{
public String edge = "stone"; public String edge = "stone";
//whether to have 3 variants //whether to have 3 variants
public boolean vary = true; public boolean vary = true;
//stuff that drops when broken
public ItemStack drops = null;
public Block(String name) { public Block(String name) {
blocks.add(this); blocks.add(this);

View File

@@ -1,5 +1,7 @@
package io.anuke.mindustry.world.blocks; package io.anuke.mindustry.world.blocks;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
@@ -65,12 +67,14 @@ public class Blocks{
shadow = "rockshadow"; shadow = "rockshadow";
breakable = true; breakable = true;
breaktime = 15; breaktime = 15;
drops = new ItemStack(Item.stone, 3);
}}, }},
rock2 = new Block("rock2"){{ rock2 = new Block("rock2"){{
shadow = "rock2shadow"; shadow = "rock2shadow";
breakable = true; breakable = true;
breaktime = 15; breaktime = 15;
drops = new ItemStack(Item.stone, 3);
}}, }},
dirtblock = new Block("dirtblock"){{ dirtblock = new Block("dirtblock"){{

Binary file not shown.

Binary file not shown.