More difficulty tweaks, made sandbox work properly
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Timer;
|
||||
import com.badlogic.gdx.utils.Timer.Task;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
@@ -19,19 +17,18 @@ import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
//TODO unified save/load dialogs
|
||||
public class LoadDialog extends FloatingDialog{
|
||||
ScrollPane pane;
|
||||
|
||||
public LoadDialog(){
|
||||
|
||||
public LoadDialog() {
|
||||
this("Load Game");
|
||||
}
|
||||
|
||||
|
||||
public LoadDialog(String title) {
|
||||
super(title);
|
||||
setup();
|
||||
|
||||
|
||||
shown(() -> {
|
||||
setup();
|
||||
Timers.runTask(2f, ()-> Core.scene.setScrollFocus(pane));
|
||||
Timers.runTask(2f, () -> Core.scene.setScrollFocus(pane));
|
||||
});
|
||||
|
||||
addCloseButton();
|
||||
@@ -42,11 +39,11 @@ public class LoadDialog extends FloatingDialog{
|
||||
|
||||
content().add("Select a save slot.").padBottom(2);
|
||||
content().row();
|
||||
|
||||
|
||||
Table slots = new Table();
|
||||
pane = new ScrollPane(slots);
|
||||
pane.setFadeScrollBars(false);
|
||||
|
||||
|
||||
slots.padRight(Unit.dp.inPixels(24));
|
||||
|
||||
for(int i = 0; i < Vars.saveSlots; i++){
|
||||
@@ -55,14 +52,12 @@ public class LoadDialog extends FloatingDialog{
|
||||
TextButton button = new TextButton("[accent]Slot " + (i + 1));
|
||||
button.pad(Unit.dp.inPixels(12));
|
||||
button.getLabelCell().top().left().growX();
|
||||
|
||||
|
||||
button.row();
|
||||
|
||||
Label info = new Label("[gray]" + (!SaveIO.isSaveValid(i) ? "<empty>" : SaveIO.getMode(slot) + ", " +
|
||||
SaveIO.getMap(slot) +
|
||||
", Wave " + SaveIO.getWave(slot) + "\nLast Saved: " + SaveIO.getTimeString(i)));
|
||||
|
||||
Label info = new Label("[gray]" + (!SaveIO.isSaveValid(i) ? "<empty>" : SaveIO.getMode(slot) + ", " + SaveIO.getMap(slot) + ", Wave " + SaveIO.getWave(slot) + "\nLast Saved: " + SaveIO.getTimeString(i)));
|
||||
info.setAlignment(Align.center, Align.center);
|
||||
|
||||
|
||||
button.add(info).padBottom(3).padTop(7);
|
||||
button.row();
|
||||
//button.addImage("white", Color.GRAY)
|
||||
@@ -73,37 +68,33 @@ public class LoadDialog extends FloatingDialog{
|
||||
slots.add(button).size(404, 104).pad(4).units(Unit.dp);
|
||||
slots.row();
|
||||
}
|
||||
|
||||
|
||||
content().add(pane);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void modifyButton(TextButton button, int slot){
|
||||
button.setDisabled(!SaveIO.isSaveValid(slot));
|
||||
button.clicked(() -> {
|
||||
if(!button.isDisabled()){
|
||||
Vars.ui.showLoading();
|
||||
|
||||
Timer.schedule(new Task(){
|
||||
@Override
|
||||
public void run(){
|
||||
Vars.ui.hideLoading();
|
||||
hide();
|
||||
try{
|
||||
SaveIO.loadFromSlot(slot);
|
||||
GameState.set(State.playing);
|
||||
Vars.ui.hideMenu();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
Vars.ui.hideMenu();
|
||||
GameState.set(State.menu);
|
||||
Vars.control.reset();
|
||||
Vars.ui.showError("[orange]Save file corrupted or invalid!");
|
||||
return;
|
||||
}
|
||||
|
||||
Timers.runTask(3f, () -> {
|
||||
Vars.ui.hideLoading();
|
||||
hide();
|
||||
try{
|
||||
SaveIO.loadFromSlot(slot);
|
||||
GameState.set(State.playing);
|
||||
Vars.ui.hideMenu();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
Vars.ui.hideMenu();
|
||||
GameState.set(State.menu);
|
||||
Vars.control.reset();
|
||||
Vars.ui.showError("[orange]Save file corrupted or invalid!");
|
||||
return;
|
||||
}
|
||||
}, 3f/60f);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import com.badlogic.gdx.utils.Timer;
|
||||
import com.badlogic.gdx.utils.Timer.Task;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.ConfirmDialog;
|
||||
import io.anuke.ucore.scene.ui.TextButton;
|
||||
import io.anuke.ucore.scene.ui.layout.Cell;
|
||||
@@ -13,48 +12,44 @@ import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
//TODO unified save/load dialogs
|
||||
public class SaveDialog extends LoadDialog{
|
||||
|
||||
public SaveDialog(){
|
||||
|
||||
public SaveDialog() {
|
||||
super("Save Game");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void modifyButton(TextButton button, int slot){
|
||||
button.clicked(()->{
|
||||
button.clicked(() -> {
|
||||
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?", () -> {
|
||||
save(slot);
|
||||
}){{
|
||||
content().pad(16);
|
||||
for(Cell<?> cell : getButtonTable().getCells())
|
||||
cell.size(110, 45).pad(4).units(Unit.dp);
|
||||
}}.show();
|
||||
}){
|
||||
{
|
||||
content().pad(16);
|
||||
for(Cell<?> cell : getButtonTable().getCells())
|
||||
cell.size(110, 45).pad(4).units(Unit.dp);
|
||||
}
|
||||
}.show();
|
||||
}else{
|
||||
save(slot);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void save(int slot){
|
||||
Vars.ui.showLoading("[orange]Saving...");
|
||||
|
||||
Timer.schedule(new Task(){
|
||||
@Override
|
||||
public void run(){
|
||||
hide();
|
||||
Vars.ui.hideLoading();
|
||||
try{
|
||||
SaveIO.saveToSlot(slot);
|
||||
}catch (Throwable e){
|
||||
e = (e.getCause() == null ? e : e.getCause());
|
||||
|
||||
Vars.ui.showError("[orange]Failed to save game!\n[white]" +
|
||||
ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" +
|
||||
"at " + e.getStackTrace()[0].getFileName() + ":"+ e.getStackTrace()[0].getLineNumber());
|
||||
}
|
||||
|
||||
|
||||
Timers.runTask(5f, () -> {
|
||||
hide();
|
||||
Vars.ui.hideLoading();
|
||||
try{
|
||||
SaveIO.saveToSlot(slot);
|
||||
}catch(Throwable e){
|
||||
e = (e.getCause() == null ? e : e.getCause());
|
||||
|
||||
Vars.ui.showError("[orange]Failed to save game!\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber());
|
||||
}
|
||||
}, 5f/60f);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class BlocksFragment implements Fragment{
|
||||
image.update(()->{
|
||||
|
||||
boolean canPlace = !control.getTutorial().active() || control.getTutorial().canPlace();
|
||||
boolean has = control.hasItems(r.requirements) && canPlace;
|
||||
boolean has = (control.hasItems(r.requirements)) && canPlace;
|
||||
//image.setDisabled(!has);
|
||||
image.setChecked(player.recipe == r);
|
||||
image.setTouchable(canPlace ? Touchable.enabled : Touchable.disabled);
|
||||
|
||||
@@ -24,12 +24,14 @@ import io.anuke.ucore.scene.builders.label;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
import io.anuke.ucore.scene.ui.Image;
|
||||
import io.anuke.ucore.scene.ui.Label;
|
||||
import io.anuke.ucore.scene.ui.layout.Cell;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Profiler;
|
||||
|
||||
public class HudFragment implements Fragment{
|
||||
private Table itemtable, respawntable;
|
||||
private Cell<Table> itemcell;
|
||||
private Array<Item> tempItems = new Array<>();
|
||||
|
||||
public void build(){
|
||||
@@ -63,6 +65,8 @@ public class HudFragment implements Fragment{
|
||||
row();
|
||||
|
||||
itemtable = new table("button").end().top().left().fillX().size(-1).get();
|
||||
itemtable.setVisible(()-> control.getMode() != GameMode.sandbox);
|
||||
itemcell = get().getCell(itemtable);
|
||||
|
||||
get().setVisible(()->!GameState.is(State.menu));
|
||||
|
||||
@@ -167,6 +171,10 @@ public class HudFragment implements Fragment{
|
||||
itemtable.clear();
|
||||
itemtable.left();
|
||||
|
||||
if(control.getMode() == GameMode.sandbox){
|
||||
return;
|
||||
}
|
||||
|
||||
tempItems.clear();
|
||||
for(Item item : control.getItems().keys()){
|
||||
tempItems.add(item);
|
||||
@@ -174,8 +182,13 @@ public class HudFragment implements Fragment{
|
||||
tempItems.sort();
|
||||
|
||||
for(Item stack : tempItems){
|
||||
int amount = control.getAmount(stack);
|
||||
String formatted = Mindustry.formatter.format(amount);
|
||||
if(amount > 99999999){
|
||||
formatted = "inf";
|
||||
}
|
||||
Image image = new Image(Draw.region("icon-" + stack.name()));
|
||||
Label label = new Label("" + Mindustry.formatter.format(control.getAmount(stack)));
|
||||
Label label = new Label(formatted);
|
||||
label.setFontScale(fontscale*1.5f);
|
||||
itemtable.add(image).size(8*3).units(Unit.dp);
|
||||
itemtable.add(label).left();
|
||||
|
||||
Reference in New Issue
Block a user