Separator output display
This commit is contained in:
@@ -5786,6 +5786,7 @@ public class Blocks{
|
|||||||
itemCapacity = 0;
|
itemCapacity = 0;
|
||||||
alwaysUnlocked = true;
|
alwaysUnlocked = true;
|
||||||
ambientSound = Sounds.none;
|
ambientSound = Sounds.none;
|
||||||
|
allDatabaseTabs = true;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
//TODO move
|
//TODO move
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package mindustry.ui;
|
|
||||||
|
|
||||||
import arc.scene.ui.layout.*;
|
|
||||||
import arc.util.*;
|
|
||||||
import mindustry.type.*;
|
|
||||||
import mindustry.world.meta.*;
|
|
||||||
|
|
||||||
//TODO replace with static methods?
|
|
||||||
/** An item image with text. */
|
|
||||||
public class ItemDisplay extends Table{
|
|
||||||
public final Item item;
|
|
||||||
public final int amount;
|
|
||||||
|
|
||||||
public ItemDisplay(Item item){
|
|
||||||
this(item, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemDisplay(Item item, int amount, boolean showName){
|
|
||||||
add(new ItemImage(new ItemStack(item, amount)));
|
|
||||||
if(showName) add(item.localizedName).padLeft(4 + amount > 99 ? 4 : 0);
|
|
||||||
|
|
||||||
this.item = item;
|
|
||||||
this.amount = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemDisplay(Item item, int amount){
|
|
||||||
this(item, amount, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Displays the item with a "/sec" qualifier based on the time period, in ticks. */
|
|
||||||
public ItemDisplay(Item item, int amount, float timePeriod, boolean showName){
|
|
||||||
add(new ItemImage(item.uiIcon, amount));
|
|
||||||
add((showName ? item.localizedName + "\n" : "") + "[lightgray]" + Strings.autoFixed(amount / (timePeriod / 60f), 2) + StatUnit.perSecond.localized()).padLeft(2).padRight(5).style(Styles.outlineLabel);
|
|
||||||
|
|
||||||
this.item = item;
|
|
||||||
this.amount = amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package mindustry.ui;
|
|
||||||
|
|
||||||
import arc.graphics.*;
|
|
||||||
import arc.scene.ui.*;
|
|
||||||
import arc.scene.ui.layout.*;
|
|
||||||
import arc.util.*;
|
|
||||||
import mindustry.type.*;
|
|
||||||
import mindustry.world.meta.*;
|
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
|
||||||
|
|
||||||
/** An ItemDisplay, but for liquids. */
|
|
||||||
public class LiquidDisplay extends Table{
|
|
||||||
public final Liquid liquid;
|
|
||||||
public final float amount;
|
|
||||||
public final boolean perSecond;
|
|
||||||
|
|
||||||
public LiquidDisplay(Liquid liquid, float amount, boolean perSecond){
|
|
||||||
this.liquid = liquid;
|
|
||||||
this.amount = amount;
|
|
||||||
this.perSecond = perSecond;
|
|
||||||
|
|
||||||
add(new Stack(){{
|
|
||||||
add(new Image(liquid.uiIcon).setScaling(Scaling.fit));
|
|
||||||
|
|
||||||
if(amount != 0){
|
|
||||||
Table t = new Table().left().bottom();
|
|
||||||
t.add(Strings.autoFixed(amount, 2)).style(Styles.outlineLabel);
|
|
||||||
add(t);
|
|
||||||
}
|
|
||||||
}}).size(iconMed).padRight(3 + (amount != 0 && Strings.autoFixed(amount, 2).length() > 2 ? 8 : 0));
|
|
||||||
|
|
||||||
if(perSecond){
|
|
||||||
add(StatUnit.perSecond.localized()).padLeft(2).padRight(5).color(Color.lightGray).style(Styles.outlineLabel);
|
|
||||||
}
|
|
||||||
|
|
||||||
add(liquid.localizedName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,7 +38,14 @@ public class Separator extends Block{
|
|||||||
stats.timePeriod = craftTime;
|
stats.timePeriod = craftTime;
|
||||||
super.setStats();
|
super.setStats();
|
||||||
|
|
||||||
stats.add(Stat.output, StatValues.items(item -> Structs.contains(results, i -> i.item == item)));
|
int[] sum = {0};
|
||||||
|
for(var r : results) sum[0] += r.amount;
|
||||||
|
|
||||||
|
stats.add(Stat.output, table -> {
|
||||||
|
for(ItemStack stack : results){
|
||||||
|
table.add(StatValues.displayItemPercent(stack.item, (int)((float)stack.amount / sum[0] * 100), true)).padRight(5);
|
||||||
|
}
|
||||||
|
});
|
||||||
stats.add(Stat.productionTime, craftTime / 60f, StatUnit.seconds);
|
stats.add(Stat.productionTime, craftTime / 60f, StatUnit.seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public class UnitFactory extends UnitBlock{
|
|||||||
}
|
}
|
||||||
|
|
||||||
ItemStack stack = plan.requirements[i];
|
ItemStack stack = plan.requirements[i];
|
||||||
req.add(new ItemDisplay(stack.item, stack.amount, plan.time, true)).pad(5);
|
req.add(StatValues.displayItem(stack.item, stack.amount, plan.time, true)).pad(5);
|
||||||
}
|
}
|
||||||
}).right().grow().pad(10f);
|
}).right().grow().pad(10f);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class StatValues{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static StatValue liquid(Liquid liquid, float amount, boolean perSecond){
|
public static StatValue liquid(Liquid liquid, float amount, boolean perSecond){
|
||||||
return table -> table.add(new LiquidDisplay(liquid, amount, perSecond));
|
return table -> table.add(displayLiquid(liquid, amount, perSecond));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StatValue liquids(Boolf<Liquid> filter, float amount, boolean perSecond){
|
public static StatValue liquids(Boolf<Liquid> filter, float amount, boolean perSecond){
|
||||||
@@ -74,7 +74,7 @@ public class StatValues{
|
|||||||
Seq<Liquid> list = content.liquids().select(i -> filter.get(i) && i.unlockedNow() && !i.isHidden());
|
Seq<Liquid> list = content.liquids().select(i -> filter.get(i) && i.unlockedNow() && !i.isHidden());
|
||||||
|
|
||||||
for(int i = 0; i < list.size; i++){
|
for(int i = 0; i < list.size; i++){
|
||||||
table.add(new LiquidDisplay(list.get(i), amount, perSecond)).padRight(5);
|
table.add(displayLiquid(list.get(i), amount, perSecond)).padRight(5);
|
||||||
|
|
||||||
if(i != list.size - 1){
|
if(i != list.size - 1){
|
||||||
table.add("/");
|
table.add("/");
|
||||||
@@ -90,7 +90,7 @@ public class StatValues{
|
|||||||
public static StatValue liquids(float timePeriod, boolean perSecond, LiquidStack... stacks){
|
public static StatValue liquids(float timePeriod, boolean perSecond, LiquidStack... stacks){
|
||||||
return table -> {
|
return table -> {
|
||||||
for(var stack : stacks){
|
for(var stack : stacks){
|
||||||
table.add(new LiquidDisplay(stack.liquid, stack.amount * (60f / timePeriod), perSecond)).padRight(5);
|
table.add(displayLiquid(stack.liquid, stack.amount * (60f / timePeriod), perSecond)).padRight(5);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ public class StatValues{
|
|||||||
public static StatValue items(boolean displayName, ItemStack... stacks){
|
public static StatValue items(boolean displayName, ItemStack... stacks){
|
||||||
return table -> {
|
return table -> {
|
||||||
for(ItemStack stack : stacks){
|
for(ItemStack stack : stacks){
|
||||||
table.add(new ItemDisplay(stack.item, stack.amount, displayName)).padRight(5);
|
table.add(displayItem(stack.item, stack.amount, displayName)).padRight(5);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ public class StatValues{
|
|||||||
public static StatValue items(float timePeriod, ItemStack... stacks){
|
public static StatValue items(float timePeriod, ItemStack... stacks){
|
||||||
return table -> {
|
return table -> {
|
||||||
for(ItemStack stack : stacks){
|
for(ItemStack stack : stacks){
|
||||||
table.add(new ItemDisplay(stack.item, stack.amount, timePeriod, true)).padRight(5);
|
table.add(displayItem(stack.item, stack.amount, timePeriod, true)).padRight(5);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ public class StatValues{
|
|||||||
for(int i = 0; i < list.size; i++){
|
for(int i = 0; i < list.size; i++){
|
||||||
Item item = list.get(i);
|
Item item = list.get(i);
|
||||||
|
|
||||||
table.add(timePeriod <= 0 ? new ItemDisplay(item) : new ItemDisplay(item, 1, timePeriod, true)).padRight(5);
|
table.add(timePeriod <= 0 ? displayItem(item) : displayItem(item, 1, timePeriod, true)).padRight(5);
|
||||||
|
|
||||||
if(i != list.size - 1){
|
if(i != list.size - 1){
|
||||||
table.add("/");
|
table.add("/");
|
||||||
@@ -135,6 +135,60 @@ public class StatValues{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Table displayLiquid(Liquid liquid, float amount, boolean perSecond){
|
||||||
|
Table t = new Table();
|
||||||
|
|
||||||
|
t.add(new Stack(){{
|
||||||
|
add(new Image(liquid.uiIcon).setScaling(Scaling.fit));
|
||||||
|
|
||||||
|
if(amount != 0){
|
||||||
|
Table t = new Table().left().bottom();
|
||||||
|
t.add(Strings.autoFixed(amount, 2)).style(Styles.outlineLabel);
|
||||||
|
add(t);
|
||||||
|
}
|
||||||
|
}}).size(iconMed).padRight(3 + (amount != 0 && Strings.autoFixed(amount, 2).length() > 2 ? 8 : 0));
|
||||||
|
|
||||||
|
if(perSecond){
|
||||||
|
t.add(StatUnit.perSecond.localized()).padLeft(2).padRight(5).color(Color.lightGray).style(Styles.outlineLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
t.add(liquid.localizedName);
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Table displayItem(Item item){
|
||||||
|
return displayItem(item, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Table displayItem(Item item, int amount, boolean showName){
|
||||||
|
Table t = new Table();
|
||||||
|
t.add(new ItemImage(new ItemStack(item, amount)));
|
||||||
|
if(showName) t.add(item.localizedName).padLeft(4 + amount > 99 ? 4 : 0);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Table displayItem(Item item, int amount){
|
||||||
|
return displayItem(item, amount, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Displays the item with a "/sec" qualifier based on the time period, in ticks. */
|
||||||
|
public static Table displayItem(Item item, int amount, float timePeriod, boolean showName){
|
||||||
|
Table t = new Table();
|
||||||
|
t.add(new ItemImage(item.uiIcon, amount));
|
||||||
|
t.add((showName ? item.localizedName + "\n" : "") + "[lightgray]" + Strings.autoFixed(amount / (timePeriod / 60f), 2) + StatUnit.perSecond.localized()).padLeft(2).padRight(5).style(Styles.outlineLabel);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Displays the item with a "/sec" qualifier based on the time period, in ticks. */
|
||||||
|
public static Table displayItemPercent(Item item, int percent, boolean showName){
|
||||||
|
Table t = new Table();
|
||||||
|
t.add(new ItemImage(item.uiIcon, 0));
|
||||||
|
t.add((showName ? item.localizedName + "\n" : "") + "[lightgray]" + percent + "%").padLeft(2).padRight(5).style(Styles.outlineLabel);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
public static StatValue content(UnlockableContent content){
|
public static StatValue content(UnlockableContent content){
|
||||||
return table -> {
|
return table -> {
|
||||||
table.add(new Image(content.uiIcon)).size(iconSmall).padRight(3);
|
table.add(new Image(content.uiIcon)).size(iconSmall).padRight(3);
|
||||||
@@ -327,9 +381,9 @@ public class StatValues{
|
|||||||
c.table(Styles.grayPanel, b -> {
|
c.table(Styles.grayPanel, b -> {
|
||||||
for(ItemStack stack : items){
|
for(ItemStack stack : items){
|
||||||
if(timePeriod < 0){
|
if(timePeriod < 0){
|
||||||
b.add(new ItemDisplay(stack.item, stack.amount, true)).pad(20f).left();
|
b.add(displayItem(stack.item, stack.amount, true)).pad(20f).left();
|
||||||
}else{
|
}else{
|
||||||
b.add(new ItemDisplay(stack.item, stack.amount, timePeriod, true)).pad(20f).left();
|
b.add(displayItem(stack.item, stack.amount, timePeriod, true)).pad(20f).left();
|
||||||
}
|
}
|
||||||
if(items.length > 1) b.row();
|
if(items.length > 1) b.row();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user