Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/dialog/Dialog.cc @ 12136

Last change on this file since 12136 was 11782, checked in by landauf, 7 years ago

tabs → spaces

  • Property svn:eol-style set to native
File size: 4.5 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    Question* Dialog::getQuestion(unsigned int index) const
92    {
93        unsigned int i = 0;
94        for (auto entry : this->questions_)
95        {
96            if (i == index)
97                return entry.second;
98            ++i;
99        }
100        return nullptr;
101    }
102
103    void Dialog::addAnswer(Answer* answer) //fuegt Answer der Map hinzu
104    {
105        this->answers_.insert(make_pair(answer->getAnswerId(), answer));
106    }
107
108    Answer* Dialog::getAnswer(unsigned int index) const
109    {
110        unsigned int i = 0;
111        for (auto entry : this->answers_)
112        {
113            if (i == index)
114                return entry.second;
115            ++i;
116        }
117        return nullptr;
118    }
119
120
121    const std::vector<std::string>& Dialog::getAnswerIds() const // returned vector mit allen momentanen AntwortenIds
122    {
123
124        Question* question = (this->questions_.find(this->currentQuestionId_))->second;
125        return question->getAnswerIds();
126
127    }
128
129    bool Dialog::execute(bool bTriggered, BaseObject* trigger)
130    { 
131        DialogManager& m = DialogManager::getInstance();
132
133        if(questions_.count(this->currentQuestionId_)){
134            m.setDialog(this);
135            OrxonoxOverlay::showOverlay("Dialog");
136        }
137        else {
138            orxout() << "no start defined " << endl;
139        }
140
141        return false;
142    }
143
144    void Dialog::update(const std::string& givenAnswerId)
145    {
146        Answer* answer = (answers_.find(givenAnswerId))->second;
147        this->currentQuestionId_ = answer->getNextQuestion();
148    }
149
150    bool Dialog::ending(const std::string& givenAnswerId)
151    {
152        return !this->questions_.count(this->answers_.find(givenAnswerId)->second->getNextQuestion());
153    }
154
155    const std::string& Dialog::getQuestionString()
156    {
157        return this->questions_.find(this->currentQuestionId_)->second->getQuestion();
158    }
159
160    const std::string& Dialog::getAnswerString(const std::string& answerId)
161    {
162        return this->answers_.find(answerId)->second->getAnswer();
163    }
164}
Note: See TracBrowser for help on using the repository browser.