QuestRequirement.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 = new Framework::XML::Element("<text width=\"auto\" height=\"auto\"/>");
  54. text->setAttribute("id",
  55. Framework::Text("requirement_description_") += getRequirementId());
  56. text->setText(description);
  57. container->addChild(text);
  58. auto status = new Framework::XML::Element("<text margin-top=\"10\" width=\"auto\" height=\"auto\"/>");
  59. status->setAttribute("align-top", text->getAttributeValue("id"));
  60. status->setAttribute("align-x", text->getAttributeValue("id"));
  61. if (zStorage->zStorage(getRequirementId())->isFullfilled())
  62. {
  63. status->setText("Completed");
  64. status->setAttribute("text-color", "0xFF00FF00");
  65. }
  66. else
  67. {
  68. status->setText("Not completed");
  69. status->setAttribute("text-color", "0xFFFF0000");
  70. }
  71. container->addChild(status);
  72. zParent->addChild(container);
  73. }
  74. QuestRequirementOpenDialogType::QuestRequirementOpenDialogType()
  75. : SubTypeFactory()
  76. {}
  77. QuestRequirementOpenDialog* QuestRequirementOpenDialogType::fromJson(
  78. Framework::JSON::JSONObject* zJson) const
  79. {
  80. return new QuestRequirementOpenDialog(
  81. zJson->zValue("id")->asString()->getString(),
  82. zJson->zValue("description")->asString()->getString(),
  83. zJson->zValue("dialogId")->asString()->getString());
  84. }
  85. Framework::JSON::JSONObject* QuestRequirementOpenDialogType::toJson(
  86. QuestRequirementOpenDialog* zObject) const
  87. {
  88. Framework::JSON::JSONObject* json = new Framework::JSON::JSONObject();
  89. json->addValue(
  90. "id", new Framework::JSON::JSONString(zObject->getRequirementId()));
  91. json->addValue("description",
  92. new Framework::JSON::JSONString(zObject->getDescription()));
  93. json->addValue(
  94. "dialogId", new Framework::JSON::JSONString(zObject->dialogId));
  95. return json;
  96. }
  97. Framework::JSON::Validator::JSONValidator*
  98. QuestRequirementOpenDialogType::getValidator(
  99. Framework::JSON::Validator::ObjectValidationBuilder<
  100. Framework::JSON::Validator::JSONValidator>* builder) const
  101. {
  102. return builder->withRequiredString("id")
  103. ->finishString()
  104. ->withRequiredString("description")
  105. ->finishString()
  106. ->withRequiredString("dialogId")
  107. ->finishString()
  108. ->finishObject();
  109. }
  110. Framework::Text QuestRequirementOpenDialogType::getTypeToken() const
  111. {
  112. return "open_dialog";
  113. }