Formatting
This commit is contained in:
@@ -10,34 +10,35 @@ import io.anuke.ucore.scene.ui.Image;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class BorderImage extends Image{
|
||||
private float thickness = 3f;
|
||||
|
||||
public BorderImage(){}
|
||||
|
||||
public BorderImage(Texture texture){
|
||||
super(texture);
|
||||
}
|
||||
|
||||
public BorderImage(Texture texture, float thick){
|
||||
super(texture);
|
||||
thickness = thick;
|
||||
}
|
||||
private float thickness = 3f;
|
||||
|
||||
public BorderImage(TextureRegion region, float thick){
|
||||
super(region);
|
||||
thickness = thick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float alpha){
|
||||
super.draw(batch, alpha);
|
||||
|
||||
float scaleX = getScaleX();
|
||||
float scaleY = getScaleY();
|
||||
|
||||
Draw.color(Palette.accent);
|
||||
Lines.stroke(Unit.dp.scl(thickness));
|
||||
Lines.rect(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
|
||||
Draw.reset();
|
||||
}
|
||||
public BorderImage(){
|
||||
}
|
||||
|
||||
public BorderImage(Texture texture){
|
||||
super(texture);
|
||||
}
|
||||
|
||||
public BorderImage(Texture texture, float thick){
|
||||
super(texture);
|
||||
thickness = thick;
|
||||
}
|
||||
|
||||
public BorderImage(TextureRegion region, float thick){
|
||||
super(region);
|
||||
thickness = thick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float alpha){
|
||||
super.draw(batch, alpha);
|
||||
|
||||
float scaleX = getScaleX();
|
||||
float scaleY = getScaleY();
|
||||
|
||||
Draw.color(Palette.accent);
|
||||
Lines.stroke(Unit.dp.scl(thickness));
|
||||
Lines.rect(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,16 +18,16 @@ import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
public class ContentDisplay {
|
||||
public class ContentDisplay{
|
||||
|
||||
public static void displayRecipe(Table table, Recipe recipe){
|
||||
Block block = recipe.result;
|
||||
|
||||
table.table(title -> {
|
||||
int size = 8*6;
|
||||
int size = 8 * 6;
|
||||
|
||||
if(block instanceof Turret){
|
||||
size = (8 * block.size + 2) * (7 - block.size*2);
|
||||
size = (8 * block.size + 2) * (7 - block.size * 2);
|
||||
}
|
||||
|
||||
title.addImage(Draw.region("block-icon-" + block.name)).size(size);
|
||||
@@ -58,7 +58,7 @@ public class ContentDisplay {
|
||||
table.add("$text.category." + cat.name()).color(Palette.accent).fillX();
|
||||
table.row();
|
||||
|
||||
for (BlockStat stat : map.keys()){
|
||||
for(BlockStat stat : map.keys()){
|
||||
table.table(inset -> {
|
||||
inset.left();
|
||||
inset.add("[LIGHT_GRAY]" + stat.localized() + ":[] ");
|
||||
@@ -92,13 +92,13 @@ public class ContentDisplay {
|
||||
|
||||
table.left().defaults().fillX();
|
||||
|
||||
table.add(Bundles.format("text.item.explosiveness", (int)(item.explosiveness * 100)));
|
||||
table.add(Bundles.format("text.item.explosiveness", (int) (item.explosiveness * 100)));
|
||||
table.row();
|
||||
table.add(Bundles.format("text.item.flammability", (int)(item.flammability * 100)));
|
||||
table.add(Bundles.format("text.item.flammability", (int) (item.flammability * 100)));
|
||||
table.row();
|
||||
table.add(Bundles.format("text.item.radioactivity", (int)(item.radioactivity * 100)));
|
||||
table.add(Bundles.format("text.item.radioactivity", (int) (item.radioactivity * 100)));
|
||||
table.row();
|
||||
table.add(Bundles.format("text.item.fluxiness", (int)(item.fluxiness * 100)));
|
||||
table.add(Bundles.format("text.item.fluxiness", (int) (item.fluxiness * 100)));
|
||||
table.row();
|
||||
table.add(Bundles.format("text.item.hardness", item.hardness));
|
||||
table.row();
|
||||
@@ -127,15 +127,15 @@ public class ContentDisplay {
|
||||
|
||||
table.left().defaults().fillX();
|
||||
|
||||
table.add(Bundles.format("text.item.explosiveness", (int)(liquid.explosiveness * 100)));
|
||||
table.add(Bundles.format("text.item.explosiveness", (int) (liquid.explosiveness * 100)));
|
||||
table.row();
|
||||
table.add(Bundles.format("text.item.flammability", (int)(liquid.flammability * 100)));
|
||||
table.add(Bundles.format("text.item.flammability", (int) (liquid.flammability * 100)));
|
||||
table.row();
|
||||
table.add(Bundles.format("text.liquid.heatcapacity", (int)(liquid.heatCapacity * 100)));
|
||||
table.add(Bundles.format("text.liquid.heatcapacity", (int) (liquid.heatCapacity * 100)));
|
||||
table.row();
|
||||
table.add(Bundles.format("text.liquid.temperature", (int)(liquid.temperature * 100)));
|
||||
table.add(Bundles.format("text.liquid.temperature", (int) (liquid.temperature * 100)));
|
||||
table.row();
|
||||
table.add(Bundles.format("text.liquid.viscosity", (int)(liquid.viscosity * 100)));
|
||||
table.add(Bundles.format("text.liquid.viscosity", (int) (liquid.viscosity * 100)));
|
||||
table.row();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,41 +2,40 @@ package io.anuke.mindustry.ui;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
|
||||
public class GridImage extends Element{
|
||||
private int imageWidth, imageHeight;
|
||||
|
||||
public GridImage(int w, int h){
|
||||
this.imageWidth = w;
|
||||
this.imageHeight = h;
|
||||
}
|
||||
private int imageWidth, imageHeight;
|
||||
|
||||
public void draw(Batch batch, float alpha){
|
||||
TextureRegion blank = Draw.region("white");
|
||||
|
||||
float xspace = (getWidth() / imageWidth);
|
||||
float yspace = (getHeight() / imageHeight);
|
||||
float s = 1f;
|
||||
public GridImage(int w, int h){
|
||||
this.imageWidth = w;
|
||||
this.imageHeight = h;
|
||||
}
|
||||
|
||||
int minspace = 10;
|
||||
public void draw(Batch batch, float alpha){
|
||||
TextureRegion blank = Draw.region("white");
|
||||
|
||||
int jumpx = (int)(Math.max(minspace, xspace) / xspace);
|
||||
int jumpy = (int)(Math.max(minspace, yspace)/ yspace);
|
||||
|
||||
for(int x = 0; x <= imageWidth; x += jumpx){
|
||||
batch.draw(blank, (int)(getX() + xspace * x - s), getY() - s, 2, getHeight()+ (x == imageWidth ? 1: 0));
|
||||
}
|
||||
|
||||
for(int y = 0; y <= imageHeight; y += jumpy){
|
||||
batch.draw(blank, getX() - s, (int)(getY() + y * yspace - s), getWidth(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
public void setImageSize(int w, int h){
|
||||
this.imageWidth = w;
|
||||
this.imageHeight = h;
|
||||
}
|
||||
float xspace = (getWidth() / imageWidth);
|
||||
float yspace = (getHeight() / imageHeight);
|
||||
float s = 1f;
|
||||
|
||||
int minspace = 10;
|
||||
|
||||
int jumpx = (int) (Math.max(minspace, xspace) / xspace);
|
||||
int jumpy = (int) (Math.max(minspace, yspace) / yspace);
|
||||
|
||||
for(int x = 0; x <= imageWidth; x += jumpx){
|
||||
batch.draw(blank, (int) (getX() + xspace * x - s), getY() - s, 2, getHeight() + (x == imageWidth ? 1 : 0));
|
||||
}
|
||||
|
||||
for(int y = 0; y <= imageHeight; y += jumpy){
|
||||
batch.draw(blank, getX() - s, (int) (getY() + y * yspace - s), getWidth(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
public void setImageSize(int w, int h){
|
||||
this.imageWidth = w;
|
||||
this.imageHeight = h;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,15 @@ package io.anuke.mindustry.ui;
|
||||
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
/**A low-garbage way to format bundle strings.*/
|
||||
public class IntFormat {
|
||||
/**
|
||||
* A low-garbage way to format bundle strings.
|
||||
*/
|
||||
public class IntFormat{
|
||||
private final StringBuilder builder = new StringBuilder();
|
||||
private final String text;
|
||||
private int lastValue = Integer.MIN_VALUE;
|
||||
|
||||
public IntFormat(String text) {
|
||||
public IntFormat(String text){
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ import io.anuke.ucore.scene.ui.layout.Stack;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class ItemImage extends Stack {
|
||||
public class ItemImage extends Stack{
|
||||
|
||||
public ItemImage(TextureRegion region, Supplier<CharSequence> text) {
|
||||
public ItemImage(TextureRegion region, Supplier<CharSequence> text){
|
||||
Table t = new Table().left().bottom();
|
||||
|
||||
t.label(text).color(Color.DARK_GRAY).padBottom(-22).get().setFontScale(Unit.dp.scl(0.5f));
|
||||
@@ -22,7 +22,7 @@ public class ItemImage extends Stack {
|
||||
add(t);
|
||||
}
|
||||
|
||||
public ItemImage(ItemStack stack) {
|
||||
public ItemImage(ItemStack stack){
|
||||
Table t = new Table().left().bottom();
|
||||
|
||||
t.add(stack.amount + "").color(Color.DARK_GRAY).padBottom(-22).get().setFontScale(Unit.dp.scl(0.5f));
|
||||
|
||||
@@ -3,18 +3,18 @@ package io.anuke.mindustry.ui;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
public class Links {
|
||||
public class Links{
|
||||
private static LinkEntry[] links;
|
||||
|
||||
private static void createLinks(){
|
||||
links = new LinkEntry[]{
|
||||
new LinkEntry("discord", "https://discord.gg/BKADYds", Color.valueOf("7289da")),
|
||||
new LinkEntry("trello", "https://trello.com/b/aE2tcUwF", Color.valueOf("026aa7")),
|
||||
new LinkEntry("wiki", "http://mindustry.wikia.com/wiki/Mindustry_Wiki", Color.valueOf("0f142f")),
|
||||
new LinkEntry("itch.io", "https://anuke.itch.io/mindustry", Color.valueOf("fa5c5c")),
|
||||
new LinkEntry("google-play", "https://play.google.com/store/apps/details?id=io.anuke.mindustry", Color.valueOf("689f38")),
|
||||
new LinkEntry("github", "https://github.com/Anuken/Mindustry/", Color.valueOf("24292e")),
|
||||
new LinkEntry("dev-builds", "https://github.com/Anuken/Mindustry/wiki", Color.valueOf("fafbfc"))
|
||||
new LinkEntry("discord", "https://discord.gg/BKADYds", Color.valueOf("7289da")),
|
||||
new LinkEntry("trello", "https://trello.com/b/aE2tcUwF", Color.valueOf("026aa7")),
|
||||
new LinkEntry("wiki", "http://mindustry.wikia.com/wiki/Mindustry_Wiki", Color.valueOf("0f142f")),
|
||||
new LinkEntry("itch.io", "https://anuke.itch.io/mindustry", Color.valueOf("fa5c5c")),
|
||||
new LinkEntry("google-play", "https://play.google.com/store/apps/details?id=io.anuke.mindustry", Color.valueOf("689f38")),
|
||||
new LinkEntry("github", "https://github.com/Anuken/Mindustry/", Color.valueOf("24292e")),
|
||||
new LinkEntry("dev-builds", "https://github.com/Anuken/Mindustry/wiki", Color.valueOf("fafbfc"))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@ public class Links {
|
||||
public final String name, description, link;
|
||||
public final Color color;
|
||||
|
||||
public LinkEntry(String name, String link, Color color) {
|
||||
public LinkEntry(String name, String link, Color color){
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.description = Bundles.getNotNull("text.link." + name +".description");
|
||||
this.description = Bundles.getNotNull("text.link." + name + ".description");
|
||||
this.link = link;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,32 +7,32 @@ import io.anuke.ucore.scene.ui.TextButton;
|
||||
|
||||
public class MenuButton extends TextButton{
|
||||
|
||||
public MenuButton(String icon, String text, Listenable clicked){
|
||||
this(icon, text, null, clicked);
|
||||
}
|
||||
|
||||
public MenuButton(String icon, String text, String description, Listenable clicked){
|
||||
super("default");
|
||||
float s = 66f;
|
||||
public MenuButton(String icon, String text, Listenable clicked){
|
||||
this(icon, text, null, clicked);
|
||||
}
|
||||
|
||||
clicked(clicked);
|
||||
public MenuButton(String icon, String text, String description, Listenable clicked){
|
||||
super("default");
|
||||
float s = 66f;
|
||||
|
||||
clearChildren();
|
||||
clicked(clicked);
|
||||
|
||||
margin(0);
|
||||
clearChildren();
|
||||
|
||||
table(t -> {
|
||||
t.addImage(icon).size(14*3);
|
||||
t.update(() -> t.setBackground(getClickListener().isOver() || getClickListener().isVisualPressed() ? "button-over" : "button"));
|
||||
}).size(s - 5, s);
|
||||
margin(0);
|
||||
|
||||
table(t -> {
|
||||
t.addImage(icon).size(14 * 3);
|
||||
t.update(() -> t.setBackground(getClickListener().isOver() || getClickListener().isVisualPressed() ? "button-over" : "button"));
|
||||
}).size(s - 5, s);
|
||||
|
||||
|
||||
table(t -> {
|
||||
t.add(text).wrap().growX().get().setAlignment(Align.center, Align.left);
|
||||
if(description != null){
|
||||
t.row();
|
||||
t.add(description).color(Color.LIGHT_GRAY);
|
||||
}
|
||||
}).padLeft(5).growX();
|
||||
}
|
||||
table(t -> {
|
||||
t.add(text).wrap().growX().get().setAlignment(Align.center, Align.left);
|
||||
if(description != null){
|
||||
t.row();
|
||||
t.add(description).color(Color.LIGHT_GRAY);
|
||||
}
|
||||
}).padLeft(5).growX();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import static io.anuke.mindustry.Vars.renderer;
|
||||
import static io.anuke.mindustry.Vars.showFog;
|
||||
|
||||
public class Minimap extends Table {
|
||||
public class Minimap extends Table{
|
||||
|
||||
public Minimap(){
|
||||
super("button");
|
||||
@@ -26,17 +26,17 @@ public class Minimap extends Table {
|
||||
|
||||
Image image = new Image(new TextureRegionDrawable(new TextureRegion())){
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
public void draw(Batch batch, float parentAlpha){
|
||||
if(renderer.minimap().getRegion() == null) return;
|
||||
|
||||
TextureRegionDrawable draw = (TextureRegionDrawable)getDrawable();
|
||||
TextureRegionDrawable draw = (TextureRegionDrawable) getDrawable();
|
||||
draw.getRegion().setRegion(renderer.minimap().getRegion());
|
||||
super.draw(batch, parentAlpha);
|
||||
if(renderer.minimap().getTexture() != null){
|
||||
renderer.minimap().drawEntities(x, y, width, height);
|
||||
}
|
||||
|
||||
if(showFog) {
|
||||
if(showFog){
|
||||
renderer.fog().getTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
|
||||
|
||||
draw.getRegion().setTexture(renderer.fog().getTexture());
|
||||
@@ -53,7 +53,7 @@ public class Minimap extends Table {
|
||||
};
|
||||
|
||||
addListener(new InputListener(){
|
||||
public boolean scrolled (InputEvent event, float x, float y, int amount) {
|
||||
public boolean scrolled(InputEvent event, float x, float y, int amount){
|
||||
renderer.minimap().zoomBy(amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import com.badlogic.gdx.utils.Align;
|
||||
import io.anuke.ucore.function.Listenable;
|
||||
import io.anuke.ucore.scene.ui.ImageButton;
|
||||
|
||||
public class MobileButton extends ImageButton {
|
||||
public class MobileButton extends ImageButton{
|
||||
|
||||
public MobileButton(String icon, float isize, String text, Listenable listener) {
|
||||
public MobileButton(String icon, float isize, String text, Listenable listener){
|
||||
super(icon);
|
||||
resizeImage(isize);
|
||||
clicked(listener);
|
||||
|
||||
@@ -16,7 +16,7 @@ import io.anuke.ucore.util.OS;
|
||||
import static io.anuke.mindustry.Vars.ios;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
public class AboutDialog extends FloatingDialog {
|
||||
public class AboutDialog extends FloatingDialog{
|
||||
private static ObjectSet<String> bannedItems = ObjectSet.with("google-play", "itch.io", "dev-builds", "trello");
|
||||
|
||||
public AboutDialog(){
|
||||
@@ -51,21 +51,21 @@ public class AboutDialog extends FloatingDialog {
|
||||
|
||||
table.table(i -> {
|
||||
i.background("button");
|
||||
i.addImage("icon-" + link.name).size(14*3f);
|
||||
}).size(h-5, h);
|
||||
i.addImage("icon-" + link.name).size(14 * 3f);
|
||||
}).size(h - 5, h);
|
||||
|
||||
table.table(inset -> {
|
||||
inset.add("[accent]"+link.name.replace("-", " ")).growX().left();
|
||||
inset.add("[accent]" + link.name.replace("-", " ")).growX().left();
|
||||
inset.row();
|
||||
inset.labelWrap(link.description).width(w - 100f).color(Color.LIGHT_GRAY).growX();
|
||||
}).padLeft(8);
|
||||
|
||||
table.addImageButton("icon-link", 14*3, () -> {
|
||||
table.addImageButton("icon-link", 14 * 3, () -> {
|
||||
if(!Gdx.net.openURI(link.link)){
|
||||
ui.showError("$text.linkfail");
|
||||
Gdx.app.getClipboard().setContents(link.link);
|
||||
}
|
||||
}).size(h-5, h);
|
||||
}).size(h - 5, h);
|
||||
|
||||
in.add(table).size(w, h).padTop(5).row();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class AdminsDialog extends FloatingDialog {
|
||||
public class AdminsDialog extends FloatingDialog{
|
||||
|
||||
public AdminsDialog(){
|
||||
super("$text.server.admins");
|
||||
@@ -40,7 +40,7 @@ public class AdminsDialog extends FloatingDialog {
|
||||
|
||||
res.labelWrap("[LIGHT_GRAY]" + info.lastName).width(w - h - 24f);
|
||||
res.add().growX();
|
||||
res.addImageButton("icon-cancel", 14*3, () -> {
|
||||
res.addImageButton("icon-cancel", 14 * 3, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
|
||||
netServer.admins.unAdminPlayer(info.id);
|
||||
for(Player player : playerGroup.all()){
|
||||
|
||||
@@ -6,7 +6,7 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class BansDialog extends FloatingDialog {
|
||||
public class BansDialog extends FloatingDialog{
|
||||
|
||||
public BansDialog(){
|
||||
super("$text.server.bans");
|
||||
@@ -40,7 +40,7 @@ public class BansDialog extends FloatingDialog {
|
||||
|
||||
res.labelWrap("IP: [LIGHT_GRAY]" + info.lastIP + "\n[]Name: [LIGHT_GRAY]" + info.lastName).width(w - h - 24f);
|
||||
res.add().growX();
|
||||
res.addImageButton("icon-cancel", 14*3, () -> {
|
||||
res.addImageButton("icon-cancel", 14 * 3, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.confirmunban", () -> {
|
||||
netServer.admins.unbanPlayerID(info.id);
|
||||
setup();
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ChangelogDialog extends FloatingDialog{
|
||||
|
||||
content().add("$text.changelog.loading");
|
||||
|
||||
if(!ios && !OS.isMac) {
|
||||
if(!ios && !OS.isMac){
|
||||
Changelogs.getChangelog(result -> {
|
||||
versions = result;
|
||||
Gdx.app.postRunnable(this::setup);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class ColorPickDialog extends Dialog{
|
||||
Table table = new Table();
|
||||
content().add(table);
|
||||
|
||||
for(int i = 0; i < playerColors.length; i ++){
|
||||
for(int i = 0; i < playerColors.length; i++){
|
||||
Color color = playerColors[i];
|
||||
|
||||
ImageButton button = table.addImageButton("white", "toggle", 34, () -> {
|
||||
@@ -32,12 +32,12 @@ public class ColorPickDialog extends Dialog{
|
||||
button.setChecked(players[0].color.equals(color));
|
||||
button.getStyle().imageUpColor = color;
|
||||
|
||||
if(i%4 == 3){
|
||||
if(i % 4 == 3){
|
||||
table.row();
|
||||
}
|
||||
}
|
||||
|
||||
keyDown(key->{
|
||||
keyDown(key -> {
|
||||
if(key == Keys.ESCAPE || key == Keys.BACK)
|
||||
hide();
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
public class ContentInfoDialog extends FloatingDialog {
|
||||
public class ContentInfoDialog extends FloatingDialog{
|
||||
|
||||
public ContentInfoDialog(){
|
||||
super("$text.info.title");
|
||||
|
||||
@@ -7,24 +7,24 @@ import io.anuke.ucore.scene.ui.Image;
|
||||
import io.anuke.ucore.scene.ui.KeybindDialog;
|
||||
|
||||
public class ControlsDialog extends KeybindDialog{
|
||||
|
||||
public ControlsDialog(){
|
||||
setDialog();
|
||||
|
||||
setFillParent(true);
|
||||
title().setAlignment(Align.center);
|
||||
getTitleTable().row();
|
||||
getTitleTable().add(new Image("white"))
|
||||
.growX().height(3f).pad(4f).get().setColor(Palette.accent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCloseButton(){
|
||||
buttons().addImageTextButton("$text.back", "icon-arrow-left", 30f, this::hide).size(230f, 64f);
|
||||
|
||||
keyDown(key->{
|
||||
if(key == Keys.ESCAPE || key == Keys.BACK)
|
||||
hide();
|
||||
});
|
||||
}
|
||||
|
||||
public ControlsDialog(){
|
||||
setDialog();
|
||||
|
||||
setFillParent(true);
|
||||
title().setAlignment(Align.center);
|
||||
getTitleTable().row();
|
||||
getTitleTable().add(new Image("white"))
|
||||
.growX().height(3f).pad(4f).get().setColor(Palette.accent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCloseButton(){
|
||||
buttons().addImageTextButton("$text.back", "icon-arrow-left", 30f, this::hide).size(230f, 64f);
|
||||
|
||||
keyDown(key -> {
|
||||
if(key == Keys.ESCAPE || key == Keys.BACK)
|
||||
hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import io.anuke.ucore.scene.ui.Dialog;
|
||||
import static io.anuke.mindustry.Vars.discordURL;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
public class DiscordDialog extends Dialog {
|
||||
public class DiscordDialog extends Dialog{
|
||||
|
||||
public DiscordDialog(){
|
||||
super("", "dialog");
|
||||
@@ -39,10 +39,10 @@ public class DiscordDialog extends Dialog {
|
||||
buttons().defaults().size(170f, 50);
|
||||
|
||||
buttons().addButton("$text.back", this::hide);
|
||||
buttons().addButton("$text.copylink", () ->{
|
||||
buttons().addButton("$text.copylink", () -> {
|
||||
Gdx.app.getClipboard().setContents(discordURL);
|
||||
});
|
||||
buttons().addButton("$text.openlink", () ->{
|
||||
buttons().addButton("$text.openlink", () -> {
|
||||
if(!Gdx.net.openURI(discordURL)){
|
||||
ui.showError("$text.linkfail");
|
||||
Gdx.app.getClipboard().setContents(discordURL);
|
||||
|
||||
@@ -23,320 +23,319 @@ import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.gwt;
|
||||
|
||||
public class FileChooser extends FloatingDialog {
|
||||
private Table files;
|
||||
private FileHandle homeDirectory = gwt ? Gdx.files.internal("") : Gdx.files.absolute(OS.isMac ? OS.getProperty("user.home") + "/Downloads/" :
|
||||
public class FileChooser extends FloatingDialog{
|
||||
public static Predicate<FileHandle> pngFilter = file -> file.extension().equalsIgnoreCase("png");
|
||||
public static Predicate<FileHandle> mapFilter = file -> file.extension().equalsIgnoreCase(Vars.mapExtension);
|
||||
public static Predicate<FileHandle> jpegFilter = file -> file.extension().equalsIgnoreCase("png") || file.extension().equalsIgnoreCase("jpg") || file.extension().equalsIgnoreCase("jpeg");
|
||||
public static Predicate<FileHandle> defaultFilter = file -> true;
|
||||
private Table files;
|
||||
private FileHandle homeDirectory = gwt ? Gdx.files.internal("") : Gdx.files.absolute(OS.isMac ? OS.getProperty("user.home") + "/Downloads/" :
|
||||
Gdx.files.getExternalStoragePath());
|
||||
private FileHandle directory = homeDirectory;
|
||||
private ScrollPane pane;
|
||||
private TextField navigation, filefield;
|
||||
private TextButton ok;
|
||||
private FileHistory stack = new FileHistory();
|
||||
private Predicate<FileHandle> filter;
|
||||
private Consumer<FileHandle> selectListener;
|
||||
private boolean open;
|
||||
|
||||
public FileChooser(String title, boolean open, Consumer<FileHandle> result){
|
||||
this(title, defaultFilter, open, result);
|
||||
}
|
||||
private FileHandle directory = homeDirectory;
|
||||
private ScrollPane pane;
|
||||
private TextField navigation, filefield;
|
||||
private TextButton ok;
|
||||
private FileHistory stack = new FileHistory();
|
||||
private Predicate<FileHandle> filter;
|
||||
private Consumer<FileHandle> selectListener;
|
||||
private boolean open;
|
||||
|
||||
public FileChooser(String title, Predicate<FileHandle> filter, boolean open, Consumer<FileHandle> result){
|
||||
super(title);
|
||||
this.open = open;
|
||||
this.filter = filter;
|
||||
this.selectListener = result;
|
||||
}
|
||||
public FileChooser(String title, boolean open, Consumer<FileHandle> result){
|
||||
this(title, defaultFilter, open, result);
|
||||
}
|
||||
|
||||
private void setupWidgets(){
|
||||
//getCell(content()).maxWidth(UIUtils.portrait() ? Gdx.graphics.getWidth() : Gdx.graphics.getWidth()/Unit.dp.scl(2f));
|
||||
content().margin(-10);
|
||||
|
||||
Table content = new Table();
|
||||
|
||||
filefield = new TextField();
|
||||
filefield.setOnlyFontChars(false);
|
||||
if(!open) Platform.instance.addDialog(filefield);
|
||||
filefield.setDisabled(open);
|
||||
public FileChooser(String title, Predicate<FileHandle> filter, boolean open, Consumer<FileHandle> result){
|
||||
super(title);
|
||||
this.open = open;
|
||||
this.filter = filter;
|
||||
this.selectListener = result;
|
||||
}
|
||||
|
||||
ok = new TextButton(open ? "$text.load" : "$text.save");
|
||||
|
||||
ok.clicked(() -> {
|
||||
if(ok.isDisabled()) return;
|
||||
if(selectListener != null)
|
||||
selectListener.accept(directory.child(filefield.getText()));
|
||||
hide();
|
||||
});
|
||||
|
||||
filefield.changed(() -> {
|
||||
ok.setDisabled(filefield.getText().replace(" ", "").isEmpty());
|
||||
});
|
||||
|
||||
filefield.change();
|
||||
|
||||
TextButton cancel = new TextButton("$text.cancel");
|
||||
cancel.clicked(this::hide);
|
||||
private void setupWidgets(){
|
||||
//getCell(content()).maxWidth(UIUtils.portrait() ? Gdx.graphics.getWidth() : Gdx.graphics.getWidth()/Unit.dp.scl(2f));
|
||||
content().margin(-10);
|
||||
|
||||
navigation = new TextField("");
|
||||
navigation.setTouchable(Touchable.disabled);
|
||||
Table content = new Table();
|
||||
|
||||
files = new Table();
|
||||
files.marginRight(10);
|
||||
files.marginLeft(3);
|
||||
filefield = new TextField();
|
||||
filefield.setOnlyFontChars(false);
|
||||
if(!open) Platform.instance.addDialog(filefield);
|
||||
filefield.setDisabled(open);
|
||||
|
||||
pane = new ScrollPane(files){
|
||||
public float getPrefHeight(){
|
||||
return Gdx.graphics.getHeight();
|
||||
}
|
||||
};
|
||||
pane.setOverscroll(false, false);
|
||||
pane.setFadeScrollBars(false);
|
||||
ok = new TextButton(open ? "$text.load" : "$text.save");
|
||||
|
||||
updateFiles(true);
|
||||
ok.clicked(() -> {
|
||||
if(ok.isDisabled()) return;
|
||||
if(selectListener != null)
|
||||
selectListener.accept(directory.child(filefield.getText()));
|
||||
hide();
|
||||
});
|
||||
|
||||
Table icontable = new Table();
|
||||
|
||||
float isize = 14*2;
|
||||
filefield.changed(() -> {
|
||||
ok.setDisabled(filefield.getText().replace(" ", "").isEmpty());
|
||||
});
|
||||
|
||||
ImageButton up = new ImageButton("icon-folder-parent");
|
||||
up.resizeImage(isize);
|
||||
up.clicked(()->{
|
||||
directory = directory.parent();
|
||||
updateFiles(true);
|
||||
});
|
||||
filefield.change();
|
||||
|
||||
//Macs are confined to the Downloads/ directory
|
||||
if(OS.isMac){
|
||||
up.setDisabled(true);
|
||||
}
|
||||
TextButton cancel = new TextButton("$text.cancel");
|
||||
cancel.clicked(this::hide);
|
||||
|
||||
ImageButton back = new ImageButton("icon-arrow-left");
|
||||
back.resizeImage(isize);
|
||||
|
||||
ImageButton forward = new ImageButton("icon-arrow-right");
|
||||
forward.resizeImage(isize);
|
||||
|
||||
forward.clicked(()-> stack.forward());
|
||||
|
||||
back.clicked(()-> stack.back());
|
||||
|
||||
ImageButton home = new ImageButton("icon-home");
|
||||
home.resizeImage(isize);
|
||||
home.clicked(()->{
|
||||
directory = homeDirectory;
|
||||
updateFiles(true);
|
||||
});
|
||||
|
||||
icontable.defaults().height(50).growX().uniform();
|
||||
icontable.add(home);
|
||||
icontable.add(back);
|
||||
icontable.add(forward);
|
||||
icontable.add(up);
|
||||
|
||||
Table fieldcontent = new Table();
|
||||
fieldcontent.bottom().left().add(new Label("File Name:"));
|
||||
fieldcontent.add(filefield).height(40f).fillX().expandX().padLeft(10f);
|
||||
|
||||
Table buttons = new Table();
|
||||
buttons.defaults().growX().height(50);
|
||||
buttons.add(cancel);
|
||||
buttons.add(ok);
|
||||
|
||||
content.top().left();
|
||||
content.add(icontable).expandX().fillX();
|
||||
content.row();
|
||||
navigation = new TextField("");
|
||||
navigation.setTouchable(Touchable.disabled);
|
||||
|
||||
content.center().add(pane).width(UIUtils.portrait() ? Gdx.graphics.getWidth()/Unit.dp.scl(1) : Gdx.graphics.getWidth()/Unit.dp.scl(2)).colspan(3).grow();
|
||||
content.row();
|
||||
|
||||
if(!open){
|
||||
content.bottom().left().add(fieldcontent).colspan(3).grow().padTop(-2).padBottom(2);
|
||||
content.row();
|
||||
}
|
||||
files = new Table();
|
||||
files.marginRight(10);
|
||||
files.marginLeft(3);
|
||||
|
||||
content.add(buttons).growX();
|
||||
|
||||
content().add(content);
|
||||
}
|
||||
|
||||
private void updateFileFieldStatus(){
|
||||
if(!open){
|
||||
ok.setDisabled(filefield.getText().replace(" ", "").isEmpty());
|
||||
}else{
|
||||
ok.setDisabled(!directory.child(filefield.getText()).exists() || directory.child(filefield.getText()).isDirectory());
|
||||
}
|
||||
}
|
||||
pane = new ScrollPane(files){
|
||||
public float getPrefHeight(){
|
||||
return Gdx.graphics.getHeight();
|
||||
}
|
||||
};
|
||||
pane.setOverscroll(false, false);
|
||||
pane.setFadeScrollBars(false);
|
||||
|
||||
private FileHandle[] getFileNames(){
|
||||
FileHandle[] handles = directory.list(file -> !file.getName().startsWith("."));
|
||||
updateFiles(true);
|
||||
|
||||
Arrays.sort(handles, (a, b) ->{
|
||||
if(a.isDirectory() && !b.isDirectory()) return -1;
|
||||
if( !a.isDirectory() && b.isDirectory()) return 1;
|
||||
return a.name().toUpperCase().compareTo(b.name().toUpperCase());
|
||||
});
|
||||
return handles;
|
||||
}
|
||||
Table icontable = new Table();
|
||||
|
||||
private void updateFiles(boolean push){
|
||||
if(push) stack.push(directory);
|
||||
//if is mac, don't display extra info since you can only ever go to downloads
|
||||
navigation.setText(OS.isMac ? directory.name() : directory.toString());
|
||||
|
||||
GlyphLayout layout = Pools.obtain(GlyphLayout.class);
|
||||
|
||||
layout.setText(Core.font, navigation.getText());
|
||||
|
||||
if(layout.width < navigation.getWidth()){
|
||||
navigation.setCursorPosition(0);
|
||||
}else{
|
||||
navigation.setCursorPosition(navigation.getText().length());
|
||||
}
|
||||
|
||||
Pools.free(layout);
|
||||
float isize = 14 * 2;
|
||||
|
||||
files.clearChildren();
|
||||
files.top().left();
|
||||
FileHandle[] names = getFileNames();
|
||||
ImageButton up = new ImageButton("icon-folder-parent");
|
||||
up.resizeImage(isize);
|
||||
up.clicked(() -> {
|
||||
directory = directory.parent();
|
||||
updateFiles(true);
|
||||
});
|
||||
|
||||
//macs are confined to the Downloads/ directory
|
||||
if(!OS.isMac) {
|
||||
Image upimage = new Image("icon-folder-parent");
|
||||
TextButton upbutton = new TextButton(".." + directory.toString());
|
||||
upbutton.clicked(() -> {
|
||||
directory = directory.parent();
|
||||
updateFiles(true);
|
||||
});
|
||||
//Macs are confined to the Downloads/ directory
|
||||
if(OS.isMac){
|
||||
up.setDisabled(true);
|
||||
}
|
||||
|
||||
upbutton.left().add(upimage).padRight(4f).size(14 * 2);
|
||||
upbutton.getLabel().setAlignment(Align.left);
|
||||
upbutton.getCells().reverse();
|
||||
ImageButton back = new ImageButton("icon-arrow-left");
|
||||
back.resizeImage(isize);
|
||||
|
||||
files.add(upbutton).align(Align.topLeft).fillX().expandX().height(50).pad(2).colspan(2);
|
||||
files.row();
|
||||
}
|
||||
|
||||
ButtonGroup<TextButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
ImageButton forward = new ImageButton("icon-arrow-right");
|
||||
forward.resizeImage(isize);
|
||||
|
||||
for(FileHandle file : names){
|
||||
if( !file.isDirectory() && !filter.test(file)) continue; //skip non-filtered files
|
||||
forward.clicked(() -> stack.forward());
|
||||
|
||||
String filename = file.name();
|
||||
back.clicked(() -> stack.back());
|
||||
|
||||
TextButton button = new TextButton(shorten(filename), "toggle");
|
||||
group.add(button);
|
||||
|
||||
button.clicked(()->{
|
||||
if( !file.isDirectory()){
|
||||
filefield.setText(filename);
|
||||
updateFileFieldStatus();
|
||||
}else{
|
||||
directory = directory.child(filename);
|
||||
updateFiles(true);
|
||||
}
|
||||
});
|
||||
|
||||
filefield.changed(()->{
|
||||
button.setChecked(filename.equals(filefield.getText()));
|
||||
});
|
||||
|
||||
Image image = new Image(file.isDirectory() ? "icon-folder" : "icon-file-text");
|
||||
|
||||
button.add(image).padRight(4f).size(14*2f);
|
||||
button.getCells().reverse();
|
||||
files.top().left().add(button).align(Align.topLeft).fillX().expandX()
|
||||
.height(50).pad(2).padTop(0).padBottom(0).colspan(2);
|
||||
button.getLabel().setAlignment(Align.left);
|
||||
files.row();
|
||||
}
|
||||
ImageButton home = new ImageButton("icon-home");
|
||||
home.resizeImage(isize);
|
||||
home.clicked(() -> {
|
||||
directory = homeDirectory;
|
||||
updateFiles(true);
|
||||
});
|
||||
|
||||
pane.setScrollY(0f);
|
||||
updateFileFieldStatus();
|
||||
|
||||
if(open) filefield.clearText();
|
||||
}
|
||||
icontable.defaults().height(50).growX().uniform();
|
||||
icontable.add(home);
|
||||
icontable.add(back);
|
||||
icontable.add(forward);
|
||||
icontable.add(up);
|
||||
|
||||
private String shorten(String string){
|
||||
int max = 30;
|
||||
if(string.length() <= max){
|
||||
return string;
|
||||
}else{
|
||||
return string.substring(0, max - 3).concat("...");
|
||||
}
|
||||
}
|
||||
Table fieldcontent = new Table();
|
||||
fieldcontent.bottom().left().add(new Label("File Name:"));
|
||||
fieldcontent.add(filefield).height(40f).fillX().expandX().padLeft(10f);
|
||||
|
||||
@Override
|
||||
public Dialog show(){
|
||||
Timers.runTask(2f, () -> {
|
||||
content().clear();
|
||||
setupWidgets();
|
||||
super.show();
|
||||
Core.scene.setScrollFocus(pane);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
Table buttons = new Table();
|
||||
buttons.defaults().growX().height(50);
|
||||
buttons.add(cancel);
|
||||
buttons.add(ok);
|
||||
|
||||
public void fileSelected(Consumer<FileHandle> listener){
|
||||
this.selectListener = listener;
|
||||
}
|
||||
content.top().left();
|
||||
content.add(icontable).expandX().fillX();
|
||||
content.row();
|
||||
|
||||
public class FileHistory{
|
||||
private Array<FileHandle> history = new Array<>();
|
||||
private int index;
|
||||
content.center().add(pane).width(UIUtils.portrait() ? Gdx.graphics.getWidth() / Unit.dp.scl(1) : Gdx.graphics.getWidth() / Unit.dp.scl(2)).colspan(3).grow();
|
||||
content.row();
|
||||
|
||||
public FileHistory(){
|
||||
if(!open){
|
||||
content.bottom().left().add(fieldcontent).colspan(3).grow().padTop(-2).padBottom(2);
|
||||
content.row();
|
||||
}
|
||||
|
||||
}
|
||||
content.add(buttons).growX();
|
||||
|
||||
public void push(FileHandle file){
|
||||
if(index != history.size) history.truncate(index);
|
||||
history.add(file);
|
||||
index ++;
|
||||
}
|
||||
content().add(content);
|
||||
}
|
||||
|
||||
public void back(){
|
||||
if( !canBack()) return;
|
||||
index --;
|
||||
directory = history.get(index - 1);
|
||||
updateFiles(false);
|
||||
}
|
||||
private void updateFileFieldStatus(){
|
||||
if(!open){
|
||||
ok.setDisabled(filefield.getText().replace(" ", "").isEmpty());
|
||||
}else{
|
||||
ok.setDisabled(!directory.child(filefield.getText()).exists() || directory.child(filefield.getText()).isDirectory());
|
||||
}
|
||||
}
|
||||
|
||||
public void forward(){
|
||||
if( !canForward()) return;
|
||||
directory = history.get(index);
|
||||
index ++;
|
||||
updateFiles(false);
|
||||
}
|
||||
private FileHandle[] getFileNames(){
|
||||
FileHandle[] handles = directory.list(file -> !file.getName().startsWith("."));
|
||||
|
||||
public boolean canForward(){
|
||||
return !(index >= history.size);
|
||||
}
|
||||
Arrays.sort(handles, (a, b) -> {
|
||||
if(a.isDirectory() && !b.isDirectory()) return -1;
|
||||
if(!a.isDirectory() && b.isDirectory()) return 1;
|
||||
return a.name().toUpperCase().compareTo(b.name().toUpperCase());
|
||||
});
|
||||
return handles;
|
||||
}
|
||||
|
||||
public boolean canBack(){
|
||||
return !(index == 1) && index > 0;
|
||||
}
|
||||
private void updateFiles(boolean push){
|
||||
if(push) stack.push(directory);
|
||||
//if is mac, don't display extra info since you can only ever go to downloads
|
||||
navigation.setText(OS.isMac ? directory.name() : directory.toString());
|
||||
|
||||
void print(){
|
||||
GlyphLayout layout = Pools.obtain(GlyphLayout.class);
|
||||
|
||||
System.out.println("\n\n\n\n\n\n");
|
||||
int i = 0;
|
||||
for(FileHandle file : history){
|
||||
i ++;
|
||||
if(index == i){
|
||||
System.out.println("[[" + file.toString() + "]]");
|
||||
}else{
|
||||
System.out.println("--" + file.toString() + "--");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
layout.setText(Core.font, navigation.getText());
|
||||
|
||||
public interface FileHandleFilter{
|
||||
boolean accept(FileHandle file);
|
||||
}
|
||||
if(layout.width < navigation.getWidth()){
|
||||
navigation.setCursorPosition(0);
|
||||
}else{
|
||||
navigation.setCursorPosition(navigation.getText().length());
|
||||
}
|
||||
|
||||
public static Predicate<FileHandle> pngFilter = file -> file.extension().equalsIgnoreCase("png");
|
||||
public static Predicate<FileHandle> mapFilter = file -> file.extension().equalsIgnoreCase(Vars.mapExtension);
|
||||
public static Predicate<FileHandle> jpegFilter = file -> file.extension().equalsIgnoreCase("png") || file.extension().equalsIgnoreCase("jpg") || file.extension().equalsIgnoreCase("jpeg");
|
||||
public static Predicate<FileHandle> defaultFilter = file -> true;
|
||||
Pools.free(layout);
|
||||
|
||||
files.clearChildren();
|
||||
files.top().left();
|
||||
FileHandle[] names = getFileNames();
|
||||
|
||||
//macs are confined to the Downloads/ directory
|
||||
if(!OS.isMac){
|
||||
Image upimage = new Image("icon-folder-parent");
|
||||
TextButton upbutton = new TextButton(".." + directory.toString());
|
||||
upbutton.clicked(() -> {
|
||||
directory = directory.parent();
|
||||
updateFiles(true);
|
||||
});
|
||||
|
||||
upbutton.left().add(upimage).padRight(4f).size(14 * 2);
|
||||
upbutton.getLabel().setAlignment(Align.left);
|
||||
upbutton.getCells().reverse();
|
||||
|
||||
files.add(upbutton).align(Align.topLeft).fillX().expandX().height(50).pad(2).colspan(2);
|
||||
files.row();
|
||||
}
|
||||
|
||||
ButtonGroup<TextButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
|
||||
for(FileHandle file : names){
|
||||
if(!file.isDirectory() && !filter.test(file)) continue; //skip non-filtered files
|
||||
|
||||
String filename = file.name();
|
||||
|
||||
TextButton button = new TextButton(shorten(filename), "toggle");
|
||||
group.add(button);
|
||||
|
||||
button.clicked(() -> {
|
||||
if(!file.isDirectory()){
|
||||
filefield.setText(filename);
|
||||
updateFileFieldStatus();
|
||||
}else{
|
||||
directory = directory.child(filename);
|
||||
updateFiles(true);
|
||||
}
|
||||
});
|
||||
|
||||
filefield.changed(() -> {
|
||||
button.setChecked(filename.equals(filefield.getText()));
|
||||
});
|
||||
|
||||
Image image = new Image(file.isDirectory() ? "icon-folder" : "icon-file-text");
|
||||
|
||||
button.add(image).padRight(4f).size(14 * 2f);
|
||||
button.getCells().reverse();
|
||||
files.top().left().add(button).align(Align.topLeft).fillX().expandX()
|
||||
.height(50).pad(2).padTop(0).padBottom(0).colspan(2);
|
||||
button.getLabel().setAlignment(Align.left);
|
||||
files.row();
|
||||
}
|
||||
|
||||
pane.setScrollY(0f);
|
||||
updateFileFieldStatus();
|
||||
|
||||
if(open) filefield.clearText();
|
||||
}
|
||||
|
||||
private String shorten(String string){
|
||||
int max = 30;
|
||||
if(string.length() <= max){
|
||||
return string;
|
||||
}else{
|
||||
return string.substring(0, max - 3).concat("...");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog show(){
|
||||
Timers.runTask(2f, () -> {
|
||||
content().clear();
|
||||
setupWidgets();
|
||||
super.show();
|
||||
Core.scene.setScrollFocus(pane);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public void fileSelected(Consumer<FileHandle> listener){
|
||||
this.selectListener = listener;
|
||||
}
|
||||
|
||||
public interface FileHandleFilter{
|
||||
boolean accept(FileHandle file);
|
||||
}
|
||||
|
||||
public class FileHistory{
|
||||
private Array<FileHandle> history = new Array<>();
|
||||
private int index;
|
||||
|
||||
public FileHistory(){
|
||||
|
||||
}
|
||||
|
||||
public void push(FileHandle file){
|
||||
if(index != history.size) history.truncate(index);
|
||||
history.add(file);
|
||||
index++;
|
||||
}
|
||||
|
||||
public void back(){
|
||||
if(!canBack()) return;
|
||||
index--;
|
||||
directory = history.get(index - 1);
|
||||
updateFiles(false);
|
||||
}
|
||||
|
||||
public void forward(){
|
||||
if(!canForward()) return;
|
||||
directory = history.get(index);
|
||||
index++;
|
||||
updateFiles(false);
|
||||
}
|
||||
|
||||
public boolean canForward(){
|
||||
return !(index >= history.size);
|
||||
}
|
||||
|
||||
public boolean canBack(){
|
||||
return !(index == 1) && index > 0;
|
||||
}
|
||||
|
||||
void print(){
|
||||
|
||||
System.out.println("\n\n\n\n\n\n");
|
||||
int i = 0;
|
||||
for(FileHandle file : history){
|
||||
i++;
|
||||
if(index == i){
|
||||
System.out.println("[[" + file.toString() + "]]");
|
||||
}else{
|
||||
System.out.println("--" + file.toString() + "--");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,43 +11,43 @@ import io.anuke.ucore.scene.ui.Dialog;
|
||||
import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
|
||||
public class FloatingDialog extends Dialog{
|
||||
|
||||
public FloatingDialog(String title){
|
||||
super(title, "dialog");
|
||||
setFillParent(true);
|
||||
title().setAlignment(Align.center);
|
||||
getTitleTable().row();
|
||||
getTitleTable().addImage("white", Palette.accent)
|
||||
.growX().height(3f).pad(4f);
|
||||
|
||||
boolean[] done = {false};
|
||||
public FloatingDialog(String title){
|
||||
super(title, "dialog");
|
||||
setFillParent(true);
|
||||
title().setAlignment(Align.center);
|
||||
getTitleTable().row();
|
||||
getTitleTable().addImage("white", Palette.accent)
|
||||
.growX().height(3f).pad(4f);
|
||||
|
||||
shown(() -> Gdx.app.postRunnable(() ->
|
||||
forEach(child -> {
|
||||
if (done[0]) return;
|
||||
boolean[] done = {false};
|
||||
|
||||
if (child instanceof ScrollPane) {
|
||||
Core.scene.setScrollFocus(child);
|
||||
done[0] = true;
|
||||
}
|
||||
})));
|
||||
}
|
||||
shown(() -> Gdx.app.postRunnable(() ->
|
||||
forEach(child -> {
|
||||
if(done[0]) return;
|
||||
|
||||
protected void onResize(Runnable run){
|
||||
Events.on(ResizeEvent.class, () -> {
|
||||
if(isShown()){
|
||||
run.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCloseButton(){
|
||||
buttons().addImageTextButton("$text.back", "icon-arrow-left", 30f, this::hide).size(230f, 64f);
|
||||
|
||||
keyDown(key -> {
|
||||
if(key == Keys.ESCAPE || key == Keys.BACK)
|
||||
hide();
|
||||
});
|
||||
}
|
||||
if(child instanceof ScrollPane){
|
||||
Core.scene.setScrollFocus(child);
|
||||
done[0] = true;
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
||||
protected void onResize(Runnable run){
|
||||
Events.on(ResizeEvent.class, () -> {
|
||||
if(isShown()){
|
||||
run.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCloseButton(){
|
||||
buttons().addImageTextButton("$text.back", "icon-arrow-left", 30f, this::hide).size(230f, 64f);
|
||||
|
||||
keyDown(key -> {
|
||||
if(key == Keys.ESCAPE || key == Keys.BACK)
|
||||
hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class HostDialog extends FloatingDialog{
|
||||
try{
|
||||
Net.host(Vars.port);
|
||||
player.isAdmin = true;
|
||||
}catch (IOException e){
|
||||
}catch(IOException e){
|
||||
ui.showError(Bundles.format("text.server.error", Strings.parseException(e, false)));
|
||||
}
|
||||
ui.loadfrag.hide();
|
||||
|
||||
@@ -25,7 +25,7 @@ import io.anuke.ucore.util.Strings;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class JoinDialog extends FloatingDialog {
|
||||
public class JoinDialog extends FloatingDialog{
|
||||
Array<Server> servers = new Array<>();
|
||||
Dialog add;
|
||||
Server renaming;
|
||||
@@ -49,7 +49,7 @@ public class JoinDialog extends FloatingDialog {
|
||||
add = new FloatingDialog("$text.joingame.title");
|
||||
add.content().add("$text.joingame.ip").padRight(5f).left();
|
||||
|
||||
Platform.instance.addDialog(add.content().addField(Settings.getString("ip"), text ->{
|
||||
Platform.instance.addDialog(add.content().addField(Settings.getString("ip"), text -> {
|
||||
Settings.putString("ip", text);
|
||||
Settings.save();
|
||||
}).size(320f, 54f).get(), 100);
|
||||
@@ -58,7 +58,7 @@ public class JoinDialog extends FloatingDialog {
|
||||
add.buttons().defaults().size(140f, 60f).pad(4f);
|
||||
add.buttons().addButton("$text.cancel", add::hide);
|
||||
add.buttons().addButton("$text.ok", () -> {
|
||||
if(renaming == null) {
|
||||
if(renaming == null){
|
||||
Server server = new Server(Settings.getString("ip"), Strings.parseInt(Settings.getString("port")));
|
||||
servers.add(server);
|
||||
saveServers();
|
||||
@@ -88,11 +88,11 @@ public class JoinDialog extends FloatingDialog {
|
||||
|
||||
void setupRemote(){
|
||||
remote.clear();
|
||||
for (Server server : servers) {
|
||||
for(Server server : servers){
|
||||
//why are java lambdas this bad
|
||||
TextButton[] buttons = {null};
|
||||
|
||||
TextButton button = buttons[0] = remote.addButton("[accent]"+server.ip, "clear", () -> {
|
||||
TextButton button = buttons[0] = remote.addButton("[accent]" + server.ip, "clear", () -> {
|
||||
if(!buttons[0].childrenPressed()) connect(server.ip, Vars.port);
|
||||
}).width(targetWidth()).height(150f).pad(4f).get();
|
||||
|
||||
@@ -104,16 +104,16 @@ public class JoinDialog extends FloatingDialog {
|
||||
|
||||
inner.add(button.getLabel()).growX();
|
||||
|
||||
inner.addImageButton("icon-loading", "empty", 16*2, () -> {
|
||||
inner.addImageButton("icon-loading", "empty", 16 * 2, () -> {
|
||||
refreshServer(server);
|
||||
}).margin(3f).padTop(6f).top().right();
|
||||
|
||||
inner.addImageButton("icon-pencil", "empty", 16*2, () -> {
|
||||
inner.addImageButton("icon-pencil", "empty", 16 * 2, () -> {
|
||||
renaming = server;
|
||||
add.show();
|
||||
}).margin(3f).padTop(6f).top().right();
|
||||
|
||||
inner.addImageButton("icon-trash-16", "empty", 16*2, () -> {
|
||||
inner.addImageButton("icon-trash-16", "empty", 16 * 2, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.server.delete", () -> {
|
||||
servers.removeValue(server, true);
|
||||
saveServers();
|
||||
@@ -124,7 +124,8 @@ public class JoinDialog extends FloatingDialog {
|
||||
|
||||
button.row();
|
||||
|
||||
server.content = button.table(t -> {}).grow().get();
|
||||
server.content = button.table(t -> {
|
||||
}).grow().get();
|
||||
|
||||
remote.row();
|
||||
}
|
||||
@@ -143,7 +144,7 @@ public class JoinDialog extends FloatingDialog {
|
||||
Net.pingHost(server.ip, server.port, host -> {
|
||||
String versionString;
|
||||
|
||||
if(host.version == -1) {
|
||||
if(host.version == -1){
|
||||
versionString = Bundles.format("text.server.version", Bundles.get("text.server.custombuild"));
|
||||
}else if(host.version == 0){
|
||||
versionString = Bundles.get("text.server.outdated");
|
||||
@@ -179,7 +180,7 @@ public class JoinDialog extends FloatingDialog {
|
||||
}
|
||||
|
||||
void refreshLocal(){
|
||||
if(!Vars.gwt) {
|
||||
if(!Vars.gwt){
|
||||
local.clear();
|
||||
local.background("button");
|
||||
local.label(() -> "[accent]" + Bundles.get("text.hosts.discovering") + Strings.animated(4, 10f, ".")).pad(10f);
|
||||
@@ -227,7 +228,7 @@ public class JoinDialog extends FloatingDialog {
|
||||
content().row();
|
||||
content().add(pane).width(w + 34).pad(0);
|
||||
content().row();
|
||||
content().addCenteredImageTextButton("$text.server.add", "icon-add", "clear", 14*3, () -> {
|
||||
content().addCenteredImageTextButton("$text.server.add", "icon-add", "clear", 14 * 3, () -> {
|
||||
renaming = null;
|
||||
add.show();
|
||||
}).marginLeft(6).width(w).height(80f).update(button -> {
|
||||
@@ -238,7 +239,7 @@ public class JoinDialog extends FloatingDialog {
|
||||
pad = 6;
|
||||
}
|
||||
|
||||
Cell<TextButton> cell = ((Table)pane.getParent()).getCell(button);
|
||||
Cell<TextButton> cell = ((Table) pane.getParent()).getCell(button);
|
||||
|
||||
if(!MathUtils.isEqual(cell.getMinWidth(), pw)){
|
||||
cell.width(pw);
|
||||
@@ -256,10 +257,10 @@ public class JoinDialog extends FloatingDialog {
|
||||
if(array.size == 0){
|
||||
local.add("$text.hosts.none").pad(10f);
|
||||
local.add().growX();
|
||||
local.addImageButton("icon-loading", 16*2f, this::refreshLocal).pad(-10f).padLeft(0).padTop(-6).size(70f, 74f);
|
||||
}else {
|
||||
for (Host a : array) {
|
||||
TextButton button = local.addButton("[accent]"+a.name, "clear", () -> {
|
||||
local.addImageButton("icon-loading", 16 * 2f, this::refreshLocal).pad(-10f).padLeft(0).padTop(-6).size(70f, 74f);
|
||||
}else{
|
||||
for(Host a : array){
|
||||
TextButton button = local.addButton("[accent]" + a.name, "clear", () -> {
|
||||
connect(a.address, Vars.port);
|
||||
}).width(w).height(80f).pad(4f).get();
|
||||
button.left();
|
||||
@@ -289,18 +290,18 @@ public class JoinDialog extends FloatingDialog {
|
||||
Net.connect(ip, port);
|
||||
hide();
|
||||
add.hide();
|
||||
}catch (Exception e) {
|
||||
}catch(Exception e){
|
||||
Throwable t = e;
|
||||
while(t.getCause() != null){
|
||||
t = t.getCause();
|
||||
}
|
||||
//TODO localize
|
||||
String error = t.getMessage() == null ? "" : t.getMessage().toLowerCase();
|
||||
if(error.contains("connection refused")) {
|
||||
if(error.contains("connection refused")){
|
||||
error = "connection refused";
|
||||
}else if(error.contains("port out of range")){
|
||||
error = "invalid port!";
|
||||
}else if(error.contains("invalid argument")) {
|
||||
}else if(error.contains("invalid argument")){
|
||||
error = "invalid IP or port!";
|
||||
}else if(t.getClass().toString().toLowerCase().contains("sockettimeout")){
|
||||
error = "timed out!\nmake sure the host has port forwarding set up,\nand that the address is correct!";
|
||||
@@ -340,6 +341,7 @@ public class JoinDialog extends FloatingDialog {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
Server(){}
|
||||
Server(){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,142 +24,142 @@ import io.anuke.ucore.util.Mathf;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class LevelDialog extends FloatingDialog{
|
||||
|
||||
public LevelDialog(){
|
||||
super("$text.level.select");
|
||||
addCloseButton();
|
||||
shown(this::setup);
|
||||
|
||||
onResize(this::setup);
|
||||
}
|
||||
|
||||
void setup(){
|
||||
content().clear();
|
||||
public LevelDialog(){
|
||||
super("$text.level.select");
|
||||
addCloseButton();
|
||||
shown(this::setup);
|
||||
|
||||
Table maps = new Table();
|
||||
maps.marginRight(14);
|
||||
ScrollPane pane = new ScrollPane(maps, "clear-black");
|
||||
pane.setFadeScrollBars(false);
|
||||
|
||||
int maxwidth = (Gdx.graphics.getHeight() > Gdx.graphics.getHeight() ? 2 : 4);
|
||||
|
||||
Table selmode = new Table();
|
||||
ButtonGroup<TextButton> group = new ButtonGroup<>();
|
||||
selmode.add("$text.level.mode").padRight(15f);
|
||||
|
||||
for(GameMode mode : GameMode.values()){
|
||||
TextButton[] b = {null};
|
||||
b[0] = Elements.newButton("$mode." + mode.name() + ".name", "toggle", () -> state.mode = mode);
|
||||
b[0].update(() -> b[0].setChecked(state.mode == mode));
|
||||
group.add(b[0]);
|
||||
selmode.add(b[0]).size(130f, 54f);
|
||||
}
|
||||
selmode.addButton("?", this::displayGameModeHelp).size(50f, 54f).padLeft(18f);
|
||||
|
||||
content().add(selmode);
|
||||
content().row();
|
||||
onResize(this::setup);
|
||||
}
|
||||
|
||||
Difficulty[] ds = Difficulty.values();
|
||||
void setup(){
|
||||
content().clear();
|
||||
|
||||
float s = 50f;
|
||||
Table maps = new Table();
|
||||
maps.marginRight(14);
|
||||
ScrollPane pane = new ScrollPane(maps, "clear-black");
|
||||
pane.setFadeScrollBars(false);
|
||||
|
||||
Table sdif = new Table();
|
||||
int maxwidth = (Gdx.graphics.getHeight() > Gdx.graphics.getHeight() ? 2 : 4);
|
||||
|
||||
sdif.add("$setting.difficulty.name").padRight(15f);
|
||||
Table selmode = new Table();
|
||||
ButtonGroup<TextButton> group = new ButtonGroup<>();
|
||||
selmode.add("$text.level.mode").padRight(15f);
|
||||
|
||||
sdif.defaults().height(s+4);
|
||||
sdif.addImageButton("icon-arrow-left", 10*3, () -> {
|
||||
state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() - 1, ds.length)]);
|
||||
}).width(s);
|
||||
for(GameMode mode : GameMode.values()){
|
||||
TextButton[] b = {null};
|
||||
b[0] = Elements.newButton("$mode." + mode.name() + ".name", "toggle", () -> state.mode = mode);
|
||||
b[0].update(() -> b[0].setChecked(state.mode == mode));
|
||||
group.add(b[0]);
|
||||
selmode.add(b[0]).size(130f, 54f);
|
||||
}
|
||||
selmode.addButton("?", this::displayGameModeHelp).size(50f, 54f).padLeft(18f);
|
||||
|
||||
sdif.addButton("", () -> {
|
||||
content().add(selmode);
|
||||
content().row();
|
||||
|
||||
}).update(t -> {
|
||||
t.setText(state.difficulty.toString());
|
||||
t.setTouchable(Touchable.disabled);
|
||||
}).width(180f);
|
||||
Difficulty[] ds = Difficulty.values();
|
||||
|
||||
sdif.addImageButton("icon-arrow-right", 10*3, () -> {
|
||||
state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() + 1, ds.length)]);
|
||||
}).width(s);
|
||||
float s = 50f;
|
||||
|
||||
content().add(sdif);
|
||||
content().row();
|
||||
Table sdif = new Table();
|
||||
|
||||
float images = 146f;
|
||||
sdif.add("$setting.difficulty.name").padRight(15f);
|
||||
|
||||
int i = 0;
|
||||
for(Map map : world.maps().all()){
|
||||
sdif.defaults().height(s + 4);
|
||||
sdif.addImageButton("icon-arrow-left", 10 * 3, () -> {
|
||||
state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() - 1, ds.length)]);
|
||||
}).width(s);
|
||||
|
||||
if(i % maxwidth == 0){
|
||||
maps.row();
|
||||
}
|
||||
|
||||
ImageButton image = new ImageButton(new TextureRegion(map.texture), "clear");
|
||||
image.margin(5);
|
||||
image.getImageCell().size(images);
|
||||
image.top();
|
||||
image.row();
|
||||
image.add("[accent]" + Bundles.get("map."+map.name+".name", map.name)).pad(3f).growX().wrap().get().setAlignment(Align.center, Align.center);
|
||||
image.row();
|
||||
image.label((() -> Bundles.format("text.level.highscore", Settings.getInt("hiscore" + map.name, 0)))).pad(3f);
|
||||
sdif.addButton("", () -> {
|
||||
|
||||
BorderImage border = new BorderImage(map.texture, 3f);
|
||||
image.replaceImage(border);
|
||||
}).update(t -> {
|
||||
t.setText(state.difficulty.toString());
|
||||
t.setTouchable(Touchable.disabled);
|
||||
}).width(180f);
|
||||
|
||||
image.clicked(() -> {
|
||||
hide();
|
||||
control.playMap(map);
|
||||
});
|
||||
|
||||
maps.add(image).width(170).fillY().top().pad(4f);
|
||||
|
||||
i ++;
|
||||
}
|
||||
sdif.addImageButton("icon-arrow-right", 10 * 3, () -> {
|
||||
state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() + 1, ds.length)]);
|
||||
}).width(s);
|
||||
|
||||
ImageButton genb = maps.addImageButton("icon-editor", "clear", 16*3, () -> {
|
||||
hide();
|
||||
content().add(sdif);
|
||||
content().row();
|
||||
|
||||
ui.loadfrag.show();
|
||||
float images = 146f;
|
||||
|
||||
Timers.run(5f, () -> {
|
||||
Cursors.restoreCursor();
|
||||
threads.run(() -> {
|
||||
world.loadProceduralMap();
|
||||
logic.play();
|
||||
Gdx.app.postRunnable(ui.loadfrag::hide);
|
||||
});
|
||||
});
|
||||
}).width(170).fillY().pad(4f).get();
|
||||
int i = 0;
|
||||
for(Map map : world.maps().all()){
|
||||
|
||||
genb.top();
|
||||
genb.margin(5);
|
||||
genb.clearChildren();
|
||||
genb.add(new BorderImage(Draw.region("icon-generated"), 3f)).size(images);
|
||||
genb.row();
|
||||
genb.add("$text.map.random").growX().wrap().pad(3f).get().setAlignment(Align.center, Align.center);
|
||||
genb.row();
|
||||
genb.add("<generated>").pad(3f);
|
||||
|
||||
content().add(pane).uniformX();
|
||||
}
|
||||
if(i % maxwidth == 0){
|
||||
maps.row();
|
||||
}
|
||||
|
||||
private void displayGameModeHelp() {
|
||||
FloatingDialog d = new FloatingDialog(Bundles.get("mode.text.help.title"));
|
||||
d.setFillParent(false);
|
||||
Table table = new Table();
|
||||
table.defaults().pad(1f);
|
||||
ScrollPane pane = new ScrollPane(table, "clear");
|
||||
pane.setFadeScrollBars(false);
|
||||
table.row();
|
||||
for(GameMode mode : GameMode.values()){
|
||||
table.labelWrap("[accent]" + mode.toString() + ":[] [lightgray]" + mode.description()).width(600f);
|
||||
table.row();
|
||||
}
|
||||
ImageButton image = new ImageButton(new TextureRegion(map.texture), "clear");
|
||||
image.margin(5);
|
||||
image.getImageCell().size(images);
|
||||
image.top();
|
||||
image.row();
|
||||
image.add("[accent]" + Bundles.get("map." + map.name + ".name", map.name)).pad(3f).growX().wrap().get().setAlignment(Align.center, Align.center);
|
||||
image.row();
|
||||
image.label((() -> Bundles.format("text.level.highscore", Settings.getInt("hiscore" + map.name, 0)))).pad(3f);
|
||||
|
||||
d.content().add(pane);
|
||||
d.buttons().addButton("$text.ok", d::hide).size(110, 50).pad(10f);
|
||||
d.show();
|
||||
}
|
||||
BorderImage border = new BorderImage(map.texture, 3f);
|
||||
image.replaceImage(border);
|
||||
|
||||
image.clicked(() -> {
|
||||
hide();
|
||||
control.playMap(map);
|
||||
});
|
||||
|
||||
maps.add(image).width(170).fillY().top().pad(4f);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
ImageButton genb = maps.addImageButton("icon-editor", "clear", 16 * 3, () -> {
|
||||
hide();
|
||||
|
||||
ui.loadfrag.show();
|
||||
|
||||
Timers.run(5f, () -> {
|
||||
Cursors.restoreCursor();
|
||||
threads.run(() -> {
|
||||
world.loadProceduralMap();
|
||||
logic.play();
|
||||
Gdx.app.postRunnable(ui.loadfrag::hide);
|
||||
});
|
||||
});
|
||||
}).width(170).fillY().pad(4f).get();
|
||||
|
||||
genb.top();
|
||||
genb.margin(5);
|
||||
genb.clearChildren();
|
||||
genb.add(new BorderImage(Draw.region("icon-generated"), 3f)).size(images);
|
||||
genb.row();
|
||||
genb.add("$text.map.random").growX().wrap().pad(3f).get().setAlignment(Align.center, Align.center);
|
||||
genb.row();
|
||||
genb.add("<generated>").pad(3f);
|
||||
|
||||
content().add(pane).uniformX();
|
||||
}
|
||||
|
||||
private void displayGameModeHelp(){
|
||||
FloatingDialog d = new FloatingDialog(Bundles.get("mode.text.help.title"));
|
||||
d.setFillParent(false);
|
||||
Table table = new Table();
|
||||
table.defaults().pad(1f);
|
||||
ScrollPane pane = new ScrollPane(table, "clear");
|
||||
pane.setFadeScrollBars(false);
|
||||
table.row();
|
||||
for(GameMode mode : GameMode.values()){
|
||||
table.labelWrap("[accent]" + mode.toString() + ":[] [lightgray]" + mode.description()).width(600f);
|
||||
table.row();
|
||||
}
|
||||
|
||||
d.content().add(pane);
|
||||
d.buttons().addButton("$text.ok", d::hide).size(110, 50).pad(10f);
|
||||
d.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,11 +6,9 @@ import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
import io.anuke.mindustry.game.EventType.ResizeEvent;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.mindustry.io.Saves.SaveSlot;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Events;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
import io.anuke.ucore.scene.ui.TextButton;
|
||||
@@ -24,150 +22,150 @@ import java.io.IOException;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class LoadDialog extends FloatingDialog{
|
||||
ScrollPane pane;
|
||||
Table slots;
|
||||
ScrollPane pane;
|
||||
Table slots;
|
||||
|
||||
public LoadDialog() {
|
||||
this("$text.loadgame");
|
||||
}
|
||||
public LoadDialog(){
|
||||
this("$text.loadgame");
|
||||
}
|
||||
|
||||
public LoadDialog(String title) {
|
||||
super(title);
|
||||
setup();
|
||||
public LoadDialog(String title){
|
||||
super(title);
|
||||
setup();
|
||||
|
||||
shown(() -> {
|
||||
setup();
|
||||
Timers.runTask(2f, () -> Core.scene.setScrollFocus(pane));
|
||||
});
|
||||
shown(() -> {
|
||||
setup();
|
||||
Timers.runTask(2f, () -> Core.scene.setScrollFocus(pane));
|
||||
});
|
||||
|
||||
addCloseButton();
|
||||
}
|
||||
addCloseButton();
|
||||
}
|
||||
|
||||
protected void setup(){
|
||||
content().clear();
|
||||
protected void setup(){
|
||||
content().clear();
|
||||
|
||||
slots = new Table();
|
||||
pane = new ScrollPane(slots, "clear-black");
|
||||
pane.setFadeScrollBars(false);
|
||||
pane.setScrollingDisabled(true, false);
|
||||
slots = new Table();
|
||||
pane = new ScrollPane(slots, "clear-black");
|
||||
pane.setFadeScrollBars(false);
|
||||
pane.setScrollingDisabled(true, false);
|
||||
|
||||
slots.marginRight(24);
|
||||
slots.marginRight(24);
|
||||
|
||||
Timers.runTask(2f, () -> Core.scene.setScrollFocus(pane));
|
||||
Timers.runTask(2f, () -> Core.scene.setScrollFocus(pane));
|
||||
|
||||
Array<SaveSlot> array = control.getSaves().getSaveSlots();
|
||||
Array<SaveSlot> array = control.getSaves().getSaveSlots();
|
||||
|
||||
for(SaveSlot slot : array){
|
||||
for(SaveSlot slot : array){
|
||||
|
||||
TextButton button = new TextButton("[accent]" + slot.getName(), "clear");
|
||||
button.getLabelCell().growX().left();
|
||||
button.getLabelCell().padBottom(8f);
|
||||
button.getLabelCell().top().left().growX();
|
||||
TextButton button = new TextButton("[accent]" + slot.getName(), "clear");
|
||||
button.getLabelCell().growX().left();
|
||||
button.getLabelCell().padBottom(8f);
|
||||
button.getLabelCell().top().left().growX();
|
||||
|
||||
button.defaults().left();
|
||||
button.defaults().left();
|
||||
|
||||
button.table(t -> {
|
||||
t.right();
|
||||
button.table(t -> {
|
||||
t.right();
|
||||
|
||||
t.addImageButton("icon-floppy", "emptytoggle", 14*3, () -> {
|
||||
slot.setAutosave(!slot.isAutosave());
|
||||
}).checked(slot.isAutosave()).right();
|
||||
t.addImageButton("icon-floppy", "emptytoggle", 14 * 3, () -> {
|
||||
slot.setAutosave(!slot.isAutosave());
|
||||
}).checked(slot.isAutosave()).right();
|
||||
|
||||
t.addImageButton("icon-trash", "empty", 14*3, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.save.delete.confirm", () -> {
|
||||
slot.delete();
|
||||
setup();
|
||||
});
|
||||
}).size(14*3).right();
|
||||
t.addImageButton("icon-trash", "empty", 14 * 3, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.save.delete.confirm", () -> {
|
||||
slot.delete();
|
||||
setup();
|
||||
});
|
||||
}).size(14 * 3).right();
|
||||
|
||||
t.addImageButton("icon-pencil-small", "empty", 14*3, () -> {
|
||||
ui.showTextInput("$text.save.rename", "$text.save.rename.text", slot.getName(), text -> {
|
||||
slot.setName(text);
|
||||
setup();
|
||||
});
|
||||
}).size(14*3).right();
|
||||
t.addImageButton("icon-pencil-small", "empty", 14 * 3, () -> {
|
||||
ui.showTextInput("$text.save.rename", "$text.save.rename.text", slot.getName(), text -> {
|
||||
slot.setName(text);
|
||||
setup();
|
||||
});
|
||||
}).size(14 * 3).right();
|
||||
|
||||
if(!gwt) {
|
||||
t.addImageButton("icon-save", "empty", 14 * 3, () -> {
|
||||
if(!ios) {
|
||||
Platform.instance.showFileChooser(Bundles.get("text.save.export"), "Mindustry Save", file -> {
|
||||
try {
|
||||
slot.exportFile(file);
|
||||
setup();
|
||||
} catch (IOException e) {
|
||||
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}, false, saveExtension);
|
||||
if(!gwt){
|
||||
t.addImageButton("icon-save", "empty", 14 * 3, () -> {
|
||||
if(!ios){
|
||||
Platform.instance.showFileChooser(Bundles.get("text.save.export"), "Mindustry Save", file -> {
|
||||
try{
|
||||
slot.exportFile(file);
|
||||
setup();
|
||||
}catch(IOException e){
|
||||
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}, false, saveExtension);
|
||||
}else{
|
||||
try {
|
||||
try{
|
||||
FileHandle file = Gdx.files.local("save-" + slot.getName() + "." + Vars.saveExtension);
|
||||
slot.exportFile(file);
|
||||
Platform.instance.shareFile(file);
|
||||
}catch (Exception e){
|
||||
}catch(Exception e){
|
||||
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}
|
||||
}).size(14 * 3).right();
|
||||
}
|
||||
}).size(14 * 3).right();
|
||||
}
|
||||
|
||||
}).padRight(-10).growX();
|
||||
}).padRight(-10).growX();
|
||||
|
||||
String color = "[lightgray]";
|
||||
String color = "[lightgray]";
|
||||
|
||||
button.defaults().padBottom(3);
|
||||
button.row();
|
||||
button.add(Bundles.format("text.save.map", color+ (slot.getMap() == null ? "Unknown" : slot.getMap().meta.name())));
|
||||
button.row();
|
||||
button.add(Bundles.get("text.level.mode") + " " +color+ slot.getMode());
|
||||
button.row();
|
||||
button.add(Bundles.format("text.save.wave", color+slot.getWave()));
|
||||
button.row();
|
||||
button.add(Bundles.format("text.save.difficulty", color+slot.getDifficulty()));
|
||||
button.row();
|
||||
button.label(() -> Bundles.format("text.save.autosave", color + Bundles.get(slot.isAutosave() ? "text.on" : "text.off")));
|
||||
button.row();
|
||||
button.add(Bundles.format("text.save.date", color+slot.getDate())).colspan(2).padTop(5).right();
|
||||
button.row();
|
||||
modifyButton(button, slot);
|
||||
button.defaults().padBottom(3);
|
||||
button.row();
|
||||
button.add(Bundles.format("text.save.map", color + (slot.getMap() == null ? "Unknown" : slot.getMap().meta.name())));
|
||||
button.row();
|
||||
button.add(Bundles.get("text.level.mode") + " " + color + slot.getMode());
|
||||
button.row();
|
||||
button.add(Bundles.format("text.save.wave", color + slot.getWave()));
|
||||
button.row();
|
||||
button.add(Bundles.format("text.save.difficulty", color + slot.getDifficulty()));
|
||||
button.row();
|
||||
button.label(() -> Bundles.format("text.save.autosave", color + Bundles.get(slot.isAutosave() ? "text.on" : "text.off")));
|
||||
button.row();
|
||||
button.add(Bundles.format("text.save.date", color + slot.getDate())).colspan(2).padTop(5).right();
|
||||
button.row();
|
||||
modifyButton(button, slot);
|
||||
|
||||
slots.add(button).uniformX().fillX().pad(4).padRight(-4).margin(10f).marginLeft(20f).marginRight(20f);
|
||||
slots.row();
|
||||
}
|
||||
slots.add(button).uniformX().fillX().pad(4).padRight(-4).margin(10f).marginLeft(20f).marginRight(20f);
|
||||
slots.row();
|
||||
}
|
||||
|
||||
content().add(pane);
|
||||
content().add(pane);
|
||||
|
||||
addSetup();
|
||||
}
|
||||
addSetup();
|
||||
}
|
||||
|
||||
public void addSetup(){
|
||||
if(control.getSaves().getSaveSlots().size == 0) {
|
||||
public void addSetup(){
|
||||
if(control.getSaves().getSaveSlots().size == 0){
|
||||
|
||||
slots.row();
|
||||
slots.addButton("$text.save.none", "clear", () -> {
|
||||
}).disabled(true).fillX().margin(20f).minWidth(340f).height(80f).pad(4f);
|
||||
}
|
||||
slots.row();
|
||||
slots.addButton("$text.save.none", "clear", () -> {
|
||||
}).disabled(true).fillX().margin(20f).minWidth(340f).height(80f).pad(4f);
|
||||
}
|
||||
|
||||
slots.row();
|
||||
slots.row();
|
||||
|
||||
if(gwt || ios) return;
|
||||
if(gwt || ios) return;
|
||||
|
||||
slots.addImageTextButton("$text.save.import", "icon-add", "clear", 14*3, () -> {
|
||||
Platform.instance.showFileChooser(Bundles.get("text.save.import"), "Mindustry Save", file -> {
|
||||
if(SaveIO.isSaveValid(file)){
|
||||
try{
|
||||
control.getSaves().importSave(file);
|
||||
setup();
|
||||
}catch (IOException e){
|
||||
ui.showError(Bundles.format("text.save.import.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}else{
|
||||
ui.showError("$text.save.import.invalid");
|
||||
}
|
||||
}, true, saveExtension);
|
||||
}).fillX().margin(10f).minWidth(300f).height(70f).pad(4f).padRight(-4);
|
||||
}
|
||||
slots.addImageTextButton("$text.save.import", "icon-add", "clear", 14 * 3, () -> {
|
||||
Platform.instance.showFileChooser(Bundles.get("text.save.import"), "Mindustry Save", file -> {
|
||||
if(SaveIO.isSaveValid(file)){
|
||||
try{
|
||||
control.getSaves().importSave(file);
|
||||
setup();
|
||||
}catch(IOException e){
|
||||
ui.showError(Bundles.format("text.save.import.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}else{
|
||||
ui.showError("$text.save.import.invalid");
|
||||
}
|
||||
}, true, saveExtension);
|
||||
}).fillX().margin(10f).minWidth(300f).height(70f).pad(4f).padRight(-4);
|
||||
}
|
||||
|
||||
public void runLoadSave(SaveSlot slot){
|
||||
public void runLoadSave(SaveSlot slot){
|
||||
ui.loadfrag.show();
|
||||
|
||||
Timers.runTask(3f, () -> {
|
||||
@@ -187,11 +185,11 @@ public class LoadDialog extends FloatingDialog{
|
||||
});
|
||||
}
|
||||
|
||||
public void modifyButton(TextButton button, SaveSlot slot){
|
||||
button.clicked(() -> {
|
||||
if(!button.childrenPressed()){
|
||||
runLoadSave(slot);
|
||||
}
|
||||
});
|
||||
}
|
||||
public void modifyButton(TextButton button, SaveSlot slot){
|
||||
button.clicked(() -> {
|
||||
if(!button.childrenPressed()){
|
||||
runLoadSave(slot);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import com.badlogic.gdx.utils.Scaling;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.ui.Image;
|
||||
import io.anuke.ucore.scene.ui.layout.Stack;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
import static io.anuke.mindustry.Vars.control;
|
||||
import static io.anuke.mindustry.Vars.players;
|
||||
|
||||
public class LocalPlayerDialog extends FloatingDialog{
|
||||
|
||||
public LocalPlayerDialog() {
|
||||
public LocalPlayerDialog(){
|
||||
super("$text.addplayers");
|
||||
|
||||
addCloseButton();
|
||||
@@ -22,7 +24,7 @@ public class LocalPlayerDialog extends FloatingDialog{
|
||||
|
||||
content().clear();
|
||||
|
||||
if(players.length > 1) {
|
||||
if(players.length > 1){
|
||||
content().addImageButton("icon-cancel", 14 * 2, () -> {
|
||||
control.removePlayer();
|
||||
rebuild();
|
||||
@@ -49,7 +51,7 @@ public class LocalPlayerDialog extends FloatingDialog{
|
||||
content().add(table).pad(5);
|
||||
}
|
||||
|
||||
if(players.length < 4) {
|
||||
if(players.length < 4){
|
||||
content().addImageButton("icon-add", 14 * 2, () -> {
|
||||
control.addPlayer(players.length);
|
||||
rebuild();
|
||||
|
||||
@@ -22,13 +22,13 @@ import java.io.DataInputStream;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class MapsDialog extends FloatingDialog {
|
||||
public class MapsDialog extends FloatingDialog{
|
||||
|
||||
public MapsDialog() {
|
||||
public MapsDialog(){
|
||||
super("$text.maps");
|
||||
|
||||
addCloseButton();
|
||||
buttons().addImageTextButton("$text.editor.importmap", "icon-add", 14*2, () -> {
|
||||
buttons().addImageTextButton("$text.editor.importmap", "icon-add", 14 * 2, () -> {
|
||||
Platform.instance.showFileChooser("$text.editor.importmap", "Map File", file -> {
|
||||
try{
|
||||
DataInputStream stream = new DataInputStream(file.read());
|
||||
@@ -50,7 +50,7 @@ public class MapsDialog extends FloatingDialog {
|
||||
setup();
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
}catch(Exception e){
|
||||
ui.showError(Bundles.format("text.editor.errorimageload", Strings.parseException(e, false)));
|
||||
Log.err(e);
|
||||
}
|
||||
@@ -86,11 +86,11 @@ public class MapsDialog extends FloatingDialog {
|
||||
button.row();
|
||||
button.addImage("white").growX().pad(4).color(Color.GRAY);
|
||||
button.row();
|
||||
((Image)button.stack(new Image(map.texture), new BorderImage(map.texture)).size(mapsize-20f).get().getChildren().first()).setScaling(Scaling.fit);
|
||||
((Image) button.stack(new Image(map.texture), new BorderImage(map.texture)).size(mapsize - 20f).get().getChildren().first()).setScaling(Scaling.fit);
|
||||
button.row();
|
||||
button.add(map.custom ? "$text.custom" : "$text.builtin").color(Color.GRAY).padTop(3);
|
||||
|
||||
i ++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if(world.maps().all().size == 0){
|
||||
@@ -139,13 +139,13 @@ public class MapsDialog extends FloatingDialog {
|
||||
|
||||
table.row();
|
||||
|
||||
table.addImageTextButton("$text.editor.openin", "icon-load-map", "clear", 16*2, () -> {
|
||||
table.addImageTextButton("$text.editor.openin", "icon-load-map", "clear", 16 * 2, () -> {
|
||||
Vars.ui.editor.beginEditMap(map.stream.get());
|
||||
dialog.hide();
|
||||
hide();
|
||||
}).fillX().height(50f).marginLeft(6);
|
||||
|
||||
table.addImageTextButton("$text.delete", "icon-trash-16", "clear", 16*2, () -> {
|
||||
table.addImageTextButton("$text.delete", "icon-trash-16", "clear", 16 * 2, () -> {
|
||||
ui.showConfirm("$text.confirm", Bundles.format("text.map.delete", map.name), () -> {
|
||||
world.maps().removeMap(map);
|
||||
dialog.hide();
|
||||
|
||||
@@ -11,136 +11,136 @@ import io.anuke.ucore.util.Bundles;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class PausedDialog extends FloatingDialog{
|
||||
private SaveDialog save = new SaveDialog();
|
||||
private LoadDialog load = new LoadDialog();
|
||||
public boolean wasPaused = false;
|
||||
public boolean wasPaused = false;
|
||||
private SaveDialog save = new SaveDialog();
|
||||
private LoadDialog load = new LoadDialog();
|
||||
|
||||
public PausedDialog() {
|
||||
super("$text.menu");
|
||||
setup();
|
||||
}
|
||||
public PausedDialog(){
|
||||
super("$text.menu");
|
||||
setup();
|
||||
}
|
||||
|
||||
void setup(){
|
||||
update(() -> {
|
||||
if(state.is(State.menu) && isShown()){
|
||||
hide();
|
||||
}
|
||||
});
|
||||
void setup(){
|
||||
update(() -> {
|
||||
if(state.is(State.menu) && isShown()){
|
||||
hide();
|
||||
}
|
||||
});
|
||||
|
||||
shown(() -> {
|
||||
wasPaused = state.is(State.paused);
|
||||
if(!Net.active()) state.set(State.paused);
|
||||
});
|
||||
|
||||
if(!mobile){
|
||||
content().defaults().width(220).height(50);
|
||||
shown(() -> {
|
||||
wasPaused = state.is(State.paused);
|
||||
if(!Net.active()) state.set(State.paused);
|
||||
});
|
||||
|
||||
content().addButton("$text.back", () -> {
|
||||
hide();
|
||||
if((!wasPaused || Net.active()) && !state.is(State.menu))
|
||||
state.set(State.playing);
|
||||
});
|
||||
if(!mobile){
|
||||
content().defaults().width(220).height(50);
|
||||
|
||||
content().row();
|
||||
content().addButton("$text.settings", ui.settings::show);
|
||||
content().addButton("$text.back", () -> {
|
||||
hide();
|
||||
if((!wasPaused || Net.active()) && !state.is(State.menu))
|
||||
state.set(State.playing);
|
||||
});
|
||||
|
||||
content().row();
|
||||
content().addButton("$text.savegame", () -> {
|
||||
save.show();
|
||||
});
|
||||
content().row();
|
||||
content().addButton("$text.settings", ui.settings::show);
|
||||
|
||||
content().row();
|
||||
content().addButton("$text.loadgame", () -> {
|
||||
load.show();
|
||||
}).disabled(b -> Net.active());
|
||||
content().row();
|
||||
content().addButton("$text.savegame", () -> {
|
||||
save.show();
|
||||
});
|
||||
|
||||
//Local multiplayer is currently functional, but disabled.
|
||||
content().row();
|
||||
content().addButton("$text.loadgame", () -> {
|
||||
load.show();
|
||||
}).disabled(b -> Net.active());
|
||||
|
||||
//Local multiplayer is currently functional, but disabled.
|
||||
/*
|
||||
content().row();
|
||||
content().addButton("$text.addplayers", () -> {
|
||||
ui.localplayers.show();
|
||||
}).disabled(b -> Net.active());*/
|
||||
|
||||
content().row();
|
||||
content().row();
|
||||
|
||||
content().addButton("$text.hostserver", () -> {
|
||||
if(!gwt){
|
||||
ui.host.show();
|
||||
}else{
|
||||
ui.showInfo("$text.host.web");
|
||||
}
|
||||
}).disabled(b -> Net.active());
|
||||
content().addButton("$text.hostserver", () -> {
|
||||
if(!gwt){
|
||||
ui.host.show();
|
||||
}else{
|
||||
ui.showInfo("$text.host.web");
|
||||
}
|
||||
}).disabled(b -> Net.active());
|
||||
|
||||
|
||||
content().row();
|
||||
|
||||
content().addButton("$text.quit", () -> {
|
||||
content().addButton("$text.quit", () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
|
||||
if(Net.client()) netClient.disconnectQuietly();
|
||||
runExitSave();
|
||||
hide();
|
||||
});
|
||||
});
|
||||
if(Net.client()) netClient.disconnectQuietly();
|
||||
runExitSave();
|
||||
hide();
|
||||
});
|
||||
});
|
||||
|
||||
}else{
|
||||
build.begin(content());
|
||||
|
||||
content().defaults().size(120f).pad(5);
|
||||
float isize = 14f*4;
|
||||
|
||||
new imagebutton("icon-play-2", isize, () -> {
|
||||
hide();
|
||||
if(!wasPaused && !state.is(State.menu))
|
||||
state.set(State.playing);
|
||||
}).text("$text.back").padTop(4f);
|
||||
|
||||
new imagebutton("icon-tools", isize, ui.settings::show).text("$text.settings").padTop(4f);
|
||||
|
||||
imagebutton sa = new imagebutton("icon-save", isize, save::show);
|
||||
sa.text("$text.save").padTop(4f);
|
||||
}else{
|
||||
build.begin(content());
|
||||
|
||||
content().row();
|
||||
|
||||
imagebutton lo = new imagebutton("icon-load", isize, load::show);
|
||||
lo.text("$text.load").padTop(4f);
|
||||
lo.cell.disabled(b -> Net.active());
|
||||
content().defaults().size(120f).pad(5);
|
||||
float isize = 14f * 4;
|
||||
|
||||
imagebutton ho = new imagebutton("icon-host", isize, () -> {
|
||||
ui.host.show();
|
||||
});
|
||||
ho.text("$text.host").padTop(4f);
|
||||
ho.cell.disabled(b -> Net.active());
|
||||
|
||||
new imagebutton("icon-quit", isize, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
|
||||
if(Net.client()) netClient.disconnectQuietly();
|
||||
runExitSave();
|
||||
hide();
|
||||
});
|
||||
}).text("Quit").padTop(4f);
|
||||
|
||||
build.end();
|
||||
}
|
||||
}
|
||||
new imagebutton("icon-play-2", isize, () -> {
|
||||
hide();
|
||||
if(!wasPaused && !state.is(State.menu))
|
||||
state.set(State.playing);
|
||||
}).text("$text.back").padTop(4f);
|
||||
|
||||
private void runExitSave(){
|
||||
if(control.getSaves().getCurrent() == null ||
|
||||
!control.getSaves().getCurrent().isAutosave()){
|
||||
state.set(State.menu);
|
||||
return;
|
||||
}
|
||||
new imagebutton("icon-tools", isize, ui.settings::show).text("$text.settings").padTop(4f);
|
||||
|
||||
ui.loadfrag.show("$text.saveload");
|
||||
imagebutton sa = new imagebutton("icon-save", isize, save::show);
|
||||
sa.text("$text.save").padTop(4f);
|
||||
|
||||
Timers.runTask(5f, () -> {
|
||||
ui.loadfrag.hide();
|
||||
try{
|
||||
control.getSaves().getCurrent().save();
|
||||
}catch(Throwable e){
|
||||
e = (e.getCause() == null ? e : e.getCause());
|
||||
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());
|
||||
}
|
||||
state.set(State.menu);
|
||||
});
|
||||
}
|
||||
content().row();
|
||||
|
||||
imagebutton lo = new imagebutton("icon-load", isize, load::show);
|
||||
lo.text("$text.load").padTop(4f);
|
||||
lo.cell.disabled(b -> Net.active());
|
||||
|
||||
imagebutton ho = new imagebutton("icon-host", isize, () -> {
|
||||
ui.host.show();
|
||||
});
|
||||
ho.text("$text.host").padTop(4f);
|
||||
ho.cell.disabled(b -> Net.active());
|
||||
|
||||
new imagebutton("icon-quit", isize, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
|
||||
if(Net.client()) netClient.disconnectQuietly();
|
||||
runExitSave();
|
||||
hide();
|
||||
});
|
||||
}).text("Quit").padTop(4f);
|
||||
|
||||
build.end();
|
||||
}
|
||||
}
|
||||
|
||||
private void runExitSave(){
|
||||
if(control.getSaves().getCurrent() == null ||
|
||||
!control.getSaves().getCurrent().isAutosave()){
|
||||
state.set(State.menu);
|
||||
return;
|
||||
}
|
||||
|
||||
ui.loadfrag.show("$text.saveload");
|
||||
|
||||
Timers.runTask(5f, () -> {
|
||||
ui.loadfrag.hide();
|
||||
try{
|
||||
control.getSaves().getCurrent().save();
|
||||
}catch(Throwable e){
|
||||
e = (e.getCause() == null ? e : e.getCause());
|
||||
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());
|
||||
}
|
||||
state.set(State.menu);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import io.anuke.ucore.scene.ui.Dialog;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class RestartDialog extends Dialog {
|
||||
|
||||
public class RestartDialog extends Dialog{
|
||||
|
||||
public RestartDialog(){
|
||||
super("$text.gameover", "dialog");
|
||||
|
||||
@@ -21,7 +21,7 @@ public class RestartDialog extends Dialog {
|
||||
pack();
|
||||
});
|
||||
|
||||
getButtonTable().addButton("$text.menu", ()-> {
|
||||
getButtonTable().addButton("$text.menu", () -> {
|
||||
hide();
|
||||
state.set(State.menu);
|
||||
logic.reset();
|
||||
|
||||
@@ -5,34 +5,35 @@ import io.anuke.ucore.util.Strings;
|
||||
|
||||
import static io.anuke.mindustry.Vars.gwt;
|
||||
|
||||
public class RollbackDialog extends FloatingDialog {
|
||||
|
||||
public RollbackDialog(){
|
||||
super("$text.server.rollback");
|
||||
|
||||
setup();
|
||||
shown(this::setup);
|
||||
}
|
||||
|
||||
private void setup(){
|
||||
content().clear();
|
||||
buttons().clear();
|
||||
|
||||
if(gwt) return;
|
||||
|
||||
content().row();
|
||||
content().add("$text.server.rollback.numberfield");
|
||||
|
||||
TextField field = content().addField("", t->{}).size(200f, 48f).get();
|
||||
field.setTextFieldFilter((f, c) -> field.getText().length() < 4);
|
||||
|
||||
content().row();
|
||||
buttons().defaults().size(200f, 50f).left().pad(2f);
|
||||
buttons().addButton("$text.cancel", this::hide);
|
||||
|
||||
buttons().addButton("$text.ok", () -> {
|
||||
//NetEvents.handleRollbackRequest(Integer.valueOf(field.getText()));
|
||||
hide();
|
||||
}).disabled(b -> field.getText().isEmpty() || !Strings.canParsePostiveInt(field.getText()));
|
||||
}
|
||||
public class RollbackDialog extends FloatingDialog{
|
||||
|
||||
public RollbackDialog(){
|
||||
super("$text.server.rollback");
|
||||
|
||||
setup();
|
||||
shown(this::setup);
|
||||
}
|
||||
|
||||
private void setup(){
|
||||
content().clear();
|
||||
buttons().clear();
|
||||
|
||||
if(gwt) return;
|
||||
|
||||
content().row();
|
||||
content().add("$text.server.rollback.numberfield");
|
||||
|
||||
TextField field = content().addField("", t -> {
|
||||
}).size(200f, 48f).get();
|
||||
field.setTextFieldFilter((f, c) -> field.getText().length() < 4);
|
||||
|
||||
content().row();
|
||||
buttons().defaults().size(200f, 50f).left().pad(2f);
|
||||
buttons().addButton("$text.cancel", this::hide);
|
||||
|
||||
buttons().addButton("$text.ok", () -> {
|
||||
//NetEvents.handleRollbackRequest(Integer.valueOf(field.getText()));
|
||||
hide();
|
||||
}).disabled(b -> field.getText().isEmpty() || !Strings.canParsePostiveInt(field.getText()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,57 +11,57 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class SaveDialog extends LoadDialog{
|
||||
|
||||
public SaveDialog() {
|
||||
super("$text.savegame");
|
||||
public SaveDialog(){
|
||||
super("$text.savegame");
|
||||
|
||||
update(() -> {
|
||||
if(state.is(State.menu) && isShown()){
|
||||
hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
update(() -> {
|
||||
if(state.is(State.menu) && isShown()){
|
||||
hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addSetup(){
|
||||
if(!control.getSaves().canAddSave()){
|
||||
return;
|
||||
}
|
||||
public void addSetup(){
|
||||
if(!control.getSaves().canAddSave()){
|
||||
return;
|
||||
}
|
||||
|
||||
slots.row();
|
||||
slots.addImageTextButton("$text.save.new", "icon-add", "clear", 14*3, () ->
|
||||
ui.showTextInput("$text.save", "$text.save.newslot", "", text -> {
|
||||
ui.loadAnd("$text.saving", () -> {
|
||||
control.getSaves().addSave(text);
|
||||
setup();
|
||||
});
|
||||
})
|
||||
).fillX().margin(10f).minWidth(300f).height(70f).pad(4f).padRight(-4);
|
||||
}
|
||||
slots.row();
|
||||
slots.addImageTextButton("$text.save.new", "icon-add", "clear", 14 * 3, () ->
|
||||
ui.showTextInput("$text.save", "$text.save.newslot", "", text -> {
|
||||
ui.loadAnd("$text.saving", () -> {
|
||||
control.getSaves().addSave(text);
|
||||
setup();
|
||||
});
|
||||
})
|
||||
).fillX().margin(10f).minWidth(300f).height(70f).pad(4f).padRight(-4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyButton(TextButton button, SaveSlot slot){
|
||||
button.clicked(() -> {
|
||||
if(button.childrenPressed()) return;
|
||||
@Override
|
||||
public void modifyButton(TextButton button, SaveSlot slot){
|
||||
button.clicked(() -> {
|
||||
if(button.childrenPressed()) return;
|
||||
|
||||
ui.showConfirm("$text.overwrite", "$text.save.overwrite", () -> save(slot));
|
||||
});
|
||||
}
|
||||
ui.showConfirm("$text.overwrite", "$text.save.overwrite", () -> save(slot));
|
||||
});
|
||||
}
|
||||
|
||||
void save(SaveSlot slot){
|
||||
void save(SaveSlot slot){
|
||||
|
||||
ui.loadfrag.show("$text.saveload");
|
||||
ui.loadfrag.show("$text.saveload");
|
||||
|
||||
Timers.runTask(5f, () -> {
|
||||
hide();
|
||||
ui.loadfrag.hide();
|
||||
try{
|
||||
slot.save();
|
||||
}catch(Throwable e){
|
||||
e.printStackTrace();
|
||||
e = (e.getCause() == null ? e : e.getCause());
|
||||
Timers.runTask(5f, () -> {
|
||||
hide();
|
||||
ui.loadfrag.hide();
|
||||
try{
|
||||
slot.save();
|
||||
}catch(Throwable e){
|
||||
e.printStackTrace();
|
||||
e = (e.getCause() == null ? e : e.getCause());
|
||||
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,164 +24,164 @@ import io.anuke.ucore.util.Mathf;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class SettingsMenuDialog extends SettingsDialog{
|
||||
public SettingsTable graphics;
|
||||
public SettingsTable game;
|
||||
public SettingsTable sound;
|
||||
public SettingsTable graphics;
|
||||
public SettingsTable game;
|
||||
public SettingsTable sound;
|
||||
|
||||
private Table prefs;
|
||||
private Table menu;
|
||||
private boolean wasPaused;
|
||||
|
||||
public SettingsMenuDialog(){
|
||||
setStyle(Core.skin.get("dialog", WindowStyle.class));
|
||||
private Table prefs;
|
||||
private Table menu;
|
||||
private boolean wasPaused;
|
||||
|
||||
hidden(() -> {
|
||||
if(!state.is(State.menu)){
|
||||
if(!wasPaused || Net.active())
|
||||
state.set(State.playing);
|
||||
}
|
||||
});
|
||||
public SettingsMenuDialog(){
|
||||
setStyle(Core.skin.get("dialog", WindowStyle.class));
|
||||
|
||||
shown(() -> {
|
||||
if(!state.is(State.menu)){
|
||||
wasPaused = state.is(State.paused);
|
||||
if(ui.paused.getScene() != null){
|
||||
wasPaused = ui.paused.wasPaused;
|
||||
}
|
||||
if(!Net.active()) state.set(State.paused);
|
||||
ui.paused.hide();
|
||||
}
|
||||
});
|
||||
hidden(() -> {
|
||||
if(!state.is(State.menu)){
|
||||
if(!wasPaused || Net.active())
|
||||
state.set(State.playing);
|
||||
}
|
||||
});
|
||||
|
||||
setFillParent(true);
|
||||
title().setAlignment(Align.center);
|
||||
getTitleTable().row();
|
||||
getTitleTable().add(new Image("white"))
|
||||
.growX().height(3f).pad(4f).get().setColor(Palette.accent);
|
||||
shown(() -> {
|
||||
if(!state.is(State.menu)){
|
||||
wasPaused = state.is(State.paused);
|
||||
if(ui.paused.getScene() != null){
|
||||
wasPaused = ui.paused.wasPaused;
|
||||
}
|
||||
if(!Net.active()) state.set(State.paused);
|
||||
ui.paused.hide();
|
||||
}
|
||||
});
|
||||
|
||||
content().clearChildren();
|
||||
content().remove();
|
||||
buttons().remove();
|
||||
setFillParent(true);
|
||||
title().setAlignment(Align.center);
|
||||
getTitleTable().row();
|
||||
getTitleTable().add(new Image("white"))
|
||||
.growX().height(3f).pad(4f).get().setColor(Palette.accent);
|
||||
|
||||
menu = new Table();
|
||||
content().clearChildren();
|
||||
content().remove();
|
||||
buttons().remove();
|
||||
|
||||
Consumer<SettingsTable> s = table -> {
|
||||
table.row();
|
||||
table.addImageTextButton("$text.back", "icon-arrow-left", 10*3, this::back).size(240f, 60f).colspan(2).padTop(15f);
|
||||
};
|
||||
menu = new Table();
|
||||
|
||||
game = new SettingsTable(s);
|
||||
graphics = new SettingsTable(s);
|
||||
sound = new SettingsTable(s);
|
||||
Consumer<SettingsTable> s = table -> {
|
||||
table.row();
|
||||
table.addImageTextButton("$text.back", "icon-arrow-left", 10 * 3, this::back).size(240f, 60f).colspan(2).padTop(15f);
|
||||
};
|
||||
|
||||
prefs = new Table();
|
||||
prefs.top();
|
||||
prefs.margin(14f);
|
||||
game = new SettingsTable(s);
|
||||
graphics = new SettingsTable(s);
|
||||
sound = new SettingsTable(s);
|
||||
|
||||
menu.defaults().size(300f, 60f).pad(3f);
|
||||
menu.addButton("$text.settings.game", () -> visible(0));
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.graphics", () -> visible(1));
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.sound", () -> visible(2));
|
||||
if(!Vars.mobile) {
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.controls", ui.controls::show);
|
||||
}
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.language", ui.language::show);
|
||||
prefs = new Table();
|
||||
prefs.top();
|
||||
prefs.margin(14f);
|
||||
|
||||
prefs.clearChildren();
|
||||
prefs.add(menu);
|
||||
menu.defaults().size(300f, 60f).pad(3f);
|
||||
menu.addButton("$text.settings.game", () -> visible(0));
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.graphics", () -> visible(1));
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.sound", () -> visible(2));
|
||||
if(!Vars.mobile){
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.controls", ui.controls::show);
|
||||
}
|
||||
menu.row();
|
||||
menu.addButton("$text.settings.language", ui.language::show);
|
||||
|
||||
ScrollPane pane = new ScrollPane(prefs, "clear");
|
||||
pane.addCaptureListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
Element actor = pane.hit(x, y, true);
|
||||
if (actor instanceof Slider) {
|
||||
pane.setFlickScroll(false);
|
||||
return true;
|
||||
}
|
||||
prefs.clearChildren();
|
||||
prefs.add(menu);
|
||||
|
||||
return super.touchDown(event, x, y, pointer, button);
|
||||
}
|
||||
ScrollPane pane = new ScrollPane(prefs, "clear");
|
||||
pane.addCaptureListener(new InputListener(){
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
|
||||
Element actor = pane.hit(x, y, true);
|
||||
if(actor instanceof Slider){
|
||||
pane.setFlickScroll(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
|
||||
pane.setFlickScroll(true);
|
||||
super.touchUp(event, x, y, pointer, button);
|
||||
}
|
||||
});
|
||||
pane.setFadeScrollBars(false);
|
||||
return super.touchDown(event, x, y, pointer, button);
|
||||
}
|
||||
|
||||
row();
|
||||
add(pane).grow().top();
|
||||
row();
|
||||
add(buttons()).fillX();
|
||||
@Override
|
||||
public void touchUp(InputEvent event, float x, float y, int pointer, int button){
|
||||
pane.setFlickScroll(true);
|
||||
super.touchUp(event, x, y, pointer, button);
|
||||
}
|
||||
});
|
||||
pane.setFadeScrollBars(false);
|
||||
|
||||
hidden(this::back);
|
||||
row();
|
||||
add(pane).grow().top();
|
||||
row();
|
||||
add(buttons()).fillX();
|
||||
|
||||
addSettings();
|
||||
}
|
||||
hidden(this::back);
|
||||
|
||||
void addSettings(){
|
||||
sound.volumePrefs();
|
||||
addSettings();
|
||||
}
|
||||
|
||||
game.screenshakePref();
|
||||
//game.checkPref("smoothcam", true);
|
||||
game.checkPref("effects", true);
|
||||
//game.sliderPref("sensitivity", 100, 10, 300, i -> i + "%");
|
||||
game.sliderPref("saveinterval", 90, 10, 5*120, i -> Bundles.format("setting.seconds", i));
|
||||
void addSettings(){
|
||||
sound.volumePrefs();
|
||||
|
||||
if(!gwt){
|
||||
graphics.checkPref("multithread", true, threads::setEnabled);
|
||||
game.screenshakePref();
|
||||
//game.checkPref("smoothcam", true);
|
||||
game.checkPref("effects", true);
|
||||
//game.sliderPref("sensitivity", 100, 10, 300, i -> i + "%");
|
||||
game.sliderPref("saveinterval", 90, 10, 5 * 120, i -> Bundles.format("setting.seconds", i));
|
||||
|
||||
if(Settings.getBool("multithread")){
|
||||
threads.setEnabled(true);
|
||||
}
|
||||
}
|
||||
if(!gwt){
|
||||
graphics.checkPref("multithread", true, threads::setEnabled);
|
||||
|
||||
if(!mobile && !gwt) {
|
||||
graphics.checkPref("vsync", true, b -> Gdx.graphics.setVSync(b));
|
||||
graphics.checkPref("fullscreen", false, b -> {
|
||||
if (b) {
|
||||
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
|
||||
} else {
|
||||
Gdx.graphics.setWindowedMode(600, 480);
|
||||
}
|
||||
});
|
||||
if(Settings.getBool("multithread")){
|
||||
threads.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
Gdx.graphics.setVSync(Settings.getBool("vsync"));
|
||||
if(Settings.getBool("fullscreen")){
|
||||
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
|
||||
}
|
||||
}
|
||||
if(!mobile && !gwt){
|
||||
graphics.checkPref("vsync", true, b -> Gdx.graphics.setVSync(b));
|
||||
graphics.checkPref("fullscreen", false, b -> {
|
||||
if(b){
|
||||
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
|
||||
}else{
|
||||
Gdx.graphics.setWindowedMode(600, 480);
|
||||
}
|
||||
});
|
||||
|
||||
graphics.checkPref("fps", false);
|
||||
graphics.checkPref("lasers", true);
|
||||
graphics.checkPref("healthbars", true);
|
||||
graphics.checkPref("minimap", !mobile); //minimap is disabled by default on mobile devices
|
||||
}
|
||||
Gdx.graphics.setVSync(Settings.getBool("vsync"));
|
||||
if(Settings.getBool("fullscreen")){
|
||||
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
|
||||
}
|
||||
}
|
||||
|
||||
private void back(){
|
||||
prefs.clearChildren();
|
||||
prefs.add(menu);
|
||||
}
|
||||
graphics.checkPref("fps", false);
|
||||
graphics.checkPref("lasers", true);
|
||||
graphics.checkPref("healthbars", true);
|
||||
graphics.checkPref("minimap", !mobile); //minimap is disabled by default on mobile devices
|
||||
}
|
||||
|
||||
private void visible(int index){
|
||||
prefs.clearChildren();
|
||||
Table table = Mathf.select(index, game, graphics, sound);
|
||||
private void back(){
|
||||
prefs.clearChildren();
|
||||
prefs.add(menu);
|
||||
}
|
||||
|
||||
private void visible(int index){
|
||||
prefs.clearChildren();
|
||||
Table table = Mathf.select(index, game, graphics, sound);
|
||||
prefs.add(table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCloseButton(){
|
||||
buttons().addImageTextButton("$text.menu", "icon-arrow-left", 30f, this::hide).size(230f, 64f);
|
||||
|
||||
keyDown(key->{
|
||||
if(key == Keys.ESCAPE || key == Keys.BACK)
|
||||
hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCloseButton(){
|
||||
buttons().addImageTextButton("$text.menu", "icon-arrow-left", 30f, this::hide).size(230f, 64f);
|
||||
|
||||
keyDown(key -> {
|
||||
if(key == Keys.ESCAPE || key == Keys.BACK)
|
||||
hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import io.anuke.mindustry.net.TraceInfo;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
public class TraceDialog extends FloatingDialog {
|
||||
public class TraceDialog extends FloatingDialog{
|
||||
|
||||
public TraceDialog(){
|
||||
super("$text.trace");
|
||||
|
||||
@@ -15,9 +15,9 @@ import io.anuke.ucore.scene.utils.UIUtils;
|
||||
|
||||
import static io.anuke.mindustry.Vars.control;
|
||||
|
||||
public class UnlocksDialog extends FloatingDialog {
|
||||
public class UnlocksDialog extends FloatingDialog{
|
||||
|
||||
public UnlocksDialog() {
|
||||
public UnlocksDialog(){
|
||||
super("$text.unlocks");
|
||||
|
||||
addCloseButton();
|
||||
@@ -38,7 +38,7 @@ public class UnlocksDialog extends FloatingDialog {
|
||||
Array<Content> array = allContent.get(key);
|
||||
if(array.size == 0 || !(array.first() instanceof UnlockableContent)) continue;
|
||||
|
||||
table.add("$content." +key + ".name").growX().left().color(Palette.accent);
|
||||
table.add("$content." + key + ".name").growX().left().color(Palette.accent);
|
||||
table.row();
|
||||
table.addImage("white").growX().pad(5).padLeft(0).padRight(0).height(3).color(Palette.accent);
|
||||
table.row();
|
||||
@@ -46,19 +46,19 @@ public class UnlocksDialog extends FloatingDialog {
|
||||
list.left();
|
||||
|
||||
int maxWidth = UIUtils.portrait() ? 7 : 13;
|
||||
int size = 8*6;
|
||||
int size = 8 * 6;
|
||||
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < array.size; i++) {
|
||||
UnlockableContent unlock = (UnlockableContent)array.get(i);
|
||||
for(int i = 0; i < array.size; i++){
|
||||
UnlockableContent unlock = (UnlockableContent) array.get(i);
|
||||
|
||||
if(unlock.isHidden()) continue;
|
||||
|
||||
Image image = control.database().isUnlocked(unlock) ? new Image(unlock.getContentIcon()) : new Image("icon-locked");
|
||||
list.add(image).size(size).pad(3);
|
||||
|
||||
if(control.database().isUnlocked(unlock)) {
|
||||
if(control.database().isUnlocked(unlock)){
|
||||
image.clicked(() -> Vars.ui.content.show(unlock));
|
||||
image.addListener(new Tooltip<>(new Table("clear"){{
|
||||
add(unlock.localizedName());
|
||||
|
||||
@@ -10,29 +10,29 @@ import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
|
||||
public class BackgroundFragment extends Fragment {
|
||||
public class BackgroundFragment extends Fragment{
|
||||
|
||||
@Override
|
||||
public void build(Group parent) {
|
||||
public void build(Group parent){
|
||||
|
||||
Core.scene.table().addRect((a, b, w, h) -> {
|
||||
Draw.color();
|
||||
|
||||
TextureRegion back = Draw.region("background");
|
||||
float backscl = (int)Math.max(Gdx.graphics.getWidth() / (float)back.getRegionWidth() * 1.5f, Unit.dp.scl(5f));
|
||||
float backscl = (int) Math.max(Gdx.graphics.getWidth() / (float) back.getRegionWidth() * 1.5f, Unit.dp.scl(5f));
|
||||
|
||||
Draw.alpha(0.5f);
|
||||
Core.batch.draw(back, w/2 - back.getRegionWidth()*backscl/2, h/2 - back.getRegionHeight()*backscl/2,
|
||||
back.getRegionWidth()*backscl, back.getRegionHeight()*backscl);
|
||||
Core.batch.draw(back, w / 2 - back.getRegionWidth() * backscl / 2, h / 2 - back.getRegionHeight() * backscl / 2,
|
||||
back.getRegionWidth() * backscl, back.getRegionHeight() * backscl);
|
||||
|
||||
boolean portrait = Gdx.graphics.getWidth() < Gdx.graphics.getHeight();
|
||||
float logoscl = (int)Unit.dp.scl(7) * (portrait ? 5f/7f : 1f);
|
||||
float logoscl = (int) Unit.dp.scl(7) * (portrait ? 5f / 7f : 1f);
|
||||
TextureRegion logo = Core.skin.getRegion("logotext");
|
||||
float logow = logo.getRegionWidth()*logoscl;
|
||||
float logoh = logo.getRegionHeight()*logoscl;
|
||||
float logow = logo.getRegionWidth() * logoscl;
|
||||
float logoh = logo.getRegionHeight() * logoscl;
|
||||
|
||||
Draw.color();
|
||||
Core.batch.draw(logo, (int)(w/2 - logow/2), (int)(h - logoh + 15 - Unit.dp.scl(portrait ? 30f : 0)), logow, logoh);
|
||||
Core.batch.draw(logo, (int) (w / 2 - logow / 2), (int) (h - logoh + 15 - Unit.dp.scl(portrait ? 30f : 0)), logow, logoh);
|
||||
}).visible(() -> state.is(State.menu)).grow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.badlogic.gdx.utils.Align;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
@@ -18,17 +19,18 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public class BlockConfigFragment extends Fragment {
|
||||
public class BlockConfigFragment extends Fragment{
|
||||
private Table table = new Table();
|
||||
private InputHandler input;
|
||||
private Tile configTile;
|
||||
private Block configBlock;
|
||||
|
||||
public BlockConfigFragment(InputHandler input){
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Group parent) {
|
||||
public void build(Group parent){
|
||||
parent.addChild(table);
|
||||
}
|
||||
|
||||
@@ -42,6 +44,7 @@ public class BlockConfigFragment extends Fragment {
|
||||
|
||||
public void showConfig(Tile tile){
|
||||
configTile = tile;
|
||||
configBlock = tile.block();
|
||||
|
||||
table.setVisible(true);
|
||||
table.clear();
|
||||
@@ -63,9 +66,9 @@ public class BlockConfigFragment extends Fragment {
|
||||
}
|
||||
|
||||
table.setOrigin(Align.center);
|
||||
Vector2 pos = Graphics.screen(tile.drawx(), tile.drawy() - tile.block().size * tilesize/2f - 1);
|
||||
Vector2 pos = Graphics.screen(tile.drawx(), tile.drawy() - tile.block().size * tilesize / 2f - 1);
|
||||
table.setPosition(pos.x, pos.y, Align.top);
|
||||
if(configTile == null || configTile.block() == Blocks.air){
|
||||
if(configTile == null || configTile.block() == Blocks.air || configTile.block() != configBlock){
|
||||
hideConfig();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -17,12 +17,12 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class BlockConsumeFragment extends Fragment {
|
||||
public class BlockConsumeFragment extends Fragment{
|
||||
private Table table;
|
||||
private boolean visible;
|
||||
|
||||
@Override
|
||||
public void build(Group parent) {
|
||||
public void build(Group parent){
|
||||
table = new Table();
|
||||
table.setVisible(() -> !state.is(State.menu) && visible);
|
||||
table.setTransform(true);
|
||||
@@ -68,7 +68,7 @@ public class BlockConsumeFragment extends Fragment {
|
||||
rebuild(block, entity);
|
||||
}
|
||||
|
||||
Vector2 v = Graphics.screen(tile.drawx() - tile.block().size * tilesize/2f, tile.drawy() + tile.block().size * tilesize/2f);
|
||||
Vector2 v = Graphics.screen(tile.drawx() - tile.block().size * tilesize / 2f, tile.drawy() + tile.block().size * tilesize / 2f);
|
||||
table.pack();
|
||||
table.setPosition(v.x, v.y, Align.topRight);
|
||||
});
|
||||
@@ -78,7 +78,8 @@ public class BlockConsumeFragment extends Fragment {
|
||||
|
||||
public void hide(){
|
||||
table.clear();
|
||||
table.update(() -> {});
|
||||
table.update(() -> {
|
||||
});
|
||||
visible = false;
|
||||
}
|
||||
|
||||
@@ -97,10 +98,10 @@ public class BlockConsumeFragment extends Fragment {
|
||||
}).get().act(0);
|
||||
|
||||
Table result = table.table(out -> {
|
||||
out.addImage(c.getIcon()).size(10*scale).color(Color.DARK_GRAY).padRight(-10*scale).padBottom(-scale*2);
|
||||
out.addImage(c.getIcon()).size(10*scale).color(Palette.accent);
|
||||
out.addImage("icon-missing").size(10*scale).color(Palette.remove).padLeft(-10*scale);
|
||||
}).size(10*scale).get();
|
||||
out.addImage(c.getIcon()).size(10 * scale).color(Color.DARK_GRAY).padRight(-10 * scale).padBottom(-scale * 2);
|
||||
out.addImage(c.getIcon()).size(10 * scale).color(Palette.accent);
|
||||
out.addImage("icon-missing").size(10 * scale).color(Palette.remove).padLeft(-10 * scale);
|
||||
}).size(10 * scale).get();
|
||||
|
||||
result.hovered(() -> hovered[0] = true);
|
||||
if(!mobile){
|
||||
|
||||
@@ -30,7 +30,7 @@ import io.anuke.ucore.util.Strings;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class BlockInventoryFragment extends Fragment {
|
||||
public class BlockInventoryFragment extends Fragment{
|
||||
private final static float holdWithdraw = 40f;
|
||||
|
||||
private Table table;
|
||||
@@ -44,8 +44,20 @@ public class BlockInventoryFragment extends Fragment {
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server, targets = Loc.both, in = In.blocks, forward = true)
|
||||
public static void requestItem(Player player, Tile tile, Item item, int amount){
|
||||
if(player == null) return;
|
||||
|
||||
int removed = tile.block().removeStack(tile, item, amount);
|
||||
|
||||
player.inventory.addItem(item, removed);
|
||||
for(int j = 0; j < Mathf.clamp(removed / 3, 1, 8); j++){
|
||||
Timers.run(j * 3f, () -> CallEntity.transferItemEffect(item, tile.drawx(), tile.drawy(), player));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Group parent) {
|
||||
public void build(Group parent){
|
||||
table = new Table();
|
||||
table.setVisible(() -> !state.is(State.menu));
|
||||
table.setTransform(true);
|
||||
@@ -55,7 +67,8 @@ public class BlockInventoryFragment extends Fragment {
|
||||
|
||||
public void showFor(Tile t){
|
||||
this.tile = t.target();
|
||||
if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.total() == 0) return;
|
||||
if(tile == null || tile.entity == null || !tile.block().isAccessible() || tile.entity.items.total() == 0)
|
||||
return;
|
||||
rebuild(true);
|
||||
}
|
||||
|
||||
@@ -93,10 +106,10 @@ public class BlockInventoryFragment extends Fragment {
|
||||
}
|
||||
|
||||
updateTablePosition();
|
||||
if(tile.block().hasItems) {
|
||||
for (int i = 0; i < Item.all().size; i++) {
|
||||
if(tile.block().hasItems){
|
||||
for(int i = 0; i < Item.all().size; i++){
|
||||
boolean has = tile.entity.items.has(Item.getByID(i));
|
||||
if (has != container.contains(i)) {
|
||||
if(has != container.contains(i)){
|
||||
rebuild(false);
|
||||
}
|
||||
}
|
||||
@@ -108,13 +121,13 @@ public class BlockInventoryFragment extends Fragment {
|
||||
int row = 0;
|
||||
|
||||
table.margin(6f);
|
||||
table.defaults().size(mobile ? 16*3 : 16*2).space(6f);
|
||||
table.defaults().size(mobile ? 16 * 3 : 16 * 2).space(6f);
|
||||
|
||||
if(tile.block().hasItems) {
|
||||
if(tile.block().hasItems){
|
||||
|
||||
for (int i = 0; i < Item.all().size; i++) {
|
||||
for(int i = 0; i < Item.all().size; i++){
|
||||
Item item = Item.getByID(i);
|
||||
if (!tile.entity.items.has(item)) continue;
|
||||
if(!tile.entity.items.has(item)) continue;
|
||||
|
||||
container.add(i);
|
||||
|
||||
@@ -133,7 +146,7 @@ public class BlockInventoryFragment extends Fragment {
|
||||
|
||||
image.addListener(new InputListener(){
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
|
||||
if(!canPick.get() || !tile.entity.items.has(item)) return false;
|
||||
int amount = Math.min(1, player.inventory.itemCapacityUsed(item));
|
||||
CallBlocks.requestItem(player, tile, item, amount);
|
||||
@@ -144,14 +157,14 @@ public class BlockInventoryFragment extends Fragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
|
||||
public void touchUp(InputEvent event, float x, float y, int pointer, int button){
|
||||
holding = false;
|
||||
lastItem = null;
|
||||
}
|
||||
});
|
||||
table.add(image);
|
||||
|
||||
if (row++ % cols == cols - 1) table.row();
|
||||
if(row++ % cols == cols - 1) table.row();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,29 +181,17 @@ public class BlockInventoryFragment extends Fragment {
|
||||
}
|
||||
|
||||
private String round(float f){
|
||||
f = (int)f;
|
||||
f = (int) f;
|
||||
if(f >= 1000){
|
||||
return Strings.toFixed(f/1000, 1) + "k";
|
||||
return Strings.toFixed(f / 1000, 1) + "k";
|
||||
}else{
|
||||
return (int)f+"";
|
||||
return (int) f + "";
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTablePosition(){
|
||||
Vector2 v = Graphics.screen(tile.drawx() + tile.block().size * tilesize/2f, tile.drawy() + tile.block().size * tilesize/2f);
|
||||
Vector2 v = Graphics.screen(tile.drawx() + tile.block().size * tilesize / 2f, tile.drawy() + tile.block().size * tilesize / 2f);
|
||||
table.pack();
|
||||
table.setPosition(v.x, v.y, Align.topLeft);
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server, targets = Loc.both, in = In.blocks, forward = true)
|
||||
public static void requestItem(Player player, Tile tile, Item item, int amount){
|
||||
if(player == null) return;
|
||||
|
||||
int removed = tile.block().removeStack(tile, item, amount);
|
||||
|
||||
player.inventory.addItem(item, removed);
|
||||
for(int j = 0; j < Mathf.clamp(removed/3, 1, 8); j ++){
|
||||
Timers.run(j*3f, () -> CallEntity.transferItemEffect(item, tile.drawx(), tile.drawy(), player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,327 +29,344 @@ import io.anuke.ucore.util.Strings;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class BlocksFragment extends Fragment{
|
||||
/**Table containing description that is shown on top.*/
|
||||
private Table descTable;
|
||||
/**Main table containing the whole menu.*/
|
||||
private Table mainTable;
|
||||
/**Table for all section buttons and blocks.*/
|
||||
private Table selectTable;
|
||||
/**Whether the whole thing is shown or hidden by the popup button.*/
|
||||
private boolean shown = true;
|
||||
/**Recipe currently hovering over.*/
|
||||
private Recipe hoverRecipe;
|
||||
/**Last category selected.*/
|
||||
private Category lastCategory;
|
||||
/**Last block pane scroll Y position.*/
|
||||
private float lastScroll;
|
||||
/**Temporary recipe array for storage*/
|
||||
private Array<Recipe> recipes = new Array<>();
|
||||
|
||||
//number of block icon rows
|
||||
private static final int rows = 4;
|
||||
//number of category button rows
|
||||
private static final int secrows = 4;
|
||||
//size of each block icon
|
||||
private static final float size = 48;
|
||||
//maximum recipe rows
|
||||
private static final int maxrow = 3;
|
||||
|
||||
public void build(Group parent){
|
||||
InputHandler input = control.input(0);
|
||||
|
||||
//create container table
|
||||
new table(){{
|
||||
abottom();
|
||||
aright();
|
||||
|
||||
//make it only be shown when needed.
|
||||
visible(() -> !state.is(State.menu));
|
||||
|
||||
//create the main blocks table
|
||||
mainTable = new table(){{
|
||||
|
||||
//add top description table
|
||||
descTable = new Table("button");
|
||||
descTable.setVisible(() -> hoverRecipe != null || input.recipe != null); //make sure it's visible when necessary
|
||||
descTable.update(() -> {
|
||||
// note: This is required because there is no direct connection between
|
||||
// input.recipe and the description ui. If input.recipe gets set to null
|
||||
// a proper cleanup of the ui elements is required.
|
||||
boolean anyRecipeShown = input.recipe != null || hoverRecipe != null;
|
||||
boolean descriptionTableClean = descTable.getChildren().size == 0;
|
||||
boolean cleanupRequired = !anyRecipeShown && !descriptionTableClean;
|
||||
if(cleanupRequired){
|
||||
descTable.clear();
|
||||
}
|
||||
});
|
||||
|
||||
add(descTable).fillX().uniformX();
|
||||
|
||||
row();
|
||||
|
||||
//now add the block selection menu
|
||||
selectTable = new table("pane") {{
|
||||
touchable(Touchable.enabled);
|
||||
|
||||
margin(10f);
|
||||
marginLeft(0f);
|
||||
marginRight(0f);
|
||||
marginTop(-5);
|
||||
|
||||
}}.right().bottom().end().get();
|
||||
|
||||
visible(() -> !state.is(State.menu));
|
||||
|
||||
}}.end().get();
|
||||
|
||||
}}.end();
|
||||
|
||||
rebuild();
|
||||
}
|
||||
|
||||
/**Rebuilds the whole placement menu, attempting to preserve previous state.*/
|
||||
void rebuild(){
|
||||
selectTable.clear();
|
||||
|
||||
InputHandler input = control.input(0);
|
||||
Stack stack = new Stack();
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
Table catTable = selectTable;
|
||||
|
||||
int cati = 0;
|
||||
int checkedi = 0;
|
||||
int rowsUsed = 0;
|
||||
|
||||
//add categories
|
||||
for (Category cat : Category.values()) {
|
||||
//get recipes out by category
|
||||
Recipe.getUnlockedByCategory(cat, recipes);
|
||||
|
||||
//empty section, nothing to see here
|
||||
if(recipes.size == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
//table where actual recipes go
|
||||
Table recipeTable = new Table();
|
||||
recipeTable.margin(4).top().left().marginRight(15);
|
||||
|
||||
//add a new row here when needed
|
||||
if (cati == secrows) {
|
||||
catTable = new Table();
|
||||
selectTable.row();
|
||||
selectTable.add(catTable).colspan(secrows).padTop(-5).growX();
|
||||
}
|
||||
|
||||
//add category button
|
||||
ImageButton catb = catTable.addImageButton( "icon-" + cat.name(), "toggle", 40, () -> {
|
||||
if (!recipeTable.isVisible() && input.recipe != null) {
|
||||
input.recipe = null;
|
||||
}
|
||||
lastCategory = cat;
|
||||
stack.act(Gdx.graphics.getDeltaTime());
|
||||
stack.act(Gdx.graphics.getDeltaTime());
|
||||
}).growX().height(54).group(group)
|
||||
.name("sectionbutton" + cat.name()).get();
|
||||
|
||||
if(lastCategory == cat || lastCategory == null){
|
||||
checkedi = cati;
|
||||
lastCategory = cat;
|
||||
}
|
||||
|
||||
//scrollpane for recipes
|
||||
ScrollPane pane = new ScrollPane(recipeTable, "clear-black");
|
||||
pane.setOverscroll(false, false);
|
||||
pane.setVisible(catb::isChecked);
|
||||
pane.setScrollYForce(lastScroll);
|
||||
pane.update(() -> {
|
||||
Element e = Core.scene.hit(Graphics.mouse().x, Graphics.mouse().y, true);
|
||||
if(e != null && e.isDescendantOf(pane)){
|
||||
Core.scene.setScrollFocus(pane);
|
||||
}else if(Core.scene.getScrollFocus() == pane){
|
||||
Core.scene.setScrollFocus(null);
|
||||
}
|
||||
|
||||
if(lastCategory == cat){
|
||||
lastScroll = pane.getVisualScrollY();
|
||||
}
|
||||
});
|
||||
stack.add(pane);
|
||||
|
||||
int i = 0;
|
||||
|
||||
//add actual recipes
|
||||
for (Recipe r : recipes) {
|
||||
if((r.debugOnly && !debug) || (r.desktopOnly && mobile)) continue;
|
||||
|
||||
ImageButton image = new ImageButton(new TextureRegion(), "select");
|
||||
|
||||
TextureRegion[] regions = r.result.getCompactIcon();
|
||||
Stack istack = new Stack();
|
||||
for(TextureRegion region : regions){
|
||||
Image u = new Image(region);
|
||||
u.update(() -> u.setColor(istack.getColor()));
|
||||
istack.add(u);
|
||||
}
|
||||
|
||||
image.getImageCell().setActor(istack).size(size);
|
||||
image.addChild(istack);
|
||||
image.setTouchable(Touchable.enabled);
|
||||
image.getImage().remove();
|
||||
|
||||
image.addListener(new ClickListener(){
|
||||
@Override
|
||||
public void enter(InputEvent event, float x, float y, int pointer, Element fromActor) {
|
||||
super.enter(event, x, y, pointer, fromActor);
|
||||
if (hoverRecipe != r) {
|
||||
hoverRecipe = r;
|
||||
updateRecipe(r);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit(InputEvent event, float x, float y, int pointer, Element toActor) {
|
||||
super.exit(event, x, y, pointer, toActor);
|
||||
hoverRecipe = null;
|
||||
updateRecipe(input.recipe);
|
||||
}
|
||||
});
|
||||
|
||||
image.clicked(() -> {
|
||||
// note: input.recipe only gets set here during a click.
|
||||
// during a hover only the visual description will be updated.
|
||||
InputHandler handler = mobile ? input : control.input(0);
|
||||
|
||||
boolean nothingSelectedYet = handler.recipe == null;
|
||||
boolean selectedSomethingElse = !nothingSelectedYet && handler.recipe != r;
|
||||
boolean shouldMakeSelection = nothingSelectedYet || selectedSomethingElse;
|
||||
if (shouldMakeSelection) {
|
||||
handler.recipe = r;
|
||||
hoverRecipe = r;
|
||||
updateRecipe(r);
|
||||
} else {
|
||||
handler.recipe = null;
|
||||
hoverRecipe = null;
|
||||
updateRecipe(null);
|
||||
}
|
||||
});
|
||||
|
||||
recipeTable.add(image).size(size + 8);
|
||||
|
||||
image.update(() -> {
|
||||
image.setChecked(r == control.input(0).recipe);
|
||||
TileEntity entity = players[0].getClosestCore();
|
||||
|
||||
if(entity == null) return;
|
||||
|
||||
for(ItemStack s : r.requirements){
|
||||
if(!entity.items.has(s.item, Mathf.ceil(s.amount))){
|
||||
istack.setColor(Color.GRAY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
istack.setColor(Color.WHITE);
|
||||
});
|
||||
|
||||
if (i % rows == rows - 1) {
|
||||
rowsUsed = Math.max((i+1)/rows, rowsUsed);
|
||||
recipeTable.row();
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
cati ++;
|
||||
}
|
||||
|
||||
if(group.getButtons().size > 0){
|
||||
group.getButtons().get(checkedi).setChecked(true);
|
||||
}
|
||||
|
||||
selectTable.row();
|
||||
selectTable.add(stack).growX().left().top().colspan(Category.values().length).padBottom(-5).height((size + 12)*rowsUsed);
|
||||
}
|
||||
|
||||
void toggle(boolean show, float t, Interpolation ip){
|
||||
if(shown){
|
||||
shown = false;
|
||||
mainTable.actions(Actions.translateBy(0, mainTable.getTranslation().y + (-mainTable.getHeight() - descTable.getHeight()), t, ip));
|
||||
}else{
|
||||
shown = true;
|
||||
mainTable.actions(Actions.translateBy(0, -mainTable.getTranslation().y, t, ip));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRecipe(Recipe recipe){
|
||||
if (recipe == null) {
|
||||
descTable.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
descTable.clear();
|
||||
descTable.setTouchable(Touchable.enabled);
|
||||
|
||||
descTable.defaults().left();
|
||||
descTable.left();
|
||||
descTable.margin(12);
|
||||
|
||||
Table header = new Table();
|
||||
|
||||
descTable.add(header).left();
|
||||
|
||||
descTable.row();
|
||||
|
||||
TextureRegion[] regions = recipe.result.getCompactIcon();
|
||||
|
||||
Stack istack = new Stack();
|
||||
|
||||
for(TextureRegion region : regions) istack.add(new Image(region));
|
||||
|
||||
header.add(istack).size(8*5).padTop(4);
|
||||
Label nameLabel = new Label(recipe.result.formalName);
|
||||
nameLabel.setWrap(true);
|
||||
header.add(nameLabel).padLeft(2).width(120f);
|
||||
|
||||
header.addButton("?", () -> ui.content.show(recipe)).expandX().padLeft(3).top().right().size(40f, 44f).padTop(-2);
|
||||
|
||||
descTable.add().pad(2);
|
||||
|
||||
Table requirements = new Table();
|
||||
|
||||
descTable.row();
|
||||
|
||||
descTable.add(requirements);
|
||||
descTable.left();
|
||||
|
||||
for(ItemStack stack : recipe.requirements){
|
||||
requirements.addImage(stack.item.region).size(8*3);
|
||||
Label reqlabel = new Label(() ->{
|
||||
TileEntity core = players[0].getClosestCore();
|
||||
if(core == null) return "*/*";
|
||||
//number of block icon rows
|
||||
private static final int rows = 4;
|
||||
//number of category button rows
|
||||
private static final int secrows = 4;
|
||||
//size of each block icon
|
||||
private static final float size = 48;
|
||||
//maximum recipe rows
|
||||
private static final int maxrow = 3;
|
||||
/**
|
||||
* Table containing description that is shown on top.
|
||||
*/
|
||||
private Table descTable;
|
||||
/**
|
||||
* Main table containing the whole menu.
|
||||
*/
|
||||
private Table mainTable;
|
||||
/**
|
||||
* Table for all section buttons and blocks.
|
||||
*/
|
||||
private Table selectTable;
|
||||
/**
|
||||
* Whether the whole thing is shown or hidden by the popup button.
|
||||
*/
|
||||
private boolean shown = true;
|
||||
/**
|
||||
* Recipe currently hovering over.
|
||||
*/
|
||||
private Recipe hoverRecipe;
|
||||
/**
|
||||
* Last category selected.
|
||||
*/
|
||||
private Category lastCategory;
|
||||
/**
|
||||
* Last block pane scroll Y position.
|
||||
*/
|
||||
private float lastScroll;
|
||||
/**
|
||||
* Temporary recipe array for storage
|
||||
*/
|
||||
private Array<Recipe> recipes = new Array<>();
|
||||
|
||||
public void build(Group parent){
|
||||
InputHandler input = control.input(0);
|
||||
|
||||
//create container table
|
||||
new table(){{
|
||||
abottom();
|
||||
aright();
|
||||
|
||||
//make it only be shown when needed.
|
||||
visible(() -> !state.is(State.menu));
|
||||
|
||||
//create the main blocks table
|
||||
mainTable = new table(){{
|
||||
|
||||
//add top description table
|
||||
descTable = new Table("button");
|
||||
descTable.setVisible(() -> hoverRecipe != null || input.recipe != null); //make sure it's visible when necessary
|
||||
descTable.update(() -> {
|
||||
// note: This is required because there is no direct connection between
|
||||
// input.recipe and the description ui. If input.recipe gets set to null
|
||||
// a proper cleanup of the ui elements is required.
|
||||
boolean anyRecipeShown = input.recipe != null || hoverRecipe != null;
|
||||
boolean descriptionTableClean = descTable.getChildren().size == 0;
|
||||
boolean cleanupRequired = !anyRecipeShown && !descriptionTableClean;
|
||||
if(cleanupRequired){
|
||||
descTable.clear();
|
||||
}
|
||||
});
|
||||
|
||||
add(descTable).fillX().uniformX();
|
||||
|
||||
row();
|
||||
|
||||
//now add the block selection menu
|
||||
selectTable = new table("pane"){{
|
||||
touchable(Touchable.enabled);
|
||||
|
||||
margin(10f);
|
||||
marginLeft(0f);
|
||||
marginRight(0f);
|
||||
marginTop(-5);
|
||||
|
||||
}}.right().bottom().end().get();
|
||||
|
||||
visible(() -> !state.is(State.menu));
|
||||
|
||||
}}.end().get();
|
||||
|
||||
}}.end();
|
||||
|
||||
rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuilds the whole placement menu, attempting to preserve previous state.
|
||||
*/
|
||||
void rebuild(){
|
||||
selectTable.clear();
|
||||
|
||||
InputHandler input = control.input(0);
|
||||
Stack stack = new Stack();
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
Table catTable = selectTable;
|
||||
|
||||
int cati = 0;
|
||||
int checkedi = 0;
|
||||
int rowsUsed = 0;
|
||||
|
||||
//add categories
|
||||
for(Category cat : Category.values()){
|
||||
//get recipes out by category
|
||||
Recipe.getUnlockedByCategory(cat, recipes);
|
||||
|
||||
//empty section, nothing to see here
|
||||
if(recipes.size == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
//table where actual recipes go
|
||||
Table recipeTable = new Table();
|
||||
recipeTable.margin(4).top().left().marginRight(15);
|
||||
|
||||
//add a new row here when needed
|
||||
if(cati == secrows){
|
||||
catTable = new Table();
|
||||
selectTable.row();
|
||||
selectTable.add(catTable).colspan(secrows).padTop(-5).growX();
|
||||
}
|
||||
|
||||
//add category button
|
||||
ImageButton catb = catTable.addImageButton("icon-" + cat.name(), "toggle", 40, () -> {
|
||||
if(!recipeTable.isVisible() && input.recipe != null){
|
||||
input.recipe = null;
|
||||
}
|
||||
lastCategory = cat;
|
||||
stack.act(Gdx.graphics.getDeltaTime());
|
||||
stack.act(Gdx.graphics.getDeltaTime());
|
||||
}).growX().height(54).group(group)
|
||||
.name("sectionbutton" + cat.name()).get();
|
||||
|
||||
if(lastCategory == cat || lastCategory == null){
|
||||
checkedi = cati;
|
||||
lastCategory = cat;
|
||||
}
|
||||
|
||||
//scrollpane for recipes
|
||||
ScrollPane pane = new ScrollPane(recipeTable, "clear-black");
|
||||
pane.setOverscroll(false, false);
|
||||
pane.setVisible(catb::isChecked);
|
||||
pane.setScrollYForce(lastScroll);
|
||||
pane.update(() -> {
|
||||
Element e = Core.scene.hit(Graphics.mouse().x, Graphics.mouse().y, true);
|
||||
if(e != null && e.isDescendantOf(pane)){
|
||||
Core.scene.setScrollFocus(pane);
|
||||
}else if(Core.scene.getScrollFocus() == pane){
|
||||
Core.scene.setScrollFocus(null);
|
||||
}
|
||||
|
||||
if(lastCategory == cat){
|
||||
lastScroll = pane.getVisualScrollY();
|
||||
}
|
||||
});
|
||||
stack.add(pane);
|
||||
|
||||
int i = 0;
|
||||
|
||||
//add actual recipes
|
||||
for(Recipe r : recipes){
|
||||
if((r.debugOnly && !debug) || (r.desktopOnly && mobile)) continue;
|
||||
|
||||
ImageButton image = new ImageButton(new TextureRegion(), "select");
|
||||
|
||||
TextureRegion[] regions = r.result.getCompactIcon();
|
||||
Stack istack = new Stack();
|
||||
for(TextureRegion region : regions){
|
||||
Image u = new Image(region);
|
||||
u.update(() -> u.setColor(istack.getColor()));
|
||||
istack.add(u);
|
||||
}
|
||||
|
||||
image.getImageCell().setActor(istack).size(size);
|
||||
image.addChild(istack);
|
||||
image.setTouchable(Touchable.enabled);
|
||||
image.getImage().remove();
|
||||
|
||||
image.addListener(new ClickListener(){
|
||||
@Override
|
||||
public void enter(InputEvent event, float x, float y, int pointer, Element fromActor){
|
||||
super.enter(event, x, y, pointer, fromActor);
|
||||
if(hoverRecipe != r){
|
||||
hoverRecipe = r;
|
||||
updateRecipe(r);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit(InputEvent event, float x, float y, int pointer, Element toActor){
|
||||
super.exit(event, x, y, pointer, toActor);
|
||||
hoverRecipe = null;
|
||||
updateRecipe(input.recipe);
|
||||
}
|
||||
});
|
||||
|
||||
image.clicked(() -> {
|
||||
// note: input.recipe only gets set here during a click.
|
||||
// during a hover only the visual description will be updated.
|
||||
InputHandler handler = mobile ? input : control.input(0);
|
||||
|
||||
boolean nothingSelectedYet = handler.recipe == null;
|
||||
boolean selectedSomethingElse = !nothingSelectedYet && handler.recipe != r;
|
||||
boolean shouldMakeSelection = nothingSelectedYet || selectedSomethingElse;
|
||||
if(shouldMakeSelection){
|
||||
handler.recipe = r;
|
||||
hoverRecipe = r;
|
||||
updateRecipe(r);
|
||||
}else{
|
||||
handler.recipe = null;
|
||||
hoverRecipe = null;
|
||||
updateRecipe(null);
|
||||
}
|
||||
});
|
||||
|
||||
recipeTable.add(image).size(size + 8);
|
||||
|
||||
image.update(() -> {
|
||||
image.setChecked(r == control.input(0).recipe);
|
||||
TileEntity entity = players[0].getClosestCore();
|
||||
|
||||
if(entity == null) return;
|
||||
|
||||
for(ItemStack s : r.requirements){
|
||||
if(!entity.items.has(s.item, Mathf.ceil(s.amount))){
|
||||
istack.setColor(Color.GRAY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
istack.setColor(Color.WHITE);
|
||||
});
|
||||
|
||||
if(i % rows == rows - 1){
|
||||
rowsUsed = Math.max((i + 1) / rows, rowsUsed);
|
||||
recipeTable.row();
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
cati++;
|
||||
}
|
||||
|
||||
if(group.getButtons().size > 0){
|
||||
group.getButtons().get(checkedi).setChecked(true);
|
||||
}
|
||||
|
||||
selectTable.row();
|
||||
selectTable.add(stack).growX().left().top().colspan(Category.values().length).padBottom(-5).height((size + 12) * rowsUsed);
|
||||
}
|
||||
|
||||
void toggle(boolean show, float t, Interpolation ip){
|
||||
if(shown){
|
||||
shown = false;
|
||||
mainTable.actions(Actions.translateBy(0, mainTable.getTranslation().y + (-mainTable.getHeight() - descTable.getHeight()), t, ip));
|
||||
}else{
|
||||
shown = true;
|
||||
mainTable.actions(Actions.translateBy(0, -mainTable.getTranslation().y, t, ip));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRecipe(Recipe recipe){
|
||||
if(recipe == null){
|
||||
descTable.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
descTable.clear();
|
||||
descTable.setTouchable(Touchable.enabled);
|
||||
|
||||
descTable.defaults().left();
|
||||
descTable.left();
|
||||
descTable.margin(12);
|
||||
|
||||
Table header = new Table();
|
||||
|
||||
descTable.add(header).left();
|
||||
|
||||
descTable.row();
|
||||
|
||||
TextureRegion[] regions = recipe.result.getCompactIcon();
|
||||
|
||||
Stack istack = new Stack();
|
||||
|
||||
for(TextureRegion region : regions) istack.add(new Image(region));
|
||||
|
||||
header.add(istack).size(8 * 5).padTop(4);
|
||||
Label nameLabel = new Label(recipe.result.formalName);
|
||||
nameLabel.setWrap(true);
|
||||
header.add(nameLabel).padLeft(2).width(120f);
|
||||
|
||||
header.addButton("?", () -> ui.content.show(recipe)).expandX().padLeft(3).top().right().size(40f, 44f).padTop(-2);
|
||||
|
||||
descTable.add().pad(2);
|
||||
|
||||
Table requirements = new Table();
|
||||
|
||||
descTable.row();
|
||||
|
||||
descTable.add(requirements);
|
||||
descTable.left();
|
||||
|
||||
for(ItemStack stack : recipe.requirements){
|
||||
requirements.addImage(stack.item.region).size(8 * 3);
|
||||
Label reqlabel = new Label(() -> {
|
||||
TileEntity core = players[0].getClosestCore();
|
||||
if(core == null) return "*/*";
|
||||
|
||||
int amount = core.items.get(stack.item);
|
||||
String color = (amount < stack.amount/2f ? "[red]" : amount < stack.amount ? "[orange]" : "[white]");
|
||||
int amount = core.items.get(stack.item);
|
||||
String color = (amount < stack.amount / 2f ? "[red]" : amount < stack.amount ? "[orange]" : "[white]");
|
||||
|
||||
return color + format(amount) + "[white]/" + stack.amount;
|
||||
});
|
||||
return color + format(amount) + "[white]/" + stack.amount;
|
||||
});
|
||||
|
||||
requirements.add(reqlabel).left();
|
||||
requirements.row();
|
||||
}
|
||||
requirements.add(reqlabel).left();
|
||||
requirements.row();
|
||||
}
|
||||
|
||||
descTable.row();
|
||||
}
|
||||
descTable.row();
|
||||
}
|
||||
|
||||
String format(int number){
|
||||
if(number >= 1000000) {
|
||||
return Strings.toFixed(number/1000000f, 1) + "[gray]mil[]";
|
||||
}else if(number >= 10000){
|
||||
return number/1000 + "[gray]k[]";
|
||||
}else if(number >= 1000){
|
||||
return Strings.toFixed(number/1000f, 1) + "[gray]k[]";
|
||||
}else{
|
||||
return number + "";
|
||||
}
|
||||
}
|
||||
String format(int number){
|
||||
if(number >= 1000000){
|
||||
return Strings.toFixed(number / 1000000f, 1) + "[gray]mil[]";
|
||||
}else if(number >= 10000){
|
||||
return number / 1000 + "[gray]k[]";
|
||||
}else if(number >= 1000){
|
||||
return Strings.toFixed(number / 1000f, 1) + "[gray]k[]";
|
||||
}else{
|
||||
return number + "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,9 +43,9 @@ public class ChatFragment extends Table{
|
||||
private Array<String> history = new Array<>();
|
||||
private int historyPos = 0;
|
||||
private int scrollPos = 0;
|
||||
private Fragment container = new Fragment() {
|
||||
private Fragment container = new Fragment(){
|
||||
@Override
|
||||
public void build(Group parent) {
|
||||
public void build(Group parent){
|
||||
scene.add(ChatFragment.this);
|
||||
}
|
||||
};
|
||||
@@ -67,17 +67,17 @@ public class ChatFragment extends Table{
|
||||
toggle();
|
||||
}
|
||||
|
||||
if (chatOpen) {
|
||||
if (Inputs.keyTap("chat_history_prev") && historyPos < history.size - 1) {
|
||||
if (historyPos == 0) history.set(0, chatfield.getText());
|
||||
if(chatOpen){
|
||||
if(Inputs.keyTap("chat_history_prev") && historyPos < history.size - 1){
|
||||
if(historyPos == 0) history.set(0, chatfield.getText());
|
||||
historyPos++;
|
||||
updateChat();
|
||||
}
|
||||
if (Inputs.keyTap("chat_history_next") && historyPos > 0) {
|
||||
if(Inputs.keyTap("chat_history_next") && historyPos > 0){
|
||||
historyPos--;
|
||||
updateChat();
|
||||
}
|
||||
scrollPos = (int)Mathf.clamp(scrollPos + Inputs.getAxis("chat_scroll"), 0, Math.max(0, messages.size - messagesShown));
|
||||
scrollPos = (int) Mathf.clamp(scrollPos + Inputs.getAxis("chat_scroll"), 0, Math.max(0, messages.size - messagesShown));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -85,7 +85,7 @@ public class ChatFragment extends Table{
|
||||
setup();
|
||||
}
|
||||
|
||||
public Fragment container() {
|
||||
public Fragment container(){
|
||||
return container;
|
||||
}
|
||||
|
||||
@@ -108,16 +108,16 @@ public class ChatFragment extends Table{
|
||||
chatfield.setStyle(chatfield.getStyle());
|
||||
Platform.instance.addDialog(chatfield, Vars.maxTextLength);
|
||||
|
||||
bottom().left().marginBottom(offsety).marginLeft(offsetx*2).add(fieldlabel).padBottom(4f);
|
||||
bottom().left().marginBottom(offsety).marginLeft(offsetx * 2).add(fieldlabel).padBottom(4f);
|
||||
|
||||
add(chatfield).padBottom(offsety).padLeft(offsetx).growX().padRight(offsetx).height(28);
|
||||
|
||||
if(Vars.mobile) {
|
||||
if(Vars.mobile){
|
||||
marginBottom(105f);
|
||||
marginRight(240f);
|
||||
}
|
||||
|
||||
if(Vars.mobile) {
|
||||
if(Vars.mobile){
|
||||
addImageButton("icon-arrow-right", 14 * 2, this::toggle).size(46f, 51f).visible(() -> chatOpen).pad(2f);
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public class ChatFragment extends Table{
|
||||
batch.setColor(shadowColor);
|
||||
|
||||
if(chatOpen)
|
||||
batch.draw(skin.getRegion("white"), offsetx, chatfield.getY(), chatfield.getWidth() + 15f, chatfield.getHeight()-1);
|
||||
batch.draw(skin.getRegion("white"), offsetx, chatfield.getY(), chatfield.getWidth() + 15f, chatfield.getHeight() - 1);
|
||||
|
||||
super.draw(batch, alpha);
|
||||
|
||||
@@ -143,18 +143,18 @@ public class ChatFragment extends Table{
|
||||
for(int i = scrollPos; i < messages.size && i < messagesShown + scrollPos && (i < fadetime || chatOpen); i++){
|
||||
|
||||
layout.setText(font, messages.get(i).formattedMessage, Color.WHITE, textWidth, Align.bottomLeft, true);
|
||||
theight += layout.height+textspacing;
|
||||
if(i - scrollPos == 0) theight -= textspacing+1;
|
||||
theight += layout.height + textspacing;
|
||||
if(i - scrollPos == 0) theight -= textspacing + 1;
|
||||
|
||||
font.getCache().clear();
|
||||
font.getCache().addText(messages.get(i).formattedMessage, fontoffsetx + offsetx, offsety + theight, textWidth, Align.bottomLeft, true);
|
||||
|
||||
if(!chatOpen && fadetime-i < 1f && fadetime-i >= 0f){
|
||||
font.getCache().setAlphas(fadetime-i);
|
||||
batch.setColor(0, 0, 0, shadowColor.a*(fadetime-i));
|
||||
if(!chatOpen && fadetime - i < 1f && fadetime - i >= 0f){
|
||||
font.getCache().setAlphas(fadetime - i);
|
||||
batch.setColor(0, 0, 0, shadowColor.a * (fadetime - i));
|
||||
}
|
||||
|
||||
batch.draw(skin.getRegion("white"), offsetx, theight-layout.height-2, textWidth + Unit.dp.scl(4f), layout.height+textspacing);
|
||||
batch.draw(skin.getRegion("white"), offsetx, theight - layout.height - 2, textWidth + Unit.dp.scl(4f), layout.height + textspacing);
|
||||
batch.setColor(shadowColor);
|
||||
|
||||
font.getCache().draw(batch);
|
||||
@@ -163,7 +163,7 @@ public class ChatFragment extends Table{
|
||||
batch.setColor(Color.WHITE);
|
||||
|
||||
if(fadetime > 0 && !chatOpen)
|
||||
fadetime -= Timers.delta()/180f;
|
||||
fadetime -= Timers.delta() / 180f;
|
||||
}
|
||||
|
||||
private void sendMessage(){
|
||||
@@ -197,12 +197,12 @@ public class ChatFragment extends Table{
|
||||
clearChatInput();
|
||||
}
|
||||
|
||||
public void updateChat() {
|
||||
public void updateChat(){
|
||||
chatfield.setText(history.get(historyPos));
|
||||
chatfield.setCursorPosition(chatfield.getText().length());
|
||||
}
|
||||
|
||||
public void clearChatInput() {
|
||||
public void clearChatInput(){
|
||||
historyPos = 0;
|
||||
history.set(0, "");
|
||||
chatfield.setText("");
|
||||
@@ -234,7 +234,7 @@ public class ChatFragment extends Table{
|
||||
if(sender == null){ //no sender, this is a server message?
|
||||
formattedMessage = message;
|
||||
}else{
|
||||
formattedMessage = "[CORAL][["+sender+"[CORAL]]:[WHITE] "+message;
|
||||
formattedMessage = "[CORAL][[" + sender + "[CORAL]]:[WHITE] " + message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class DebugFragment extends Fragment {
|
||||
public class DebugFragment extends Fragment{
|
||||
private static StringBuilder log = new StringBuilder();
|
||||
|
||||
static{
|
||||
@@ -35,7 +35,7 @@ public class DebugFragment extends Fragment {
|
||||
@Override
|
||||
public void print(String text, Object... args){
|
||||
super.print(text, args);
|
||||
if(log.length() < 1000) {
|
||||
if(log.length() < 1000){
|
||||
log.append(Log.format(text, args));
|
||||
log.append("\n");
|
||||
}
|
||||
@@ -43,109 +43,6 @@ public class DebugFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Group parent){
|
||||
|
||||
Player player = players[0];
|
||||
new table(){{
|
||||
visible(() -> debug);
|
||||
|
||||
abottom().aleft();
|
||||
|
||||
new table("pane"){{
|
||||
defaults().fillX().width(100f);
|
||||
|
||||
new label(() -> Gdx.app.getJavaHeap() / 1024 / 1024 + "MB");
|
||||
row();
|
||||
|
||||
new label("Debug");
|
||||
row();
|
||||
new button("noclip", "toggle", () -> noclip = !noclip);
|
||||
row();
|
||||
new button("items", () -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ItemDrop.create(Item.all().random(), 5, player.x, player.y, Mathf.random(360f));
|
||||
}
|
||||
});
|
||||
row();
|
||||
new button("team", "toggle", player::toggleTeam);
|
||||
row();
|
||||
new button("blocks", "toggle", () -> showBlockDebug = !showBlockDebug);
|
||||
row();
|
||||
new button("fog", () -> showFog = !showFog);
|
||||
row();
|
||||
new button("gameover", () ->{
|
||||
state.teams.get(Team.blue).cores.get(0).entity.health = 0;
|
||||
state.teams.get(Team.blue).cores.get(0).entity.damage(1);
|
||||
});
|
||||
row();
|
||||
new button("wave", () -> state.wavetime = 0f);
|
||||
row();
|
||||
new button("death", () -> player.damage(99999, true));
|
||||
row();
|
||||
new button("spawn", () -> {
|
||||
FloatingDialog dialog = new FloatingDialog("debug spawn");
|
||||
for(UnitType type : UnitType.all()){
|
||||
dialog.content().addImageButton("white", 40, () -> {
|
||||
BaseUnit unit = type.create(player.getTeam());
|
||||
unit.inventory.addAmmo(type.weapon.getAmmoType(type.weapon.getAcceptedItems().iterator().next()));
|
||||
unit.setWave();
|
||||
unit.set(player.x, player.y);
|
||||
unit.add();
|
||||
}).get().getStyle().imageUp = new TextureRegionDrawable(type.iconRegion);
|
||||
}
|
||||
dialog.addCloseButton();
|
||||
dialog.setFillParent(false);
|
||||
dialog.show();
|
||||
});
|
||||
row();
|
||||
}}.end();
|
||||
|
||||
row();
|
||||
|
||||
}}.end();
|
||||
|
||||
|
||||
new table(){{
|
||||
visible(() -> console);
|
||||
|
||||
atop().aleft();
|
||||
|
||||
new table("pane") {{
|
||||
defaults().fillX();
|
||||
|
||||
ScrollPane pane = new ScrollPane(new Label(DebugFragment::debugInfo), "clear");
|
||||
|
||||
add(pane);
|
||||
row();
|
||||
new button("dump", () -> {
|
||||
try{
|
||||
FileHandle file = Gdx.files.local("packet-dump.txt");
|
||||
file.writeString("--INFO--\n", false);
|
||||
file.writeString(debugInfo(), true);
|
||||
file.writeString("--LOG--\n\n", true);
|
||||
file.writeString(log.toString(), true);
|
||||
}catch (Exception e){
|
||||
ui.showError("Error dumping log.");
|
||||
}
|
||||
});
|
||||
}}.end();
|
||||
}}.end();
|
||||
|
||||
new table(){{
|
||||
visible(() -> console);
|
||||
|
||||
atop();
|
||||
|
||||
Table table = new Table("pane");
|
||||
table.label(() -> log.toString());
|
||||
|
||||
ScrollPane pane = new ScrollPane(table, "clear");
|
||||
|
||||
get().add(pane);
|
||||
}}.end();
|
||||
}
|
||||
|
||||
public static void printDebugInfo(){
|
||||
Gdx.app.error("Minudstry Info Dump", debugInfo());
|
||||
}
|
||||
@@ -166,9 +63,9 @@ public class DebugFragment extends Fragment {
|
||||
"units: " + totalUnits,
|
||||
"bullets: " + bulletGroup.size(),
|
||||
Net.client() ?
|
||||
"chat.open: " + ui.chatfrag.chatOpen() + "\n" +
|
||||
"chat.messages: " + ui.chatfrag.getMessagesSize() + "\n" +
|
||||
"client.connecting: " + netClient.isConnecting() + "\n" : "",
|
||||
"chat.open: " + ui.chatfrag.chatOpen() + "\n" +
|
||||
"chat.messages: " + ui.chatfrag.getMessagesSize() + "\n" +
|
||||
"client.connecting: " + netClient.isConnecting() + "\n" : "",
|
||||
"players: " + playerGroup.size(),
|
||||
"tiles: " + tileGroup.size(),
|
||||
"tiles.sleeping: " + TileEntity.sleepingEntities,
|
||||
@@ -212,10 +109,113 @@ public class DebugFragment extends Fragment {
|
||||
|
||||
private static StringBuilder join(String... strings){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String string : strings) {
|
||||
for(String string : strings){
|
||||
builder.append(string);
|
||||
builder.append("\n");
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Group parent){
|
||||
|
||||
Player player = players[0];
|
||||
new table(){{
|
||||
visible(() -> debug);
|
||||
|
||||
abottom().aleft();
|
||||
|
||||
new table("pane"){{
|
||||
defaults().fillX().width(100f);
|
||||
|
||||
new label(() -> Gdx.app.getJavaHeap() / 1024 / 1024 + "MB");
|
||||
row();
|
||||
|
||||
new label("Debug");
|
||||
row();
|
||||
new button("noclip", "toggle", () -> noclip = !noclip);
|
||||
row();
|
||||
new button("items", () -> {
|
||||
for(int i = 0; i < 10; i++){
|
||||
ItemDrop.create(Item.all().random(), 5, player.x, player.y, Mathf.random(360f));
|
||||
}
|
||||
});
|
||||
row();
|
||||
new button("team", "toggle", player::toggleTeam);
|
||||
row();
|
||||
new button("blocks", "toggle", () -> showBlockDebug = !showBlockDebug);
|
||||
row();
|
||||
new button("fog", () -> showFog = !showFog);
|
||||
row();
|
||||
new button("gameover", () -> {
|
||||
state.teams.get(Team.blue).cores.get(0).entity.health = 0;
|
||||
state.teams.get(Team.blue).cores.get(0).entity.damage(1);
|
||||
});
|
||||
row();
|
||||
new button("wave", () -> state.wavetime = 0f);
|
||||
row();
|
||||
new button("death", () -> player.damage(99999, true));
|
||||
row();
|
||||
new button("spawn", () -> {
|
||||
FloatingDialog dialog = new FloatingDialog("debug spawn");
|
||||
for(UnitType type : UnitType.all()){
|
||||
dialog.content().addImageButton("white", 40, () -> {
|
||||
BaseUnit unit = type.create(player.getTeam());
|
||||
unit.inventory.addAmmo(type.weapon.getAmmoType(type.weapon.getAcceptedItems().iterator().next()));
|
||||
unit.setWave();
|
||||
unit.set(player.x, player.y);
|
||||
unit.add();
|
||||
}).get().getStyle().imageUp = new TextureRegionDrawable(type.iconRegion);
|
||||
}
|
||||
dialog.addCloseButton();
|
||||
dialog.setFillParent(false);
|
||||
dialog.show();
|
||||
});
|
||||
row();
|
||||
}}.end();
|
||||
|
||||
row();
|
||||
|
||||
}}.end();
|
||||
|
||||
|
||||
new table(){{
|
||||
visible(() -> console);
|
||||
|
||||
atop().aleft();
|
||||
|
||||
new table("pane"){{
|
||||
defaults().fillX();
|
||||
|
||||
ScrollPane pane = new ScrollPane(new Label(DebugFragment::debugInfo), "clear");
|
||||
|
||||
add(pane);
|
||||
row();
|
||||
new button("dump", () -> {
|
||||
try{
|
||||
FileHandle file = Gdx.files.local("packet-dump.txt");
|
||||
file.writeString("--INFO--\n", false);
|
||||
file.writeString(debugInfo(), true);
|
||||
file.writeString("--LOG--\n\n", true);
|
||||
file.writeString(log.toString(), true);
|
||||
}catch(Exception e){
|
||||
ui.showError("Error dumping log.");
|
||||
}
|
||||
});
|
||||
}}.end();
|
||||
}}.end();
|
||||
|
||||
new table(){{
|
||||
visible(() -> console);
|
||||
|
||||
atop();
|
||||
|
||||
Table table = new Table("pane");
|
||||
table.label(() -> log.toString());
|
||||
|
||||
ScrollPane pane = new ScrollPane(table, "clear");
|
||||
|
||||
get().add(pane);
|
||||
}}.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ package io.anuke.mindustry.ui.fragments;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
|
||||
public abstract class Fragment{
|
||||
public abstract void build(Group parent);
|
||||
public abstract void build(Group parent);
|
||||
}
|
||||
|
||||
@@ -34,316 +34,318 @@ import io.anuke.ucore.util.Bundles;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class HudFragment extends Fragment{
|
||||
public final BlocksFragment blockfrag = new BlocksFragment();
|
||||
public final BlocksFragment blockfrag = new BlocksFragment();
|
||||
|
||||
private ImageButton menu, flip;
|
||||
private Table respawntable;
|
||||
private Table wavetable;
|
||||
private Table infolabel;
|
||||
private Table lastUnlockTable;
|
||||
private Table lastUnlockLayout;
|
||||
private boolean shown = true;
|
||||
private float dsize = 58;
|
||||
private float isize = 40;
|
||||
private ImageButton menu, flip;
|
||||
private Table respawntable;
|
||||
private Table wavetable;
|
||||
private Table infolabel;
|
||||
private Table lastUnlockTable;
|
||||
private Table lastUnlockLayout;
|
||||
private boolean shown = true;
|
||||
private float dsize = 58;
|
||||
private float isize = 40;
|
||||
|
||||
public void build(Group parent){
|
||||
public void build(Group parent){
|
||||
|
||||
//menu at top left
|
||||
new table(){{
|
||||
atop();
|
||||
aleft();
|
||||
//menu at top left
|
||||
new table(){{
|
||||
atop();
|
||||
aleft();
|
||||
|
||||
new table(){{
|
||||
new table(){{
|
||||
|
||||
new table() {{
|
||||
left();
|
||||
defaults().size(dsize).left();
|
||||
new table(){{
|
||||
left();
|
||||
defaults().size(dsize).left();
|
||||
|
||||
menu = new imagebutton("icon-menu", isize, ui.paused::show).get();
|
||||
flip = new imagebutton("icon-arrow-up", isize, () -> toggleMenus()).get();
|
||||
menu = new imagebutton("icon-menu", isize, ui.paused::show).get();
|
||||
flip = new imagebutton("icon-arrow-up", isize, () -> toggleMenus()).get();
|
||||
|
||||
update(t -> {
|
||||
if(Inputs.keyTap("toggle_menus") && !ui.chatfrag.chatOpen()){
|
||||
toggleMenus();
|
||||
}
|
||||
});
|
||||
update(t -> {
|
||||
if(Inputs.keyTap("toggle_menus") && !ui.chatfrag.chatOpen()){
|
||||
toggleMenus();
|
||||
}
|
||||
});
|
||||
|
||||
new imagebutton("icon-pause", isize, () -> {
|
||||
if (Net.active()) {
|
||||
ui.listfrag.toggle();
|
||||
} else {
|
||||
state.set(state.is(State.paused) ? State.playing : State.paused);
|
||||
}
|
||||
}).update(i -> {
|
||||
if (Net.active()) {
|
||||
i.getStyle().imageUp = Core.skin.getDrawable("icon-players");
|
||||
} else {
|
||||
i.setDisabled(Net.active());
|
||||
i.getStyle().imageUp = Core.skin.getDrawable(state.is(State.paused) ? "icon-play" : "icon-pause");
|
||||
}
|
||||
}).get();
|
||||
new imagebutton("icon-pause", isize, () -> {
|
||||
if(Net.active()){
|
||||
ui.listfrag.toggle();
|
||||
}else{
|
||||
state.set(state.is(State.paused) ? State.playing : State.paused);
|
||||
}
|
||||
}).update(i -> {
|
||||
if(Net.active()){
|
||||
i.getStyle().imageUp = Core.skin.getDrawable("icon-players");
|
||||
}else{
|
||||
i.setDisabled(Net.active());
|
||||
i.getStyle().imageUp = Core.skin.getDrawable(state.is(State.paused) ? "icon-play" : "icon-pause");
|
||||
}
|
||||
}).get();
|
||||
|
||||
new imagebutton("icon-settings", isize, () -> {
|
||||
if (Net.active() && mobile) {
|
||||
if (ui.chatfrag.chatOpen()) {
|
||||
ui.chatfrag.hide();
|
||||
} else {
|
||||
ui.chatfrag.toggle();
|
||||
}
|
||||
} else {
|
||||
ui.settings.show();
|
||||
}
|
||||
}).update(i -> {
|
||||
if (Net.active() && mobile) {
|
||||
i.getStyle().imageUp = Core.skin.getDrawable("icon-chat");
|
||||
} else {
|
||||
i.getStyle().imageUp = Core.skin.getDrawable("icon-settings");
|
||||
}
|
||||
}).get();
|
||||
new imagebutton("icon-settings", isize, () -> {
|
||||
if(Net.active() && mobile){
|
||||
if(ui.chatfrag.chatOpen()){
|
||||
ui.chatfrag.hide();
|
||||
}else{
|
||||
ui.chatfrag.toggle();
|
||||
}
|
||||
}else{
|
||||
ui.settings.show();
|
||||
}
|
||||
}).update(i -> {
|
||||
if(Net.active() && mobile){
|
||||
i.getStyle().imageUp = Core.skin.getDrawable("icon-chat");
|
||||
}else{
|
||||
i.getStyle().imageUp = Core.skin.getDrawable("icon-settings");
|
||||
}
|
||||
}).get();
|
||||
|
||||
}}.end();
|
||||
}}.end();
|
||||
|
||||
row();
|
||||
row();
|
||||
|
||||
new table() {{
|
||||
touchable(Touchable.enabled);
|
||||
addWaveTable();
|
||||
}}.fillX().end();
|
||||
new table(){{
|
||||
touchable(Touchable.enabled);
|
||||
addWaveTable();
|
||||
}}.fillX().end();
|
||||
|
||||
row();
|
||||
row();
|
||||
|
||||
visible(() -> !state.is(State.menu));
|
||||
row();
|
||||
new table(){{
|
||||
IntFormat fps = new IntFormat("text.fps");
|
||||
IntFormat tps = new IntFormat("text.tps");
|
||||
IntFormat ping = new IntFormat("text.ping");
|
||||
new label(() -> fps.get(Gdx.graphics.getFramesPerSecond())).padRight(10);
|
||||
new label(() -> tps.get(threads.getTPS())).visible(() -> threads.isEnabled());
|
||||
row();
|
||||
new label(() -> ping.get(Net.getPing())).visible(() -> Net.client() && !gwt).colspan(2);
|
||||
visible(() -> !state.is(State.menu));
|
||||
row();
|
||||
new table(){{
|
||||
IntFormat fps = new IntFormat("text.fps");
|
||||
IntFormat tps = new IntFormat("text.tps");
|
||||
IntFormat ping = new IntFormat("text.ping");
|
||||
new label(() -> fps.get(Gdx.graphics.getFramesPerSecond())).padRight(10);
|
||||
new label(() -> tps.get(threads.getTPS())).visible(() -> threads.isEnabled());
|
||||
row();
|
||||
new label(() -> ping.get(Net.getPing())).visible(() -> Net.client() && !gwt).colspan(2);
|
||||
|
||||
infolabel = get();
|
||||
}}.size(-1).end().visible(() -> Settings.getBool("fps"));
|
||||
infolabel = get();
|
||||
}}.size(-1).end().visible(() -> Settings.getBool("fps"));
|
||||
|
||||
}}.end();
|
||||
}}.end();
|
||||
}}.end();
|
||||
}}.end();
|
||||
|
||||
new table(){{
|
||||
visible(() -> !state.is(State.menu));
|
||||
atop();
|
||||
aright();
|
||||
new table(){{
|
||||
visible(() -> !state.is(State.menu));
|
||||
atop();
|
||||
aright();
|
||||
|
||||
Minimap minimap = new Minimap();
|
||||
Minimap minimap = new Minimap();
|
||||
|
||||
add(minimap).visible(() -> Settings.getBool("minimap"));
|
||||
}}.end();
|
||||
add(minimap).visible(() -> Settings.getBool("minimap"));
|
||||
}}.end();
|
||||
|
||||
//paused table
|
||||
new table(){{
|
||||
visible(() -> state.is(State.paused) && !Net.active());
|
||||
atop();
|
||||
//paused table
|
||||
new table(){{
|
||||
visible(() -> state.is(State.paused) && !Net.active());
|
||||
atop();
|
||||
|
||||
new table("pane"){{
|
||||
new label("[orange]< "+ Bundles.get("text.paused") + " >").scale(0.75f).pad(6);
|
||||
}}.end();
|
||||
}}.end();
|
||||
new table("pane"){{
|
||||
new label("[orange]< " + Bundles.get("text.paused") + " >").scale(0.75f).pad(6);
|
||||
}}.end();
|
||||
}}.end();
|
||||
|
||||
//respawn background table
|
||||
new table("white"){{
|
||||
respawntable = get();
|
||||
respawntable.setColor(Color.CLEAR);
|
||||
update(t -> {
|
||||
if(state.is(State.menu)){
|
||||
respawntable.setColor(Color.CLEAR);
|
||||
}
|
||||
});
|
||||
}}.end();
|
||||
//respawn background table
|
||||
new table("white"){{
|
||||
respawntable = get();
|
||||
respawntable.setColor(Color.CLEAR);
|
||||
update(t -> {
|
||||
if(state.is(State.menu)){
|
||||
respawntable.setColor(Color.CLEAR);
|
||||
}
|
||||
});
|
||||
}}.end();
|
||||
|
||||
new table(){{
|
||||
abottom();
|
||||
visible(() -> !state.is(State.menu) && control.getSaves().isSaving());
|
||||
new table(){{
|
||||
abottom();
|
||||
visible(() -> !state.is(State.menu) && control.getSaves().isSaving());
|
||||
|
||||
new label("$text.saveload");
|
||||
new label("$text.saveload");
|
||||
|
||||
}}.end();
|
||||
}}.end();
|
||||
|
||||
blockfrag.build(Core.scene.getRoot());
|
||||
}
|
||||
blockfrag.build(Core.scene.getRoot());
|
||||
}
|
||||
|
||||
/**Show unlock notification for a new recipe.*/
|
||||
public void showUnlock(Recipe recipe){
|
||||
blockfrag.rebuild();
|
||||
/**
|
||||
* Show unlock notification for a new recipe.
|
||||
*/
|
||||
public void showUnlock(Recipe recipe){
|
||||
blockfrag.rebuild();
|
||||
|
||||
//if there's currently no unlock notification...
|
||||
if(lastUnlockTable == null) {
|
||||
Table table = new Table("button");
|
||||
table.update(() -> {
|
||||
if(state.is(State.menu)){
|
||||
table.remove();
|
||||
lastUnlockLayout = null;
|
||||
lastUnlockTable = null;
|
||||
}
|
||||
});
|
||||
table.margin(12);
|
||||
//if there's currently no unlock notification...
|
||||
if(lastUnlockTable == null){
|
||||
Table table = new Table("button");
|
||||
table.update(() -> {
|
||||
if(state.is(State.menu)){
|
||||
table.remove();
|
||||
lastUnlockLayout = null;
|
||||
lastUnlockTable = null;
|
||||
}
|
||||
});
|
||||
table.margin(12);
|
||||
|
||||
Table in = new Table();
|
||||
Table in = new Table();
|
||||
|
||||
//create texture stack for displaying
|
||||
Stack stack = new Stack();
|
||||
for (TextureRegion region : recipe.result.getCompactIcon()) {
|
||||
Image image = new Image(region);
|
||||
image.setScaling(Scaling.fit);
|
||||
stack.add(image);
|
||||
}
|
||||
//create texture stack for displaying
|
||||
Stack stack = new Stack();
|
||||
for(TextureRegion region : recipe.result.getCompactIcon()){
|
||||
Image image = new Image(region);
|
||||
image.setScaling(Scaling.fit);
|
||||
stack.add(image);
|
||||
}
|
||||
|
||||
in.add(stack).size(48f).pad(2);
|
||||
in.add(stack).size(48f).pad(2);
|
||||
|
||||
//add to table
|
||||
table.add(in).padRight(8);
|
||||
table.add("$text.unlocked");
|
||||
table.pack();
|
||||
//add to table
|
||||
table.add(in).padRight(8);
|
||||
table.add("$text.unlocked");
|
||||
table.pack();
|
||||
|
||||
//create container table which will align and move
|
||||
Table container = Core.scene.table();
|
||||
container.top().add(table);
|
||||
container.setTranslation(0, table.getPrefHeight());
|
||||
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(4f),
|
||||
//nesting actions() calls is necessary so the right prefHeight() is used
|
||||
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.run(() ->{
|
||||
lastUnlockTable = null;
|
||||
lastUnlockLayout = null;
|
||||
}), Actions.removeActor())));
|
||||
//create container table which will align and move
|
||||
Table container = Core.scene.table();
|
||||
container.top().add(table);
|
||||
container.setTranslation(0, table.getPrefHeight());
|
||||
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(4f),
|
||||
//nesting actions() calls is necessary so the right prefHeight() is used
|
||||
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.run(() -> {
|
||||
lastUnlockTable = null;
|
||||
lastUnlockLayout = null;
|
||||
}), Actions.removeActor())));
|
||||
|
||||
lastUnlockTable = container;
|
||||
lastUnlockLayout = in;
|
||||
}else{
|
||||
//max column size
|
||||
int col = 3;
|
||||
//max amount of elements minus extra 'plus'
|
||||
int cap = col*col-1;
|
||||
lastUnlockTable = container;
|
||||
lastUnlockLayout = in;
|
||||
}else{
|
||||
//max column size
|
||||
int col = 3;
|
||||
//max amount of elements minus extra 'plus'
|
||||
int cap = col * col - 1;
|
||||
|
||||
//get old elements
|
||||
Array<Element> elements = new Array<>(lastUnlockLayout.getChildren());
|
||||
int esize = elements.size;
|
||||
//get old elements
|
||||
Array<Element> elements = new Array<>(lastUnlockLayout.getChildren());
|
||||
int esize = elements.size;
|
||||
|
||||
//...if it's already reached the cap, ignore everything
|
||||
if(esize > cap) return;
|
||||
//...if it's already reached the cap, ignore everything
|
||||
if(esize > cap) return;
|
||||
|
||||
//get size of each element
|
||||
float size = 48f / Math.min(elements.size + 1, col);
|
||||
//get size of each element
|
||||
float size = 48f / Math.min(elements.size + 1, col);
|
||||
|
||||
//correct plurals if needed
|
||||
if(esize == 1){
|
||||
((Label)lastUnlockLayout.getParent().find(e -> e instanceof Label)).setText("$text.unlocked.plural");
|
||||
}
|
||||
//correct plurals if needed
|
||||
if(esize == 1){
|
||||
((Label) lastUnlockLayout.getParent().find(e -> e instanceof Label)).setText("$text.unlocked.plural");
|
||||
}
|
||||
|
||||
lastUnlockLayout.clearChildren();
|
||||
lastUnlockLayout.defaults().size(size).pad(2);
|
||||
lastUnlockLayout.clearChildren();
|
||||
lastUnlockLayout.defaults().size(size).pad(2);
|
||||
|
||||
for(int i = 0; i < esize && i <= cap; i ++){
|
||||
lastUnlockLayout.add(elements.get(i));
|
||||
for(int i = 0; i < esize && i <= cap; i++){
|
||||
lastUnlockLayout.add(elements.get(i));
|
||||
|
||||
if(i % col == col - 1){
|
||||
lastUnlockLayout.row();
|
||||
}
|
||||
}
|
||||
if(i % col == col - 1){
|
||||
lastUnlockLayout.row();
|
||||
}
|
||||
}
|
||||
|
||||
//if there's space, add it
|
||||
if(esize < cap) {
|
||||
//if there's space, add it
|
||||
if(esize < cap){
|
||||
|
||||
Stack stack = new Stack();
|
||||
for (TextureRegion region : recipe.result.getCompactIcon()) {
|
||||
Image image = new Image(region);
|
||||
image.setScaling(Scaling.fit);
|
||||
stack.add(image);
|
||||
}
|
||||
Stack stack = new Stack();
|
||||
for(TextureRegion region : recipe.result.getCompactIcon()){
|
||||
Image image = new Image(region);
|
||||
image.setScaling(Scaling.fit);
|
||||
stack.add(image);
|
||||
}
|
||||
|
||||
lastUnlockLayout.add(stack);
|
||||
}else{ //else, add a specific icon to denote no more space
|
||||
lastUnlockLayout.addImage("icon-add");
|
||||
}
|
||||
lastUnlockLayout.add(stack);
|
||||
}else{ //else, add a specific icon to denote no more space
|
||||
lastUnlockLayout.addImage("icon-add");
|
||||
}
|
||||
|
||||
lastUnlockLayout.pack();
|
||||
}
|
||||
}
|
||||
lastUnlockLayout.pack();
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleMenus(){
|
||||
wavetable.clearActions();
|
||||
infolabel.clearActions();
|
||||
private void toggleMenus(){
|
||||
wavetable.clearActions();
|
||||
infolabel.clearActions();
|
||||
|
||||
float dur = 0.3f;
|
||||
Interpolation in = Interpolation.pow3Out;
|
||||
float dur = 0.3f;
|
||||
Interpolation in = Interpolation.pow3Out;
|
||||
|
||||
flip.getStyle().imageUp = Core.skin.getDrawable(shown ? "icon-arrow-down" : "icon-arrow-up");
|
||||
flip.getStyle().imageUp = Core.skin.getDrawable(shown ? "icon-arrow-down" : "icon-arrow-up");
|
||||
|
||||
if (shown) {
|
||||
shown = false;
|
||||
blockfrag.toggle(false, dur, in);
|
||||
wavetable.actions(Actions.translateBy(0, (wavetable.getHeight() + dsize) - wavetable.getTranslation().y, dur, in));
|
||||
infolabel.actions(Actions.translateBy(0, (wavetable.getHeight()) - wavetable.getTranslation().y, dur, in));
|
||||
} else {
|
||||
shown = true;
|
||||
blockfrag.toggle(true, dur, in);
|
||||
wavetable.actions(Actions.translateBy(0, -wavetable.getTranslation().y, dur, in));
|
||||
infolabel.actions(Actions.translateBy(0, -infolabel.getTranslation().y, dur, in));
|
||||
}
|
||||
}
|
||||
if(shown){
|
||||
shown = false;
|
||||
blockfrag.toggle(false, dur, in);
|
||||
wavetable.actions(Actions.translateBy(0, (wavetable.getHeight() + dsize) - wavetable.getTranslation().y, dur, in));
|
||||
infolabel.actions(Actions.translateBy(0, (wavetable.getHeight()) - wavetable.getTranslation().y, dur, in));
|
||||
}else{
|
||||
shown = true;
|
||||
blockfrag.toggle(true, dur, in);
|
||||
wavetable.actions(Actions.translateBy(0, -wavetable.getTranslation().y, dur, in));
|
||||
infolabel.actions(Actions.translateBy(0, -infolabel.getTranslation().y, dur, in));
|
||||
}
|
||||
}
|
||||
|
||||
private String getEnemiesRemaining() {
|
||||
int enemies = unitGroups[Team.red.ordinal()].size();
|
||||
if(enemies == 1) {
|
||||
return Bundles.format("text.enemies.single", enemies);
|
||||
} else {
|
||||
return Bundles.format("text.enemies", enemies);
|
||||
}
|
||||
}
|
||||
private String getEnemiesRemaining(){
|
||||
int enemies = unitGroups[Team.red.ordinal()].size();
|
||||
if(enemies == 1){
|
||||
return Bundles.format("text.enemies.single", enemies);
|
||||
}else{
|
||||
return Bundles.format("text.enemies", enemies);
|
||||
}
|
||||
}
|
||||
|
||||
private void addWaveTable(){
|
||||
float uheight = 66f;
|
||||
private void addWaveTable(){
|
||||
float uheight = 66f;
|
||||
|
||||
IntFormat wavef = new IntFormat("text.wave");
|
||||
IntFormat timef = new IntFormat("text.wave.waiting");
|
||||
IntFormat wavef = new IntFormat("text.wave");
|
||||
IntFormat timef = new IntFormat("text.wave.waiting");
|
||||
|
||||
wavetable = new table("button"){{
|
||||
aleft();
|
||||
new table(){{
|
||||
aleft();
|
||||
wavetable = new table("button"){{
|
||||
aleft();
|
||||
new table(){{
|
||||
aleft();
|
||||
|
||||
new label(() -> wavef.get(state.wave)).scale(fontScale *1.5f).left().padLeft(-6);
|
||||
new label(() -> wavef.get(state.wave)).scale(fontScale * 1.5f).left().padLeft(-6);
|
||||
|
||||
row();
|
||||
row();
|
||||
|
||||
new label(() -> unitGroups[Team.red.ordinal()].size() > 0 && state.mode.disableWaveTimer ?
|
||||
getEnemiesRemaining() :
|
||||
(state.mode.disableWaveTimer) ? "$text.waiting"
|
||||
: timef.get((int) (state.wavetime / 60f)))
|
||||
.minWidth(126).padLeft(-6).left();
|
||||
new label(() -> unitGroups[Team.red.ordinal()].size() > 0 && state.mode.disableWaveTimer ?
|
||||
getEnemiesRemaining() :
|
||||
(state.mode.disableWaveTimer) ? "$text.waiting"
|
||||
: timef.get((int) (state.wavetime / 60f)))
|
||||
.minWidth(126).padLeft(-6).left();
|
||||
|
||||
margin(10f);
|
||||
get().marginLeft(6);
|
||||
}}.left().end();
|
||||
margin(10f);
|
||||
get().marginLeft(6);
|
||||
}}.left().end();
|
||||
|
||||
add().growX();
|
||||
add().growX();
|
||||
|
||||
playButton(uheight);
|
||||
}}.height(uheight).fillX().expandX().end().get();
|
||||
wavetable.getParent().getParent().swapActor(wavetable.getParent(), menu.getParent());
|
||||
}
|
||||
playButton(uheight);
|
||||
}}.height(uheight).fillX().expandX().end().get();
|
||||
wavetable.getParent().getParent().swapActor(wavetable.getParent(), menu.getParent());
|
||||
}
|
||||
|
||||
private void playButton(float uheight){
|
||||
new imagebutton("icon-play", 30f, () -> {
|
||||
if(Net.client() && players[0].isAdmin){
|
||||
Call.onAdminRequest(players[0], AdminAction.wave);
|
||||
}else {
|
||||
state.wavetime = 0f;
|
||||
}
|
||||
}).height(uheight).fillX().right().padTop(-8f).padBottom(-12f).padLeft(-15).padRight(-10).width(40f).update(l->{
|
||||
boolean vis = state.mode.disableWaveTimer && ((Net.server() || players[0].isAdmin) || !Net.active());
|
||||
boolean paused = state.is(State.paused) || !vis;
|
||||
private void playButton(float uheight){
|
||||
new imagebutton("icon-play", 30f, () -> {
|
||||
if(Net.client() && players[0].isAdmin){
|
||||
Call.onAdminRequest(players[0], AdminAction.wave);
|
||||
}else{
|
||||
state.wavetime = 0f;
|
||||
}
|
||||
}).height(uheight).fillX().right().padTop(-8f).padBottom(-12f).padLeft(-15).padRight(-10).width(40f).update(l -> {
|
||||
boolean vis = state.mode.disableWaveTimer && ((Net.server() || players[0].isAdmin) || !Net.active());
|
||||
boolean paused = state.is(State.paused) || !vis;
|
||||
|
||||
l.getStyle().imageUp = Core.skin.getDrawable(vis ? "icon-play" : "clear");
|
||||
l.setTouchable(!paused ? Touchable.enabled : Touchable.disabled);
|
||||
}).visible(() -> state.mode.disableWaveTimer && ((Net.server() || players[0].isAdmin) || !Net.active()) && unitGroups[Team.red.ordinal()].size() == 0);
|
||||
}
|
||||
l.getStyle().imageUp = Core.skin.getDrawable(vis ? "icon-play" : "clear");
|
||||
l.setTouchable(!paused ? Touchable.enabled : Touchable.disabled);
|
||||
}).visible(() -> state.mode.disableWaveTimer && ((Net.server() || players[0].isAdmin) || !Net.active()) && unitGroups[Team.red.ordinal()].size() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ import io.anuke.ucore.scene.ui.Label;
|
||||
import io.anuke.ucore.scene.ui.TextButton;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
public class LoadingFragment extends Fragment {
|
||||
public class LoadingFragment extends Fragment{
|
||||
private Table table;
|
||||
private TextButton button;
|
||||
|
||||
@Override
|
||||
public void build(Group parent) {
|
||||
public void build(Group parent){
|
||||
|
||||
table = new table("loadDim"){{
|
||||
table = new table("loadDim"){{
|
||||
add().height(70f).row();
|
||||
|
||||
touchable(Touchable.enabled);
|
||||
@@ -33,7 +33,8 @@ public class LoadingFragment extends Fragment {
|
||||
|
||||
row();
|
||||
|
||||
button = get().addButton("$text.cancel", () -> {}).pad(20).size(250f, 70f).get();
|
||||
button = get().addButton("$text.cancel", () -> {
|
||||
}).pad(20).size(250f, 70f).get();
|
||||
button.setVisible(false);
|
||||
}}.end().get();
|
||||
|
||||
|
||||
@@ -18,175 +18,175 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class MenuFragment extends Fragment{
|
||||
private Table mobileContainer;
|
||||
private Table mobileContainer;
|
||||
|
||||
@Override
|
||||
public void build(Group parent){
|
||||
new table(){{
|
||||
visible(() -> state.is(State.menu));
|
||||
@Override
|
||||
public void build(Group parent){
|
||||
new table(){{
|
||||
visible(() -> state.is(State.menu));
|
||||
|
||||
if(!mobile){
|
||||
buildDesktop();
|
||||
}else{
|
||||
buildMobile();
|
||||
if(!mobile){
|
||||
buildDesktop();
|
||||
}else{
|
||||
buildMobile();
|
||||
|
||||
Events.on(ResizeEvent.class, () -> buildMobile());
|
||||
}
|
||||
}}.end();
|
||||
Events.on(ResizeEvent.class, () -> buildMobile());
|
||||
}
|
||||
}}.end();
|
||||
|
||||
//discord icon in top right
|
||||
if(Platform.instance.hasDiscord()) {
|
||||
new table() {{
|
||||
abottom().atop().aright();
|
||||
get().addButton("", "discord", ui.discord::show).size(81, 42);
|
||||
}}.end().visible(() -> state.is(State.menu));
|
||||
}
|
||||
//discord icon in top right
|
||||
if(Platform.instance.hasDiscord()){
|
||||
new table(){{
|
||||
abottom().atop().aright();
|
||||
get().addButton("", "discord", ui.discord::show).size(81, 42);
|
||||
}}.end().visible(() -> state.is(State.menu));
|
||||
}
|
||||
|
||||
//info icon
|
||||
if(mobile) {
|
||||
new table() {{
|
||||
abottom().atop().aleft();
|
||||
get().addButton("", "info", ui.about::show).size(81, 42);
|
||||
}}.end().visible(() -> state.is(State.menu));
|
||||
}
|
||||
//info icon
|
||||
if(mobile){
|
||||
new table(){{
|
||||
abottom().atop().aleft();
|
||||
get().addButton("", "info", ui.about::show).size(81, 42);
|
||||
}}.end().visible(() -> state.is(State.menu));
|
||||
}
|
||||
|
||||
//version info
|
||||
new table(){{
|
||||
visible(() -> state.is(State.menu));
|
||||
abottom().aleft();
|
||||
new label("Mindustry " + Version.code + " " + Version.type + " / " + Version.buildName);
|
||||
}}.end();
|
||||
}
|
||||
//version info
|
||||
new table(){{
|
||||
visible(() -> state.is(State.menu));
|
||||
abottom().aleft();
|
||||
new label("Mindustry " + Version.code + " " + Version.type + " / " + Version.buildName);
|
||||
}}.end();
|
||||
}
|
||||
|
||||
private void buildMobile(){
|
||||
if(mobileContainer == null){
|
||||
mobileContainer = build.getTable();
|
||||
}
|
||||
private void buildMobile(){
|
||||
if(mobileContainer == null){
|
||||
mobileContainer = build.getTable();
|
||||
}
|
||||
|
||||
mobileContainer.clear();
|
||||
mobileContainer.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
mobileContainer.clear();
|
||||
mobileContainer.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
|
||||
float size = 120f;
|
||||
float isize = 14f * 4;
|
||||
mobileContainer.defaults().size(size).pad(5).padTop(4f);
|
||||
float size = 120f;
|
||||
float isize = 14f * 4;
|
||||
mobileContainer.defaults().size(size).pad(5).padTop(4f);
|
||||
|
||||
MobileButton
|
||||
play = new MobileButton("icon-play-2", isize, "$text.play", ui.levels::show),
|
||||
maps = new MobileButton("icon-map", isize, "$text.maps", ui.maps::show),
|
||||
load = new MobileButton("icon-load", isize, "$text.load", ui.load::show),
|
||||
join = new MobileButton("icon-add", isize, "$text.joingame", ui.join::show),
|
||||
editor = new MobileButton("icon-editor", isize, "$text.editor", () -> ui.loadAnd(ui.editor::show)),
|
||||
tools = new MobileButton("icon-tools", isize, "$text.settings", ui.settings::show),
|
||||
unlocks = new MobileButton("icon-unlocks", isize, "$text.unlocks", ui.unlocks::show),
|
||||
donate = new MobileButton("icon-donate", isize, "$text.donate", Platform.instance::openDonations);
|
||||
MobileButton
|
||||
play = new MobileButton("icon-play-2", isize, "$text.play", ui.levels::show),
|
||||
maps = new MobileButton("icon-map", isize, "$text.maps", ui.maps::show),
|
||||
load = new MobileButton("icon-load", isize, "$text.load", ui.load::show),
|
||||
join = new MobileButton("icon-add", isize, "$text.joingame", ui.join::show),
|
||||
editor = new MobileButton("icon-editor", isize, "$text.editor", () -> ui.loadAnd(ui.editor::show)),
|
||||
tools = new MobileButton("icon-tools", isize, "$text.settings", ui.settings::show),
|
||||
unlocks = new MobileButton("icon-unlocks", isize, "$text.unlocks", ui.unlocks::show),
|
||||
donate = new MobileButton("icon-donate", isize, "$text.donate", Platform.instance::openDonations);
|
||||
|
||||
if(Gdx.graphics.getWidth() > Gdx.graphics.getHeight()){
|
||||
mobileContainer.add(play);
|
||||
mobileContainer.add(join);
|
||||
mobileContainer.add(load);
|
||||
mobileContainer.add(maps);
|
||||
mobileContainer.row();
|
||||
if(Gdx.graphics.getWidth() > Gdx.graphics.getHeight()){
|
||||
mobileContainer.add(play);
|
||||
mobileContainer.add(join);
|
||||
mobileContainer.add(load);
|
||||
mobileContainer.add(maps);
|
||||
mobileContainer.row();
|
||||
|
||||
mobileContainer.table(table -> {
|
||||
table.defaults().set(mobileContainer.defaults());
|
||||
mobileContainer.table(table -> {
|
||||
table.defaults().set(mobileContainer.defaults());
|
||||
|
||||
table.add(editor);
|
||||
table.add(tools);
|
||||
table.add(unlocks);
|
||||
table.add(editor);
|
||||
table.add(tools);
|
||||
table.add(unlocks);
|
||||
|
||||
if(Platform.instance.canDonate()) table.add(donate);
|
||||
}).colspan(4);
|
||||
}else{
|
||||
mobileContainer.add(play);
|
||||
mobileContainer.add(maps);
|
||||
mobileContainer.row();
|
||||
mobileContainer.add(load);
|
||||
mobileContainer.add(join);
|
||||
mobileContainer.row();
|
||||
mobileContainer.add(editor);
|
||||
mobileContainer.add(tools);
|
||||
mobileContainer.row();
|
||||
if(Platform.instance.canDonate()) table.add(donate);
|
||||
}).colspan(4);
|
||||
}else{
|
||||
mobileContainer.add(play);
|
||||
mobileContainer.add(maps);
|
||||
mobileContainer.row();
|
||||
mobileContainer.add(load);
|
||||
mobileContainer.add(join);
|
||||
mobileContainer.row();
|
||||
mobileContainer.add(editor);
|
||||
mobileContainer.add(tools);
|
||||
mobileContainer.row();
|
||||
|
||||
mobileContainer.table(table -> {
|
||||
table.defaults().set(mobileContainer.defaults());
|
||||
mobileContainer.table(table -> {
|
||||
table.defaults().set(mobileContainer.defaults());
|
||||
|
||||
table.add(unlocks);
|
||||
table.add(unlocks);
|
||||
|
||||
if(Platform.instance.canDonate()) table.add(donate);
|
||||
}).colspan(2);
|
||||
}
|
||||
}
|
||||
if(Platform.instance.canDonate()) table.add(donate);
|
||||
}).colspan(2);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildDesktop(){
|
||||
new table(){{
|
||||
private void buildDesktop(){
|
||||
new table(){{
|
||||
|
||||
float w = 200f;
|
||||
float bw = w * 2f + 10f;
|
||||
float w = 200f;
|
||||
float bw = w * 2f + 10f;
|
||||
|
||||
defaults().size(w, 66f).padTop(5).padRight(5);
|
||||
defaults().size(w, 66f).padTop(5).padRight(5);
|
||||
|
||||
add(new MenuButton("icon-play-2", "$text.play", MenuFragment.this::showPlaySelect)).width(bw).colspan(2);
|
||||
add(new MenuButton("icon-play-2", "$text.play", MenuFragment.this::showPlaySelect)).width(bw).colspan(2);
|
||||
|
||||
row();
|
||||
row();
|
||||
|
||||
add(new MenuButton("icon-editor", "$text.editor", () -> ui.loadAnd(ui.editor::show)));
|
||||
add(new MenuButton("icon-editor", "$text.editor", () -> ui.loadAnd(ui.editor::show)));
|
||||
|
||||
add(new MenuButton("icon-map", "$text.maps", ui.maps::show));
|
||||
add(new MenuButton("icon-map", "$text.maps", ui.maps::show));
|
||||
|
||||
row();
|
||||
row();
|
||||
|
||||
add(new MenuButton("icon-info", "$text.about.button", ui.about::show));
|
||||
add(new MenuButton("icon-info", "$text.about.button", ui.about::show));
|
||||
|
||||
add(new MenuButton("icon-tools", "$text.settings", ui.settings::show));
|
||||
add(new MenuButton("icon-tools", "$text.settings", ui.settings::show));
|
||||
|
||||
row();
|
||||
row();
|
||||
|
||||
add(new MenuButton("icon-menu", "$text.changelog.title", ui.changelog::show));
|
||||
add(new MenuButton("icon-menu", "$text.changelog.title", ui.changelog::show));
|
||||
|
||||
add(new MenuButton("icon-unlocks", "$text.unlocks", ui.unlocks::show));
|
||||
add(new MenuButton("icon-unlocks", "$text.unlocks", ui.unlocks::show));
|
||||
|
||||
row();
|
||||
row();
|
||||
|
||||
if(!gwt){
|
||||
add(new MenuButton("icon-exit", "$text.quit", Gdx.app::exit)).width(bw).colspan(2);
|
||||
}
|
||||
if(!gwt){
|
||||
add(new MenuButton("icon-exit", "$text.quit", Gdx.app::exit)).width(bw).colspan(2);
|
||||
}
|
||||
|
||||
get().margin(16);
|
||||
}}.end();
|
||||
}
|
||||
get().margin(16);
|
||||
}}.end();
|
||||
}
|
||||
|
||||
private void showPlaySelect(){
|
||||
float w = 200f;
|
||||
float bw = w * 2f + 10f;
|
||||
private void showPlaySelect(){
|
||||
float w = 200f;
|
||||
float bw = w * 2f + 10f;
|
||||
|
||||
FloatingDialog dialog = new FloatingDialog("$text.play");
|
||||
dialog.addCloseButton();
|
||||
dialog.content().defaults().height(66f).width(w).padRight(5f);
|
||||
FloatingDialog dialog = new FloatingDialog("$text.play");
|
||||
dialog.addCloseButton();
|
||||
dialog.content().defaults().height(66f).width(w).padRight(5f);
|
||||
|
||||
dialog.content().add(new MenuButton("icon-play-2", "$text.newgame", () -> {
|
||||
dialog.hide();
|
||||
ui.levels.show();
|
||||
})).width(bw).colspan(2);
|
||||
dialog.content().row();
|
||||
dialog.content().add(new MenuButton("icon-play-2", "$text.newgame", () -> {
|
||||
dialog.hide();
|
||||
ui.levels.show();
|
||||
})).width(bw).colspan(2);
|
||||
dialog.content().row();
|
||||
|
||||
dialog.content().add(new MenuButton("icon-add", "$text.joingame", () -> {
|
||||
if(Platform.instance.canJoinGame()){
|
||||
ui.join.show();
|
||||
dialog.hide();
|
||||
}else{
|
||||
ui.showInfo("$text.multiplayer.web");
|
||||
}
|
||||
}));
|
||||
dialog.content().add(new MenuButton("icon-add", "$text.joingame", () -> {
|
||||
if(Platform.instance.canJoinGame()){
|
||||
ui.join.show();
|
||||
dialog.hide();
|
||||
}else{
|
||||
ui.showInfo("$text.multiplayer.web");
|
||||
}
|
||||
}));
|
||||
|
||||
dialog.content().add(new MenuButton("icon-tutorial", "$text.tutorial", ()-> ui.showInfo("The tutorial is currently not yet implemented.")));
|
||||
dialog.content().add(new MenuButton("icon-tutorial", "$text.tutorial", () -> ui.showInfo("The tutorial is currently not yet implemented.")));
|
||||
|
||||
dialog.content().row();
|
||||
dialog.content().row();
|
||||
|
||||
dialog.content().add(new MenuButton("icon-load", "$text.loadgame", () -> {
|
||||
ui.load.show();
|
||||
dialog.hide();
|
||||
})).width(bw).colspan(2);
|
||||
dialog.content().add(new MenuButton("icon-load", "$text.loadgame", () -> {
|
||||
ui.load.show();
|
||||
dialog.hide();
|
||||
})).width(bw).colspan(2);
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package io.anuke.mindustry.ui.fragments;
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
|
||||
/**Fragment for displaying overlays such as block inventories. One is created for each input handler.*/
|
||||
/**
|
||||
* Fragment for displaying overlays such as block inventories. One is created for each input handler.
|
||||
*/
|
||||
public class OverlayFragment extends Fragment{
|
||||
public final BlockInventoryFragment inv;
|
||||
public final BlockConfigFragment config;
|
||||
|
||||
@@ -116,26 +116,26 @@ public class PlayerListFragment extends Fragment{
|
||||
button.labelWrap("[#" + player.color.toString().toUpperCase() + "]" + player.name).width(170f).pad(10);
|
||||
button.add().grow();
|
||||
|
||||
button.addImage("icon-admin").size(14*2).visible(() -> player.isAdmin && !(!player.isLocal && Net.server())).padRight(5);
|
||||
button.addImage("icon-admin").size(14 * 2).visible(() -> player.isAdmin && !(!player.isLocal && Net.server())).padRight(5);
|
||||
|
||||
if((Net.server() || players[0].isAdmin) && !player.isLocal && (!player.isAdmin || Net.server())){
|
||||
button.add().growY();
|
||||
|
||||
float bs = (h + 14)/2f;
|
||||
float bs = (h + 14) / 2f;
|
||||
|
||||
button.table(t -> {
|
||||
t.defaults().size(bs - 1, bs + 3);
|
||||
//TODO requests.
|
||||
|
||||
t.addImageButton("icon-ban", 14*2, () -> {
|
||||
t.addImageButton("icon-ban", 14 * 2, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.confirmban", () -> Call.onAdminRequest(player, AdminAction.ban));
|
||||
}).padBottom(-5.1f);
|
||||
|
||||
t.addImageButton("icon-cancel", 14*2, () -> Call.onAdminRequest(player, AdminAction.kick)).padBottom(-5.1f);
|
||||
t.addImageButton("icon-cancel", 14 * 2, () -> Call.onAdminRequest(player, AdminAction.kick)).padBottom(-5.1f);
|
||||
|
||||
t.row();
|
||||
|
||||
t.addImageButton("icon-admin", "toggle", 14*2, () -> {
|
||||
t.addImageButton("icon-admin", "toggle", 14 * 2, () -> {
|
||||
if(Net.client()) return;
|
||||
|
||||
String id = netServer.admins.getTraceByID(player.uuid).uuid;
|
||||
@@ -154,7 +154,7 @@ public class PlayerListFragment extends Fragment{
|
||||
b.setDisabled(Net.client());
|
||||
}).get().setTouchable(() -> Net.client() ? Touchable.disabled : Touchable.enabled);
|
||||
|
||||
t.addImageButton("icon-zoom-small", 14*2, () -> Call.onAdminRequest(player, AdminAction.trace));
|
||||
t.addImageButton("icon-zoom-small", 14 * 2, () -> Call.onAdminRequest(player, AdminAction.trace));
|
||||
|
||||
}).padRight(12).padTop(-5).padLeft(0).padBottom(-10).size(bs + 10f, bs);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user