UPD: Added LobbyScene

This commit is contained in:
sebastian 2026-08-06 21:34:22 +02:00
parent 6c2f580134
commit 452bf92e20
9 changed files with 118 additions and 2 deletions

View File

@ -329,6 +329,10 @@ add_executable(ColorRace
game/src/multiplayer/LudoGameClient.cpp game/src/multiplayer/LudoGameClient.cpp
game/src/multiplayer/LudoGameClient.h game/src/multiplayer/LudoGameClient.h
game/src/multiplayer/LudoNetworkEvents.h game/src/multiplayer/LudoNetworkEvents.h
game/src/multiplayer/lobby/LobbyScene.cpp
game/src/multiplayer/lobby/LobbyScene.h
game/src/multiplayer/lobby/LobbyUiLayer.cpp
game/src/multiplayer/lobby/LobbyUiLayer.h
) )
target_link_libraries(ColorRace PRIVATE target_link_libraries(ColorRace PRIVATE

View File

@ -22,6 +22,8 @@ namespace engine {
using T = std::decay_t<decltype(e)>; using T = std::decay_t<decltype(e)>;
if constexpr (std::is_same_v<T, QuitRequested>) { if constexpr (std::is_same_v<T, QuitRequested>) {
m_window->requestWindowClose(); m_window->requestWindowClose();
} else if constexpr (std::is_same_v<T, SceneSwitchRequested>) {
m_sceneManager.switchTo(e.nextScene, std::move(e.onSceneLoaded));
} }
}, event); }, event);
}); });

View File

@ -6,8 +6,15 @@
#define COLORRACE_APPLICATIONEVENTS_H #define COLORRACE_APPLICATIONEVENTS_H
#include <variant> #include <variant>
#include "layer/Scene.h"
struct QuitRequested {}; struct QuitRequested {};
struct SceneSwitchRequested {
std::unique_ptr<engine::Scene> nextScene;
std::function<void()> onSceneLoaded;
};
using ApplicationEvents = std::variant<QuitRequested>; using ApplicationEvents = std::variant<QuitRequested>;
#endif //COLORRACE_APPLICATIONEVENTS_H #endif //COLORRACE_APPLICATIONEVENTS_H

@ -1 +1 @@
Subproject commit 944f2f63e06e1d368f85c11916046312b1d0067f Subproject commit 79214c855ac1c414fe85ffe76af4e2e57b8305ec

View File

@ -6,6 +6,7 @@
#include "imgui.h" #include "imgui.h"
#include "GLFW/glfw3.h" #include "GLFW/glfw3.h"
#include "multiplayer/lobby/LobbyScene.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
void MainMenuUiLayer::onRender() { void MainMenuUiLayer::onRender() {
@ -70,7 +71,8 @@ void MainMenuUiLayer::onAttachImpl() {
if (e.success) { if (e.success) {
spdlog::info("Received positive Connection Result"); spdlog::info("Received positive Connection Result");
m_connectionError = false; m_connectionError = false;
m_closeConnectPopup = true; std::unique_ptr<LobbyScene> lobbyScene = std::make_unique<LobbyScene>(m_applicationEventBus, getInputStack(), getKeyboard(), getMouse());
} else { } else {
spdlog::info("Received negative Connection Result"); spdlog::info("Received negative Connection Result");
m_connectionError = true; m_connectionError = true;

View File

@ -0,0 +1,19 @@
//
// Created by sebastian on 06.08.26.
//
#include "LobbyScene.h"
std::vector<engine::AssetRequest> LobbyScene::getRequiredAssets() const {
std::vector<engine::AssetRequest> requests;
requests.emplace_back(engine::TextureRequest("lobby_background", "assets/textures/multiplayer_lobby.png"));
return requests;
}
void LobbyScene::onEnter() {
Scene::onEnter();
}
void LobbyScene::onExit() {
Scene::onExit();
}

View File

@ -0,0 +1,23 @@
//
// Created by sebastian on 06.08.26.
//
#ifndef COLORRACE_LOBBYSCENE_H
#define COLORRACE_LOBBYSCENE_H
#include "layer/Scene.h"
class LobbyScene : public engine::Scene {
public:
LobbyScene(const std::shared_ptr<engine::EventBus<ApplicationEvents>> &applicationEventbus,
engine::InputContextStack &inputStack, engine::Keyboard &keyboard, engine::Mouse &mouse)
: Scene(applicationEventbus, inputStack, keyboard, mouse) {
}
std::vector<engine::AssetRequest> getRequiredAssets() const override;
void onEnter() override;
void onExit() override;
};
#endif //COLORRACE_LOBBYSCENE_H

View File

@ -0,0 +1,19 @@
//
// Created by sebastian on 06.08.26.
//
#include "LobbyUiLayer.h"
void LobbyUiLayer::onAttachImpl() {
Layer::onAttachImpl();
auto backgroundTexture = m_assetManager.getTexture("lobby_background");
backgroundImage = std::make_unique<engine::GUITexture>(backgroundTexture, glm::vec2(0,0), glm::vec2(1,1));
}
void LobbyUiLayer::onRender() {
std::vector<engine::GUITexture> guiElements;
guiElements.emplace_back(*backgroundImage);
m_guiRenderer.render(guiElements);
}

View File

@ -0,0 +1,40 @@
//
// Created by sebastian on 06.08.26.
//
#ifndef COLORRACE_LOBBYUILAYER_H
#define COLORRACE_LOBBYUILAYER_H
#include "layer/Layer.h"
#include "loader/assets/AssetManager.h"
#include "renderer/GuiRenderer.h"
#include "renderer/ui/GUITexture.h"
class LobbyUiLayer : public engine::Layer {
public:
LobbyUiLayer(engine::Keyboard &keyboard, engine::Mouse &mouse,
engine::EventBus<engine::animation::AnimationMarkerEvent> &animationEventBus, engine::AssetManager& assetManager)
: Layer(keyboard, mouse, animationEventBus), m_assetManager(assetManager) {
}
LobbyUiLayer(engine::Keyboard &keyboard, engine::Mouse &mouse,
engine::EventBus<engine::animation::AnimationMarkerEvent> &animationEventBus,
const std::shared_ptr<engine::EventBus<std::variant<QuitRequested>>> &applicationEventBus, engine::AssetManager& assetManager)
: Layer(keyboard, mouse, animationEventBus, applicationEventBus), m_assetManager(assetManager) {
}
void onRender() override;
void onUpdate(float deltaTime) override;
protected:
void onAttachImpl() override;
void onDetachImpl() override;
private:
std::unique_ptr<engine::GUITexture> backgroundImage;
engine::AssetManager& m_assetManager;
engine::renderer::GuiRenderer m_guiRenderer;
};
#endif //COLORRACE_LOBBYUILAYER_H