diff --git a/assets/sprites/ui/bars/sidebar.9.png b/assets/sprites/ui/bars/sidebar.9.png new file mode 100644 index 0000000..06a1885 Binary files /dev/null and b/assets/sprites/ui/bars/sidebar.9.png differ diff --git a/src/UnitInfo/core/HudUi.java b/src/UnitInfo/core/HudUi.java index ab6c2f6..36a93de 100644 --- a/src/UnitInfo/core/HudUi.java +++ b/src/UnitInfo/core/HudUi.java @@ -79,7 +79,7 @@ public class HudUi { Events.on(EventType.WaveEvent.class, e -> waveTable.rebuild()); Events.on(EventType.WorldLoadEvent.class, e -> itemTable.rebuild()); Events.run(EventType.Trigger.update, ()->{ - unitTable.setEvent(); + if(unitTable!=null) unitTable.setEvent(); itemTable.setEvent(); OverDrawer.target = getTarget(); OverDrawer.locked = locked; @@ -286,10 +286,9 @@ public class HudUi { label.setText(bundle.get(hud)); table.removeChild(baseTable); labelTable.setPosition(buttons.items[uiIndex].x, buttons.items[uiIndex].y); - unitTable = new UnitDisplay(); waveTable = new WaveDisplay(); itemTable = new CoreDisplay(); - baseTable = table.table(tt -> tt.stack(unitTable, waveTable, itemTable, labelTable).align(Align.left).left().visible(() -> settings.getBool("infoui"))).left().get(); + baseTable = table.table(tt -> tt.stack(waveTable, itemTable, labelTable).align(Align.left).left().visible(() -> settings.getBool("infoui"))).left().get(); a = 1f; } @@ -322,10 +321,9 @@ public class HudUi { t.row(); } }); - unitTable = new UnitDisplay(); waveTable = new WaveDisplay(); itemTable = new CoreDisplay(); - baseTable = table.table(tt -> tt.stack(unitTable, waveTable, itemTable, labelTable).align(Align.left).left().visible(() -> settings.getBool("infoui"))).left().get(); + baseTable = table.table(tt -> tt.stack(waveTable, itemTable, labelTable).align(Align.left).left().visible(() -> settings.getBool("infoui"))).left().get(); table.fillParent = true; table.visibility = () -> ui.hudfrag.shown && !ui.minimapfrag.shown(); diff --git a/src/UnitInfo/core/Main.java b/src/UnitInfo/core/Main.java index 363d364..a9d37fc 100644 --- a/src/UnitInfo/core/Main.java +++ b/src/UnitInfo/core/Main.java @@ -1,25 +1,17 @@ package UnitInfo.core; import UnitInfo.shaders.*; +import UnitInfo.ui.HUDFragment; +import UnitInfo.ui.MindowsTex; +import UnitInfo.ui.UnitDisplay; +import UnitInfo.ui.WindowTables; import arc.*; -import arc.audio.Sound; -import arc.files.Fi; -import arc.input.KeyCode; -import arc.scene.ui.TextArea; -import arc.struct.Seq; -import arc.util.Log; -import arc.util.Nullable; -import arc.util.Strings; -import arc.util.Timer; import mindustry.*; import mindustry.game.EventType.*; -import mindustry.gen.Call; -import mindustry.gen.Player; -import mindustry.gen.Sounds; import mindustry.mod.*; -import mindustry.ui.dialogs.BaseDialog; import static UnitInfo.SVars.*; +import static UnitInfo.ui.UnitDisplay.getTarget; import static arc.Core.*; public class Main extends Mod { @@ -36,8 +28,18 @@ public class Main extends Mod { meta.description = bundle.get("shar-description"); }); + Events.run(Trigger.class, () -> { + try { + BarInfo.getInfo(getTarget()); + } catch (IllegalAccessException | NoSuchFieldException err) { + err.printStackTrace(); + } + }); + Events.on(ClientLoadEvent.class, e -> { new SettingS().init(); + MindowsTex.init(); + new HUDFragment().build(Vars.ui.hudGroup); hud = new HudUi(); hud.addTable(); hud.addWaveInfoTable(); diff --git a/src/UnitInfo/core/SettingS.java b/src/UnitInfo/core/SettingS.java index 3c5f3c9..689ceaf 100644 --- a/src/UnitInfo/core/SettingS.java +++ b/src/UnitInfo/core/SettingS.java @@ -98,7 +98,7 @@ public class SettingS { sharset = new SettingsMenuDialog.SettingsTable(); dialog.cont.center().add(new Table(t -> t.pane(sharset).grow().row())); ui.settings.shown(() -> { - Table settingUi = (Table)((Group)((Group)(ui.settings.getChildren().get(1))).getChildren().get(0)).getChildren().get(0); //This looks so stupid lol - lmfao - hehe + Table settingUi = (Table)((Group)((Group)(ui.settings.getChildren().get(1))).getChildren().get(0)).getChildren().get(0); //This looks so stupid lol settingUi.row(); settingUi.button(bundle.get("setting.shar-title"), Styles.cleart, dialog::show); }); diff --git a/src/UnitInfo/ui/HUDFragment.java b/src/UnitInfo/ui/HUDFragment.java new file mode 100644 index 0000000..9bfd486 --- /dev/null +++ b/src/UnitInfo/ui/HUDFragment.java @@ -0,0 +1,29 @@ +package UnitInfo.ui; + +import arc.scene.*; +import mindustry.ui.fragments.*; + +import static UnitInfo.ui.WindowTables.unitTable; + +public class HUDFragment extends Fragment{ + @Override + public void build(Group parent){ + parent.fill(t -> { + t.name = "Windows"; + t.visible(() -> parent.visible); + + // windows (totally not a copyright violation) + t.center().right(); + t.add(unitTable).size(250f).visible(false); + + // sidebar + t.add(new TaskbarTable( + unitTable + )).visible(TaskbarTable.visibility); + + t.update(()->{ + if(unitTable instanceof Updatable u) u.setEvent(); + }); + }); + }; +} \ No newline at end of file diff --git a/src/UnitInfo/ui/MindowsTex.java b/src/UnitInfo/ui/MindowsTex.java new file mode 100644 index 0000000..ccbbbb4 --- /dev/null +++ b/src/UnitInfo/ui/MindowsTex.java @@ -0,0 +1,12 @@ +package UnitInfo.ui; + +import arc.*; +import arc.scene.style.*; + +public class MindowsTex{ + public static Drawable sidebar; + + public static void init(){ + sidebar = Core.atlas.drawable("unitinfo-sidebar"); + } +} \ No newline at end of file diff --git a/src/UnitInfo/ui/SBar.java b/src/UnitInfo/ui/SBar.java index 8dcbc1e..189f6f4 100644 --- a/src/UnitInfo/ui/SBar.java +++ b/src/UnitInfo/ui/SBar.java @@ -140,6 +140,6 @@ public class SBar extends Element{ ScissorStack.pop(); } - Fonts.outline.draw(name, x + width / 2f, y + height * 0.75f, Color.white, Scl.scl(modUiScale < 1 ? modUiScale : 1), false, Align.center); + Fonts.outline.draw(name, x + width / 2f, y + height * 0.75f, Color.white, 1, false, Align.center); } } diff --git a/src/UnitInfo/ui/TaskbarTable.java b/src/UnitInfo/ui/TaskbarTable.java new file mode 100644 index 0000000..597f7dc --- /dev/null +++ b/src/UnitInfo/ui/TaskbarTable.java @@ -0,0 +1,25 @@ +package UnitInfo.ui; + +import arc.func.*; +import arc.scene.ui.layout.*; +import mindustry.*; +import mindustry.ui.*; + +public class TaskbarTable extends Table{ + public static Boolp visibility = () -> Vars.ui.hudfrag.shown && !Vars.ui.minimapfrag.shown(); + + public TaskbarTable(WindowTable... items){ + visible = true; + table(MindowsTex.sidebar,t -> { + t.top().center(); + for(WindowTable w : items){ + t.button(w.icon, Styles.emptyi, () -> { + w.visible(visibility); + }).disabled(b -> w.visible) + .size(40f) + .padLeft(5f); + t.row(); + } + }).right().center().width(40f); + } +} \ No newline at end of file diff --git a/src/UnitInfo/ui/UnitDisplay.java b/src/UnitInfo/ui/UnitDisplay.java index c097545..94e04f4 100644 --- a/src/UnitInfo/ui/UnitDisplay.java +++ b/src/UnitInfo/ui/UnitDisplay.java @@ -2,22 +2,27 @@ package UnitInfo.ui; import UnitInfo.SVars; import UnitInfo.core.BarInfo; +import arc.Core; import arc.func.Prov; 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.scene.actions.Actions; +import arc.scene.event.Touchable; import arc.scene.style.*; import arc.scene.ui.*; import arc.scene.ui.layout.*; import arc.struct.Bits; import arc.struct.Seq; -import arc.util.Strings; -import arc.util.Time; -import arc.util.Tmp; +import arc.util.*; +import mindustry.Vars; +import mindustry.ai.formations.FormationPattern; import mindustry.core.UI; -import mindustry.ctype.UnlockableContent; import mindustry.entities.units.WeaponMount; import mindustry.gen.*; import mindustry.graphics.Pal; @@ -36,150 +41,111 @@ import static UnitInfo.SVars.modUiScale; import static arc.Core.*; import static mindustry.Vars.*; -public class UnitDisplay extends Table { - static float weaponScrollPos; - static Seq bars = new Seq<>(); +public class UnitDisplay extends WindowTable implements Updatable { static Seq lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear); static final Rect scissor = new Rect(); public UnitDisplay() { - fillParent = true; - visibility = () -> 0 == SVars.hud.uiIndex; + super("Unit Display", Icon.units, t -> {}); + } - left().defaults().width(Scl.scl(modUiScale) * 35 * 8f).height(Scl.scl(modUiScale) * 35 * 8f); - bars.clear(); - for(int i = 0; i < 6; i++) bars.add(addBar(i)); - Table table1 = new Table(Tex.button, t -> { + @Override + public void build() { + top(); + topBar(); + + Log.info("called"); + //new UnitInfoDisplay().marginBottom(80f); + table(Styles.black8, t -> { t.table(Tex.underline2, tt -> { - tt.setWidth(Scl.scl(modUiScale) * 35 * 8f); - Stack stack = new Stack(){{ - add(new Table(ttt -> { + tt.stack( + new Table(ttt -> { Prov reg = () -> { TextureRegion region = clear; - if(getTarget() instanceof Unit u && u.type != null) region = u.type.uiIcon; - else if(getTarget() instanceof Building b) { - if(getTarget() instanceof ConstructBlock.ConstructBuild cb) region = cb.current.uiIcon; - else if(b.block != null) region = b.block.uiIcon; + 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.hovered(() -> { + Time.run(60 * 2, () -> { + if (imagebt.isOver()) lockTarget(); }); }); - imagebt.clicked(()->{ - if(getTarget() instanceof Unit u && u.type != null) ui.content.show(u.type); - else if(getTarget() instanceof Building b && b.block != null) ui.content.show(b.block); + 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(SVars.hud.locked ? Color.red.shiftHue(2*60%Time.delta) : Color.white)); + i.getStyle().imageUp = reg.get().tint(Tmp.c1.set(SVars.hud.locked ? Color.red.shiftHue(2 * 60 % Time.delta) : Color.white)); i.getStyle().imageDown = reg.get().tint(Tmp.c1.mul(Color.darkGray)); i.layout(); - }).size(Scl.scl(modUiScale) * 4 * 8f); - })); - - add(new Table(ttt -> { + }).size(4 * 8f); + }), + new Table(ttt -> { ttt.stack( - new Table(temp -> { - temp.image(new ScaledNinePatchDrawable(new NinePatch(Icon.defenseSmall.getRegion()), modUiScale)); - 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); - label.setFontScale(Scl.scl(modUiScale) * 0.5f); - temp.add(label).center(); - temp.pack(); - }) - ).padLeft(Scl.scl(modUiScale) * 2 * 8f).padBottom(Scl.scl(modUiScale) * 2 * 8f); - })); - }}; + 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); + }) + ); - Label label = new Label(() -> { + tt.label(() -> { String name = ""; - if(getTarget() instanceof Unit u && u.type != null) + Teamc target = getTarget(); + if (target instanceof Unit u && u.type != null) name = u.type.localizedName; - if(getTarget() instanceof Building b && b.block != null) { - if(getTarget() instanceof ConstructBlock.ConstructBuild cb) name = cb.current.localizedName; + if (target instanceof Building b && b.block != null) { + if (target instanceof ConstructBlock.ConstructBuild cb) + name = cb.current.localizedName; else name = b.block.localizedName; } return "[accent]" + (name.length() > 13 ? name.substring(0, 13) + "..." : name) + "[]"; }); - label.setFontScale(Scl.scl(modUiScale) * 0.75f); - tt.top(); - tt.add(stack); - tt.add(label); + tt.addListener(new Tooltip(to -> { + Teamc target = getTarget(); - tt.addListener(new Tooltip(tool -> { - tool.background(Tex.button).table(to -> { - Teamc target = getTarget(); - to.table(Tex.underline2, tool2 -> { - Label targetName = new Label(()->{ - if(target instanceof Unit u) return u.type.localizedName; - else if(target instanceof Building b) return b.block.localizedName; - else return ""; - }); - targetName.setFontScale(Scl.scl(modUiScale)); - tool2.add(targetName); - }).row(); + to.background(Styles.black6); - Label ownerName = new Label(()->target instanceof Unit u && u.isPlayer() ? u.getPlayer().name() : "AI"); - ownerName.setFontScale(Scl.scl(modUiScale)); - to.add(ownerName).row(); - - Label targetPos = new Label(()->target == null ? "(" + 0 + ", " + 0 + ")" : "(" + Strings.fixed(target.x() / tilesize, 2) + ", " + Strings.fixed(target.y() / tilesize, 2) + ")"); - targetPos.setFontScale(Scl.scl(modUiScale)); - to.add(targetPos).row(); - }); - - tool.update(() -> { - NinePatchDrawable patch = (NinePatchDrawable)Tex.button; - tool.setBackground(patch.tint(Tmp.c1.set(patch.getPatch().getColor()).a(settings.getInt("uiopacity") / 100f))); - }); + 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().isNull() ? Color.gray : getTarget().team().color))); - }); - t.row(); - ScrollPane pane = t.pane(Styles.nonePane, new Table(tt -> { - for(Element bar : bars){ - bar.setScale(Scl.scl(modUiScale)); - tt.add(bar).growX().left(); - tt.row(); - } - tt.row(); - tt.add(new WeaponDisplay()); - }).left()).get(); - pane.update(() -> { - Element result = scene.hit(input.mouseX(), input.mouseY(), true); - if(pane.hasScroll() && (result == null || !result.isDescendantOf(pane))) - scene.setScrollFocus(null); - weaponScrollPos = pane.getScrollY(); - }); - - pane.setOverscroll(false, false); - pane.setScrollingDisabled(true, false); - pane.setScrollYForce(weaponScrollPos); - - t.update(() -> { - NinePatchDrawable patch = (NinePatchDrawable)Tex.button; - t.setBackground(patch.tint(Tmp.c1.set(patch.getPatch().getColor()).a(settings.getInt("uiopacity") / 100f))); - }); - }); - table(t -> t.stack(new UnitInfoDisplay().marginBottom(80f), table1).padRight(Scl.scl(modUiScale) * 8 * 8f)); - - update(() -> { - try { - BarInfo.getInfo(getTarget()); - } catch (IllegalAccessException | NoSuchFieldException e) { - e.printStackTrace(); + //tt.update(() -> tt.setBackground(((NinePatchDrawable) Tex.underline2).tint(getTarget() == null ? Color.gray : getTarget().team().color))); + }).row(); + for (int i = 0; i < 6; i++) { + addBar(t, i); + t.row(); } - }); + //tt.add(new WeaponDisplay()); + }).top().right().grow(); + resizeButton(); } public static Teamc getTarget() { @@ -191,9 +157,41 @@ public class UnitDisplay extends Table { SVars.hud.lockedTarget = SVars.hud.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 setEvent() { 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; + } + }); + } } } @@ -248,51 +246,44 @@ public class UnitDisplay extends Table { return region; } - public Element addBar(int i){ - return new Stack(){{ - add(new Table(t -> { - t.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) - )).width(Scl.scl(modUiScale) * 24 * 8f).height(Scl.scl(modUiScale) * 4 * 8f).growX().left(); - })); - add(new Table(t -> { - t.right(); - t.add(new Image(){ - @Override - public void draw() { - validate(); + 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); + 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); + 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 * Scl.scl(modUiScale) * 0.75f); - })); - }}; + 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(); } @@ -388,7 +379,7 @@ public class UnitDisplay extends Table { t.clear(); if(applied != null){ - for(StatusEffect effect : content.statusEffects()){ + for(StatusEffect effect : Vars.content.statusEffects()){ if(applied.get(effect.id) && !effect.isHidden()){ t.image(effect.uiIcon).size(iconSmall).get() .addListener(new Tooltip(l -> l.label(() -> effect.localizedName + " [lightgray]" + UI.formatTime(st.getDuration(effect))).style(Styles.outlineLabel))); diff --git a/src/UnitInfo/ui/Updatable.java b/src/UnitInfo/ui/Updatable.java new file mode 100644 index 0000000..42d17ba --- /dev/null +++ b/src/UnitInfo/ui/Updatable.java @@ -0,0 +1,5 @@ +package UnitInfo.ui; + +public interface Updatable { + void setEvent(); +} diff --git a/src/UnitInfo/ui/WindowTable.java b/src/UnitInfo/ui/WindowTable.java new file mode 100644 index 0000000..ea6a723 --- /dev/null +++ b/src/UnitInfo/ui/WindowTable.java @@ -0,0 +1,134 @@ +package UnitInfo.ui; + +import arc.func.*; +import arc.input.*; +import arc.math.geom.*; +import arc.scene.event.*; +import arc.scene.style.*; +import arc.scene.ui.layout.*; +import arc.util.*; +import mindustry.gen.*; +import mindustry.ui.*; + +import java.awt.*; + +public class WindowTable extends Table{ + public Cons content, onClose; + public TextureRegionDrawable icon; + public float maxWindowHeight, maxWindowWidth; + public boolean maxWidthEnabled = false, maxHeightEnabled = false; + + public WindowTable() { + this("none", Icon.none, c->{}); + } + + public WindowTable(String title, TextureRegionDrawable icon, Cons
content){ + this(title, icon, content, t -> t.visible(() -> false)); + } + + public WindowTable(String title, TextureRegionDrawable icon, Cons
content, Cons
onClose){ + this.name = title; + this.icon = icon; + this.content = content; + this.onClose = onClose; + build(); + } + + public void build(){ + top(); + topBar(); + + // window contents + table(Styles.black5, t -> { + content.get(t); + }).grow(); + + resizeButton(); + } + + public void topBar(){ + table(t -> { + t.table(Tex.buttonEdge1, b -> { + b.top().left(); + b.image(icon).size(20f).padLeft(15).top().left(); + b.pane(Styles.nonePane, p -> { + p.top().left(); + p.labelWrap(name).padLeft(20).top().left().get().setAlignment(Align.topLeft); + }).top().left().height(40f).growX().get().setScrollingDisabled(true, true); + }).maxHeight(40f).grow(); + t.table(Tex.buttonEdge3, b -> { + b.button(Icon.cancel, Styles.emptyi, () -> onClose.get(this)); + }).maxHeight(40f).width(80f).growY(); + + t.touchable = Touchable.enabled; + t.addListener(new InputListener(){ + float lastX, lastY; + @Override + public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button) { + Vec2 v = t.localToStageCoordinates(Tmp.v1.set(x, y)); + lastX = v.x; + lastY = v.y; + t.toFront(); + return true; + } + + @Override + public void touchDragged(InputEvent event, float x, float y, int pointer) { + Vec2 v = t.localToStageCoordinates(Tmp.v1.set(x, y)); + + moveBy(v.x - lastX, v.y - lastY); + lastX = v.x; + lastY = v.y; + } + }); + }).top().height(40f).growX(); + row(); + } + + public void resizeButton(){ + row(); + table(Styles.black5, t -> { + t.table().growX(); + t.table(Icon.resizeSmall, r -> { + r.bottom().left(); + r.touchable = Touchable.enabled; + r.addListener(new InputListener(){ + float lastX, lastY; + @Override + public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button) { + Vec2 v = r.localToStageCoordinates(Tmp.v1.set(x, y)); + lastX = v.x; + lastY = v.y; + return true; + } + + @Override + public void touchDragged(InputEvent event, float x, float y, int pointer) { + Vec2 v = r.localToStageCoordinates(Tmp.v1.set(x, y)); + float w = v.x - lastX; + float h = v.y - lastY; + + // will softlock if initial size is smaller than minimum + // so don't do that! + if(getWidth() + w < 160f || (getWidth() + w > maxWindowWidth && maxWidthEnabled)) w = 0; + if(getHeight() - h < 160f || (getHeight() - h > maxWindowHeight && maxHeightEnabled)) h = 0; + sizeBy(w, -h); + moveBy(0, h); + lastX = v.x; + lastY = v.y; + } + }); + }).size(20f).left(); + }).height(20f).growX(); + } + + public void setMaxWindowWidth(float maxWindowWidth){ + this.maxWindowWidth = maxWindowWidth; + maxWidthEnabled = true; + } + + public void setMaxWindowHeight(float maxWindowHeight){ + this.maxWindowHeight = maxWindowHeight; + maxHeightEnabled = true; + } +} \ No newline at end of file diff --git a/src/UnitInfo/ui/WindowTables.java b/src/UnitInfo/ui/WindowTables.java new file mode 100644 index 0000000..afadbdc --- /dev/null +++ b/src/UnitInfo/ui/WindowTables.java @@ -0,0 +1,5 @@ +package UnitInfo.ui; + +public class WindowTables { + public static WindowTable unitTable = new UnitDisplay(); +}