1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: Benjamin Knecht |
---|
14 | */ |
---|
15 | |
---|
16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
17 | |
---|
18 | #include "hud.h" |
---|
19 | |
---|
20 | #include "state.h" |
---|
21 | #include "debug.h" |
---|
22 | |
---|
23 | #include "world_entities/weapons/weapon_manager.h" |
---|
24 | #include "glgui.h" |
---|
25 | #include "glgui_widget.h" |
---|
26 | #include "glgui_box.h" |
---|
27 | #include "glgui_bar.h" |
---|
28 | #include "elements/glgui_energywidgetvertical.h" |
---|
29 | |
---|
30 | #include "glgui_inputline.h" |
---|
31 | #include "specials/glgui_notifier.h" |
---|
32 | #include "elements/glgui_radar.h" |
---|
33 | #include "world_entities/space_ships/space_ship.h" |
---|
34 | |
---|
35 | #include "tools/camera.h" |
---|
36 | #include "multi_type.h" |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | /// HACK |
---|
42 | #include "player.h" |
---|
43 | #include "playable.h" |
---|
44 | |
---|
45 | ObjectListDefinition(Hud); |
---|
46 | /** |
---|
47 | * standard constructor |
---|
48 | * @todo this constructor is not jet implemented - do it |
---|
49 | */ |
---|
50 | Hud::Hud () |
---|
51 | { |
---|
52 | this->registerObject(this, Hud::_objectList); |
---|
53 | |
---|
54 | //this->setSize2D( |
---|
55 | this->playmode = Full3D; |
---|
56 | this->weaponManager = NULL; |
---|
57 | this->weaponManagerSecondary = NULL; |
---|
58 | this->energyWidget = NULL; |
---|
59 | this->shieldWidget = NULL; |
---|
60 | this->healthWidget = NULL; |
---|
61 | this->leftRect = NULL; |
---|
62 | this->rightRect = NULL; |
---|
63 | this->resX = 1; |
---|
64 | this->resY = 1; |
---|
65 | this->leftHit = NULL; |
---|
66 | this->rightHit = NULL; |
---|
67 | this->ifinit = true; |
---|
68 | this->hidden = false; |
---|
69 | |
---|
70 | this->barSocket = NULL; |
---|
71 | this->_radar = NULL; |
---|
72 | this->inputLine = NULL; |
---|
73 | this->notifier = NULL; |
---|
74 | this->topRect = NULL; |
---|
75 | this->bottomRect = NULL; |
---|
76 | this->middleRect = NULL; |
---|
77 | |
---|
78 | this->init(); |
---|
79 | |
---|
80 | |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | /** |
---|
85 | * standard deconstructor |
---|
86 | */ |
---|
87 | Hud::~Hud () |
---|
88 | { |
---|
89 | if (this->inputLine) delete this->inputLine; |
---|
90 | if (this->notifier) delete this->notifier; |
---|
91 | if (this->leftHit) delete this->leftHit; |
---|
92 | if (this->rightHit) delete this->rightHit; |
---|
93 | |
---|
94 | if (this->_radar) delete this->_radar; |
---|
95 | if (this->barSocket) delete this->barSocket; |
---|
96 | if (this->rightRect) delete this->rightRect; |
---|
97 | if (this->leftRect) delete this->leftRect; |
---|
98 | if (this->topRect) delete this->topRect; |
---|
99 | if (this->bottomRect) delete this->bottomRect; |
---|
100 | if (this->middleRect) delete this->middleRect; |
---|
101 | |
---|
102 | |
---|
103 | //if (this->shipValuesBox != NULL) |
---|
104 | //delete this->shipValuesBox; |
---|
105 | |
---|
106 | // delete what has to be deleted here |
---|
107 | } |
---|
108 | |
---|
109 | void Hud::init() |
---|
110 | { |
---|
111 | this->overlayPercentage = 40; |
---|
112 | this->overlayActive = false; |
---|
113 | this->rightRect = new OrxGui::GLGuiImage(); |
---|
114 | this->leftRect = new OrxGui::GLGuiImage(); |
---|
115 | this->topRect = new OrxGui::GLGuiImage(); |
---|
116 | this->bottomRect = new OrxGui::GLGuiImage(); |
---|
117 | this->middleRect = new OrxGui::GLGuiImage(); |
---|
118 | |
---|
119 | this->inputLine = new OrxGui::GLGuiInputLine(); |
---|
120 | this->inputLine->setParent2D(this); |
---|
121 | this->notifier = new OrxGui::GLGuiNotifier(); |
---|
122 | this->notifier->setParent2D(this); |
---|
123 | notifier->setAbsCoor2D(100,100); |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | this->_radar = new OrxGui::GLGuiRadar(); |
---|
128 | this->radarCenterNode = NULL; |
---|
129 | |
---|
130 | this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE); |
---|
131 | this->subscribeEvent(ES_ALL, SDLK_TAB); |
---|
132 | |
---|
133 | if (this->playmode == FirstPerson) |
---|
134 | { |
---|
135 | /*this->topHit = new OrxGui::GLGuiImage(); |
---|
136 | this->topHit->loadImageFromFile("textures/gui/gui_hitbar.png"); |
---|
137 | this->topHit->setParent2D(this->middleRect); |
---|
138 | this->topHit->setAbsDir2D(-1.5708); |
---|
139 | |
---|
140 | this->bottomHit = new OrxGui::GLGuiImage(); |
---|
141 | this->bottomHit->loadImageFromFile("textures/gui/gui_hitbar.png"); |
---|
142 | this->bottomHit->setParent2D(this->middleRect); |
---|
143 | this->bottomHit->setAbsDir2D(1.5708);*/ |
---|
144 | |
---|
145 | this->barSocket = new OrxGui::GLGuiImage(); |
---|
146 | this->barSocket->loadImageFromFile("textures/gui/gui_barSocket.png"); |
---|
147 | this->barSocket->setParent2D(this->bottomRect); |
---|
148 | |
---|
149 | this->leftHit = new OrxGui::GLGuiImage(); |
---|
150 | this->leftHit->loadImageFromFile("textures/gui/gui_hitbarl.png"); |
---|
151 | this->leftHit->setParent2D(this->middleRect); |
---|
152 | |
---|
153 | |
---|
154 | this->rightHit = new OrxGui::GLGuiImage(); |
---|
155 | this->rightHit->loadImageFromFile("textures/gui/gui_hitbar.png"); |
---|
156 | this->rightHit->setParent2D(this->middleRect); |
---|
157 | |
---|
158 | this->healthText = new OrxGui::GLGuiText(); |
---|
159 | this->healthText->setParent2D(this->barSocket); |
---|
160 | |
---|
161 | this->shieldText = new OrxGui::GLGuiText(); |
---|
162 | this->shieldText->setParent2D(this->barSocket); |
---|
163 | |
---|
164 | |
---|
165 | this->leftRect->setParent2D(this); |
---|
166 | this->rightRect->setParent2D(this); |
---|
167 | } |
---|
168 | |
---|
169 | //this->shipValuesBox = NULL; |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | void Hud::loadParams(const TiXmlElement* root) |
---|
174 | { |
---|
175 | Element2D::loadParams(root); |
---|
176 | } |
---|
177 | |
---|
178 | void Hud::notifyUser(const std::string& message) |
---|
179 | { |
---|
180 | this->notifier->pushNotifyMessage(message); |
---|
181 | } |
---|
182 | |
---|
183 | void Hud::setBackGround() |
---|
184 | {} |
---|
185 | |
---|
186 | void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget) |
---|
187 | { |
---|
188 | //if (this->shipValuesBox == NULL) |
---|
189 | //this->createShipValuesBox(); |
---|
190 | |
---|
191 | // decopple old widget |
---|
192 | if (this->energyWidget != NULL) |
---|
193 | { |
---|
194 | this->energyWidget->hide(); |
---|
195 | } |
---|
196 | |
---|
197 | this->energyWidget = widget; |
---|
198 | if (this->energyWidget != NULL) |
---|
199 | { |
---|
200 | //this->energyWidget->shiftDir2D(270); |
---|
201 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedName("Electronics"); |
---|
202 | //this->shipValuesBox->pack(this->energyWidget); |
---|
203 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setStandardSettings(); |
---|
204 | this->energyWidget->setParent2D(this->leftRect); |
---|
205 | dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png"); |
---|
206 | if (!this->hidden) |
---|
207 | this->energyWidget->show(); |
---|
208 | else |
---|
209 | this->energyWidget->hide(); |
---|
210 | /* this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); |
---|
211 | this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ |
---|
212 | } |
---|
213 | |
---|
214 | this->updateResolution(); |
---|
215 | } |
---|
216 | |
---|
217 | void Hud::setShieldWidget(OrxGui::GLGuiWidget* widget) |
---|
218 | { |
---|
219 | if( this->playmode == FirstPerson ) |
---|
220 | { |
---|
221 | this->shieldWidget = new OrxGui::GLGuiBar(); |
---|
222 | dynamic_cast<OrxGui::GLGuiBar*> (this->shieldWidget)->setMaximum(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->maximum()); |
---|
223 | dynamic_cast<OrxGui::GLGuiBar*> (this->shieldWidget)->setValue(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->value()); |
---|
224 | this->shieldWidget->setBackgroundTexture(Texture()); |
---|
225 | this->shieldWidget->setBackgroundColor(Color(0,0,0,0)); |
---|
226 | this->shieldWidget->setForegroundTexture("textures/gui/gui_element_background_faded.png"); |
---|
227 | this->shieldWidget->setForegroundColor(Color(1,1,0,0.5)); |
---|
228 | dynamic_cast<OrxGui::GLGuiBar*>(this->shieldWidget)->setChangedValueColor(Color(1,0,0,0.2)); |
---|
229 | this->shieldWidget->setWidgetSize(150,40); |
---|
230 | this->shieldWidget->setRelDir2D(180); |
---|
231 | this->shieldWidget->setParent2D(this->barSocket); |
---|
232 | |
---|
233 | this->shieldText->setTextSize(50); |
---|
234 | this->shieldText->setChangedTextColor(Color::white); |
---|
235 | this->shieldText->setForegroundColor(Color(1,1,0,1)); |
---|
236 | this->shieldText->setBackgroundTexture(Texture()); |
---|
237 | this->shieldText->setBackgroundColor(Color(0,0,0,0)); |
---|
238 | MultiType val(dynamic_cast<OrxGui::GLGuiBar*>(this->shieldWidget)->value()); |
---|
239 | val.setType(MT_INT); |
---|
240 | this->shieldText->setText(val.getString()); |
---|
241 | } |
---|
242 | else |
---|
243 | { |
---|
244 | /* |
---|
245 | if (this->shipValuesBox == NULL) |
---|
246 | this->createShipValuesBox(); |
---|
247 | */ |
---|
248 | |
---|
249 | // decopple old widget |
---|
250 | if (this->shieldWidget != NULL) |
---|
251 | { |
---|
252 | this->shieldWidget->hide(); |
---|
253 | } |
---|
254 | |
---|
255 | this->shieldWidget = widget; |
---|
256 | if (this->shieldWidget != NULL) |
---|
257 | { |
---|
258 | //this->shieldWidget->shiftDir2D(270); |
---|
259 | //this->shipValuesBox->pack(this->shieldWidget); |
---|
260 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setStandardSettings(); |
---|
261 | this->shieldWidget->setParent2D(this->leftRect); |
---|
262 | dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setDisplayedImage("textures/gui/gui_shield_icon.png"); |
---|
263 | if (!this->hidden) |
---|
264 | this->shieldWidget->show(); |
---|
265 | else |
---|
266 | this->shieldWidget->hide(); |
---|
267 | /* this->shieldWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); |
---|
268 | this->shieldWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ |
---|
269 | } |
---|
270 | else |
---|
271 | printf("schild im hud nicht uebergeben!!!!!!!!!!!!!!!!!!!!!!!!!"); |
---|
272 | } |
---|
273 | |
---|
274 | this->updateResolution(); |
---|
275 | } |
---|
276 | |
---|
277 | void Hud::setHealthWidget(OrxGui::GLGuiWidget* widget) |
---|
278 | { |
---|
279 | if( this->playmode == FirstPerson ) |
---|
280 | { |
---|
281 | this->healthWidget = new OrxGui::GLGuiBar(); |
---|
282 | dynamic_cast<OrxGui::GLGuiBar*> (this->healthWidget)->setMaximum(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->maximum()); |
---|
283 | dynamic_cast<OrxGui::GLGuiBar*> (this->healthWidget)->setValue(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->value()); |
---|
284 | this->healthWidget->setBackgroundTexture(Texture()); |
---|
285 | this->healthWidget->setBackgroundColor(Color(0,0,0,0)); |
---|
286 | this->healthWidget->setForegroundTexture("textures/gui/gui_element_background_faded.png"); |
---|
287 | this->healthWidget->setForegroundColor(Color::red); |
---|
288 | dynamic_cast<OrxGui::GLGuiBar*>(this->healthWidget)->setChangedValueColor(Color(1,0,0,0.2)); |
---|
289 | this->healthWidget->setWidgetSize(150,20); |
---|
290 | this->healthWidget->setRelDir2D(180); |
---|
291 | this->healthWidget->setParent2D(this->barSocket); |
---|
292 | |
---|
293 | this->healthText->setTextSize(80); |
---|
294 | this->healthText->setChangedTextColor(Color::white); |
---|
295 | this->healthText->setForegroundColor(Color::red); |
---|
296 | this->healthText->setBackgroundTexture(Texture()); |
---|
297 | this->healthText->setBackgroundColor(Color(0,0,0,0)); |
---|
298 | MultiType val(dynamic_cast<OrxGui::GLGuiBar*>(this->healthWidget)->value()); |
---|
299 | val.setType(MT_INT); |
---|
300 | this->healthText->setText(val.getString()); |
---|
301 | } |
---|
302 | else |
---|
303 | { |
---|
304 | /* |
---|
305 | if (this->shipValuesBox == NULL) |
---|
306 | this->createShipValuesBox(); |
---|
307 | */ |
---|
308 | |
---|
309 | // decopple old widget |
---|
310 | if (this->healthWidget != NULL) |
---|
311 | { |
---|
312 | this->healthWidget->hide(); |
---|
313 | } |
---|
314 | |
---|
315 | this->healthWidget = widget; |
---|
316 | if (this->healthWidget != NULL) |
---|
317 | { |
---|
318 | //this->healthWidget->shiftDir2D(270); |
---|
319 | //this->shipValuesBox->pack(this->healthWidget); |
---|
320 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->healthWidget)->setStandardSettings(); |
---|
321 | this->healthWidget->setParent2D(this->leftRect); |
---|
322 | dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->healthWidget)->setDisplayedImage("textures/gui/gui_health_icon.png"); |
---|
323 | if(!this->hidden) |
---|
324 | this->healthWidget->show(); |
---|
325 | else |
---|
326 | this->healthWidget->hide(); |
---|
327 | /* this->healthWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); |
---|
328 | this->healthWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ |
---|
329 | } |
---|
330 | } |
---|
331 | |
---|
332 | this->updateResolution(); |
---|
333 | } |
---|
334 | |
---|
335 | |
---|
336 | void Hud::setImplantWidget(OrxGui::GLGuiWidget* widget) |
---|
337 | { |
---|
338 | //if (this->shipValuesBox == NULL) |
---|
339 | //this->createShipValuesBox(); |
---|
340 | |
---|
341 | // decopple old widget |
---|
342 | if (this->implantWidget != NULL) |
---|
343 | { |
---|
344 | this->implantWidget->hide(); |
---|
345 | } |
---|
346 | |
---|
347 | this->implantWidget = widget; |
---|
348 | if (this->implantWidget != NULL) |
---|
349 | { |
---|
350 | //this->energyWidget->shiftDir2D(270); |
---|
351 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedName("Electronics"); |
---|
352 | //this->shipValuesBox->pack(this->energyWidget); |
---|
353 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setStandardSettings(); |
---|
354 | this->implantWidget->setParent2D(this->leftRect); |
---|
355 | dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->implantWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png"); |
---|
356 | if (!this->hidden) |
---|
357 | this->implantWidget->show(); |
---|
358 | else |
---|
359 | this->implantWidget->hide(); |
---|
360 | /* this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); |
---|
361 | this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ |
---|
362 | } |
---|
363 | |
---|
364 | this->updateResolution(); |
---|
365 | } |
---|
366 | |
---|
367 | void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec) |
---|
368 | { |
---|
369 | //clearWeaponManager(); |
---|
370 | |
---|
371 | //Hide all widgets |
---|
372 | if (this->weaponManager != NULL) |
---|
373 | { |
---|
374 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) |
---|
375 | { |
---|
376 | Weapon* weapon = this->weaponManager->getWeapon(i); |
---|
377 | if (weapon != NULL) |
---|
378 | { |
---|
379 | weapon->getEnergyWidget()->hide(); |
---|
380 | //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
381 | } |
---|
382 | } |
---|
383 | } |
---|
384 | |
---|
385 | if (this->weaponManagerSecondary != NULL) |
---|
386 | { |
---|
387 | for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++) |
---|
388 | { |
---|
389 | Weapon* weapon = this->weaponManagerSecondary->getWeapon(i); |
---|
390 | if (weapon != NULL) |
---|
391 | { |
---|
392 | weapon->getEnergyWidget()->hide(); |
---|
393 | //this->weaponsWidgetsSec.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
394 | } |
---|
395 | } |
---|
396 | } |
---|
397 | |
---|
398 | this->weaponManager = weaponMan; |
---|
399 | this->weaponManagerSecondary = weaponManSec; |
---|
400 | |
---|
401 | this->updateWeaponManager(); |
---|
402 | // this->updateResolution(); |
---|
403 | } |
---|
404 | |
---|
405 | /* |
---|
406 | void Hud::clearWeaponManager() |
---|
407 | { |
---|
408 | //Hide all widgets |
---|
409 | if (this->weaponManager != NULL) |
---|
410 | { |
---|
411 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) |
---|
412 | { |
---|
413 | Weapon* weapon = this->weaponManager->getWeapon(i); |
---|
414 | if (weapon != NULL) |
---|
415 | { |
---|
416 | weapon->getEnergyWidget()->hide(); |
---|
417 | //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
418 | } |
---|
419 | } |
---|
420 | } |
---|
421 | |
---|
422 | if (this->weaponManagerSecondary != NULL) |
---|
423 | { |
---|
424 | for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++) |
---|
425 | { |
---|
426 | Weapon* weapon = this->weaponManagerSecondary->getWeapon(i); |
---|
427 | if (weapon != NULL) |
---|
428 | { |
---|
429 | weapon->getEnergyWidget()->hide(); |
---|
430 | //this->weaponsWidgetsSec.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
431 | } |
---|
432 | } |
---|
433 | } |
---|
434 | |
---|
435 | //this->weaponsWidgetsPrim.clear(); |
---|
436 | //this->weaponsWidgetsSec.clear(); |
---|
437 | } |
---|
438 | */ |
---|
439 | |
---|
440 | void Hud::setMode(Hud::Playmode playmode) |
---|
441 | { |
---|
442 | this->playmode = playmode; |
---|
443 | this->init(); |
---|
444 | } |
---|
445 | |
---|
446 | void Hud::updateWeaponManager() |
---|
447 | { |
---|
448 | // hide all the Widgets |
---|
449 | |
---|
450 | std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget; |
---|
451 | for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) |
---|
452 | { |
---|
453 | (*weaponWidget)->hide(); |
---|
454 | } |
---|
455 | this->weaponsWidgetsPrim.clear(); |
---|
456 | |
---|
457 | for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++) |
---|
458 | { |
---|
459 | (*weaponWidget)->hide(); |
---|
460 | } |
---|
461 | this->weaponsWidgetsSec.clear(); |
---|
462 | |
---|
463 | |
---|
464 | // add all that we need again. |
---|
465 | |
---|
466 | if (this->weaponManager != NULL) |
---|
467 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) |
---|
468 | { |
---|
469 | Weapon* weapon = this->weaponManager->getWeapon(i); |
---|
470 | if (weapon != NULL) |
---|
471 | { |
---|
472 | //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName()); |
---|
473 | if (this->playmode != FirstPerson) |
---|
474 | weapon->getEnergyWidget()->setParent2D(this->rightRect); |
---|
475 | else |
---|
476 | weapon->getEnergyWidget()->setParent2D(this->bottomRect); |
---|
477 | if (!this->hidden) |
---|
478 | weapon->getEnergyWidget()->show(); |
---|
479 | else |
---|
480 | weapon->getEnergyWidget()->hide(); |
---|
481 | weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); |
---|
482 | weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); |
---|
483 | weapon->getEnergyWidget()->setWidgetSize(120,30); |
---|
484 | //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); |
---|
485 | this->weaponsWidgetsPrim.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
486 | } |
---|
487 | } |
---|
488 | |
---|
489 | if (this->weaponManagerSecondary != NULL) |
---|
490 | for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++) |
---|
491 | { |
---|
492 | Weapon* weapon = this->weaponManagerSecondary->getWeapon(i); |
---|
493 | if (weapon != NULL) |
---|
494 | { |
---|
495 | //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName()); |
---|
496 | weapon->getEnergyWidget()->setParent2D(this->rightRect); |
---|
497 | if (!this->hidden) |
---|
498 | weapon->getEnergyWidget()->show(); |
---|
499 | else |
---|
500 | weapon->getEnergyWidget()->hide(); |
---|
501 | weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); |
---|
502 | weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); |
---|
503 | weapon->getEnergyWidget()->setWidgetSize(150,50); |
---|
504 | //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); |
---|
505 | this->weaponsWidgetsSec.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
506 | } |
---|
507 | } |
---|
508 | |
---|
509 | this->updateResolution(); |
---|
510 | |
---|
511 | } |
---|
512 | |
---|
513 | void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget) |
---|
514 | {} |
---|
515 | |
---|
516 | void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget) |
---|
517 | {} |
---|
518 | |
---|
519 | void Hud::getHit() |
---|
520 | { |
---|
521 | this->leftHit->show(); |
---|
522 | this->rightHit->show(); |
---|
523 | hitBarCount = 0.33; |
---|
524 | } |
---|
525 | |
---|
526 | void Hud::tick(float dt) |
---|
527 | { |
---|
528 | |
---|
529 | if (this->playmode == FirstPerson && this->leftHit != NULL) |
---|
530 | { |
---|
531 | if (this->ifinit) |
---|
532 | { |
---|
533 | this->leftHit->shiftDir2D(3.1416); |
---|
534 | this->ifinit = false; |
---|
535 | } |
---|
536 | if (this->leftHit->isVisible()) |
---|
537 | { |
---|
538 | hitBarCount -= dt; |
---|
539 | } |
---|
540 | if (hitBarCount <= 0) |
---|
541 | { |
---|
542 | hitBarCount = 0; |
---|
543 | this->leftHit->hide(); |
---|
544 | this->rightHit->hide(); |
---|
545 | } |
---|
546 | } |
---|
547 | //Crosshair* crosshair = dynamic_cast<Crosshair*>(this->weaponManager->getFixedTarget()); |
---|
548 | if ((State::getCamera())->getName() == "GameWorldCamera") |
---|
549 | { |
---|
550 | this->hidden = false; |
---|
551 | if(this->weaponManager) |
---|
552 | this->weaponManager->showCrosshair(); |
---|
553 | } |
---|
554 | else |
---|
555 | { |
---|
556 | this->hidden = true; |
---|
557 | if(this->weaponManager) |
---|
558 | this->weaponManager->hideCrosshair(); |
---|
559 | } |
---|
560 | this->updateResolution(); |
---|
561 | } |
---|
562 | |
---|
563 | void Hud::updateResolution() |
---|
564 | { |
---|
565 | this->resX = State::getResX(); |
---|
566 | this->resY = State::getResY(); |
---|
567 | |
---|
568 | this->setSize2D(this->resX, this->resY); |
---|
569 | if( this->playmode != FirstPerson ) |
---|
570 | { |
---|
571 | this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY); |
---|
572 | this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY); |
---|
573 | } |
---|
574 | |
---|
575 | int overlayWidth = 0; |
---|
576 | if (overlayPercentage >= 20) |
---|
577 | overlayWidth = this->resX * (overlayPercentage)/(200); |
---|
578 | else |
---|
579 | overlayWidth = this->resX / 10; // fixed warning! |
---|
580 | //if (overlayWidth < 100) |
---|
581 | //overlayWidth = 100; |
---|
582 | |
---|
583 | this->rightRect->hide(); |
---|
584 | this->leftRect->hide(); |
---|
585 | |
---|
586 | if( this->playmode != FirstPerson ) |
---|
587 | { |
---|
588 | |
---|
589 | this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY)); |
---|
590 | this->leftRect->setAbsCoor2D(0,0); |
---|
591 | this->leftRect->setBackgroundTexture(Texture()); |
---|
592 | this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2)); |
---|
593 | this->leftRect->setForegroundTexture(Texture()); |
---|
594 | this->leftRect->setForegroundColor(Color(0,0,0,0)); |
---|
595 | |
---|
596 | this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY)); |
---|
597 | this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0); |
---|
598 | this->rightRect->setBackgroundTexture(Texture()); |
---|
599 | this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2)); |
---|
600 | this->rightRect->setForegroundTexture(Texture()); |
---|
601 | this->rightRect->setForegroundColor(Color(0,0,0,0)); |
---|
602 | } |
---|
603 | else |
---|
604 | { |
---|
605 | this->bottomRect->setParent2D(this); |
---|
606 | this->bottomRect->setWidgetSize(float(this->resX), float(overlayWidth)); |
---|
607 | this->bottomRect->setAbsCoor2D(0, this->resY - overlayWidth); |
---|
608 | //this->bottomRect->show(); |
---|
609 | |
---|
610 | this->topRect->setParent2D(this); |
---|
611 | this->topRect->setWidgetSize(float(this->resX), float(overlayWidth)); |
---|
612 | this->topRect->setAbsCoor2D(0, 0); |
---|
613 | //this->topRect->show(); |
---|
614 | |
---|
615 | this->middleRect->setParent2D(this); |
---|
616 | this->middleRect->setWidgetSize(float(this->resY)/2, float(this->resY)/2); |
---|
617 | this->middleRect->setAbsCoor2D(float(this->resX)/4, float(this->resY)/4/*float(this->resX/2), float(this->resY/2)*/); |
---|
618 | //this->middleRect->show(); |
---|
619 | |
---|
620 | /*this->bottomHit->setRelCoor2D(0, this->resY/4); |
---|
621 | this->bottomHit->setWidgetSize(this->resX/8, this->resX/3); |
---|
622 | this->bottomHit->show(); |
---|
623 | this->topHit->setRelCoor2D(0, -this->resY/4); |
---|
624 | this->topHit->setWidgetSize(this->resX/8, this->resX/3); |
---|
625 | this->topHit->show();*/ |
---|
626 | this->leftHit->setRelCoor2D(0, 0); |
---|
627 | this->leftHit->setWidgetSize(this->resX/9, this->resX/3); |
---|
628 | //this->leftHit->hide(); |
---|
629 | this->rightHit->setRelCoor2D(this->resX/3, 0); |
---|
630 | this->rightHit->setWidgetSize(this->resX/9, this->resX/3); |
---|
631 | //this->rightHit->hide(); |
---|
632 | |
---|
633 | this->barSocket->setWidgetSize(overlayWidth, overlayWidth); |
---|
634 | this->barSocket->setRelCoor2D(this->resX - overlayWidth, 0); |
---|
635 | if (!this->hidden) |
---|
636 | this->barSocket->show(); |
---|
637 | else |
---|
638 | this->barSocket->hide(); |
---|
639 | |
---|
640 | //this->middleRect->show(); |
---|
641 | |
---|
642 | |
---|
643 | } |
---|
644 | |
---|
645 | if (this->overlayActive && !this->hidden) |
---|
646 | { |
---|
647 | this->rightRect->show(); |
---|
648 | this->leftRect->show(); |
---|
649 | } |
---|
650 | |
---|
651 | |
---|
652 | if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager()) |
---|
653 | { |
---|
654 | PRINTF(4)("UPDATING RADAR\n"); |
---|
655 | if( this->playmode != FirstPerson ) |
---|
656 | this->_radar->setParent2D(this->leftRect); |
---|
657 | else |
---|
658 | this->_radar->setParent2D(this->topRect); |
---|
659 | if (radarCenterNode == NULL) |
---|
660 | this->_radar->setCenterNode(State::getPlayer()->getPlayable()); |
---|
661 | else |
---|
662 | this->_radar->setCenterNode(this->radarCenterNode); |
---|
663 | |
---|
664 | //this->_radar->addEntityList(&State::getObjectManager()->getEntityList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0)); |
---|
665 | this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_00), Color(1, 0, 0)); |
---|
666 | this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_01), Color(0, 0, 1)); |
---|
667 | this->_radar->setAbsCoor2D(0, 0.01 * this->resY); |
---|
668 | this->_radar->setWidgetSize(overlayWidth, overlayWidth); |
---|
669 | this->_radar->setRange(300); |
---|
670 | if (!this->hidden) |
---|
671 | this->_radar->show(); |
---|
672 | else |
---|
673 | this->_radar->hide(); |
---|
674 | |
---|
675 | int statWidgetsNumber = 0; |
---|
676 | float expectedHealthSizeX = 0; |
---|
677 | float expectedHealthSizeY = 0; |
---|
678 | float newSizeY = 0; float newSizeX = 0; |
---|
679 | float moduloWidth = 0; |
---|
680 | |
---|
681 | if( this->playmode != FirstPerson ) |
---|
682 | { |
---|
683 | if (this->healthWidget != NULL) |
---|
684 | { |
---|
685 | expectedHealthSizeX = 150; |
---|
686 | expectedHealthSizeY = 50; |
---|
687 | statWidgetsNumber++; |
---|
688 | } |
---|
689 | |
---|
690 | if (this->shieldWidget != NULL) |
---|
691 | statWidgetsNumber++; |
---|
692 | |
---|
693 | if (this->energyWidget != NULL) |
---|
694 | statWidgetsNumber++; |
---|
695 | |
---|
696 | if ((expectedHealthSizeY * statWidgetsNumber) > overlayWidth) |
---|
697 | { |
---|
698 | newSizeY = overlayWidth / float(statWidgetsNumber); |
---|
699 | newSizeX = expectedHealthSizeX; |
---|
700 | PRINTF(0)("Statwidgets resized\n"); |
---|
701 | } |
---|
702 | else |
---|
703 | { |
---|
704 | newSizeY = expectedHealthSizeY; |
---|
705 | newSizeX = expectedHealthSizeX; |
---|
706 | moduloWidth = int(overlayWidth) % int(expectedHealthSizeY * statWidgetsNumber); |
---|
707 | } |
---|
708 | |
---|
709 | float posY = overlayWidth + newSizeX; |
---|
710 | |
---|
711 | if (this->healthWidget != NULL) |
---|
712 | { |
---|
713 | this->healthWidget->setSize2D(newSizeX, newSizeY); |
---|
714 | this->healthWidget->setRelCoor2D((statWidgetsNumber - 1) * newSizeY + 3 * moduloWidth / (statWidgetsNumber + 1),posY); |
---|
715 | } |
---|
716 | if (this->shieldWidget != NULL) |
---|
717 | { |
---|
718 | this->shieldWidget->setSize2D(newSizeX, newSizeY); |
---|
719 | this->shieldWidget->setRelCoor2D((statWidgetsNumber - 2) * newSizeY + 2 *moduloWidth / (statWidgetsNumber + 1),posY); |
---|
720 | } |
---|
721 | if (this->energyWidget != NULL) |
---|
722 | { |
---|
723 | this->energyWidget->setSize2D(newSizeX, newSizeY); |
---|
724 | this->energyWidget->setRelCoor2D(moduloWidth / (statWidgetsNumber + 1),posY); |
---|
725 | } |
---|
726 | } |
---|
727 | else |
---|
728 | { |
---|
729 | this->barSocket->setParent2D(this->bottomRect); |
---|
730 | this->barSocket->setWidgetSize( float(overlayWidth), float(overlayWidth)); |
---|
731 | this->barSocket->setRelCoor2D(this->resX - float(overlayWidth),0); |
---|
732 | if (!this->hidden) |
---|
733 | this->barSocket->show(); |
---|
734 | else |
---|
735 | this->barSocket->hide(); |
---|
736 | if (this->shieldWidget) |
---|
737 | { |
---|
738 | this->shieldWidget->setRelCoor2D(40,overlayWidth/2+10); |
---|
739 | if (!this->hidden) |
---|
740 | this->shieldWidget->show(); |
---|
741 | else |
---|
742 | this->shieldWidget->hide(); |
---|
743 | this->shieldText->setRelCoor2D(overlayWidth/2-30,overlayWidth/2-60); |
---|
744 | if (!this->hidden) |
---|
745 | this->shieldText->show(); |
---|
746 | else |
---|
747 | this->shieldText->hide(); |
---|
748 | } |
---|
749 | this->healthWidget->setRelCoor2D(40,overlayWidth/2); |
---|
750 | if (!this->hidden) |
---|
751 | this->healthWidget->show(); |
---|
752 | else |
---|
753 | this->healthWidget->hide(); |
---|
754 | this->healthText->setRelCoor2D(overlayWidth/2-50,overlayWidth/2-20); |
---|
755 | if (!this->hidden) |
---|
756 | this->healthText->show(); |
---|
757 | else |
---|
758 | this->healthText->hide(); |
---|
759 | |
---|
760 | } |
---|
761 | |
---|
762 | |
---|
763 | /* |
---|
764 | if (this->healthWidget != NULL) |
---|
765 | this->healthWidget->setRelCoor2D(100,0.2*this->resY + this->healthWidget->getSizeX2D()); |
---|
766 | if (this->shieldWidget != NULL) |
---|
767 | this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->healthWidget->getSizeX2D()); |
---|
768 | if (this->energyWidget != NULL) |
---|
769 | this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->healthWidget->getSizeX2D()); |
---|
770 | */ |
---|
771 | //this->shieldWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D(),0); |
---|
772 | //this->energyWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D() + this->shieldWidget->getSizeX2D(),0); |
---|
773 | } |
---|
774 | |
---|
775 | /* |
---|
776 | if (this->shipValuesBox != NULL) |
---|
777 | { |
---|
778 | this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY); |
---|
779 | this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY); |
---|
780 | } |
---|
781 | else |
---|
782 | createShipValuesBox(); |
---|
783 | */ |
---|
784 | if (this->playmode != FirstPerson ) |
---|
785 | { |
---|
786 | std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget; |
---|
787 | Vector2D pos = Vector2D(overlayWidth, 0.4*this->resY); |
---|
788 | float largestWidgetSizeX = 0; |
---|
789 | //PRINTF(0)("Cur Pos: %f,%f\n",pos.x,pos.y); |
---|
790 | // out of reasons i can't get behind, this version is segfaulting when calling getSizeX2D or getSizeY2D. the other |
---|
791 | // element2D- related function works tough.. :s |
---|
792 | |
---|
793 | for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) |
---|
794 | { |
---|
795 | float ySize = (*weaponWidget)->getSizeY2D(); |
---|
796 | float xSize = (*weaponWidget)->getSizeX2D(); |
---|
797 | if (xSize > largestWidgetSizeX) |
---|
798 | largestWidgetSizeX = xSize; |
---|
799 | if (pos.x < ySize) |
---|
800 | { |
---|
801 | pos.x = overlayWidth; |
---|
802 | pos.y += largestWidgetSizeX; |
---|
803 | } |
---|
804 | pos.x -= ySize; |
---|
805 | (*weaponWidget)->setAbsCoor2D(pos.x + this->rightRect->getAbsCoor2D().x, pos.y); |
---|
806 | //(*weaponWidget)->setAbsCoor2D(0,100); |
---|
807 | if (!this->hidden) |
---|
808 | (*weaponWidget)->show(); |
---|
809 | else |
---|
810 | (*weaponWidget)->hide(); |
---|
811 | //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); |
---|
812 | } |
---|
813 | |
---|
814 | weaponWidget = this->weaponsWidgetsSec.begin(); |
---|
815 | float expectedWidgetSizeY = 0; |
---|
816 | if (weaponWidget != this->weaponsWidgetsSec.end()) |
---|
817 | { |
---|
818 | expectedWidgetSizeY = (*weaponWidget)->getSizeY2D(); |
---|
819 | } |
---|
820 | pos.y = resY - expectedWidgetSizeY * 0.6; |
---|
821 | pos.x = overlayWidth + this->rightRect->getAbsCoor2D().x; |
---|
822 | |
---|
823 | for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++) |
---|
824 | { |
---|
825 | float ySize = (*weaponWidget)->getSizeY2D(); |
---|
826 | float xSize = (*weaponWidget)->getSizeX2D(); |
---|
827 | if (xSize > largestWidgetSizeX) |
---|
828 | largestWidgetSizeX = xSize; |
---|
829 | if (pos.x < ySize) |
---|
830 | { |
---|
831 | pos.x = overlayWidth; |
---|
832 | pos.y -= largestWidgetSizeX + expectedWidgetSizeY * 0.6; |
---|
833 | } |
---|
834 | pos.x -= ySize; |
---|
835 | //PRINTF(0)("secweaponwidget y-size: %f/n", (*weaponWidget)->getSizeY2D()); |
---|
836 | (*weaponWidget)->setAbsCoor2D(pos.x, pos.y);//+this->rightRect->getAbsCoor2D().x, pos.y); |
---|
837 | if (!this->hidden) |
---|
838 | (*weaponWidget)->show(); |
---|
839 | else |
---|
840 | (*weaponWidget)->hide(); |
---|
841 | //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); |
---|
842 | } |
---|
843 | } |
---|
844 | else |
---|
845 | { |
---|
846 | std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget; |
---|
847 | Vector2D pos = Vector2D(overlayWidth, 0.4*this->resY); |
---|
848 | float largestWidgetSizeX = 0; |
---|
849 | |
---|
850 | for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) |
---|
851 | { |
---|
852 | (*weaponWidget)->setParent2D(this->barSocket); |
---|
853 | (*weaponWidget)->setRelCoor2D(overlayWidth/2, 0); |
---|
854 | //(*weaponWidget)->setAbsCoor2D(0,100); |
---|
855 | if (!this->hidden) |
---|
856 | (*weaponWidget)->show(); |
---|
857 | else |
---|
858 | (*weaponWidget)->hide(); |
---|
859 | //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); |
---|
860 | } |
---|
861 | } |
---|
862 | |
---|
863 | } |
---|
864 | |
---|
865 | void Hud::draw() const |
---|
866 | { |
---|
867 | // GLGuiWidget::draw(); |
---|
868 | } |
---|
869 | |
---|
870 | |
---|
871 | void Hud::process(const Event &event) |
---|
872 | { |
---|
873 | if (event.type == EV_VIDEO_RESIZE) |
---|
874 | this->updateResolution(); |
---|
875 | else if (event.type == SDLK_TAB) |
---|
876 | { |
---|
877 | /// TODO SHOW THE INPUT-LINE |
---|
878 | // this->inputLine->select(); |
---|
879 | } |
---|
880 | } |
---|
881 | |
---|
882 | /* |
---|
883 | void Hud::createShipValuesBox() |
---|
884 | { |
---|
885 | this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Vertical); |
---|
886 | //this->shipValuesBox->setWidgetSize(1000,500); |
---|
887 | //this->shipValuesBox->setBackgroundTexture("textures/gui_container_background.png"); |
---|
888 | this->shipValuesBox->setBackgroundTexture(Texture()); |
---|
889 | this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5)); |
---|
890 | this->shipValuesBox->setVisibility(true); |
---|
891 | } |
---|
892 | */ |
---|
893 | |
---|
894 | |
---|