mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-09-20 21:08:42 +03:00
Launch pad destination selection
This commit is contained in:
parent
1cc8d7e3f4
commit
3db2ffb843
@ -489,6 +489,7 @@ loadout = Loadout
|
||||
resources = Resources
|
||||
bannedblocks = Banned Blocks
|
||||
addall = Add All
|
||||
launch.destination = Destination: {0}
|
||||
configure.invalid = Amount must be a number between 0 and {0}.
|
||||
zone.unlocked = [lightgray]{0} unlocked.
|
||||
zone.requirement.complete = Requirement for {0} completed:[lightgray]\n{1}
|
||||
@ -521,6 +522,8 @@ sectors.production = Production:
|
||||
sectors.stored = Stored:
|
||||
sectors.resume = Resume
|
||||
sectors.launch = Launch
|
||||
sectors.select = Select
|
||||
sectors.sundest = [lightgray]none (sun)
|
||||
|
||||
#NOTE TO TRANSLATORS: don't bother editing these, they'll be removed and/or rewritten anyway
|
||||
sector.groundZero.name = Ground Zero
|
||||
|
@ -33,6 +33,8 @@ public class SectorInfo{
|
||||
public boolean hasCore = true;
|
||||
/** Sector that was launched from. */
|
||||
public @Nullable Sector origin;
|
||||
/** Launch destination. */
|
||||
public @Nullable Sector destination;
|
||||
/** Resources known to occur at this sector. */
|
||||
public Seq<UnlockableContent> resources = new Seq<>();
|
||||
/** Time spent at this sector. Do not use unless you know what you're doing. */
|
||||
@ -43,6 +45,12 @@ public class SectorInfo{
|
||||
/** Core item storage to prevent spoofing. */
|
||||
private transient int[] lastCoreItems;
|
||||
|
||||
/** @return the real location items go when launched on this sector */
|
||||
public Sector getRealDestination(){
|
||||
//on multiplayer the destination is, by default, the first captured sector (basically random)
|
||||
return !net.client() || destination != null ? destination : state.rules.sector.planet.sectors.find(Sector::hasBase);
|
||||
}
|
||||
|
||||
/** Updates export statistics. */
|
||||
public void handleItemExport(ItemStack stack){
|
||||
handleItemExport(stack.item, stack.amount);
|
||||
|
@ -165,10 +165,23 @@ public class Universe{
|
||||
//if so, just delete the save for now. it's lost.
|
||||
//TODO don't delete it later maybe
|
||||
sector.save.delete();
|
||||
//clear recieved
|
||||
sector.setExtraItems(new ItemSeq());
|
||||
sector.save = null;
|
||||
}
|
||||
}
|
||||
|
||||
//export to another sector
|
||||
if(sector.save.meta.secinfo.destination != null){
|
||||
Sector to = sector.save.meta.secinfo.destination;
|
||||
if(to.save != null){
|
||||
ItemSeq items = to.getExtraItems();
|
||||
//calculated exported items to this sector
|
||||
sector.save.meta.secinfo.export.each((item, stat) -> items.add(item, (int)(stat.mean * newSecondsPassed)));
|
||||
to.setExtraItems(items);
|
||||
}
|
||||
}
|
||||
|
||||
//reset time spent to 0
|
||||
sector.setTimeSpent(0f);
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ public class DesktopInput extends InputHandler{
|
||||
}).visible(() -> state.isCampaign()).tooltip("@planetmap");
|
||||
|
||||
table.button(Icon.up, Styles.clearPartiali, () -> {
|
||||
ui.planet.show(state.getSector(), player.team().core());
|
||||
ui.planet.showLaunch(state.getSector(), player.team().core());
|
||||
}).visible(() -> state.isCampaign()).tooltip("@launchcore").disabled(b -> player.team().core() == null);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
@ -34,6 +35,7 @@ public class LaunchPad extends Block{
|
||||
hasItems = true;
|
||||
solid = true;
|
||||
update = true;
|
||||
configurable = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,6 +53,7 @@ public class LaunchPad extends Block{
|
||||
}
|
||||
|
||||
public class LaunchPadBuild extends Building{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
@ -107,6 +110,30 @@ public class LaunchPad extends Block{
|
||||
Effect.shake(3f, 3f, this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
super.display(table);
|
||||
|
||||
table.row();
|
||||
table.label(() -> {
|
||||
Sector dest = state.secinfo.getRealDestination();
|
||||
|
||||
return Core.bundle.format("launch.destination",
|
||||
dest == null ? Core.bundle.get("sectors.sundest") :
|
||||
dest.preset == null ?
|
||||
"[accent]Sector " + dest.id :
|
||||
"[accent]" + dest.preset.localizedName);
|
||||
}).pad(4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildConfiguration(Table table){
|
||||
table.button(Icon.upOpen, Styles.clearTransi, () -> {
|
||||
ui.planet.showSelect(state.rules.sector, other -> state.secinfo.destination = other);
|
||||
deselect();
|
||||
}).size(40f);
|
||||
}
|
||||
}
|
||||
|
||||
@EntityDef(LaunchPayloadc.class)
|
||||
@ -176,8 +203,7 @@ public class LaunchPad extends Block{
|
||||
public void remove(){
|
||||
if(!state.isCampaign()) return;
|
||||
|
||||
//on multiplayer the destination is a the first captured sector (basically random)
|
||||
Sector destsec = !net.client() ? state.secinfo.origin : state.rules.sector.planet.sectors.find(Sector::hasBase);
|
||||
Sector destsec = state.secinfo.getRealDestination();
|
||||
|
||||
//actually launch the items upon removal
|
||||
if(team() == state.rules.defaultTeam){
|
||||
@ -193,12 +219,6 @@ public class LaunchPad extends Block{
|
||||
}
|
||||
|
||||
destsec.setExtraItems(dest);
|
||||
}else if(team().core() != null){
|
||||
//dump launched stuff into the core
|
||||
for(ItemStack stack : stacks){
|
||||
int min = Math.min(team().core().block.itemCapacity - team().core().items.get(stack.item), stack.amount);
|
||||
team().core().items.add(stack.item, min);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -425,20 +425,12 @@ public class LogicBlock extends Block{
|
||||
|
||||
@Override
|
||||
public void buildConfiguration(Table table){
|
||||
Table cont = new Table();
|
||||
cont.defaults().size(40);
|
||||
|
||||
cont.button(Icon.pencil, Styles.clearTransi, () -> {
|
||||
table.button(Icon.pencil, Styles.clearTransi, () -> {
|
||||
Vars.ui.logic.show(code, code -> {
|
||||
configure(compress(code, relativeConnections()));
|
||||
});
|
||||
});
|
||||
|
||||
//cont.button(Icon.refreshSmall, Styles.clearTransi, () -> {
|
||||
|
||||
//});
|
||||
|
||||
table.add(cont);
|
||||
}).size(40);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user