Updated uCore / Sector deploying support

This commit is contained in:
Anuken
2018-07-16 20:53:35 -04:00
parent dd45b43d7f
commit 07f0be8d8d
8 changed files with 79 additions and 25 deletions

View File

@@ -8,7 +8,6 @@ import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.maps.Map;
import io.anuke.mindustry.ui.BorderImage;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.ButtonGroup;
@@ -16,7 +15,6 @@ import io.anuke.ucore.scene.ui.ImageButton;
import io.anuke.ucore.scene.ui.ScrollPane;
import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.scene.utils.Elements;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
@@ -119,17 +117,19 @@ public class LevelDialog extends FloatingDialog{
ImageButton genb = maps.addImageButton("icon-editor", "clear", 16 * 3, () -> {
hide();
//TODO
/*
ui.loadfrag.show();
Timers.run(5f, () -> {
Cursors.restoreCursor();
threads.run(() -> {
world.loadProceduralMap();
world.loadProceduralMap(0, 0);
logic.play();
Gdx.app.postRunnable(ui.loadfrag::hide);
});
});
});*/
}).width(170).fillY().pad(4f).get();
genb.top();

View File

@@ -1,20 +1,27 @@
package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.graphics.Palette;
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.event.ClickListener;
import io.anuke.ucore.scene.event.InputEvent;
import io.anuke.ucore.scene.event.InputListener;
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.Mathf;
import static io.anuke.mindustry.Vars.world;
import static io.anuke.mindustry.Vars.*;
public class SectorsDialog extends FloatingDialog{
private Rectangle clip = new Rectangle();
private Sector selected;
public SectorsDialog(){
super("$text.sectors");
@@ -26,13 +33,26 @@ public class SectorsDialog extends FloatingDialog{
void setup(){
content().clear();
content().label(() -> Bundles.format("text.sector", selected == null ? "<none>" :
selected.x + ", " + selected.y + (!selected.unlocked ? Bundles.get("text.sector.locked") : "")));
content().row();
content().add(new SectorView()).grow();
content().row();
buttons().addImageTextButton("$text.sector.deploy", "icon-play", 10*3, () -> {
hide();
ui.loadLogic(() -> {
world.loadProceduralMap(selected.x, selected.y);
logic.play();
});
}).size(230f, 64f).disabled(b -> selected == null);
}
class SectorView extends Element{
float panX, panY;
float lastX, lastY;
float sectorSize = 100f;
boolean clicked = false;
SectorView(){
addListener(new InputListener(){
@@ -58,6 +78,13 @@ public class SectorsDialog extends FloatingDialog{
Cursors.restoreCursor();
}
});
addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y){
clicked = true;
}
});
}
@Override
@@ -65,7 +92,7 @@ public class SectorsDialog extends FloatingDialog{
Draw.alpha(alpha);
float clipSize = Math.min(width, height);
int shownSectors = Math.round(clipSize/sectorSize/2f + 1f);
int shownSectors = (int)(clipSize/sectorSize);
clip.setSize(clipSize).setCenter(x + width/2f, y + height/2f);
Graphics.flush();
boolean clipped = ScissorStack.pushScissors(clip);
@@ -73,6 +100,8 @@ public class SectorsDialog extends FloatingDialog{
int offsetX = (int)(panX / sectorSize);
int offsetY = (int)(panY / sectorSize);
Vector2 mouse = Graphics.mouse();
for(int x = -shownSectors; x <= shownSectors; x++){
for(int y = -shownSectors; y <= shownSectors; y++){
int sectorX = offsetX + x;
@@ -86,16 +115,39 @@ public class SectorsDialog extends FloatingDialog{
}
Sector sector = world.sectors().get(sectorX, sectorY);
Draw.rect(sector.texture, drawX, drawY, sectorSize, sectorSize);
Lines.stroke(2f);
Lines.crect(drawX, drawY, sectorSize, sectorSize);
if(sector == null) continue;
Draw.color(Color.WHITE);
Draw.rect(sector.texture, drawX, drawY, sectorSize, sectorSize);
if(sector == selected){
Draw.color(Palette.place);
}else if(Mathf.inRect(mouse.x, mouse.y, drawX - sectorSize/2f, drawY - sectorSize/2f, drawX + sectorSize/2f, drawY + sectorSize/2f)){
if(clicked){
selected = sector;
}
Draw.color(Palette.remove);
}else if (sector.unlocked){
Draw.color(Palette.accent);
}else{
Draw.color(Color.LIGHT_GRAY);
}
Lines.stroke(selected == sector ? 5f : 3f);
Lines.crect(drawX, drawY, sectorSize, sectorSize);
}
}
Draw.color(Palette.accent);
Lines.stroke(4f);
Lines.crect(x + width/2f, y + height/2f, clipSize, clipSize);
Draw.reset();
Graphics.flush();
if(clipped) ScissorStack.popScissors();
clicked = false;
}
}
}