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.debug.handling.DebugUIHandler;
import de.bixilon.minosoft.protocol.network.Connection; import de.bixilon.minosoft.protocol.network.Connection;
import javafx.application.Application; import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.input.KeyCode; 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.getIcons().add(new Image(DebugMainWindow.class.getResourceAsStream("/icons/windowIcon.png")));
stage.show(); 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 // listen for enter in text field
TextField chatToSend = ((TextField) scene.lookup("#chatToSend")); TextField chatToSend = ((TextField) scene.lookup("#chatToSend"));
chatToSend.setOnKeyPressed(event -> { 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.debug.gui.DebugMainWindow;
import de.bixilon.minosoft.game.datatypes.TextComponent; 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.ArrayList;
import java.util.List; import java.util.List;
@ -25,19 +27,21 @@ public class DebugUIHandler {
public void printText(TextComponent component) { public void printText(TextComponent component) {
if (DebugMainWindow.isInitialized()) { if (DebugMainWindow.isInitialized()) {
TextArea chat = ((TextArea) DebugMainWindow.getStage().getScene().lookup("#chat")); TextFlow chat = ((TextFlow) DebugMainWindow.getStage().getScene().lookup("#chat"));
chat.appendText((chat.getText().isBlank() ? "" : "\n") + component.getRawMessage()); Platform.runLater(
() -> chat.getChildren().add(new Text(component.getRawMessage() + "\n"))
);
} else { } else {
toPrint.add(component); toPrint.add(component);
} }
} }
public void printTextLeft() { public void printTextLeft() {
TextArea chat = ((TextArea) DebugMainWindow.getStage().getScene().lookup("#chat")); TextFlow chat = ((TextFlow) DebugMainWindow.getStage().getScene().lookup("#chat"));
if (toPrint != null) { if (toPrint != null) {
// append here // append here
for (TextComponent toDoComponent : toPrint) { for (TextComponent toDoComponent : toPrint) {
chat.appendText((chat.getText().isBlank() ? "" : "\n") + toDoComponent.getRawMessage()); chat.getChildren().add(new Text(toDoComponent.getRawMessage() + "\n"));
} }
toPrint = null; toPrint = null;
} }

View File

@ -26,7 +26,7 @@ public class DebugUIPacketHandler extends PacketHandler {
@Override @Override
public void handle(PacketChatMessage pkg) { 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; this.json = json;
} }
//ToDo
public String getRawMessage() { public String getRawMessage() {
if (json.has("text") && json.getString("text").length() != 0) { if (json.has("text") && json.getString("text").length() != 0) {
return json.getString("text"); return json.getString("text");
@ -187,9 +186,6 @@ public class TextComponent {
} }
public String getPrefix() { public String getPrefix() {
if (prefix == null) {
return color.getPrefix();
}
return prefix; return prefix;
} }

View File

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

View File

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

View File

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

View File

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

View File

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