UIDialogElement.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "UIDialogElement.h"
  2. #include "UIReference.h"
  3. UIDialogElement::UIDialogElement()
  4. : UIContainerElement(),
  5. notifyOnClose(0)
  6. {}
  7. UIDialogElement::~UIDialogElement()
  8. {
  9. if (notifyOnClose)
  10. {
  11. notifyOnClose->release();
  12. }
  13. }
  14. void UIDialogElement::setTitle(const Framework::Text& title)
  15. {
  16. this->title = title;
  17. }
  18. const Framework::Text& UIDialogElement::getTitle() const
  19. {
  20. return title;
  21. }
  22. void UIDialogElement::setNotifyOnClose(UIReference* notifyOnClose)
  23. {
  24. if (this->notifyOnClose)
  25. {
  26. this->notifyOnClose->release();
  27. }
  28. this->notifyOnClose = notifyOnClose;
  29. }
  30. UIReference* UIDialogElement::zNotifyOnClose() const
  31. {
  32. return notifyOnClose;
  33. }
  34. Framework::XML::Element* UIDialogElement::toUIML(
  35. Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
  36. {
  37. Framework::XML::Element* result
  38. = UIContainerElement::toUIML(zTarget, zActor);
  39. result->setName("dialog");
  40. result->setAttribute("title", title);
  41. if (notifyOnClose)
  42. {
  43. result->setAttribute(
  44. "notifyOnClose", notifyOnClose->getReferenceId(zTarget, zActor));
  45. }
  46. return result;
  47. }
  48. UIDialogElementFactory::UIDialogElementFactory()
  49. : UIContainerElementFactory<UIDialogElement>()
  50. {}
  51. JSONObjectValidationBuilder* UIDialogElementFactory::addToValidator(
  52. JSONObjectValidationBuilder* builder) const
  53. {
  54. return UIContainerElementFactory::addToValidator(builder)
  55. ->withRequiredString("title")
  56. ->finishString()
  57. ->withRequiredAttribute("notifyOnClose",
  58. Game::INSTANCE->zTypeRegistry()->getValidator<UIReference>(),
  59. false,
  60. true);
  61. }
  62. UIDialogElement* UIDialogElementFactory::fromJson(
  63. Framework::JSON::JSONObject* zJson) const
  64. {
  65. UIDialogElement* result = UIContainerElementFactory::fromJson(zJson);
  66. result->setTitle(zJson->zValue("title")->asString()->getString());
  67. if (zJson->hasValue("notifyOnClose"))
  68. {
  69. result->setNotifyOnClose(
  70. Game::INSTANCE->zTypeRegistry()->fromJson<UIReference>(
  71. zJson->zValue("notifyOnClose")));
  72. }
  73. return result;
  74. }
  75. Framework::JSON::JSONObject* UIDialogElementFactory::toJsonObject(
  76. UIDialogElement* zObject) const
  77. {
  78. Framework::JSON::JSONObject* result
  79. = UIContainerElementFactory::toJsonObject(zObject);
  80. result->addValue(
  81. "title", new Framework::JSON::JSONString(zObject->getTitle()));
  82. if (zObject->zNotifyOnClose())
  83. {
  84. result->addValue("notifyOnClose",
  85. Game::INSTANCE->zTypeRegistry()->toJson<UIReference>(
  86. zObject->zNotifyOnClose()));
  87. }
  88. return result;
  89. }
  90. UIDialogElement* UIDialogElementFactory::createElement(
  91. Framework::JSON::JSONObject* zJson) const
  92. {
  93. return new UIDialogElement();
  94. }
  95. const char* UIDialogElementFactory::getTypeToken() const
  96. {
  97. return "dialog";
  98. }