diff --git a/game/src/mainMenu/layer/MainMenuUiLayer.cpp b/game/src/mainMenu/layer/MainMenuUiLayer.cpp index 4e733f1..011419c 100644 --- a/game/src/mainMenu/layer/MainMenuUiLayer.cpp +++ b/game/src/mainMenu/layer/MainMenuUiLayer.cpp @@ -6,6 +6,7 @@ #include "imgui.h" #include "GLFW/glfw3.h" +#include "spdlog/spdlog.h" void MainMenuUiLayer::onRender() { Layer::onRender(); @@ -26,7 +27,7 @@ void MainMenuUiLayer::onRender() { const ImVec2 buttonSize(180, 40); - if (ImGui::Button("Play", buttonSize)) { + if (ImGui::Button("Neues Spiel", buttonSize)) { // z.B. State-Wechsel: game.setState(GameState::Playing); } @@ -34,12 +35,25 @@ void MainMenuUiLayer::onRender() { ImGui::Spacing(); + if (ImGui::Button("Multiplayer", buttonSize)) { + spdlog::info("Open Multiplayer Modal"); + ImGui::OpenPopup("ConnectToServer"); + } + + ImGui::Spacing(); + + ImGui::Spacing(); + if (ImGui::Button("Quit", buttonSize)) { ApplicationEvents e = QuitRequested{}; m_applicationEventBus->publish(e); } + renderConnectDialog(); + ImGui::End(); + + } void MainMenuUiLayer::onAttachImpl() { @@ -54,6 +68,37 @@ void MainMenuUiLayer::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(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) { Layer::onUpdate(deltaTime); } diff --git a/game/src/mainMenu/layer/MainMenuUiLayer.h b/game/src/mainMenu/layer/MainMenuUiLayer.h index f9d83c4..3cf7d6a 100644 --- a/game/src/mainMenu/layer/MainMenuUiLayer.h +++ b/game/src/mainMenu/layer/MainMenuUiLayer.h @@ -28,8 +28,14 @@ protected: private: engine::AssetManager& m_assetManager; std::unique_ptr backgroundImage; - 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(); };