mirror of
https://github.com/yawaflua/Informatis.git
synced 2025-12-10 03:59:26 +02:00
added unit bar
This commit is contained in:
@@ -14,4 +14,6 @@ shar-stat.power = Power: {0} / {1}
|
|||||||
# Settings
|
# Settings
|
||||||
setting.weaponui.name = Display weapon UI
|
setting.weaponui.name = Display weapon UI
|
||||||
setting.commandedunitui.name = Display commandUnits UI
|
setting.commandedunitui.name = Display commandUnits UI
|
||||||
setting.uiopacity.name = UnitInfo UI background Opacity
|
setting.unithealthui.name = Display Unit Bar
|
||||||
|
setting.uiopacity.name = UI background Opacity
|
||||||
|
setting.baropacity.name = Health Bar Opacity
|
||||||
@@ -14,4 +14,6 @@ shar-stat.power = 전력: {0} / {1}
|
|||||||
# Settings
|
# Settings
|
||||||
setting.weaponui.name = 무기 UI 표시
|
setting.weaponui.name = 무기 UI 표시
|
||||||
setting.commandedunitui.name = 지휘 유닛 UI 표시
|
setting.commandedunitui.name = 지휘 유닛 UI 표시
|
||||||
setting.uiopacity.name = UnitInfo UI 배경 투명도
|
setting.unithealthui.name = 유닛 바 표시
|
||||||
|
setting.uiopacity.name = UI 배경 투명도
|
||||||
|
setting.baropacity.name = 유닛 바 투명도
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
package UnitInfo.core;
|
package UnitInfo.core;
|
||||||
|
|
||||||
|
import UnitInfo.ui.FreeBar;
|
||||||
import UnitInfo.ui.SBar;
|
import UnitInfo.ui.SBar;
|
||||||
import arc.Core;
|
import arc.Core;
|
||||||
import arc.func.Func;
|
import arc.func.Func;
|
||||||
import arc.graphics.Color;
|
import arc.graphics.Color;
|
||||||
import arc.graphics.g2d.Draw;
|
import arc.graphics.g2d.*;
|
||||||
import arc.graphics.g2d.TextureRegion;
|
|
||||||
import arc.math.Mathf;
|
import arc.math.Mathf;
|
||||||
|
import arc.math.geom.Rect;
|
||||||
import arc.scene.Element;
|
import arc.scene.Element;
|
||||||
import arc.scene.style.TransformDrawable;
|
import arc.scene.style.TransformDrawable;
|
||||||
import arc.scene.ui.*;
|
import arc.scene.ui.*;
|
||||||
@@ -302,7 +303,7 @@ public class HudUi {
|
|||||||
t.top();
|
t.top();
|
||||||
t.add(new SBar(
|
t.add(new SBar(
|
||||||
() -> Core.bundle.format("shar-stat.ammos", getUnit().ammo, getUnit().type.ammoCapacity),
|
() -> Core.bundle.format("shar-stat.ammos", getUnit().ammo, getUnit().type.ammoCapacity),
|
||||||
() -> player.dead() || player.unit() instanceof BlockUnitc ? Pal.ammo : getUnit().type.ammoType.color,
|
() -> getUnit().dead() || getUnit() instanceof BlockUnitc ? Pal.ammo : getUnit().type.ammoType.color,
|
||||||
() -> getUnit().ammof(),
|
() -> getUnit().ammof(),
|
||||||
() -> Vars.state.rules.unitAmmo
|
() -> Vars.state.rules.unitAmmo
|
||||||
)).growX().left();
|
)).growX().left();
|
||||||
@@ -506,7 +507,7 @@ public class HudUi {
|
|||||||
ttt.add(new Image(){{
|
ttt.add(new Image(){{
|
||||||
update(() -> {
|
update(() -> {
|
||||||
TextureRegion region = Core.atlas.find("clear");
|
TextureRegion region = Core.atlas.find("clear");
|
||||||
if(getUnit() instanceof BlockUnitUnit && getUnit().type != null && ((BlockUnitUnit)getUnit()).tile() instanceof Turret.TurretBuild) region = ((BlockUnitUnit)getUnit()).tile().block.icon(Cicon.large);
|
if(getUnit() instanceof BlockUnitUnit && getUnit().type != null) region = ((BlockUnitUnit)getUnit()).tile().block.icon(Cicon.large);
|
||||||
else if(getUnit() != null && getUnit().type != null) region = getUnit().type.icon(Cicon.large);
|
else if(getUnit() != null && getUnit().type != null) region = getUnit().type.icon(Cicon.large);
|
||||||
setDrawable(region);
|
setDrawable(region);
|
||||||
});
|
});
|
||||||
@@ -604,11 +605,6 @@ public class HudUi {
|
|||||||
&& (!Vars.mobile ||
|
&& (!Vars.mobile ||
|
||||||
!(getUnit().isBuilding() || Vars.control.input.block != null || !Vars.control.input.selectRequests.isEmpty()
|
!(getUnit().isBuilding() || Vars.control.input.block != null || !Vars.control.input.selectRequests.isEmpty()
|
||||||
&& !(Vars.control.input.lastSchematic != null && !Vars.control.input.selectRequests.isEmpty())));
|
&& !(Vars.control.input.lastSchematic != null && !Vars.control.input.selectRequests.isEmpty())));
|
||||||
}){
|
}));
|
||||||
@Override
|
|
||||||
public void draw() {
|
|
||||||
super.draw();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,30 @@
|
|||||||
package UnitInfo.core;
|
package UnitInfo.core;
|
||||||
|
|
||||||
|
import UnitInfo.ui.FreeBar;
|
||||||
|
import arc.Core;
|
||||||
import arc.Events;
|
import arc.Events;
|
||||||
|
import arc.math.geom.Rect;
|
||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
|
import mindustry.gen.Groups;
|
||||||
import mindustry.mod.Mod;
|
import mindustry.mod.Mod;
|
||||||
|
|
||||||
public class Main extends Mod {
|
public class Main extends Mod {
|
||||||
public static Setting settingAdder = new Setting();
|
public static Setting settingAdder = new Setting();
|
||||||
|
|
||||||
public Main(){
|
public Main(){
|
||||||
Events.on(ClientLoadEvent.class, e -> {
|
Events.on(ClientLoadEvent.class, e -> {
|
||||||
settingAdder.init();
|
settingAdder.init();
|
||||||
new HudUi().addTable();
|
HudUi hud = new HudUi();
|
||||||
|
hud.addTable();
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.on(WorldLoadEvent.class, e -> {
|
Events.on(WorldLoadEvent.class, e -> {
|
||||||
new HudUi().addTable();
|
HudUi hud = new HudUi();
|
||||||
|
hud.addTable();
|
||||||
|
});
|
||||||
|
Events.run(Trigger.draw, () -> {
|
||||||
|
if(Core.settings.getBool("unithealthui"))
|
||||||
|
Groups.unit.each(unit -> new FreeBar().draw(unit));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,13 @@ public class Setting {
|
|||||||
|
|
||||||
addGraphicSetting("weaponui");
|
addGraphicSetting("weaponui");
|
||||||
addGraphicSetting("commandedunitui");
|
addGraphicSetting("commandedunitui");
|
||||||
|
addGraphicSetting("unithealthui");
|
||||||
Vars.ui.settings.graphics.sliderPref("uiopacity", 50, 0, 100, 5, s -> s + "%");
|
Vars.ui.settings.graphics.sliderPref("uiopacity", 50, 0, 100, 5, s -> s + "%");
|
||||||
|
Vars.ui.settings.graphics.sliderPref("baropacity", 50, 0, 100, 5, s -> s + "%");
|
||||||
|
|
||||||
Core.settings.defaults("weaponui", true);
|
Core.settings.defaults("weaponui", true);
|
||||||
Core.settings.defaults("commandedunitui", true);
|
Core.settings.defaults("commandedunitui", true);
|
||||||
|
Core.settings.defaults("unithealthui", true);
|
||||||
|
|
||||||
|
|
||||||
Core.settings.put("uiscalechanged", tmp);
|
Core.settings.put("uiscalechanged", tmp);
|
||||||
|
|||||||
88
src/UnitInfo/ui/FreeBar.java
Normal file
88
src/UnitInfo/ui/FreeBar.java
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
package UnitInfo.ui;
|
||||||
|
|
||||||
|
import arc.graphics.g2d.*;
|
||||||
|
import arc.math.*;
|
||||||
|
import arc.struct.FloatSeq;
|
||||||
|
import arc.util.Log;
|
||||||
|
import mindustry.Vars;
|
||||||
|
import mindustry.entities.abilities.ForceFieldAbility;
|
||||||
|
import mindustry.entities.abilities.ShieldRegenFieldAbility;
|
||||||
|
import mindustry.gen.*;
|
||||||
|
import mindustry.graphics.Layer;
|
||||||
|
import mindustry.graphics.Pal;
|
||||||
|
|
||||||
|
import static arc.Core.settings;
|
||||||
|
import static mindustry.Vars.content;
|
||||||
|
|
||||||
|
public class FreeBar {
|
||||||
|
public float value;
|
||||||
|
|
||||||
|
public void draw(Unit unit){
|
||||||
|
if(unit.dead()) return;
|
||||||
|
float height = 2f;
|
||||||
|
|
||||||
|
if(Float.isNaN(value)) value = 0;
|
||||||
|
if(Float.isInfinite(value)) value = 1f;
|
||||||
|
value = Mathf.lerpDelta(value, Mathf.clamp(unit.healthf()), 0.15f);
|
||||||
|
|
||||||
|
Draw.z(Layer.flyingUnit + 1);
|
||||||
|
Draw.color(0.1f, 0.1f, 0.1f, (settings.getInt("baropacity") / 100f));
|
||||||
|
float width = unit.type.hitSize + 4f;
|
||||||
|
|
||||||
|
float x = unit.x;
|
||||||
|
float y = unit.y - 8;
|
||||||
|
for(int i : Mathf.signs) {
|
||||||
|
for(int ii = 0; ii < 2; ii++){
|
||||||
|
float shadowx = x + ii * 0.25f;
|
||||||
|
float shadowy = y - ii * 0.5f;
|
||||||
|
Fill.poly(FloatSeq.with(
|
||||||
|
shadowx - (width / 2 + height), shadowy,
|
||||||
|
shadowx - width / 2, shadowy + i * height,
|
||||||
|
shadowx + width / 2, shadowy + i * height,
|
||||||
|
shadowx + (width / 2 + height), shadowy,
|
||||||
|
shadowx + width / 2, shadowy + i * -height,
|
||||||
|
shadowx - width / 2, shadowy + i * -height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Draw.color(Pal.health.cpy().a((settings.getInt("baropacity") / 100f)));
|
||||||
|
float topWidth = - width / 2 + width * Mathf.clamp(unit.healthf());
|
||||||
|
for(int i : Mathf.signs) {
|
||||||
|
Fill.poly(FloatSeq.with(
|
||||||
|
x - (width / 2 + height), y,
|
||||||
|
x - width / 2, y + i * height,
|
||||||
|
x + topWidth, y + i * height,
|
||||||
|
x - (width / 2 + height) + (width + 2 * height) * Mathf.clamp(unit.healthf()), y,
|
||||||
|
x + topWidth, y + i * -height,
|
||||||
|
x - width / 2, y + i * -height));
|
||||||
|
}
|
||||||
|
if(Vars.state.rules.unitAmmo){
|
||||||
|
Draw.color((unit.dead() || unit instanceof BlockUnitc ? Pal.ammo : unit.type.ammoType.color).cpy().a((settings.getInt("baropacity") / 100f)));
|
||||||
|
topWidth = - width / 2 + width * Mathf.clamp(unit.ammof());
|
||||||
|
|
||||||
|
Fill.poly(FloatSeq.with(
|
||||||
|
x - (width / 2 + height), y,
|
||||||
|
x - width / 2, y + height,
|
||||||
|
x + topWidth, y + height,
|
||||||
|
x - (width / 2 + height) + (width + 2 * height) * Mathf.clamp(unit.ammof()), y,
|
||||||
|
x + topWidth, y - height,
|
||||||
|
x - width / 2, y - height));
|
||||||
|
}
|
||||||
|
|
||||||
|
float max1 = ((ShieldRegenFieldAbility)content.units().copy().filter(ut -> ut.abilities.find(abil -> abil instanceof ShieldRegenFieldAbility) != null).sort(ut -> ((ShieldRegenFieldAbility)ut.abilities.find(abil -> abil instanceof ShieldRegenFieldAbility)).max).peek().abilities.find(abil -> abil instanceof ShieldRegenFieldAbility)).max;
|
||||||
|
float max2 = 0f;
|
||||||
|
if(unit.type.abilities.find(abil -> abil instanceof ForceFieldAbility) != null) max2 = ((ForceFieldAbility) unit.type.abilities.find(abil -> abil instanceof ForceFieldAbility)).max;
|
||||||
|
float max = Mathf.clamp(unit.shield / Math.max(max1, max2));
|
||||||
|
|
||||||
|
Draw.color(Pal.surge.cpy().a((settings.getInt("baropacity") / 100f)));
|
||||||
|
topWidth = - width / 2 + width * max;
|
||||||
|
|
||||||
|
Fill.poly(FloatSeq.with(
|
||||||
|
x - (width / 2 + height), y,
|
||||||
|
x - width / 2, y - height,
|
||||||
|
x + topWidth, y - height,
|
||||||
|
x - (width / 2 + height) + (width + 2 * height) * max, y,
|
||||||
|
x + topWidth, y + height,
|
||||||
|
x - width / 2, y + height));
|
||||||
|
Draw.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user