12 auto ®istry = AScene::getRegistry();
14 registry.onComponentAdded(
15 [&renderer, ®istry](
const ecs::Entity e,
const std::type_info &type)
17 const auto *colorComp = registry.getComponent<
ecs::Color>(e);
18 const auto *fontComp = registry.getComponent<
ecs::Font>(e);
19 const auto *textComp = registry.getComponent<
ecs::Text>(e);
24 if (textComp && transform && fontComp)
26 renderer->createFont(fontComp->
id, fontComp->path);
28 {.font_name = fontComp->
id,
29 .color = {.r = colorComp->r, .g = colorComp->g, .b = colorComp->b, .a = colorComp->a},
30 .content = textComp->content,
31 .size = textComp->font_size,
34 .name = textComp->
id});
39 registry.createEntity()
41 .with<ecs::Transform>(
"transform_title", 100.F, 60.F, 0.F)
44 .with<ecs::Text>(
"title", std::string(
"JOIN ROOM"), 72U)
48 registry.createEntity()
50 .with<ecs::Transform>(
"transform_no_rooms", 100.F, 200.F, 0.F)
54 .with<ecs::Text>(
"no_rooms_text", std::string(
"No rooms available"), 32U)
57 registry.createEntity()
59 .with<ecs::Transform>(
"transform_refresh", 100.F, 400.F, 0.F)
63 .with<ecs::Text>(
"refresh_text", std::string(
"Refresh"), 32U)
66 registry.createEntity()
68 .with<ecs::Transform>(
"transform_back", 100.F, 450.F, 0.F)
71 .with<ecs::Text>(
"back_text", std::string(
"Back"), 32U)
92 utl::Logger::log(
"JoinRoomScene: Received lobby list with " + std::to_string(lobbyCount) +
" lobbies",
97 for (
const auto &lobby : lobbies)
100 for (
size_t i = 0; i < lobby.lobbyName.size() && lobby.lobbyName[i] !=
'\0'; ++i)
104 std::string lobbyName(lobby.lobbyName.data(), nameLen);
105 utl::Logger::log(
"JoinRoomScene: Found lobby '" + lobbyName +
"' (ID: " + std::to_string(lobby.lobbyId) +
106 ") with " + std::to_string(lobby.currentPlayers) +
"/" +
107 std::to_string(lobby.maxPlayers) +
" players",
111 catch (
const std::exception &e)
113 utl::Logger::log(
"JoinRoomScene: Failed to handle lobby list response - " + std::string(e.what()),
127 utl::Logger::log(
"JoinRoomScene: Successfully joined lobby " + std::to_string(lobbyId),
131 onJoin(
static_cast<int>(lobbyId), &lobbyInfo);
136 std::string errorMsg;
140 errorMsg =
"Lobby not found";
143 errorMsg =
"Lobby is full";
146 errorMsg =
"Already in a lobby";
149 errorMsg =
"Failed to join lobby";
155 catch (
const std::exception &e)
157 utl::Logger::log(
"JoinRoomScene: Failed to handle lobby join response - " + std::string(e.what()),
164 auto ® = getRegistry();
169 m_animationTime += dt;
171 for (
auto &[entity, text] : texts)
173 if (text.id ==
"refresh_text")
175 auto &color = colors.at(entity);
176 if (m_selectedIndex == m_rooms.size())
178 const float glowIntensity = std::sin(m_animationTime * 2.5F);
180 color.g =
static_cast<unsigned char>(191U + (glowIntensity * 50));
190 else if (text.id ==
"back_text")
192 auto &color = colors.at(entity);
193 if (m_selectedIndex == m_rooms.size() + 1)
195 const float glowIntensity = std::sin(m_animationTime * 2.5F);
197 color.g =
static_cast<unsigned char>(191U + (glowIntensity * 50));
209 for (
size_t i = 0; i < m_roomEntities.size(); ++i)
211 if (
auto *color = reg.getComponent<
ecs::Color>(m_roomEntities[i]))
213 if (i == m_selectedIndex)
215 float glowIntensity = std::sin(m_animationTime * 2.5F);
217 color->g =
static_cast<unsigned char>(191U + (glowIntensity * 50));
233 const size_t totalOptions = m_rooms.size() + 2;
248 if (totalOptions > 0)
250 m_selectedIndex = (m_selectedIndex == 0) ? totalOptions - 1 : m_selectedIndex - 1;
256 if (totalOptions > 0)
258 m_selectedIndex = (m_selectedIndex == totalOptions - 1) ? 0 : m_selectedIndex + 1;
263 if (m_selectedIndex < m_rooms.size())
266 joinPacket.
lobbyId = m_rooms[m_selectedIndex].lobbyId;
270 else if (m_selectedIndex == m_rooms.size() && onRefreshRequest)
275 else if (m_selectedIndex == m_rooms.size() + 1 && onBackToMulti)
299 if (onRefreshRequest)
307 auto ®istry = getRegistry();
309 utl::Logger::log(
"JoinRoomScene: Updating room display with " + std::to_string(m_rooms.size()) +
" rooms",
314 if (
auto *noRoomsText = registry.getComponent<
ecs::Text>(m_noRoomsEntity))
316 noRoomsText->content = m_rooms.empty() ?
"No rooms available" :
"";
319 for (
size_t i = 0; i < m_rooms.size(); ++i)
328 std::string lobbyName(lobby.
lobbyName.data(), nameLen);
330 std::string roomText =
336 registry.createEntity()
338 .with<ecs::Transform>(
"transform_room_" + std::to_string(i), 100.F, 200.F + i * 40.F, 0.F)
342 .with<ecs::Text>(
"room_" + std::to_string(i), roomText, 28U)
345 m_roomEntities.push_back(roomEntity);
348 if (m_selectedIndex >= m_rooms.size() + 2)
356 auto ®istry = getRegistry();
360 if (registry.getComponent<
ecs::Text>(entity) !=
nullptr)
362 registry.removeComponent<
ecs::Text>(entity);
364 if (registry.getComponent<
ecs::Color>(entity) !=
nullptr)
372 if (registry.getComponent<
ecs::Font>(entity) !=
nullptr)
374 registry.removeComponent<
ecs::Font>(entity);
378 m_roomEntities.clear();
383 for (
const std::vector<utl::Event> events = m_eventBus.consumeForTarget(m_eventComponentId);
384 const auto &event : events)
389 handleLobbyListResponse(event);
392 handleLobbyJoinResponse(event);
This file contains the component definitions.
Lobby browser scene for joining multiplayer games.
This file contains the Logger class.
Network packet serializer for RNP protocol.
utl::EventBus & m_eventBus
std::uint32_t m_eventComponentId
ecs::Entity m_noRoomsEntity
Entity displaying "No rooms available" message.
void handleLobbyListResponse(const utl::Event &event)
Handle lobby list response from server.
void clearRoomEntities()
Clear all lobby display entities.
void event(const eng::Event &event) override
Handle input events.
void setRooms(const std::vector< rnp::LobbyInfo > &rooms)
Update the displayed list of available lobbies.
void update(float dt, const eng::WindowSize &size) override
Update the join room scene (called each frame)
void refreshRoomList() const
Request updated lobby list from server.
JoinRoomScene(eng::id assignedId, const std::shared_ptr< eng::IRenderer > &renderer)
Constructor.
void setupEventSubscriptions() const
Subscribe to event bus events.
void processEventBus()
Process events from event bus.
void updateRoomDisplay()
Update the visual display of the lobby list.
void handleLobbyJoinResponse(const utl::Event &event) const
Handle lobby join response from server.
Binary serializer for RNP protocol packets.
PacketLobbyJoinResponse deserializeLobbyJoinResponse()
Deserialize LOBBY_JOIN_RESPONSE packet.
PacketLobbyListResponse deserializeLobbyListResponse()
Deserialize LOBBY_LIST_RESPONSE packet.
void registerComponent(std::uint32_t componentId, const std::string &name)
Register component name for better debugging.
Event structure for inter-component communication.
std::vector< std::uint8_t > data
Serialized event data.
static void log(const std::string &message, const LogLevel &logLevel)
This file contains common definitions and constants.
static constexpr eng::Color TEXT_VALUE_COLOR
static constexpr eng::Color GRAY_BLUE_SUBTLE
static constexpr eng::Color CYAN_ELECTRIC
static constexpr eng::Color INFO_TEXT_COLOR
constexpr auto FONTS_RTYPE
static constexpr std::uint32_t NETWORK_CLIENT
Lobby information structure.
std::array< char, 32 > lobbyName
std::uint8_t currentPlayers
LOBBY_JOIN packet payload.