This commit is contained in:
60
app/src/main/java/gui/menu/ConnexionStatusView.java
Normal file
60
app/src/main/java/gui/menu/ConnexionStatusView.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package gui.menu;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import imgui.ImGui;
|
||||
import network.client.Client;
|
||||
import network.server.Server;
|
||||
|
||||
public class ConnexionStatusView extends BaseView {
|
||||
|
||||
private Client client;
|
||||
private Server server;
|
||||
|
||||
public ConnexionStatusView(StateMachine stateMachine, String address, short port) throws UnknownHostException, IOException {
|
||||
this(stateMachine, null, new Client(address, port));
|
||||
}
|
||||
|
||||
public ConnexionStatusView(StateMachine stateMachine, short port) throws UnknownHostException, IOException {
|
||||
this(stateMachine, new Server(port), new Client("localhost", port));
|
||||
}
|
||||
|
||||
private ConnexionStatusView(StateMachine stateMachine, Server server, Client client) {
|
||||
super(stateMachine);
|
||||
this.client = client;
|
||||
this.client.onConnect.connect(this::onConnect);
|
||||
this.client.onClosed.connect(this::onLeave);
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public void onConnect() {
|
||||
// System.out.println("Connecté");
|
||||
this.stateMachine.pushState(new MultiPlayerView(stateMachine, client));
|
||||
}
|
||||
|
||||
public void onLeave() {
|
||||
// System.out.println("Quitté !");
|
||||
this.client.onDisconnect.clear();
|
||||
this.client = null;
|
||||
// on passe le menu de la connexion
|
||||
this.closeMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
ImGui.text("Connecting ...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanResources() {
|
||||
// System.out.println("Bye bye !");
|
||||
if (this.server != null) {
|
||||
this.server.stop();
|
||||
}
|
||||
if (this.client != null) {
|
||||
this.client.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user