123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #include "QuestDialog.h"
- #include "Game.h"
- QuestDialog::QuestDialog(int playerId)
- : UIDialog("quests", playerId, 0)
- {
- QuestManager* zManager = Game::INSTANCE->zQuestManager();
- Framework::Text uiml = "<dialog id=\"quests\" title=\"Quests\" "
- "width=\"1200\" height=\"800\">";
- uiml.append()
- << "<listView id=\"collectionList\" width=\"200\" height=\"100%\" "
- "member-height=\"40\" align-top=\"start\" "
- "align-left=\"start\" onSelectMessage=\"quests;0\">";
- QuestParty* party = zManager->zParty(playerId);
- int index = 0;
- for (QuestCollection* questCollection : zManager->questCollections)
- {
- if (questCollection->isVisible(party, zManager))
- {
- uiml.append() << "<listItem id=\"quest_collection_" << index++
- << "\" collectionName=\""
- << questCollection->getName() << "\">"
- << questCollection->getName()
- << "</listItem>";
- }
- }
- uiml.append()
- << "</listView><questGraph id=\"visible_quest_graph\" width=\"1000\" "
- "align-left=\"collectionList\" "
- "height=\"100%\"/></dialog>";
- this->uiml = new Framework::XML::Element(uiml);
- }
- void QuestDialog::api(
- Framework::StreamReader* zRequest, NetworkMessage* zResponse)
- {
- char typ;
- zRequest->lese(&typ, 1);
- switch (typ)
- {
- case 0: // onSelect Message of listView
- {
- int selection;
- zRequest->lese((char*)&selection, 4);
- auto questGraph = this->uiml->selectChildsByName("questGraph");
- questGraph.selectChildren().remove();
- auto listItems
- = uiml->selectChildsByName("listView").selectChildren();
- listItems.removeAttribute("selected");
- listItems
- .whereAttributeEquals(
- "id", Framework::Text("quest_collection_") + selection)
- .forEach([this, &questGraph](
- Framework::XML::Element* zElement) {
- zElement->setAttribute("selected", "");
- auto collectionName
- = zElement->getAttributeValue("collectionName");
- QuestManager* zManager = Game::INSTANCE->zQuestManager();
- auto questCollection
- = zManager->zCollection(collectionName);
- QuestParty* zParty = zManager->zParty(getPlayerId());
- for (Quest* quest : questCollection->quests)
- {
- if (quest->isVisible(zParty, zManager))
- {
- questGraph.addChild(getQuestGraphItem(quest, zParty));
- }
- }
- });
- update();
- break;
- }
- }
- }
- Framework::XML::Element* QuestDialog::getQuestGraphItem(
- Quest* zQuest, QuestParty* zParty)
- {
- Framework::Text requirements = "";
- int index = 0;
- int currentGroup = 0;
- for (Framework::Text* requiredQuest : zQuest->requiredQuestsIds)
- {
- int group = zQuest->requiredQuestsGroups.get(index);
- if (index != 0)
- {
- if (group != currentGroup)
- {
- requirements += "||";
- currentGroup = group;
- }
- else
- {
- requirements += "&&";
- }
- }
- else
- {
- currentGroup = group;
- }
- requirements += *requiredQuest;
- index++;
- }
- if (!zQuest->isActive(zParty))
- {
- Framework::Text result = "<questGraphItem id=\"quest_";
- result.append()
- << zQuest->questId << "\" name=\"Unknown Quest\" image=\""
- << zQuest->imagePath
- << "\" description=\"You have to finish other quests befor this "
- "quest will be available.\" finished=\"false\" mainQuest=\""
- << zQuest->mainQuest << "\" requirements=\"" << requirements
- << "\" width=\"" << (zQuest->mainQuest ? "50" : "30")
- << "\" height=\"" << (zQuest->mainQuest ? "50" : "30") << "\"/>";
- return new Framework::XML::Element(result);
- }
- else
- {
- QuestStorage* zStorage = zParty->zQuestStorage(zQuest->questId);
- Framework::Text result = "<questGraphItem id=\"quest_";
- result.append() << zQuest->questId << "\" name=\""
- << zQuest->questName + "\" image=\""
- << zQuest->imagePath << "\" description=\""
- << zQuest->description
- << "\" finished=\"" << zStorage->isQuestFinished() << "\" mainQuest=\""
- << zQuest->mainQuest
- << "\" requirements=\"" << requirements << "\" width=\""
- << (zQuest->mainQuest ? "50" : "30") << "\" height=\""
- << (zQuest->mainQuest ? "50" : "30") << "\"/>";
- return new Framework::XML::Element(result);
- }
- }
|