1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 14:59:54 +00:00

Avoid using Settings::Manager::set* functions directly

This commit is contained in:
elsid 2023-04-10 22:01:06 +02:00
parent 258ae9d98e
commit c5ab0c8b73
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625

View file

@ -168,10 +168,9 @@ namespace MWGui
std::string type = getSettingType(current); std::string type = getSettingType(current);
if (type == checkButtonType) if (type == checkButtonType)
{ {
std::string initialValue const std::string initialValue
= Settings::Manager::getBool(getSettingName(current), getSettingCategory(current)) = Settings::get<bool>(getSettingCategory(current), getSettingName(current)) ? "#{Interface:On}"
? "#{Interface:On}" : "#{Interface:Off}";
: "#{Interface:Off}";
current->castType<MyGUI::Button>()->setCaptionWithReplacing(initialValue); current->castType<MyGUI::Button>()->setCaptionWithReplacing(initialValue);
if (init) if (init)
current->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); current->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled);
@ -186,22 +185,28 @@ namespace MWGui
// TODO: ScrollBar isn't meant for this. should probably use a dedicated FloatSlider widget // TODO: ScrollBar isn't meant for this. should probably use a dedicated FloatSlider widget
float min, max; float min, max;
getSettingMinMax(scroll, min, max); getSettingMinMax(scroll, min, max);
float value = Settings::Manager::getFloat(getSettingName(current), getSettingCategory(current)); float value;
if (valueType == "Cell") if (valueType == "Cell")
{ {
value = Settings::get<float>(getSettingCategory(current), getSettingName(current));
std::stringstream ss; std::stringstream ss;
ss << std::fixed << std::setprecision(2) << value / Constants::CellSizeInUnits; ss << std::fixed << std::setprecision(2) << value / Constants::CellSizeInUnits;
valueStr = ss.str(); valueStr = ss.str();
} }
else if (valueType == "Float") else if (valueType == "Float")
{ {
value = Settings::get<float>(getSettingCategory(current), getSettingName(current));
std::stringstream ss; std::stringstream ss;
ss << std::fixed << std::setprecision(2) << value; ss << std::fixed << std::setprecision(2) << value;
valueStr = ss.str(); valueStr = ss.str();
} }
else else
valueStr = MyGUI::utility::toString(int(value)); {
const int intValue = Settings::get<int>(getSettingCategory(current), getSettingName(current));
valueStr = MyGUI::utility::toString(intValue);
value = static_cast<float>(intValue);
}
value = std::clamp(value, min, max); value = std::clamp(value, min, max);
value = (value - min) / (max - min); value = (value - min) / (max - min);
@ -210,7 +215,7 @@ namespace MWGui
} }
else else
{ {
int value = Settings::Manager::getInt(getSettingName(current), getSettingCategory(current)); const int value = Settings::get<int>(getSettingCategory(current), getSettingName(current));
valueStr = MyGUI::utility::toString(value); valueStr = MyGUI::utility::toString(value);
scroll->setScrollPosition(value); scroll->setScrollPosition(value);
} }
@ -656,7 +661,7 @@ namespace MWGui
if (getSettingType(_sender) == checkButtonType) if (getSettingType(_sender) == checkButtonType)
{ {
Settings::Manager::setBool(getSettingName(_sender), getSettingCategory(_sender), newState); Settings::get<bool>(getSettingCategory(_sender), getSettingName(_sender)).set(newState);
apply(); apply();
return; return;
} }
@ -693,9 +698,10 @@ namespace MWGui
getSettingMinMax(scroller, min, max); getSettingMinMax(scroller, min, max);
value = min + (max - min) * value; value = min + (max - min) * value;
if (valueType == "Float") if (valueType == "Float")
Settings::Manager::setFloat(getSettingName(scroller), getSettingCategory(scroller), value); Settings::get<float>(getSettingCategory(scroller), getSettingName(scroller)).set(value);
else else
Settings::Manager::setInt(getSettingName(scroller), getSettingCategory(scroller), (int)value); Settings::get<int>(getSettingCategory(scroller), getSettingName(scroller))
.set(static_cast<int>(value));
if (valueType == "Cell") if (valueType == "Cell")
{ {
@ -714,7 +720,7 @@ namespace MWGui
} }
else else
{ {
Settings::Manager::setInt(getSettingName(scroller), getSettingCategory(scroller), pos); Settings::get<int>(getSettingCategory(scroller), getSettingName(scroller)).set(pos);
valueStr = MyGUI::utility::toString(pos); valueStr = MyGUI::utility::toString(pos);
} }
updateSliderLabel(scroller, valueStr); updateSliderLabel(scroller, valueStr);