debugUi: replace TextAre with TextFlow

This commit is contained in:
bixilon 2020-06-15 17:32:07 +02:00
parent 853af59344
commit 747139cad1
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
9 changed files with 37 additions and 37 deletions

View File

@ -16,10 +16,8 @@ package de.bixilon.minosoft.debug.gui;
import de.bixilon.minosoft.debug.handling.DebugUIHandler;
import de.bixilon.minosoft.protocol.network.Connection;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
@ -64,8 +62,6 @@ public class DebugMainWindow extends Application {
stage.getIcons().add(new Image(DebugMainWindow.class.getResourceAsStream("/icons/windowIcon.png")));
stage.show();
// autoscroll for chat
((TextArea) scene.lookup("#chat")).textProperty().addListener((ChangeListener<Object>) (observableValue, o, t1) -> ((TextArea) scene.lookup("#chat")).setScrollTop(Double.MAX_VALUE));
// listen for enter in text field
TextField chatToSend = ((TextField) scene.lookup("#chatToSend"));
chatToSend.setOnKeyPressed(event -> {

View File

@ -15,7 +15,9 @@ 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 javafx.application.Platform;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import java.util.ArrayList;
import java.util.List;
@ -25,19 +27,21 @@ public class DebugUIHandler {
public void printText(TextComponent component) {
if (DebugMainWindow.isInitialized()) {
TextArea chat = ((TextArea) DebugMainWindow.getStage().getScene().lookup("#chat"));
chat.appendText((chat.getText().isBlank() ? "" : "\n") + component.getRawMessage());
TextFlow chat = ((TextFlow) DebugMainWindow.getStage().getScene().lookup("#chat"));
Platform.runLater(
() -> chat.getChildren().add(new Text(component.getRawMessage() + "\n"))
);
} else {
toPrint.add(component);
}
}
public void printTextLeft() {
TextArea chat = ((TextArea) DebugMainWindow.getStage().getScene().lookup("#chat"));
TextFlow chat = ((TextFlow) DebugMainWindow.getStage().getScene().lookup("#chat"));
if (toPrint != null) {
// append here
for (TextComponent toDoComponent : toPrint) {
chat.appendText((chat.getText().isBlank() ? "" : "\n") + toDoComponent.getRawMessage());
chat.getChildren().add(new Text(toDoComponent.getRawMessage() + "\n"));
}
toPrint = null;
}

View File

@ -26,7 +26,7 @@ public class DebugUIPacketHandler extends PacketHandler {
@Override
public void handle(PacketChatMessage pkg) {
window.getUIHandler().printText(pkg.getChatComponent());
window.getUIHandler().printText(pkg.getTextComponent());
}
}

View File

@ -34,7 +34,6 @@ public class TextComponent {
this.json = json;
}
//ToDo
public String getRawMessage() {
if (json.has("text") && json.getString("text").length() != 0) {
return json.getString("text");
@ -187,9 +186,6 @@ public class TextComponent {
}
public String getPrefix() {
if (prefix == null) {
return color.getPrefix();
}
return prefix;
}

View File

@ -25,7 +25,7 @@ public class PacketLoginDisconnect implements ClientboundPacket {
@Override
public void read(InPacketBuffer buffer, ProtocolVersion v) {
reason = buffer.readChatComponent();
reason = buffer.readTextComponent();
}
@Override

View File

@ -28,7 +28,7 @@ public class PacketChatMessage implements ClientboundPacket {
public void read(InPacketBuffer buffer, ProtocolVersion v) {
switch (v) {
case VERSION_1_7_10:
c = buffer.readChatComponent();
c = buffer.readTextComponent();
break;
}
}
@ -38,7 +38,7 @@ public class PacketChatMessage implements ClientboundPacket {
Log.game(String.format("[CHAT] %s", c.getColoredMessage()));
}
public TextComponent getChatComponent() {
public TextComponent getTextComponent() {
return c;
}

View File

@ -28,7 +28,7 @@ public class PacketDisconnect implements ClientboundPacket {
public void read(InPacketBuffer buffer, ProtocolVersion v) {
switch (v) {
case VERSION_1_7_10:
reason = buffer.readChatComponent();
reason = buffer.readTextComponent();
break;
}
}

View File

@ -13,15 +13,15 @@
package de.bixilon.minosoft.protocol.protocol;
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
import de.bixilon.minosoft.game.datatypes.TextComponent;
import de.bixilon.minosoft.game.datatypes.Direction;
import de.bixilon.minosoft.game.datatypes.Slot;
import de.bixilon.minosoft.game.datatypes.TextComponent;
import de.bixilon.minosoft.game.datatypes.entities.Pose;
import de.bixilon.minosoft.game.datatypes.particle.BlockParticle;
import de.bixilon.minosoft.game.datatypes.particle.OtherParticles;
import de.bixilon.minosoft.game.datatypes.particle.Particle;
import de.bixilon.minosoft.game.datatypes.particle.Particles;
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
import de.bixilon.minosoft.nbt.tag.CompoundTag;
import de.bixilon.minosoft.nbt.tag.TagTypes;
import de.bixilon.minosoft.util.Util;
@ -187,7 +187,7 @@ public class InByteBuffer {
return "dataLen: " + bytes.length + "; pos: " + pos;
}
public TextComponent readChatComponent() {
public TextComponent readTextComponent() {
return new TextComponent(readString());
}

View File

@ -1,23 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.TextFlow?>
<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="112.0" layoutY="85.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
<content>
<TextArea id="chat" editable="false" maxHeight="-Infinity" maxWidth="-Infinity"
wrapText="true"/>
</content>
</ScrollPane>
<TextField id="chatToSend" layoutX="112.0" layoutY="358.0" prefHeight="28.0" prefWidth="520.0"
promptText="&lt;Enter Chat Message&gt;" AnchorPane.bottomAnchor="0.0"
AnchorPane.rightAnchor="0.0"/>
</children>
</AnchorPane>
</children>
<AnchorPane prefHeight="666.0" prefWidth="998.0" VBox.vgrow="ALWAYS">
<TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Tab text="Chat">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<ScrollPane layoutX="441.0" layoutY="184.0" AnchorPane.bottomAnchor="28.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<TextFlow id="chat" prefWidth="635.0"/>
</content>
</ScrollPane>
<TextField id="chatToSend" promptText="&lt;Enter Chat Message&gt;" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="339.0"/>
</AnchorPane>
</Tab>
</TabPane>
</AnchorPane>
</VBox>