/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * ... * Co-authors: * ... * */ #include "DialogManager.h" #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "core/EventIncludes.h" #include "Dialog.h" #include "Question.h" namespace orxonox { RegisterClass(Dialog); //Constructor: Dialog::Dialog(Context* context) : BaseObject(context) { RegisterObject(Dialog); } void Dialog::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(Dialog, XMLPort, xmlelement, mode); XMLPortParam(Dialog, "name", setName, getName, xmlelement, mode); XMLPortParam(Dialog, "currentQuestionId", setCurrentQuestionId, getCurrentQuestionId, xmlelement, mode); XMLPortObject(Dialog, Question, "questions", addQuestion, getQuestion, xmlelement, mode); XMLPortObject(Dialog, Answer, "answers", addAnswer, getAnswer, xmlelement, mode); } void Dialog::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(Dialog, XMLEventPort, xmlelement, mode); XMLPortEventSink(Dialog, BaseObject, "execute", execute, xmlelement, mode); } void Dialog::setName(const std::string& name) { this->name_ = name; } const std::string& Dialog::getName() const { return this->name_; } void Dialog::setCurrentQuestionId(const std::string& questionId) { this->currentQuestionId_ = questionId; } const std::string& Dialog::getCurrentQuestionId() const { return this->currentQuestionId_; } void Dialog::addQuestion(Question* question) //fuegt Question der Map hinzu { this->questions_.insert(make_pair(question->getQuestionId(), question)); } Question* Dialog::getQuestion(unsigned int index) const { unsigned int i = 0; for (auto entry : this->questions_) { if (i == index) return entry.second; ++i; } return nullptr; } void Dialog::addAnswer(Answer* answer) //fuegt Answer der Map hinzu { this->answers_.insert(make_pair(answer->getAnswerId(), answer)); } Answer* Dialog::getAnswer(unsigned int index) const { unsigned int i = 0; for (auto entry : this->answers_) { if (i == index) return entry.second; ++i; } return nullptr; } const std::vector& Dialog::getAnswerIds() const // returned vector mit allen momentanen AntwortenIds { Question* question = (this->questions_.find(this->currentQuestionId_))->second; return question->getAnswerIds(); } bool Dialog::execute(bool bTriggered, BaseObject* trigger) { DialogManager& m = DialogManager::getInstance(); if(questions_.count(this->currentQuestionId_)){ m.setDialog(this); OrxonoxOverlay::showOverlay("Dialog"); } else { orxout() << "no start defined " << endl; } return false; } void Dialog::update(const std::string& givenAnswerId) { Answer* answer = (answers_.find(givenAnswerId))->second; this->currentQuestionId_ = answer->getNextQuestion(); } bool Dialog::ending(const std::string& givenAnswerId) { return !this->questions_.count(this->answers_.find(givenAnswerId)->second->getNextQuestion()); } const std::string& Dialog::getQuestionString() { return this->questions_.find(this->currentQuestionId_)->second->getQuestion(); } const std::string& Dialog::getAnswerString(const std::string& answerId) { return this->answers_.find(answerId)->second->getAnswer(); } }