Peoplemon  0.1.0
Peoplemon 3 game source documentation
ConversationNode.hpp
Go to the documentation of this file.
1 #ifndef EDITOR_COMPONENTS_CONVERSATIONNODE_HPP
2 #define EDITOR_COMPONENTS_CONVERSATIONNODE_HPP
3 
4 #include <BLIB/Interfaces/GUI.hpp>
8 
9 namespace editor
10 {
11 namespace component
12 {
19 public:
21  using NotifyCb = std::function<void()>;
22 
24  using CreateNode = std::function<unsigned int(unsigned int)>;
25 
27  using SelectCb = std::function<void(unsigned int)>;
28 
29  // Called when the window should force focus or not
30  using FocusCb = std::function<void(bool)>;
31 
44  ConversationNode(const FocusCb& focusCb, const NotifyCb& editCb, const NotifyCb& deleteCb,
45  const NotifyCb& regenTree, const CreateNode& createNode,
46  const SelectCb& selectCb, bl::gui::Box::Ptr& container,
47  const std::vector<core::file::Conversation::Node>* nodes);
48 
55  void update(unsigned int i, const core::file::Conversation::Node& node);
56 
63 
67  void setParent(bl::gui::GUI* parent);
68 
69 private:
70  class NodeConnector {
71  public:
72  using ChangeCb = std::function<void(unsigned int)>;
73 
74  NodeConnector(const std::string& prompt, const NotifyCb& regenTree,
75  const CreateNode& createNode, const NotifyCb& syncJumpCb,
76  const ChangeCb& changeCb, const SelectCb& selectCb,
77  const std::vector<core::file::Conversation::Node>* nodes);
78 
79  void sync();
80  void setSelected(unsigned int node);
81  unsigned int getSelected() const;
82  bl::gui::Box::Ptr& content();
83 
84  private:
85  bl::gui::Box::Ptr row;
86  bl::gui::ComboBox::Ptr entry;
87  const std::vector<core::file::Conversation::Node>* nodes;
88  };
89 
90  class Choice {
91  public:
92  using OnChange = std::function<void(unsigned int, const std::string&, unsigned int)>;
93  using OnDelete = std::function<void(unsigned int, std::list<Choice>::iterator)>;
94 
95  Choice(unsigned int index, const std::string& c, unsigned int jump,
96  const OnChange& onChange, const OnDelete& onDelete, const NotifyCb& regenTree,
97  const CreateNode& createNode, const NotifyCb& syncJumpCb, const SelectCb& selectCb,
98  const std::vector<core::file::Conversation::Node>* nodes);
99 
100  void setIndex(unsigned int i);
101  void setIterator(std::list<Choice>::iterator it);
102  bl::gui::Box::Ptr& content();
103  void syncJump();
104 
105  private:
106  const OnChange onChange;
107  const OnDelete onDelete;
108  const SelectCb onJump;
109  unsigned int index;
110  std::list<Choice>::iterator it;
111  bl::gui::Box::Ptr box;
112  bl::gui::TextEntry::Ptr entry;
113  NodeConnector jump;
114  };
115 
116  bl::gui::GUI* parent;
117  const FocusCb focusCb;
118  const NotifyCb onEdit;
119  const NotifyCb onDelete;
120  const NotifyCb regenTree;
121  const CreateNode createNodeCb;
122  const SelectCb onJump;
123  const std::vector<core::file::Conversation::Node>* allNodes;
125  unsigned int index;
126 
127  bl::gui::Label::Ptr nodeTitle;
128  bl::gui::Box::Ptr editArea;
129  bl::gui::ComboBox::Ptr typeEntry;
130 
131  NodeConnector passNext;
132  NodeConnector failNext;
133 
134  bl::gui::Box::Ptr promptRow;
135  bl::gui::TextEntry::Ptr promptEntry;
136  NodeConnector nextNode;
137 
138  bl::gui::Box::Ptr choiceArea;
139  bl::gui::ScrollArea::Ptr choiceScroll;
140  std::list<Choice> choices;
141  void onChoiceChange(unsigned int j, const std::string& t, unsigned int n);
142  void onChoiceDelete(unsigned int i, std::list<Choice>::iterator it);
143  void syncJumps();
144 
145  component::ItemSelector::Ptr itemSelector;
146  bl::gui::CheckButton::Ptr itemBeforeCheck;
147  bl::gui::CheckButton::Ptr itemAfterCheck;
148  bl::gui::Box::Ptr itemRow;
149  void onItemChange();
150 
151  bl::gui::Box::Ptr moneyRow;
152  bl::gui::TextEntry::Ptr moneyEntry;
153  void onMoneyChange();
154 
155  bl::gui::Box::Ptr flagRow;
156  bl::gui::TextEntry::Ptr flagEntry;
157 
158  bl::gui::Box::Ptr scriptRow;
159  bl::gui::Label::Ptr scriptLabel;
160  ScriptSelector scriptSelector;
161 
162  void onTypeChange();
163 };
164 
165 } // namespace component
166 } // namespace editor
167 
168 #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...
Helper component for editing individual conversation nodes.
const core::file::Conversation::Node & getValue() const
Get the current node value.
std::function< unsigned int(unsigned int)> CreateNode
Called when a new node should be created.
void update(unsigned int i, const core::file::Conversation::Node &node)
Update the node editor content with the given node value.
std::function< void(unsigned int)> SelectCb
Called when a node is jumped to.
std::function< void(bool)> FocusCb
std::function< void()> NotifyCb
Called when the node value is modified.
void setParent(bl::gui::GUI *parent)
Set the parent GUI object.
ConversationNode(const FocusCb &focusCb, const NotifyCb &editCb, const NotifyCb &deleteCb, const NotifyCb &regenTree, const CreateNode &createNode, const SelectCb &selectCb, bl::gui::Box::Ptr &container, const std::vector< core::file::Conversation::Node > *nodes)
Construct a new Conversation Node editor.
std::shared_ptr< ItemSelector > Ptr
Pointer to this component.