it is done
This commit is contained in:
12
core/src/mindustry/world/meta/Attribute.java
Normal file
12
core/src/mindustry/world/meta/Attribute.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
public enum Attribute{
|
||||
/** Heat of this block. Used for calculating output of thermal generators. */
|
||||
heat,
|
||||
/** Spore content of this block. Used for increasing cultivator yield. */
|
||||
spores,
|
||||
/** Water content of this block. Used for increasing water extractor yield. */
|
||||
water,
|
||||
/** Oil content of this block. Used for increasing oil extractor yield. */
|
||||
oil
|
||||
}
|
||||
24
core/src/mindustry/world/meta/BlockBars.java
Normal file
24
core/src/mindustry/world/meta/BlockBars.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import arc.struct.OrderedMap;
|
||||
import arc.func.Func;
|
||||
import mindustry.entities.type.TileEntity;
|
||||
import mindustry.ui.Bar;
|
||||
|
||||
public class BlockBars{
|
||||
private OrderedMap<String, Func<TileEntity, Bar>> bars = new OrderedMap<>();
|
||||
|
||||
public void add(String name, Func<TileEntity, Bar> sup){
|
||||
bars.put(name, sup);
|
||||
}
|
||||
|
||||
public void remove(String name){
|
||||
if(!bars.containsKey(name))
|
||||
throw new RuntimeException("No bar with name '" + name + "' found; current bars: " + bars.keys().toArray());
|
||||
bars.remove(name);
|
||||
}
|
||||
|
||||
public Iterable<Func<TileEntity, Bar>> list(){
|
||||
return bars.values();
|
||||
}
|
||||
}
|
||||
21
core/src/mindustry/world/meta/BlockFlag.java
Normal file
21
core/src/mindustry/world/meta/BlockFlag.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
/** Stores special flags of blocks for easy querying. */
|
||||
public enum BlockFlag{
|
||||
/** Enemy core; primary target for all units. */
|
||||
core,
|
||||
/** Rally point for units.*/
|
||||
rally,
|
||||
/** Producer of important goods. */
|
||||
producer,
|
||||
/** A turret. */
|
||||
turret,
|
||||
/** Only the command center block.*/
|
||||
comandCenter,
|
||||
/** Repair point. */
|
||||
repair,
|
||||
/** Upgrade pad. */
|
||||
mechPad;
|
||||
|
||||
public final static BlockFlag[] all = values();
|
||||
}
|
||||
5
core/src/mindustry/world/meta/BlockGroup.java
Normal file
5
core/src/mindustry/world/meta/BlockGroup.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
public enum BlockGroup{
|
||||
none, walls, turrets, transportation, power, liquids, drills
|
||||
}
|
||||
59
core/src/mindustry/world/meta/BlockStat.java
Normal file
59
core/src/mindustry/world/meta/BlockStat.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import arc.Core;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/** Describes one type of stat for a block. */
|
||||
public enum BlockStat{
|
||||
health(StatCategory.general),
|
||||
size(StatCategory.general),
|
||||
buildTime(StatCategory.general),
|
||||
buildCost(StatCategory.general),
|
||||
|
||||
itemCapacity(StatCategory.items),
|
||||
itemsMoved(StatCategory.items),
|
||||
launchTime(StatCategory.items),
|
||||
|
||||
liquidCapacity(StatCategory.liquids),
|
||||
|
||||
powerCapacity(StatCategory.power),
|
||||
powerUse(StatCategory.power),
|
||||
powerDamage(StatCategory.power),
|
||||
powerRange(StatCategory.power),
|
||||
powerConnections(StatCategory.power),
|
||||
basePowerGeneration(StatCategory.power),
|
||||
|
||||
input(StatCategory.crafting),
|
||||
output(StatCategory.crafting),
|
||||
productionTime(StatCategory.crafting),
|
||||
drillTier(StatCategory.crafting),
|
||||
drillSpeed(StatCategory.crafting),
|
||||
maxUnits(StatCategory.crafting),
|
||||
|
||||
speedIncrease(StatCategory.shooting),
|
||||
repairTime(StatCategory.shooting),
|
||||
range(StatCategory.shooting),
|
||||
shootRange(StatCategory.shooting),
|
||||
inaccuracy(StatCategory.shooting),
|
||||
shots(StatCategory.shooting),
|
||||
reload(StatCategory.shooting),
|
||||
powerShot(StatCategory.shooting),
|
||||
targetsAir(StatCategory.shooting),
|
||||
targetsGround(StatCategory.shooting),
|
||||
damage(StatCategory.shooting),
|
||||
ammo(StatCategory.shooting),
|
||||
|
||||
booster(StatCategory.optional),
|
||||
boostEffect(StatCategory.optional);
|
||||
|
||||
public final StatCategory category;
|
||||
|
||||
BlockStat(StatCategory category){
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String localized(){
|
||||
return Core.bundle.get("blocks." + name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
78
core/src/mindustry/world/meta/BlockStats.java
Normal file
78
core/src/mindustry/world/meta/BlockStats.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import arc.struct.Array;
|
||||
import arc.struct.ObjectMap.Entry;
|
||||
import arc.struct.OrderedMap;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.meta.values.*;
|
||||
|
||||
/** Hold and organizes a list of block stats. */
|
||||
public class BlockStats{
|
||||
private final OrderedMap<StatCategory, OrderedMap<BlockStat, Array<StatValue>>> map = new OrderedMap<>();
|
||||
private boolean dirty;
|
||||
|
||||
/** Adds a single float value with this stat, formatted to 2 decimal places. */
|
||||
public void add(BlockStat stat, float value, StatUnit unit){
|
||||
add(stat, new NumberValue(value, unit));
|
||||
}
|
||||
|
||||
/** Adds a single y/n boolean value. */
|
||||
public void add(BlockStat stat, boolean value){
|
||||
add(stat, new BooleanValue(value));
|
||||
}
|
||||
|
||||
/** Adds an item value. */
|
||||
public void add(BlockStat stat, Item item){
|
||||
add(stat, new ItemListValue(new ItemStack(item, 1)));
|
||||
}
|
||||
|
||||
/** Adds an item value. */
|
||||
public void add(BlockStat stat, ItemStack item){
|
||||
add(stat, new ItemListValue(item));
|
||||
}
|
||||
|
||||
/** Adds an item value. */
|
||||
public void add(BlockStat stat, Liquid liquid, float amount, boolean perSecond){
|
||||
add(stat, new LiquidValue(liquid, amount, perSecond));
|
||||
}
|
||||
|
||||
/** Adds a single string value with this stat. */
|
||||
public void add(BlockStat stat, String format, Object... args){
|
||||
add(stat, new StringValue(format, args));
|
||||
}
|
||||
|
||||
/** Adds a stat value. */
|
||||
public void add(BlockStat stat, StatValue value){
|
||||
if(!map.containsKey(stat.category)){
|
||||
map.put(stat.category, new OrderedMap<>());
|
||||
}
|
||||
|
||||
map.get(stat.category).getOr(stat, Array::new).add(value);
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
/** Removes a stat, if it exists. */
|
||||
public void remove(BlockStat stat){
|
||||
if(!map.containsKey(stat.category) || !map.get(stat.category).containsKey(stat)){
|
||||
throw new RuntimeException("No stat entry found: \"" + stat + "\" in block.");
|
||||
}
|
||||
|
||||
map.get(stat.category).remove(stat);
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
public OrderedMap<StatCategory, OrderedMap<BlockStat, Array<StatValue>>> toMap(){
|
||||
//sort stats by index if they've been modified
|
||||
if(dirty){
|
||||
map.orderedKeys().sort();
|
||||
for(Entry<StatCategory, OrderedMap<BlockStat, Array<StatValue>>> entry : map.entries()){
|
||||
entry.value.orderedKeys().sort();
|
||||
}
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
23
core/src/mindustry/world/meta/BuildVisibility.java
Normal file
23
core/src/mindustry/world/meta/BuildVisibility.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import arc.func.*;
|
||||
import mindustry.*;
|
||||
|
||||
public enum BuildVisibility{
|
||||
hidden(() -> false),
|
||||
shown(() -> true),
|
||||
debugOnly(() -> false),
|
||||
sandboxOnly(() -> Vars.state.rules.infiniteResources),
|
||||
campaignOnly(() -> Vars.world.isZone()),
|
||||
lightingOnly(() -> Vars.state.rules.lighting);
|
||||
|
||||
private final Boolp visible;
|
||||
|
||||
public boolean visible(){
|
||||
return visible.get();
|
||||
}
|
||||
|
||||
BuildVisibility(Boolp visible){
|
||||
this.visible = visible;
|
||||
}
|
||||
}
|
||||
7
core/src/mindustry/world/meta/PowerType.java
Normal file
7
core/src/mindustry/world/meta/PowerType.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
public enum PowerType{
|
||||
consumer,
|
||||
producer,
|
||||
bridge
|
||||
}
|
||||
19
core/src/mindustry/world/meta/Producers.java
Normal file
19
core/src/mindustry/world/meta/Producers.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import mindustry.ctype.Content;
|
||||
|
||||
public class Producers{
|
||||
private Content output;
|
||||
|
||||
public void set(Content content){
|
||||
this.output = content;
|
||||
}
|
||||
|
||||
public Content get(){
|
||||
return output;
|
||||
}
|
||||
|
||||
public boolean is(Content content){
|
||||
return content == output;
|
||||
}
|
||||
}
|
||||
18
core/src/mindustry/world/meta/StatCategory.java
Normal file
18
core/src/mindustry/world/meta/StatCategory.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import arc.Core;
|
||||
|
||||
/** A specific category for a stat. */
|
||||
public enum StatCategory{
|
||||
general,
|
||||
power,
|
||||
liquids,
|
||||
items,
|
||||
crafting,
|
||||
shooting,
|
||||
optional;
|
||||
|
||||
public String localized(){
|
||||
return Core.bundle.get("category." + name());
|
||||
}
|
||||
}
|
||||
39
core/src/mindustry/world/meta/StatUnit.java
Normal file
39
core/src/mindustry/world/meta/StatUnit.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import arc.Core;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Defines a unit of measurement for block stats.
|
||||
*/
|
||||
public enum StatUnit{
|
||||
blocks,
|
||||
powerSecond,
|
||||
liquidSecond,
|
||||
itemsSecond,
|
||||
liquidUnits,
|
||||
powerUnits,
|
||||
degrees,
|
||||
seconds,
|
||||
perSecond,
|
||||
timesSpeed(false),
|
||||
percent(false),
|
||||
none,
|
||||
items;
|
||||
|
||||
public final boolean space;
|
||||
|
||||
StatUnit(boolean space){
|
||||
this.space = space;
|
||||
}
|
||||
|
||||
StatUnit(){
|
||||
this(true);
|
||||
}
|
||||
|
||||
public String localized(){
|
||||
if(this == none) return "";
|
||||
return Core.bundle.get("unit." + name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
14
core/src/mindustry/world/meta/StatValue.java
Normal file
14
core/src/mindustry/world/meta/StatValue.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import arc.scene.ui.layout.Table;
|
||||
|
||||
/**
|
||||
* A base interface for a value of a stat that is displayed.
|
||||
*/
|
||||
public interface StatValue{
|
||||
/**
|
||||
* This method should provide all elements necessary to display this stat to the specified table.
|
||||
* For example, a stat that is just text would add a label to the table.
|
||||
*/
|
||||
void display(Table table);
|
||||
}
|
||||
89
core/src/mindustry/world/meta/values/AmmoListValue.java
Normal file
89
core/src/mindustry/world/meta/values/AmmoListValue.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.ctype.UnlockableContent;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.ui.Cicon;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class AmmoListValue<T extends UnlockableContent> implements StatValue{
|
||||
private final ObjectMap<T, BulletType> map;
|
||||
|
||||
public AmmoListValue(ObjectMap<T, BulletType> map){
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
|
||||
table.row();
|
||||
for(T t : map.keys()){
|
||||
BulletType type = map.get(t);
|
||||
table.addImage(icon(t)).size(3 * 8).padRight(4).right().top();
|
||||
table.add(t.localizedName).padRight(10).left().top();
|
||||
table.table(Tex.underline, bt -> {
|
||||
bt.left().defaults().padRight(3).left();
|
||||
|
||||
if(type.damage > 0){
|
||||
bt.add(Core.bundle.format("bullet.damage", type.damage));
|
||||
}
|
||||
|
||||
if(type.splashDamage > 0){
|
||||
sep(bt, Core.bundle.format("bullet.splashdamage", (int)type.splashDamage, Strings.fixed(type.splashDamageRadius / tilesize, 1)));
|
||||
}
|
||||
|
||||
if(!Mathf.equal(type.ammoMultiplier, 1f))
|
||||
sep(bt, Core.bundle.format("bullet.multiplier", (int)type.ammoMultiplier));
|
||||
if(!Mathf.equal(type.reloadMultiplier, 1f))
|
||||
sep(bt, Core.bundle.format("bullet.reload", Strings.fixed(type.reloadMultiplier, 1)));
|
||||
|
||||
if(type.knockback > 0){
|
||||
sep(bt, Core.bundle.format("bullet.knockback", Strings.fixed(type.knockback, 1)));
|
||||
}
|
||||
|
||||
if((type.status == StatusEffects.burning || type.status == StatusEffects.melting) || type.incendAmount > 0){
|
||||
sep(bt, "$bullet.incendiary");
|
||||
}
|
||||
|
||||
if(type.status == StatusEffects.freezing){
|
||||
sep(bt, "$bullet.freezing");
|
||||
}
|
||||
|
||||
if(type.status == StatusEffects.tarred){
|
||||
sep(bt, "$bullet.tarred");
|
||||
}
|
||||
|
||||
if(type.homingPower > 0.01f){
|
||||
sep(bt, "$bullet.homing");
|
||||
}
|
||||
|
||||
if(type.lightining > 0){
|
||||
sep(bt, "$bullet.shock");
|
||||
}
|
||||
|
||||
if(type.fragBullet != null){
|
||||
sep(bt, "$bullet.frag");
|
||||
}
|
||||
}).left().padTop(-9);
|
||||
table.row();
|
||||
}
|
||||
}
|
||||
|
||||
void sep(Table table, String text){
|
||||
table.row();
|
||||
table.add(text);
|
||||
}
|
||||
|
||||
TextureRegion icon(T t){
|
||||
return t.icon(Cicon.medium);
|
||||
}
|
||||
}
|
||||
17
core/src/mindustry/world/meta/values/BooleanValue.java
Normal file
17
core/src/mindustry/world/meta/values/BooleanValue.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.scene.ui.layout.Table;
|
||||
import mindustry.world.meta.StatValue;
|
||||
|
||||
public class BooleanValue implements StatValue{
|
||||
private final boolean value;
|
||||
|
||||
public BooleanValue(boolean value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
table.add(!value ? "$no" : "$yes");
|
||||
}
|
||||
}
|
||||
56
core/src/mindustry/world/meta/values/BoosterListValue.java
Normal file
56
core/src/mindustry/world/meta/values/BoosterListValue.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.*;
|
||||
import arc.func.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.Cicon;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class BoosterListValue implements StatValue{
|
||||
protected float reload, maxUsed, multiplier;
|
||||
protected boolean baseReload;
|
||||
protected Boolf<Liquid> filter;
|
||||
|
||||
public BoosterListValue(float reload, float maxUsed, float multiplier, boolean baseReload, Boolf<Liquid> filter){
|
||||
this.reload = reload;
|
||||
this.maxUsed = maxUsed;
|
||||
this.baseReload = baseReload;
|
||||
this.multiplier = multiplier;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
|
||||
table.row();
|
||||
table.table(c -> {
|
||||
for(Liquid liquid : content.liquids()){
|
||||
if(!filter.get(liquid)) continue;
|
||||
|
||||
c.addImage(liquid.icon(Cicon.medium)).size(3 * 8).padRight(4).right().top();
|
||||
c.add(liquid.localizedName).padRight(10).left().top();
|
||||
c.table(Tex.underline, bt -> {
|
||||
bt.left().defaults().padRight(3).left();
|
||||
|
||||
float reloadRate = (baseReload ? 1f : 0f) + maxUsed * multiplier * liquid.heatCapacity;
|
||||
float standardReload = baseReload ? reload : reload / (maxUsed * multiplier * 0.4f);
|
||||
float result = standardReload / (reload / reloadRate);
|
||||
bt.add(Core.bundle.format("bullet.reload", Strings.fixed(result, 1)));
|
||||
}).left().padTop(-9);
|
||||
c.row();
|
||||
}
|
||||
}).colspan(table.getColumns());
|
||||
table.row();
|
||||
|
||||
}
|
||||
|
||||
void sep(Table table, String text){
|
||||
table.row();
|
||||
table.add(text);
|
||||
}
|
||||
}
|
||||
33
core/src/mindustry/world/meta/values/ItemFilterValue.java
Normal file
33
core/src/mindustry/world/meta/values/ItemFilterValue.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.struct.Array;
|
||||
import arc.func.Boolf;
|
||||
import arc.scene.ui.layout.Table;
|
||||
import mindustry.type.Item;
|
||||
import mindustry.ui.ItemDisplay;
|
||||
import mindustry.world.meta.StatValue;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class ItemFilterValue implements StatValue{
|
||||
private final Boolf<Item> filter;
|
||||
|
||||
public ItemFilterValue(Boolf<Item> filter){
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
Array<Item> list = content.items().select(filter);
|
||||
|
||||
for(int i = 0; i < list.size; i++){
|
||||
Item item = list.get(i);
|
||||
|
||||
table.add(new ItemDisplay(item)).padRight(5);
|
||||
|
||||
if(i != list.size - 1){
|
||||
table.add("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
core/src/mindustry/world/meta/values/ItemListValue.java
Normal file
27
core/src/mindustry/world/meta/values/ItemListValue.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.scene.ui.layout.Table;
|
||||
import mindustry.type.ItemStack;
|
||||
import mindustry.ui.ItemDisplay;
|
||||
import mindustry.world.meta.StatValue;
|
||||
|
||||
public class ItemListValue implements StatValue{
|
||||
private final ItemStack[] stacks;
|
||||
private final boolean displayName;
|
||||
|
||||
public ItemListValue(ItemStack... stacks){
|
||||
this(true, stacks);
|
||||
}
|
||||
|
||||
public ItemListValue(boolean displayName, ItemStack... stacks){
|
||||
this.stacks = stacks;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
for(ItemStack stack : stacks){
|
||||
table.add(new ItemDisplay(stack.item, stack.amount, displayName)).padRight(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
core/src/mindustry/world/meta/values/LiquidFilterValue.java
Normal file
39
core/src/mindustry/world/meta/values/LiquidFilterValue.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.struct.Array;
|
||||
import arc.func.Boolf;
|
||||
import arc.scene.ui.layout.Table;
|
||||
import mindustry.type.Liquid;
|
||||
import mindustry.ui.LiquidDisplay;
|
||||
import mindustry.world.meta.StatValue;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class LiquidFilterValue implements StatValue{
|
||||
private final Boolf<Liquid> filter;
|
||||
private final float amount;
|
||||
private final boolean perSecond;
|
||||
|
||||
public LiquidFilterValue(Boolf<Liquid> filter, float amount, boolean perSecond){
|
||||
this.filter = filter;
|
||||
this.amount = amount;
|
||||
this.perSecond = perSecond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
Array<Liquid> list = new Array<>();
|
||||
|
||||
for(Liquid item : content.liquids()){
|
||||
if(!item.isHidden() && filter.get(item)) list.add(item);
|
||||
}
|
||||
|
||||
for(int i = 0; i < list.size; i++){
|
||||
table.add(new LiquidDisplay(list.get(i), amount, perSecond)).padRight(5);
|
||||
|
||||
if(i != list.size - 1){
|
||||
table.add("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
core/src/mindustry/world/meta/values/LiquidValue.java
Normal file
23
core/src/mindustry/world/meta/values/LiquidValue.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.scene.ui.layout.Table;
|
||||
import mindustry.type.Liquid;
|
||||
import mindustry.ui.LiquidDisplay;
|
||||
import mindustry.world.meta.StatValue;
|
||||
|
||||
public class LiquidValue implements StatValue{
|
||||
private final Liquid liquid;
|
||||
private final float amount;
|
||||
private final boolean perSecond;
|
||||
|
||||
public LiquidValue(Liquid liquid, float amount, boolean perSecond){
|
||||
this.liquid = liquid;
|
||||
this.amount = amount;
|
||||
this.perSecond = perSecond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
table.add(new LiquidDisplay(liquid, amount, perSecond));
|
||||
}
|
||||
}
|
||||
28
core/src/mindustry/world/meta/values/NumberValue.java
Normal file
28
core/src/mindustry/world/meta/values/NumberValue.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.scene.ui.layout.Table;
|
||||
import arc.util.Strings;
|
||||
import mindustry.world.meta.StatUnit;
|
||||
import mindustry.world.meta.StatValue;
|
||||
|
||||
/**
|
||||
* A stat that is a number with a unit attacked.
|
||||
* The number is rounded to 2 decimal places by default.
|
||||
*/
|
||||
public class NumberValue implements StatValue{
|
||||
private final StatUnit unit;
|
||||
private final float value;
|
||||
|
||||
public NumberValue(float value, StatUnit unit){
|
||||
this.unit = unit;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
int precision = Math.abs((int)value - value) <= 0.001f ? 0 : Math.abs((int)(value * 10) - value * 10) <= 0.001f ? 1 : 2;
|
||||
|
||||
table.add(Strings.fixed(value, precision));
|
||||
table.add((unit.space ? " " : "") + unit.localized());
|
||||
}
|
||||
}
|
||||
18
core/src/mindustry/world/meta/values/StringValue.java
Normal file
18
core/src/mindustry/world/meta/values/StringValue.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.scene.ui.layout.Table;
|
||||
import arc.util.Strings;
|
||||
import mindustry.world.meta.StatValue;
|
||||
|
||||
public class StringValue implements StatValue{
|
||||
private final String value;
|
||||
|
||||
public StringValue(String value, Object... args){
|
||||
this.value = Strings.format(value, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
table.add(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user