Peoplemon  0.1.0
Peoplemon 3 game source documentation
ConversationTree.hpp
Go to the documentation of this file.
1 #ifndef EDITOR_COMPONENTS_CONVERSATIONTREE_HPP
2 #define EDITOR_COMPONENTS_CONVERSATIONTREE_HPP
3 
4 #include <BLIB/Graphics.hpp>
5 #include <BLIB/Interfaces/GUI.hpp>
8 
9 namespace editor
10 {
11 namespace component
12 {
18 class ConversationTree : public bl::gui::Element {
19 public:
20  using Ptr = std::shared_ptr<ConversationTree>;
21 
22  static constexpr float NodeRadius = 60.f;
23  static constexpr float NodeRadiusSquared = NodeRadius * NodeRadius;
24  static constexpr float NodePadding = 100.f;
25  static constexpr float Spacing = NodeRadius * 2.f + NodePadding;
26 
27  struct Node {
28  glm::vec2 center;
29  bool terminator;
30  unsigned int index; // in source
31  std::string label;
32 
33  Node() = default;
34  void setup(const sf::Vector2f& pos, const core::file::Conversation::Node& src,
35  unsigned int i, bool terminator);
36 
37  friend class ConversationTree;
38  };
39 
40  struct Edge {
41  unsigned int from;
42  unsigned int to;
43  };
44 
46  using ClickCb = std::function<void(unsigned int)>;
47 
53  static Ptr create(const ClickCb& clickCb);
54 
60  void update(const std::vector<core::file::Conversation::Node>& nodes);
61 
67  void setSelected(unsigned int i);
68 
72  const std::vector<Node>& getNodes() const { return renderNodes; }
73 
77  const std::vector<Edge>& getEdges() const { return edges; }
78 
82  unsigned int getSelectedNode() const { return selected; }
83 
87  unsigned int getTreeVersion() const { return treeVersion; }
88 
92  const glm::vec2& getCamCenter() const { return camCenter; }
93 
97  float getCamZoom() const { return camZoom; }
98 
102  bool shouldHighlightSelectedNode() const { return highlightSelected; }
103 
104 private:
105  const ClickCb clickCb;
106  std::vector<Node> renderNodes;
107  std::vector<Edge> edges;
108  unsigned int selected;
109  float flashTime;
110  unsigned int treeVersion;
111  glm::vec2 camCenter;
112  float camZoom;
113  bool highlightSelected;
114 
115  ConversationTree(const ClickCb& clickCb);
116 
117  void onDrag(const bl::gui::Event& dragEvent);
118  virtual bool handleScroll(const bl::gui::Event& zoomEvent) override;
119  void onClick(const bl::gui::Event& clickEvent);
120  void centerView();
121  sf::FloatRect getVirtualBounds() const;
122 
123  sf::Vector2f transformToTreeCoord(const sf::Vector2f& point) const;
124 
125  virtual void update(float dt) override;
126  virtual sf::Vector2f minimumRequisition() const override;
127  virtual bl::gui::rdr::Component* doPrepareRender(bl::gui::rdr::Renderer& renderer) override;
128 };
129 
130 } // namespace component
131 } // namespace editor
132 
133 #endif
All classes and functionality used for implementing the game editor.
Definition: Tile.hpp:11
Building block of conversations. A conversation is a tree of nodes and each node is an action that ha...
Special component that renders a clickable tree view of a conversation.
void setSelected(unsigned int i)
Set the selected node index.
const std::vector< Edge > & getEdges() const
Used by the renderer component.
unsigned int getTreeVersion() const
Used by the renderer component.
static constexpr float NodeRadiusSquared
unsigned int getSelectedNode() const
Used by the renderer component.
const glm::vec2 & getCamCenter() const
Used by the renderer component.
std::function< void(unsigned int)> ClickCb
Called when a node is clicked.
bool shouldHighlightSelectedNode() const
Used by the renderer component.
void update(const std::vector< core::file::Conversation::Node > &nodes)
Updates the rendered tree with the new nodes.
float getCamZoom() const
Used by the renderer component.
static Ptr create(const ClickCb &clickCb)
Construct a new Conversation Tree component.
std::shared_ptr< ConversationTree > Ptr
const std::vector< Node > & getNodes() const
Used by the renderer component.
void setup(const sf::Vector2f &pos, const core::file::Conversation::Node &src, unsigned int i, bool terminator)