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