R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
WaitingRoomMenu.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** r-type
4** File description:
5** WaitingRoomMenu - Menu for waiting before game starts
6*/
7
8#pragma once
9
10#include <functional>
11#include <memory>
12#include <string>
13#include <vector>
14
16#include "Menu/BaseMenu.hpp"
17#include "UI/IUIFactory.hpp"
18
19namespace Game {
23 struct PlayerInfo {
24 uint32_t playerId;
25 std::string playerName;
26 bool isHost;
28
29 PlayerInfo(uint32_t id, const std::string &name, bool host, bool spectator)
30 : playerId(id), playerName(name), isHost(host), isSpectator(spectator) {}
31 };
32
36 class WaitingRoomMenu : public BaseMenu {
37 public:
38 explicit WaitingRoomMenu(UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics);
39 ~WaitingRoomMenu() override = default;
40
44 void SetOnStartGame(std::function<void()> onStartGame);
45
49 void SetOnBack(std::function<void()> onBack);
50
54 void UpdatePlayerList(const std::vector<PlayerInfo> &players);
55
59 void SetRoomInfo(const std::string &roomName, uint32_t currentPlayers, uint32_t maxPlayers);
60
64 void SetIsHost(bool isHost);
65
69 void SetIsSpectator(bool isSpectator);
70
71 void Initialize() override;
72 void Update() override;
73 void Render() override;
74
75 private:
76 void OnStartGameClicked();
77 void OnBackClicked();
78 void RebuildPlayerList();
79
80 std::function<void()> _onStartGame{};
81 std::function<void()> _onBack{};
82
84
85 std::string _roomName;
86 uint32_t _currentPlayers = 0;
87 uint32_t _maxPlayers = 4;
88 bool _isHost = false;
89 bool _isSpectator = false; // True if player is in spectator mode
90
91 std::vector<PlayerInfo> _players;
92 std::shared_ptr<UI::IButton> _startGameButton;
93 std::shared_ptr<UI::IButton> _backButton;
94
95 static constexpr float PLAYER_ITEM_HEIGHT = 50.0f;
96 static constexpr float PLAYER_ITEM_SPACING = 10.0f;
97 static constexpr float LIST_START_Y = 150.0f;
98 static constexpr size_t MAX_VISIBLE_PLAYERS = 8;
99 };
100} // namespace Game
Base class for all menu implementations.
Definition BaseMenu.hpp:26
Menu displayed while waiting for game to start.
~WaitingRoomMenu() override=default
std::shared_ptr< UI::IButton > _startGameButton
void Update() override
Update menu state (should be called every frame).
void SetOnStartGame(std::function< void()> onStartGame)
Set callback triggered when Start Game button is clicked (host only)
std::function< void()> _onStartGame
Graphics::IGraphics & _graphics
static constexpr float PLAYER_ITEM_HEIGHT
void Render() override
Render menu (should be called every frame).
void SetRoomInfo(const std::string &roomName, uint32_t currentPlayers, uint32_t maxPlayers)
Set room name and player count info.
std::shared_ptr< UI::IButton > _backButton
static constexpr float LIST_START_Y
void UpdatePlayerList(const std::vector< PlayerInfo > &players)
Update the player list.
void SetOnBack(std::function< void()> onBack)
Set callback triggered when Back button is clicked.
std::vector< PlayerInfo > _players
void SetIsSpectator(bool isSpectator)
Set whether current player is spectator (shows spectator banner)
std::function< void()> _onBack
void Initialize() override
Initialize menu (must be implemented by derived classes).
void SetIsHost(bool isHost)
Set whether current player is host (enables Start Game button)
static constexpr float PLAYER_ITEM_SPACING
static constexpr size_t MAX_VISIBLE_PLAYERS
Abstract interface for graphics rendering operations.
Definition IGraphics.hpp:32
Abstract factory interface for creating UI elements.
Player information in waiting room.
PlayerInfo(uint32_t id, const std::string &name, bool host, bool spectator)