R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
RoomListMenu.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** r-type
4** File description:
5** RoomListMenu - Menu for selecting or creating a room
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 class RoomListMenu : public BaseMenu {
24 public:
25 struct RoomInfo {
26 std::string roomId;
27 std::string roomName;
28 uint32_t playerCount;
29 uint32_t maxPlayers;
31 uint8_t state; // 0=WAITING, 1=STARTING, 2=IN_PROGRESS, 3=FINISHED
32
33 RoomInfo(const std::string &id, const std::string &name, uint32_t count, uint32_t max, bool priv,
34 uint8_t st)
35 : roomId(id),
36 roomName(name),
37 playerCount(count),
38 maxPlayers(max),
39 isPrivate(priv),
40 state(st) {}
41 };
42
43 explicit RoomListMenu(UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics);
44 ~RoomListMenu() override = default;
45
49 void SetOnRoomSelected(std::function<void(const std::string &roomId)> onRoomSelected);
50
54 void SetOnCreateRoom(std::function<void()> onCreateRoom);
55
59 void SetOnBack(std::function<void()> onBack);
60
64 void UpdateRoomList(const std::vector<RoomInfo> &rooms);
65
69 void ClearRooms();
70
71 void Initialize() override;
72 void Update() override;
73 void Render() override;
74
78 void Show() override;
79
80 private:
81 void OnRoomClicked(size_t index);
83 void OnBackClicked();
84 void RebuildRoomList();
85
86 std::function<void(const std::string &)> _onRoomSelected{};
87 std::function<void()> _onCreateRoom{};
88 std::function<void()> _onBack{};
89
91
92 std::vector<RoomInfo> _rooms;
93 std::vector<std::shared_ptr<UI::IButton>> _roomButtons;
94
95 std::shared_ptr<UI::IButton> _createRoomButton;
96 std::shared_ptr<UI::IButton> _backButton;
97
98 static constexpr float ROOM_BUTTON_WIDTH = 500.0f;
99 static constexpr float ROOM_BUTTON_HEIGHT = 60.0f;
100 static constexpr float ROOM_BUTTON_SPACING = 10.0f;
101 static constexpr float LIST_START_Y = 100.0f;
102 static constexpr size_t MAX_VISIBLE_ROOMS = 6;
103 };
104} // namespace Game
Base class for all menu implementations.
Definition BaseMenu.hpp:26
Room list menu for selecting and managing game rooms.
void SetOnBack(std::function< void()> onBack)
Set callback triggered when Back button is clicked.
std::shared_ptr< UI::IButton > _createRoomButton
std::vector< std::shared_ptr< UI::IButton > > _roomButtons
void UpdateRoomList(const std::vector< RoomInfo > &rooms)
Update the room list.
static constexpr float ROOM_BUTTON_HEIGHT
void SetOnRoomSelected(std::function< void(const std::string &roomId)> onRoomSelected)
Set callback triggered when a room is selected.
void Update() override
Update menu state (should be called every frame).
~RoomListMenu() override=default
void SetOnCreateRoom(std::function< void()> onCreateRoom)
Set callback triggered when "Create Room" button is clicked.
std::function< void(const std::string &)> _onRoomSelected
void Render() override
Render menu (should be called every frame).
static constexpr size_t MAX_VISIBLE_ROOMS
static constexpr float ROOM_BUTTON_SPACING
std::function< void()> _onCreateRoom
void Show() override
Show the menu and play the room menu open sound effect.
std::shared_ptr< UI::IButton > _backButton
void ClearRooms()
Clear all rooms.
Graphics::IGraphics & _graphics
std::function< void()> _onBack
static constexpr float ROOM_BUTTON_WIDTH
void OnRoomClicked(size_t index)
void Initialize() override
Initialize menu (must be implemented by derived classes).
static constexpr float LIST_START_Y
std::vector< RoomInfo > _rooms
Abstract interface for graphics rendering operations.
Definition IGraphics.hpp:32
Abstract factory interface for creating UI elements.
RoomInfo(const std::string &id, const std::string &name, uint32_t count, uint32_t max, bool priv, uint8_t st)