New sector dialog done
This commit is contained in:
@@ -13,7 +13,6 @@ import io.anuke.ucore.scene.ui.Dialog;
|
||||
import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
public class FloatingDialog extends Dialog{
|
||||
private boolean wasPaused;
|
||||
@@ -29,19 +28,16 @@ public class FloatingDialog extends Dialog{
|
||||
|
||||
hidden(() -> {
|
||||
if(shouldPause && !state.is(State.menu)){
|
||||
if(!wasPaused || Net.active())
|
||||
if(!wasPaused || Net.active()){
|
||||
state.set(State.playing);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
shown(() -> {
|
||||
if(shouldPause && !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();
|
||||
state.set(State.paused);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -71,8 +67,9 @@ public class FloatingDialog extends Dialog{
|
||||
buttons().addImageTextButton("$text.back", "icon-arrow-left", 30f, this::hide).size(230f, 64f);
|
||||
|
||||
keyDown(key -> {
|
||||
if(key == Keys.ESCAPE || key == Keys.BACK)
|
||||
hide();
|
||||
if(key == Keys.ESCAPE || key == Keys.BACK) {
|
||||
Gdx.app.postRunnable(this::hide);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,8 +177,6 @@ public class JoinDialog extends FloatingDialog{
|
||||
t.add("[lightgray]" + Bundles.format("text.save.map", host.mapname) + " / " + Bundles.format("text.save.wave", host.wave)).left();
|
||||
}).expand().left().bottom().padLeft(12f).padBottom(8);
|
||||
|
||||
//server.content.add(versionString).top().expandY().top().expandX();
|
||||
|
||||
}, e -> {
|
||||
server.content.clear();
|
||||
server.content.add("$text.host.invalid");
|
||||
@@ -321,7 +319,6 @@ public class JoinDialog extends FloatingDialog{
|
||||
public String ip;
|
||||
public int port;
|
||||
|
||||
transient Host host;
|
||||
transient Table content;
|
||||
|
||||
void setIP(String ip){
|
||||
|
||||
@@ -147,9 +147,14 @@ public class MapsDialog extends FloatingDialog{
|
||||
table.row();
|
||||
|
||||
table.addImageTextButton("$text.editor.openin", "icon-load-map", "clear", 16 * 2, () -> {
|
||||
Vars.ui.editor.beginEditMap(map.stream.get());
|
||||
dialog.hide();
|
||||
hide();
|
||||
try{
|
||||
Vars.ui.editor.beginEditMap(map.stream.get());
|
||||
dialog.hide();
|
||||
hide();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
ui.showError("$text.error.mapnotfound");
|
||||
}
|
||||
}).fillX().height(50f).marginLeft(6);
|
||||
|
||||
table.addImageTextButton("$text.delete", "icon-trash-16", "clear", 16 * 2, () -> {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
@@ -8,16 +9,22 @@ import io.anuke.ucore.util.Bundles;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class PausedDialog extends FloatingDialog{
|
||||
public boolean wasPaused = false;
|
||||
private SaveDialog save = new SaveDialog();
|
||||
private LoadDialog load = new LoadDialog();
|
||||
private Table missionTable;
|
||||
|
||||
public PausedDialog(){
|
||||
super("$text.menu");
|
||||
shouldPause = true;
|
||||
setup();
|
||||
|
||||
shown(this::rebuild);
|
||||
|
||||
keyDown(key -> {
|
||||
if(key == Keys.ESCAPE || key == Keys.BACK) {
|
||||
hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void rebuild(){
|
||||
@@ -40,11 +47,6 @@ public class PausedDialog extends FloatingDialog{
|
||||
}
|
||||
});
|
||||
|
||||
shown(() -> {
|
||||
wasPaused = state.is(State.paused);
|
||||
if(!Net.active()) state.set(State.paused);
|
||||
});
|
||||
|
||||
content().table(t -> missionTable = t).colspan(mobile ? 3 : 1);
|
||||
content().row();
|
||||
|
||||
@@ -53,8 +55,6 @@ public class PausedDialog extends FloatingDialog{
|
||||
|
||||
content().addButton("$text.back", () -> {
|
||||
hide();
|
||||
if((!wasPaused || Net.active()) && !state.is(State.menu))
|
||||
state.set(State.playing);
|
||||
});
|
||||
|
||||
content().row();
|
||||
@@ -86,8 +86,6 @@ public class PausedDialog extends FloatingDialog{
|
||||
|
||||
content().addRowImageTextButton("$text.back", "icon-play-2", isize, () -> {
|
||||
hide();
|
||||
if(!wasPaused && !state.is(State.menu))
|
||||
state.set(State.playing);
|
||||
});
|
||||
content().addRowImageTextButton("$text.settings", "icon-tools", isize, ui.settings::show);
|
||||
content().addRowImageTextButton("$text.save", "icon-save", isize, save::show).disabled(b -> world.getSector() != null);
|
||||
|
||||
@@ -1,68 +1,119 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.maps.Sector;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.event.InputEvent;
|
||||
import io.anuke.ucore.scene.event.InputListener;
|
||||
import io.anuke.ucore.scene.event.Touchable;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
import io.anuke.ucore.scene.utils.ScissorStack;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class SectorsDialog extends FloatingDialog{
|
||||
private Rectangle clip = new Rectangle();
|
||||
private static final float sectorSize = Unit.dp.scl(32*5);
|
||||
private Sector selected;
|
||||
private Table table;
|
||||
private SectorView view;
|
||||
|
||||
public SectorsDialog(){
|
||||
super("$text.sectors");
|
||||
super("");
|
||||
|
||||
table = new Table(){
|
||||
@Override
|
||||
public float getPrefWidth(){
|
||||
return sectorSize*2f;
|
||||
}
|
||||
};
|
||||
table.visible(() -> selected != null);
|
||||
table.update(() -> {
|
||||
if(selected != null){
|
||||
|
||||
int offsetX = (int)(view.panX / sectorSize);
|
||||
int offsetY = (int)(view.panY / sectorSize);
|
||||
float drawX = x + width/2f+ selected.x * (sectorSize-2) - offsetX * sectorSize - view.panX % sectorSize + sectorSize/2f;
|
||||
float drawY = y + height/2f + selected.y * (sectorSize-2) - offsetY * sectorSize - view.panY % sectorSize + sectorSize/2f;
|
||||
|
||||
table.setPosition(drawX, drawY - sectorSize/2f + 1, Align.top);
|
||||
}
|
||||
});
|
||||
|
||||
Group container = new Group();
|
||||
container.setTouchable(Touchable.childrenOnly);
|
||||
container.addChild(table);
|
||||
|
||||
margin(0);
|
||||
getTitleTable().clear();
|
||||
clear();
|
||||
stack(content(), buttons(), container).grow();
|
||||
|
||||
shown(this::setup);
|
||||
}
|
||||
|
||||
void setup(){
|
||||
selected = null;
|
||||
|
||||
table.clear();
|
||||
content().clear();
|
||||
buttons().clear();
|
||||
buttons().bottom().margin(15);
|
||||
|
||||
addCloseButton();
|
||||
|
||||
content().label(() -> Bundles.format("text.sector", selected == null ? Bundles.get("text.none") :
|
||||
(selected.x + ", " + selected.y + (!selected.complete && selected.saveID != -1 ? " " + Bundles.get("text.sector.locked") : ""))
|
||||
+ (selected.saveID == -1 ? " " + Bundles.get("text.sector.unexplored") :
|
||||
(selected.hasSave() ? " [accent]/[white] " + Bundles.format("text.sector.time", selected.getSave().getPlayTime()) : ""))));
|
||||
content().row();
|
||||
content().label(() -> Bundles.format("text.mission.main", selected == null || selected.completedMissions >= selected.missions.size
|
||||
? Bundles.get("text.none") : selected.getDominantMission().menuDisplayString()));
|
||||
content().row();
|
||||
content().add(new SectorView()).grow();
|
||||
content().row();
|
||||
|
||||
buttons().addImageTextButton("$text.sector.abandon", "icon-cancel", 16*2, () ->
|
||||
ui.showConfirm("$text.confirm", "$text.sector.abandon.confirm", () -> world.sectors.abandonSector(selected)))
|
||||
.size(200f, 64f).disabled(b -> selected == null || !selected.hasSave());
|
||||
|
||||
buttons().row();
|
||||
|
||||
buttons().addImageTextButton("$text.sector.deploy", "icon-play", 10*3, () -> {
|
||||
hide();
|
||||
ui.loadLogic(() -> world.sectors.playSector(selected));
|
||||
}).disabled(b -> selected == null)
|
||||
.fillX().height(64f).colspan(2).update(t -> t.setText(selected != null && selected.hasSave() ? "$text.sector.resume" : "$text.sector.deploy"));
|
||||
content().add(view = new SectorView()).grow();
|
||||
}
|
||||
|
||||
void selectSector(Sector sector){
|
||||
Log.info((int)' ');
|
||||
selected = sector;
|
||||
|
||||
table.clear();
|
||||
table.background("button").margin(5);
|
||||
|
||||
table.defaults().pad(3);
|
||||
table.add(Bundles.format("text.sector", sector.x + ", " + sector.y));
|
||||
table.row();
|
||||
|
||||
if(selected.completedMissions < selected.missions.size && !selected.complete){
|
||||
table.labelWrap(Bundles.format("text.mission", selected.getDominantMission().menuDisplayString())).growX();
|
||||
table.row();
|
||||
}
|
||||
|
||||
if(selected.hasSave()){
|
||||
table.labelWrap(Bundles.format("text.sector.time", selected.getSave().getPlayTime())).growX();
|
||||
table.row();
|
||||
}
|
||||
|
||||
table.table(t -> {
|
||||
t.addImageTextButton(sector.hasSave() ? "$text.sector.resume" : "$text.sector.deploy", "icon-play", 10*3, () -> {
|
||||
hide();
|
||||
Vars.ui.loadLogic(() -> world.sectors.playSector(selected));
|
||||
}).height(60f).growX();
|
||||
|
||||
if(selected.hasSave()){
|
||||
t.addImageTextButton("$text.sector.abandon", "icon-cancel", 16 * 2, () ->
|
||||
Vars.ui.showConfirm("$text.confirm", "$text.sector.abandon.confirm", () -> world.sectors.abandonSector(selected))
|
||||
).width(sectorSize).height(60f);
|
||||
}
|
||||
}).pad(-5).growX().padTop(0);
|
||||
|
||||
table.pack();
|
||||
table.act(Gdx.graphics.getDeltaTime());
|
||||
}
|
||||
|
||||
public Sector getSelected(){
|
||||
@@ -71,17 +122,15 @@ public class SectorsDialog extends FloatingDialog{
|
||||
|
||||
class SectorView extends Element{
|
||||
float lastX, lastY;
|
||||
float sectorSize = Unit.dp.scl(32*5);
|
||||
float sectorPadding = Unit.dp.scl(14f);
|
||||
boolean clicked = false;
|
||||
float panX = -sectorPadding/2f, panY = -sectorSize/2f;
|
||||
float panX = 0, panY = -sectorSize/2f;
|
||||
|
||||
SectorView(){
|
||||
addListener(new InputListener(){
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
|
||||
if(pointer != 0) return false;
|
||||
Cursors.setHand();
|
||||
//Cursors.setHand();
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
return true;
|
||||
@@ -111,16 +160,11 @@ public class SectorsDialog extends FloatingDialog{
|
||||
public void draw(){
|
||||
Draw.alpha(alpha);
|
||||
|
||||
float padSectorSize = sectorSize + sectorPadding;
|
||||
int shownSectorsX = (int)(width/sectorSize);
|
||||
int shownSectorsY = (int)(height/sectorSize);
|
||||
|
||||
int shownSectorsX = (int)(width/padSectorSize);
|
||||
int shownSectorsY = (int)(height/padSectorSize);
|
||||
clip.setSize(width, height).setCenter(x + width/2f, y + height/2f);
|
||||
Graphics.flush();
|
||||
boolean clipped = ScissorStack.pushScissors(clip);
|
||||
|
||||
int offsetX = (int)(panX / padSectorSize);
|
||||
int offsetY = (int)(panY / padSectorSize);
|
||||
int offsetX = (int)(panX / sectorSize);
|
||||
int offsetY = (int)(panY / sectorSize);
|
||||
|
||||
Vector2 mouse = Graphics.mouse();
|
||||
|
||||
@@ -129,58 +173,77 @@ public class SectorsDialog extends FloatingDialog{
|
||||
int sectorX = offsetX + x;
|
||||
int sectorY = offsetY + y;
|
||||
|
||||
float drawX = x + width/2f+ sectorX * padSectorSize - offsetX * padSectorSize - panX % padSectorSize;
|
||||
float drawY = y + height/2f + sectorY * padSectorSize - offsetY * padSectorSize - panY % padSectorSize;
|
||||
float drawX = x + width/2f+ sectorX * (sectorSize-2) - offsetX * sectorSize - panX % sectorSize + sectorSize/2f;
|
||||
float drawY = y + height/2f + sectorY * (sectorSize-2) - offsetY * sectorSize - panY % sectorSize + sectorSize/2f;
|
||||
|
||||
Sector sector = world.sectors.get(sectorX, sectorY);
|
||||
int width = 1;
|
||||
int height = 1;
|
||||
float paddingx = (width-1) * sectorPadding;
|
||||
float paddingy = (height-1) * sectorPadding;
|
||||
|
||||
if(sector != null && (sector.x != sectorX || sector.y != sectorY)){
|
||||
if(sector == null || sector.texture == null){
|
||||
Draw.reset();
|
||||
Draw.rect("empty-sector", drawX, drawY, sectorSize, sectorSize);
|
||||
|
||||
int i = 0;
|
||||
for(GridPoint2 point : Geometry.d4){
|
||||
Sector other = world.sectors.get(sectorX + point.x, sectorY + point.y);
|
||||
if(other != null){
|
||||
Draw.rect("sector-edge", drawX, drawY, sectorSize, sectorSize, i*90);
|
||||
}
|
||||
|
||||
i ++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
drawX += (width-1)/2f*padSectorSize;
|
||||
drawY += (height-1)/2f*padSectorSize;
|
||||
Draw.colorl(!sector.complete ? 0.3f : 1f);
|
||||
Draw.rect(sector.texture, drawX, drawY, sectorSize, sectorSize);
|
||||
|
||||
if(sector != null && sector.texture != null){
|
||||
Draw.colorl(!sector.complete ? 0.3f : 1f);
|
||||
Draw.rect(sector.texture, drawX, drawY, sectorSize * width + paddingx, sectorSize * height + paddingy);
|
||||
if(sector.missions.size == 0) continue;
|
||||
|
||||
String region = sector.getDominantMission().getIcon();
|
||||
|
||||
if(sector.complete){
|
||||
region = "icon-mission-done";
|
||||
}
|
||||
|
||||
float stroke = 4f;
|
||||
Color iconColor = Color.WHITE;
|
||||
Color backColor = Color.BLACK;
|
||||
Color selectColor = Color.CLEAR;
|
||||
|
||||
if(sector == null){
|
||||
Draw.color(Color.DARK_GRAY);
|
||||
}else if(sector == selected){
|
||||
Draw.color(Palette.place);
|
||||
stroke = 6f;
|
||||
}else if(Mathf.inRect(mouse.x, mouse.y, drawX - padSectorSize/2f * width, drawY - padSectorSize/2f * height,
|
||||
drawX + padSectorSize/2f * width, drawY + padSectorSize/2f * height)){
|
||||
if(sector == selected){
|
||||
selectColor = Palette.accent;
|
||||
}else if(Mathf.inRect(mouse.x, mouse.y, drawX - sectorSize / 2f, drawY - sectorSize / 2f,
|
||||
drawX + sectorSize / 2f, drawY + sectorSize / 2f)){
|
||||
if(clicked){
|
||||
selectSector(sector);
|
||||
}
|
||||
Draw.color(Palette.remove);
|
||||
}else if (sector.complete){
|
||||
Draw.color(Palette.accent);
|
||||
selectColor = Color.WHITE;
|
||||
}else{
|
||||
Draw.color(Color.LIGHT_GRAY);
|
||||
iconColor = Color.GRAY;
|
||||
}
|
||||
|
||||
Lines.stroke(Unit.dp.scl(stroke));
|
||||
Lines.crect(drawX, drawY, sectorSize * width + paddingx, sectorSize * height + paddingy, (int)stroke);
|
||||
if(sector.complete){
|
||||
iconColor = backColor = Color.CLEAR;
|
||||
}
|
||||
|
||||
Draw.color(selectColor);
|
||||
Draw.rect("sector-select", drawX, drawY, sectorSize, sectorSize);
|
||||
|
||||
Draw.color(backColor);
|
||||
Draw.alpha(0.75f * backColor.a);
|
||||
Draw.rect("icon-mission-background", drawX, drawY, Unit.dp.scl(18f * 5), Unit.dp.scl(18f * 5));
|
||||
|
||||
float size = Unit.dp.scl(10f * 5);
|
||||
|
||||
Draw.color(iconColor);
|
||||
Shaders.outline.color = Color.BLACK;
|
||||
Shaders.outline.region = Draw.region(region);
|
||||
//Graphics.shader(Shaders.outline);
|
||||
Draw.rect(region, drawX, drawY, size, size);
|
||||
//Graphics.shader();
|
||||
}
|
||||
}
|
||||
|
||||
Draw.color(Palette.accent);
|
||||
Lines.stroke(Unit.dp.scl(4f));
|
||||
Lines.crect(x + width/2f, y + height/2f, width, height);
|
||||
|
||||
Draw.reset();
|
||||
Graphics.flush();
|
||||
if(clipped) ScissorStack.popScissors();
|
||||
|
||||
clicked = false;
|
||||
}
|
||||
|
||||
@@ -50,11 +50,7 @@ public class SettingsMenuDialog extends SettingsDialog{
|
||||
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();
|
||||
state.set(State.paused);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ public class UnlocksDialog extends FloatingDialog{
|
||||
public UnlocksDialog(){
|
||||
super("$text.unlocks");
|
||||
|
||||
addCloseButton();
|
||||
shouldPause = true;
|
||||
addCloseButton();
|
||||
shown(this::rebuild);
|
||||
onResize(this::rebuild);
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class UnlocksDialog extends FloatingDialog{
|
||||
|
||||
Array<Content>[] allContent = content.getContentMap();
|
||||
|
||||
for(int j =0; j< allContent.length; j ++){
|
||||
for(int j = 0; j < allContent.length; j ++){
|
||||
ContentType type = ContentType.values()[j];
|
||||
|
||||
Array<Content> array = allContent[j];
|
||||
|
||||
Reference in New Issue
Block a user