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
Line 
1#include "DialogManager.h"
2#include "core/CoreIncludes.h"
3#include "core/XMLPort.h"
4#include "core/EventIncludes.h"
5#include "Dialog.h"
6#include "Question.h"
7
8
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);
26                XMLPortObject(Dialog, Question, "questions", addQuestion, getQuestion, xmlelement, mode);
27                XMLPortObject(Dialog, Answer, "answers", addAnswer, getAnswer, xmlelement, mode);
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
37        void Dialog::setName(const std::string& name)
38        {
39                this->name_ = name;
40        }
41
42        const std::string& Dialog::getName() const 
43        {
44                return this->name_;
45        }
46
47        void Dialog::setCurrentQuestionId(const std::string& questionId)
48        {
49                this->currentQuestionId_ = questionId;
50        }
51
52        const std::string& Dialog::getCurrentQuestionId() const
53        {
54                return this->currentQuestionId_;
55        }
56
57
58        void Dialog::addQuestion(Question* question) //fuegt Question der Map hinzu
59        {
60                this->questions_.insert(make_pair(question->getQuestionId(), question));
61        }
62
63        const Question* Dialog::getQuestion() const // returned nichts
64        {
65                return nullptr;
66        }
67
68        void Dialog::addAnswer(Answer* answer) //fuegt Answer der Map hinzu
69        {
70                this->answers_.insert(make_pair(answer->getAnswerId(), answer));
71        }
72
73        const Answer* Dialog::getAnswer(unsigned int index) const       //returned sting der Antwort zur Id.
74        {
75                return nullptr;
76        }
77
78
79        const std::vector<std::string>* Dialog::getAnswerIds() // returned vector mit allen momentanen AntwortenIds
80        {
81               
82                Question* question = (this->questions_.find(this->currentQuestionId_))->second;
83                const std::vector<std::string>* answers = question->getAnswerIds();
84                return answers;
85               
86        } 
87       
88        bool Dialog::execute(bool bTriggered, BaseObject* trigger)
89    { 
90        DialogManager& m = DialogManager::getInstance();
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       
100        return false;
101    }
102
103    void Dialog::update(const std::string& givenAnswerId)
104    {
105        Answer* answer = (answers_.find(givenAnswerId))->second;
106        this->currentQuestionId_ = answer->getNextQuestion();
107    }
108
109    bool Dialog::ending(const std::string& givenAnswerId)
110    {
111        return !this->questions_.count(this->answers_.find(givenAnswerId)->second->getNextQuestion());
112    }
113
114        const std::string& Dialog::getQuestionString()
115        {
116                return this->questions_.find(this->currentQuestionId_)->second->getQuestion();
117        }
118
119        const std::string& Dialog::getAnswerString(std::string answerId)
120        {
121                return this->answers_.find(answerId)->second->getAnswer();
122        }
123}
Note: See TracBrowser for help on using the repository browser.