From 3f414fb6df93be1ea5bca88f36f95af74b843abd Mon Sep 17 00:00:00 2001 From: bixilon Date: Sun, 14 Jun 2020 23:22:34 +0200 Subject: [PATCH] very wip debug UI --- pom.xml | 23 ++++-- .../minosoft/config/GameConfiguration.java | 3 +- .../bixilon/minosoft/debug/DebugWindow.java | 48 ++++++++++++ .../minosoft/debug/gui/DebugMainWindow.java | 76 +++++++++++++++++++ .../debug/handling/DebugUIHandler.java | 50 ++++++++++++ .../handling/DebugUIPacketHandler.java} | 19 +++-- .../game/datatypes/TextComponent.java | 1 - .../minosoft/protocol/network/Connection.java | 12 +++ src/main/resources/config/game.yml | 3 +- src/main/resources/layout/debug/main.fxml | 18 +++++ 10 files changed, 234 insertions(+), 19 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/debug/DebugWindow.java create mode 100644 src/main/java/de/bixilon/minosoft/debug/gui/DebugMainWindow.java create mode 100644 src/main/java/de/bixilon/minosoft/debug/handling/DebugUIHandler.java rename src/main/java/de/bixilon/minosoft/{gui/debug/DebugMainWindows.java => debug/handling/DebugUIPacketHandler.java} (61%) create mode 100644 src/main/resources/layout/debug/main.fxml diff --git a/pom.xml b/pom.xml index 08c0c2848..9fc71e48f 100644 --- a/pom.xml +++ b/pom.xml @@ -20,20 +20,14 @@ de.bixilon Minosoft 0.1 - - - jitpack.io - http://www.jitpack.io - - org.apache.maven.plugins maven-compiler-plugin - 11 - 11 + 14 + 14 @@ -56,6 +50,19 @@ snakeyaml 1.25 + + org.openjfx + javafx-controls + 14.0.1 + pom + + + org.openjfx + javafx-fxml + 14.0.1 + pom + + \ No newline at end of file diff --git a/src/main/java/de/bixilon/minosoft/config/GameConfiguration.java b/src/main/java/de/bixilon/minosoft/config/GameConfiguration.java index 264410225..91a95405d 100644 --- a/src/main/java/de/bixilon/minosoft/config/GameConfiguration.java +++ b/src/main/java/de/bixilon/minosoft/config/GameConfiguration.java @@ -18,7 +18,8 @@ public enum GameConfiguration implements ConfigEnum { GAME_RENDER_DISTANCE("game.render-distance"), NETWORK_FAKE_CLIENT_BRAND("network.fake-client-brand"), GENERAL_LOG_LEVEL("general.log-level"), - CLIENT_TOKEN("account.clientToken"); + CLIENT_TOKEN("account.clientToken"), + DEBUG_UI("debug.debugUi"); final String path; diff --git a/src/main/java/de/bixilon/minosoft/debug/DebugWindow.java b/src/main/java/de/bixilon/minosoft/debug/DebugWindow.java new file mode 100644 index 000000000..4e0ba9d1f --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/debug/DebugWindow.java @@ -0,0 +1,48 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.debug; + +import de.bixilon.minosoft.debug.gui.DebugMainWindow; +import de.bixilon.minosoft.debug.handling.DebugUIHandler; +import de.bixilon.minosoft.debug.handling.DebugUIPacketHandler; +import de.bixilon.minosoft.protocol.network.Connection; + +public class DebugWindow { + final Connection connection; + Thread uiThread; + DebugUIHandler handler; + + public DebugWindow(Connection connection) { + this.connection = connection; + handler = new DebugUIHandler(); + connection.addHandler(new DebugUIPacketHandler(this)); + } + + public Connection getConnection() { + return connection; + } + + public void run() { + // start gui + uiThread = new Thread(() -> { + DebugMainWindow.setHandler(handler); + DebugMainWindow.initAndShow(); + }); + uiThread.start(); + } + + public DebugUIHandler getUIHandler() { + return handler; + } +} diff --git a/src/main/java/de/bixilon/minosoft/debug/gui/DebugMainWindow.java b/src/main/java/de/bixilon/minosoft/debug/gui/DebugMainWindow.java new file mode 100644 index 000000000..b342bfb49 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/debug/gui/DebugMainWindow.java @@ -0,0 +1,76 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.debug.gui; + +import de.bixilon.minosoft.debug.handling.DebugUIHandler; +import javafx.application.Application; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.control.TextArea; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +import java.io.IOException; + +public class DebugMainWindow extends Application { + static DebugUIHandler handler; + static Stage stage; + static boolean initialized = false; + + public static void initAndShow() { + launch(); + } + + public static void setHandler(DebugUIHandler handler) { + DebugMainWindow.handler = handler; + } + + public static Stage getStage() { + return stage; + } + + public static boolean isInitialized() { + return initialized; + } + + @Override + public void start(Stage stage) throws IOException { + + VBox root = FXMLLoader.load(getClass().getResource("/layout/debug/main.fxml")); + Scene scene = new Scene(root); + stage.setScene(scene); + stage.setTitle("Minosoft DebugUI"); + stage.show(); + + // autoscroll for chat + ((TextArea) scene.lookup("#chat")).textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observableValue, Object o, Object t1) { + ((TextArea) scene.lookup("#chat")).setScrollTop(Double.MAX_VALUE); //this will scroll to the bottom + + } + }); + + + DebugMainWindow.stage = stage; + initialized = true; + handler.initializedCallback(); + + // bring to front + stage.setAlwaysOnTop(true); + stage.setAlwaysOnTop(false); + } +} diff --git a/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIHandler.java b/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIHandler.java new file mode 100644 index 000000000..996e12c8a --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIHandler.java @@ -0,0 +1,50 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.debug.handling; + +import de.bixilon.minosoft.debug.gui.DebugMainWindow; +import de.bixilon.minosoft.game.datatypes.TextComponent; +import javafx.scene.control.TextArea; + +import java.util.ArrayList; +import java.util.List; + +public class DebugUIHandler { + List toPrint = new ArrayList<>(); + + public void printText(TextComponent component) { + if (DebugMainWindow.isInitialized()) { + TextArea chat = ((TextArea) DebugMainWindow.getStage().getScene().lookup("#chat")); + chat.appendText((chat.getText().isBlank() ? "" : "\n") + component.getRawMessage()); + } else { + toPrint.add(component); + } + } + + public void printTextLeft() { + TextArea chat = ((TextArea) DebugMainWindow.getStage().getScene().lookup("#chat")); + if (toPrint != null) { + // append here + for (TextComponent toDoComponent : toPrint) { + chat.appendText((chat.getText().isBlank() ? "" : "\n") + toDoComponent.getRawMessage()); + } + toPrint = null; + } + + } + + public void initializedCallback() { + printTextLeft(); + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/debug/DebugMainWindows.java b/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIPacketHandler.java similarity index 61% rename from src/main/java/de/bixilon/minosoft/gui/debug/DebugMainWindows.java rename to src/main/java/de/bixilon/minosoft/debug/handling/DebugUIPacketHandler.java index 182362aea..11d97c7e9 100644 --- a/src/main/java/de/bixilon/minosoft/gui/debug/DebugMainWindows.java +++ b/src/main/java/de/bixilon/minosoft/debug/handling/DebugUIPacketHandler.java @@ -11,19 +11,22 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.debug; +package de.bixilon.minosoft.debug.handling; -import javafx.application.Application; -import javafx.stage.Stage; +import de.bixilon.minosoft.debug.DebugWindow; +import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketChatMessage; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; -public class DebugMainWindows extends Application { +public class DebugUIPacketHandler extends PacketHandler { + DebugWindow window; - public static void run() { - launch(); + public DebugUIPacketHandler(DebugWindow window) { + this.window = window; } @Override - public void start(Stage stage) { - + public void handle(PacketChatMessage pkg) { + window.getUIHandler().printText(pkg.getChatComponent()); } + } diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/TextComponent.java b/src/main/java/de/bixilon/minosoft/game/datatypes/TextComponent.java index 7ae1e7a4f..72220a0cd 100644 --- a/src/main/java/de/bixilon/minosoft/game/datatypes/TextComponent.java +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/TextComponent.java @@ -53,7 +53,6 @@ public class TextComponent { } buffer.append(object.getString("text")); } - buffer.append(ChatAttributes.RESET); return buffer.toString(); } return ""; diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java b/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java index 45483fd46..0c26c3f72 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java +++ b/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java @@ -13,6 +13,9 @@ package de.bixilon.minosoft.protocol.network; +import de.bixilon.minosoft.Minosoft; +import de.bixilon.minosoft.config.GameConfiguration; +import de.bixilon.minosoft.debug.DebugWindow; import de.bixilon.minosoft.game.datatypes.Player; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; @@ -40,6 +43,7 @@ public class Connection { private Player player; private ConnectionState state = ConnectionState.DISCONNECTED; private boolean onlyPing; + private DebugWindow debugWindow; public Connection(String host, int port) { this.host = host; @@ -103,6 +107,14 @@ public class Connection { case LOGIN: network.sendPacket(new PacketLoginStart(player)); break; + case PLAY: + // connected, start debug UI if enabled + if (Minosoft.getConfig().getBoolean(GameConfiguration.DEBUG_UI)) { + // nice dude, start + debugWindow = new DebugWindow(this); + debugWindow.run(); + } + break; } } diff --git a/src/main/resources/config/game.yml b/src/main/resources/config/game.yml index d0b80a778..95ee9b3db 100644 --- a/src/main/resources/config/game.yml +++ b/src/main/resources/config/game.yml @@ -18,4 +18,5 @@ account: # this will be removed soon, only for debugging (pre alpha stage): some features are not implemented yet -/- debug: host: "127.0.0.1" - port: 25565 \ No newline at end of file + port: 25565 + debugUi: true \ No newline at end of file diff --git a/src/main/resources/layout/debug/main.fxml b/src/main/resources/layout/debug/main.fxml new file mode 100644 index 000000000..08887e62e --- /dev/null +++ b/src/main/resources/layout/debug/main.fxml @@ -0,0 +1,18 @@ + + + + + + + + + + + +