Multiplayer Connect Modal
This commit is contained in:
parent
fe9ecb1ecc
commit
19a3e55e5f
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
void MainMenuUiLayer::onRender() {
|
void MainMenuUiLayer::onRender() {
|
||||||
Layer::onRender();
|
Layer::onRender();
|
||||||
@ -26,7 +27,7 @@ void MainMenuUiLayer::onRender() {
|
|||||||
|
|
||||||
const ImVec2 buttonSize(180, 40);
|
const ImVec2 buttonSize(180, 40);
|
||||||
|
|
||||||
if (ImGui::Button("Play", buttonSize)) {
|
if (ImGui::Button("Neues Spiel", buttonSize)) {
|
||||||
// z.B. State-Wechsel: game.setState(GameState::Playing);
|
// z.B. State-Wechsel: game.setState(GameState::Playing);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,12 +35,25 @@ void MainMenuUiLayer::onRender() {
|
|||||||
|
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
|
|
||||||
|
if (ImGui::Button("Multiplayer", buttonSize)) {
|
||||||
|
spdlog::info("Open Multiplayer Modal");
|
||||||
|
ImGui::OpenPopup("ConnectToServer");
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Spacing();
|
||||||
|
|
||||||
|
ImGui::Spacing();
|
||||||
|
|
||||||
if (ImGui::Button("Quit", buttonSize)) {
|
if (ImGui::Button("Quit", buttonSize)) {
|
||||||
ApplicationEvents e = QuitRequested{};
|
ApplicationEvents e = QuitRequested{};
|
||||||
m_applicationEventBus->publish(e);
|
m_applicationEventBus->publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderConnectDialog();
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenuUiLayer::onAttachImpl() {
|
void MainMenuUiLayer::onAttachImpl() {
|
||||||
@ -54,6 +68,37 @@ void MainMenuUiLayer::onDetachImpl() {
|
|||||||
Layer::onDetachImpl();
|
Layer::onDetachImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainMenuUiLayer::renderConnectDialog() {
|
||||||
|
// Zentriert öffnen
|
||||||
|
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||||
|
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||||
|
|
||||||
|
if (ImGui::BeginPopupModal("ConnectToServer", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||||
|
ImGui::InputText("Host", m_hostBuffer, sizeof(m_hostBuffer));
|
||||||
|
ImGui::InputInt("Port", &m_port);
|
||||||
|
|
||||||
|
if (m_connectionError) {
|
||||||
|
ImGui::TextColored(ImVec4(1, 0.3f, 0.3f, 1), "%s", m_errorMessage.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Spacing();
|
||||||
|
|
||||||
|
if (ImGui::Button("Connect", ImVec2(120, 0))) {
|
||||||
|
// ApplicationEvents::ConnectRequested e{ m_hostBuffer, static_cast<uint16_t>(m_port) };
|
||||||
|
// m_appEvents.publish(e);
|
||||||
|
// Popup offen lassen bis Ergebnis feststeht, siehe unten
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
if (ImGui::Button("Cancel", ImVec2(120, 0))) {
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainMenuUiLayer::onUpdate(float deltaTime) {
|
void MainMenuUiLayer::onUpdate(float deltaTime) {
|
||||||
Layer::onUpdate(deltaTime);
|
Layer::onUpdate(deltaTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,8 +28,14 @@ protected:
|
|||||||
private:
|
private:
|
||||||
engine::AssetManager& m_assetManager;
|
engine::AssetManager& m_assetManager;
|
||||||
std::unique_ptr<engine::GUITexture> backgroundImage;
|
std::unique_ptr<engine::GUITexture> backgroundImage;
|
||||||
|
|
||||||
engine::renderer::GuiRenderer m_guiRenderer;
|
engine::renderer::GuiRenderer m_guiRenderer;
|
||||||
|
|
||||||
|
char m_hostBuffer[64] = "127.0.0.1";
|
||||||
|
int m_port = 7777;
|
||||||
|
bool m_connectionError = false;
|
||||||
|
std::string m_errorMessage;
|
||||||
|
|
||||||
|
void renderConnectDialog();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user