payload/status effect display

This commit is contained in:
sharlotte
2021-08-15 15:35:12 +09:00
parent 4b1050778e
commit 1a1ad180b5

View File

@@ -32,6 +32,7 @@ import mindustry.world.*;
import mindustry.world.blocks.*; import mindustry.world.blocks.*;
import mindustry.world.blocks.defense.turrets.*; import mindustry.world.blocks.defense.turrets.*;
import mindustry.world.blocks.distribution.MassDriver; import mindustry.world.blocks.distribution.MassDriver;
import mindustry.world.blocks.payloads.Payload;
import mindustry.world.blocks.payloads.PayloadMassDriver; import mindustry.world.blocks.payloads.PayloadMassDriver;
import mindustry.world.blocks.power.PowerNode; import mindustry.world.blocks.power.PowerNode;
import mindustry.world.blocks.storage.*; import mindustry.world.blocks.storage.*;
@@ -344,7 +345,6 @@ public class HudUi {
buttons.each(b -> b.setChecked(buttons.indexOf(b) == index)); buttons.each(b -> b.setChecked(buttons.indexOf(b) == index));
label.setText(bundle.get(hud)); label.setText(bundle.get(hud));
addBars(); addBars();
addWeapon();
addUnitTable(); addUnitTable();
addWaveTable(); addWaveTable();
addCoreTable(); addCoreTable();
@@ -423,10 +423,10 @@ public class HudUi {
} }
}); });
}); });
Table table = (Table)((Group)((Group)((Group)((Group)ui.hudGroup.getChildren().get(5)) //HudFragment#118, name: overlaymarker Table table = (Table)((Group)((Group)((Group)ui.hudGroup.getChildren().get(5)) //HudFragment#118, name: overlaymarker
.getChildren().get(mobile ? 2 : 0)) //HudFragment#192, name: wave/editor .getChildren().get(mobile ? 2 : 0)) //HudFragment#192, name: wave/editor
.getChildren().get(0)) //HudFragment#196, name: waves .getChildren().get(0)) //HudFragment#196, name: waves
.getChildren().get(0)); //HudFragment#200 -> HudFragment#590, name: status .getChildren().get(0); //HudFragment#200 -> HudFragment#590, name: status
table.row(); table.row();
table.add(waveInfoTable); table.add(waveInfoTable);
} }
@@ -624,22 +624,24 @@ public class HudUi {
}}); }});
} }
public void addWeapon(){ public void addWeaponTable(Table table){
weapon = new Table(Tex.button, tt -> { table.table().update(t -> {
tt.left().defaults().minSize(Scl.scl(modUiScale) * 12 * 8f); t.clear();
tt.defaults().width(Scl.scl(modUiScale) * 8 * 8f).minHeight(Scl.scl(modUiScale) * 4 * 8f); t.add(new Table(Tex.button, tt -> {
tt.defaults().width(Scl.scl(modUiScale) * 8 * 8f).minHeight(Scl.scl(modUiScale) * 4 * 8f).align(Align.left);
if(getTarget() instanceof Unit u && u.type != null) { tt.visibility = () -> settings.getBool("weaponui") && getTarget() instanceof Unit u && u.type != null && u.type.weapons.size > 0;
if(settings.getBool("weaponui") && getTarget() instanceof Unit u && u.type != null) {
UnitType type = u.type; UnitType type = u.type;
for(int r = 0; r < type.weapons.size; r++){ for(int r = 0; r < type.weapons.size; r++){
Weapon weapon = type.weapons.get(r); Weapon weapon = type.weapons.get(r);
WeaponMount mount = u.mounts[r]; WeaponMount mount = u.mounts[r];
TextureRegion region = !weapon.name.equals("") && weapon.outlineRegion.found() ? weapon.outlineRegion : type.uiIcon; TextureRegion region = !weapon.name.equals("") && weapon.outlineRegion.found() ? weapon.outlineRegion : type.uiIcon;
if(type.weapons.size > 1 && r % 3 == 0) tt.row(); int finalR = r;
else if(r % 3 == 0) tt.row(); tt.table(ttt -> {
tt.table(weapontable -> { if(type.weapons.size > 1 && finalR % 3 == 0) tt.row();
weapontable.add(new Stack(){{ else if(finalR % 3 == 0) tt.row();
add(new Table(o -> { ttt.stack(
new Table(o -> {
o.left(); o.left();
o.add(new Image(region){ o.add(new Image(region){
@Override @Override
@@ -669,9 +671,8 @@ public class HudUi {
getDrawable().draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY); getDrawable().draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
} }
}).scaling(Scaling.fill).size(Scl.scl(modUiScale) * iconLarge); }).scaling(Scaling.fill).size(Scl.scl(modUiScale) * iconLarge);
})); })
, new Table(h -> {
add(new Table(h -> {
h.defaults().growX().height(Scl.scl(modUiScale) * 9f).width(Scl.scl(modUiScale) * iconLarge).padTop(Scl.scl(modUiScale) * 18f); h.defaults().growX().height(Scl.scl(modUiScale) * 9f).width(Scl.scl(modUiScale) * iconLarge).padTop(Scl.scl(modUiScale) * 18f);
h.add(new Bar( h.add(new Bar(
() -> "", () -> "",
@@ -679,7 +680,6 @@ public class HudUi {
() -> mount.reload / weapon.reload)); () -> mount.reload / weapon.reload));
h.pack(); h.pack();
})); }));
}});
}); });
} }
} }
@@ -691,17 +691,70 @@ public class HudUi {
Draw.color(color.r, color.g, color.b, (settings.getInt("uiopacity") / 100f) * this.parentAlpha); Draw.color(color.r, color.g, color.b, (settings.getInt("uiopacity") / 100f) * this.parentAlpha);
getBackground().draw(x, y, width, height); getBackground().draw(x, y, width, height);
} }
}; });
});
}
public Table addInfoTable(Table table){
return table.table(table1 -> {
table1.left().top();
float[] count = new float[]{-1};
table1.table().update(t -> {
if(getTarget() instanceof Payloadc payload){
if(count[0] != payload.payloadUsed()){
t.clear();
t.top().left();
float pad = 0;
float items = payload.payloads().size;
if(8 * 2 * items + pad * items > 275f){
pad = (275f - (8 * 2) * items) / items;
}
int i = 0;
for(Payload p : payload.payloads()){
t.image(p.icon()).size(8 * 2).padRight(pad);
if(++i % 12 == 0) t.row();
}
count[0] = payload.payloadUsed();
}
}else{
count[0] = -1;
t.clear();
}
}).growX().visible(() -> getTarget() instanceof Payloadc p && p.payloadUsed() > 0).colspan(2);
table1.row();
Bits statuses = new Bits();
table1.table().update(t -> {
t.left();
if(getTarget() instanceof Statusc st){
Bits applied = st.statusBits();
if(!statuses.equals(applied)){
t.clear();
if(applied != null){
for(StatusEffect effect : content.statusEffects()){
if(applied.get(effect.id) && !effect.isHidden()){
t.image(effect.uiIcon).size(iconSmall).get().addListener(new Tooltip(l -> l.label(() ->
effect.localizedName + " [lightgray]" + UI.formatTime(st.getDuration(effect))).style(Styles.outlineLabel)));
}
}
statuses.set(applied);
}
}
}
}).left();
}).get();
} }
public void addUnitTable(){ public void addUnitTable(){
if(uiIndex != 0) return; if(uiIndex != 0) return;
unitTable = new Table(table -> { unitTable = new Table(table -> {
table.left(); table.left().defaults().width(Scl.scl(modUiScale < 1 ? modUiScale : 1) * 27 * 8f).maxHeight(Scl.scl(modUiScale < 1 ? modUiScale : 1) * 35 * 8f).align(Align.left);
addBars(); addBars();
table.add(new Table(Tex.button, t -> { Table table1 = new Table(Tex.button, t -> {
t.defaults().width(Scl.scl(modUiScale) * 25 * 8f);
t.table(Tex.underline2, tt -> { t.table(Tex.underline2, tt -> {
Stack stack = new Stack(){{ Stack stack = new Stack(){{
add(new Table(ttt -> ttt.add(new Image(){{ add(new Table(ttt -> ttt.add(new Image(){{
@@ -717,9 +770,10 @@ public class HudUi {
}}.setScaling(Scaling.fit)).size(Scl.scl(modUiScale) * 4f * 8f))); }}.setScaling(Scaling.fit)).size(Scl.scl(modUiScale) * 4f * 8f)));
add(new Table(ttt -> { add(new Table(ttt -> {
ttt.add(new Stack(){{ ttt.add(new Stack(){{
add(new Table(temp -> temp.add(new Image(){{ add(new Table(temp -> {
update(()-> setDrawable(getTarget() instanceof Unit ? Icon.defenseSmall.getRegion() : clear)); temp.add(new Image(Icon.defenseSmall.getRegion()).setScaling(Scaling.fit));
}}.setScaling(Scaling.fit)))); temp.visibility = () -> getTarget() instanceof Unit;
}));
add(new Table(temp -> { add(new Table(temp -> {
if(getTarget() instanceof Unit) { if(getTarget() instanceof Unit) {
@@ -747,23 +801,23 @@ public class HudUi {
if(modUiScale < 1) label.setFontScale(Scl.scl(modUiScale)); if(modUiScale < 1) label.setFontScale(Scl.scl(modUiScale));
TextButton button = Elem.newButton("?", Styles.clearPartialt, () -> { TextButton button = Elem.newButton("?", Styles.clearPartialt, () -> {
if(getTarget() instanceof Unit && ((Unit) getTarget()).type() != null) if(getTarget() instanceof Unit u && u.type != null)
ui.content.show(((Unit) getTarget()).type); ui.content.show(u.type);
if(getTarget() instanceof Building && ((Building) getTarget()).block != null) { if(getTarget() instanceof Building b && b.block != null) {
ui.content.show(((Building) getTarget()).block); ui.content.show(b.block);
} }
}); });
button.visibility = () -> getTarget() != null; button.visibility = () -> getTarget() != null;
button.update(()->{
lockButton.getStyle().imageUp = Icon.lock.tint(locked ? Pal.accent : Color.white);
lockButton.getStyle().imageDown = Icon.lock.tint(locked ? Pal.accent : Color.white);
});
lockButton = Elem.newImageButton(Styles.clearPartiali, Icon.lock.tint(locked ? Pal.accent : Color.white), 3 * 8f, () -> { lockButton = Elem.newImageButton(Styles.clearPartiali, Icon.lock.tint(locked ? Pal.accent : Color.white), 3 * 8f, () -> {
locked = !locked; locked = !locked;
if(locked) lockedTarget = getTarget(); if(locked) lockedTarget = getTarget();
else lockedTarget = null; else lockedTarget = null;
}); });
button.update(()->{
lockButton.getStyle().imageUp = Icon.lock.tint(locked ? Pal.accent : Color.white);
lockButton.getStyle().imageDown = Icon.lock.tint(locked ? Pal.accent : Color.white);
});
lockButton.visibility = () -> getTarget() != null; lockButton.visibility = () -> getTarget() != null;
tt.top(); tt.top();
@@ -817,8 +871,11 @@ public class HudUi {
Draw.color(color.r, color.g, color.b, (settings.getInt("uiopacity") / 100f) * this.parentAlpha); Draw.color(color.r, color.g, color.b, (settings.getInt("uiopacity") / 100f) * this.parentAlpha);
getBackground().draw(x, y, width, height); getBackground().draw(x, y, width, height);
} }
}); };
table.table(t -> t.stack(table1, addInfoTable(t)));
table.row(); table.row();
table.table(this::addWeaponTable);
table.update(() -> { table.update(() -> {
try { try {
BarInfo.getInfo(getTarget()); BarInfo.getInfo(getTarget());
@@ -829,17 +886,10 @@ public class HudUi {
numbers = BarInfo.numbers; numbers = BarInfo.numbers;
colors = BarInfo.colors; colors = BarInfo.colors;
if(getTarget() instanceof Turret.TurretBuild){ if(getTarget() instanceof Turret.TurretBuild tb){
if(((Turret.TurretBuild) getTarget()).charging) charge += Time.delta; if(tb.charging) charge += Time.delta;
else charge = 0f; else charge = 0f;
} }
table.removeChild(weapon);
if(settings.getBool("weaponui") && getTarget() instanceof Unit u && u.type != null) {
addWeapon();
table.row();
table.add(weapon);
}
}); });
table.fillParent = true; table.fillParent = true;
@@ -1002,8 +1052,7 @@ public class HudUi {
wavePane.setWidget(new Table(tx -> tx.table(this::setWave).left())); wavePane.setWidget(new Table(tx -> tx.table(this::setWave).left()));
waveTable = new Table(table -> { waveTable = new Table(table -> {
table.left(); table.left().defaults().width(Scl.scl(modUiScale < 1 ? modUiScale : 1) * 32 * 8f).maxHeight(Scl.scl(modUiScale < 1 ? modUiScale : 1) * 32 * 8f).align(Align.left);
table.defaults().width(Scl.scl(modUiScale < 1 ? modUiScale : 1) * 32 * 8f).maxHeight(Scl.scl(modUiScale < 1 ? modUiScale : 1) * 32 * 8f).align(Align.left);
table.add(new Table(Tex.button, t -> t.add(wavePane)){ table.add(new Table(Tex.button, t -> t.add(wavePane)){
@Override @Override
protected void drawBackground(float x, float y) { protected void drawBackground(float x, float y) {