summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--StarsEx/AudDlg.cpp22
-rw-r--r--StarsEx/AudDlg.h4
-rw-r--r--StarsEx/AudioConfig.cpp177
-rw-r--r--StarsEx/AudioConfig.h10
-rw-r--r--StarsEx/test/AudioConfig.cpp12
-rw-r--r--data/content/Content/content.txt3
-rw-r--r--data/content/Screens/AudDlg.frm73
-rw-r--r--data/shatter/Screens/AudDlg.frm52
8 files changed, 233 insertions, 120 deletions
diff --git a/StarsEx/AudDlg.cpp b/StarsEx/AudDlg.cpp
index 35eb56b..829b987 100644
--- a/StarsEx/AudDlg.cpp
+++ b/StarsEx/AudDlg.cpp
@@ -62,6 +62,10 @@ AudDlg::RegisterControls()
menu_music_slider = (Slider*) FindControl(205);
game_music_slider = (Slider*) FindControl(206);
+ master_volume_slider = (Slider*) FindControl(207);
+ music_volume_slider = (Slider*) FindControl(208);
+ world_volume_slider = (Slider*) FindControl(209);
+
apply = (Button*) FindControl(1);
REGISTER_CLIENT(EID_CLICK, apply, AudDlg, OnApply);
@@ -113,6 +117,15 @@ AudDlg::Show()
if (game_music_slider)
game_music_slider->SetValue(audio->GetGameMusic());
+
+ if (master_volume_slider)
+ master_volume_slider->SetValue(audio->GetMasterVolume());
+
+ if (music_volume_slider)
+ music_volume_slider->SetValue(audio->GetMusicVolume());
+
+ if (world_volume_slider)
+ world_volume_slider->SetValue(audio->GetWorldVolume());
}
if (vid_btn) vid_btn->SetButtonState(0);
@@ -183,6 +196,15 @@ AudDlg::Apply()
if (game_music_slider)
audio->SetGameMusic(game_music_slider->GetValue());
+ if (master_volume_slider)
+ audio->SetMasterVolume(master_volume_slider->GetValue());
+
+ if (music_volume_slider)
+ audio->SetMusicVolume(music_volume_slider->GetValue());
+
+ if (world_volume_slider)
+ audio->SetWorldVolume(world_volume_slider->GetValue());
+
audio->Save();
}
diff --git a/StarsEx/AudDlg.h b/StarsEx/AudDlg.h
index 35658f0..88ed35c 100644
--- a/StarsEx/AudDlg.h
+++ b/StarsEx/AudDlg.h
@@ -62,6 +62,10 @@ protected:
Slider* menu_music_slider;
Slider* game_music_slider;
+ Slider* master_volume_slider;
+ Slider* music_volume_slider;
+ Slider* world_volume_slider;
+
Button* aud_btn;
Button* vid_btn;
Button* opt_btn;
diff --git a/StarsEx/AudioConfig.cpp b/StarsEx/AudioConfig.cpp
index 8d4d74a..b025c41 100644
--- a/StarsEx/AudioConfig.cpp
+++ b/StarsEx/AudioConfig.cpp
@@ -13,6 +13,8 @@
#include "AudioConfig.h"
+#include <algorithm>
+
#include "DataLoader.h"
#include "ParseUtil.h"
#include "Button.h"
@@ -20,27 +22,30 @@
// +--------------------------------------------------------------------+
-static AudioConfig* audio_config = 0;
+static AudioConfig* audio_config = nullptr;
// +--------------------------------------------------------------------+
-AudioConfig::AudioConfig()
- : menu_music(90),
- game_music(90),
- efx_volume(90),
- gui_volume(90),
- wrn_volume(90),
- vox_volume(90),
- training(false)
+AudioConfig::AudioConfig() :
+ master_volume(100),
+ music_volume(100),
+ world_volume(100),
+ menu_music(80),
+ game_music(80),
+ efx_volume(80),
+ gui_volume(80),
+ wrn_volume(80),
+ vox_volume(80),
+ training(false)
{
if (!audio_config)
- audio_config = this;
+ audio_config = this;
}
AudioConfig::~AudioConfig()
{
if (audio_config == this)
- audio_config = 0;
+ audio_config = nullptr;
}
// +--------------------------------------------------------------------+
@@ -50,14 +55,14 @@ AudioConfig::Initialize()
{
audio_config = new AudioConfig;
if (audio_config)
- audio_config->Load();
+ audio_config->Load();
}
void
AudioConfig::Close()
{
delete audio_config;
- audio_config = 0;
+ audio_config = nullptr;
}
AudioConfig*
@@ -68,12 +73,19 @@ AudioConfig::GetInstance()
// +--------------------------------------------------------------------+
+static constexpr
+int
+denormalize(const double& v)
+{
+ return -50 * (100.0 - v);
+}
+
int
AudioConfig::MenuMusic()
{
if (audio_config)
- return -50 * (100 - audio_config->menu_music);
-
+ return denormalize(
+ audio_config->menu_music * (audio_config->music_volume / 100.0) * (audio_config->master_volume / 100.0));
return 0;
}
@@ -83,7 +95,8 @@ AudioConfig::GameMusic()
int vol = 0;
if (audio_config) {
- vol = -50 * (100 - audio_config->game_music);
+ vol = denormalize(
+ audio_config->game_music * (audio_config->music_volume / 100.0) * (audio_config->master_volume / 100.0));
if (audio_config->training)
vol -= 2000;
@@ -98,7 +111,8 @@ AudioConfig::EfxVolume()
int vol = 0;
if (audio_config) {
- vol = -50 * (100 - audio_config->efx_volume);
+ vol = denormalize(
+ audio_config->efx_volume * (audio_config->world_volume / 100.0) * (audio_config->master_volume / 100.0));
if (audio_config->training)
vol -= 2000;
@@ -111,8 +125,7 @@ int
AudioConfig::GuiVolume()
{
if (audio_config)
- return -50 * (100 - audio_config->gui_volume);
-
+ return denormalize(audio_config->gui_volume * (audio_config->master_volume / 100.0));
return 0;
}
@@ -122,7 +135,8 @@ AudioConfig::WrnVolume()
int vol = 0;
if (audio_config) {
- vol = -50 * (100 - audio_config->wrn_volume);
+ vol = denormalize(
+ audio_config->wrn_volume * (audio_config->world_volume / 100.0) * (audio_config->master_volume / 100.0));
if (audio_config->training)
vol -= 2000;
@@ -137,7 +151,8 @@ AudioConfig::VoxVolume()
int vol = 0;
if (audio_config) {
- vol = -50 * (100 - audio_config->vox_volume);
+ vol = denormalize(
+ audio_config->vox_volume * (audio_config->world_volume / 100.0) * (audio_config->master_volume / 100.0));
if (audio_config->training && vol < -750)
vol = -750;
@@ -162,59 +177,59 @@ AudioConfig::SetTraining(bool t)
// +--------------------------------------------------------------------+
void
-AudioConfig::SetMenuMusic(int v)
+AudioConfig::SetMasterVolume(int v)
{
- if (v < 0) v = 0;
- else if (v > 100) v = 100;
+ master_volume = std::clamp(v, 0, 100);
+ Button::SetVolume(GuiVolume());
+}
- menu_music = v;
+void
+AudioConfig::SetMusicVolume(int v)
+{
+ music_volume = std::clamp(v, 0, 100);
}
void
-AudioConfig::SetGameMusic(int v)
+AudioConfig::SetWorldVolume(int v)
{
- if (v < 0) v = 0;
- else if (v > 100) v = 100;
+ world_volume = std::clamp(v, 0, 100);
+}
- game_music = v;
+void
+AudioConfig::SetMenuMusic(int v)
+{
+ menu_music = std::clamp(v, 0, 100);
}
void
-AudioConfig::SetEfxVolume(int v)
+AudioConfig::SetGameMusic(int v)
{
- if (v < 0) v = 0;
- else if (v > 100) v = 100;
+ game_music = std::clamp(v, 0, 100);
+}
- efx_volume = v;
+void
+AudioConfig::SetEfxVolume(int v)
+{
+ efx_volume = std::clamp(v, 0, 100);
}
void
AudioConfig::SetGuiVolume(int v)
{
- if (v < 0) v = 0;
- else if (v > 100) v = 100;
-
- gui_volume = v;
- Button::SetVolume(-50 * (100 - gui_volume));
+ gui_volume = std::clamp(v, 0, 100);
+ Button::SetVolume(GuiVolume());
}
void
AudioConfig::SetWrnVolume(int v)
{
- if (v < 0) v = 0;
- else if (v > 100) v = 100;
-
- wrn_volume = v;
- Button::SetVolume(-50 * (100 - wrn_volume));
+ wrn_volume = std::clamp(v, 0, 100);
}
void
AudioConfig::SetVoxVolume(int v)
{
- if (v < 0) v = 0;
- else if (v > 100) v = 100;
-
- vox_volume = v;
+ vox_volume = std::clamp(v, 0, 100);
}
// +--------------------------------------------------------------------+
@@ -274,72 +289,49 @@ AudioConfig::Load()
TermDef* def = term->isDef();
if (def) {
- if (def->name()->value() == "menu_music") {
+ if (def->name()->value() == "master_volume") {
GetDefNumber(v, def, filename);
+ SetMasterVolume(v);
+ }
- if (v < 0 || v > 100) {
- Print("WARNING: Invalid menu_music (%d) in '%s'\n", v, filename);
- }
- else {
- menu_music = v;
- }
+ if (def->name()->value() == "music_volume") {
+ GetDefNumber(v, def, filename);
+ SetMusicVolume(v);
}
- else if (def->name()->value() == "game_music") {
+ if (def->name()->value() == "world_volume") {
+ GetDefNumber(v, def, filename);
+ SetWorldVolume(v);
+ }
+
+ if (def->name()->value() == "menu_music") {
GetDefNumber(v, def, filename);
+ SetMenuMusic(v);
+ }
- if (v < 0 || v > 100) {
- Print("WARNING: Invalid game_music (%d) in '%s'\n", v, filename);
- }
- else {
- game_music = v;
- }
+ else if (def->name()->value() == "game_music") {
+ GetDefNumber(v, def, filename);
+ SetGameMusic(v);
}
else if (def->name()->value() == "efx_volume") {
GetDefNumber(v, def, filename);
-
- if (v < 0 || v > 100) {
- Print("WARNING: Invalid efx_volume (%d) in '%s'\n", v, filename);
- }
- else {
- efx_volume = v;
- }
+ SetEfxVolume(v);
}
else if (def->name()->value() == "gui_volume") {
GetDefNumber(v, def, filename);
-
- if (v < 0 || v > 100) {
- Print("WARNING: Invalid gui_volume (%d) in '%s'\n", v, filename);
- }
- else {
- gui_volume = v;
-
- Button::SetVolume(-50 * (100 - gui_volume));
- }
+ SetGuiVolume(v);
}
else if (def->name()->value() == "wrn_volume") {
GetDefNumber(v, def, filename);
-
- if (v < 0 || v > 100) {
- Print("WARNING: Invalid wrn_volume (%d) in '%s'\n", v, filename);
- }
- else {
- wrn_volume = v;
- }
+ SetWrnVolume(v);
}
else if (def->name()->value() == "vox_volume") {
GetDefNumber(v, def, filename);
-
- if (v < 0 || v > 100) {
- Print("WARNING: Invalid vox_volume (%d) in '%s'\n", v, filename);
- }
- else {
- vox_volume = v;
- }
+ SetVoxVolume(v);
}
else
@@ -366,6 +358,9 @@ AudioConfig::Save()
fopen_s(&f, "audio.cfg", "wb");
if (f) {
fprintf(f, "AUDIO\n\n");
+ fprintf(f, "master_volume: %3d\n", master_volume);
+ fprintf(f, "music_volume: %3d\n", music_volume);
+ fprintf(f, "world_volume: %3d\n\n", world_volume);
fprintf(f, "menu_music: %3d\n", menu_music);
fprintf(f, "game_music: %3d\n\n", game_music);
fprintf(f, "efx_volume: %3d\n", efx_volume);
diff --git a/StarsEx/AudioConfig.h b/StarsEx/AudioConfig.h
index f721592..1f01868 100644
--- a/StarsEx/AudioConfig.h
+++ b/StarsEx/AudioConfig.h
@@ -40,6 +40,9 @@ public:
static int Silence();
static void SetTraining(bool t);
+ int GetMasterVolume() const { return master_volume; }
+ int GetMusicVolume() const { return music_volume; }
+ int GetWorldVolume() const { return world_volume; }
int GetMenuMusic() const { return menu_music; }
int GetGameMusic() const { return game_music; }
int GetEfxVolume() const { return efx_volume; }
@@ -47,6 +50,9 @@ public:
int GetWrnVolume() const { return wrn_volume; }
int GetVoxVolume() const { return vox_volume; }
+ void SetMasterVolume(int v);
+ void SetMusicVolume(int v);
+ void SetWorldVolume(int v);
void SetMenuMusic(int v);
void SetGameMusic(int v);
void SetEfxVolume(int v);
@@ -55,6 +61,10 @@ public:
void SetVoxVolume(int v);
protected:
+ int master_volume;
+ int music_volume;
+ int world_volume;
+
int menu_music;
int game_music;
diff --git a/StarsEx/test/AudioConfig.cpp b/StarsEx/test/AudioConfig.cpp
index f6a05d4..8de3b68 100644
--- a/StarsEx/test/AudioConfig.cpp
+++ b/StarsEx/test/AudioConfig.cpp
@@ -9,8 +9,18 @@ TEST(StarsEx, AudioConfig)
ASSERT_EQ(&audio, AudioConfig::GetInstance());
audio.SetMenuMusic(100);
ASSERT_EQ(0, AudioConfig::MenuMusic());
- audio.SetMenuMusic(50);
+ audio.SetMasterVolume(50);
ASSERT_EQ(-2500, AudioConfig::MenuMusic());
+ audio.SetMusicVolume(50);
+ ASSERT_EQ(-3750, AudioConfig::MenuMusic());
audio.SetMenuMusic(0);
ASSERT_EQ(-5000, AudioConfig::MenuMusic());
+ audio.SetEfxVolume(100);
+ ASSERT_EQ(-2500, AudioConfig::EfxVolume());
+ audio.SetMasterVolume(100);
+ ASSERT_EQ(0, AudioConfig::EfxVolume());
+ audio.SetWorldVolume(20);
+ ASSERT_EQ(-4000, AudioConfig::EfxVolume());
+ audio.SetEfxVolume(50);
+ ASSERT_EQ(-4500, AudioConfig::EfxVolume());
}
diff --git a/data/content/Content/content.txt b/data/content/Content/content.txt
index 2a16b75..d37a367 100644
--- a/data/content/Content/content.txt
+++ b/data/content/Content/content.txt
@@ -597,6 +597,9 @@ form.options.tab.controls = Controls
form.options.tab.gameplay = Gameplay
form.options.tab.mods = Mod Config
+form.audio.volume.master = Master Volume:
+form.audio.volume.music = Music Volume:
+form.audio.volume.world = World Volume:
form.audio.volume.effects = Effects Volume:
form.audio.volume.gui = GUI Volume:
form.audio.volume.warning = Warning Volume:
diff --git a/data/content/Screens/AudDlg.frm b/data/content/Screens/AudDlg.frm
index cb99410..8f82287 100644
--- a/data/content/Screens/AudDlg.frm
+++ b/data/content/Screens/AudDlg.frm
@@ -148,8 +148,8 @@ form: {
x_mins: ( 20, 100, 100, 20, 100, 100, 20)
x_weights: (0.2, 0.3, 0.3, 0.2, 0.3, 0.3, 0.2)
- y_mins: ( 20, 25, 25, 25, 25, 25, 25, 25, 20)
- y_weights: (0.3, 0, 0, 0, 0, 0, 0, 0, 0.7)
+ y_mins: ( 20, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 20)
+ y_weights: (0.3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.7)
}
}
@@ -164,11 +164,35 @@ form: {
},
ctrl: {
+ id: 107
+ pid: 300
+ type: label
+ text: "form.audio.volume.master"
+ cells: (1,1,1,1)
+ },
+
+ ctrl: {
+ id: 108
+ pid: 300
+ type: label
+ text: "form.audio.volume.music"
+ cells: (1,2,1,1)
+ },
+
+ ctrl: {
+ id: 109
+ pid: 300
+ type: label
+ text: "form.audio.volume.world"
+ cells: (1,3,1,1)
+ },
+
+ ctrl: {
id: 101
pid: 300
type: label
text: "form.audio.volume.effects"
- cells: (1,1,1,1)
+ cells: (1,4,1,1)
},
ctrl: {
@@ -176,7 +200,7 @@ form: {
pid: 300
type: label
text: "form.audio.volume.gui"
- cells: (1,2,1,1)
+ cells: (1,5,1,1)
},
ctrl: {
@@ -184,7 +208,7 @@ form: {
pid: 300
type: label
text: "form.audio.volume.warning"
- cells: (1,3,1,1)
+ cells: (1,6,1,1)
},
ctrl: {
@@ -192,7 +216,7 @@ form: {
pid: 300
type: label
text: "form.audio.volume.vox"
- cells: (1,4,1,1)
+ cells: (1,7,1,1)
},
ctrl: {
@@ -200,7 +224,7 @@ form: {
pid: 300
type: label
text: "form.audio.music.menu"
- cells: (1,6,1,1)
+ cells: (1,8,1,1)
},
ctrl: {
@@ -208,7 +232,7 @@ form: {
pid: 300
type: label
text: "form.audio.music.game"
- cells: (1,7,1,1)
+ cells: (1,9,1,1)
},
defctrl: {
@@ -225,47 +249,68 @@ form: {
},
ctrl: {
- id: 201
+ id: 207
pid: 300
type: slider
cells: (2,1,1,1)
},
ctrl: {
- id: 202
+ id: 208
pid: 300
type: slider
cells: (2,2,1,1)
},
ctrl: {
- id: 203
+ id: 209
pid: 300
type: slider
cells: (2,3,1,1)
},
ctrl: {
- id: 204
+ id: 201
pid: 300
type: slider
cells: (2,4,1,1)
},
ctrl: {
- id: 205
+ id: 202
+ pid: 300
+ type: slider
+ cells: (2,5,1,1)
+ },
+
+ ctrl: {
+ id: 203
pid: 300
type: slider
cells: (2,6,1,1)
},
ctrl: {
- id: 206
+ id: 204
pid: 300
type: slider
cells: (2,7,1,1)
},
+ ctrl: {
+ id: 205
+ pid: 300
+ type: slider
+ cells: (2,8,1,1)
+ },
+
+ ctrl: {
+ id: 206
+ pid: 300
+ type: slider
+ cells: (2,9,1,1)
+ },
+
// buttons:
diff --git a/data/shatter/Screens/AudDlg.frm b/data/shatter/Screens/AudDlg.frm
index f18b128..5822954 100644
--- a/data/shatter/Screens/AudDlg.frm
+++ b/data/shatter/Screens/AudDlg.frm
@@ -148,8 +148,8 @@ form: {
x_mins: ( 20, 100, 100, 20, 100, 100, 20)
x_weights: (0.2, 0.3, 0.3, 0.2, 0.3, 0.3, 0.2)
- y_mins: ( 20, 25, 25, 25, 25, 25, 25, 25, 20)
- y_weights: (0.3, 0, 0, 0, 0, 0, 0, 0, 0.7)
+ y_mins: ( 20, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 20)
+ y_weights: (0.3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.7)
}
}
@@ -164,11 +164,35 @@ form: {
},
ctrl: {
+ id: 107
+ pid: 300
+ type: label
+ text: "Master Volume:"
+ cells: (1,1,1,1)
+ },
+
+ ctrl: {
+ id: 108
+ pid: 300
+ type: label
+ text: "Music Volume:"
+ cells: (1,2,1,1)
+ },
+
+ ctrl: {
+ id: 109
+ pid: 300
+ type: label
+ text: "World Volume:"
+ cells: (1,3,1,1)
+ },
+
+ ctrl: {
id: 101
pid: 300
type: label
text: "Effects Volume:"
- cells: (1,1,1,1)
+ cells: (1,4,1,1)
},
ctrl: {
@@ -176,7 +200,7 @@ form: {
pid: 300
type: label
text: "GUI Volume:"
- cells: (1,2,1,1)
+ cells: (1,5,1,1)
},
ctrl: {
@@ -184,7 +208,7 @@ form: {
pid: 300
type: label
text: "Warning Volume:"
- cells: (1,3,1,1)
+ cells: (1,6,1,1)
},
ctrl: {
@@ -192,7 +216,7 @@ form: {
pid: 300
type: label
text: "Vox Volume:"
- cells: (1,4,1,1)
+ cells: (1,7,1,1)
},
ctrl: {
@@ -200,7 +224,7 @@ form: {
pid: 300
type: label
text: "Menu Music:"
- cells: (1,6,1,1)
+ cells: (1,8,1,1)
},
ctrl: {
@@ -208,7 +232,7 @@ form: {
pid: 300
type: label
text: "In Game Music:"
- cells: (1,7,1,1)
+ cells: (1,9,1,1)
},
defctrl: {
@@ -228,42 +252,42 @@ form: {
id: 201
pid: 300
type: slider
- cells: (2,1,1,1)
+ cells: (2,4,1,1)
},
ctrl: {
id: 202
pid: 300
type: slider
- cells: (2,2,1,1)
+ cells: (2,5,1,1)
},
ctrl: {
id: 203
pid: 300
type: slider
- cells: (2,3,1,1)
+ cells: (2,6,1,1)
},
ctrl: {
id: 204
pid: 300
type: slider
- cells: (2,4,1,1)
+ cells: (2,7,1,1)
},
ctrl: {
id: 205
pid: 300
type: slider
- cells: (2,6,1,1)
+ cells: (2,8,1,1)
},
ctrl: {
id: 206
pid: 300
type: slider
- cells: (2,7,1,1)
+ cells: (2,9,1,1)
},