- Timestamp:
- Feb 20, 2018, 12:09:09 AM (7 years ago)
- Location:
- code/branches/Presentation_HS17_merge/src/modules/dialog
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Presentation_HS17_merge/src/modules/dialog/Answer.cc
r11781 r11782 33 33 namespace orxonox{ 34 34 35 35 RegisterClass(Answer); 36 36 37 37 38 39 Answer::Answer(Context* context) : BaseObject(context) 40 41 42 38 // Constructor: 39 Answer::Answer(Context* context) : BaseObject(context) 40 { 41 RegisterObject(Answer); 42 } 43 43 44 45 46 44 void Answer::XMLPort(Element& xmlelement, XMLPort::Mode mode) 45 { 46 SUPER(Answer, XMLPort, xmlelement, mode); 47 47 48 49 50 51 48 XMLPortParam(Answer, "Id", setAnswerId, getAnswerId, xmlelement, mode); 49 XMLPortParam(Answer, "answer", setAnswer, getAnswer, xmlelement, mode); 50 XMLPortParam(Answer, "nextQuestionId", setNextQuestion, getNextQuestion, xmlelement,mode); 51 } 52 52 53 54 55 53 void Answer::setAnswerId(const std::string& answerId){ 54 this->answerId_ = answerId; 55 } 56 56 57 58 59 60 57 const std::string& Answer::getAnswerId() const 58 { 59 return this->answerId_; 60 } 61 61 62 63 64 65 62 void Answer::setNextQuestion(const std::string& nextId) 63 { 64 this->nextQuestionId_ = nextId; 65 } 66 66 67 68 69 70 67 const std::string& Answer::getNextQuestion() const 68 { 69 return this->nextQuestionId_; 70 } 71 71 72 73 74 75 72 void Answer::setAnswer(const std::string& answer) 73 { 74 this->answer_ = answer; 75 } 76 76 77 78 79 80 81 } 77 const std::string& Answer::getAnswer() const 78 { 79 return this->answer_; 80 } 81 } -
code/branches/Presentation_HS17_merge/src/modules/dialog/Answer.h
r11781 r11782 38 38 namespace orxonox 39 39 { 40 41 40 /** 41 @brief 42 42 class containing the pc side of the Dialog 43 43 44 44 this class contains one possible text option of the pc, it's id and the id of the reaction of the npc to this answer 45 45 */ 46 46 47 class _DialogExport Answer : public BaseObject 48 { 49 public: 50 Answer(Context* context); 51 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 class _DialogExport Answer : public BaseObject 48 { 49 public: 50 Answer(Context* context); 53 51 54 void setAnswerId(const std::string& answerId); //xmlPort-Funktion, setzt AntwortId 55 const std::string& getAnswerId() const; //xmlPort-Funktion, gibt AntwortId 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 56 53 57 void setNextQuestion(const std::string& nextId); //xmlPort-Funktion, um Dialog zu beenden tag benutzen der von keiner Frage benutzt wird58 const std::string& getNextQuestion() const; //xmlPort-Funktion, gibt Id der Folgefrage 54 void setAnswerId(const std::string& answerId); //xmlPort-Funktion, setzt AntwortId 55 const std::string& getAnswerId() const; //xmlPort-Funktion, gibt AntwortId 59 56 60 void setAnswer(const std::string& awns); //xmlPort-Funktion, setzt Antworttext 61 const std::string& getAnswer() const; //xmlPort-Funktion, gibt Antworttext 57 void setNextQuestion(const std::string& nextId); //xmlPort-Funktion, um Dialog zu beenden tag benutzen der von keiner Frage benutzt wird 58 const std::string& getNextQuestion() const; //xmlPort-Funktion, gibt Id der Folgefrage 62 59 63 private: 64 std::string answerId_; //!< id of the pc textoption 65 std::string answer_; //!< string with the pc text 66 std::string nextQuestionId_; //!< id of the npc reaction to pc answer 67 }; 60 void setAnswer(const std::string& awns); //xmlPort-Funktion, setzt Antworttext 61 const std::string& getAnswer() const; //xmlPort-Funktion, gibt Antworttext 62 63 private: 64 std::string answerId_; //!< id of the pc textoption 65 std::string answer_; //!< string with the pc text 66 std::string nextQuestionId_; //!< id of the npc reaction to pc answer 67 }; 68 68 } 69 69 -
code/branches/Presentation_HS17_merge/src/modules/dialog/AnswerId.cc
r11781 r11782 33 33 namespace orxonox{ 34 34 35 35 RegisterClass(AnswerId); 36 36 37 38 39 40 37 AnswerId::AnswerId(Context* context) : BaseObject(context) 38 { 39 RegisterObject(AnswerId); 40 } 41 41 42 43 44 42 void AnswerId::XMLPort(Element& xmlelement, XMLPort::Mode mode) 43 { 44 SUPER(AnswerId, XMLPort, xmlelement, mode); 45 45 46 47 46 XMLPortParam(AnswerId, "Id", setId, getId, xmlelement, mode); 47 } 48 48 49 50 51 52 53 54 55 56 57 49 void AnswerId::setId(const std::string& id) 50 { 51 this->id_ = id; 52 } 53 54 const std::string& AnswerId::getId() const 55 { 56 return this->id_; 57 } 58 58 } -
code/branches/Presentation_HS17_merge/src/modules/dialog/AnswerId.h
r11781 r11782 39 39 namespace orxonox{ 40 40 41 42 41 /** 42 @brief 43 43 container class for answerids in xml 44 44 45 45 */ 46 46 47 class _DialogExport AnswerId : public BaseObject 48 { 49 public: 50 AnswerId(Context* context); 51 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 class _DialogExport AnswerId : public BaseObject 48 { 49 public: 50 AnswerId(Context* context); 53 51 54 void setId(const std::string& Id); //allows to set Id, only use in xmlPort for initializing AnswerIds in lvl files 55 const std::string& getId() const; //allows to get Id, used in xmlPort 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 56 53 57 private: 58 std::string id_; //!< id of one answer 59 }; 54 void setId(const std::string& Id); //allows to set Id, only use in xmlPort for initializing AnswerIds in lvl files 55 const std::string& getId() const; //allows to get Id, used in xmlPort 56 57 private: 58 std::string id_; //!< id of one answer 59 }; 60 60 } 61 61 -
code/branches/Presentation_HS17_merge/src/modules/dialog/Dialog.cc
r11781 r11782 38 38 { 39 39 40 RegisterClass(Dialog); 41 42 //Constructor: 43 Dialog::Dialog(Context* context) : BaseObject(context) 44 { 45 RegisterObject(Dialog); 46 } 40 RegisterClass(Dialog); 47 41 48 void Dialog::XMLPort(Element& xmlelement, XMLPort::Mode mode) 49 { 50 SUPER(Dialog, XMLPort, xmlelement, mode); 42 //Constructor: 43 Dialog::Dialog(Context* context) : BaseObject(context) 44 { 45 RegisterObject(Dialog); 46 } 51 47 52 XMLPortParam(Dialog, "name", setName, getName, xmlelement, mode); 53 XMLPortParam(Dialog, "currentQuestionId", setCurrentQuestionId, getCurrentQuestionId, xmlelement, mode); 54 XMLPortObject(Dialog, Question, "questions", addQuestion, getQuestion, xmlelement, mode); 55 XMLPortObject(Dialog, Answer, "answers", addAnswer, getAnswer, xmlelement, mode); 56 } 48 void Dialog::XMLPort(Element& xmlelement, XMLPort::Mode mode) 49 { 50 SUPER(Dialog, XMLPort, xmlelement, mode); 57 51 58 void Dialog::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 52 XMLPortParam(Dialog, "name", setName, getName, xmlelement, mode); 53 XMLPortParam(Dialog, "currentQuestionId", setCurrentQuestionId, getCurrentQuestionId, xmlelement, mode); 54 XMLPortObject(Dialog, Question, "questions", addQuestion, getQuestion, xmlelement, mode); 55 XMLPortObject(Dialog, Answer, "answers", addAnswer, getAnswer, xmlelement, mode); 56 } 57 58 void Dialog::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 59 59 { 60 60 SUPER(Dialog, XMLEventPort, xmlelement, mode); … … 63 63 } 64 64 65 66 67 68 65 void Dialog::setName(const std::string& name) 66 { 67 this->name_ = name; 68 } 69 69 70 const std::string& Dialog::getName() const 71 72 73 70 const std::string& Dialog::getName() const 71 { 72 return this->name_; 73 } 74 74 75 76 77 78 75 void Dialog::setCurrentQuestionId(const std::string& questionId) 76 { 77 this->currentQuestionId_ = questionId; 78 } 79 79 80 81 82 83 80 const std::string& Dialog::getCurrentQuestionId() const 81 { 82 return this->currentQuestionId_; 83 } 84 84 85 85 86 87 88 89 86 void Dialog::addQuestion(Question* question) //fuegt Question der Map hinzu 87 { 88 this->questions_.insert(make_pair(question->getQuestionId(), question)); 89 } 90 90 91 92 91 Question* Dialog::getQuestion(unsigned int index) const 92 { 93 93 unsigned int i = 0; 94 94 for (auto entry : this->questions_) … … 99 99 } 100 100 return nullptr; 101 101 } 102 102 103 104 105 106 103 void Dialog::addAnswer(Answer* answer) //fuegt Answer der Map hinzu 104 { 105 this->answers_.insert(make_pair(answer->getAnswerId(), answer)); 106 } 107 107 108 109 108 Answer* Dialog::getAnswer(unsigned int index) const 109 { 110 110 unsigned int i = 0; 111 111 for (auto entry : this->answers_) … … 116 116 } 117 117 return nullptr; 118 118 } 119 119 120 120 121 122 123 124 125 126 127 } 128 129 121 const std::vector<std::string>& Dialog::getAnswerIds() const // returned vector mit allen momentanen AntwortenIds 122 { 123 124 Question* question = (this->questions_.find(this->currentQuestionId_))->second; 125 return question->getAnswerIds(); 126 127 } 128 129 bool Dialog::execute(bool bTriggered, BaseObject* trigger) 130 130 { 131 132 133 134 135 136 137 138 139 140 131 DialogManager& m = DialogManager::getInstance(); 132 133 if(questions_.count(this->currentQuestionId_)){ 134 m.setDialog(this); 135 OrxonoxOverlay::showOverlay("Dialog"); 136 } 137 else { 138 orxout() << "no start defined " << endl; 139 } 140 141 141 return false; 142 142 } … … 144 144 void Dialog::update(const std::string& givenAnswerId) 145 145 { 146 147 146 Answer* answer = (answers_.find(givenAnswerId))->second; 147 this->currentQuestionId_ = answer->getNextQuestion(); 148 148 } 149 149 150 150 bool Dialog::ending(const std::string& givenAnswerId) 151 151 { 152 152 return !this->questions_.count(this->answers_.find(givenAnswerId)->second->getNextQuestion()); 153 153 } 154 154 155 156 157 158 155 const std::string& Dialog::getQuestionString() 156 { 157 return this->questions_.find(this->currentQuestionId_)->second->getQuestion(); 158 } 159 159 160 161 162 163 160 const std::string& Dialog::getAnswerString(const std::string& answerId) 161 { 162 return this->answers_.find(answerId)->second->getAnswer(); 163 } 164 164 } -
code/branches/Presentation_HS17_merge/src/modules/dialog/Dialog.h
r11781 r11782 44 44 namespace orxonox 45 45 { 46 47 46 /** 47 @brief 48 48 class containing core of one dialog with one npc 49 49 … … 51 51 it realizes a state machine with the question beeing the states and the answers beeing the connections, it has a current state and 52 52 can be commanded to go to the next state according to a given answer 53 53 */ 54 54 55 56 57 58 55 class _DialogExport Dialog : public BaseObject 56 { 57 public: 58 Dialog(Context* context); 59 59 60 61 60 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 61 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 62 62 63 void setName(const std::string& name);//xmlPort-Funktion, sets Namen64 const std::string& getName() const;//xmlPort-Funktion, returns Namen63 void setName(const std::string& name); //xmlPort-Funktion, sets Namen 64 const std::string& getName() const; //xmlPort-Funktion, returns Namen 65 65 66 void setCurrentQuestionId(const std::string& questionId);//xmlPort-Funktion, sets string id of current question67 const std::string& getCurrentQuestionId() const;//xmlPort-Funktion, returns id of current question66 void setCurrentQuestionId(const std::string& questionId); //xmlPort-Funktion, sets string id of current question 67 const std::string& getCurrentQuestionId() const; //xmlPort-Funktion, returns id of current question 68 68 69 70 69 void addQuestion(Question* question); //xmlPort-Funktion, adds question to map 70 Question* getQuestion(unsigned int index) const; //xmlPort-Funktion 71 71 72 73 72 void addAnswer(Answer* answer); //xmlPort-Funktion, adds answer to map 73 Answer* getAnswer(unsigned int index) const; //xmlPort-Funktion 74 74 75 76 77 75 /** 76 @brief 77 returns a pointer to the array of answers belonging to the current question for use in dialogManager 78 78 79 80 81 82 79 @return 80 pointer to answerId array of question 81 */ 82 const std::vector<std::string>& getAnswerIds() const; 83 83 84 85 86 84 /** 85 @brief 86 function called when the trigger object defined in the xml file sets to triggered 87 87 88 89 90 91 92 93 94 95 88 @param bTriggered 89 needs to be set like this for correctness 90 @param trigger 91 needs to be set like this for correctness 92 @return 93 not really used 94 */ 95 bool execute(bool bTriggered, BaseObject* trigger); 96 96 97 98 99 97 /** 98 @brief 99 updates the current Dialog according to the id of a given answer, by setting currentQuestionId to the next one 100 100 101 102 103 104 101 @param givenAnswerId 102 id of the answer given by player 103 */ 104 void update(const std::string& givenAnswerId); 105 105 106 107 108 106 /** 107 @brief 108 tests if there is a next question for the given answerId 109 109 110 111 112 113 114 115 110 @param givenAnswerId 111 id of the answer given by player 112 @return 113 true if there is no more Question to the given answerId 114 */ 115 bool ending(const std::string& givenAnswerId); 116 116 117 118 119 117 /** 118 @brief 119 gives the text of the npc in the current state 120 120 121 122 123 124 121 @return 122 sting with npc text 123 */ 124 const std::string& getQuestionString(); 125 125 126 127 128 returns a sting with the pc answer to the id 126 /** 127 @brief 128 returns a sting with the pc answer to the id 129 129 130 131 132 133 134 135 130 @param answerId 131 the id of the answer looked for 132 @return 133 sting with answer 134 */ 135 const std::string& getAnswerString(const std::string& answerId); 136 136 137 private: 138 std::string name_;//!< name of the npc talking139 std::string currentQuestionId_;//!< id of the npc question currently active140 std::map<std::string, Question*> questions_;//!< a map form the ids of npc textoptions to the objects containing them141 std::map<std::string, Answer*> answers_;//!< a map form the ids of npc textoptions to the objects containing them142 137 private: 138 std::string name_; //!< name of the npc talking 139 std::string currentQuestionId_; //!< id of the npc question currently active 140 std::map<std::string, Question*> questions_; //!< a map form the ids of npc textoptions to the objects containing them 141 std::map<std::string, Answer*> answers_; //!< a map form the ids of npc textoptions to the objects containing them 142 }; 143 143 } 144 144 -
code/branches/Presentation_HS17_merge/src/modules/dialog/DialogManager.cc
r11781 r11782 33 33 34 34 namespace orxonox { 35 ManageScopedSingleton(DialogManager, ScopeID::ROOT, false); 36 35 ManageScopedSingleton(DialogManager, ScopeID::ROOT, false); 37 36 38 39 DialogManager::DialogManager()40 {41 this->currentTalk_ = nullptr;42 this->answerIds_ = nullptr;43 }44 37 45 void DialogManager::setDialog(Dialog* dialog)46 {47 this->currentTalk_ = dialog;48 this->answerIds_ = &this->currentTalk_->getAnswerIds();49 }50 38 51 //from here onward funcionality for lua axports 39 DialogManager::DialogManager() 40 { 41 this->currentTalk_ = nullptr; 42 this->answerIds_ = nullptr; 43 } 44 45 void DialogManager::setDialog(Dialog* dialog) 46 { 47 this->currentTalk_ = dialog; 48 this->answerIds_ = &this->currentTalk_->getAnswerIds(); 49 } 50 51 //from here onward funcionality for lua axports 52 52 53 53 std::string DialogManager::getQuestion() 54 54 { 55 55 return this->currentTalk_->getQuestionString(); 56 56 } 57 57 … … 63 63 std::string DialogManager::getAnswer(int index) 64 64 { 65 65 return this->currentTalk_->getAnswerString(this->answerIds_->at(index)); 66 66 } 67 67 68 68 std::string DialogManager::getPerson() 69 69 { 70 70 return this->currentTalk_->getName(); 71 71 } 72 72 … … 86 86 void DialogManager::update(int index) 87 87 { 88 89 88 this->currentTalk_->update(this->answerIds_->at(index)); 89 this->answerIds_ = &this->currentTalk_->getAnswerIds(); 90 90 } 91 91 } -
code/branches/Presentation_HS17_merge/src/modules/dialog/Question.cc
r11781 r11782 33 33 { 34 34 35 35 RegisterClass(Question); 36 36 37 38 39 40 37 Question::Question(Context* context) : BaseObject(context) 38 { 39 RegisterObject(Question); 40 } 41 41 42 43 44 42 void Question::XMLPort(Element& xmlement, XMLPort::Mode mode) 43 { 44 SUPER(Question, XMLPort, xmlement, mode); 45 45 46 47 46 XMLPortParam(Question, "question", setQuestion, getQuestion, xmlement, mode); 47 XMLPortParam(Question, "Id", setQuestionId, getQuestionId, xmlement, mode); 48 48 49 50 49 XMLPortObject(Question, AnswerId, "answerIds", addAnswerId, getAnswerId, xmlement, mode); 50 } 51 51 52 53 54 55 52 void Question::setQuestionId(const std::string& Id) 53 { 54 this->questionId_ = Id; 55 } 56 56 57 58 59 60 57 const std::string& Question::getQuestionId() const 58 { 59 return this->questionId_; 60 } 61 61 62 63 64 65 62 void Question::setQuestion(const std::string& question) 63 { 64 this->question_ = question; 65 } 66 66 67 68 69 70 67 const std::string& Question::getQuestion() const 68 { 69 return this->question_; 70 } 71 71 72 73 74 75 72 void Question::addAnswerId(AnswerId* answerId) 73 { 74 this->answerIds_.push_back(answerId->getId()); 75 } 76 76 77 78 79 80 77 AnswerId* Question::getAnswerId(unsigned int index) const 78 { 79 return nullptr; 80 } 81 81 82 const std::vector<std::string>& Question::getAnswerIds() const 83 { 84 return this->answerIds_; 85 } 86 82 const std::vector<std::string>& Question::getAnswerIds() const 83 { 84 return this->answerIds_; 85 } 87 86 } -
code/branches/Presentation_HS17_merge/src/modules/dialog/Question.h
r11781 r11782 42 42 { 43 43 44 45 44 /** 45 @brief 46 46 class containing the npc side of the Dialog 47 47 48 48 this class contains one possible text option of the npc, it's id and the ids of possible player reactions (answers) 49 49 */ 50 50 51 52 53 54 51 class _DialogExport Question : public BaseObject 52 { 53 public: 54 Question(Context* context); 55 55 56 56 virtual void XMLPort(Element& xmelement, XMLPort::Mode mode); 57 57 58 void setQuestionId(const std::string& Id);//xmlPort-Funktion, setzt Id59 const std::string& getQuestionId() const;//xmlPort-Funktion, gibt Id string zuruek58 void setQuestionId(const std::string& Id); //xmlPort-Funktion, setzt Id 59 const std::string& getQuestionId() const; //xmlPort-Funktion, gibt Id string zuruek 60 60 61 void setQuestion(const std::string& question);//xmlPort-Funktion, setzt Fragen string62 const std::string& getQuestion() const;//xmlPort-Funktion, gibt Fragen string61 void setQuestion(const std::string& question); //xmlPort-Funktion, setzt Fragen string 62 const std::string& getQuestion() const; //xmlPort-Funktion, gibt Fragen string 63 63 64 void addAnswerId(AnswerId* answerId);//xmlPort-Funktion, nimmt AnswerIds von entsprechenden Objekten und fuegt sie in List ein.65 AnswerId* getAnswerId(unsigned int index) const;//xmlPort-Funktion, gibt nichts zuruek64 void addAnswerId(AnswerId* answerId); //xmlPort-Funktion, nimmt AnswerIds von entsprechenden Objekten und fuegt sie in List ein. 65 AnswerId* getAnswerId(unsigned int index) const; //xmlPort-Funktion, gibt nichts zuruek 66 66 67 68 69 67 /** 68 @brief 69 gives pointer to possivle answerIds of this question 70 70 71 72 73 74 71 @return 72 returns pointer to the array with ids of possible pc textoptions 73 */ 74 const std::vector<std::string>& getAnswerIds() const; //returnt Pointer auf Vektor mit allen Ids 75 75 76 76 77 77 78 private: 79 std::string questionId_; //!< id of npc textoption 80 std::string question_;//!< string with npc text81 std::vector<std::string> answerIds_;//!< vector with possible player reactions82 78 private: 79 std::string questionId_; //!< id of npc textoption 80 std::string question_; //!< string with npc text 81 std::vector<std::string> answerIds_; //!< vector with possible player reactions 82 }; 83 83 } 84 84
Note: See TracChangeset
for help on using the changeset viewer.