UICraftingProgress.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "UICraftingProgress.h"
  2. #include "UIReference.h"
  3. UICraftingProgress::UICraftingProgress()
  4. : UIElement(),
  5. reference(0)
  6. {}
  7. UICraftingProgress::~UICraftingProgress()
  8. {
  9. if (reference)
  10. {
  11. reference->release();
  12. }
  13. }
  14. void UICraftingProgress::setReference(UIReference* reference)
  15. {
  16. if (this->reference)
  17. {
  18. this->reference->release();
  19. }
  20. this->reference = reference;
  21. }
  22. UIReference* UICraftingProgress::zReference() const
  23. {
  24. return reference;
  25. }
  26. void UICraftingProgress::setBackgroundImagePath(
  27. const Framework::Text& backgroundImagePath)
  28. {
  29. this->backgroundImagePath = backgroundImagePath;
  30. }
  31. const Framework::Text& UICraftingProgress::getBackgroundImagePath() const
  32. {
  33. return backgroundImagePath;
  34. }
  35. void UICraftingProgress::setForegroundImagePath(
  36. const Framework::Text& foregroundImagePath)
  37. {
  38. this->foregroundImagePath = foregroundImagePath;
  39. }
  40. const Framework::Text& UICraftingProgress::getForegroundImagePath() const
  41. {
  42. return foregroundImagePath;
  43. }
  44. void UICraftingProgress::setDirection(const Framework::Text& direction)
  45. {
  46. this->direction = direction;
  47. }
  48. const Framework::Text& UICraftingProgress::getDirection() const
  49. {
  50. return direction;
  51. }
  52. Framework::XML::Element* UICraftingProgress::toUIML(
  53. Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
  54. {
  55. Framework::XML::Element* element = UIElement::toUIML(zTarget, zActor);
  56. element->setName("craftingProgress");
  57. element->setAttribute("target", reference->getReferenceId(zTarget, zActor));
  58. element->setAttribute("backgroundImagePath", backgroundImagePath);
  59. element->setAttribute("foregroundImagePath", foregroundImagePath);
  60. element->setAttribute("direction", direction);
  61. return element;
  62. }
  63. UICraftingProgressFactory::UICraftingProgressFactory()
  64. : UIElementFactory()
  65. {}
  66. JSONObjectValidationBuilder* UICraftingProgressFactory::addToValidator(
  67. JSONObjectValidationBuilder* builder) const
  68. {
  69. return UIElementFactory::addToValidator(builder)
  70. ->withRequiredAttribute("reference",
  71. Game::INSTANCE->zTypeRegistry()->getValidator<UIReference>())
  72. ->withRequiredString("backgroundImagePath")
  73. ->finishString()
  74. ->withRequiredString("foregroundImagePath")
  75. ->finishString()
  76. ->withRequiredString("direction")
  77. ->whichIsOneOf({"TOP", "LEFT", "BOTTOM", "RIGHT"})
  78. ->finishString();
  79. }
  80. UICraftingProgress* UICraftingProgressFactory::fromJson(
  81. Framework::JSON::JSONObject* zJson) const
  82. {
  83. UICraftingProgress* result = UIElementFactory::fromJson(zJson);
  84. result->setReference(Game::INSTANCE->zTypeRegistry()->fromJson<UIReference>(
  85. zJson->zValue("reference")));
  86. result->setBackgroundImagePath(
  87. zJson->zValue("backgroundImagePath")->asString()->getString());
  88. result->setForegroundImagePath(
  89. zJson->zValue("foregroundImagePath")->asString()->getString());
  90. result->setDirection(zJson->zValue("direction")->asString()->getString());
  91. return result;
  92. }
  93. Framework::JSON::JSONObject* UICraftingProgressFactory::toJsonObject(
  94. UICraftingProgress* zObject) const
  95. {
  96. Framework::JSON::JSONObject* result
  97. = UIElementFactory::toJsonObject(zObject);
  98. result->addValue("reference",
  99. Game::INSTANCE->zTypeRegistry()->toJson(zObject->zReference()));
  100. result->addValue("backgroundImagePath",
  101. new Framework::JSON::JSONString(zObject->getBackgroundImagePath()));
  102. result->addValue("foregroundImagePath",
  103. new Framework::JSON::JSONString(zObject->getForegroundImagePath()));
  104. result->addValue(
  105. "direction", new Framework::JSON::JSONString(zObject->getDirection()));
  106. return result;
  107. }
  108. UICraftingProgress* UICraftingProgressFactory::createElement(
  109. Framework::JSON::JSONObject* zJson) const
  110. {
  111. return new UICraftingProgress();
  112. }
  113. const char* UICraftingProgressFactory::getTypeToken() const
  114. {
  115. return "craftingProgress";
  116. }