QuestDialog.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "QuestDialog.h"
  2. #include "Game.h"
  3. QuestDialog::QuestDialog(int playerId)
  4. : UIDialog("quests", playerId, 0)
  5. {
  6. QuestManager* zManager = Game::INSTANCE->zQuestManager();
  7. Framework::Text uiml = "<dialog id=\"quests\" title=\"Quests\" "
  8. "width=\"1200\" height=\"800\">";
  9. uiml.append()
  10. << "<listView id=\"collectionList\" width=\"200\" height=\"100%\" "
  11. "member-height=\"40\" align-top=\"start\" "
  12. "align-left=\"start\" onSelectMessage=\"quests;0\">";
  13. QuestParty* party = zManager->zParty(playerId);
  14. int index = 0;
  15. for (QuestCollection* questCollection : zManager->questCollections)
  16. {
  17. if (questCollection->isVisible(party, zManager))
  18. {
  19. uiml.append() << "<listItem id=\"quest_collection_" << index++
  20. << "\" collectionName=\""
  21. << questCollection->getName() << "\">"
  22. << questCollection->getName()
  23. << "</listItem>";
  24. }
  25. }
  26. uiml.append()
  27. << "</listView><questGraph id=\"visible_quest_graph\" width=\"1000\" "
  28. "align-left=\"collectionList\" "
  29. "height=\"100%\"/></dialog>";
  30. this->uiml = new Framework::XML::Element(uiml);
  31. }
  32. void QuestDialog::api(
  33. Framework::StreamReader* zRequest, NetworkMessage* zResponse)
  34. {
  35. char typ;
  36. zRequest->lese(&typ, 1);
  37. switch (typ)
  38. {
  39. case 0: // onSelect Message of listView
  40. {
  41. int selection;
  42. zRequest->lese((char*)&selection, 4);
  43. auto questGraph = this->uiml->selectChildsByName("questGraph");
  44. questGraph.selectChildren().remove();
  45. auto listItems
  46. = uiml->selectChildsByName("listView").selectChildren();
  47. listItems.removeAttribute("selected");
  48. listItems
  49. .whereAttributeEquals(
  50. "id", Framework::Text("quest_collection_") + selection)
  51. .forEach([this, &questGraph](
  52. Framework::XML::Element* zElement) {
  53. zElement->setAttribute("selected", "");
  54. auto collectionName
  55. = zElement->getAttributeValue("collectionName");
  56. QuestManager* zManager = Game::INSTANCE->zQuestManager();
  57. auto questCollection
  58. = zManager->zCollection(collectionName);
  59. QuestParty* zParty = zManager->zParty(getPlayerId());
  60. for (Quest* quest : questCollection->quests)
  61. {
  62. if (quest->isVisible(zParty, zManager))
  63. {
  64. questGraph.addChild(getQuestGraphItem(quest, zParty));
  65. }
  66. }
  67. });
  68. update();
  69. break;
  70. }
  71. }
  72. }
  73. Framework::XML::Element* QuestDialog::getQuestGraphItem(
  74. Quest* zQuest, QuestParty* zParty)
  75. {
  76. Framework::Text requirements = "";
  77. int index = 0;
  78. int currentGroup = 0;
  79. for (Framework::Text* requiredQuest : zQuest->requiredQuestsIds)
  80. {
  81. int group = zQuest->requiredQuestsGroups.get(index);
  82. if (index != 0)
  83. {
  84. if (group != currentGroup)
  85. {
  86. requirements += "||";
  87. currentGroup = group;
  88. }
  89. else
  90. {
  91. requirements += "&&";
  92. }
  93. }
  94. else
  95. {
  96. currentGroup = group;
  97. }
  98. requirements += *requiredQuest;
  99. index++;
  100. }
  101. if (!zQuest->isActive(zParty))
  102. {
  103. Framework::Text result = "<questGraphItem id=\"quest_";
  104. result.append()
  105. << zQuest->questId << "\" name=\"Unknown Quest\" image=\""
  106. << zQuest->imagePath
  107. << "\" description=\"You have to finish other quests befor this "
  108. "quest will be available.\" finished=\"false\" mainQuest=\""
  109. << zQuest->mainQuest << "\" requirements=\"" << requirements
  110. << "\" width=\"" << (zQuest->mainQuest ? "50" : "30")
  111. << "\" height=\"" << (zQuest->mainQuest ? "50" : "30") << "\"/>";
  112. return new Framework::XML::Element(result);
  113. }
  114. else
  115. {
  116. QuestStorage* zStorage = zParty->zQuestStorage(zQuest->questId);
  117. Framework::Text result = "<questGraphItem id=\"quest_";
  118. result.append() << zQuest->questId << "\" name=\""
  119. << zQuest->questName + "\" image=\""
  120. << zQuest->imagePath << "\" description=\""
  121. << zQuest->description
  122. << "\" finished=\"" << zStorage->isQuestFinished() << "\" mainQuest=\""
  123. << zQuest->mainQuest
  124. << "\" requirements=\"" << requirements << "\" width=\""
  125. << (zQuest->mainQuest ? "50" : "30") << "\" height=\""
  126. << (zQuest->mainQuest ? "50" : "30") << "\"/>";
  127. return new Framework::XML::Element(result);
  128. }
  129. }