package gui.menu; import java.io.IOException; import java.util.Random; import imgui.ImGui; import imgui.ImVec2; import imgui.type.ImInt; import imgui.type.ImString; 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); address.resize(20); } private void renderCreate() { ImVec2 displaySize = ImGui.getIO().getDisplaySize(); 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, pseudo.get(), (short) port.get())); } catch (IOException e) { e.printStackTrace(); } } ImGui.endChild(); } private void renderJoin() { ImVec2 displaySize = ImGui.getIO().getDisplaySize(); ImGui.beginChild("##JoinGame", new ImVec2(displaySize.x / 2.0f, displaySize.y * 8.0f / 9.0f)); 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, pseudo.get(), address.get(), (short) port.get())); } catch (IOException e) { e.printStackTrace(); } } ImGui.endChild(); } @Override public void render() { renderCreate(); ImGui.sameLine(); renderJoin(); ImVec2 displaySize = ImGui.getIO().getDisplaySize(); ImVec2 buttonSize = new ImVec2(500, 70.0f); float centerX = displaySize.x / 2.0f - buttonSize.x / 2.0f; ImGui.setCursorPosX(centerX); if (ImGui.button("Retour", buttonSize)) { closeMenu(); } } }