mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -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.root.setVisible(server != null || !empty);
|
||||||
this.hBox.setVisible(server != null || !empty);
|
this.hBox.setVisible(server != null || !empty);
|
||||||
if (empty) {
|
if (empty) {
|
||||||
resetCell();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
resetCell();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this.server != server) {
|
||||||
resetCell();
|
resetCell();
|
||||||
|
}
|
||||||
server.setCell(this);
|
server.setCell(this);
|
||||||
|
|
||||||
this.server = server;
|
this.server = server;
|
||||||
@ -140,7 +139,8 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
|||||||
if (server.getLastPing() == null) {
|
if (server.getLastPing() == null) {
|
||||||
server.ping();
|
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();
|
ServerListPing ping = event.getServerListPing();
|
||||||
if (server != this.server) {
|
if (server != this.server) {
|
||||||
// cell does not contains us anymore
|
// 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()));
|
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()));
|
this.pingField.setText(String.format("%dms", event.getLatency()));
|
||||||
switch (PingBars.byPing(event.getLatency())) {
|
switch (PingBars.byPing(event.getLatency())) {
|
||||||
case BARS_5 -> this.pingField.getStyleClass().add("ping-5-bars");
|
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
|
// ToDo: show progress dialog
|
||||||
|
|
||||||
connection.connect(this.server.getLastPing().getAddress(), version, new CountUpAndDownLatch(1));
|
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);
|
this.server.addConnection(connection);
|
||||||
}, "ConnectThread").start();
|
}, "ConnectThread").start();
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class SessionListCell extends ListCell<Connection> implements Initializab
|
|||||||
}
|
}
|
||||||
setStyle(null);
|
setStyle(null);
|
||||||
this.connection = connection;
|
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.connectionId.setText(String.format("#%d", connection.getConnectionId()));
|
||||||
this.account.setText(connection.getPlayer().getAccount().getUsername());
|
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
|
// if you need instant fireing support
|
||||||
public EventInvokerCallback(Class<? extends ConnectionEvent> eventType, InvokerCallback<V> callback) {
|
public EventInvokerCallback(InvokerCallback<V> callback) {
|
||||||
this(false, callback);
|
this(false, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,21 +390,24 @@ public class Connection {
|
|||||||
this.desiredVersionNumber = desiredVersionNumber;
|
this.desiredVersionNumber = desiredVersionNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unregisterEvent(EventInvoker method) {
|
||||||
|
this.eventListeners.remove(method);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void registerEvent(EventInvoker method) {
|
public void registerEvent(EventInvoker method) {
|
||||||
this.eventListeners.add(method);
|
if (method.getEventType().isAssignableFrom(ServerListStatusArriveEvent.class) && wasPingDone()) {
|
||||||
if (method.getEventType() == ServerListStatusArriveEvent.class) {
|
|
||||||
if (getConnectionState() == ConnectionStates.FAILED || getConnectionState() == ConnectionStates.FAILED_NO_RETRY || this.lastPing != null) {
|
|
||||||
// ping done
|
// ping done
|
||||||
method.invoke(new ServerListStatusArriveEvent(this, this.lastPing));
|
method.invoke(new ServerListStatusArriveEvent(this, this.lastPing));
|
||||||
}
|
} else if (method.getEventType().isAssignableFrom(ServerListPongEvent.class) && wasPingDone() && this.pong != null) {
|
||||||
} else if (method.getEventType() == ServerListPongEvent.class) {
|
|
||||||
if (getConnectionState() == ConnectionStates.FAILED || getConnectionState() == ConnectionStates.FAILED_NO_RETRY || this.lastPing != null) {
|
|
||||||
// ping done
|
|
||||||
if (this.pong != null) {
|
|
||||||
method.invoke(this.pong);
|
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() {
|
public Throwable getLastConnectionException() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user