Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi-item boosters displaying multiple times #10297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void setStats(){

if(consItems && itemConsumer instanceof ConsumeItems coni){
stats.remove(Stat.booster);
stats.add(Stat.booster, StatValues.itemBoosters("+{0} " + StatUnit.shieldHealth.localized(), stats.timePeriod, phaseShieldBoost, phaseRadiusBoost, coni.items, this::consumesItem));
stats.add(Stat.booster, StatValues.itemBoosters("+{0} " + StatUnit.shieldHealth.localized(), stats.timePeriod, phaseShieldBoost, phaseRadiusBoost, coni.items));
stats.add(Stat.booster, StatValues.speedBoosters("", coolantConsumption, Float.MAX_VALUE, true, this::consumesLiquid));
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/world/blocks/defense/MendProjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setStats(){
stats.add(Stat.booster, StatValues.itemBoosters(
"{0}" + StatUnit.timesSpeed.localized(),
stats.timePeriod, (phaseBoost + healPercent) / healPercent, phaseRangeBoost,
cons.items, this::consumesItem)
cons.items)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void setStats(){

if(hasBoost && findConsumer(f -> f instanceof ConsumeItems) instanceof ConsumeItems items){
stats.remove(Stat.booster);
stats.add(Stat.booster, StatValues.itemBoosters("+{0}%", stats.timePeriod, speedBoostPhase * 100f, phaseRangeBoost, items.items, this::consumesItem));
stats.add(Stat.booster, StatValues.itemBoosters("+{0}%", stats.timePeriod, speedBoostPhase * 100f, phaseRangeBoost, items.items));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void setStats(){
stats.add(Stat.booster, StatValues.itemBoosters(
"{0}" + StatUnit.timesSpeed.localized(),
stats.timePeriod, optionalMultiplier, 0f,
cons.items, this::consumesItem)
cons.items)
);
}
}
Expand Down
35 changes: 19 additions & 16 deletions core/src/mindustry/world/meta/StatValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,35 +442,38 @@ public static StatValue speedBoosters(String unit, float amount, float speed, bo
};
}

public static StatValue itemBoosters(String unit, float timePeriod, float speedBoost, float rangeBoost, ItemStack[] items, Boolf<Item> filter){
public static StatValue itemBoosters(String unit, float timePeriod, float speedBoost, float rangeBoost, ItemStack[] items){
return table -> {
table.row();
table.table(c -> {
for(Item item : content.items()){
if(!filter.get(item)) continue;

c.table(Styles.grayPanel, b -> {
c.table(Styles.grayPanel, b -> {
b.table(it -> {
for(ItemStack stack : items){
if(timePeriod < 0){
b.add(displayItem(stack.item, stack.amount, true)).pad(20f).left();
it.add(displayItem(stack.item, stack.amount, true)).pad(10f).padLeft(15f).left();
}else{
b.add(displayItem(stack.item, stack.amount, timePeriod, true)).pad(20f).left();
it.add(displayItem(stack.item, stack.amount, timePeriod, true)).pad(10f).padLeft(15f).left();
}
if(items.length > 1) b.row();
it.row();
}

b.table(bt -> {
bt.right().defaults().padRight(3).left();
if(rangeBoost != 0) bt.add("[lightgray]+[stat]" + Strings.autoFixed(rangeBoost / tilesize, 2) + "[lightgray] " + StatUnit.blocks.localized()).row();
if(speedBoost != 0) bt.add("[lightgray]" + unit.replace("{0}", "[stat]" + Strings.autoFixed(speedBoost, 2) + "[lightgray]"));
}).right().grow().pad(10f).padRight(15f);
}).growX().pad(5).padBottom(-5).row();
}
}).left();

b.table(bt -> {
bt.right().defaults().padRight(3).left();
if(rangeBoost != 0) bt.add("[lightgray]+[stat]" + Strings.autoFixed(rangeBoost / tilesize, 2) + "[lightgray] " + StatUnit.blocks.localized()).row();
if(speedBoost != 0) bt.add("[lightgray]" + unit.replace("{0}", "[stat]" + Strings.autoFixed(speedBoost, 2) + "[lightgray]"));
}).right().top().grow().pad(10f).padRight(15f);
}).growX().pad(5).padBottom(-5).row();
}).growX().colspan(table.getColumns());
table.row();
};
}

/** @deprecated Filter is no longer used. */
public static StatValue itemBoosters(String unit, float timePeriod, float speedBoost, float rangeBoost, ItemStack[] items, Boolf<Item> filter){
return itemBoosters(unit, timePeriod, speedBoost, rangeBoost, items);
}

public static StatValue weapons(UnitType unit, Seq<Weapon> weapons){
return table -> {
table.row();
Expand Down
Loading