12 return shift ?
'A' :
'a';
14 return shift ?
'Z' :
'z';
16 return shift ?
'E' :
'e';
18 return shift ?
'R' :
'r';
20 return shift ?
'T' :
't';
22 return shift ?
'Y' :
'y';
24 return shift ?
'U' :
'u';
26 return shift ?
'I' :
'i';
28 return shift ?
'O' :
'o';
30 return shift ?
'P' :
'p';
33 return shift ?
'Q' :
'q';
35 return shift ?
'S' :
's';
37 return shift ?
'D' :
'd';
39 return shift ?
'F' :
'f';
41 return shift ?
'G' :
'g';
43 return shift ?
'H' :
'h';
45 return shift ?
'J' :
'j';
47 return shift ?
'K' :
'k';
49 return shift ?
'M' :
'm';
51 return shift ?
'L' :
'l';
54 return shift ?
'W' :
'w';
56 return shift ?
'X' :
'x';
58 return shift ?
'C' :
'c';
60 return shift ?
'V' :
'v';
62 return shift ?
'B' :
'b';
64 return shift ?
'N' :
'n';
96 const std::string &host,
const std::string &port,
const std::string &playerName)
97 : AScene(assignedId), m_playerName(playerName), m_host(host), m_port(port)
99 auto ®istry = AScene::getRegistry();
101 registry.onComponentAdded(
102 [&renderer, ®istry](
const ecs::Entity e,
const std::type_info &type)
104 const auto *colorComp = registry.getComponent<
ecs::Color>(e);
105 const auto *fontComp = registry.getComponent<
ecs::Font>(e);
106 const auto *textComp = registry.getComponent<
ecs::Text>(e);
111 if (textComp && transform && fontComp)
113 renderer->createFont(fontComp->
id, fontComp->path);
114 renderer->createText(
115 {.font_name = fontComp->
id,
116 .color = {.r = colorComp->r, .g = colorComp->g, .b = colorComp->b, .a = colorComp->a},
117 .content = textComp->content,
118 .size = textComp->font_size,
121 .name = textComp->
id});
125 registry.createEntity()
127 .with<ecs::Transform>(
"transform_title", 100.F, 60.F, 0.F)
130 .with<ecs::Text>(
"title", std::string(
"SERVER"), 72U)
134 float yPosition = 0.0F;
137 yPosition = 200.F + i * 50.F;
141 yPosition = 200.F + i * 50.F + 30.F;
143 registry.createEntity()
145 .with<ecs::Transform>(
"transform_option_" + std::to_string(i), 100.F, yPosition, 0.F)
153 registry.createEntity()
155 .with<ecs::Transform>(
"transform_player_name_value", 580.F, 200.F, 0.F)
159 .with<ecs::Text>(
"player_name_value",
m_playerName, 24U)
163 registry.createEntity()
165 .with<ecs::Transform>(
"transform_server_ip_value", 580.F, 250.F, 0.F)
169 .with<ecs::Text>(
"server_ip_value",
m_host, 24U)
173 registry.createEntity()
175 .with<ecs::Transform>(
"transform_server_port_value", 580.F, 300.F, 0.F)
179 .with<ecs::Text>(
"server_port_value",
m_port, 24U)
188 auto ® = getRegistry();
192 m_animationTime += dt;
194 for (
auto &[entity, text] : texts)
196 for (
size_t i = 0; i < m_serverOptions.size(); ++i)
198 if (text.id ==
"option_" + m_serverOptions[i])
200 auto &color = colors.at(entity);
202 if (i == m_selectedIndex)
204 const float glowIntensity = std::sin(m_animationTime * 2.5f);
206 color.g =
static_cast<unsigned char>(191U + glowIntensity * 50);
236 m_selectedIndex = (m_selectedIndex == 0) ? m_serverOptions.size() - 1 : m_selectedIndex - 1;
241 m_selectedIndex = (m_selectedIndex == m_serverOptions.size() - 1) ? 0 : m_selectedIndex + 1;
245 if (m_selectedIndex == 3 && onConnect)
247 connectServer(m_playerName, m_host, m_port);
248 onConnect(m_playerName, m_host, m_port);
250 else if (m_selectedIndex == 4 && onBackToMenu)
257 if (m_selectedIndex < 3)
259 if (std::string ¤tField = getCurrentEditField(); !currentField.empty())
261 currentField.pop_back();
262 updateValueDisplay();
268 if (m_selectedIndex < 3)
272 std::string ¤tField = getCurrentEditField();
273 if (c ==
' ' && m_selectedIndex != 0)
277 if (currentField.length() < 20)
280 updateValueDisplay();
295 if (m_selectedIndex == 0)
299 if (m_selectedIndex == 1)
308 auto ® = getRegistry();
310 if (
auto *playerNameText = reg.getComponent<
ecs::Text>(m_playerNameValueEntity))
312 playerNameText->content = m_playerName;
315 if (
auto *serverIPText = reg.getComponent<
ecs::Text>(m_serverIPValueEntity))
317 serverIPText->content = m_host;
320 if (
auto *serverPortText = reg.getComponent<
ecs::Text>(m_serverPortValueEntity))
322 serverPortText->content = m_port;
327 const std::string &serverPort)
const
333 const auto data = serializer.
getData();
This file contains the component definitions.
static char keyToChar(const eng::Key key, bool shift=false)
Server connection configuration scene for R-Type multiplayer.
utl::EventBus & m_eventBus
std::uint32_t m_eventComponentId
void event(const eng::Event &event) override
Handle input events.
ecs::Entity m_serverPortValueEntity
Text entity displaying server port.
std::string m_port
Server port input field.
void updateValueDisplay()
Update the visual display of input values.
void connectServer(const std::string &playerName, const std::string &serverIP, const std::string &serverPort) const
Initiate server connection with provided settings.
std::string m_host
Server host/IP input field.
ecs::Entity m_playerNameValueEntity
Text entity displaying player name.
const std::vector< std::string > m_serverOptions
ecs::Entity m_serverIPValueEntity
Text entity displaying server IP.
ServerScene(eng::id assignedId, const std::shared_ptr< eng::IRenderer > &renderer, const std::string &host, const std::string &port, const std::string &playerName)
Constructor.
std::string & getCurrentEditField()
Get reference to the currently selected input field.
std::string m_playerName
Player name input field.
void update(float dt, const eng::WindowSize &size) override
Update the scene (called each frame)
Binary serializer for RNP protocol packets.
void writeString(const std::string &str, std::size_t maxLength)
Write a string with length prefix.
const std::vector< std::uint8_t > & getData() const
Get the serialized data.
void registerComponent(std::uint32_t componentId, const std::string &name)
Register component name for better debugging.
static char keyToChar(const eng::Key key, bool shift=false)
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
constexpr auto FONTS_RTYPE
static constexpr std::uint32_t NETWORK_CLIENT