very wip debug UI

This commit is contained in:
bixilon 2020-06-14 23:22:34 +02:00
parent 686ee386bd
commit 3f414fb6df
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
10 changed files with 234 additions and 19 deletions

23
pom.xml
View File

@ -20,20 +20,14 @@
<groupId>de.bixilon</groupId>
<artifactId>Minosoft</artifactId>
<version>0.1</version>
<repositories>
<repository>
<id>jitpack.io</id>
<url>http://www.jitpack.io</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
<source>14</source>
<target>14</target>
</configuration>
</plugin>
</plugins>
@ -56,6 +50,19 @@
<artifactId>snakeyaml</artifactId>
<version>1.25</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>14.0.1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>14.0.1</version>
<type>pom</type>
</dependency>
</dependencies>
</project>

View File

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

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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<Object>() {
@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);
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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<TextComponent> 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();
}
}

View File

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

View File

@ -53,7 +53,6 @@ public class TextComponent {
}
buffer.append(object.getString("text"));
}
buffer.append(ChatAttributes.RESET);
return buffer.toString();
}
return "";

View File

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

View File

@ -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
port: 25565
debugUi: true

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.*?>
<VBox xmlns:fx="http://javafx.com/fxml/1" prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.171">
<children>
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="666.0" prefWidth="998.0" VBox.vgrow="ALWAYS">
<children>
<ScrollPane layoutX="440.0" layoutY="186.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
<content>
<TextArea id="chat" editable="false" wrapText="true"/>
</content>
</ScrollPane>
</children>
</AnchorPane>
</children>
</VBox>