mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 01:16:46 -04:00
TextComponents: reuse same ObservableList (JavaFX)
This commit is contained in:
parent
cad9766d51
commit
a666b0c924
@ -16,7 +16,6 @@ package de.bixilon.minosoft.data.text;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.modding.event.events.annotations.Unsafe;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.Node;
|
||||
|
||||
@ -197,10 +196,9 @@ public class BaseComponent implements ChatComponent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableList<Node> getJavaFXText() {
|
||||
ObservableList<Node> list = FXCollections.observableArrayList();
|
||||
parts.forEach((chatPart) -> list.addAll(chatPart.getJavaFXText()));
|
||||
return list;
|
||||
public ObservableList<Node> getJavaFXText(ObservableList<Node> nodes) {
|
||||
parts.forEach((chatPart) -> chatPart.getJavaFXText(nodes));
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@Unsafe
|
||||
|
@ -48,5 +48,5 @@ public interface ChatComponent {
|
||||
/**
|
||||
* @return Returns the a list of Nodes, drawable in JavaFX (TextFlow)
|
||||
*/
|
||||
ObservableList<Node> getJavaFXText();
|
||||
ObservableList<Node> getJavaFXText(ObservableList<Node> nodes);
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package de.bixilon.minosoft.data.text;
|
||||
import javafx.animation.Animation;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.paint.Color;
|
||||
@ -179,7 +178,7 @@ public class TextComponent implements ChatComponent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableList<Node> getJavaFXText() {
|
||||
public ObservableList<Node> getJavaFXText(ObservableList<Node> nodes) {
|
||||
Text text = new Text(this.text);
|
||||
if (color != null) {
|
||||
text.setFill(Color.web(color.toString()));
|
||||
@ -197,7 +196,8 @@ public class TextComponent implements ChatComponent {
|
||||
case ITALIC -> text.setStyle("-fx-font-weight: italic;");
|
||||
}
|
||||
}));
|
||||
return FXCollections.observableArrayList(text);
|
||||
nodes.add(text);
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,10 +66,10 @@ public class TranslatableComponent implements ChatComponent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableList<Node> getJavaFXText() {
|
||||
public ObservableList<Node> getJavaFXText(ObservableList<Node> nodes) {
|
||||
// ToDo fix nested base component (formatting), not just a string
|
||||
|
||||
// This is just a dirty workaround to enable formatting and coloring. Still need to do hover, click, ... stuff
|
||||
return new BaseComponent(getLegacyText()).getJavaFXText();
|
||||
return new BaseComponent(getLegacyText()).getJavaFXText(nodes);
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import de.bixilon.minosoft.protocol.ping.ForgeModInfo;
|
||||
import de.bixilon.minosoft.protocol.ping.ServerListPing;
|
||||
import de.bixilon.minosoft.util.DNSUtil;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.geometry.Insets;
|
||||
@ -173,7 +174,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
}
|
||||
serverBrand.setText(ping.getServerModInfo().getBrand());
|
||||
serverBrand.setTooltip(new Tooltip(ping.getServerModInfo().getInfo()));
|
||||
motd.getChildren().addAll(ping.getMotd().getJavaFXText());
|
||||
motd.getChildren().addAll(ping.getMotd().getJavaFXText(FXCollections.observableArrayList()));
|
||||
if (ping.getFavicon() != null) {
|
||||
icon.setImage(GUITools.getImage(ping.getFavicon()));
|
||||
if (!Arrays.equals(ping.getFavicon(), server.getFavicon())) {
|
||||
@ -405,7 +406,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
Label serverBrandLabel = new Label(lastPing.getServerBrand());
|
||||
Label playersOnlineMaxLabel = new Label(LocaleManager.translate(Strings.SERVER_INFO_SLOTS_PLAYERS_ONLINE, lastPing.getPlayerOnline(), lastPing.getMaxPlayers()));
|
||||
TextFlow motdLabel = new TextFlow();
|
||||
motdLabel.getChildren().addAll(lastPing.getMotd().getJavaFXText());
|
||||
motdLabel.getChildren().addAll(lastPing.getMotd().getJavaFXText(FXCollections.observableArrayList()));
|
||||
Label moddedBrandLabel = new Label(lastPing.getServerModInfo().getBrand());
|
||||
|
||||
grid.add(new Label(LocaleManager.translate(Strings.SERVER_INFO_REAL_SERVER_ADDRESS) + ":"), 0, ++column);
|
||||
|
Loading…
x
Reference in New Issue
Block a user