Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11607 was 11607, checked in by maxima, 6 years ago

No more compiler errors. XMLPortObjects not yet implemented.

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
8namespace orxonox
9{
10
11        RegisterClass(Dialog);
12       
13        //Constructor:
14        Dialog::Dialog(Context* context) : BaseObject(context)
15        {
16                RegisterObject(Dialog);
17        }
18
19        void Dialog::XMLPort(Element& xmlelement, XMLPort::Mode mode)
20        {
21                SUPER(Dialog, XMLPort, xmlelement, mode);
22
23                XMLPortParam(Dialog, "name", setName, getName, xmlelement, mode);
24                XMLPortParam(Dialog, "currentQuestionId", setCurrentQuestionId, getCurrentQuestionId, xmlelement, mode);
25                XMLPortObject(Dialog, Question, "Questions", addQuestion, getQuestion, xmlelement, mode);
26                XMLPortObject(Dialog, Answer, "Answers", addAnswer, getAnswer, xmlelement, mode);
27        }
28
29        void Dialog::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
30    {
31        SUPER(Dialog, XMLEventPort, xmlelement, mode);
32
33        XMLPortEventSink(Dialog, BaseObject, "execute", execute, xmlelement, mode); 
34    }
35
36        void Dialog::setName(std::string name)
37        {
38                this->name_ = name;
39        }
40
41        std::string Dialog::getName() 
42        {
43                return this->name_;
44        }
45
46        void Dialog::setCurrentQuestionId(std::string questionId)
47        {
48                this->currentQuestionId_ = questionId;
49        }
50
51        std::string Dialog::getCurrentQuestionId()
52        {
53                return this->currentQuestionId_;
54        }
55
56
57        void Dialog::addQuestion(Question* question) //fuegt Question der Map hinzu
58        {
59                //questions_.emplace(question->getQuestionId(), question->getQuestion());
60        }
61
62        void Dialog::addAnswer(Answer* answer) //fuegt Answer der Map hinzu
63        {
64                //answers_.emplace(std::make_pair(answer->getAnswerId(), answer->getAnswer()));
65        }
66
67        Question* Dialog::getQuestion(unsigned int index) const // returned nichts
68        {
69                return nullptr;
70                // Question question = (questions_.find(this->currentQuestionId_))->second;
71                // return question.getQuestion();
72        }
73
74        Answer* Dialog::getAnswer(unsigned int index) const//tolua_export               //returned sting der Antwort zur Id.
75        {
76                return nullptr;
77                // return (this->answers_.find(answerId))->second.getAnswer();
78        }
79
80        std::vector<std::string> Dialog::getAnswers() // returned vector mit allen momentanen AntwortenIds
81        {
82
83                Question question = (questions_.find(this->currentQuestionId_))->second;
84                std::vector<std::string> answers = question.getAnswerIds();
85                return answers;
86        } 
87       
88        bool Dialog::execute(bool bTriggered, BaseObject* trigger)
89    { 
90        DialogManager& m = DialogManager::getInstance();
91        m.setDialog(this);
92        orxout() << "dialog executed \n"; 
93        OrxonoxOverlay::showOverlay("Dialog");
94
95        return false;
96    }
97
98    void Dialog::update(std::string givenAnswer)
99    {
100        Answer answer = (answers_.find(givenAnswer))->second;
101        this->currentQuestionId_ = answer.getNextQuestion();
102    }
103
104    bool Dialog::ending() //tolua_export        //retruned true wenn die Id der Antwort end ist oder keine Antworten auf die frage eingetragen sind
105    {
106        bool end = false;
107        if (this->currentQuestionId_ == "end"){
108                end = true;
109        } else if ((questions_.find(this->currentQuestionId_)->second).getAnswerIds().empty()){
110                end = true;
111        }       
112        return end;
113    }
114}
Note: See TracBrowser for help on using the repository browser.