Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Dialog_HS17/src/modules/dialog/Dialog.cc @ 11658

Last change on this file since 11658 was 11644, checked in by kuchlert, 6 years ago

eigentlich fertig nur noch altes system entfernen

File size: 3.1 KB
RevLine 
[11579]1#include "DialogManager.h"
2#include "core/CoreIncludes.h"
3#include "core/XMLPort.h"
4#include "core/EventIncludes.h"
[11607]5#include "Dialog.h"
6#include "Question.h"
[11579]7
[11611]8
[11579]9namespace orxonox
10{
11
12        RegisterClass(Dialog);
13       
14        //Constructor:
15        Dialog::Dialog(Context* context) : BaseObject(context)
16        {
17                RegisterObject(Dialog);
18        }
19
20        void Dialog::XMLPort(Element& xmlelement, XMLPort::Mode mode)
21        {
22                SUPER(Dialog, XMLPort, xmlelement, mode);
23
24                XMLPortParam(Dialog, "name", setName, getName, xmlelement, mode);
25                XMLPortParam(Dialog, "currentQuestionId", setCurrentQuestionId, getCurrentQuestionId, xmlelement, mode);
[11642]26                XMLPortObject(Dialog, Question, "questions", addQuestion, getQuestion, xmlelement, mode);
27                XMLPortObject(Dialog, Answer, "answers", addAnswer, getAnswer, xmlelement, mode);
[11579]28        }
29
30        void Dialog::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
31    {
32        SUPER(Dialog, XMLEventPort, xmlelement, mode);
33
34        XMLPortEventSink(Dialog, BaseObject, "execute", execute, xmlelement, mode); 
35    }
36
[11644]37        void Dialog::setName(const std::string& name)
[11579]38        {
39                this->name_ = name;
40        }
41
[11644]42        const std::string& Dialog::getName() const 
[11579]43        {
44                return this->name_;
45        }
46
[11644]47        void Dialog::setCurrentQuestionId(const std::string& questionId)
[11579]48        {
49                this->currentQuestionId_ = questionId;
50        }
51
[11644]52        const std::string& Dialog::getCurrentQuestionId() const
[11579]53        {
54                return this->currentQuestionId_;
55        }
56
57
[11607]58        void Dialog::addQuestion(Question* question) //fuegt Question der Map hinzu
[11579]59        {
[11611]60                this->questions_.insert(make_pair(question->getQuestionId(), question));
[11579]61        }
62
[11644]63        const Question* Dialog::getQuestion() const // returned nichts
[11579]64        {
[11644]65                return nullptr;
[11579]66        }
67
[11644]68        void Dialog::addAnswer(Answer* answer) //fuegt Answer der Map hinzu
[11579]69        {
[11644]70                this->answers_.insert(make_pair(answer->getAnswerId(), answer));
[11579]71        }
72
[11644]73        const Answer* Dialog::getAnswer(unsigned int index) const       //returned sting der Antwort zur Id.
[11579]74        {
[11607]75                return nullptr;
[11579]76        }
77
[11644]78
79        const std::vector<std::string>* Dialog::getAnswerIds() // returned vector mit allen momentanen AntwortenIds
[11579]80        {
[11642]81               
[11611]82                Question* question = (this->questions_.find(this->currentQuestionId_))->second;
[11644]83                const std::vector<std::string>* answers = question->getAnswerIds();
[11579]84                return answers;
[11642]85               
[11579]86        } 
87       
88        bool Dialog::execute(bool bTriggered, BaseObject* trigger)
89    { 
90        DialogManager& m = DialogManager::getInstance();
[11642]91       
92        if(questions_.count(this->currentQuestionId_)){
93                m.setDialog(this);
94                OrxonoxOverlay::showOverlay("Dialog");
95        }
96        else {
97                orxout() << "no start defined " << endl;
98        }
99       
[11579]100        return false;
101    }
102
[11644]103    void Dialog::update(const std::string& givenAnswerId)
[11579]104    {
[11644]105        Answer* answer = (answers_.find(givenAnswerId))->second;
[11611]106        this->currentQuestionId_ = answer->getNextQuestion();
[11579]107    }
108
[11644]109    bool Dialog::ending(const std::string& givenAnswerId)
[11579]110    {
[11644]111        return !this->questions_.count(this->answers_.find(givenAnswerId)->second->getNextQuestion());
[11579]112    }
[11612]113
[11644]114        const std::string& Dialog::getQuestionString()
[11612]115        {
116                return this->questions_.find(this->currentQuestionId_)->second->getQuestion();
117        }
[11642]118
[11644]119        const std::string& Dialog::getAnswerString(std::string answerId)
[11642]120        {
121                return this->answers_.find(answerId)->second->getAnswer();
122        }
[11579]123}
Note: See TracBrowser for help on using the repository browser.