SettingsWindow: support auto-updating of slider labels through the layout file

coverity_scan
scrawl 9 years ago
parent ece40b1e96
commit 190bf15887

@ -130,12 +130,14 @@ namespace MWGui
if (type == sliderType)
{
MyGUI::ScrollBar* scroll = current->castType<MyGUI::ScrollBar>();
std::string valueStr;
if (getSettingValueType(current) == "Float")
{
// TODO: ScrollBar isn't meant for this. should probably use a dedicated FloatSlider widget
float min,max;
getSettingMinMax(scroll, min, max);
float value = Settings::Manager::getFloat(getSettingName(current), getSettingCategory(current));
valueStr = MyGUI::utility::toString((int)value);
value = std::max(min, std::min(value, max));
value = (value-min)/(max-min);
@ -144,15 +146,30 @@ namespace MWGui
else
{
int value = Settings::Manager::getInt(getSettingName(current), getSettingCategory(current));
valueStr = MyGUI::utility::toString(value);
scroll->setScrollPosition(value);
}
scroll->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition);
updateSliderLabel(scroll, valueStr);
}
configureWidgets(current);
}
}
void SettingsWindow::updateSliderLabel(MyGUI::ScrollBar *scroller, const std::string& value)
{
std::string labelWidgetName = scroller->getUserString("SettingLabelWidget");
if (!labelWidgetName.empty())
{
MyGUI::TextBox* textBox;
getWidget(textBox, labelWidgetName);
std::string labelCaption = scroller->getUserString("SettingLabelCaption");
boost::algorithm::replace_all(labelCaption, "%s", value);
textBox->setCaptionWithReplacing(labelCaption);
}
}
SettingsWindow::SettingsWindow() :
WindowBase("openmw_settings_window.layout"),
mKeyboardMode(true)
@ -167,17 +184,13 @@ namespace MWGui
getWidget(mFullscreenButton, "FullscreenButton");
getWidget(mVSyncButton, "VSyncButton");
getWidget(mWindowBorderButton, "WindowBorderButton");
getWidget(mFOVSlider, "FOVSlider");
getWidget(mAnisotropySlider, "AnisotropySlider");
getWidget(mTextureFilteringButton, "TextureFilteringButton");
getWidget(mAnisotropyLabel, "AnisotropyLabel");
getWidget(mAnisotropyBox, "AnisotropyBox");
getWidget(mShadersButton, "ShadersButton");
getWidget(mShadowsEnabledButton, "ShadowsEnabledButton");
getWidget(mShadowsTextureSize, "ShadowsTextureSize");
getWidget(mControlsBox, "ControlsBox");
getWidget(mResetControlsButton, "ResetControlsButton");
getWidget(mDifficultySlider, "DifficultySlider");
getWidget(mKeyboardSwitch, "KeyboardButton");
getWidget(mControllerSwitch, "ControllerButton");
getWidget(mWaterTextureSize, "WaterTextureSize");
@ -238,7 +251,6 @@ namespace MWGui
std::string tmip = Settings::Manager::getString("texture mipmap", "General");
mTextureFilteringButton->setCaption(textureMipmappingToStr(tmip));
mAnisotropyLabel->setCaption("Anisotropy (" + MyGUI::utility::toString(Settings::Manager::getInt("anisotropy", "General")) + ")");
int waterTextureSize = Settings::Manager::getInt ("rtt size", "Water");
if (waterTextureSize >= 512)
@ -255,15 +267,6 @@ namespace MWGui
mShadowsEnabledButton->setEnabled(false);
}
MyGUI::TextBox* fovText;
getWidget(fovText, "FovText");
fovText->setCaption("Field of View (" + MyGUI::utility::toString(int(Settings::Manager::getInt("field of view", "Camera"))) + ")");
MyGUI::TextBox* diffText;
getWidget(diffText, "DifficultyText");
diffText->setCaptionWithReplacing("#{sDifficulty} (" + MyGUI::utility::toString(int(Settings::Manager::getInt("difficulty", "Game"))) + ")");
mWindowBorderButton->setEnabled(!Settings::Manager::getBool("fullscreen", "Video"));
mKeyboardSwitch->setStateSelected(true);
@ -439,6 +442,7 @@ namespace MWGui
{
if (getSettingType(scroller) == "Slider")
{
std::string valueStr;
if (getSettingValueType(scroller) == "Float")
{
float value = pos / float(scroller->getScrollRange()-1);
@ -447,28 +451,15 @@ namespace MWGui
getSettingMinMax(scroller, min, max);
value = min + (max-min) * value;
Settings::Manager::setFloat(getSettingName(scroller), getSettingCategory(scroller), value);
if (scroller == mFOVSlider)
{
MyGUI::TextBox* fovText;
getWidget(fovText, "FovText");
fovText->setCaption("Field of View (" + MyGUI::utility::toString(int(value)) + ")");
}
if (scroller == mDifficultySlider)
{
MyGUI::TextBox* diffText;
getWidget(diffText, "DifficultyText");
diffText->setCaptionWithReplacing("#{sDifficulty} (" + MyGUI::utility::toString(int(value)) + ")");
}
valueStr = MyGUI::utility::toString(int(value));
}
else
{
Settings::Manager::setInt(getSettingName(scroller), getSettingCategory(scroller), pos);
if (scroller == mAnisotropySlider)
{
mAnisotropyLabel->setCaption("Anisotropy (" + MyGUI::utility::toString(pos) + ")");
}
valueStr = MyGUI::utility::toString(pos);
}
updateSliderLabel(scroller, valueStr);
apply();
}
}

