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