QuestGraph.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #pragma once
  2. #include <Schrift.h>
  3. #include <UIMLView.h>
  4. #include "NetworkAPIProcessor.h"
  5. class QuestGraphElement : public Framework::UIMLElement
  6. {
  7. public:
  8. QuestGraphElement();
  9. //! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig
  10. //! ist
  11. bool isApplicableFor(Framework::XML::Element& element) override;
  12. //! erstellt eine neue Zeichnung zu einem gegebenen xml Element
  13. Framework::Zeichnung* parseElement(Framework::XML::Element& element,
  14. Framework::UIMLContainer& generalFactory) override;
  15. bool updateElement(Framework::XML::Element& element,
  16. Framework::Zeichnung& z,
  17. Framework::UIMLContainer& generalFactory) override;
  18. //! wendet die layout parameter zu einer Zeichnung an
  19. void layout(Framework::XML::Element& element,
  20. Framework::Zeichnung& z,
  21. int pWidth,
  22. int pHeight,
  23. Framework::UIMLContainer& generalLayouter) override;
  24. };
  25. class QuestGraphItemElement : public Framework::UIMLElement
  26. {
  27. public:
  28. QuestGraphItemElement();
  29. //! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig
  30. //! ist
  31. bool isApplicableFor(Framework::XML::Element& element) override;
  32. //! erstellt eine neue Zeichnung zu einem gegebenen xml Element
  33. Framework::Zeichnung* parseElement(Framework::XML::Element& element,
  34. Framework::UIMLContainer& generalFactory) override;
  35. bool updateElement(Framework::XML::Element& element,
  36. Framework::Zeichnung& z,
  37. Framework::UIMLContainer& generalFactory) override;
  38. //! wendet die layout parameter zu einer Zeichnung an
  39. void layout(Framework::XML::Element& element,
  40. Framework::Zeichnung& z,
  41. int pWidth,
  42. int pHeight,
  43. Framework::UIMLContainer& generalLayouter) override;
  44. };
  45. class QuestGraphItem;
  46. struct ConnectionInfo
  47. {
  48. QuestGraphItem* target;
  49. int id;
  50. };
  51. class AndNode;
  52. struct ConnectionTarget
  53. {
  54. int targetIndex;
  55. AndNode* zTarget;
  56. };
  57. class Connection : public Framework::ReferenceCounter
  58. {
  59. private:
  60. QuestGraphItem* zSource;
  61. Framework::Array<ConnectionTarget> targets;
  62. int vx;
  63. int minY;
  64. int maxY;
  65. public:
  66. Connection(QuestGraphItem* zSource);
  67. void renderVertical(Framework::Bild& rObj);
  68. void renderHorizontal(Framework::Bild& rObj);
  69. void setVx(int vx);
  70. void addConnectionTarget(ConnectionTarget target);
  71. void setTargetIndex(AndNode* zTarget, int index);
  72. void layout();
  73. bool isActive() const;
  74. int getOrderNum() const;
  75. int getTargetCount() const;
  76. int getVerticalLength() const;
  77. int getVx() const;
  78. };
  79. class AndNode : public Framework::ZeichnungHintergrund
  80. {
  81. private:
  82. Framework::Array<Connection*> connections;
  83. Framework::TextRenderer tr;
  84. public:
  85. AndNode();
  86. void addConnection(Connection* zConnection);
  87. void render(Framework::Bild& rObj);
  88. Framework::Punkt getTargetPosition(int index);
  89. void layout();
  90. bool isActive() const;
  91. int getConnectionCount() const;
  92. };
  93. class OrConnection : public Framework::ReferenceCounter
  94. {
  95. private:
  96. Framework::RCArray<AndNode> andNodes;
  97. QuestGraphItem* zTarget;
  98. int minY;
  99. int maxY;
  100. public:
  101. OrConnection(QuestGraphItem* zTarget,
  102. const Framework::Array<ConnectionInfo>& connections);
  103. void render(Framework::Bild& rObj);
  104. void layout();
  105. int getNeededHeight() const;
  106. bool isActive() const;
  107. bool isHorizontalLineConflict(int y) const;
  108. };
  109. class QuestGraphItem : public Framework::ZeichnungHintergrund
  110. {
  111. private:
  112. int layerIndex;
  113. int nodeIndex;
  114. Framework::Array<ConnectionInfo> previousLayersConnections;
  115. Framework::Array<ConnectionInfo> nextLayersConnections;
  116. Framework::Text id;
  117. Framework::Text requirements;
  118. Framework::Text onClick;
  119. Connection* outgoingConnection;
  120. OrConnection* incommingConnection;
  121. bool finished;
  122. bool rewarded;
  123. bool mainQuest;
  124. bool virtualNode;
  125. double animationProgress;
  126. public:
  127. QuestGraphItem();
  128. ~QuestGraphItem();
  129. bool tick(double tickVal);
  130. void render(Framework::Bild& rObj);
  131. void renderVerticalConnections(Framework::Bild& rObj);
  132. void renderHorizontalConnections(Framework::Bild& rObj);
  133. void replacePreviousConnections(
  134. QuestGraphItem* zBefore, QuestGraphItem* zAfter);
  135. const Framework::Text& getId() const;
  136. const Framework::Text& getRequirements() const;
  137. bool calculateLaxerIndex();
  138. int getLayerIndex() const;
  139. void setVirtual(bool virtualNode);
  140. void setNodeIndex(int index);
  141. void addNextLayerRef(ConnectionInfo zItem);
  142. void addPreviousLayerRef(ConnectionInfo zItem);
  143. void initializeConnections();
  144. const Framework::Array<ConnectionInfo>& getNextLayersConnections() const;
  145. int getNodeIndex() const;
  146. bool isMainQuest() const;
  147. bool isVirtual() const;
  148. bool isFinished() const;
  149. Connection* zOutgoingConnection() const;
  150. OrConnection* zIncommingConnection() const;
  151. friend QuestGraphItemElement;
  152. };
  153. class QuestGraphItemLayer : public Framework::ReferenceCounter
  154. {
  155. private:
  156. Framework::RCArray<QuestGraphItem> items;
  157. public:
  158. QuestGraphItemLayer();
  159. bool tick(double tickVal);
  160. void render(Framework::Bild& rObj);
  161. void doMausEreignis(Framework::MausEreignis& me);
  162. void addItem(QuestGraphItem* item);
  163. bool sortItems();
  164. int fixItemPositions(int x);
  165. void sortConnections();
  166. const Framework::RCArray<QuestGraphItem>& getItems() const;
  167. int getLeyerHeight() const;
  168. void centerVertically(int pos);
  169. void resolveHorizontalConflicts(const QuestGraphItemLayer* zNextLayer);
  170. bool isHorizontalLineConflict(int y) const;
  171. };
  172. class QuestGraph : public Framework::ZeichnungHintergrund
  173. {
  174. private:
  175. Framework::Text id;
  176. Framework::RCArray<QuestGraphItemLayer> layers;
  177. QuestGraphItemLayer invalidNodes;
  178. Framework::Text collectionName;
  179. public:
  180. QuestGraph();
  181. bool tick(double tickVal);
  182. void render(Framework::Bild& rObj) override;
  183. void doMausEreignis(Framework::MausEreignis& me, bool userRet) override;
  184. void addVirtualConnectionNodes();
  185. void sortItems();
  186. void fixItemPositions();
  187. void centerVertically();
  188. void addItem(QuestGraphItem* item);
  189. friend QuestGraphElement;
  190. };