1 /*! 2 @file 3 @author Albert Semenov 4 @date 09/2010 5 */ 6 7 #include "Precompiled.h" 8 #include "SettingsGeneralControl.h" 9 #include "SettingsManager.h" 10 #include "FactoryManager.h" 11 12 namespace tools 13 { 14 FACTORY_ITEM_ATTRIBUTE(SettingsGeneralControl)15 FACTORY_ITEM_ATTRIBUTE(SettingsGeneralControl) 16 17 SettingsGeneralControl::SettingsGeneralControl() : 18 mGridStep(0), 19 mGridEdit(nullptr), 20 mSaveLastTexture(nullptr), 21 mInterfaceLanguage(nullptr) 22 { 23 } 24 ~SettingsGeneralControl()25 SettingsGeneralControl::~SettingsGeneralControl() 26 { 27 mSaveLastTexture->eventMouseButtonClick -= MyGUI::newDelegate(this, &SettingsGeneralControl::notifyMouseButtonClick); 28 mGridEdit->eventEditSelectAccept -= MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStepAccept); 29 mGridEdit->eventKeyLostFocus -= MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStep); 30 } 31 OnInitialise(Control * _parent,MyGUI::Widget * _place,const std::string & _layoutName)32 void SettingsGeneralControl::OnInitialise(Control* _parent, MyGUI::Widget* _place, const std::string& _layoutName) 33 { 34 Control::OnInitialise(_parent, _place, _layoutName); 35 36 assignWidget(mGridEdit, "gridEdit"); 37 assignWidget(mSaveLastTexture, "SaveLastTexture"); 38 assignWidget(mInterfaceLanguage, "InterfaceLanguage"); 39 40 mGridEdit->eventEditSelectAccept += MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStepAccept); 41 mGridEdit->eventKeyLostFocus += MyGUI::newDelegate(this, &SettingsGeneralControl::notifyNewGridStep); 42 mSaveLastTexture->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsGeneralControl::notifyMouseButtonClick); 43 } 44 loadSettings()45 void SettingsGeneralControl::loadSettings() 46 { 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")); 51 } 52 saveSettings()53 void SettingsGeneralControl::saveSettings() 54 { 55 SettingsManager::getInstance().setValue("Settings/GridStep", mGridStep); 56 SettingsManager::getInstance().setValue("Settings/SaveLastTexture", mSaveLastTexture->getStateSelected()); 57 SettingsManager::getInstance().setValue("Settings/InterfaceLanguage", getLanguageValue()); 58 } 59 notifyNewGridStep(MyGUI::Widget * _sender,MyGUI::Widget * _new)60 void SettingsGeneralControl::notifyNewGridStep(MyGUI::Widget* _sender, MyGUI::Widget* _new) 61 { 62 mGridStep = MyGUI::utility::parseInt(mGridEdit->getOnlyText()); 63 mGridStep = (std::max)(1, mGridStep); 64 mGridEdit->setCaption(MyGUI::utility::toString(mGridStep)); 65 } 66 notifyNewGridStepAccept(MyGUI::EditBox * _sender)67 void SettingsGeneralControl::notifyNewGridStepAccept(MyGUI::EditBox* _sender) 68 { 69 notifyNewGridStep(_sender); 70 } 71 notifyMouseButtonClick(MyGUI::Widget * _sender)72 void SettingsGeneralControl::notifyMouseButtonClick(MyGUI::Widget* _sender) 73 { 74 MyGUI::Button* button = _sender->castType<MyGUI::Button>(false); 75 if (button != nullptr) 76 button->setStateSelected(!button->getStateSelected()); 77 } 78 setLanguageValue(const std::string & _value)79 void SettingsGeneralControl::setLanguageValue(const std::string& _value) 80 { 81 for (size_t index = 0; index < mInterfaceLanguage->getItemCount(); index ++) 82 { 83 if (mInterfaceLanguage->getItemNameAt(index) == _value) 84 { 85 mInterfaceLanguage->setIndexSelected(index); 86 return; 87 } 88 } 89 for (size_t index = 0; index < mInterfaceLanguage->getItemCount(); index ++) 90 { 91 if (mInterfaceLanguage->getItemNameAt(index) == "Auto") 92 { 93 mInterfaceLanguage->setIndexSelected(index); 94 return; 95 } 96 } 97 } 98 getLanguageValue()99 std::string SettingsGeneralControl::getLanguageValue() 100 { 101 if (mInterfaceLanguage->getIndexSelected() == MyGUI::ITEM_NONE) 102 return "Auto"; 103 return mInterfaceLanguage->getItemNameAt(mInterfaceLanguage->getIndexSelected()); 104 } 105 OnCommand(const std::string & _command)106 void SettingsGeneralControl::OnCommand(const std::string& _command) 107 { 108 Control::OnCommand(_command); 109 110 if (_command == "Command_LoadSettings") 111 loadSettings(); 112 else if (_command == "Command_SaveSettings") 113 saveSettings(); 114 } 115 116 } 117