Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/world_entities/questGUI/quest_gui.cc @ 10222

Last change on this file since 10222 was 10222, checked in by hejja, 17 years ago

more

File size: 5.8 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 1004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer    std::string             questName;
15    std::string             questDescription;
16    std::string             questPicture;
17    std::string             questDifficulty;
18    std::string             rewardDescription;
19    std::string             rewardPicture;: Andreas Hejj
20
21*/
22
23
24#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
25
26#include "debug.h"
27#include "quest_gui.h"
28
29#include "event_handler.h"
30
31#include "state.h"
32
33#include "util/loading/load_param.h"
34#include "util/loading/factory.h"
35
36#include "graphics_engine.h"
37#include "camera.h"
38#include "sound_engine.h"
39
40#include "sound_source.h"
41
42#include "glgui_widget.h"
43#include "glgui.h"
44#include "menu/glgui_imagebutton.h"
45#include "glgui_multiline_text.h"
46#include <glgui_image.h>
47
48
49#include "quest.h"
50
51#include "shell_command.h"
52
53
54
55
56ObjectListDefinition(QuestGUI);
57
58CREATE_FACTORY(QuestGUI);
59SHELL_COMMAND(gui, QuestGUI, guiInit);
60//SHELL_COMMAND(cancel, QuestGUI, guiDestruct);
61
62
63QuestGUI::QuestGUI(const TiXmlElement* root)
64{
65  this->registerObject(this, QuestGUI::_objectList);
66 
67  this->toList(OM_GROUP_00);
68 
69  this->questBox = NULL; 
70 
71  this->bKillGui = false;
72 
73  this->background = "maps/rand2.png";
74
75  this->myQuest = new Quest(root);
76  if(root)
77    this->loadParams( root);
78
79}
80
81
82/**
83 * deconstructor
84 */
85QuestGUI::~QuestGUI () 
86{
87  if( this->myQuest)
88    delete this->myQuest;
89}
90
91/**
92 * loads the xml tagsthis->questDescription
93 * @param root: root xml tag for this element
94 */
95void QuestGUI::loadParams(const TiXmlElement* root)
96{
97  WorldEntity::loadParams(root);
98}
99
100
101
102/**
103 * initializes the gui
104 */
105void QuestGUI::guiInit()
106{ 
107  if (questBox == NULL)
108  {
109    this->questBox= new OrxGui::GLGuiBox(OrxGui::Vertical);
110    questBox->setBorderTop(10);
111    questBox->setBorderRight(10);
112    questBox->setBorderBottom(20);
113    questBox->setBorderLeft(10);
114    this->questBox->setBackgroundTexture(background);
115    this->bKillGui = false;
116   
117    OrxGui::GLGuiBox* headerBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
118    {
119      OrxGui::GLGuiImage* questImage = new OrxGui::GLGuiImage();
120      questImage->setWidgetSize(100, 100);
121      questImage->loadImageFromFile(this->myQuest->getQuestPicture());
122      questImage->show();
123      headerBox->pack(questImage);
124     
125      OrxGui::GLGuiBox* outlineBox = new OrxGui::GLGuiBox(OrxGui::Vertical);
126      {
127        OrxGui::GLGuiMultiLineText* questDetails = new OrxGui::GLGuiMultiLineText();
128        questDetails->setText(this->myQuest->getQuestDifficulty());
129        questDetails->append(this->myQuest->getQuestPersons());
130        outlineBox->setBorderTop(0);
131        outlineBox->setBorderRight(0);
132        outlineBox->setBorderBottom(20);
133        outlineBox->setBorderLeft(0);
134        outlineBox->pack(questDetails);
135      }
136      headerBox->setBorderTop(0);
137      headerBox->setBorderRight(0);
138      headerBox->setBorderBottom(20);
139      headerBox->setBorderLeft(0);
140      headerBox->pack(outlineBox);
141    }
142   
143    OrxGui::GLGuiBox* labelBox = new OrxGui::GLGuiBox(OrxGui::Vertical);
144    { 
145      OrxGui::GLGuiMultiLineText* questTxt = new OrxGui::GLGuiMultiLineText();
146      questTxt->setText(this->myQuest->getQuestDescription());
147      labelBox->setBorderTop(0);
148      labelBox->setBorderRight(0);
149      labelBox->setBorderBottom(20);
150      labelBox->setBorderLeft(0);
151      labelBox->pack(questTxt);
152    }
153   
154   
155    OrxGui::GLGuiBox* rewardBox = new OrxGui::GLGuiBox(OrxGui::Vertical);
156    {
157      OrxGui::GLGuiImage* rewardImage = new OrxGui::GLGuiImage();
158      rewardImage->setWidgetSize(50, 50);
159      rewardImage->loadImageFromFile(this->myQuest->getRewardPicture());
160      rewardImage->show();
161      rewardBox->pack(rewardImage);
162   
163      OrxGui::GLGuiMultiLineText* rewardTxt = new OrxGui::GLGuiMultiLineText();
164      rewardTxt->setText(this->myQuest->getRewardDescription());
165      rewardBox->setBorderTop(0);
166      rewardBox->setBorderRight(0);
167      rewardBox->setBorderBottom(20);
168      rewardBox->setBorderLeft(0);
169      rewardBox->pack(rewardTxt);
170    }
171   
172    OrxGui::GLGuiBox* answerBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
173    {
174      OrxGui::GLGuiBox* acceptBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
175      {
176        OrxGui::GLGuiButton* acceptButton = new OrxGui::GLGuiPushButton("Accept");
177        acceptButton->released.connect(this, &QuestGUI::accept);
178        acceptBox->setBorderRight(70);
179        acceptBox->pack(acceptButton);
180      }
181     
182      OrxGui::GLGuiBox* refuseBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
183      {
184        OrxGui::GLGuiButton* refuseButton = new OrxGui::GLGuiPushButton("Refuse");
185        refuseButton->released.connect(this, &QuestGUI::refuse);
186        refuseBox->setBorderLeft(0);
187        refuseBox->pack(refuseButton);
188      }
189      answerBox->pack(acceptBox);
190      answerBox->pack(refuseBox);
191    }
192    this->questBox->pack(headerBox);
193    this->questBox->pack(labelBox);
194    this->questBox->pack(rewardBox);
195    this->questBox->pack(answerBox);
196    this->questBox->showAll();
197   
198    this->questBox->setAbsCoor2D(300, 100);
199    OrxGui::GLGuiHandler::getInstance()->activate();
200    OrxGui::GLGuiHandler::getInstance()->activateCursor();
201  }
202  else
203  {
204    this->bKillGui = true;
205  }
206 
207}
208
209   
210void QuestGUI::tick(float dt)
211{
212  if( this->bKillGui)
213    this->killgui();
214}
215   
216
217void QuestGUI::accept()
218{
219  this->myQuest->setQuestActive();
220  this->bKillGui = true;
221}
222
223void QuestGUI::refuse()
224{
225  this->bKillGui = true;
226}
227
228void QuestGUI::killgui()
229{
230  OrxGui::GLGuiHandler::getInstance()->deactivate();
231  OrxGui::GLGuiHandler::getInstance()->deactivateCursor();
232  delete this->questBox;
233  this->questBox = NULL;
234}
Note: See TracBrowser for help on using the repository browser.