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
RevLine 
[11749]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
[11579]29#include "DialogManager.h"
30#include "core/CoreIncludes.h"
31#include "core/XMLPort.h"
32#include "core/EventIncludes.h"
[11607]33#include "Dialog.h"
34#include "Question.h"
[11579]35
[11611]36
[11579]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);
[11642]54                XMLPortObject(Dialog, Question, "questions", addQuestion, getQuestion, xmlelement, mode);
55                XMLPortObject(Dialog, Answer, "answers", addAnswer, getAnswer, xmlelement, mode);
[11579]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
[11644]65        void Dialog::setName(const std::string& name)
[11579]66        {
67                this->name_ = name;
68        }
69
[11644]70        const std::string& Dialog::getName() const 
[11579]71        {
72                return this->name_;
73        }
74
[11644]75        void Dialog::setCurrentQuestionId(const std::string& questionId)
[11579]76        {
77                this->currentQuestionId_ = questionId;
78        }
79
[11644]80        const std::string& Dialog::getCurrentQuestionId() const
[11579]81        {
82                return this->currentQuestionId_;
83        }
84
85
[11607]86        void Dialog::addQuestion(Question* question) //fuegt Question der Map hinzu
[11579]87        {
[11611]88                this->questions_.insert(make_pair(question->getQuestionId(), question));
[11579]89        }
90
[11644]91        const Question* Dialog::getQuestion() const // returned nichts
[11579]92        {
[11644]93                return nullptr;
[11579]94        }
95
[11644]96        void Dialog::addAnswer(Answer* answer) //fuegt Answer der Map hinzu
[11579]97        {
[11644]98                this->answers_.insert(make_pair(answer->getAnswerId(), answer));
[11579]99        }
100
[11644]101        const Answer* Dialog::getAnswer(unsigned int index) const       //returned sting der Antwort zur Id.
[11579]102        {
[11607]103                return nullptr;
[11579]104        }
105
[11644]106
107        const std::vector<std::string>* Dialog::getAnswerIds() // returned vector mit allen momentanen AntwortenIds
[11579]108        {
[11642]109               
[11611]110                Question* question = (this->questions_.find(this->currentQuestionId_))->second;
[11644]111                const std::vector<std::string>* answers = question->getAnswerIds();
[11579]112                return answers;
[11642]113               
[11579]114        } 
115       
116        bool Dialog::execute(bool bTriggered, BaseObject* trigger)
117    { 
118        DialogManager& m = DialogManager::getInstance();
[11642]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       
[11579]128        return false;
129    }
130
[11644]131    void Dialog::update(const std::string& givenAnswerId)
[11579]132    {
[11644]133        Answer* answer = (answers_.find(givenAnswerId))->second;
[11611]134        this->currentQuestionId_ = answer->getNextQuestion();
[11579]135    }
136
[11644]137    bool Dialog::ending(const std::string& givenAnswerId)
[11579]138    {
[11644]139        return !this->questions_.count(this->answers_.find(givenAnswerId)->second->getNextQuestion());
[11579]140    }
[11612]141
[11644]142        const std::string& Dialog::getQuestionString()
[11612]143        {
144                return this->questions_.find(this->currentQuestionId_)->second->getQuestion();
145        }
[11642]146
[11644]147        const std::string& Dialog::getAnswerString(std::string answerId)
[11642]148        {
149                return this->answers_.find(answerId)->second->getAnswer();
150        }
[11749]151}
Note: See TracBrowser for help on using the repository browser.