6
#include "Precompiled.h"
7
#include "SettingsGeneralControl.h"
8
#include "SettingsManager.h"
12
SettingsGeneralControl::SettingsGeneralControl(MyGUI::Widget* _parent) :
13
wraps::BaseLayout("SettingsGeneralControl.layout", _parent),
16
mSaveLastTexture(nullptr),
17
mInterfaceLanguage(nullptr)
19
assignWidget(mGridEdit, "gridEdit");
20
assignWidget(mSaveLastTexture, "SaveLastTexture");
21
assignWidget(mInterfaceLanguage, "InterfaceLanguage");
23
mGridEdit->eventEditSelectAccept += MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStepAccept);
24
mGridEdit->eventKeyLostFocus += MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStep);
25
mSaveLastTexture->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsGeneralControl::notifyMouseButtonClick);
28
SettingsGeneralControl::~SettingsGeneralControl()
30
mSaveLastTexture->eventMouseButtonClick -= MyGUI::newDelegate(this, &SettingsGeneralControl::notifyMouseButtonClick);
31
mGridEdit->eventEditSelectAccept -= MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStepAccept);
32
mGridEdit->eventKeyLostFocus -= MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStep);
35
void SettingsGeneralControl::loadSettings()
37
mGridStep = SettingsManager::getInstance().getSector("Settings")->getPropertyValue<int>("Grid");
38
mGridEdit->setCaption(MyGUI::utility::toString(mGridStep));
39
mSaveLastTexture->setStateSelected(SettingsManager::getInstance().getSector("Settings")->getPropertyValue<bool>("SaveLastTexture"));
40
setLanguageValue(SettingsManager::getInstance().getSector("Settings")->getPropertyValue("InterfaceLanguage"));
43
void SettingsGeneralControl::saveSettings()
45
SettingsManager::getInstance().getSector("Settings")->setPropertyValue("Grid", mGridStep);
46
SettingsManager::getInstance().getSector("Settings")->setPropertyValue("SaveLastTexture", mSaveLastTexture->getStateSelected());
47
SettingsManager::getInstance().getSector("Settings")->setPropertyValue("InterfaceLanguage", getLanguageValue());
50
void SettingsGeneralControl::notifyNewGridStep(MyGUI::Widget* _sender, MyGUI::Widget* _new)
52
mGridStep = MyGUI::utility::parseInt(mGridEdit->getOnlyText());
53
mGridStep = std::max(1, mGridStep);
54
mGridEdit->setCaption(MyGUI::utility::toString(mGridStep));
57
void SettingsGeneralControl::notifyNewGridStepAccept(MyGUI::EditBox* _sender)
59
notifyNewGridStep(_sender);
62
void SettingsGeneralControl::notifyMouseButtonClick(MyGUI::Widget* _sender)
64
MyGUI::Button* button = _sender->castType<MyGUI::Button>(false);
65
if (button != nullptr)
66
button->setStateSelected(!button->getStateSelected());
69
void SettingsGeneralControl::setLanguageValue(const std::string& _value)
71
for (size_t index = 0; index < mInterfaceLanguage->getItemCount(); index ++)
73
if (mInterfaceLanguage->getItemNameAt(index) == _value)
75
mInterfaceLanguage->setIndexSelected(index);
79
for (size_t index = 0; index < mInterfaceLanguage->getItemCount(); index ++)
81
if (mInterfaceLanguage->getItemNameAt(index) == "Auto")
83
mInterfaceLanguage->setIndexSelected(index);
89
std::string SettingsGeneralControl::getLanguageValue()
91
if (mInterfaceLanguage->getIndexSelected() == MyGUI::ITEM_NONE)
93
return mInterfaceLanguage->getItemNameAt(mInterfaceLanguage->getIndexSelected());
7
#include "Precompiled.h"
8
#include "SettingsGeneralControl.h"
9
#include "SettingsManager.h"
10
#include "FactoryManager.h"
15
FACTORY_ITEM_ATTRIBUTE(SettingsGeneralControl)
17
SettingsGeneralControl::SettingsGeneralControl() :
20
mSaveLastTexture(nullptr),
21
mInterfaceLanguage(nullptr)
25
SettingsGeneralControl::~SettingsGeneralControl()
27
mSaveLastTexture->eventMouseButtonClick -= MyGUI::newDelegate(this, &SettingsGeneralControl::notifyMouseButtonClick);
28
mGridEdit->eventEditSelectAccept -= MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStepAccept);
29
mGridEdit->eventKeyLostFocus -= MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStep);
32
void SettingsGeneralControl::OnInitialise(Control* _parent, MyGUI::Widget* _place, const std::string& _layoutName)
34
Control::OnInitialise(_parent, _place, _layoutName);
36
assignWidget(mGridEdit, "gridEdit");
37
assignWidget(mSaveLastTexture, "SaveLastTexture");
38
assignWidget(mInterfaceLanguage, "InterfaceLanguage");
40
mGridEdit->eventEditSelectAccept += MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStepAccept);
41
mGridEdit->eventKeyLostFocus += MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStep);
42
mSaveLastTexture->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsGeneralControl::notifyMouseButtonClick);
45
void SettingsGeneralControl::loadSettings()
47
mGridStep = SettingsManager::getInstance().getValue<int>("Settings/GridStep");
48
mGridEdit->setCaption(MyGUI::utility::toString(mGridStep));
49
mSaveLastTexture->setStateSelected(SettingsManager::getInstance().getValue<bool>("Settings/SaveLastTexture"));
50
setLanguageValue(SettingsManager::getInstance().getValue("Settings/InterfaceLanguage"));
53
void SettingsGeneralControl::saveSettings()
55
SettingsManager::getInstance().setValue("Settings/GridStep", mGridStep);
56
SettingsManager::getInstance().setValue("Settings/SaveLastTexture", mSaveLastTexture->getStateSelected());
57
SettingsManager::getInstance().setValue("Settings/InterfaceLanguage", getLanguageValue());
60
void SettingsGeneralControl::notifyNewGridStep(MyGUI::Widget* _sender, MyGUI::Widget* _new)
62
mGridStep = MyGUI::utility::parseInt(mGridEdit->getOnlyText());
63
mGridStep = (std::max)(1, mGridStep);
64
mGridEdit->setCaption(MyGUI::utility::toString(mGridStep));
67
void SettingsGeneralControl::notifyNewGridStepAccept(MyGUI::EditBox* _sender)
69
notifyNewGridStep(_sender);
72
void SettingsGeneralControl::notifyMouseButtonClick(MyGUI::Widget* _sender)
74
MyGUI::Button* button = _sender->castType<MyGUI::Button>(false);
75
if (button != nullptr)
76
button->setStateSelected(!button->getStateSelected());
79
void SettingsGeneralControl::setLanguageValue(const std::string& _value)
81
for (size_t index = 0; index < mInterfaceLanguage->getItemCount(); index ++)
83
if (mInterfaceLanguage->getItemNameAt(index) == _value)
85
mInterfaceLanguage->setIndexSelected(index);
89
for (size_t index = 0; index < mInterfaceLanguage->getItemCount(); index ++)
91
if (mInterfaceLanguage->getItemNameAt(index) == "Auto")
93
mInterfaceLanguage->setIndexSelected(index);
99
std::string SettingsGeneralControl::getLanguageValue()
101
if (mInterfaceLanguage->getIndexSelected() == MyGUI::ITEM_NONE)
103
return mInterfaceLanguage->getItemNameAt(mInterfaceLanguage->getIndexSelected());
106
void SettingsGeneralControl::OnCommand(const std::string& _command)
108
Control::OnCommand(_command);
110
if (_command == "Command_LoadSettings")
112
else if (_command == "Command_SaveSettings")