1 | #ifndef _Dialog_H__ |
---|
2 | #define _Dialog_H__ |
---|
3 | |
---|
4 | #include "core/BaseObject.h" |
---|
5 | #include "DialogPrereqs.h" |
---|
6 | #include "Question.h" |
---|
7 | #include "Answer.h" |
---|
8 | #include "core/XMLPort.h" |
---|
9 | #include "core/CoreIncludes.h" |
---|
10 | #include "overlays/OrxonoxOverlay.h" |
---|
11 | |
---|
12 | #include <map> |
---|
13 | #include <vector> |
---|
14 | #include <string> |
---|
15 | |
---|
16 | namespace orxonox |
---|
17 | { |
---|
18 | /** |
---|
19 | @brief |
---|
20 | class containing core of one dialog with one npc |
---|
21 | |
---|
22 | this class contains a map of all answerids to answers (player text options) and one of all questionids to questions (npc text options) |
---|
23 | it realizes a state machine with the question beeing the states and the answers beeing the connections, it has a current state and |
---|
24 | can be commanded to go to the next state according to a given answer |
---|
25 | */ |
---|
26 | |
---|
27 | class _DialogExport Dialog : public BaseObject |
---|
28 | { |
---|
29 | public: |
---|
30 | Dialog(Context* context); |
---|
31 | |
---|
32 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
33 | virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); |
---|
34 | |
---|
35 | void setName(const std::string& name); //xmlPort-Funktion, sets Namen |
---|
36 | const std::string& getName() const; //xmlPort-Funktion, returns Namen |
---|
37 | |
---|
38 | void setCurrentQuestionId(const std::string& questionId); //xmlPort-Funktion, sets string id of current question |
---|
39 | const std::string& getCurrentQuestionId() const; //xmlPort-Funktion, returns id of current question |
---|
40 | |
---|
41 | void addQuestion(Question* question); //xmlPort-Funktion, adds question to map |
---|
42 | const Question* getQuestion() const; //xmlPort-Funktion, returns nullptr |
---|
43 | |
---|
44 | void addAnswer(Answer* answer); //xmlPort-Funktion, adds answer to map |
---|
45 | const Answer* getAnswer(unsigned int index) const; //xmlPort-Funktion, returns nullptr |
---|
46 | |
---|
47 | /** |
---|
48 | @brief |
---|
49 | returns a pointer to the array of answers belonging to the current question for use in dialogManager |
---|
50 | |
---|
51 | @return |
---|
52 | pointer to answerId array of question |
---|
53 | */ |
---|
54 | const std::vector<std::string>* getAnswerIds(); |
---|
55 | |
---|
56 | /** |
---|
57 | @brief |
---|
58 | function called when the trigger object defined in the xml file sets to triggered |
---|
59 | |
---|
60 | @param bTriggered |
---|
61 | needs to be set like this for correctness |
---|
62 | @param trigger |
---|
63 | needs to be set like this for correctness |
---|
64 | @return |
---|
65 | not really used |
---|
66 | */ |
---|
67 | bool execute(bool bTriggered, BaseObject* trigger); |
---|
68 | |
---|
69 | /** |
---|
70 | @brief |
---|
71 | updates the current Dialog according to the id of a given answer, by setting currentQuestionId to the next one |
---|
72 | |
---|
73 | @param givenAnswerId |
---|
74 | id of the answer given by player |
---|
75 | */ |
---|
76 | void update(const std::string& givenAnswerId); |
---|
77 | |
---|
78 | /** |
---|
79 | @brief |
---|
80 | tests if there is a next question for the given answerId |
---|
81 | |
---|
82 | @param givenAnswerId |
---|
83 | id of the answer given by player |
---|
84 | @return |
---|
85 | true if there is no more Question to the given answerId |
---|
86 | */ |
---|
87 | bool ending(const std::string& givenAnswerId); |
---|
88 | |
---|
89 | /** |
---|
90 | @brief |
---|
91 | gives the text of the npc in the current state |
---|
92 | |
---|
93 | @return |
---|
94 | sting with npc text |
---|
95 | */ |
---|
96 | const std::string& getQuestionString(); |
---|
97 | |
---|
98 | /** |
---|
99 | @brief |
---|
100 | returns a sting with the pc answer to the id |
---|
101 | |
---|
102 | @param answerId |
---|
103 | the id of the answer looked for |
---|
104 | @return |
---|
105 | sting with answer |
---|
106 | */ |
---|
107 | const std::string& getAnswerString(std::string answerId); |
---|
108 | |
---|
109 | private: |
---|
110 | std::string name_; //!< name of the npc talking |
---|
111 | std::string currentQuestionId_; //!< id of the npc question currently active |
---|
112 | std::map<std::string, Question*> questions_; //!< a map form the ids of npc textoptions to the objects containing them |
---|
113 | std::map<std::string, Answer*> answers_; //!< a map form the ids of npc textoptions to the objects containing them |
---|
114 | }; |
---|
115 | } |
---|
116 | |
---|
117 | #endif |
---|