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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
|
#include "Precompiled.h"
#include "EditorWidgets.h"
#include "Common.h"
#include "WidgetTypes.h"
#include "GroupMessage.h"
#include "BackwardCompatibilityManager.h"
#include "WidgetSelectorManager.h"
#include "SettingsManager.h"
template <> tools::EditorWidgets* MyGUI::Singleton<tools::EditorWidgets>::msInstance = nullptr;
template <> const char* MyGUI::Singleton<tools::EditorWidgets>::mClassTypeName = "EditorWidgets";
namespace tools
{
const std::string LogSection = "LayoutEditor";
const std::string CodeGeneratorSettingsNodeName = "CodeGeneratorSettings";
EditorWidgets::EditorWidgets() :
mWidgetsChanged(false)
{
}
EditorWidgets::~EditorWidgets()
{
}
void EditorWidgets::initialise()
{
mWidgetsChanged = true;
MyGUI::ResourceManager::getInstance().registerLoadXmlDelegate("IgnoreParameters") = MyGUI::newDelegate(this, &EditorWidgets::loadIgnoreParameters);
MyGUI::ResourceManager::getInstance().registerLoadXmlDelegate("SkinReplace") = MyGUI::newDelegate(this, &EditorWidgets::loadSkinReplace);
MyGUI::Gui::getInstance().eventFrameStart += MyGUI::newDelegate(this, &EditorWidgets::notifyFrameStarted);
MyGUI::WidgetManager::getInstance().registerUnlinker(this);
}
void EditorWidgets::shutdown()
{
MyGUI::WidgetManager::getInstance().unregisterUnlinker(this);
MyGUI::Gui::getInstance().eventFrameStart -= MyGUI::newDelegate(this, &EditorWidgets::notifyFrameStarted);
destroyAllWidgets();
mCodeGeneratorSettings.clear();
}
void EditorWidgets::destroyAllWidgets()
{
for (std::vector<WidgetContainer*>::iterator iter = mWidgets.begin(); iter != mWidgets.end(); ++iter)
delete *iter;
mWidgets.clear();
}
bool EditorWidgets::load(const MyGUI::UString& _fileName)
{
size_t index = _fileName.find("|");
if (index != MyGUI::UString::npos)
{
MyGUI::UString fileName = _fileName.substr(0, index);
MyGUI::UString itemIndex = _fileName.substr(index + 1);
return loadFromProject(fileName, MyGUI::utility::parseValue<size_t>(itemIndex));
}
mCurrentFileName = _fileName;
mCurrentItemName.clear();
MyGUI::xml::Document doc;
if (!doc.open(_fileName))
{
MYGUI_LOGGING(LogSection, Error, getClassTypeName() << " : " << doc.getLastError());
return false;
}
MyGUI::xml::ElementPtr root = doc.getRoot();
if ((nullptr == root) || (root->getName() != "MyGUI"))
{
MYGUI_LOGGING(LogSection, Error, getClassTypeName() << " : '" << _fileName << "', tag 'MyGUI' not found");
return false;
}
if (root->findAttribute("type") == "Layout")
{
loadWidgetsFromXmlNode(root);
}
else
{
return false;
}
mWidgetsChanged = true;
return true;
}
bool EditorWidgets::loadFromProject(const MyGUI::UString& _fileName, size_t _index)
{
mCurrentFileName = _fileName;
MyGUI::xml::Document doc;
if (!doc.open(_fileName))
{
MYGUI_LOGGING(LogSection, Error, getClassTypeName() << " : " << doc.getLastError());
return false;
}
MyGUI::xml::ElementPtr root = doc.getRoot();
if ((nullptr == root) || (root->getName() != "MyGUI"))
{
MYGUI_LOGGING(LogSection, Error, getClassTypeName() << " : '" << _fileName << "', tag 'MyGUI' not found");
return false;
}
if (root->findAttribute("type") == "Resource")
{
// берем детей и крутимся
MyGUI::xml::ElementEnumerator element = root->getElementEnumerator();
while (element.next("Resource"))
{
if (element->findAttribute("type") == "ResourceLayout")
{
if (_index == 0)
{
mCurrentItemName = element->findAttribute("name");
loadWidgetsFromXmlNode(element.current());
break;
}
else
{
_index --;
}
}
}
}
else
{
return false;
}
mWidgetsChanged = true;
return true;
}
bool EditorWidgets::save(const MyGUI::UString& _fileName)
{
size_t index = _fileName.find("|");
if (index != MyGUI::UString::npos)
{
MyGUI::UString fileName = _fileName.substr(0, index);
MyGUI::UString itemIndex = _fileName.substr(index + 1);
return saveToProject(fileName, MyGUI::utility::parseValue<size_t>(itemIndex));
}
mCurrentFileName = _fileName;
mCurrentItemName.clear();
MyGUI::xml::Document doc;
doc.createDeclaration();
MyGUI::xml::ElementPtr root = doc.createRoot("MyGUI");
root->addAttribute("type", "Layout");
saveWidgetsToXmlNode(root, true);
if (!doc.save(_fileName))
{
MYGUI_LOGGING(LogSection, Error, getClassTypeName() << " : " << doc.getLastError());
return false;
}
return true;
}
bool EditorWidgets::saveToProject(const MyGUI::UString& _fileName, size_t _index)
{
mCurrentFileName = _fileName;
MyGUI::xml::Document doc;
if (!doc.open(_fileName))
{
MYGUI_LOGGING(LogSection, Error, getClassTypeName() << " : " << doc.getLastError());
return false;
}
MyGUI::xml::ElementPtr root = doc.getRoot();
if ((nullptr == root) || (root->getName() != "MyGUI"))
{
MYGUI_LOGGING(LogSection, Error, getClassTypeName() << " : '" << _fileName << "', tag 'MyGUI' not found");
return false;
}
if (root->findAttribute("type") == "Resource")
{
// берем детей и крутимся
MyGUI::xml::ElementEnumerator element = root->getElementEnumerator();
while (element.next("Resource"))
{
if (element->findAttribute("type") == "ResourceLayout")
{
if (_index == 0)
{
mCurrentItemName = element->findAttribute("name");
element->clear();
element->addAttribute("type", "ResourceLayout");
element->addAttribute("name", mCurrentItemName);
saveWidgetsToXmlNode(element.current(), true);
if (!doc.save(_fileName))
{
MYGUI_LOGGING(LogSection, Error, getClassTypeName() << " : " << doc.getLastError());
return false;
}
return true;
}
else
{
_index --;
}
}
}
return false;
}
return false;
}
void EditorWidgets::loadxmlDocument(MyGUI::xml::Document* doc, bool _testMode)
{
MyGUI::xml::ElementPtr root = doc->getRoot();
std::string type;
if (root->findAttribute("type", type))
{
if (type == "Layout")
{
loadWidgetsFromXmlNode(root, _testMode);
}
}
mWidgetsChanged = true;
}
MyGUI::xml::Document* EditorWidgets::savexmlDocument()
{
MyGUI::xml::Document* doc = new MyGUI::xml::Document();
doc->createDeclaration();
MyGUI::xml::ElementPtr root = doc->createRoot("MyGUI");
root->addAttribute("type", "Layout");
saveWidgetsToXmlNode(root);
return doc;
}
void EditorWidgets::add(WidgetContainer* _container)
{
if (nullptr == _container->getWidget()->getParent())
{
mWidgets.push_back(_container);
}
else
{
MyGUI::Widget* parent = _container->getWidget()->getParent();
WidgetContainer* containerParent = find(parent);
while (nullptr == containerParent)
{
parent = parent->getParent();
if (parent == nullptr)
return;
containerParent = find(parent);
}
containerParent->childContainers.push_back(_container);
}
mWidgetsChanged = true;
}
void EditorWidgets::remove(MyGUI::Widget* _widget)
{
remove(find(_widget));
mWidgetsChanged = true;
}
void EditorWidgets::remove(WidgetContainer* _container)
{
if (nullptr != _container)
{
std::vector<WidgetContainer*>::reverse_iterator iter;
while (_container->childContainers.empty() == false)
{
iter = _container->childContainers.rbegin();
remove(*iter);
}
if (nullptr == _container->getWidget()->getParent())
{
mWidgets.erase(std::find(mWidgets.begin(), mWidgets.end(), _container));
}
else
{
MyGUI::Widget* parent = _container->getWidget()->getParent();
WidgetContainer* containerParent = find(parent);
while (nullptr == containerParent)
{
parent = parent->getParent();
if (parent == nullptr)
{
// такого не должно быть, или утечка памяти,
// так как удалять нельзя им пользуется код вызывающий данную функцию
return;
}
containerParent = find(parent);
}
containerParent->childContainers.erase(std::find(containerParent->childContainers.begin(), containerParent->childContainers.end(), _container));
}
MyGUI::Gui::getInstance().destroyWidget(_container->getWidget());
delete _container;
}
mWidgetsChanged = true;
}
bool EditorWidgets::unbind(WidgetContainer* _container)
{
bool result = false;
if (nullptr != _container)
{
std::vector<WidgetContainer*>::reverse_iterator iter;
while (_container->childContainers.empty() == false)
{
iter = _container->childContainers.rbegin();
if (unbind(*iter))
result = true;
}
if (nullptr == _container->getWidget()->getParent())
{
mWidgets.erase(std::find(mWidgets.begin(), mWidgets.end(), _container));
}
else
{
MyGUI::Widget* parent = _container->getWidget()->getParent();
WidgetContainer* containerParent = find(parent);
while (nullptr == containerParent)
{
parent = parent->getParent();
if (parent == nullptr)
{
// такого не должно быть, или утечка памяти,
// так как удалять нельзя им пользуется код вызывающий данную функцию
return result;
}
containerParent = find(parent);
}
containerParent->childContainers.erase(std::find(containerParent->childContainers.begin(), containerParent->childContainers.end(), _container));
}
delete _container;
result = true;
}
mWidgetsChanged = true;
return result;
}
void EditorWidgets::clear()
{
mCurrentFileName.clear();
mCurrentItemName.clear();
while (!mWidgets.empty())
{
remove(mWidgets[mWidgets.size()-1]);
}
mCodeGeneratorSettings.clear();
}
WidgetContainer* EditorWidgets::find(MyGUI::Widget* _widget)
{
return _find(_widget, "", mWidgets);
}
WidgetContainer* EditorWidgets::find(const std::string& _name)
{
return _find(nullptr, _name, mWidgets);
}
WidgetContainer* EditorWidgets::_find(MyGUI::Widget* _widget, const std::string& _name, std::vector<WidgetContainer*> _widgets)
{
for (std::vector<WidgetContainer*>::iterator iter = _widgets.begin(); iter != _widgets.end(); ++iter)
{
if (((*iter)->getWidget() == _widget) || ((_name.empty() == false) && ((*iter)->getName() == _name)))
{
return *iter;
}
WidgetContainer* retContainer = _find(_widget, _name, (*iter)->childContainers);
if (retContainer)
return retContainer;
}
return nullptr;
}
void EditorWidgets::parseWidget(MyGUI::xml::ElementEnumerator& _widget, MyGUI::Widget* _parent, bool _testMode)
{
WidgetContainer* container = new WidgetContainer();
// парсим атрибуты виджета
MyGUI::IntCoord coord;
MyGUI::Align align = MyGUI::Align::Default;
MyGUI::WidgetStyle widgetStyle = MyGUI::WidgetStyle::Child;
std::string position;
container->setName(_widget->findAttribute("name"));
container->setType(_widget->findAttribute("type"));
container->setSkin(_widget->findAttribute("skin"));
container->setLayerName(_widget->findAttribute("layer"));
std::string tmp;
if (_widget->findAttribute("style", tmp))
{
container->setStyle(tmp);
widgetStyle = MyGUI::WidgetStyle::parse(tmp);
}
if (_widget->findAttribute("align", tmp))
{
container->setAlign(tmp);
align = MyGUI::Align::parse(tmp);
}
if (_widget->findAttribute("position", position))
coord = MyGUI::IntCoord::parse(position);
if (_widget->findAttribute("position_real", position))
{
container->setRelativeMode(true);
MyGUI::IntSize textureSize = SettingsManager::getInstance().getValue<MyGUI::IntSize>("Settings/WorkspaceTextureSize");
MyGUI::IntSize size = _testMode ? MyGUI::RenderManager::getInstance().getViewSize() : textureSize;
coord = MyGUI::CoordConverter::convertFromRelative(MyGUI::FloatCoord::parse(position), _parent == nullptr ? size : _parent->getClientCoord().size());
}
// проверяем скин на присутствие
std::string skin = container->getSkin();
bool exist = isSkinExist(container->getSkin());
if (!exist && !container->getSkin().empty())
{
skin = WidgetTypes::getInstance().findWidgetStyle(container->getType())->default_skin;
std::string skin_string;
if (skin.empty())
skin_string = "empty skin";
else
skin_string = "'" + skin + "'";
// FIXME : not translated string
std::string mess = MyGUI::utility::toString("'", container->getSkin(), "' skin not found , temporary changed to ", skin_string);
GroupMessage::getInstance().addMessage(mess, MyGUI::LogLevel::Error);
}
if (!_testMode)
skin = getSkinReplace(skin);
std::string layer = DEFAULT_EDITOR_LAYER;
if (_testMode)
{
// use widget's layer if possible
if (MyGUI::LayerManager::getInstance().isExist(container->getLayerName()))
layer = container->getLayerName();
else
layer = DEFAULT_TEST_MODE_LAYER;
}
std::string widgetType = MyGUI::FactoryManager::getInstance().isFactoryExist("Widget", container->getType()) ?
container->getType() : MyGUI::Widget::getClassTypeName();
if (nullptr == _parent)
{
container->setWidget(MyGUI::Gui::getInstance().createWidgetT(widgetType, skin, coord, align, layer));
}
else
{
container->setWidget(_parent->createWidgetT(widgetStyle, widgetType, skin, coord, align, layer));
}
add(container);
// берем детей и крутимся
MyGUI::xml::ElementEnumerator widget = _widget->getElementEnumerator();
while (widget.next())
{
std::string key, value, type;
if (widget->getName() == "Widget")
{
parseWidget(widget, container->getWidget(), _testMode);
}
else if (widget->getName() == "Property")
{
// парсим атрибуты
if (!widget->findAttribute("key", key))
continue;
if (!widget->findAttribute("value", value))
continue;
// конвертим проперти в текущий вариант версии
key = MyGUI::BackwardCompatibility::getPropertyRename(key);
size_t indexSeparator = key.find('_');
if (indexSeparator != std::string::npos)
key = key.substr(indexSeparator + 1);
// и пытаемся парсить свойство
if (tryToApplyProperty(container->getWidget(), key, value, _testMode) == false)
continue;
container->setProperty(key, value, false);
}
else if (widget->getName() == "UserString")
{
// парсим атрибуты
if (!widget->findAttribute("key", key))
continue;
if (!widget->findAttribute("value", value))
continue;
//container->mUserString.insert(MyGUI::PairString(key, value));
container->setUserData(key, value);
}
else if (widget->getName() == "Controller")
{
// парсим атрибуты
if (!widget->findAttribute("type", type))
continue;
ControllerInfo* controllerInfo = new ControllerInfo();
controllerInfo->mType = type;
MyGUI::ControllerItem* item = nullptr;
if (_testMode)
{
item = MyGUI::ControllerManager::getInstance().createItem(type);
}
MyGUI::xml::ElementEnumerator prop = widget->getElementEnumerator();
while (prop.next("Property"))
{
if (!prop->findAttribute("key", key))
continue;
if (!prop->findAttribute("value", value))
continue;
controllerInfo->mProperty[key] = value;
if (item)
{
item->setProperty(key, value);
}
}
if (item)
{
MyGUI::ControllerManager::getInstance().addItem(container->getWidget(), item);
}
container->mController.push_back(controllerInfo);
}
};
}
bool EditorWidgets::tryToApplyProperty(MyGUI::Widget* _widget, const std::string& _key, const std::string& _value, bool _testMode)
{
WidgetContainer* container = EditorWidgets::getInstance().find(_widget);
if (container->existUserData("LE_TargetWidgetType"))
return true;
try
{
if (_key == "Image_Texture")
{
if (!MyGUI::DataManager::getInstance().isDataExist(_value))
{
GroupMessage::getInstance().addMessage("No such " + _key + ": '" + _value + "'. This value will be saved.", MyGUI::LogLevel::Warning);
return true;
}
}
if (_testMode || std::find(mIgnoreParameters.begin(), mIgnoreParameters.end(), _key) == mIgnoreParameters.end())
{
_widget->setProperty(_key, _value);
}
}
catch (...)
{
GroupMessage::getInstance().addMessage("Can't apply '" + _key + "'property.", MyGUI::LogLevel::Error);
return false;
}
return true;
}
void EditorWidgets::serialiseWidget(WidgetContainer* _container, MyGUI::xml::ElementPtr _node, bool _compatibility)
{
MyGUI::xml::ElementPtr node = _node->createChild("Widget");
node->addAttribute("type", _container->getType());
node->addAttribute("skin", _container->getSkin());
if (!_container->getRelativeMode())
node->addAttribute("position", _container->position());
else
node->addAttribute("position_real", _container->position(false));
if (!_container->getAlign().empty())
node->addAttribute("align", _container->getAlign());
if (!_container->getStyle().empty())
node->addAttribute("style", _container->getStyle());
if (!_container->getLayerName().empty())
node->addAttribute("layer", _container->getLayerName());
if (!_container->getName().empty())
node->addAttribute("name", _container->getName());
WidgetContainer::PropertyEnumerator propertyItem = _container->getPropertyEnumerator();
while (propertyItem.next())
{
BackwardCompatibilityManager::getInstance().serialiseProperty(node, _container->getType(), propertyItem.current(), _compatibility);
}
WidgetContainer::UserDataEnumerator userData = _container->getUserDataEnumerator();
while (userData.next())
{
MyGUI::xml::ElementPtr nodeProp = node->createChild("UserString");
nodeProp->addAttribute("key", userData.current().first);
nodeProp->addAttribute("value", userData.current().second);
}
for (std::vector<ControllerInfo*>::iterator iter = _container->mController.begin(); iter != _container->mController.end(); ++iter)
{
MyGUI::xml::ElementPtr nodeController = node->createChild("Controller");
nodeController->addAttribute("type", (*iter)->mType);
for (MyGUI::MapString::iterator iterProp = (*iter)->mProperty.begin(); iterProp != (*iter)->mProperty.end(); ++iterProp)
{
MyGUI::xml::ElementPtr nodeProp = nodeController->createChild("Property");
nodeProp->addAttribute("key", iterProp->first);
nodeProp->addAttribute("value", iterProp->second);
}
}
for (std::vector<WidgetContainer*>::iterator iter = _container->childContainers.begin(); iter != _container->childContainers.end(); ++iter)
{
serialiseWidget(*iter, node, _compatibility);
}
}
void EditorWidgets::loadIgnoreParameters(MyGUI::xml::ElementPtr _node, const std::string& _file, MyGUI::Version _version)
{
MyGUI::xml::ElementEnumerator parameter = _node->getElementEnumerator();
while (parameter.next("Parameter"))
{
std::string name = parameter->findAttribute("key");
mIgnoreParameters.push_back(name);
}
}
void EditorWidgets::notifyFrameStarted(float _time)
{
if (mWidgetsChanged)
{
mWidgetsChanged = false;
eventChangeWidgets();
}
}
void EditorWidgets::invalidateWidgets()
{
mWidgetsChanged = true;
}
EnumeratorWidgetContainer EditorWidgets::getWidgets()
{
return EnumeratorWidgetContainer(mWidgets);
}
std::string EditorWidgets::getSkinReplace(const std::string& _skinName)
{
MyGUI::MapString::iterator item = mSkinReplaces.find(_skinName);
if (item != mSkinReplaces.end())
return (*item).second;
return _skinName;
}
void EditorWidgets::loadSkinReplace(MyGUI::xml::ElementPtr _node, const std::string& _file, MyGUI::Version _version)
{
MyGUI::xml::ElementEnumerator node = _node->getElementEnumerator();
while (node.next("Skin"))
mSkinReplaces[node->findAttribute("key")] = node->getContent();
}
bool EditorWidgets::isSkinExist(const std::string& _skinName)
{
return _skinName == "Default" ||
MyGUI::SkinManager::getInstance().isExist(_skinName) ||
(MyGUI::LayoutManager::getInstance().isExist(_skinName) && checkTemplate(_skinName));
}
bool EditorWidgets::checkTemplate(const std::string& _skinName)
{
MyGUI::ResourceLayout* templateInfo = MyGUI::LayoutManager::getInstance().getByName(_skinName, false);
if (templateInfo != nullptr)
{
const MyGUI::VectorWidgetInfo& data = templateInfo->getLayoutData();
for (MyGUI::VectorWidgetInfo::const_iterator container = data.begin(); container != data.end(); ++container)
{
if (container->name == "Root")
return true;
}
}
return false;
}
const MyGUI::UString& EditorWidgets::getCurrentFileName() const
{
return mCurrentFileName;
}
const MyGUI::UString& EditorWidgets::getCurrentItemName() const
{
return mCurrentItemName;
}
void EditorWidgets::_unlinkWidget(MyGUI::Widget* _widget)
{
WidgetContainer* container = find(_widget);
if (container != nullptr)
{
bool result = unbind(container);
mWidgetsChanged = true;
if (result)
WidgetSelectorManager::getInstance().setSelectedWidget(nullptr);
}
}
MyGUI::MapString& EditorWidgets::getCodeGeneratorSettings()
{
return mCodeGeneratorSettings;
}
void EditorWidgets::loadWidgetsFromXmlNode(MyGUI::xml::ElementPtr _root, bool _testMode)
{
// берем детей и крутимся
MyGUI::xml::ElementEnumerator element = _root->getElementEnumerator();
while (element.next())
{
if (element->getName() == "Widget")
parseWidget(element, nullptr, _testMode);
else if (element->getName() == CodeGeneratorSettingsNodeName)
loadCodeGeneratorSettings(element.current());
}
}
void EditorWidgets::saveWidgetsToXmlNode(MyGUI::xml::ElementPtr _root, bool _compatibility)
{
_root->addAttribute("version", BackwardCompatibilityManager::getInstancePtr()->getCurrentVersion());
for (std::vector<WidgetContainer*>::iterator iter = mWidgets.begin(); iter != mWidgets.end(); ++iter)
{
// в корень только сирот
if (nullptr == (*iter)->getWidget()->getParent())
serialiseWidget(*iter, _root, _compatibility);
}
saveCodeGeneratorSettings(_root);
}
void EditorWidgets::loadCodeGeneratorSettings(MyGUI::xml::ElementPtr _sectorNode)
{
MyGUI::xml::ElementEnumerator widget = _sectorNode->getElementEnumerator();
while (widget.next())
{
std::string key, value;
if (widget->getName() == "Property")
{
// парсим атрибуты
if (!widget->findAttribute("key", key))
continue;
if (!widget->findAttribute("value", value))
continue;
mCodeGeneratorSettings[key] = value;
}
}
}
void EditorWidgets::saveCodeGeneratorSettings(MyGUI::xml::ElementPtr _rootNode)
{
MyGUI::xml::ElementPtr node = _rootNode->createChild(CodeGeneratorSettingsNodeName);
for (MyGUI::MapString::const_iterator iter = mCodeGeneratorSettings.begin(); iter != mCodeGeneratorSettings.end(); ++iter)
{
MyGUI::xml::ElementPtr nodeProp = node->createChild("Property");
nodeProp->addAttribute("key", iter->first);
nodeProp->addAttribute("value", iter->second);
}
}
void EditorWidgets::onSetWidgetCoord(MyGUI::Widget* _widget, const MyGUI::IntCoord& _value, const std::string& _owner)
{
eventChangeWidgetCoord(_widget, _value, _owner);
}
}
|