11 : AScene(assignedId), m_renderer(renderer), m_appConfig(config)
13 auto ®istry = AScene::getRegistry();
15 registry.onComponentAdded(
16 [&renderer, ®istry](
const ecs::Entity e,
const std::type_info &type)
18 const auto *colorComp = registry.getComponent<
ecs::Color>(e);
19 const auto *fontComp = registry.getComponent<
ecs::Font>(e);
20 const auto *rectComp = registry.getComponent<
ecs::Rect>(e);
21 const auto *scaleComp = registry.getComponent<
ecs::Scale>(e);
22 const auto *textComp = registry.getComponent<
ecs::Text>(e);
23 const auto *textureComp = registry.getComponent<
ecs::Texture>(e);
28 if (textComp && transform && fontComp)
30 renderer->createFont(fontComp->
id, fontComp->path);
32 {.font_name = fontComp->
id,
33 .color = {.r = colorComp->r, .g = colorComp->g, .b = colorComp->b, .a = colorComp->a},
34 .content = textComp->content,
35 .size = textComp->font_size,
38 .name = textComp->
id});
43 const float scale_x = scaleComp ? scaleComp->x : 1.F;
44 const float scale_y = scaleComp ? scaleComp->y : 1.F;
46 renderer->createTexture(textureComp->
id, textureComp->path);
48 if (transform && textureComp)
52 renderer->createSprite(textureComp->
id + std::to_string(e), textureComp->
id, transform->x,
53 transform->y, scale_x, scale_y,
static_cast<int>(rectComp->pos_x),
54 static_cast<int>(rectComp->pos_y), rectComp->size_x, rectComp->size_y);
58 renderer->createSprite(textureComp->
id + std::to_string(e), textureComp->
id, transform->x,
66 registry.createEntity()
68 .with<ecs::Transform>(
"transform_title", 100.F, 60.F, 0.F)
71 .with<ecs::Text>(
"title", std::string(
"SETTINGS"), 72U)
76 registry.createEntity()
78 .with<ecs::Transform>(
"transform_setting_" + std::to_string(i), 100.F, 200.F + i * 50.F, 0.F)
86 registry.createEntity()
88 .with<ecs::Transform>(
"transform_volume_value", 580.F, 200.F, 0.F)
92 .with<ecs::Text>(
"volume_value", std::string(
"50"), 24U)
95 registry.createEntity()
97 .with<ecs::Transform>(
"transform_quality_value", 580.F, 250.F, 0.F)
101 .with<ecs::Text>(
"quality_value", std::string(
"Medium"), 24U)
104 registry.createEntity()
106 .with<ecs::Transform>(
"transform_control_value", 580.F, 300.F, 0.F)
110 .with<ecs::Text>(
"control_value", std::string(
"WASD"), 24U)
114 registry.createEntity()
116 .with<ecs::Scale>(
"scale_skin_sprite", 2.0f, 2.0f)
119 .with<ecs::Rect>(
"rect_skin_sprite", 0.0f, 0.0f, 33, 17)
120 .with<
ecs::Texture>(
"skin_sprite",
"assets/sprites/r-typesheet42.gif")
122 registry.createEntity()
124 .with<ecs::Transform>(
"transform_instruction", 80.F, 480.F, 0.F)
128 .with<ecs::Text>(
"instruction", std::string(
"UP/DOWN navigate, LEFT/RIGHT change, ESC back"), 16U)
181 auto ®istry = getRegistry();
183 if (
auto *volumeValueText = registry.getComponent<
ecs::Text>(m_volumeValueEntity))
185 volumeValueText->content = std::to_string(m_audioVolume);
187 if (
auto *qualityValueText = registry.getComponent<
ecs::Text>(m_qualityValueEntity))
189 const std::vector<std::string> fpsOptions = {
"60 FPS",
"144 FPS",
"240 FPS"};
190 qualityValueText->content = fpsOptions[
static_cast<size_t>(m_videoQuality)];
192 if (
auto *controlValueText = registry.getComponent<
ecs::Text>(m_controlValueEntity))
194 const std::vector<std::string> controlSchemes = {
"WASD",
"ZQSD",
"Arrows"};
195 controlValueText->content = controlSchemes[
static_cast<size_t>(m_controlScheme)];
197 if (
auto *skinRect = registry.getComponent<
ecs::Rect>(m_skinSpriteEntity))
199 const std::vector shipLines = {0.0f, 17.0f, 34.0f, 51.0f, 68.0f};
201 skinRect->pos_y = shipLines[
static_cast<size_t>(m_skinIndex)];
202 skinRect->pos_x = 0.0f;
203 skinRect->size_x = 33U;
204 skinRect->size_y = 17U;
219 m_selectedIndex = (m_selectedIndex == 0) ? m_settingsOptions.size() - 1 : m_selectedIndex - 1;
224 m_selectedIndex = (m_selectedIndex == m_settingsOptions.size() - 1) ? 0 : m_selectedIndex + 1;
229 if (
const std::string &selectedOption = m_settingsOptions[m_selectedIndex];
230 selectedOption ==
"Back to Menu")
238 if (
const std::string &selectedOption = m_settingsOptions[m_selectedIndex];
239 selectedOption ==
"Audio Volume")
241 const float newVolume = m_audioVolume + ((
event.key ==
eng::Key::Right) ? 0.01F : -0.01F);
242 m_audioVolume = (std::max)(0.0F, (std::min)(10.0F, newVolume));
243 m_appConfig.audioVolume = m_audioVolume;
245 else if (selectedOption ==
"FPS")
249 m_videoQuality = (m_videoQuality == 0) ? 2 : m_videoQuality - 1;
253 m_videoQuality = (m_videoQuality == 2) ? 0 : m_videoQuality + 1;
255 m_appConfig.videoQuality = m_videoQuality;
258 else if (selectedOption ==
"Controls")
262 m_controlScheme = (m_controlScheme == 0) ? 2 : m_controlScheme - 1;
266 m_controlScheme = (m_controlScheme == 2) ? 0 : m_controlScheme + 1;
268 m_appConfig.controlScheme = m_controlScheme;
270 else if (selectedOption ==
"Skin")
274 m_skinIndex = (m_skinIndex == 0) ? 4 : m_skinIndex - 1;
278 m_skinIndex = (m_skinIndex == 4) ? 0 : m_skinIndex + 1;
280 m_appConfig.skinIndex = m_skinIndex;
284 updateSettingsDisplay();