This commit is contained in:
@@ -14,12 +14,12 @@ public class ConnexionStatusView extends BaseView {
|
||||
|
||||
private String displayText = "Connecting ...";
|
||||
|
||||
public ConnexionStatusView(StateMachine stateMachine, String address, short port)
|
||||
public ConnexionStatusView(StateMachine stateMachine, String pseudo, String address, short port)
|
||||
throws UnknownHostException, IOException {
|
||||
super(stateMachine);
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
this.client = new Client(address, port);
|
||||
this.client = new Client(pseudo, address, port);
|
||||
bindListeners();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -29,12 +29,13 @@ public class ConnexionStatusView extends BaseView {
|
||||
t.start();
|
||||
}
|
||||
|
||||
public ConnexionStatusView(StateMachine stateMachine, short port) throws UnknownHostException, IOException {
|
||||
public ConnexionStatusView(StateMachine stateMachine, String pseudo, short port)
|
||||
throws UnknownHostException, IOException {
|
||||
super(stateMachine);
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
this.server = new Server(port);
|
||||
this.client = new Client("localhost", port);
|
||||
this.client = new Client(pseudo, "localhost", port);
|
||||
bindListeners();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package gui.menu;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import imgui.ImGui;
|
||||
import imgui.ImVec2;
|
||||
@@ -11,6 +12,7 @@ public class MultiMenu extends BaseView {
|
||||
|
||||
private final ImInt port = new ImInt(25565);
|
||||
private final ImString address = new ImString("localhost");
|
||||
private final ImString pseudo = new ImString("Joueur" + new Random().nextInt());
|
||||
|
||||
public MultiMenu(StateMachine stateMachine) {
|
||||
super(stateMachine);
|
||||
@@ -22,9 +24,10 @@ public class MultiMenu extends BaseView {
|
||||
ImGui.beginChild("##CreateGame", new ImVec2(displaySize.x / 2.0f, displaySize.y * 8.0f / 9.0f));
|
||||
if (ImGui.inputInt("Port", port))
|
||||
port.set(Math.clamp(port.get(), 1, 65535));
|
||||
ImGui.inputText("Pseudo", pseudo);
|
||||
if (ImGui.button("Créer")) {
|
||||
try {
|
||||
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, (short) port.get()));
|
||||
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, pseudo.get(), (short) port.get()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -38,6 +41,7 @@ public class MultiMenu extends BaseView {
|
||||
ImGui.inputText("Adresse", address);
|
||||
if (ImGui.inputInt("Port", port))
|
||||
port.set(Math.clamp(port.get(), 1, 65535));
|
||||
ImGui.inputText("Pseudo", pseudo);
|
||||
if (ImGui.button("Rejoindre")) {
|
||||
try {
|
||||
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, address.get(), (short) port.get()));
|
||||
|
||||
Reference in New Issue
Block a user