[11749] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * ... |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[11579] | 29 | #include "DialogManager.h" |
---|
| 30 | #include "core/CoreIncludes.h" |
---|
| 31 | #include "core/XMLPort.h" |
---|
| 32 | #include "core/EventIncludes.h" |
---|
[11607] | 33 | #include "Dialog.h" |
---|
| 34 | #include "Question.h" |
---|
[11579] | 35 | |
---|
[11611] | 36 | |
---|
[11579] | 37 | namespace orxonox |
---|
| 38 | { |
---|
| 39 | |
---|
[11782] | 40 | RegisterClass(Dialog); |
---|
[11579] | 41 | |
---|
[11782] | 42 | //Constructor: |
---|
| 43 | Dialog::Dialog(Context* context) : BaseObject(context) |
---|
| 44 | { |
---|
| 45 | RegisterObject(Dialog); |
---|
| 46 | } |
---|
[11579] | 47 | |
---|
[11782] | 48 | void Dialog::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 49 | { |
---|
| 50 | SUPER(Dialog, XMLPort, xmlelement, mode); |
---|
[11579] | 51 | |
---|
[11782] | 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) |
---|
[11579] | 59 | { |
---|
| 60 | SUPER(Dialog, XMLEventPort, xmlelement, mode); |
---|
| 61 | |
---|
| 62 | XMLPortEventSink(Dialog, BaseObject, "execute", execute, xmlelement, mode); |
---|
| 63 | } |
---|
| 64 | |
---|
[11782] | 65 | void Dialog::setName(const std::string& name) |
---|
| 66 | { |
---|
| 67 | this->name_ = name; |
---|
| 68 | } |
---|
[11579] | 69 | |
---|
[11782] | 70 | const std::string& Dialog::getName() const |
---|
| 71 | { |
---|
| 72 | return this->name_; |
---|
| 73 | } |
---|
[11579] | 74 | |
---|
[11782] | 75 | void Dialog::setCurrentQuestionId(const std::string& questionId) |
---|
| 76 | { |
---|
| 77 | this->currentQuestionId_ = questionId; |
---|
| 78 | } |
---|
[11579] | 79 | |
---|
[11782] | 80 | const std::string& Dialog::getCurrentQuestionId() const |
---|
| 81 | { |
---|
| 82 | return this->currentQuestionId_; |
---|
| 83 | } |
---|
[11579] | 84 | |
---|
| 85 | |
---|
[11782] | 86 | void Dialog::addQuestion(Question* question) //fuegt Question der Map hinzu |
---|
| 87 | { |
---|
| 88 | this->questions_.insert(make_pair(question->getQuestionId(), question)); |
---|
| 89 | } |
---|
[11579] | 90 | |
---|
[11782] | 91 | Question* Dialog::getQuestion(unsigned int index) const |
---|
| 92 | { |
---|
[11750] | 93 | unsigned int i = 0; |
---|
| 94 | for (auto entry : this->questions_) |
---|
| 95 | { |
---|
| 96 | if (i == index) |
---|
| 97 | return entry.second; |
---|
| 98 | ++i; |
---|
| 99 | } |
---|
| 100 | return nullptr; |
---|
[11782] | 101 | } |
---|
[11579] | 102 | |
---|
[11782] | 103 | void Dialog::addAnswer(Answer* answer) //fuegt Answer der Map hinzu |
---|
| 104 | { |
---|
| 105 | this->answers_.insert(make_pair(answer->getAnswerId(), answer)); |
---|
| 106 | } |
---|
[11579] | 107 | |
---|
[11782] | 108 | Answer* Dialog::getAnswer(unsigned int index) const |
---|
| 109 | { |
---|
[11750] | 110 | unsigned int i = 0; |
---|
| 111 | for (auto entry : this->answers_) |
---|
| 112 | { |
---|
| 113 | if (i == index) |
---|
| 114 | return entry.second; |
---|
| 115 | ++i; |
---|
| 116 | } |
---|
| 117 | return nullptr; |
---|
[11782] | 118 | } |
---|
[11579] | 119 | |
---|
[11644] | 120 | |
---|
[11782] | 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) |
---|
[11579] | 130 | { |
---|
[11782] | 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 | |
---|
[11579] | 141 | return false; |
---|
| 142 | } |
---|
| 143 | |
---|
[11644] | 144 | void Dialog::update(const std::string& givenAnswerId) |
---|
[11579] | 145 | { |
---|
[11782] | 146 | Answer* answer = (answers_.find(givenAnswerId))->second; |
---|
| 147 | this->currentQuestionId_ = answer->getNextQuestion(); |
---|
[11579] | 148 | } |
---|
| 149 | |
---|
[11644] | 150 | bool Dialog::ending(const std::string& givenAnswerId) |
---|
[11579] | 151 | { |
---|
[11782] | 152 | return !this->questions_.count(this->answers_.find(givenAnswerId)->second->getNextQuestion()); |
---|
[11579] | 153 | } |
---|
[11612] | 154 | |
---|
[11782] | 155 | const std::string& Dialog::getQuestionString() |
---|
| 156 | { |
---|
| 157 | return this->questions_.find(this->currentQuestionId_)->second->getQuestion(); |
---|
| 158 | } |
---|
[11642] | 159 | |
---|
[11782] | 160 | const std::string& Dialog::getAnswerString(const std::string& answerId) |
---|
| 161 | { |
---|
| 162 | return this->answers_.find(answerId)->second->getAnswer(); |
---|
| 163 | } |
---|
[11749] | 164 | } |
---|