Launcher: fix connected state

This commit is contained in:
Bixilon 2020-12-11 17:27:12 +01:00
parent ac0eb4f2f1
commit 2bee414802
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 20 additions and 15 deletions

View File

@ -127,7 +127,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
}
faviconField.setImage(favicon);
if (server.isConnected()) {
setStyle("-fx-background-color: darkseagreen;");
getStyleClass().add("list-cell-connected");
optionsSessions.setDisable(false);
} else {
optionsSessions.setDisable(true);
@ -144,13 +144,13 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
resetCell();
if (server.isConnected()) {
setStyle("-fx-background-color: darkseagreen;");
getStyleClass().add("list-cell-connected");
}
if (ping == null) {
// Offline
playersField.setText("");
versionField.setText(LocaleManager.translate(Strings.OFFLINE));
versionField.setStyle("-fx-text-fill: red;");
versionField.getStyleClass().add("version-error");
setErrorMotd(String.format("%s", server.getLastPing().getLastConnectionException()));
optionsConnect.setDisable(true);
canConnect = false;
@ -208,11 +208,13 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
private void resetCell() {
// clear all cells
setStyle(null);
getStyleClass().remove("list-cell-connected");
motdField.getChildren().clear();
brandField.setText("");
brandField.setTooltip(null);
motdField.setStyle(null);
versionField.setText(LocaleManager.translate(Strings.CONNECTING));
versionField.getStyleClass().remove("version-error");
versionField.setStyle(null);
playersField.setText("");
optionsConnect.setDisable(true);
@ -273,7 +275,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
}
optionsConnect.setDisable(true);
connection.connect(server.getLastPing().getAddress(), version);
connection.registerEvent(new EventInvokerCallback<>(this::handleConnectionCallback));
connection.registerEvent(new EventInvokerCallback<>(ConnectionStateChangeEvent.class, this::handleConnectionCallback));
server.addConnection(connection);
}
@ -293,16 +295,15 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
// maybe we got disconnected
if (!server.isConnected()) {
setStyle(null);
getStyleClass().remove("list-cell-connected");
optionsSessions.setDisable(true);
optionsConnect.setDisable(false);
return;
}
return;
}
if (Minosoft.getSelectedAccount() != connection.getPlayer().getAccount()) {
optionsConnect.setDisable(false);
}
setStyle("-fx-background-color: darkseagreen;");
optionsConnect.setDisable(Minosoft.getSelectedAccount() == connection.getPlayer().getAccount());
getStyleClass().add("list-cell-connected");
optionsSessions.setDisable(false);
});
}

View File

@ -83,7 +83,7 @@ public class SessionListCell extends ListCell<Connection> implements Initializab
}
setStyle(null);
this.connection = connection;
connection.registerEvent(new EventInvokerCallback<>(this::handleConnectionCallback));
connection.registerEvent(new EventInvokerCallback<>(ConnectionStateChangeEvent.class, this::handleConnectionCallback));
connectionId.setText(String.format("#%d", connection.getConnectionId()));
account.setText(connection.getPlayer().getAccount().getPlayerName());
}

View File

@ -33,10 +33,6 @@ public class EventInvokerCallback<V extends ConnectionEvent> extends EventInvoke
this.eventType = eventType; // ToDo: how to get the class of V? seems to be impossible
}
public EventInvokerCallback(InvokerCallback<V> callback) {
this(false, callback);
}
@SuppressWarnings("unchecked")
public void invoke(ConnectionEvent event) {
if (eventType != event.getClass()) {

View File

@ -104,7 +104,7 @@
}
.menu-item:disabled {
-fx-opacity: 80%;
-fx-opacity: 60%;
}
.menu-button {
@ -165,3 +165,11 @@
.list-view {
-fx-background-color: -secondary-color;
}
.version-error {
-fx-text-fill: red;
}
.list-cell-connected {
-fx-background-color: darkseagreen;
}