From 5f6eb5e4403569065f87115e722fe3be9b8bf49b Mon Sep 17 00:00:00 2001
From: riso <4726939+risostk@users.noreply.github.com>
Date: Fri, 25 Dec 2020 13:29:56 -0600
Subject: [PATCH] Few improvements of spinner and option UI (#4453)
* few improvements of option UI
* small fix
* show the correct spinner text when not activated
* camera name for translation
* clean the code (loop camera spinner)
---
.../gui/dialogs/custom_camera_settings.stkgui | 2 +-
src/guiengine/widgets/spinner_widget.cpp | 11 +-------
.../dialogs/custom_camera_settings.cpp | 12 +++++++++
.../options/options_screen_audio.cpp | 16 ++++++++++++
.../options/options_screen_ui.cpp | 26 +++++++++++--------
5 files changed, 45 insertions(+), 22 deletions(-)
diff --git a/data/gui/dialogs/custom_camera_settings.stkgui b/data/gui/dialogs/custom_camera_settings.stkgui
index 2837d19c9..63c5a02d6 100644
--- a/data/gui/dialogs/custom_camera_settings.stkgui
+++ b/data/gui/dialogs/custom_camera_settings.stkgui
@@ -5,7 +5,7 @@
-
+
diff --git a/src/guiengine/widgets/spinner_widget.cpp b/src/guiengine/widgets/spinner_widget.cpp
index b0f553178..9d92b3d89 100644
--- a/src/guiengine/widgets/spinner_widget.cpp
+++ b/src/guiengine/widgets/spinner_widget.cpp
@@ -417,7 +417,7 @@ void SpinnerWidget::setValue(const int new_value)
std::string imagefile = file_manager->searchTexture(s);
((IGUIImage*)(m_children[1].m_element))->setImage(irr_driver->getTexture(imagefile));
}
- else if (m_labels.size() > 0 && m_children.size() > 0 && !m_deactivated)
+ else if (m_labels.size() > 0 && m_children.size() > 0)
{
assert(new_value >= 0);
assert(new_value < (int)m_labels.size());
@@ -502,15 +502,6 @@ void SpinnerWidget::setActive(bool active)
setCustomText(m_custom_text);
}
}
- else
- {
- // Save it temporary because setValue(which is uses for update in
- // this case) overwrites it
- core::stringw custom_text = m_custom_text;
- setText(L"-");
- setValue(getValue()); // Update the display
- m_custom_text = custom_text;
- }
} // setActive
// -----------------------------------------------------------------------------
diff --git a/src/states_screens/dialogs/custom_camera_settings.cpp b/src/states_screens/dialogs/custom_camera_settings.cpp
index 679e387f2..41a59b9f2 100644
--- a/src/states_screens/dialogs/custom_camera_settings.cpp
+++ b/src/states_screens/dialogs/custom_camera_settings.cpp
@@ -19,6 +19,7 @@
#include "config/user_config.hpp"
#include "guiengine/widgets/check_box_widget.hpp"
+#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/spinner_widget.hpp"
#include "states_screens/options/options_screen_ui.hpp"
#include "utils/translation.hpp"
@@ -62,6 +63,11 @@ void CustomCameraSettingsDialog::beforeAddingWidgets()
getWidget("backward_camera_angle")->setRange(0 , 45);
if (UserConfigParams::m_camera_present == 1) // Standard camera
{
+ getWidget("camera_name")->setText(_("Standard"), false);
+ getWidget("fov")->setValue(UserConfigParams::m_standard_camera_fov);
+ getWidget("camera_distance")->setFloatValue(UserConfigParams::m_standard_camera_distance);
+ getWidget("camera_angle")->setValue(UserConfigParams::m_standard_camera_forward_up_angle);
+ getWidget("backward_camera_angle")->setValue(UserConfigParams::m_standard_camera_backward_up_angle);
getWidget("camera_smoothing")->setState(UserConfigParams::m_standard_camera_forward_smoothing);
getWidget("use_soccer_camera")->setState(UserConfigParams::m_standard_reverse_look_use_soccer_cam);
// Not allowed to change fov, distance, and angles. Only allow to change smoothing and follow soccer
@@ -72,6 +78,11 @@ void CustomCameraSettingsDialog::beforeAddingWidgets()
}
else if (UserConfigParams::m_camera_present == 2) // Drone chase camera
{
+ getWidget("camera_name")->setText(_("Drone chase"), false);
+ getWidget("fov")->setValue(UserConfigParams::m_drone_camera_fov);
+ getWidget("camera_distance")->setFloatValue(UserConfigParams::m_drone_camera_distance);
+ getWidget("camera_angle")->setValue(UserConfigParams::m_drone_camera_forward_up_angle);
+ getWidget("backward_camera_angle")->setValue(UserConfigParams::m_drone_camera_backward_up_angle);
getWidget("camera_smoothing")->setState(UserConfigParams::m_drone_camera_forward_smoothing);
getWidget("use_soccer_camera")->setState(UserConfigParams::m_drone_reverse_look_use_soccer_cam);
// Not allowed to change fov, distance, and angles. Only allow to change smoothing and follow soccer
@@ -82,6 +93,7 @@ void CustomCameraSettingsDialog::beforeAddingWidgets()
}
else // Custom camera
{
+ getWidget("camera_name")->setText(_("Custom"), false);
getWidget("fov")->setValue(UserConfigParams::m_saved_camera_fov);
getWidget("camera_distance")->setFloatValue(UserConfigParams::m_saved_camera_distance);
getWidget("camera_angle")->setValue(UserConfigParams::m_saved_camera_forward_up_angle);
diff --git a/src/states_screens/options/options_screen_audio.cpp b/src/states_screens/options/options_screen_audio.cpp
index 5f5d4f56b..6efc86fa1 100644
--- a/src/states_screens/options/options_screen_audio.cpp
+++ b/src/states_screens/options/options_screen_audio.cpp
@@ -83,6 +83,11 @@ void OptionsScreenAudio::init()
sfx->setState( UserConfigParams::m_sfx );
music->setState( UserConfigParams::m_music );
+ if(!UserConfigParams::m_sfx)
+ getWidget("sfx_volume")->setActive(false);
+ if(!UserConfigParams::m_music)
+ getWidget("music_volume")->setActive(false);
+
} // init
// -----------------------------------------------------------------------------
@@ -155,9 +160,15 @@ void OptionsScreenAudio::eventCallback(Widget* widget, const std::string& name,
Log::info("OptionsScreenAudio", "Music is now %s", ((bool) UserConfigParams::m_music) ? "on" : "off");
if(w->getState() == false)
+ {
music_manager->stopMusic();
+ getWidget("music_volume")->setActive(false);
+ }
else
+ {
music_manager->startMusic();
+ getWidget("music_volume")->setActive(true);
+ }
}
else if(name == "sfx_enabled")
{
@@ -169,6 +180,11 @@ void OptionsScreenAudio::eventCallback(Widget* widget, const std::string& name,
if (UserConfigParams::m_sfx)
{
SFXManager::get()->quickSound("horn");
+ getWidget("sfx_volume")->setActive(true);
+ }
+ else
+ {
+ getWidget("sfx_volume")->setActive(false);
}
}
} // eventCallback
diff --git a/src/states_screens/options/options_screen_ui.cpp b/src/states_screens/options/options_screen_ui.cpp
index 51fc18dbc..f11543dd6 100644
--- a/src/states_screens/options/options_screen_ui.cpp
+++ b/src/states_screens/options/options_screen_ui.cpp
@@ -150,6 +150,20 @@ void OptionsScreenUI::loadedFromFile()
font_size->m_properties[GUIEngine::PROP_MAX_VALUE] = "5";
}
+ // Setup camera spinner
+ GUIEngine::SpinnerWidget* camera_preset = getWidget("camera_preset");
+ assert( camera_preset != NULL );
+
+ camera_preset->m_properties[PROP_WRAP_AROUND] = "true";
+ camera_preset->clearLabels();
+ //I18N: In the UI options, Camera setting: Custom
+ camera_preset->addLabel( core::stringw(_("Custom")));
+ //I18N: In the UI options, Camera setting: Standard
+ camera_preset->addLabel( core::stringw(_("Standard")));
+ //I18N: In the UI options, Camera setting: Drone chase
+ camera_preset->addLabel( core::stringw(_("Drone chase")));
+ camera_preset->m_properties[GUIEngine::PROP_MIN_VALUE] = "0";
+ camera_preset->m_properties[GUIEngine::PROP_MAX_VALUE] = "2";
updateCameraPresetSpinner();
font_size->setValueUpdatedCallback([this](SpinnerWidget* spinner)
@@ -339,21 +353,11 @@ void OptionsScreenUI::init()
irr_driver->setMaxTextureSize();
}
+ // --- select the right camera in the spinner
GUIEngine::SpinnerWidget* camera_preset = getWidget("camera_preset");
assert( camera_preset != NULL );
- camera_preset->m_properties[PROP_WRAP_AROUND] = "true";
- camera_preset->clearLabels();
- //I18N: In the UI options, Camera setting: Custom
- camera_preset->addLabel( core::stringw(_("Custom")));
- //I18N: In the UI options, Camera setting: Standard
- camera_preset->addLabel( core::stringw(_("Standard")));
- //I18N: In the UI options, Camera setting: Drone chase
- camera_preset->addLabel( core::stringw(_("Drone chase")));
- camera_preset->m_properties[GUIEngine::PROP_MIN_VALUE] = "1";
- camera_preset->m_properties[GUIEngine::PROP_MAX_VALUE] = "2";
camera_preset->setValue(UserConfigParams::m_camera_present); // use the saved camera
-
updateCameraPresetSpinner();
} // init