mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 20:50:06 +00:00
Save settings changes functionality
This commit is contained in:
parent
f7cc902eef
commit
6b90c5471d
3 changed files with 21 additions and 5 deletions
|
|
@ -24,6 +24,9 @@ static boost::json::value ConvertSettingsToJson();
|
||||||
static void GenerateDefaultSettings();
|
static void GenerateDefaultSettings();
|
||||||
static bool LoadSettings(const boost::json::object& settingsJson);
|
static bool LoadSettings(const boost::json::object& settingsJson);
|
||||||
|
|
||||||
|
static bool initialized_ {false};
|
||||||
|
static std::string settingsPath_ {};
|
||||||
|
|
||||||
void Initialize()
|
void Initialize()
|
||||||
{
|
{
|
||||||
std::string appDataPath {
|
std::string appDataPath {
|
||||||
|
|
@ -39,9 +42,10 @@ void Initialize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string settingsPath {appDataPath + "/settings.json"};
|
settingsPath_ = appDataPath + "/settings.json";
|
||||||
|
initialized_ = true;
|
||||||
|
|
||||||
ReadSettings(settingsPath);
|
ReadSettings(settingsPath_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadSettings(const std::string& settingsPath)
|
void ReadSettings(const std::string& settingsPath)
|
||||||
|
|
@ -71,6 +75,17 @@ void ReadSettings(const std::string& settingsPath)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SaveSettings()
|
||||||
|
{
|
||||||
|
if (initialized_)
|
||||||
|
{
|
||||||
|
logger_->info("Saving settings");
|
||||||
|
|
||||||
|
boost::json::value settingsJson = ConvertSettingsToJson();
|
||||||
|
util::json::WriteJsonFile(settingsPath_, settingsJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
settings::GeneralSettings& general_settings()
|
settings::GeneralSettings& general_settings()
|
||||||
{
|
{
|
||||||
static settings::GeneralSettings generalSettings_;
|
static settings::GeneralSettings generalSettings_;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ namespace SettingsManager
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void ReadSettings(const std::string& settingsPath);
|
void ReadSettings(const std::string& settingsPath);
|
||||||
|
void SaveSettings();
|
||||||
|
|
||||||
settings::GeneralSettings& general_settings();
|
settings::GeneralSettings& general_settings();
|
||||||
settings::MapSettings& map_settings();
|
settings::MapSettings& map_settings();
|
||||||
|
|
|
||||||
|
|
@ -373,7 +373,7 @@ void SettingsDialogImpl::UpdateRadarDialogLocation(const std::string& id)
|
||||||
|
|
||||||
void SettingsDialogImpl::ApplyChanges()
|
void SettingsDialogImpl::ApplyChanges()
|
||||||
{
|
{
|
||||||
logger_->info("Apply settings changes");
|
logger_->info("Applying settings changes");
|
||||||
|
|
||||||
bool committed = false;
|
bool committed = false;
|
||||||
|
|
||||||
|
|
@ -384,13 +384,13 @@ void SettingsDialogImpl::ApplyChanges()
|
||||||
|
|
||||||
if (committed)
|
if (committed)
|
||||||
{
|
{
|
||||||
logger_->info("Saving changes");
|
manager::SettingsManager::SaveSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialogImpl::DiscardChanges()
|
void SettingsDialogImpl::DiscardChanges()
|
||||||
{
|
{
|
||||||
logger_->info("Discard settings changes");
|
logger_->info("Discarding settings changes");
|
||||||
|
|
||||||
for (auto& setting : settings_)
|
for (auto& setting : settings_)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue