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 | #include "event_handler.h" |
---|
49 | |
---|
50 | #include "quest.h" |
---|
51 | |
---|
52 | #include "shell_command.h" |
---|
53 | |
---|
54 | ObjectListDefinition(QuestGUI); |
---|
55 | |
---|
56 | CREATE_FACTORY(QuestGUI); |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | #include "script_class.h" |
---|
61 | CREATE_SCRIPTABLE_CLASS(QuestGUI, |
---|
62 | addMethod("startGUI", Executor0<QuestGUI, lua_State*>(&QuestGUI::startGUI)) |
---|
63 | ->addMethod("stopGUI", Executor0<QuestGUI, lua_State*>(&QuestGUI::stopGUI)) |
---|
64 | ->addMethod("isActive", Executor0ret<QuestGUI, lua_State*,bool>(&QuestGUI::isActive)) |
---|
65 | ); |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | QuestGUI::QuestGUI(const TiXmlElement* root) |
---|
70 | { |
---|
71 | if (root != NULL) |
---|
72 | { |
---|
73 | this->registerObject(this, QuestGUI::_objectList); |
---|
74 | |
---|
75 | this->toList(OM_GROUP_00); |
---|
76 | |
---|
77 | this->questBox = NULL; |
---|
78 | |
---|
79 | this->bKillGui = false; |
---|
80 | |
---|
81 | this->bActive = false; |
---|
82 | |
---|
83 | this->myQuest = new Quest(root); |
---|
84 | |
---|
85 | if(root) |
---|
86 | this->loadParams( root); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | /** |
---|
92 | * deconstructor |
---|
93 | */ |
---|
94 | QuestGUI::~QuestGUI () |
---|
95 | { |
---|
96 | if( this->myQuest) |
---|
97 | delete this->myQuest; |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * loads the xml tagsthis->questDescription |
---|
102 | * @param root: root xml tag for this element |
---|
103 | */ |
---|
104 | void QuestGUI::loadParams(const TiXmlElement* root) |
---|
105 | { |
---|
106 | WorldEntity::loadParams(root); |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | /** |
---|
112 | * initializes the gui |
---|
113 | */ |
---|
114 | void QuestGUI::startGUI() |
---|
115 | { |
---|
116 | this->bKillGui = false; |
---|
117 | |
---|
118 | |
---|
119 | if (questBox == NULL) |
---|
120 | { |
---|
121 | this->questBox= new OrxGui::GLGuiBox(OrxGui::Vertical); |
---|
122 | questBox->setBorderTop(10); |
---|
123 | questBox->setBorderRight(10); |
---|
124 | questBox->setBorderLeft(10); |
---|
125 | questBox->setBorderBottom(10); |
---|
126 | this->questBox->setBackgroundTexture("textures/gui/gui_quest_border.png"); |
---|
127 | |
---|
128 | OrxGui::GLGuiBox* headerBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
129 | { |
---|
130 | headerBox->setBackgroundTexture("textures/gui/gui_quest_border_low.png"); |
---|
131 | OrxGui::GLGuiImage* questImage = new OrxGui::GLGuiImage(); |
---|
132 | questImage->setWidgetSize(100, 100); |
---|
133 | questImage->loadImageFromFile(this->myQuest->getQuestPicture()); |
---|
134 | questImage->show(); |
---|
135 | headerBox->pack(questImage); |
---|
136 | |
---|
137 | OrxGui::GLGuiBox* outlineBox = new OrxGui::GLGuiBox(OrxGui::Vertical); |
---|
138 | { |
---|
139 | OrxGui::GLGuiMultiLineText* questDetails = new OrxGui::GLGuiMultiLineText(); |
---|
140 | questDetails->setText(this->myQuest->getQuestDifficulty()); |
---|
141 | questDetails->append(this->myQuest->getQuestPersons()); |
---|
142 | outlineBox->setBorderTop(0); |
---|
143 | outlineBox->setBorderRight(0); |
---|
144 | outlineBox->setBorderLeft(0); |
---|
145 | outlineBox->setBorderBottom(10); |
---|
146 | outlineBox->pack(questDetails); |
---|
147 | } |
---|
148 | headerBox->setBorderTop(0); |
---|
149 | headerBox->setBorderRight(0); |
---|
150 | headerBox->setBorderLeft(0); |
---|
151 | headerBox->setBorderBottom(10); |
---|
152 | headerBox->pack(outlineBox); |
---|
153 | } |
---|
154 | |
---|
155 | OrxGui::GLGuiBox* labelBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
156 | { |
---|
157 | labelBox->setBackgroundTexture("textures/gui/gui_quest_border_low.png"); |
---|
158 | OrxGui::GLGuiMultiLineText* questTxt = new OrxGui::GLGuiMultiLineText(); |
---|
159 | questTxt->setText(this->myQuest->getQuestDescription()); |
---|
160 | labelBox->pack(questTxt); |
---|
161 | |
---|
162 | OrxGui::GLGuiImage* placeImage = new OrxGui::GLGuiImage(); |
---|
163 | placeImage->setWidgetSize(85, 10); |
---|
164 | placeImage->loadImageFromFile("textures/gui/gui_quest_black.png"); |
---|
165 | placeImage->show(); |
---|
166 | labelBox->pack(placeImage); |
---|
167 | |
---|
168 | |
---|
169 | labelBox->setBorderTop(0); |
---|
170 | labelBox->setBorderRight(0); |
---|
171 | labelBox->setBorderLeft(55); |
---|
172 | labelBox->setBorderBottom(10); |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | OrxGui::GLGuiBox* rewardBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
177 | { |
---|
178 | rewardBox->setBackgroundTexture("textures/gui/gui_quest_border_low.png"); |
---|
179 | OrxGui::GLGuiImage* rewardImage = new OrxGui::GLGuiImage(); |
---|
180 | rewardImage->setWidgetSize(100, 100); |
---|
181 | rewardImage->loadImageFromFile(this->myQuest->getRewardPicture()); |
---|
182 | rewardImage->show(); |
---|
183 | rewardBox->pack(rewardImage); |
---|
184 | |
---|
185 | OrxGui::GLGuiMultiLineText* rewardTxt = new OrxGui::GLGuiMultiLineText(); |
---|
186 | rewardTxt->setText(this->myQuest->getRewardDescription()); |
---|
187 | rewardBox->setBorderTop(0); |
---|
188 | rewardBox->setBorderRight(0); |
---|
189 | rewardBox->setBorderLeft(0); |
---|
190 | rewardBox->setBorderBottom(10); |
---|
191 | rewardBox->pack(rewardTxt); |
---|
192 | } |
---|
193 | |
---|
194 | OrxGui::GLGuiBox* answerBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
195 | { |
---|
196 | OrxGui::GLGuiImage* placeImage = new OrxGui::GLGuiImage(); |
---|
197 | placeImage->setWidgetSize(20, 10); |
---|
198 | placeImage->loadImageFromFile("textures/gui/gui_quest_black.png"); |
---|
199 | placeImage->show(); |
---|
200 | answerBox->pack(placeImage); |
---|
201 | |
---|
202 | OrxGui::GLGuiBox* acceptBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
203 | { |
---|
204 | //acceptBox->setBackgroundTexture("maps/accept.png"); |
---|
205 | acceptBox->setBackgroundTexture("textures/gui/gui_quest_accept.gif", OrxGui::Normal); |
---|
206 | //acceptBox->setBackgroundTexture("maps/gui_quest_acceptrout.png", OrxGui::Selected); |
---|
207 | OrxGui::GLGuiButton* acceptButton = new OrxGui::GLGuiPushButton(" "); |
---|
208 | acceptButton->released.connect(this, &QuestGUI::accept); |
---|
209 | acceptBox->setBorderTop(7); |
---|
210 | acceptBox->setBorderRight(7); |
---|
211 | acceptBox->setBorderLeft(7); |
---|
212 | acceptBox->setBorderBottom(7); |
---|
213 | acceptBox->pack(acceptButton); |
---|
214 | } |
---|
215 | answerBox->pack(acceptBox); |
---|
216 | |
---|
217 | OrxGui::GLGuiImage* placeImage2 = new OrxGui::GLGuiImage(); |
---|
218 | placeImage2->setWidgetSize(300, 10); |
---|
219 | placeImage2->loadImageFromFile("textures/gui/gui_quest_black.png"); |
---|
220 | placeImage2->show(); |
---|
221 | answerBox->pack(placeImage2); |
---|
222 | |
---|
223 | OrxGui::GLGuiBox* refuseBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
224 | { |
---|
225 | refuseBox->setBackgroundTexture("textures/gui/gui_quest_refuserout.gif"); |
---|
226 | OrxGui::GLGuiButton* refuseButton = new OrxGui::GLGuiPushButton(" "); |
---|
227 | refuseButton->released.connect(this, &QuestGUI::refuse); |
---|
228 | refuseBox->setBorderTop(7); |
---|
229 | refuseBox->setBorderRight(7); |
---|
230 | refuseBox->setBorderLeft(7); |
---|
231 | refuseBox->setBorderBottom(7); |
---|
232 | refuseBox->pack(refuseButton); |
---|
233 | } |
---|
234 | answerBox->setBorderTop(15); |
---|
235 | answerBox->setBorderRight(0); |
---|
236 | answerBox->setBorderLeft(0); |
---|
237 | answerBox->setBorderBottom(20); |
---|
238 | answerBox->pack(refuseBox); |
---|
239 | } |
---|
240 | this->questBox->pack(headerBox); |
---|
241 | this->questBox->pack(labelBox); |
---|
242 | this->questBox->pack(rewardBox); |
---|
243 | this->questBox->pack(answerBox); |
---|
244 | this->questBox->showAll(); |
---|
245 | |
---|
246 | this->questBox->setAbsCoor2D(300, 100); |
---|
247 | |
---|
248 | OrxGui::GLGuiHandler::getInstance()->activate(); |
---|
249 | OrxGui::GLGuiHandler::getInstance()->activateCursor(); |
---|
250 | EventHandler::getInstance()->pushState( ES_MENU); |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | void QuestGUI::stopGUI() |
---|
255 | { |
---|
256 | this->bKillGui = true; |
---|
257 | } |
---|
258 | |
---|
259 | |
---|
260 | void QuestGUI::tick(float dt) |
---|
261 | { |
---|
262 | if( this->bKillGui) |
---|
263 | this->killgui(); |
---|
264 | } |
---|
265 | |
---|
266 | |
---|
267 | void QuestGUI::accept() |
---|
268 | { |
---|
269 | this->myQuest->setQuestActive(); |
---|
270 | this->bKillGui = true; |
---|
271 | bActive=true; |
---|
272 | } |
---|
273 | |
---|
274 | void QuestGUI::refuse() |
---|
275 | { |
---|
276 | this->bKillGui = true; |
---|
277 | bActive=false; |
---|
278 | } |
---|
279 | |
---|
280 | void QuestGUI::killgui() |
---|
281 | { |
---|
282 | OrxGui::GLGuiHandler::getInstance()->deactivate(); |
---|
283 | OrxGui::GLGuiHandler::getInstance()->deactivateCursor(); |
---|
284 | EventHandler::getInstance()->popState(); |
---|
285 | delete this->questBox; |
---|
286 | this->questBox = NULL; |
---|
287 | this->bKillGui = false; |
---|
288 | //this->bActive = false; |
---|
289 | } |
---|