Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Presentation_HS17_merge/src/modules/dialog/Dialog.cc @ 11749

Last change on this file since 11749 was 11749, checked in by landauf, 6 years ago

[Dialog_HS17] added license text

File size: 4.0 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      ...
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "DialogManager.h"
30#include "core/CoreIncludes.h"
31#include "core/XMLPort.h"
32#include "core/EventIncludes.h"
33#include "Dialog.h"
34#include "Question.h"
35
36
37namespace orxonox
38{
39
40        RegisterClass(Dialog);
41       
42        //Constructor:
43        Dialog::Dialog(Context* context) : BaseObject(context)
44        {
45                RegisterObject(Dialog);
46        }
47
48        void Dialog::XMLPort(Element& xmlelement, XMLPort::Mode mode)
49        {
50                SUPER(Dialog, XMLPort, xmlelement, mode);
51
52                XMLPortParam(Dialog, "name", setName, getName, xmlelement, mode);
53                XMLPortParam(Dialog, "currentQuestionId", setCurrentQuestionId, getCurrentQuestionId, xmlelement, mode);
54                XMLPortObject(Dialog, Question, "questions", addQuestion, getQuestion, xmlelement, mode);
55                XMLPortObject(Dialog, Answer, "answers", addAnswer, getAnswer, xmlelement, mode);
56        }
57
58        void Dialog::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
59    {
60        SUPER(Dialog, XMLEventPort, xmlelement, mode);
61
62        XMLPortEventSink(Dialog, BaseObject, "execute", execute, xmlelement, mode); 
63    }
64
65        void Dialog::setName(const std::string& name)
66        {
67                this->name_ = name;
68        }
69
70        const std::string& Dialog::getName() const 
71        {
72                return this->name_;
73        }
74
75        void Dialog::setCurrentQuestionId(const std::string& questionId)
76        {
77                this->currentQuestionId_ = questionId;
78        }
79
80        const std::string& Dialog::getCurrentQuestionId() const
81        {
82                return this->currentQuestionId_;
83        }
84
85
86        void Dialog::addQuestion(Question* question) //fuegt Question der Map hinzu
87        {
88                this->questions_.insert(make_pair(question->getQuestionId(), question));
89        }
90
91        const Question* Dialog::getQuestion() const // returned nichts
92        {
93                return nullptr;
94        }
95
96        void Dialog::addAnswer(Answer* answer) //fuegt Answer der Map hinzu
97        {
98                this->answers_.insert(make_pair(answer->getAnswerId(), answer));
99        }
100
101        const Answer* Dialog::getAnswer(unsigned int index) const       //returned sting der Antwort zur Id.
102        {
103                return nullptr;
104        }
105
106
107        const std::vector<std::string>* Dialog::getAnswerIds() // returned vector mit allen momentanen AntwortenIds
108        {
109               
110                Question* question = (this->questions_.find(this->currentQuestionId_))->second;
111                const std::vector<std::string>* answers = question->getAnswerIds();
112                return answers;
113               
114        } 
115       
116        bool Dialog::execute(bool bTriggered, BaseObject* trigger)
117    { 
118        DialogManager& m = DialogManager::getInstance();
119       
120        if(questions_.count(this->currentQuestionId_)){
121                m.setDialog(this);
122                OrxonoxOverlay::showOverlay("Dialog");
123        }
124        else {
125                orxout() << "no start defined " << endl;
126        }
127       
128        return false;
129    }
130
131    void Dialog::update(const std::string& givenAnswerId)
132    {
133        Answer* answer = (answers_.find(givenAnswerId))->second;
134        this->currentQuestionId_ = answer->getNextQuestion();
135    }
136
137    bool Dialog::ending(const std::string& givenAnswerId)
138    {
139        return !this->questions_.count(this->answers_.find(givenAnswerId)->second->getNextQuestion());
140    }
141
142        const std::string& Dialog::getQuestionString()
143        {
144                return this->questions_.find(this->currentQuestionId_)->second->getQuestion();
145        }
146
147        const std::string& Dialog::getAnswerString(std::string answerId)
148        {
149                return this->answers_.find(answerId)->second->getAnswer();
150        }
151}
Note: See TracBrowser for help on using the repository browser.