feat(service-menu): pobla AUDIO amb toggles i sliders de volum

This commit is contained in:
2026-05-24 11:49:14 +02:00
parent 71c43ec6fe
commit 56d7d4af52
6 changed files with 148 additions and 5 deletions
+108 -1
View File
@@ -11,6 +11,7 @@
#include "core/audio/audio.hpp"
#include "core/config/engine_config.hpp"
#include "core/defaults/audio.hpp"
#include "core/defaults/service_menu.hpp"
#include "core/locale/locale.hpp"
#include "core/rendering/sdl_manager.hpp"
@@ -116,7 +117,7 @@ namespace System {
root.title_key = "service_menu.title";
root.items = {
makeSubmenu("service_menu.video", [this] { pushPage(buildVideoPage()); }),
makeSubmenu("service_menu.audio", [this] { pushSubmenuPlaceholder("service_menu.audio"); }),
makeSubmenu("service_menu.audio", [this] { pushPage(buildAudioPage()); }),
makeSubmenu("service_menu.options", [this] { pushSubmenuPlaceholder("service_menu.options"); }),
makeSubmenu("service_menu.system", [this] { pushSubmenuPlaceholder("service_menu.system"); }),
};
@@ -197,6 +198,112 @@ namespace System {
return page;
}
auto ServiceMenu::buildAudioPage() -> Page {
auto on_off_text = [](bool v) -> std::string {
return Locale::get().text(v ? "service_menu.value_on" : "service_menu.value_off");
};
// Aplica un step de volum (±VOLUME_STEP) a un valor 0..1 i retorna el
// resultat clampat. El motor s'encarrega d'aplicar-lo amb el getter.
auto step_volume = [](float current, int dir) -> float {
const float STEP = Defaults::Audio::VOLUME_STEP;
return std::clamp(current + (static_cast<float>(dir) * STEP), 0.0F, 1.0F);
};
Page page;
page.title_key = "service_menu.audio";
page.items = {
// AUDIO (master ON/OFF)
Item{
.kind = Kind::TOGGLE,
.label_key = "service_menu.audio_master",
.selectable = true,
.on_activate = {},
.get_value_text = [on_off_text] {
const Audio* a = Audio::get();
return on_off_text(a != nullptr && a->isEnabled()); },
.on_change = [](int) {
if (auto* a = Audio::get(); a != nullptr) {
a->toggleEnabled();
} },
},
// VOLUM GENERAL (master)
Item{
.kind = Kind::INT_RANGE,
.label_key = "service_menu.audio_master_volume",
.selectable = true,
.on_activate = {},
.get_value_text = [] {
const Audio* a = Audio::get();
const float V = (a != nullptr) ? a->getMasterVolume() : 0.0F;
return std::to_string(Audio::toPercent(V)); },
.on_change = [step_volume](int dir) {
if (auto* a = Audio::get(); a != nullptr) {
a->setMasterVolume(step_volume(a->getMasterVolume(), dir));
} },
},
// MUSICA ON/OFF
Item{
.kind = Kind::TOGGLE,
.label_key = "service_menu.audio_music",
.selectable = true,
.on_activate = {},
.get_value_text = [on_off_text] {
const Audio* a = Audio::get();
return on_off_text(a != nullptr && a->isMusicEnabled()); },
.on_change = [](int) {
if (auto* a = Audio::get(); a != nullptr) {
a->toggleMusic();
} },
},
// VOLUM MUSICA
Item{
.kind = Kind::INT_RANGE,
.label_key = "service_menu.audio_music_volume",
.selectable = true,
.on_activate = {},
.get_value_text = [] {
const Audio* a = Audio::get();
const float V = (a != nullptr) ? a->getMusicVolume() : 0.0F;
return std::to_string(Audio::toPercent(V)); },
.on_change = [step_volume](int dir) {
if (auto* a = Audio::get(); a != nullptr) {
a->setMusicVolume(step_volume(a->getMusicVolume(), dir));
} },
},
// SONS ON/OFF
Item{
.kind = Kind::TOGGLE,
.label_key = "service_menu.audio_sound",
.selectable = true,
.on_activate = {},
.get_value_text = [on_off_text] {
const Audio* a = Audio::get();
return on_off_text(a != nullptr && a->isSoundEnabled()); },
.on_change = [](int) {
if (auto* a = Audio::get(); a != nullptr) {
a->toggleSound();
} },
},
// VOLUM SONS
Item{
.kind = Kind::INT_RANGE,
.label_key = "service_menu.audio_sound_volume",
.selectable = true,
.on_activate = {},
.get_value_text = [] {
const Audio* a = Audio::get();
const float V = (a != nullptr) ? a->getSoundVolume() : 0.0F;
return std::to_string(Audio::toPercent(V)); },
.on_change = [step_volume](int dir) {
if (auto* a = Audio::get(); a != nullptr) {
a->setSoundVolume(step_volume(a->getSoundVolume(), dir));
} },
},
};
return page;
}
void ServiceMenu::pushPage(Page page) {
stack_.push_back(std::move(page));
// El cursor salta a una pagina nova: enganxem el highlight per a
+1
View File
@@ -88,6 +88,7 @@ namespace System {
void buildRootPage();
void pushSubmenuPlaceholder(const std::string& title_key);
[[nodiscard]] auto buildVideoPage() const -> Page;
[[nodiscard]] static auto buildAudioPage() -> Page;
void pushPage(Page page);
void popPage();
void moveCursor(int direction);