1 /*! 2 @file 3 @author Albert Semenov 4 @date 09/2010 5 */ 6 7 #include "Precompiled.h" 8 #include "SettingsUpdateResourcesControl.h" 9 #include "SettingsManager.h" 10 #include "Localise.h" 11 #include "FactoryManager.h" 12 13 namespace tools 14 { 15 FACTORY_ITEM_ATTRIBUTE(SettingsUpdateResourcesControl)16 FACTORY_ITEM_ATTRIBUTE(SettingsUpdateResourcesControl) 17 18 SettingsUpdateResourcesControl::SettingsUpdateResourcesControl() : 19 mResourceAdd(nullptr), 20 mResourceDelete(nullptr), 21 mResources(nullptr), 22 mTextFieldControl(nullptr) 23 { 24 } 25 ~SettingsUpdateResourcesControl()26 SettingsUpdateResourcesControl::~SettingsUpdateResourcesControl() 27 { 28 mResourceAdd->eventMouseButtonClick -= MyGUI::newDelegate(this, &SettingsUpdateResourcesControl::notifyClickAdd); 29 mResourceDelete->eventMouseButtonClick -= MyGUI::newDelegate(this, &SettingsUpdateResourcesControl::notifyClickDelete); 30 31 delete mTextFieldControl; 32 mTextFieldControl = nullptr; 33 } 34 OnInitialise(Control * _parent,MyGUI::Widget * _place,const std::string & _layoutName)35 void SettingsUpdateResourcesControl::OnInitialise(Control* _parent, MyGUI::Widget* _place, const std::string& _layoutName) 36 { 37 Control::OnInitialise(_parent, _place, _layoutName); 38 39 assignWidget(mResourceAdd, "ResourceAdd"); 40 assignWidget(mResourceDelete, "ResourceDelete"); 41 assignWidget(mResources, "Resources"); 42 43 mTextFieldControl = new TextFieldControl(); 44 mTextFieldControl->Initialise(); 45 mTextFieldControl->eventEndDialog.connect(this, &SettingsUpdateResourcesControl::notifyEndDialog); 46 47 mResourceAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsUpdateResourcesControl::notifyClickAdd); 48 mResourceDelete->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsUpdateResourcesControl::notifyClickDelete); 49 } 50 loadSettings()51 void SettingsUpdateResourcesControl::loadSettings() 52 { 53 mResources->removeAllItems(); 54 SettingsManager::VectorString paths = SettingsManager::getInstance().getValueList("Resources/UpdateResource.List"); 55 for (SettingsManager::VectorString::const_iterator item = paths.begin(); item != paths.end(); ++ item) 56 mResources->addItem(*item); 57 } 58 saveSettings()59 void SettingsUpdateResourcesControl::saveSettings() 60 { 61 SettingsManager::VectorString paths; 62 for (size_t index = 0; index < mResources->getItemCount(); ++ index) 63 paths.push_back(mResources->getItemNameAt(index)); 64 SettingsManager::getInstance().setValueList("Resources/UpdateResource.List", paths); 65 } 66 notifyClickAdd(MyGUI::Widget * _sender)67 void SettingsUpdateResourcesControl::notifyClickAdd(MyGUI::Widget* _sender) 68 { 69 mResources->addItem(""); 70 mResources->beginToItemAt(mResources->getItemCount() - 1); 71 72 mTextFieldControl->setCaption(replaceTags("CaptionAddResource")); 73 mTextFieldControl->setTextField(""); 74 75 MyGUI::Widget* widget = mResources->getWidgetByIndex(mResources->getItemCount() - 1); 76 if (widget != nullptr) 77 mTextFieldControl->setCoord(MyGUI::IntCoord(widget->getAbsoluteLeft(), widget->getAbsoluteTop(), widget->getWidth(), widget->getHeight())); 78 79 mTextFieldControl->doModal(); 80 } 81 notifyClickDelete(MyGUI::Widget * _sender)82 void SettingsUpdateResourcesControl::notifyClickDelete(MyGUI::Widget* _sender) 83 { 84 size_t index = mResources->getIndexSelected(); 85 if (index != MyGUI::ITEM_NONE) 86 mResources->removeItemAt(index); 87 } 88 notifyEndDialog(Dialog * _sender,bool _result)89 void SettingsUpdateResourcesControl::notifyEndDialog(Dialog* _sender, bool _result) 90 { 91 mTextFieldControl->endModal(); 92 93 if (_result) 94 { 95 if (mTextFieldControl->getTextField() != "") 96 { 97 mResources->setItemNameAt(mResources->getItemCount() - 1, mTextFieldControl->getTextField()); 98 return; 99 } 100 } 101 102 mResources->removeItemAt(mResources->getItemCount() - 1); 103 } 104 OnCommand(const std::string & _command)105 void SettingsUpdateResourcesControl::OnCommand(const std::string& _command) 106 { 107 Control::OnCommand(_command); 108 109 if (_command == "Command_LoadSettings") 110 loadSettings(); 111 else if (_command == "Command_SaveSettings") 112 saveSettings(); 113 } 114 115 } 116