mooore stuff
Some checks failed
Linux arm64 / Build (push) Failing after 5m5s

This commit is contained in:
2025-01-26 13:46:23 +01:00
parent caf7011f08
commit e51cc23459
20 changed files with 395 additions and 65 deletions

View File

@@ -12,7 +12,7 @@ public abstract class BaseView {
public abstract void render();
public void onKill() {}
public void cleanResources() {}
public void closeMenu() {
this.stateMachine.popState();

View 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();
}
}
}

View File

@@ -22,7 +22,7 @@ public class MultiMenu extends BaseView {
ImGui.inputInt("Port", port);
if (ImGui.button("Créer")) {
try {
this.stateMachine.pushState(new MultiPlayerView(stateMachine, (short) port.get()));
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, (short) port.get()));
} catch (IOException e) {
e.printStackTrace();
}
@@ -37,7 +37,7 @@ public class MultiMenu extends BaseView {
ImGui.inputInt("Port", port);
if (ImGui.button("Rejoindre")) {
try {
this.stateMachine.pushState(new MultiPlayerView(stateMachine, address.get(), (short) port.get()));
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, address.get(), (short) port.get()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

View File

@@ -1,53 +1,28 @@
package gui.menu;
import java.io.IOException;
import java.net.UnknownHostException;
import imgui.ImGui;
import network.client.Client;
import network.server.Server;
public class MultiPlayerView extends BaseView {
private final Client client;
private Client client;
private Server server;
/**
* Client
*
* @param stateMachine
* @param address
* @param port
* @throws IOException
* @throws UnknownHostException
*/
public MultiPlayerView(StateMachine stateMachine, String address, short port)
throws UnknownHostException, IOException {
public MultiPlayerView(StateMachine stateMachine, Client client) {
super(stateMachine);
this.client = new Client(address, port);
}
/**
* Server
*
* @param stateMachine
* @param port
* @throws IOException
*/
public MultiPlayerView(StateMachine stateMachine, short port) throws IOException {
super(stateMachine);
this.server = new Server(port);
this.client = new Client("localhost", port);
this.client = client;
this.client.onDisconnect.connect(this::onDisconnect);
}
@Override
public void onKill() {
if (this.server != null) {
this.server.stop();
}
if (this.client != null) {
this.client.stop();
}
public void closeMenu() {
this.client.forceDisconnect();
super.closeMenu();
}
public void onDisconnect() {
// System.out.println("ohohohohohohoho");
this.stateMachine.popState();
this.client.onDisconnect.clear();
}
@Override

View File

@@ -17,7 +17,7 @@ public class StateMachine {
public void clear() {
for (BaseView view : menus) {
view.onKill();
view.cleanResources();
}
menus.clear();
}
@@ -27,13 +27,13 @@ public class StateMachine {
}
public void popState() {
menus.get(menus.size() - 1).onKill();
menus.getLast().cleanResources();
menus.pop();
}
private void checkEscape() {
if (ImGui.isKeyPressed(ImGuiKey.Escape) && menus.size() > 1) {
popState();
menus.getLast().closeMenu();
}
}