QuestRequirement.cpp 4.0 KB

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