mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-07 14:26:38 -04:00
very wip debug UI
This commit is contained in:
parent
686ee386bd
commit
3f414fb6df
23
pom.xml
23
pom.xml
@ -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>
|
@ -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;
|
||||
|
48
src/main/java/de/bixilon/minosoft/debug/DebugWindow.java
Normal file
48
src/main/java/de/bixilon/minosoft/debug/DebugWindow.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
@ -53,7 +53,6 @@ public class TextComponent {
|
||||
}
|
||||
buffer.append(object.getString("text"));
|
||||
}
|
||||
buffer.append(ChatAttributes.RESET);
|
||||
return buffer.toString();
|
||||
}
|
||||
return "";
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
18
src/main/resources/layout/debug/main.fxml
Normal file
18
src/main/resources/layout/debug/main.fxml
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user