normalitzat Audio
This commit is contained in:
@@ -459,7 +459,7 @@ namespace Options {
|
||||
}
|
||||
if (aud.contains("volume")) {
|
||||
try {
|
||||
audio.volume = std::clamp(aud["volume"].get_value<int>(), 0, 100);
|
||||
audio.volume = std::clamp(aud["volume"].get_value<float>(), 0.0F, 1.0F);
|
||||
} catch (...) {}
|
||||
}
|
||||
if (aud.contains("music")) {
|
||||
@@ -471,7 +471,7 @@ namespace Options {
|
||||
}
|
||||
if (mus.contains("volume")) {
|
||||
try {
|
||||
audio.music.volume = std::clamp(mus["volume"].get_value<int>(), 0, 100);
|
||||
audio.music.volume = std::clamp(mus["volume"].get_value<float>(), 0.0F, 1.0F);
|
||||
} catch (...) {}
|
||||
}
|
||||
}
|
||||
@@ -484,7 +484,7 @@ namespace Options {
|
||||
}
|
||||
if (snd.contains("volume")) {
|
||||
try {
|
||||
audio.sound.volume = std::clamp(snd["volume"].get_value<int>(), 0, 100);
|
||||
audio.sound.volume = std::clamp(snd["volume"].get_value<float>(), 0.0F, 1.0F);
|
||||
} catch (...) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,19 +94,19 @@ namespace Options {
|
||||
|
||||
struct Music {
|
||||
bool enabled = Defaults::Music::ENABLED; // Indica si la música suena o no
|
||||
int volume = Defaults::Music::VOLUME; // Volumen de la música
|
||||
float volume = Defaults::Music::VOLUME; // Volumen de la música (0.0..1.0)
|
||||
};
|
||||
|
||||
struct Sound {
|
||||
bool enabled = Defaults::Sound::ENABLED; // Indica si los sonidos suenan o no
|
||||
int volume = Defaults::Sound::VOLUME; // Volumen de los sonidos
|
||||
float volume = Defaults::Sound::VOLUME; // Volumen de los sonidos (0.0..1.0)
|
||||
};
|
||||
|
||||
struct Audio {
|
||||
Music music; // Opciones para la música
|
||||
Sound sound; // Opciones para los efectos de sonido
|
||||
bool enabled = Defaults::Audio::ENABLED; // Indica si el audio está activo o no
|
||||
int volume = Defaults::Audio::VOLUME; // Volumen general del audio
|
||||
float volume = Defaults::Audio::VOLUME; // Volumen general del audio (0.0..1.0)
|
||||
};
|
||||
|
||||
struct Loading {
|
||||
|
||||
@@ -106,6 +106,40 @@ class IntOption : public MenuOption {
|
||||
int min_value_, max_value_, step_value_;
|
||||
};
|
||||
|
||||
// VolumeOption: emmagatzema un float 0.0..1.0 però es mostra/edita com a int 0..100.
|
||||
// Pensat per als sliders de volum que l'usuari veu com percentatge però que
|
||||
// internament viuen en float (API unificada del motor d'àudio).
|
||||
class VolumeOption : public MenuOption {
|
||||
public:
|
||||
VolumeOption(const std::string& cap, ServiceMenu::SettingsGroup grp, float* var, int step_percent = 5)
|
||||
: MenuOption(cap, grp),
|
||||
linked_variable_(var),
|
||||
step_value_(step_percent) {}
|
||||
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override { return Behavior::ADJUST; }
|
||||
[[nodiscard]] auto getValueAsString() const -> std::string override {
|
||||
int pct = static_cast<int>(*linked_variable_ * 100.0F + 0.5F);
|
||||
return std::to_string(pct);
|
||||
}
|
||||
void adjustValue(bool adjust_up) override {
|
||||
int current = static_cast<int>(*linked_variable_ * 100.0F + 0.5F);
|
||||
int new_value = std::clamp(current + (adjust_up ? step_value_ : -step_value_), 0, 100);
|
||||
*linked_variable_ = static_cast<float>(new_value) / 100.0F;
|
||||
}
|
||||
auto getMaxValueWidth(Text* text_renderer) const -> int override {
|
||||
int max_width = 0;
|
||||
for (int value = 0; value <= 100; value += step_value_) {
|
||||
int width = text_renderer->length(std::to_string(value), -2);
|
||||
max_width = std::max(max_width, width);
|
||||
}
|
||||
return max_width;
|
||||
}
|
||||
|
||||
private:
|
||||
float* linked_variable_;
|
||||
int step_value_;
|
||||
};
|
||||
|
||||
class ListOption : public MenuOption {
|
||||
public:
|
||||
ListOption(const std::string& cap, ServiceMenu::SettingsGroup grp, std::vector<std::string> values, std::function<std::string()> current_value_getter, std::function<void(const std::string&)> new_value_setter)
|
||||
|
||||
@@ -490,28 +490,22 @@ void ServiceMenu::initializeOptions() {
|
||||
SettingsGroup::AUDIO,
|
||||
&Options::audio.enabled));
|
||||
|
||||
options_.push_back(std::make_unique<IntOption>(
|
||||
options_.push_back(std::make_unique<VolumeOption>(
|
||||
Lang::getText("[SERVICE_MENU] MAIN_VOLUME"),
|
||||
SettingsGroup::AUDIO,
|
||||
&Options::audio.volume,
|
||||
0,
|
||||
100,
|
||||
5));
|
||||
|
||||
options_.push_back(std::make_unique<IntOption>(
|
||||
options_.push_back(std::make_unique<VolumeOption>(
|
||||
Lang::getText("[SERVICE_MENU] MUSIC_VOLUME"),
|
||||
SettingsGroup::AUDIO,
|
||||
&Options::audio.music.volume,
|
||||
0,
|
||||
100,
|
||||
5));
|
||||
|
||||
options_.push_back(std::make_unique<IntOption>(
|
||||
options_.push_back(std::make_unique<VolumeOption>(
|
||||
Lang::getText("[SERVICE_MENU] SFX_VOLUME"),
|
||||
SettingsGroup::AUDIO,
|
||||
&Options::audio.sound.volume,
|
||||
0,
|
||||
100,
|
||||
5));
|
||||
|
||||
// SETTINGS
|
||||
|
||||
Reference in New Issue
Block a user