From e7db1dfbfef8e084d88642d9dfcbb7b0c57c47b2 Mon Sep 17 00:00:00 2001 From: sharlottes Date: Wed, 13 Apr 2022 01:12:44 +0900 Subject: [PATCH] command window --- src/UnitInfo/ui/HUDFragment.java | 4 +- src/UnitInfo/ui/windows/CommandDisplay.java | 64 +++++++++++++++++++++ src/UnitInfo/ui/windows/WindowTables.java | 3 +- 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/UnitInfo/ui/windows/CommandDisplay.java diff --git a/src/UnitInfo/ui/HUDFragment.java b/src/UnitInfo/ui/HUDFragment.java index 97d6d5a..461eb4a 100644 --- a/src/UnitInfo/ui/HUDFragment.java +++ b/src/UnitInfo/ui/HUDFragment.java @@ -18,7 +18,8 @@ public class HUDFragment extends Fragment{ unitTable, waveTable, coreTable, - playerTable + playerTable, + commandTable )).visible(TaskbarTable.visibility); // windows (totally not a copyright violation) @@ -26,6 +27,7 @@ public class HUDFragment extends Fragment{ t.add(waveTable).size(250f).visible(false); t.add(coreTable).size(250f).visible(false); t.add(playerTable).size(250f).visible(false); + t.add(commandTable).size(250f).visible(false); t.update(()->{ for (Element child : t.getChildren()) { diff --git a/src/UnitInfo/ui/windows/CommandDisplay.java b/src/UnitInfo/ui/windows/CommandDisplay.java new file mode 100644 index 0000000..627f4d4 --- /dev/null +++ b/src/UnitInfo/ui/windows/CommandDisplay.java @@ -0,0 +1,64 @@ +package UnitInfo.ui.windows; + +import UnitInfo.ui.OverScrollPane; +import arc.Core; +import arc.math.geom.Vec2; +import arc.scene.ui.TextField; +import arc.scene.ui.layout.Table; +import arc.scene.utils.Elem; +import arc.struct.Seq; +import arc.util.CommandHandler; +import mindustry.Vars; +import mindustry.gen.Icon; +import mindustry.graphics.Pal; +import mindustry.ui.Styles; + +public class CommandDisplay extends WindowTable { + Vec2 scrollPos = new Vec2(0, 0); + + public CommandDisplay() { + super("Command Display", Icon.commandRally, t -> { + }); + } + + @Override + public void build() { + scrollPos = new Vec2(0, 0); + top(); + topBar(); + + table(Styles.black8, table -> { + table.add(new OverScrollPane(rebuild(), Styles.nonePane, scrollPos).disableScroll(true, false)).grow().name("player-pane"); + }).top().right().grow().get().parent = null; + + resizeButton(); + } + + public Table rebuild() { + return new Table(table -> { + for(CommandHandler.Command cmd : Vars.netServer.clientCommands.getCommandList()) { + table.table(cmdtable-> { + Seq fields = new Seq<>(); + cmdtable.table(body->{ + body.left(); + body.table(main->{ + main.add(cmd.text); + for(CommandHandler.CommandParam param : cmd.params) { + TextField field = main.field(null, f->{}).get(); + field.setMessageText(param.name); + fields.add(field); + } + }).left().row(); + body.add(cmd.description).color(Pal.gray).left().row(); + }).minWidth(400f).left(); + cmdtable.button(Icon.play, ()->{ + final String[] params = {""}; + fields.forEach(f-> params[0] +=" "+f.getText()); + Vars.netServer.clientCommands.handleMessage(Vars.netServer.clientCommands.getPrefix()+cmd.text+params[0], Vars.player); + }); + }).row(); + table.image().height(4f).color(Pal.gray).growX().row(); + } + }); + } +} \ No newline at end of file diff --git a/src/UnitInfo/ui/windows/WindowTables.java b/src/UnitInfo/ui/windows/WindowTables.java index e17f82c..0f6af6a 100644 --- a/src/UnitInfo/ui/windows/WindowTables.java +++ b/src/UnitInfo/ui/windows/WindowTables.java @@ -2,12 +2,13 @@ package UnitInfo.ui.windows; public class WindowTables { public static WindowTable - unitTable, waveTable, coreTable, playerTable; + unitTable, waveTable, coreTable, playerTable, commandTable; public static void init() { unitTable = new UnitDisplay(); waveTable = new WaveDisplay(); coreTable = new CoreDisplay(); playerTable = new PlayerDisplay(); + commandTable = new CommandDisplay(); } }