mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
fix ui bug: only show connecting after click on cell
This commit is contained in:
parent
37a9b7b843
commit
ccccc9cefe
@ -111,16 +111,15 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
this.root.setVisible(server != null || !empty);
|
||||
this.hBox.setVisible(server != null || !empty);
|
||||
if (empty) {
|
||||
resetCell();
|
||||
return;
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
resetCell();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.server != server) {
|
||||
resetCell();
|
||||
}
|
||||
server.setCell(this);
|
||||
|
||||
this.server = server;
|
||||
@ -140,7 +139,8 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
if (server.getLastPing() == null) {
|
||||
server.ping();
|
||||
}
|
||||
server.getLastPing().registerEvent(new EventInvokerCallback<ServerListStatusArriveEvent>(ServerListStatusArriveEvent.class, event -> Platform.runLater(() -> {
|
||||
|
||||
server.getLastPing().registerEvent(new EventInvokerCallback<ServerListStatusArriveEvent>(event -> Platform.runLater(() -> {
|
||||
ServerListPing ping = event.getServerListPing();
|
||||
if (server != this.server) {
|
||||
// cell does not contains us anymore
|
||||
@ -201,7 +201,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
setErrorMotd(String.format("%s: %s", server.getLastPing().getLastConnectionException().getClass().getCanonicalName(), server.getLastPing().getLastConnectionException().getMessage()));
|
||||
}
|
||||
})));
|
||||
server.getLastPing().registerEvent(new EventInvokerCallback<ServerListPongEvent>(ServerListPongEvent.class, event -> Platform.runLater(() -> {
|
||||
server.getLastPing().registerEvent(new EventInvokerCallback<ServerListPongEvent>(event -> Platform.runLater(() -> {
|
||||
this.pingField.setText(String.format("%dms", event.getLatency()));
|
||||
switch (PingBars.byPing(event.getLatency())) {
|
||||
case BARS_5 -> this.pingField.getStyleClass().add("ping-5-bars");
|
||||
@ -299,7 +299,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
// ToDo: show progress dialog
|
||||
|
||||
connection.connect(this.server.getLastPing().getAddress(), version, new CountUpAndDownLatch(1));
|
||||
connection.registerEvent(new EventInvokerCallback<>(ConnectionStateChangeEvent.class, this::handleConnectionCallback));
|
||||
connection.registerEvent(new EventInvokerCallback<>(this::handleConnectionCallback));
|
||||
this.server.addConnection(connection);
|
||||
}, "ConnectThread").start();
|
||||
|
||||
|
@ -83,7 +83,7 @@ public class SessionListCell extends ListCell<Connection> implements Initializab
|
||||
}
|
||||
setStyle(null);
|
||||
this.connection = connection;
|
||||
connection.registerEvent(new EventInvokerCallback<>(ConnectionStateChangeEvent.class, this::handleConnectionCallback));
|
||||
connection.registerEvent(new EventInvokerCallback<>(this::handleConnectionCallback));
|
||||
this.connectionId.setText(String.format("#%d", connection.getConnectionId()));
|
||||
this.account.setText(connection.getPlayer().getAccount().getUsername());
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class EventInvokerCallback<V extends ConnectionEvent> extends EventInvoke
|
||||
}
|
||||
|
||||
// if you need instant fireing support
|
||||
public EventInvokerCallback(Class<? extends ConnectionEvent> eventType, InvokerCallback<V> callback) {
|
||||
public EventInvokerCallback(InvokerCallback<V> callback) {
|
||||
this(false, callback);
|
||||
}
|
||||
|
||||
|
@ -390,21 +390,24 @@ public class Connection {
|
||||
this.desiredVersionNumber = desiredVersionNumber;
|
||||
}
|
||||
|
||||
public void unregisterEvent(EventInvoker method) {
|
||||
this.eventListeners.remove(method);
|
||||
|
||||
}
|
||||
|
||||
public void registerEvent(EventInvoker method) {
|
||||
this.eventListeners.add(method);
|
||||
if (method.getEventType() == ServerListStatusArriveEvent.class) {
|
||||
if (getConnectionState() == ConnectionStates.FAILED || getConnectionState() == ConnectionStates.FAILED_NO_RETRY || this.lastPing != null) {
|
||||
if (method.getEventType().isAssignableFrom(ServerListStatusArriveEvent.class) && wasPingDone()) {
|
||||
// ping done
|
||||
method.invoke(new ServerListStatusArriveEvent(this, this.lastPing));
|
||||
}
|
||||
} else if (method.getEventType() == ServerListPongEvent.class) {
|
||||
if (getConnectionState() == ConnectionStates.FAILED || getConnectionState() == ConnectionStates.FAILED_NO_RETRY || this.lastPing != null) {
|
||||
// ping done
|
||||
if (this.pong != null) {
|
||||
} else if (method.getEventType().isAssignableFrom(ServerListPongEvent.class) && wasPingDone() && this.pong != null) {
|
||||
method.invoke(this.pong);
|
||||
} else {
|
||||
this.eventListeners.add(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean wasPingDone() {
|
||||
return getConnectionState() == ConnectionStates.FAILED || getConnectionState() == ConnectionStates.FAILED_NO_RETRY || this.lastPing != null;
|
||||
}
|
||||
|
||||
public Throwable getLastConnectionException() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user