@ -30,11 +30,7 @@ namespace MWGui
MyGUI::Button* mFullscreenButton;
MyGUI::Button* mVSyncButton;
MyGUI::Button* mWindowBorderButton;
MyGUI::ScrollBar* mFOVSlider;
MyGUI::ScrollBar* mDifficultySlider;
MyGUI::ScrollBar* mAnisotropySlider;
MyGUI::ComboBox* mTextureFilteringButton;
MyGUI::TextBox* mAnisotropyLabel;
MyGUI::Widget* mAnisotropyBox;
MyGUI::Button* mShadersButton;
@ -76,6 +72,7 @@ namespace MWGui
void apply();
void configureWidgets(MyGUI::Widget* widget);
void updateSliderLabel(MyGUI::ScrollBar* scroller, const std::string& value);
private:
void resetScrollbars();

@ -61,6 +61,8 @@
<UserString key="SettingValueType" value="Float"/>
<UserString key="SettingMin" value="-100"/>
<UserString key="SettingMax" value="100"/>
<UserString key="SettingLabelWidget" value="DifficultyText"/>
<UserString key="SettingLabelCaption" value="#{sDifficulty} (%s)"/>
</Widget>
<Widget type="TextBox" skin="SandText" position="0 38 352 16" align="Left Top">
<Property key="Caption" value="#{sEasy}"/>
@ -274,7 +276,6 @@
</Widget>
<Widget type="TextBox" skin="NormalText" position="0 198 329 18" align="Left Top" name="FovText">
<Property key="Caption" value="Field of View"/>
</Widget>
<Widget type="MWScrollBar" skin="MW_HScroll" position="0 222 329 18" align="HStretch Top" name="FOVSlider">
<Property key="Range" value="10000"/>
@ -285,6 +286,8 @@
<UserString key="SettingValueType" value="Float"/>
<UserString key="SettingMin" value="30"/>
<UserString key="SettingMax" value="110"/>
<UserString key="SettingLabelWidget" value="FovText"/>
<UserString key="SettingLabelCaption" value="Field of View (%s)"/>
</Widget>
<Widget type="TextBox" skin="SandText" position="0 246 329 18" align="Left Top">
<Property key="Caption" value="#{sLow}"/>
@ -334,6 +337,8 @@
<UserString key="SettingType" value="Slider"/>
<UserString key="SettingCategory" value="General"/>
<UserString key="SettingName" value="anisotropy"/>
<UserString key="SettingLabelWidget" value="AnisotropyLabel"/>
<UserString key="SettingLabelCaption" value="Anisotropy (%s)"/>
</Widget>
</Widget>
<Widget type="TextBox" skin="NormalText" position="4 130 322 18" align="Left Top">

Loading…
Cancel
Save