Launching dialog bugfixes & requirement display

This commit is contained in:
Anuken 2020-06-28 11:40:03 -04:00
parent bd274f804a
commit 6386cae19a
5 changed files with 76 additions and 27 deletions

View File

@ -461,7 +461,9 @@ requirement.core = Destroy Enemy Core in {0}
requirement.unlock = Unlock {0}
resume = Resume Zone:\n[lightgray]{0}
bestwave = [lightgray]Best Wave: {0}
#TODO fix/remove this
launch = < LAUNCH >
launch.text = Launch
launch.title = Launch Successful
launch.next = [lightgray]next opportunity at wave {0}
launch.unable2 = [scarlet]Unable to LAUNCH.[]

View File

@ -249,8 +249,8 @@ public class Control implements ApplicationListener, Loadable{
ent.lifetime(Vars.launchDuration);
ent.add();
//remove launch requirements from core
tile.items.remove(tile.block.requirements);
//remove schematic requirements from core
tile.items.remove(universe.getLastLoadout().requirements());
}
public void playSector(Sector sector){

View File

@ -5,6 +5,7 @@ import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.ui.dialogs.SchematicsDialog.*;
import mindustry.world.blocks.storage.*;
@ -14,6 +15,7 @@ import static mindustry.Vars.*;
/** Dialog for selecting loadout at sector launch. */
public class LaunchLoadoutDialog extends BaseDialog{
Schematic selected;
boolean valid;
public LaunchLoadoutDialog(){
super("$configure");
@ -24,23 +26,44 @@ public class LaunchLoadoutDialog extends BaseDialog{
buttons.clear();
addCloseButton();
buttons.button("$ok", () -> {
buttons.button("$launch.text", Icon.ok, () -> {
universe.updateLoadout(core, selected);
confirm.run();
hide();
});
}).disabled(b -> !valid);
int cols = Math.max((int)(Core.graphics.getWidth() / Scl.scl(230)), 1);
ButtonGroup<Button> group = new ButtonGroup<>();
selected = universe.getLoadout(core);
Table items = new Table();
Runnable rebuildItems = () -> {
items.clearChildren();
int i = 0;
for(ItemStack s : selected.requirements()){
items.image(s.item.icon(Cicon.small)).left();
items.add((state.rules.infiniteResources || build.items.has(s.item, s.amount)) ? "[lightgray]" + s.amount + "" :
((build.items.has(s.item, s.amount) ? "[lightgray]" : "[scarlet]") + Math.min(build.items.get(s.item), s.amount) + "[lightgray]/" + s.amount))
.padLeft(2).left().padRight(4);
if(++i % 4 == 0){
items.row();
}
}
};
cont.pane(t -> {
int i = 0;
for(Schematic s : schematics.getLoadouts(core)){
t.button(b -> b.add(new SchematicImage(s)), Styles.togglet, () -> selected = s)
.group(group).pad(4).disabled(!build.items.has(s.requirements())).checked(s == selected).size(200f);
t.button(b -> b.add(new SchematicImage(s)), Styles.togglet, () -> {
selected = s;
rebuildItems.run();
valid = build.items.has(selected.requirements());
}).group(group).pad(4).disabled(!build.items.has(s.requirements())).checked(s == selected).size(200f);
if(++i % cols == 0){
t.row();
@ -48,6 +71,12 @@ public class LaunchLoadoutDialog extends BaseDialog{
}
}).growX().get().setScrollingDisabled(true, false);
cont.row();
cont.add(items);
rebuildItems.run();
//TODO configure items to launch with
show();

View File

@ -40,6 +40,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
private @Nullable Sector selected, hovered, launchSector;
private CoreEntity launcher;
private Mode mode = look;
private boolean launching;
public PlanetDialog(){
super("", Styles.fullDialog);
@ -76,19 +77,6 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
zoom = Mathf.clamp(zoom + value / 10f, 0.5f, 2f);
});
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())){
selected = hovered;
}
if(selected != null){
updateSelected();
}
}
});
shown(this::setup);
}
@ -97,6 +85,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
public Dialog show(){
mode = look;
selected = hovered = launchSector = null;
launching= false;
return super.show();
}
@ -104,6 +93,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
this.launcher = launcher;
selected = null;
hovered = null;
launching = false;
//update view to sector
planets.camPos.set(Tmp.v33.set(sector.tile.v).rotate(Vec3.Y, -sector.planet.getRotation()));
@ -204,7 +194,19 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
cont.clear();
titleTable.remove();
cont.rect((x, y, w, h) -> planets.render(this)).grow();
//add listener to the background rect, so it doesn't get unnecessary touch input
cont.rect((x, y, w, h) -> planets.render(this)).grow().get().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())){
selected = hovered;
}
if(selected != null){
updateSelected();
}
}
});
}
@Override
@ -234,6 +236,12 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
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();
//smooth camera toward the sector
if(mode == launch && launching){
float len = planets.camPos.len();
planets.camPos.slerp(Tmp.v31.set(selected.tile.v).rotate(Vec3.Y,-selected.planet.getRotation()).setLength(len), 0.1f);
}
}else{
stable.remove();
}
@ -348,6 +356,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
shouldHide = false;
loadouts.show((CoreBlock)launcher.block, launcher, () -> {
control.handleLaunch(launcher);
launching = true;
zoom = 0.5f;
ui.hudfrag.showLaunchDirect();
@ -366,14 +375,19 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
stable.update(() -> {
if(selected != null){
//fade out UI when not facing selected sector
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();
selected = null;
if(launching){
stable.getColor().sub(0, 0, 0, 0.05f * Time.delta());
}else{
//fade out UI when not facing selected sector
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();
selected = null;
}
}
}
});

View File

@ -236,6 +236,10 @@ public class ItemModule extends BlockModule{
for(ItemStack stack : stacks) remove(stack.item, stack.amount);
}
public void remove(Iterable<ItemStack> stacks){
for(ItemStack stack : stacks) remove(stack.item, stack.amount);
}
public void remove(ItemStack stack){
remove(stack.item, stack.amount);
}