add mute option to settings

This commit is contained in:
SimoneN64
2023-06-28 09:49:58 +02:00
parent 9242fe986f
commit cc7e9bc464
2 changed files with 17 additions and 17 deletions

View File

@@ -28,18 +28,23 @@ Settings::Settings() {
settingsFile = std::fstream("resources/settings.json", std::fstream::in | std::fstream::out); settingsFile = std::fstream("resources/settings.json", std::fstream::in | std::fstream::out);
settings = json::parse(settingsFile); settings = json::parse(settingsFile);
checkjsonentry(volumeR, float, "audio", "volumeR", 0.5); checkjsonentry(oldVolumeL, float, "audio", "volumeL", 0.5);
checkjsonentry(volumeL, float, "audio", "volumeL", 0.5); volumeL = oldVolumeL;
checkjsonentry(oldVolumeR, float, "audio", "volumeR", 0.5);
volumeR = oldVolumeR;
checkjsonentry(mute, bool, "audio", "mute", false);
checkjsonentry(lockChannels, bool, "audio", "lockChannels", true); checkjsonentry(lockChannels, bool, "audio", "lockChannels", true);
} else { } else {
settingsFile = std::fstream("resources/settings.json", std::fstream::trunc | std::fstream::in | std::fstream::out); settingsFile = std::fstream("resources/settings.json", std::fstream::trunc | std::fstream::in | std::fstream::out);
settings["audio"]["volumeR"] = 0.5; settings["audio"]["volumeR"] = 0.5;
settings["audio"]["volumeL"] = 0.5; settings["audio"]["volumeL"] = 0.5;
settings["audio"]["lockChannels"] = true; settings["audio"]["lockChannels"] = true;
settings["audio"]["mute"] = false;
volumeR = 0.5; oldVolumeR = volumeR = 0.5;
volumeL = 0.5; oldVolumeL = volumeL = 0.5;
lockChannels = true; lockChannels = true;
mute = false;
settingsFile << settings; settingsFile << settings;
} }
@@ -51,26 +56,21 @@ Settings::~Settings() {
std::fstream settingsFile; std::fstream settingsFile;
if(fileExists) { if(fileExists) {
settingsFile = std::fstream("resources/settings.json", std::fstream::trunc | std::fstream::out); settingsFile = std::fstream("resources/settings.json", std::fstream::trunc | std::fstream::out);
settings["audio"]["volumeR"] = volumeR;
settings["audio"]["volumeL"] = volumeL;
settings["audio"]["lockChannels"] = lockChannels;
settingsFile << settings;
} else { } else {
settingsFile = std::fstream("resources/settings.json", std::fstream::out); settingsFile = std::fstream("resources/settings.json", std::fstream::out);
settings["audio"]["volumeR"] = volumeR;
settings["audio"]["volumeL"] = volumeL;
settings["audio"]["lockChannels"] = lockChannels;
settingsFile << settings;
} }
settings["audio"]["volumeR"] = oldVolumeR;
settings["audio"]["volumeL"] = oldVolumeL;
settings["audio"]["lockChannels"] = lockChannels;
settings["audio"]["mute"] = mute;
settingsFile << settings;
settingsFile.close(); settingsFile.close();
} }
void Settings::RenderWidget(bool& show) { void Settings::RenderWidget(bool& show) {
if(show) { if(show) {
static float oldVolumeL = volumeL, oldVolumeR = volumeR;
ImGui::OpenPopup("Settings"); ImGui::OpenPopup("Settings");
if(ImGui::BeginPopupModal("Settings", &show)) { if(ImGui::BeginPopupModal("Settings", &show)) {
enum class SelectedSetting { Audio, COUNT }; enum class SelectedSetting { Audio, COUNT };

View File

@@ -11,11 +11,11 @@ struct Settings {
[[nodiscard]] FORCE_INLINE float GetVolumeL() const { return volumeL; }; [[nodiscard]] FORCE_INLINE float GetVolumeL() const { return volumeL; };
[[nodiscard]] FORCE_INLINE float GetVolumeR() const { return volumeR; }; [[nodiscard]] FORCE_INLINE float GetVolumeR() const { return volumeR; };
[[nodiscard]] FORCE_INLINE bool GetLockChannels() const { return lockChannels; }
void RenderWidget(bool& show); void RenderWidget(bool& show);
private: private:
float volumeL = 0.0, volumeR = 0.0; float volumeL, volumeR;
float oldVolumeL, oldVolumeR;
bool lockChannels = true; bool lockChannels = true;
bool mute = false; bool mute = false;
json settings; json settings;