This commit is contained in:
Benau 2018-09-19 09:19:34 +08:00
parent afe2b6f2f4
commit 951c48292a
3 changed files with 78 additions and 14 deletions

View File

@ -5,12 +5,14 @@
<model id="model" width="100%" layout="horizontal-row" height="100%">
</model>
</div>
<label text="0 to use the original color, otherwise pick one from slider."
width="100%" text_align="center" word_wrap="true"
I18N="In the kart color slider dialog"/>
<div width="20%" height="fit" text-align="left" layout="horizontal-row" >
<checkbox id="toggle-slider" />
<spacer width="40"/>
<label id="toggle-text"/>
</div>
<spacer height="30" width="10"/>
<div height="fit" width="100%" layout="horizontal-row">
<gauge id="color-slider" min_value="0" max_value="100" proportion="1"/>
<gauge id="color-slider" min_value="1" max_value="100" proportion="1"/>
</div>
<spacer height="30" width="10"/>
<button id="close" text="Apply" align="center"/>

View File

@ -25,6 +25,8 @@
#include "graphics/irr_driver.hpp"
#include "graphics/render_info.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/widgets/check_box_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/model_view_widget.hpp"
#include "guiengine/widgets/spinner_widget.hpp"
#include "states_screens/state_manager.hpp"
@ -38,10 +40,29 @@ KartColorSliderDialog::KartColorSliderDialog(PlayerProfile* pp)
loadFromFile("kart_color_slider.stkgui");
m_player_profile = pp;
SpinnerWidget* color_slider = getWidget<SpinnerWidget>("color-slider");
color_slider->setValue(int(pp->getDefaultKartColor() * 100.0f));
m_model_view->getModelViewRenderInfo()->setHue(float(color_slider->getValue()) / 100.0f);
color_slider->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
// I18N: In kart color choosing dialog
m_original_color = _("Use original color");
// I18N: In kart color choosing dialog
m_choose_color = _("Pick a color from slider");
if (m_player_profile->getDefaultKartColor() != 0.0f)
{
m_toggle_slider->setState(true);
m_toggle_text->setText(m_choose_color, false);
m_color_slider->setActive(true);
m_color_slider->setValue(int(
m_player_profile->getDefaultKartColor() * 100.0f));
m_model_view->getModelViewRenderInfo()->setHue(
float(m_color_slider->getValue()) / 100.0f);
}
else
{
m_toggle_slider->setState(false);
m_toggle_text->setText(m_original_color, false);
m_color_slider->setActive(false);
m_model_view->getModelViewRenderInfo()->setHue(0.0f);
}
m_toggle_slider->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
} // KartColorSliderDialog
// ----------------------------------------------------------------------------
@ -127,22 +148,48 @@ void KartColorSliderDialog::beforeAddingWidgets()
m_model_view->setRotateContinuously(35.0f);
m_model_view->update(0);
m_toggle_slider = getWidget<CheckBoxWidget>("toggle-slider");
m_toggle_text = getWidget<LabelWidget>("toggle-text");
m_color_slider = getWidget<SpinnerWidget>("color-slider");
} // beforeAddingWidgets
// ----------------------------------------------------------------------------
void KartColorSliderDialog::toggleSlider()
{
if (m_toggle_slider->getState())
{
m_color_slider->setActive(true);
m_color_slider->setValue(100);
m_model_view->getModelViewRenderInfo()->setHue(1.0f);
m_toggle_text->setText(m_choose_color, false);
}
else
{
m_color_slider->setActive(false);
m_model_view->getModelViewRenderInfo()->setHue(0.0f);
m_toggle_text->setText(m_original_color, false);
}
} // toggleSlider
// ----------------------------------------------------------------------------
GUIEngine::EventPropagation
KartColorSliderDialog::processEvent(const std::string& eventSource)
{
if (eventSource == "color-slider")
if (eventSource == "toggle-slider")
{
toggleSlider();
}
else if (eventSource == "color-slider")
{
m_model_view->getModelViewRenderInfo()->setHue(float(
getWidget<SpinnerWidget>("color-slider")->getValue()) / 100.0f);
m_color_slider->getValue()) / 100.0f);
}
else if (eventSource == "close")
{
float color = float(getWidget<SpinnerWidget>("color-slider")
->getValue());
m_player_profile->setDefaultKartColor(color / 100.0f);
float color = 0.0f;
if (m_toggle_slider->getState())
color = float(m_color_slider->getValue()) / 100.0f;
m_player_profile->setDefaultKartColor(color);
ModalDialog::dismiss();
return GUIEngine::EVENT_BLOCK;
}

View File

@ -23,7 +23,13 @@
#include "utils/cpp2011.hpp"
class PlayerProfile;
namespace GUIEngine { class ModelViewWidget; }
namespace GUIEngine
{
class CheckBoxWidget;
class LabelWidget;
class ModelViewWidget;
class SpinnerWidget;
}
/**
* \ingroup states_screens
@ -33,8 +39,17 @@ class KartColorSliderDialog : public GUIEngine::ModalDialog
private:
PlayerProfile* m_player_profile;
GUIEngine::CheckBoxWidget* m_toggle_slider;
GUIEngine::LabelWidget* m_toggle_text;
GUIEngine::ModelViewWidget* m_model_view;
GUIEngine::SpinnerWidget* m_color_slider;
core::stringw m_original_color, m_choose_color;
void toggleSlider();
public:
KartColorSliderDialog(PlayerProfile* pp);