QuestRequirement.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include "QuestRequirement.h"
  2. #include <Fenster.h>
  3. #include "Quest.h"
  4. QuestRequirement::QuestRequirement()
  5. : ReferenceCounter()
  6. {}
  7. void QuestRequirement::api(Framework::StreamReader* message,
  8. Framework::XML::Element* zParent,
  9. QuestStorage* zStorage)
  10. {}
  11. void QuestRequirement::setRequirementId(Framework::Text id)
  12. {
  13. this->id = id;
  14. }
  15. const Framework::Text& QuestRequirement::getRequirementId() const
  16. {
  17. return id;
  18. }
  19. void QuestRequirement::setDescription(Framework::Text description)
  20. {
  21. this->description = description;
  22. }
  23. const Framework::Text& QuestRequirement::getDescription() const
  24. {
  25. return description;
  26. }
  27. QuestRequirementOpenDialog::QuestRequirementOpenDialog()
  28. : QuestRequirement()
  29. {}
  30. void QuestRequirementOpenDialog::processEvent(
  31. QuestEvent* zEvent, QuestStorage* zStorage)
  32. {
  33. QuestRequirementStorage* zRequirementStorage
  34. = zStorage->zStorage(getRequirementId());
  35. QuestEventOpenDialog* event = dynamic_cast<QuestEventOpenDialog*>(zEvent);
  36. if (event)
  37. {
  38. if (event->getDialogId() == dialogId)
  39. {
  40. zRequirementStorage->setFullfilled(true);
  41. }
  42. }
  43. }
  44. void QuestRequirementOpenDialog::addRequirementUIML(QuestStorage* zStorage,
  45. Framework::XML::Element* zParent,
  46. Framework::Text onClickPrefix)
  47. {
  48. Framework::XML::Element* container = new Framework::XML::Element(
  49. "<frame width=\"100%\" height=\"50\" display=\"row\" gap=\"10\"/>");
  50. container->setAttribute("style",
  51. Framework::Text() += (Framework::Fenster::Style::Sichtbar
  52. | Framework::Fenster::Style::Erlaubt));
  53. container->setAttribute(
  54. "id", Framework::Text("requirement_") += getRequirementId());
  55. // TODO: add icon of dialog
  56. auto text
  57. = new Framework::XML::Element("<text width=\"auto\" height=\"auto\"/>");
  58. text->setAttribute("id",
  59. Framework::Text("requirement_description_") += getRequirementId());
  60. text->setText(description);
  61. container->addChild(text);
  62. auto status = new Framework::XML::Element(
  63. "<text margin-top=\"10\" width=\"auto\" height=\"auto\"/>");
  64. status->setAttribute("align-top", text->getAttributeValue("id"));
  65. status->setAttribute("align-x", text->getAttributeValue("id"));
  66. if (zStorage->zStorage(getRequirementId())->isFullfilled())
  67. {
  68. status->setText("Completed");
  69. status->setAttribute("text-color", "0xFF00FF00");
  70. }
  71. else
  72. {
  73. status->setText("Not completed");
  74. status->setAttribute("text-color", "0xFFFF0000");
  75. }
  76. container->addChild(status);
  77. zParent->addChild(container);
  78. }
  79. void QuestRequirementOpenDialog::setDialogId(Framework::Text dialogId)
  80. {
  81. this->dialogId = dialogId;
  82. }
  83. const Framework::Text& QuestRequirementOpenDialog::getDialogId() const
  84. {
  85. return dialogId;
  86. }
  87. QuestRequirementOpenDialogType::QuestRequirementOpenDialogType()
  88. : QuestRequirementFactoryBase()
  89. {}
  90. QuestRequirementOpenDialog* QuestRequirementOpenDialogType::createValue(
  91. Framework::JSON::JSONObject* zJson) const
  92. {
  93. return new QuestRequirementOpenDialog();
  94. }
  95. void QuestRequirementOpenDialogType::fromJson(
  96. QuestRequirementOpenDialog* zResult,
  97. Framework::JSON::JSONObject* zJson) const
  98. {
  99. zResult->setDialogId(zJson->zValue("dialogId")->asString()->getString());
  100. QuestRequirementFactoryBase::fromJson(zResult, zJson);
  101. }
  102. void QuestRequirementOpenDialogType::toJson(QuestRequirementOpenDialog* zObject,
  103. Framework::JSON::JSONObject* zResult) const
  104. {
  105. zResult->addValue(
  106. "dialogId", new Framework::JSON::JSONString(zObject->dialogId));
  107. QuestRequirementFactoryBase::toJson(zObject, zResult);
  108. }
  109. JSONObjectValidationBuilder* QuestRequirementOpenDialogType::addToValidator(
  110. JSONObjectValidationBuilder* builder) const
  111. {
  112. return QuestRequirementFactoryBase::addToValidator(
  113. builder->withRequiredString("id")
  114. ->finishString()
  115. ->withRequiredString("description")
  116. ->finishString()
  117. ->withRequiredString("dialogId")
  118. ->finishString());
  119. }
  120. Framework::Text QuestRequirementOpenDialogType::getTypeToken() const
  121. {
  122. return "open_dialog";
  123. }