unittable is windowed

This commit is contained in:
sharlottes
2022-04-08 23:53:55 +09:00
parent 959b271788
commit 74f81fc9f8
12 changed files with 378 additions and 177 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

View File

@@ -79,7 +79,7 @@ public class HudUi {
Events.on(EventType.WaveEvent.class, e -> waveTable.rebuild()); Events.on(EventType.WaveEvent.class, e -> waveTable.rebuild());
Events.on(EventType.WorldLoadEvent.class, e -> itemTable.rebuild()); Events.on(EventType.WorldLoadEvent.class, e -> itemTable.rebuild());
Events.run(EventType.Trigger.update, ()->{ Events.run(EventType.Trigger.update, ()->{
unitTable.setEvent(); if(unitTable!=null) unitTable.setEvent();
itemTable.setEvent(); itemTable.setEvent();
OverDrawer.target = getTarget(); OverDrawer.target = getTarget();
OverDrawer.locked = locked; OverDrawer.locked = locked;
@@ -286,10 +286,9 @@ public class HudUi {
label.setText(bundle.get(hud)); label.setText(bundle.get(hud));
table.removeChild(baseTable); table.removeChild(baseTable);
labelTable.setPosition(buttons.items[uiIndex].x, buttons.items[uiIndex].y); labelTable.setPosition(buttons.items[uiIndex].x, buttons.items[uiIndex].y);
unitTable = new UnitDisplay();
waveTable = new WaveDisplay(); waveTable = new WaveDisplay();
itemTable = new CoreDisplay(); 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; a = 1f;
} }
@@ -322,10 +321,9 @@ public class HudUi {
t.row(); t.row();
} }
}); });
unitTable = new UnitDisplay();
waveTable = new WaveDisplay(); waveTable = new WaveDisplay();
itemTable = new CoreDisplay(); 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.fillParent = true;
table.visibility = () -> ui.hudfrag.shown && !ui.minimapfrag.shown(); table.visibility = () -> ui.hudfrag.shown && !ui.minimapfrag.shown();

View File

@@ -1,25 +1,17 @@
package UnitInfo.core; package UnitInfo.core;
import UnitInfo.shaders.*; import UnitInfo.shaders.*;
import UnitInfo.ui.HUDFragment;
import UnitInfo.ui.MindowsTex;
import UnitInfo.ui.UnitDisplay;
import UnitInfo.ui.WindowTables;
import arc.*; 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.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.gen.Call;
import mindustry.gen.Player;
import mindustry.gen.Sounds;
import mindustry.mod.*; import mindustry.mod.*;
import mindustry.ui.dialogs.BaseDialog;
import static UnitInfo.SVars.*; import static UnitInfo.SVars.*;
import static UnitInfo.ui.UnitDisplay.getTarget;
import static arc.Core.*; import static arc.Core.*;
public class Main extends Mod { public class Main extends Mod {
@@ -36,8 +28,18 @@ public class Main extends Mod {
meta.description = bundle.get("shar-description"); 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 -> { Events.on(ClientLoadEvent.class, e -> {
new SettingS().init(); new SettingS().init();
MindowsTex.init();
new HUDFragment().build(Vars.ui.hudGroup);
hud = new HudUi(); hud = new HudUi();
hud.addTable(); hud.addTable();
hud.addWaveInfoTable(); hud.addWaveInfoTable();

View File

@@ -98,7 +98,7 @@ public class SettingS {
sharset = new SettingsMenuDialog.SettingsTable(); sharset = new SettingsMenuDialog.SettingsTable();
dialog.cont.center().add(new Table(t -> t.pane(sharset).grow().row())); dialog.cont.center().add(new Table(t -> t.pane(sharset).grow().row()));
ui.settings.shown(() -> { 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.row();
settingUi.button(bundle.get("setting.shar-title"), Styles.cleart, dialog::show); settingUi.button(bundle.get("setting.shar-title"), Styles.cleart, dialog::show);
}); });

View File

@@ -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();
});
});
};
}

