mirror of
https://github.com/yawaflua/Informatis.git
synced 2025-12-10 12:09:27 +02:00
ui clean up
This commit is contained in:
@@ -1,27 +1,17 @@
|
||||
package unitinfo.ui.windows;
|
||||
|
||||
import unitinfo.core.BarInfo;
|
||||
import unitinfo.ui.SBar;
|
||||
import unitinfo.ui.SIcons;
|
||||
import unitinfo.ui.Updatable;
|
||||
import arc.Core;
|
||||
import arc.func.Prov;
|
||||
import unitinfo.core.*;
|
||||
import unitinfo.ui.*;
|
||||
import arc.graphics.Color;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.input.KeyCode;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.geom.Rect;
|
||||
import arc.math.geom.Vec2;
|
||||
import arc.math.geom.Vec3;
|
||||
import arc.scene.Element;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.Bits;
|
||||
import arc.struct.Seq;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.Vars;
|
||||
import mindustry.ai.formations.FormationPattern;
|
||||
import mindustry.core.UI;
|
||||
import mindustry.entities.units.WeaponMount;
|
||||
import mindustry.gen.*;
|
||||
@@ -38,167 +28,101 @@ import mindustry.world.blocks.power.*;
|
||||
|
||||
import static unitinfo.SVars.*;
|
||||
import static unitinfo.SUtils.*;
|
||||
import static arc.Core.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class UnitDisplay extends Window implements Updatable {
|
||||
static Seq<Color> lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear);
|
||||
static final Rect scissor = new Rect();
|
||||
float scrollPos;
|
||||
class UnitDisplay extends Window {
|
||||
final Seq<Color> lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear);
|
||||
final Rect scissor = new Rect();
|
||||
Vec2 scrollPos;
|
||||
|
||||
public UnitDisplay() {
|
||||
super(Icon.units, "unit");
|
||||
}
|
||||
|
||||
//TODO: add new UnitInfoDisplay(), new WeaponDisplay();
|
||||
@Override
|
||||
public void build(Table table) {
|
||||
protected void build(Table table) {
|
||||
scrollPos = new Vec2(0,0);
|
||||
|
||||
table.top().background(Styles.black8);
|
||||
table.table(tt -> {
|
||||
tt.center();
|
||||
Image image = new Image() {
|
||||
@Override
|
||||
public void draw() {
|
||||
super.draw();
|
||||
|
||||
//TODO: add new UnitInfoDisplay(), new WeaponDisplay();
|
||||
table.table(Tex.underline2, tt -> {
|
||||
tt.stack(
|
||||
new Table(ttt -> {
|
||||
Prov<TextureRegionDrawable> reg = () -> {
|
||||
TextureRegion region = clear;
|
||||
Teamc target = getTarget();
|
||||
if (target instanceof Unit u && u.type != null) region = u.type.uiIcon;
|
||||
else if (target instanceof Building b) {
|
||||
if (target instanceof ConstructBlock.ConstructBuild cb)
|
||||
region = cb.current.uiIcon;
|
||||
else if (b.block != null) region = b.block.uiIcon;
|
||||
}
|
||||
return new TextureRegionDrawable(region);
|
||||
};
|
||||
Drawable img = reg.get();
|
||||
ImageButton imagebt = new ImageButton(img, img);
|
||||
|
||||
imagebt.hovered(() -> {
|
||||
Time.run(60 * 2, () -> {
|
||||
if (imagebt.isOver()) lockTarget();
|
||||
});
|
||||
});
|
||||
imagebt.clicked(() -> {
|
||||
Teamc target = getTarget();
|
||||
if (target instanceof Unit u && u.type != null) ui.content.show(u.type);
|
||||
else if (target instanceof Building b && b.block != null) ui.content.show(b.block);
|
||||
});
|
||||
ttt.add(imagebt).update((i) -> {
|
||||
i.getStyle().imageUp = reg.get().tint(Tmp.c1.set(locked ? Color.red.cpy().shiftHue(2 * Time.time) : Color.white));
|
||||
i.getStyle().imageDown = reg.get().tint(Tmp.c1.mul(Color.darkGray));
|
||||
i.layout();
|
||||
}).size(4 * 8f);
|
||||
}),
|
||||
new Table(ttt -> {
|
||||
ttt.stack(
|
||||
new Table(temp -> {
|
||||
temp.image(new ScaledNinePatchDrawable(new NinePatch(Icon.defenseSmall.getRegion()), 1));
|
||||
temp.visibility = () -> getTarget() instanceof Unit;
|
||||
}),
|
||||
new Table(temp -> {
|
||||
Label label = new Label(() -> (getTarget() instanceof Unit u && u.type != null ? (int) u.type.armor + "" : ""));
|
||||
label.setColor(Pal.surge);
|
||||
temp.add(label).center();
|
||||
temp.pack();
|
||||
})
|
||||
).padLeft(2 * 8f).padBottom(2 * 8f);
|
||||
})
|
||||
);
|
||||
|
||||
tt.label(() -> {
|
||||
String name = "";
|
||||
Teamc target = getTarget();
|
||||
if (target instanceof Unit u && u.type != null)
|
||||
name = u.type.localizedName;
|
||||
if (target instanceof Building b && b.block != null) {
|
||||
if (target instanceof ConstructBlock.ConstructBuild cb)
|
||||
name = cb.current.localizedName;
|
||||
else name = b.block.localizedName;
|
||||
int offset = 8;
|
||||
Draw.color(locked?Pal.accent:Pal.gray);
|
||||
Draw.alpha(parentAlpha);
|
||||
Lines.stroke(Scl.scl(3f));
|
||||
Lines.rect(x-offset/2f, y-offset/2f, width+offset, height+offset);
|
||||
Draw.reset();
|
||||
}
|
||||
return "[accent]" + (name.length() > 13 ? name.substring(0, 13) + "..." : name) + "[]";
|
||||
};
|
||||
image.update(()->{
|
||||
TextureRegion region = clear;
|
||||
if (target instanceof Unit u && u.type != null) region = u.type.uiIcon;
|
||||
else if (target instanceof Building b) {
|
||||
if (target instanceof ConstructBlock.ConstructBuild cb) region = cb.current.uiIcon;
|
||||
else if (b.block != null) region = b.block.uiIcon;
|
||||
}
|
||||
image.setDrawable(region);
|
||||
});
|
||||
image.clicked(Main::lockTarget);
|
||||
|
||||
tt.addListener(new Tooltip(to -> {
|
||||
Teamc target = getTarget();
|
||||
|
||||
to.background(Styles.black6);
|
||||
|
||||
to.table(Tex.underline2, tool2 -> {
|
||||
tool2.label(() -> {
|
||||
if (target instanceof Unit u) return u.type.localizedName;
|
||||
else if (target instanceof Building b) return b.block.localizedName;
|
||||
else return "";
|
||||
});
|
||||
}).row();
|
||||
to.label(() -> target instanceof Unit u && u.isPlayer() ? u.getPlayer().name() : "AI").row();
|
||||
to.label(() -> target == null
|
||||
? "(" + 0 + ", " + 0 + ")"
|
||||
: "(" + Strings.fixed(target.x() / tilesize, 2) + ", " + Strings.fixed(target.y() / tilesize, 2) + ")").row();
|
||||
}));
|
||||
tt.update(() -> tt.setBackground(((NinePatchDrawable) Tex.underline2).tint(getTarget() == null ? Color.gray : getTarget().team().color)));
|
||||
}).row();
|
||||
ScrollPane pane = table.pane(Styles.nonePane, new Table(tt -> {
|
||||
tt.add(image).size(iconMed).padRight(12f);
|
||||
tt.label(() -> {
|
||||
if (target instanceof Unit u && u.type != null) return u.type.localizedName;
|
||||
if (target instanceof Building b && b.block != null) {
|
||||
if (target instanceof ConstructBlock.ConstructBuild cb) return cb.current.localizedName;
|
||||
return b.block.localizedName;
|
||||
}
|
||||
return "";
|
||||
}).color(Pal.accent);
|
||||
}).tooltip((to -> {
|
||||
to.background(Styles.black6);
|
||||
to.label(() -> target instanceof Unit u && u.isPlayer() ? u.getPlayer().name() : "AI").row();
|
||||
to.label(() -> target == null ? "(" + 0 + ", " + 0 + ")" : "(" + Strings.fixed(target.x() / tilesize, 2) + ", " + Strings.fixed(target.y() / tilesize, 2) + ")").row();
|
||||
to.label(() -> target instanceof Unit u ? "[accent]"+ Strings.fixed(u.armor, 0) + "[] Armor" : "");
|
||||
})).margin(12f).row();
|
||||
table.image().height(4f).color(player.team().color).growX().row();
|
||||
table.add(new OverScrollPane(new Table(bars -> {
|
||||
bars.top();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
addBar(tt, i);
|
||||
tt.row();
|
||||
int index = i;
|
||||
bars.table(bar -> {
|
||||
bar.add(new SBar(
|
||||
() -> BarInfo.strings.get(index),
|
||||
() -> {
|
||||
if (BarInfo.colors.get(index) != Color.clear) lastColors.set(index, BarInfo.colors.get(index));
|
||||
return lastColors.get(index);
|
||||
},
|
||||
() -> BarInfo.numbers.get(index)
|
||||
)).height(4 * 8f).growX();
|
||||
bar.add(new Image(){
|
||||
@Override
|
||||
public void draw() {
|
||||
validate();
|
||||
|
||||
Draw.color(Color.white);
|
||||
Draw.alpha(parentAlpha * color.a);
|
||||
TextureRegionDrawable region = new TextureRegionDrawable(getRegions(index));
|
||||
region.draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
|
||||
Draw.color(BarInfo.colors.get(index));
|
||||
if(ScissorStack.push(scissor.set(x, y, imageWidth * scaleX, imageHeight * scaleY * BarInfo.numbers.get(index)))){
|
||||
region.draw(x, y, imageWidth * scaleX, imageHeight * scaleY);
|
||||
ScissorStack.pop();
|
||||
}
|
||||
}
|
||||
}).size(iconMed * 0.75f).padLeft(8f);
|
||||
}).growX().row();
|
||||
}
|
||||
}).left()).top().right().grow().get();
|
||||
pane.update(() -> {
|
||||
Element result = scene.hit(input.mouseX(), input.mouseY(), true);
|
||||
if(pane.hasScroll() && (result == null || !result.isDescendantOf(pane)))
|
||||
scene.setScrollFocus(null);
|
||||
scrollPos = pane.getScrollY();
|
||||
});
|
||||
|
||||
pane.setOverscroll(false, false);
|
||||
pane.setScrollingDisabled(true, false);
|
||||
pane.setScrollYForce(scrollPos);
|
||||
}), Styles.nonePane, scrollPos).disableScroll(true, false)).growX().padTop(12f);
|
||||
}
|
||||
|
||||
public void lockTarget() {
|
||||
locked = !locked;
|
||||
target = locked ? getTarget() : null;
|
||||
}
|
||||
|
||||
public void showMoving() {
|
||||
Table table = new Table(Styles.black3).margin(4);
|
||||
Vec2 pos = input.mouse();
|
||||
table.update(() -> {
|
||||
if(Vars.state.isMenu()) table.remove();
|
||||
Vec2 vec = Core.camera.project(pos.x, pos.y);
|
||||
table.setPosition(vec.x, vec.y, Align.center);
|
||||
});
|
||||
|
||||
table.add("hello world").style(Styles.defaultLabel);
|
||||
table.pack();
|
||||
}
|
||||
|
||||
float angle = 360;
|
||||
@Override
|
||||
public void update() {
|
||||
if((input.keyDown(KeyCode.shiftRight) || input.keyDown(KeyCode.shiftLeft))) {
|
||||
if(input.keyTap(KeyCode.f)) {
|
||||
showMoving();
|
||||
}
|
||||
if(input.keyTap(KeyCode.r)) lockTarget();
|
||||
if(input.keyTap(KeyCode.r)) {
|
||||
player.unit().commandNearby(new FormationPattern() {
|
||||
@Override
|
||||
public Vec3 calculateSlotLocation(Vec3 out, int slot) {
|
||||
angle+=0.3f;
|
||||
float radian = angle / 360 * slot/slots * Mathf.degRad;
|
||||
float sizeScaling = 0.25f;
|
||||
float rotateSpeed = 0.01f;
|
||||
|
||||
out.set(Tmp.v1.set(this.spacing * (sizeScaling * 5 * Mathf.cos(2 * radian) + sizeScaling * 2 * Mathf.cos(3 * radian)), this.spacing * (sizeScaling * 2 * Mathf.sin(3 * radian) - sizeScaling * 5 * Mathf.sin(2 * radian))).rotateRad(Time.time * rotateSpeed), 0);
|
||||
return out;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TextureRegion getRegions(int i){
|
||||
Teamc target = getTarget();
|
||||
//do not ask me WHAT THE FUCK IS THIS
|
||||
TextureRegion getRegions(int i){
|
||||
TextureRegion region = clear;
|
||||
|
||||
if(i == 0){
|
||||
@@ -248,49 +172,8 @@ public class UnitDisplay extends Window implements Updatable {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void addBar(Table table, int i){
|
||||
table.add(new SBar(
|
||||
() -> BarInfo.strings.get(i),
|
||||
() -> {
|
||||
if (BarInfo.colors.get(i) != Color.clear) lastColors.set(i, BarInfo.colors.get(i));
|
||||
return lastColors.get(i);
|
||||
},
|
||||
() -> BarInfo.numbers.get(i)
|
||||
)).height(4 * 8f).growX().left();
|
||||
table.add(new Image(){
|
||||
@Override
|
||||
public void draw() {
|
||||
validate();
|
||||
|
||||
float x = this.x;
|
||||
float y = this.y;
|
||||
float scaleX = this.scaleX;
|
||||
float scaleY = this.scaleY;
|
||||
Draw.color(Color.white);
|
||||
Draw.alpha(parentAlpha * color.a);
|
||||
|
||||
TextureRegionDrawable region = new TextureRegionDrawable(getRegions(i));
|
||||
float rotation = getRotation();
|
||||
if(scaleX != 1 || scaleY != 1 || rotation != 0){
|
||||
region.draw(x + imageX, y + imageY, originX - imageX, originY - imageY,
|
||||
imageWidth, imageHeight, scaleX, scaleY, rotation);
|
||||
return;
|
||||
}
|
||||
region.draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
|
||||
|
||||
Draw.color(BarInfo.colors.get(i));
|
||||
if(ScissorStack.push(scissor.set(x, y, imageWidth * scaleX, imageHeight * scaleY * BarInfo.numbers.get(i)))){
|
||||
region.draw(x, y, imageWidth * scaleX, imageHeight * scaleY);
|
||||
ScissorStack.pop();
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
}).size(iconMed * 0.75f).left();
|
||||
}
|
||||
|
||||
|
||||
static class WeaponDisplay extends Table {
|
||||
public WeaponDisplay() {
|
||||
WeaponDisplay() {
|
||||
table().update(tt -> {
|
||||
tt.clear();
|
||||
if(getTarget() instanceof Unit u && u.type != null && u.hasWeapons()) {
|
||||
@@ -344,7 +227,7 @@ public class UnitDisplay extends Window implements Updatable {
|
||||
}
|
||||
}
|
||||
static class UnitInfoDisplay extends Table {
|
||||
public UnitInfoDisplay() {
|
||||
UnitInfoDisplay() {
|
||||
top();
|
||||
float[] count = new float[]{-1};
|
||||
table().update(t -> {
|
||||
|
||||
Reference in New Issue
Block a user