set default TextComponent color to white, fixes

This commit is contained in:
Bixilon 2020-11-27 13:28:34 +01:00
parent b6db5558a1
commit 25e9856d1a
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 46 additions and 13 deletions

View File

@ -157,7 +157,9 @@ public class TextComponent extends ChatComponent {
@Override
public ObservableList<Node> getJavaFXText(ObservableList<Node> nodes) {
Text text = new Text(this.text);
if (color != null) {
if (color == null) {
text.setFill(Color.WHITE);
} else {
text.setFill(Color.web(color.toString()));
}
formatting.forEach((chatFormattingCode -> {

View File

@ -207,7 +207,12 @@ public class MainWindow implements Initializable {
ServerListCell.listView.getItems().add(server1);
} else {
server1.setName(serverName);
server1.setAddress(serverAddress);
server1.setDesiredVersionId(desiredVersionId);
if (server1.getCell() != null) {
server1.getCell().setName(server1.getName());
//ToDo: version
}
}
server1.saveToConfig();
Log.info(String.format("%s and saved server (serverName=%s, serverAddress=%s, version=%d)", ((server == null) ? "Added" : "Edited"), serverName.getLegacyText(), serverAddress, desiredVersionId));

View File

@ -36,6 +36,7 @@ public class Server {
private byte[] favicon;
private Connection lastPing;
private boolean readOnly = false;
private ServerListCell cell;
public Server(int id, BaseComponent name, String address, int desiredVersion, byte[] favicon) {
this(id, name, address, desiredVersion);
@ -192,4 +193,12 @@ public class Server {
public boolean isReadOnly() {
return readOnly;
}
public ServerListCell getCell() {
return cell;
}
public void setCell(ServerListCell cell) {
this.cell = cell;
}
}

View File

@ -22,6 +22,7 @@ import de.bixilon.minosoft.data.locale.LocaleManager;
import de.bixilon.minosoft.data.locale.Strings;
import de.bixilon.minosoft.data.mappings.versions.Version;
import de.bixilon.minosoft.data.mappings.versions.Versions;
import de.bixilon.minosoft.data.text.BaseComponent;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.modding.event.EventInvokerCallback;
import de.bixilon.minosoft.modding.event.events.ConnectionStateChangeEvent;
@ -32,6 +33,7 @@ import de.bixilon.minosoft.protocol.ping.ServerListPing;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
@ -113,10 +115,11 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
if (server.equals(this.server)) {
return;
}
server.setCell(this);
resetCell();
this.server = server;
nameField.getChildren().setAll(server.getName().getJavaFXText());
setName(server.getName());
Image favicon = GUITools.getImage(server.getFavicon());
if (favicon == null) {
@ -195,6 +198,13 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
})));
}
public void setName(BaseComponent name) {
nameField.getChildren().setAll(name.getJavaFXText());
for (Node node : nameField.getChildren()) {
node.setStyle("-fx-font-size: 15pt ;");
}
}
private void resetCell() {
// clear all cells
setStyle(null);

View File

@ -333,13 +333,8 @@ public class PacketHandler {
}
public void handle(PacketEntityVelocity pkg) {
Entity entity;
if (pkg.getEntityId() == connection.getPlayer().getEntity().getEntityId()) {
// that's us!
entity = connection.getPlayer().getEntity();
} else {
entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId());
}
Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId());
if (entity == null) {
// thanks mojang
return;
@ -490,6 +485,7 @@ public class PacketHandler {
for (int i = 0; i < 4; i++) {
nbt.writeTag(String.format("Text%d", (i + 1)), new StringTag(pkg.getLines()[i].getLegacyText()));
}
// ToDo: handle sign updates
}
public void handle(PacketEntityAnimation pkg) {
@ -585,7 +581,7 @@ public class PacketHandler {
connection.fireEvent(new SingleSlotChangeEvent(connection, pkg));
if (pkg.getWindowId() == -1) {
// invalid window Id
// thanks mojang
// ToDo: what is windowId -1
return;
}
@ -639,9 +635,8 @@ public class PacketHandler {
case CREATE_UPDATE -> connection.getPlayer().getScoreboardManager().getObjective(pkg.getScoreName()).addScore(new ScoreboardScore(pkg.getItemName(), pkg.getScoreName(), pkg.getScoreValue()));
case REMOVE -> {
ScoreboardObjective objective = connection.getPlayer().getScoreboardManager().getObjective(pkg.getScoreName());
if (objective == null) {
Log.warn(String.format("Server tried to remove score witch was not created before (itemName=\"%s\", scoreName=\"%s\")!", pkg.getItemName(), pkg.getScoreName()));
} else {
if (objective != null) {
// thanks mojang
objective.removeScore(pkg.getItemName());
}
}

View File

@ -1,4 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>