Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

fixed addQuestion and addAnswer in Dialog

File size: 3.0 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(std::string name)
38        {
39                this->name_ = name;
40        }
41
42        std::string Dialog::getName() 
43        {
44                return this->name_;
45        }
46
47        void Dialog::setCurrentQuestionId(std::string questionId)
48        {
49                this->currentQuestionId_ = questionId;
50        }
51
52        std::string Dialog::getCurrentQuestionId()
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        void Dialog::addAnswer(Answer* answer) //fuegt Answer der Map hinzu
64        {
65                this->answers_.insert(make_pair(answer->getAnswerId(), answer));
66        }
67
68        Question* Dialog::getQuestion(unsigned int index) const // returned nichts
69        {
70                return nullptr;
71                // Question question = (questions_.find(this->currentQuestionId_))->second;
72                // return question.getQuestion();
73        }
74
75        Answer* Dialog::getAnswer(unsigned int index) const     //returned sting der Antwort zur Id.
76        {
77                return nullptr;
78                // return (this->answers_.find(answerId))->second.getAnswer();
79        }
80
81        std::vector<std::string> Dialog::getAnswers() // returned vector mit allen momentanen AntwortenIds
82        {
83
84                Question* question = (this->questions_.find(this->currentQuestionId_))->second;
85                std::vector<std::string> answers = question->getAnswerIds();
86                return answers;
87        } 
88       
89        bool Dialog::execute(bool bTriggered, BaseObject* trigger)
90    { 
91        DialogManager& m = DialogManager::getInstance();
92        m.setDialog(this);
93        orxout() << "dialog executed \n"; 
94        OrxonoxOverlay::showOverlay("Dialog");
95
96        return false;
97    }
98
99    void Dialog::update(std::string givenAnswer)
100    {
101        Answer* answer = (answers_.find(givenAnswer))->second;
102        this->currentQuestionId_ = answer->getNextQuestion();
103    }
104
105    bool Dialog::ending() //retruned true wenn die Id der Antwort end ist oder keine Antworten auf die frage eingetragen sind
106    {
107        bool end = false;
108        if (this->currentQuestionId_ == "end"){
109                end = true;
110        } else if ((this->questions_.find(this->currentQuestionId_)->second)->getAnswerIds().empty()){
111                end = true;
112        }       
113        return end;
114    }
115}
Note: See TracBrowser for help on using the repository browser.