Sector launch impl
This commit is contained in:
@@ -11,22 +11,31 @@ import arc.scene.event.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.g3d.*;
|
||||
import mindustry.graphics.g3d.PlanetRenderer.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.type.Sector.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
import static mindustry.graphics.g3d.PlanetRenderer.*;
|
||||
import static mindustry.ui.dialogs.PlanetDialog.Mode.*;
|
||||
|
||||
public class PlanetDialog extends BaseDialog{
|
||||
public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
|
||||
private final FrameBuffer buffer = new FrameBuffer(2, 2, true);
|
||||
private final PlanetRenderer planets = renderer.planets;
|
||||
private final Table stable = new Table().background(Styles.black3);
|
||||
|
||||
private float zoom = 1f;
|
||||
private Table stable;
|
||||
private int launchRange;
|
||||
private float zoom = 1f, selectAlpha = 1f;
|
||||
private @Nullable Sector selected, hovered, launchSector;
|
||||
private Mode mode = look;
|
||||
|
||||
public PlanetDialog(){
|
||||
super("", Styles.fullDialog);
|
||||
@@ -66,43 +75,128 @@ public class PlanetDialog extends BaseDialog{
|
||||
addListener(new ElementGestureListener(){
|
||||
@Override
|
||||
public void tap(InputEvent event, float x, float y, int count, KeyCode button){
|
||||
planets.selected = planets.hovered != null && planets.hovered.locked() ? null : planets.hovered;
|
||||
if(planets.selected != null){
|
||||
if(hovered != null && (mode == launch ? canLaunch(hovered) && hovered != launchSector : hovered.unlocked())){
|
||||
selected = hovered;
|
||||
}
|
||||
|
||||
if(selected != null){
|
||||
updateSelected();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
stable = new Table();
|
||||
stable.background(Styles.black3);
|
||||
|
||||
shown(this::setup);
|
||||
}
|
||||
|
||||
/** show with no limitations, just as a map. */
|
||||
@Override
|
||||
public Dialog show(){
|
||||
//TODO
|
||||
mode = look;
|
||||
selected = hovered = launchSector = null;
|
||||
return super.show();
|
||||
}
|
||||
|
||||
public void show(Sector selected, int range){
|
||||
planets.selected = null;
|
||||
planets.hovered = null;
|
||||
public void show(Sector sector, int range){
|
||||
selected = null;
|
||||
hovered = null;
|
||||
|
||||
//update view to sector
|
||||
planets.camPos.set(Tmp.v33.set(selected.tile.v).rotate(Vec3.Y, -selected.planet.getRotation()));
|
||||
zoom = planets.zoom = 1f;
|
||||
planets.camPos.set(Tmp.v33.set(sector.tile.v).rotate(Vec3.Y, -sector.planet.getRotation()));
|
||||
zoom = 1f;
|
||||
planets.zoom = 2f;
|
||||
selectAlpha = 0f;
|
||||
launchRange = range;
|
||||
launchSector = sector;
|
||||
|
||||
show();
|
||||
//TODO
|
||||
mode = launch;
|
||||
|
||||
super.show();
|
||||
}
|
||||
|
||||
boolean canLaunch(Sector sector){
|
||||
return mode == launch && sector.tile.v.within(launchSector.tile.v, (launchRange + 0.5f) * planets.planet.sectorApproxRadius*2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderSectors(Planet planet){
|
||||
|
||||
//draw all sector stuff
|
||||
for(Sector sec : planet.sectors){
|
||||
if(selectAlpha > 0.01f){
|
||||
if(canLaunch(sec) || sec.unlocked()){
|
||||
Color color =
|
||||
sec.hasBase() ? Team.sharded.color :
|
||||
sec.preset != null ? Team.derelict.color :
|
||||
sec.hasEnemyBase() ? Team.crux.color :
|
||||
null;
|
||||
|
||||
if(color != null){
|
||||
planets.drawSelection(sec, Tmp.c1.set(color).mul(0.8f).a(selectAlpha), 0.026f, -0.001f);
|
||||
}
|
||||
}else{
|
||||
planets.fill(sec, Tmp.c1.set(shadowColor).mul(1, 1, 1, selectAlpha), -0.001f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(launchSector != null){
|
||||
planets.fill(launchSector, hoverColor, -0.001f);
|
||||
}
|
||||
|
||||
//draw hover border
|
||||
if(hovered != null){
|
||||
planets.fill(hovered, hoverColor, -0.001f);
|
||||
planets.drawBorders(hovered, borderColor);
|
||||
}
|
||||
|
||||
//draw selected borders
|
||||
if(selected != null){
|
||||
planets.drawSelection(selected);
|
||||
planets.drawBorders(selected, borderColor);
|
||||
}
|
||||
|
||||
planets.batch.flush(Gl.triangles);
|
||||
|
||||
if(mode == launch){
|
||||
if(hovered != launchSector && hovered != null && canLaunch(hovered)){
|
||||
planets.drawArc(planet, launchSector.tile.v, hovered.tile.v);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
//TODO render arcs
|
||||
if(selected != null && selected.preset != null){
|
||||
for(Objective o : selected.preset.requirements){
|
||||
if(o instanceof SectorObjective){
|
||||
SectorPreset preset = ((SectorObjective)o).preset;
|
||||
planets.drawArc(planet, selected.tile.v, preset.sector.tile.v);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderProjections(){
|
||||
if(hovered != null){
|
||||
planets.drawPlane(hovered, () -> {
|
||||
Draw.color(Color.white, Pal.accent, Mathf.absin(5f, 1f));
|
||||
|
||||
TextureRegion icon = hovered.locked() && !canLaunch(hovered) ? Icon.lock.getRegion() : hovered.is(SectorAttribute.naval) ? Liquids.water.icon(Cicon.large) : null;
|
||||
|
||||
if(icon != null){
|
||||
Draw.rect(icon, 0, 0);
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void setup(){
|
||||
cont.clear();
|
||||
titleTable.remove();
|
||||
|
||||
cont.rect((x, y, w, h) -> planets.render()).grow();
|
||||
cont.rect((x, y, w, h) -> planets.render(this)).grow();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,9 +222,9 @@ public class PlanetDialog extends BaseDialog{
|
||||
public void act(float delta){
|
||||
super.act(delta);
|
||||
|
||||
if(planets.selected != null){
|
||||
if(selected != null){
|
||||
addChild(stable);
|
||||
Vec3 pos = planets.cam.project(Tmp.v31.set(planets.selected.tile.v).setLength(PlanetRenderer.outlineRad).rotate(Vec3.Y, -planets.planet.getRotation()).add(planets.planet.position));
|
||||
Vec3 pos = planets.cam.project(Tmp.v31.set(selected.tile.v).setLength(PlanetRenderer.outlineRad).rotate(Vec3.Y, -planets.planet.getRotation()).add(planets.planet.position));
|
||||
stable.setPosition(pos.x, pos.y, Align.center);
|
||||
stable.toFront();
|
||||
}else{
|
||||
@@ -138,18 +232,23 @@ public class PlanetDialog extends BaseDialog{
|
||||
}
|
||||
|
||||
if(planets.planet.isLandable()){
|
||||
planets.hovered = planets.planet.getSector(planets.cam.getMouseRay(), PlanetRenderer.outlineRad);
|
||||
hovered = planets.planet.getSector(planets.cam.getMouseRay(), PlanetRenderer.outlineRad);
|
||||
}else{
|
||||
planets.hovered = planets.selected = null;
|
||||
hovered = selected = null;
|
||||
}
|
||||
|
||||
planets.zoom = Mathf.lerpDelta(planets.zoom, zoom, 0.4f);
|
||||
planets.selectAlpha = Mathf.lerpDelta(planets.selectAlpha, Mathf.num(planets.zoom < 1.9f), 0.1f);
|
||||
selectAlpha = Mathf.lerpDelta(selectAlpha, Mathf.num(planets.zoom < 1.9f), 0.1f);
|
||||
}
|
||||
|
||||
//TODO add strings to bundle after prototyping is done
|
||||
private void updateSelected(){
|
||||
Sector sector = planets.selected;
|
||||
Sector sector = selected;
|
||||
|
||||
if(sector == null){
|
||||
stable.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
float x = stable.getX(Align.center), y = stable.getY(Align.center);
|
||||
stable.clear();
|
||||
@@ -207,7 +306,6 @@ public class PlanetDialog extends BaseDialog{
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}).row();
|
||||
}
|
||||
|
||||
@@ -220,31 +318,40 @@ public class PlanetDialog extends BaseDialog{
|
||||
|
||||
stable.row();
|
||||
|
||||
stable.button("Launch", Styles.transt, () -> {
|
||||
if(sector.is(SectorAttribute.naval)){
|
||||
ui.showInfo("You need a naval loadout to launch here.");
|
||||
return;
|
||||
}
|
||||
control.playSector(sector);
|
||||
hide();
|
||||
}).growX().padTop(2f).height(50f).minWidth(170f);
|
||||
if((sector.hasBase() && mode == look) || canLaunch(sector)){
|
||||
stable.button(sector.hasBase() ? "Resume" : "Launch", Styles.transt, () -> {
|
||||
if(sector.is(SectorAttribute.naval)){
|
||||
ui.showInfo("You need a naval loadout to launch here.");
|
||||
return;
|
||||
}
|
||||
control.playSector(sector);
|
||||
hide();
|
||||
}).growX().padTop(2f).height(50f).minWidth(170f);
|
||||
}
|
||||
|
||||
stable.pack();
|
||||
stable.setPosition(x, y, Align.center);
|
||||
|
||||
stable.update(() -> {
|
||||
if(planets.selected != null){
|
||||
if(selected != null){
|
||||
//fade out UI when not facing selected sector
|
||||
Tmp.v31.set(planets.selected.tile.v).rotate(Vec3.Y, -planets.planet.getRotation()).scl(-1f).nor();
|
||||
Tmp.v31.set(selected.tile.v).rotate(Vec3.Y, -planets.planet.getRotation()).scl(-1f).nor();
|
||||
float dot = planets.cam.direction.dot(Tmp.v31);
|
||||
stable.getColor().a = Math.max(dot, 0f)*2f;
|
||||
if(dot*2f <= -0.1f){
|
||||
stable.remove();
|
||||
planets.selected = null;
|
||||
selected = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
stable.act(0f);
|
||||
}
|
||||
|
||||
enum Mode{
|
||||
/** Look around for existing sectors. Can only deploy. */
|
||||
look,
|
||||
/** Launch to a new location. */
|
||||
launch
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user