View File

@@ -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");
}
}

View File

@@ -140,6 +140,6 @@ public class SBar extends Element{
ScissorStack.pop(); 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);
} }
} }

View File

@@ -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);
}
}

View File

@@ -2,22 +2,27 @@ package UnitInfo.ui;
import UnitInfo.SVars; import UnitInfo.SVars;
import UnitInfo.core.BarInfo; import UnitInfo.core.BarInfo;
import arc.Core;
import arc.func.Prov; import arc.func.Prov;
import arc.graphics.Color; import arc.graphics.Color;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.input.KeyCode; import arc.input.KeyCode;
import arc.math.Mathf;
import arc.math.geom.Rect; import arc.math.geom.Rect;
import arc.math.geom.Vec2;
import arc.math.geom.Vec3;
import arc.scene.Element; import arc.scene.Element;
import arc.scene.actions.Actions;
import arc.scene.event.Touchable;
import arc.scene.style.*; import arc.scene.style.*;
import arc.scene.ui.*; import arc.scene.ui.*;
import arc.scene.ui.layout.*; import arc.scene.ui.layout.*;
import arc.struct.Bits; import arc.struct.Bits;
import arc.struct.Seq; import arc.struct.Seq;
import arc.util.Strings; import arc.util.*;
import arc.util.Time; import mindustry.Vars;
import arc.util.Tmp; import mindustry.ai.formations.FormationPattern;
import mindustry.core.UI; import mindustry.core.UI;
import mindustry.ctype.UnlockableContent;
import mindustry.entities.units.WeaponMount; import mindustry.entities.units.WeaponMount;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.Pal; import mindustry.graphics.Pal;
@@ -36,150 +41,111 @@ import static UnitInfo.SVars.modUiScale;
import static arc.Core.*; import static arc.Core.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class UnitDisplay extends Table { public class UnitDisplay extends WindowTable implements Updatable {
static float weaponScrollPos;
static Seq<Element> bars = new Seq<>();
static Seq<Color> lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear); static Seq<Color> lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear);
static final Rect scissor = new Rect(); static final Rect scissor = new Rect();
public UnitDisplay() { public UnitDisplay() {
fillParent = true; super("Unit Display", Icon.units, t -> {});
visibility = () -> 0 == SVars.hud.uiIndex; }
left().defaults().width(Scl.scl(modUiScale) * 35 * 8f).height(Scl.scl(modUiScale) * 35 * 8f); @Override
bars.clear(); public void build() {
for(int i = 0; i < 6; i++) bars.add(addBar(i)); top();
Table table1 = new Table(Tex.button, t -> { topBar();
Log.info("called");
//new UnitInfoDisplay().marginBottom(80f);
table(Styles.black8, t -> {
t.table(Tex.underline2, tt -> { t.table(Tex.underline2, tt -> {
tt.setWidth(Scl.scl(modUiScale) * 35 * 8f); tt.stack(
Stack stack = new Stack(){{ new Table(ttt -> {
add(new Table(ttt -> {
Prov<TextureRegionDrawable> reg = () -> { Prov<TextureRegionDrawable> reg = () -> {
TextureRegion region = clear; TextureRegion region = clear;
if(getTarget() instanceof Unit u && u.type != null) region = u.type.uiIcon; Teamc target = getTarget();
else if(getTarget() instanceof Building b) { if (target instanceof Unit u && u.type != null) region = u.type.uiIcon;
if(getTarget() instanceof ConstructBlock.ConstructBuild cb) region = cb.current.uiIcon; else if (target instanceof Building b) {
else if(b.block != null) region = b.block.uiIcon; if (target instanceof ConstructBlock.ConstructBuild cb)
region = cb.current.uiIcon;
else if (b.block != null) region = b.block.uiIcon;
} }
return new TextureRegionDrawable(region); return new TextureRegionDrawable(region);
}; };
Drawable img = reg.get(); Drawable img = reg.get();
ImageButton imagebt = new ImageButton(img, img); ImageButton imagebt = new ImageButton(img, img);
imagebt.hovered(()->{ imagebt.hovered(() -> {
Time.run(60*2, ()->{ Time.run(60 * 2, () -> {
if(imagebt.isOver()) lockTarget(); if (imagebt.isOver()) lockTarget();
}); });
}); });
imagebt.clicked(()->{ imagebt.clicked(() -> {
if(getTarget() instanceof Unit u && u.type != null) ui.content.show(u.type); Teamc target = getTarget();
else if(getTarget() instanceof Building b && b.block != null) ui.content.show(b.block); 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) -> { 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.getStyle().imageDown = reg.get().tint(Tmp.c1.mul(Color.darkGray));
i.layout(); i.layout();
}).size(Scl.scl(modUiScale) * 4 * 8f); }).size(4 * 8f);
})); }),
new Table(ttt -> {
add(new Table(ttt -> {
ttt.stack( ttt.stack(
new Table(temp -> { new Table(temp -> {
temp.image(new ScaledNinePatchDrawable(new NinePatch(Icon.defenseSmall.getRegion()), modUiScale)); temp.image(new ScaledNinePatchDrawable(new NinePatch(Icon.defenseSmall.getRegion()), 1));
temp.visibility = () -> getTarget() instanceof Unit; temp.visibility = () -> getTarget() instanceof Unit;
}), }),
new Table(temp -> { new Table(temp -> {
Label label = new Label(() -> (getTarget() instanceof Unit u && u.type != null ? (int) u.type.armor + "" : "")); Label label = new Label(() -> (getTarget() instanceof Unit u && u.type != null ? (int) u.type.armor + "" : ""));
label.setColor(Pal.surge); label.setColor(Pal.surge);
label.setFontScale(Scl.scl(modUiScale) * 0.5f);
temp.add(label).center(); temp.add(label).center();
temp.pack(); temp.pack();
}) })
).padLeft(Scl.scl(modUiScale) * 2 * 8f).padBottom(Scl.scl(modUiScale) * 2 * 8f); ).padLeft(2 * 8f).padBottom(2 * 8f);
})); })
}}; );
Label label = new Label(() -> { tt.label(() -> {
String name = ""; 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; name = u.type.localizedName;
if(getTarget() instanceof Building b && b.block != null) { if (target instanceof Building b && b.block != null) {
if(getTarget() instanceof ConstructBlock.ConstructBuild cb) name = cb.current.localizedName; if (target instanceof ConstructBlock.ConstructBuild cb)
name = cb.current.localizedName;
else name = b.block.localizedName; else name = b.block.localizedName;
} }
return "[accent]" + (name.length() > 13 ? name.substring(0, 13) + "..." : name) + "[]"; return "[accent]" + (name.length() > 13 ? name.substring(0, 13) + "..." : name) + "[]";
}); });
label.setFontScale(Scl.scl(modUiScale) * 0.75f);
tt.top(); tt.addListener(new Tooltip(to -> {
tt.add(stack);
tt.add(label);
tt.addListener(new Tooltip(tool -> {
tool.background(Tex.button).table(to -> {
Teamc target = getTarget(); Teamc target = getTarget();
to.background(Styles.black6);
to.table(Tex.underline2, tool2 -> { to.table(Tex.underline2, tool2 -> {
Label targetName = new Label(()->{ tool2.label(() -> {
if(target instanceof Unit u) return u.type.localizedName; if (target instanceof Unit u) return u.type.localizedName;
else if(target instanceof Building b) return b.block.localizedName; else if (target instanceof Building b) return b.block.localizedName;
else return ""; else return "";
}); });
targetName.setFontScale(Scl.scl(modUiScale));
tool2.add(targetName);
}).row(); }).row();
to.label(() -> target instanceof Unit u && u.isPlayer() ? u.getPlayer().name() : "AI").row();
Label ownerName = new Label(()->target instanceof Unit u && u.isPlayer() ? u.getPlayer().name() : "AI"); to.label(() -> target == null
ownerName.setFontScale(Scl.scl(modUiScale)); ? "(" + 0 + ", " + 0 + ")"
to.add(ownerName).row(); : "(" + Strings.fixed(target.x() / tilesize, 2) + ", " + Strings.fixed(target.y() / tilesize, 2) + ")").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)));
});
})); }));
tt.update(() -> tt.setBackground(((NinePatchDrawable)Tex.underline2).tint(getTarget().isNull() ? Color.gray : getTarget().team().color))); //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(); 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());
tt.add(new WeaponDisplay()); }).top().right().grow();
}).left()).get(); resizeButton();
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();
}
});
} }
public static Teamc getTarget() { public static Teamc getTarget() {
@@ -191,9 +157,41 @@ public class UnitDisplay extends Table {
SVars.hud.lockedTarget = SVars.hud.locked ? getTarget() : null; 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() { public void setEvent() {
if((input.keyDown(KeyCode.shiftRight) || input.keyDown(KeyCode.shiftLeft))) { 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)) 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,21 +246,16 @@ public class UnitDisplay extends Table {
return region; return region;
} }
public Element addBar(int i){ public void addBar(Table table, int i){
return new Stack(){{ table.add(new SBar(
add(new Table(t -> {
t.add(new SBar(
() -> BarInfo.strings.get(i), () -> BarInfo.strings.get(i),
() -> { () -> {
if (BarInfo.colors.get(i) != Color.clear) lastColors.set(i, BarInfo.colors.get(i)); if (BarInfo.colors.get(i) != Color.clear) lastColors.set(i, BarInfo.colors.get(i));
return lastColors.get(i); return lastColors.get(i);
}, },
() -> BarInfo.numbers.get(i) () -> BarInfo.numbers.get(i)
)).width(Scl.scl(modUiScale) * 24 * 8f).height(Scl.scl(modUiScale) * 4 * 8f).growX().left(); )).height(4 * 8f).growX().left();
})); table.add(new Image(){
add(new Table(t -> {
t.right();
t.add(new Image(){
@Override @Override
public void draw() { public void draw() {
validate(); validate();
@@ -290,9 +283,7 @@ public class UnitDisplay extends Table {
} }
Draw.reset(); Draw.reset();
} }
}).size(iconMed * Scl.scl(modUiScale) * 0.75f); }).size(iconMed * 0.75f).left();
}));
}};
} }
@@ -388,7 +379,7 @@ public class UnitDisplay extends Table {
t.clear(); t.clear();
if(applied != null){ if(applied != null){
for(StatusEffect effect : content.statusEffects()){ for(StatusEffect effect : Vars.content.statusEffects()){
if(applied.get(effect.id) && !effect.isHidden()){ if(applied.get(effect.id) && !effect.isHidden()){
t.image(effect.uiIcon).size(iconSmall).get() t.image(effect.uiIcon).size(iconSmall).get()
.addListener(new Tooltip(l -> l.label(() -> effect.localizedName + " [lightgray]" + UI.formatTime(st.getDuration(effect))).style(Styles.outlineLabel))); .addListener(new Tooltip(l -> l.label(() -> effect.localizedName + " [lightgray]" + UI.formatTime(st.getDuration(effect))).style(Styles.outlineLabel)));

View File

@@ -0,0 +1,5 @@
package UnitInfo.ui;
public interface Updatable {
void setEvent();
}

View File

@@ -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<Table> 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<Table> content){
this(title, icon, content, t -> t.visible(() -> false));
}
public WindowTable(String title, TextureRegionDrawable icon, Cons<Table> content, Cons<Table> 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;
}
}

View File

@@ -0,0 +1,5 @@
package UnitInfo.ui;
public class WindowTables {
public static WindowTable unitTable = new UnitDisplay();
}