Launch pad destination selection

This commit is contained in:
Anuken
2020-09-23 18:00:24 -04:00
parent 1cc8d7e3f4
commit 3db2ffb843
8 changed files with 101 additions and 39 deletions

View File

@@ -87,7 +87,7 @@ public class PausedDialog extends BaseDialog{
}else if(state.isCampaign()){
cont.buttonRow("@launchcore", Icon.up, () -> {
hide();
ui.planet.show(state.getSector(), player.team().core());
ui.planet.showLaunch(state.getSector(), player.team().core());
}).disabled(b -> player.team().core() == null);
cont.row();

View File

@@ -1,6 +1,7 @@
package mindustry.ui.dialogs;
import arc.*;
import arc.func.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.graphics.gl.*;
@@ -29,17 +30,18 @@ import static mindustry.graphics.g3d.PlanetRenderer.*;
import static mindustry.ui.dialogs.PlanetDialog.Mode.*;
public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
private final FrameBuffer buffer = new FrameBuffer(2, 2, true);
final FrameBuffer buffer = new FrameBuffer(2, 2, true);
final PlanetRenderer planets = renderer.planets;
private final LaunchLoadoutDialog loadouts = new LaunchLoadoutDialog();
private final Table stable = new Table().background(Styles.black3);
final LaunchLoadoutDialog loadouts = new LaunchLoadoutDialog();
final Table stable = new Table().background(Styles.black3);
private int launchRange;
private float zoom = 1f, selectAlpha = 1f;
int launchRange;
float zoom = 1f, selectAlpha = 1f;
@Nullable Sector selected, hovered, launchSector;
private CoreBuild launcher;
CoreBuild launcher;
Mode mode = look;
private boolean launching;
boolean launching;
Cons<Sector> listener = s -> {};
public PlanetDialog(){
super("", Styles.fullDialog);
@@ -93,7 +95,25 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
return super.show();
}
public void show(Sector sector, CoreBuild launcher){
public void showSelect(Sector sector, Cons<Sector> listener){
selected = null;
hovered = null;
launching = false;
this.listener = listener;
//update view to sector
lookAt(sector);
zoom = 1f;
planets.zoom = 2f;
selectAlpha = 0f;
launchSector = sector;
mode = select;
super.show();
}
public void showLaunch(Sector sector, CoreBuild launcher){
if(launcher == null) return;
this.launcher = launcher;
@@ -118,7 +138,9 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
planets.camPos.set(Tmp.v33.set(sector.tile.v).rotate(Vec3.Y, -sector.planet.getRotation()));
}
boolean canLaunch(Sector sector){
boolean canSelect(Sector sector){
if(mode == select) return sector.hasBase();
return mode == launch &&
(sector.tile.v.within(launchSector.tile.v, (launchRange + 0.5f) * planets.planet.sectorApproxRadius*2) //within range
|| (sector.preset != null && sector.preset.unlocked())); //is an unlocked preset
@@ -131,7 +153,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
for(Sector sec : planet.sectors){
if(selectAlpha > 0.01f){
if(canLaunch(sec) || sec.unlocked()){
if(canSelect(sec) || sec.unlocked()){
if(sec.baseCoverage > 0){
planets.fill(sec, Tmp.c1.set(Team.crux.color).a(0.5f * sec.baseCoverage * selectAlpha), -0.002f);
}
@@ -169,8 +191,8 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
planets.batch.flush(Gl.triangles);
if(mode == launch){
if(hovered != launchSector && hovered != null && canLaunch(hovered)){
if(mode == launch || mode == select){
if(hovered != launchSector && hovered != null && canSelect(hovered)){
planets.drawArc(planet, launchSector.tile.v, hovered.tile.v);
}
}
@@ -193,7 +215,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
planets.drawPlane(hovered, () -> {
Draw.color(Color.white, Pal.accent, Mathf.absin(5f, 1f));
TextureRegion icon = hovered.locked() && !canLaunch(hovered) ? Icon.lock.getRegion() : null;
TextureRegion icon = hovered.locked() && !canSelect(hovered) ? Icon.lock.getRegion() : null;
if(icon != null){
Draw.rect(icon, 0, 0);
@@ -219,7 +241,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
addListener(new ElementGestureListener(){
@Override
public void tap(InputEvent event, float x, float y, int count, KeyCode button){
if(hovered != null && (mode == launch ? canLaunch(hovered) && hovered != launchSector : hovered.unlocked())){
if(hovered != null && (mode == launch ? canSelect(hovered) && hovered != launchSector : hovered.unlocked())){
selected = hovered;
}
@@ -239,7 +261,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
new Table(t -> {
//TODO localize
t.top();
t.label(() -> mode == launch ? "Select Launch Sector" : "Turn " + universe.turn()).style(Styles.outlineLabel).color(Pal.accent);
t.label(() -> mode == select ? "@sectors.select" : mode == launch ? "Select Launch Sector" : "Turn " + universe.turn()).style(Styles.outlineLabel).color(Pal.accent);
})).grow();
}
@@ -382,13 +404,13 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
stable.row();
if((sector.hasBase() && mode == look) || canLaunch(sector) || (sector.preset != null && sector.preset.alwaysUnlocked)){
stable.button(sector.hasBase() ? "@sectors.resume" : "@sectors.launch", Styles.transt, () -> {
if((sector.hasBase() && mode == look) || canSelect(sector) || (sector.preset != null && sector.preset.alwaysUnlocked)){
stable.button(mode == select ? "@sectors.select" : sector.hasBase() ? "@sectors.resume" : "@sectors.launch", Styles.transt, () -> {
boolean shouldHide = true;
//save before launch.
if(control.saves.getCurrent() != null && state.isGame()){
if(control.saves.getCurrent() != null && state.isGame() && mode != select){
try{
control.saves.getCurrent().save();
}catch(Throwable e){
@@ -408,6 +430,8 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
ui.hudfrag.showLaunchDirect();
Time.runTask(launchDuration, () -> control.playSector(current, sector));
});
}else if(mode == select){
listener.get(sector);
}else{
control.playSector(sector);
}
@@ -444,6 +468,8 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
/** Look around for existing sectors. Can only deploy. */
look,
/** Launch to a new location. */
launch
launch,
/** Select a sector for some purpose. */
select
}
}