mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -04:00
Launcher: serverList: color green, when connected
This commit is contained in:
parent
1910cba677
commit
72a0557a59
@ -18,7 +18,6 @@ import de.bixilon.minosoft.game.datatypes.objectLoader.versions.Versions;
|
|||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.util.DNSUtil;
|
import de.bixilon.minosoft.util.DNSUtil;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
@ -41,7 +40,7 @@ public class MainWindow implements Initializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void addServer(ActionEvent e) {
|
public void addServer() {
|
||||||
Dialog<Pair<String, String>> dialog = new Dialog<>();
|
Dialog<Pair<String, String>> dialog = new Dialog<>();
|
||||||
dialog.setTitle("Add server");
|
dialog.setTitle("Add server");
|
||||||
dialog.setHeaderText("Enter the details of the server");
|
dialog.setHeaderText("Enter the details of the server");
|
||||||
@ -92,7 +91,7 @@ public class MainWindow implements Initializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void quit(ActionEvent e) {
|
public void quit() {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
|||||||
@FXML
|
@FXML
|
||||||
private AnchorPane root;
|
private AnchorPane root;
|
||||||
private Server server;
|
private Server server;
|
||||||
|
boolean canConnect = false;
|
||||||
|
|
||||||
public static ServerListCell newInstance() {
|
public static ServerListCell newInstance() {
|
||||||
FXMLLoader loader = new FXMLLoader(ServerListCell.class.getResource("/layout/cells/server.fxml"));
|
FXMLLoader loader = new FXMLLoader(ServerListCell.class.getResource("/layout/cells/server.fxml"));
|
||||||
@ -99,10 +100,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
|||||||
favicon = GUITools.logo;
|
favicon = GUITools.logo;
|
||||||
}
|
}
|
||||||
icon.setImage(favicon);
|
icon.setImage(favicon);
|
||||||
optionsConnect.setOnAction(e -> {
|
optionsConnect.setOnAction(e -> connect());
|
||||||
Connection connection = new Connection(Connection.lastConnectionId++, server.getAddress(), new Player(Minosoft.accountList.get(0)));
|
|
||||||
connection.resolve(ConnectionReasons.CONNECT, server.getDesiredVersion());
|
|
||||||
});
|
|
||||||
optionsEdit.setOnAction(e -> edit());
|
optionsEdit.setOnAction(e -> edit());
|
||||||
optionsDelete.setOnAction(e -> delete());
|
optionsDelete.setOnAction(e -> delete());
|
||||||
|
|
||||||
@ -113,6 +111,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
|||||||
players.setText("");
|
players.setText("");
|
||||||
version.setText("Offline");
|
version.setText("Offline");
|
||||||
optionsConnect.setDisable(true);
|
optionsConnect.setDisable(true);
|
||||||
|
canConnect = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
players.setText(String.format("%d/%d", ping.getPlayerOnline(), ping.getMaxPlayers()));
|
players.setText(String.format("%d/%d", ping.getPlayerOnline(), ping.getMaxPlayers()));
|
||||||
@ -126,8 +125,10 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
|||||||
version.setText(ping.getServerVersion());
|
version.setText(ping.getServerVersion());
|
||||||
version.setTextFill(Color.RED);
|
version.setTextFill(Color.RED);
|
||||||
optionsConnect.setDisable(true);
|
optionsConnect.setDisable(true);
|
||||||
|
canConnect = false;
|
||||||
} else {
|
} else {
|
||||||
version.setText(serverVersion.getVersionName());
|
version.setText(serverVersion.getVersionName());
|
||||||
|
canConnect = true;
|
||||||
}
|
}
|
||||||
motd.setText(ping.getMotd().getRawMessage());
|
motd.setText(ping.getMotd().getRawMessage());
|
||||||
if (ping.getFavicon() != null) {
|
if (ping.getFavicon() != null) {
|
||||||
@ -138,6 +139,11 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
|||||||
}));
|
}));
|
||||||
connection.resolve(ConnectionReasons.PING); // resolve dns address and ping
|
connection.resolve(ConnectionReasons.PING); // resolve dns address and ping
|
||||||
}
|
}
|
||||||
|
setOnMouseClicked(click -> {
|
||||||
|
if (click.getClickCount() == 2) {
|
||||||
|
connect();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -206,4 +212,13 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
|||||||
listView.getItems().remove(server);
|
listView.getItems().remove(server);
|
||||||
server.delete();
|
server.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void connect() {
|
||||||
|
if (!canConnect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Connection connection = new Connection(Connection.lastConnectionId++, server.getAddress(), new Player(Minosoft.accountList.get(0)));
|
||||||
|
connection.resolve(ConnectionReasons.CONNECT, server.getDesiredVersion());
|
||||||
|
setStyle("-fx-background-color: darkseagreen;");
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user