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: Patrick Boenzli |
---|
13 | |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD |
---|
17 | |
---|
18 | |
---|
19 | #include "simple_game_menu.h" |
---|
20 | |
---|
21 | #include "event_handler.h" |
---|
22 | |
---|
23 | #include "state.h" |
---|
24 | #include "class_list.h" |
---|
25 | |
---|
26 | #include "util/loading/load_param.h" |
---|
27 | #include "fast_factory.h" |
---|
28 | #include "util/loading/factory.h" |
---|
29 | |
---|
30 | #include "world_entity.h" |
---|
31 | #include "elements/image_entity.h" |
---|
32 | #include "terrain_entity.h" |
---|
33 | #include "camera.h" |
---|
34 | |
---|
35 | #include "graphics_engine.h" |
---|
36 | #include "object_manager.h" |
---|
37 | #include "sound_engine.h" |
---|
38 | #include "sound_source.h" |
---|
39 | |
---|
40 | #include "cd_engine.h" |
---|
41 | |
---|
42 | #include "glgui.h" |
---|
43 | |
---|
44 | //! This creates a Factory to fabricate a SimpleGameMenu |
---|
45 | CREATE_FACTORY(SimpleGameMenu, CL_SIMPLE_GAME_MENU); |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | SimpleGameMenu::SimpleGameMenu(const TiXmlElement* root) |
---|
50 | : GameWorld() |
---|
51 | { |
---|
52 | this->setClassID(CL_SIMPLE_GAME_MENU, "SimpleGameMenu"); |
---|
53 | this->setName("SimpleGameMenu uninitialized"); |
---|
54 | |
---|
55 | this->dataTank = new SimpleGameMenuData(); |
---|
56 | |
---|
57 | this->cameraVector = Vector(50.0, 0.0, 0.0); |
---|
58 | this->menuLayers.push_back(MenuLayer()); |
---|
59 | this->menuLayers.push_back(MenuLayer()); |
---|
60 | |
---|
61 | this->layerIndex = 0; |
---|
62 | this->menuSelectedIndex = 0; |
---|
63 | this->selectorSource = NULL; |
---|
64 | |
---|
65 | |
---|
66 | /// GUI |
---|
67 | ///(this is as modular as it is possible). |
---|
68 | OrxGui::GLGuiPushButton* pb = new OrxGui::GLGuiPushButton("PUSH ME"); |
---|
69 | //pb->connectSignal(OrxGui::Signal_release, this, createExecutor<SimpleGameMenu>(&SimpleGameMenu::enterGui)); |
---|
70 | pb->connect(SIGNAL(pb, released), this, SLOT(SimpleGameMenu, enterGui)); |
---|
71 | pb->show(); |
---|
72 | pb->setAbsCoor2D(50, 50); |
---|
73 | |
---|
74 | OrxGui::GLGuiHandler::getInstance()->activateCursor(); |
---|
75 | OrxGui::GLGuiHandler::getInstance()->activate(); |
---|
76 | ///// |
---|
77 | |
---|
78 | if (root != NULL) |
---|
79 | this->loadParams(root); |
---|
80 | |
---|
81 | State::setMenuID(this->getNextStoryID()); |
---|
82 | } |
---|
83 | |
---|
84 | /// HACK only for testing. |
---|
85 | void SimpleGameMenu::enterGui() |
---|
86 | { |
---|
87 | |
---|
88 | OrxGui::GLGuiBox* box = new OrxGui::GLGuiBox(); |
---|
89 | { |
---|
90 | /// |
---|
91 | OrxGui::GLGuiButton* dnpb = new OrxGui::GLGuiCheckButton("Push the button"); |
---|
92 | |
---|
93 | box->pack(dnpb); |
---|
94 | |
---|
95 | OrxGui::GLGuiPushButton* rdnpb = new OrxGui::GLGuiPushButton("Quit ORXONOX!!"); |
---|
96 | rdnpb->connect(SIGNAL(rdnpb, released), this, SLOT(SimpleGameMenu, quitMenu)); |
---|
97 | |
---|
98 | box->pack(rdnpb); |
---|
99 | |
---|
100 | OrxGui::GLGuiInputLine* input = new OrxGui::GLGuiInputLine(); |
---|
101 | input->setText("input some text here"); |
---|
102 | input->connect(SIGNAL(input, textChanged), this, SLOT(SimpleGameMenu, TEST)); |
---|
103 | box->pack(input); |
---|
104 | |
---|
105 | OrxGui::GLGuiSlider* slider = new OrxGui::GLGuiSlider(); |
---|
106 | slider->connect(SIGNAL(slider, valueChanged), this, SLOT(SimpleGameMenu, TEST)); |
---|
107 | slider->connect(SIGNAL(slider, valueChanged), box, SLOT(OrxGui::GLGuiWidget, setBackgroundColor)); |
---|
108 | slider->setRange(0, 1); |
---|
109 | slider->setValue(slider->min()); |
---|
110 | box->pack(slider); |
---|
111 | } |
---|
112 | box->setAbsCoor2D(50, 200); |
---|
113 | |
---|
114 | box->showAll(); |
---|
115 | |
---|
116 | |
---|
117 | OrxGui::GLGuiBox* imageSelector = new OrxGui::GLGuiBox(); |
---|
118 | { |
---|
119 | image = new OrxGui::GLGuiImage(); |
---|
120 | image->setWidgetSize(300, 300); |
---|
121 | image->setAbsCoor2D(300, 300); |
---|
122 | imageSelector->pack(image); |
---|
123 | |
---|
124 | imageName = new OrxGui::GLGuiInputLine(); |
---|
125 | imageSelector->pack(imageName); |
---|
126 | |
---|
127 | OrxGui::GLGuiSlider* slider = new OrxGui::GLGuiSlider(); |
---|
128 | slider->setWidgetSize(200, 30); |
---|
129 | slider->setRange(0, 100); |
---|
130 | slider->setStep(1); |
---|
131 | slider->setValue(slider->min()); |
---|
132 | slider->connect(SIGNAL(slider, valueChanged), this, SLOT(SimpleGameMenu, setImage)); |
---|
133 | |
---|
134 | imageSelector->pack(slider); |
---|
135 | slider->setValue(0); |
---|
136 | } |
---|
137 | imageSelector->showAll(); |
---|
138 | imageSelector->setAbsCoor2D(400, 30); |
---|
139 | |
---|
140 | |
---|
141 | ///// |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | #include "class_list.h" |
---|
146 | void SimpleGameMenu::setImage(int i) |
---|
147 | { |
---|
148 | const std::list<BaseObject*>* textures = ClassList::getList(CL_TEXTURE); |
---|
149 | |
---|
150 | if(textures) |
---|
151 | { |
---|
152 | std::list<BaseObject*>::const_iterator test = textures->begin(); |
---|
153 | std::list<BaseObject*>::const_iterator lastOK = textures->begin(); |
---|
154 | while (true) |
---|
155 | { |
---|
156 | if (--i == 0 || test == textures->end()) |
---|
157 | break; |
---|
158 | if (dynamic_cast<Texture*>(*test)->getTexture() != 0) |
---|
159 | lastOK = test; |
---|
160 | test++; |
---|
161 | } |
---|
162 | this->image->loadImageFromTexture(*dynamic_cast<Texture*>(*lastOK)); |
---|
163 | this->imageName->setText((*lastOK)->getName()); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | #include "threading.h" |
---|
169 | void SimpleGameMenu::execURL() const |
---|
170 | { |
---|
171 | std::string URL = "http://www.orxonox.net"; |
---|
172 | SDL_CreateThread(startURL, (void*)&URL); |
---|
173 | } |
---|
174 | |
---|
175 | #ifdef __OSX__ |
---|
176 | #include <ApplicationServices/ApplicationServices.h> |
---|
177 | #elif defined __WIN32__ |
---|
178 | #include <shellapi.h> |
---|
179 | #endif |
---|
180 | |
---|
181 | int SimpleGameMenu::startURL(void* url) |
---|
182 | { |
---|
183 | std::string URL = *(std::string*)url; |
---|
184 | #ifdef __linux__ |
---|
185 | system ((std::string("firefox ") + URL).c_str()); |
---|
186 | #elif defined __OSX__ |
---|
187 | CFURLRef url_handle = CFURLCreateWithBytes (NULL, (UInt8 *)URL.c_str(), URL.size(), |
---|
188 | kCFStringEncodingASCII, NULL); |
---|
189 | LSOpenCFURLRef (url_handle, NULL); |
---|
190 | CFRelease (url_handle); |
---|
191 | #elif defined __WIN32__ |
---|
192 | ShellExecute(GetActiveWindow(), |
---|
193 | "open", URL.c_str(), NULL, NULL, SW_SHOWNORMAL); |
---|
194 | } |
---|
195 | #endif |
---|
196 | PRINTF(3)("loaded external webpage %s\n", URL.c_str()); |
---|
197 | } |
---|
198 | |
---|
199 | /** |
---|
200 | * @brief remove the SimpleGameMenu from memory |
---|
201 | * |
---|
202 | * delete everything explicitly, that isn't contained in the parenting tree! |
---|
203 | * things contained in the tree are deleted automaticaly |
---|
204 | */ |
---|
205 | SimpleGameMenu::~SimpleGameMenu () |
---|
206 | { |
---|
207 | PRINTF(3)("SimpleGameMenu::~SimpleGameMenu() - deleting current world\n"); |
---|
208 | |
---|
209 | if( this->dataTank) |
---|
210 | delete this->dataTank; |
---|
211 | delete OrxGui::GLGuiHandler::getInstance( ); |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | /** |
---|
216 | * @brief loads the parameters of a SimpleGameMenu from an XML-element |
---|
217 | * @param root the XML-element to load from |
---|
218 | */ |
---|
219 | void SimpleGameMenu::loadParams(const TiXmlElement* root) |
---|
220 | { |
---|
221 | /* skip the GameWorld, since it does not define any useful loadParams for this class */ |
---|
222 | //static_cast<GameWorld*>(this)->loadParams(root); |
---|
223 | GameWorld::loadParams(root); |
---|
224 | |
---|
225 | PRINTF(4)("Loaded SimpleGameMenu specific stuff\n"); |
---|
226 | } |
---|
227 | |
---|
228 | |
---|
229 | /** |
---|
230 | * @brief this is executed just before load |
---|
231 | * |
---|
232 | * since the load function sometimes needs data, that has been initialized |
---|
233 | * before the load and after the proceeding storyentity has finished |
---|
234 | */ |
---|
235 | ErrorMessage SimpleGameMenu::init() |
---|
236 | { |
---|
237 | /* call underlying init funciton */ |
---|
238 | GameWorld::init(); |
---|
239 | |
---|
240 | this->subscribeEvent(ES_MENU, SDLK_UP); |
---|
241 | this->subscribeEvent(ES_MENU, SDLK_DOWN); |
---|
242 | this->subscribeEvent(ES_MENU, SDLK_RETURN); |
---|
243 | this->subscribeEvent(ES_MENU, SDLK_SPACE); |
---|
244 | this->subscribeEvent(ES_MENU, SDLK_ESCAPE); |
---|
245 | |
---|
246 | this->dataTank->localCamera->setRelCoor(this->cameraVector); |
---|
247 | |
---|
248 | GraphicsEngine::getInstance()->displayFPS(false); |
---|
249 | |
---|
250 | this->layerIndex = 0; |
---|
251 | this->menuSelectedIndex = 0; |
---|
252 | } |
---|
253 | |
---|
254 | |
---|
255 | /** |
---|
256 | * @brief load the data |
---|
257 | */ |
---|
258 | ErrorMessage SimpleGameMenu::loadData() |
---|
259 | { |
---|
260 | GameWorld::loadData(); |
---|
261 | |
---|
262 | if (this->dataXML != NULL) |
---|
263 | { |
---|
264 | LoadParam(dataXML, "selector-sound", this, SimpleGameMenu, setSelectorSound); |
---|
265 | |
---|
266 | TiXmlElement* element = this->dataXML->FirstChildElement("Elements"); |
---|
267 | |
---|
268 | |
---|
269 | if( element == NULL) |
---|
270 | { |
---|
271 | PRINTF(1)("SimpleGameMenu is missing 'Elements'\n"); |
---|
272 | } |
---|
273 | else |
---|
274 | { |
---|
275 | element = element->FirstChildElement(); |
---|
276 | // load Players/Objects/Whatever |
---|
277 | PRINTF(4)("Loading Elements\n"); |
---|
278 | while( element != NULL) |
---|
279 | { |
---|
280 | BaseObject* created = Factory::fabricate(element); |
---|
281 | if( created != NULL ) |
---|
282 | { |
---|
283 | PRINTF(4)("Created a %s::%s\n", created->getClassName(), created->getName()); |
---|
284 | if (!created->isA(CL_ELEMENT_2D)) |
---|
285 | PRINTF(2)("Error the Created Entity is not an Element2D but an %s::%s\n", created->getClassName(), created->getName()); |
---|
286 | } |
---|
287 | element = element->NextSiblingElement(); |
---|
288 | } |
---|
289 | PRINTF(4)("Done loading Elements\n"); |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | /* get the menu list */ |
---|
294 | const std::list<BaseObject*>* imageEntityList = ClassList::getList(CL_IMAGE_ENTITY); |
---|
295 | std::list<BaseObject*>::const_iterator entity; |
---|
296 | for (entity = imageEntityList->begin(); entity != imageEntityList->end(); entity++) |
---|
297 | { |
---|
298 | |
---|
299 | if( !strcmp("Selector_Menu", (*entity)->getName())) |
---|
300 | { |
---|
301 | this->menuSelector = dynamic_cast<ImageEntity*>(*entity); |
---|
302 | this->menuSelector->setBindNode((const PNode*)NULL); |
---|
303 | } |
---|
304 | } |
---|
305 | |
---|
306 | imageEntityList = ClassList::getList(CL_TEXT_ELEMENT); |
---|
307 | for (entity = imageEntityList->begin(); entity != imageEntityList->end(); entity++) |
---|
308 | { |
---|
309 | if( !strcmp( "StartGame_Menu", (*entity)->getName())) |
---|
310 | { |
---|
311 | this->menuStartGame = dynamic_cast<TextElement*>(*entity); |
---|
312 | this->menuStartGame->setBindNode((const PNode*)NULL); |
---|
313 | this->menuStartGame->setRelCoor2D(State::getResX() / 2.0f, |
---|
314 | State::getResY() / 2.0f - 60.0f); |
---|
315 | this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity)); |
---|
316 | |
---|
317 | } |
---|
318 | else if( !strcmp( "Multiplayer_Menu", (*entity)->getName())) |
---|
319 | { |
---|
320 | this->menuStartMultiplayerGame = dynamic_cast<TextElement*>(*entity); |
---|
321 | this->menuStartMultiplayerGame->setBindNode((const PNode*)NULL); |
---|
322 | this->menuStartMultiplayerGame->setRelCoor2D(State::getResX() / 2.0f, |
---|
323 | State::getResY() / 2.0f + ((this->menuLayers[0].menuList.size() -1 ) * 60.0f)); |
---|
324 | this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity)); |
---|
325 | } |
---|
326 | else if( !strcmp( "Quit_Menu", (*entity)->getName())) |
---|
327 | { |
---|
328 | this->menuQuitGame = dynamic_cast<TextElement*>(*entity); |
---|
329 | this->menuQuitGame->setBindNode((const PNode*)NULL); |
---|
330 | this->menuQuitGame->setRelCoor2D(State::getResX() / 2.0f, |
---|
331 | State::getResY() / 2.0f + ((this->menuLayers[0].menuList.size() -1 )* 60.0f)); |
---|
332 | this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity)); |
---|
333 | } |
---|
334 | } |
---|
335 | this->menuSelected->getNullElement()->update2D(0.1f); |
---|
336 | this->menuSelectedIndex = 0; |
---|
337 | this->menuSelected = this->menuLayers[0].menuList[this->menuSelectedIndex]; |
---|
338 | this->sliderTo(this->menuSelected, 0.0f); |
---|
339 | |
---|
340 | |
---|
341 | // loading the storyentities submenu (singleplayer) |
---|
342 | const std::list<BaseObject*>* storyEntities = ClassList::getList(CL_STORY_ENTITY); |
---|
343 | std::list<BaseObject*>::const_iterator it; |
---|
344 | for( it = storyEntities->begin(); it != storyEntities->end(); it++) |
---|
345 | { |
---|
346 | StoryEntity* se = dynamic_cast<StoryEntity*>(*it); |
---|
347 | if( se->isContainedInMenu()) |
---|
348 | { |
---|
349 | this->menuLayers[1].storyList.push_back(se); |
---|
350 | |
---|
351 | // generating menu item |
---|
352 | TextElement* te = new TextElement(); |
---|
353 | te->setVisibility(false); |
---|
354 | te->setText(se->getName()); |
---|
355 | te->setRelCoor2D(State::getResX() / 2.0f - 200.0f, State::getResY() / 2.0f + ((this->menuLayers[1].menuList.size() - 2.0f) * 60.0f)); |
---|
356 | this->menuLayers[1].menuList.push_back(te); |
---|
357 | |
---|
358 | // generating screenshoot item |
---|
359 | ImageEntity* ie = new ImageEntity(); |
---|
360 | ie->setVisibility(false); |
---|
361 | ie->setBindNode((const PNode*)NULL); |
---|
362 | ie->setTexture(se->getMenuScreenshoot()); |
---|
363 | ie->setRelCoor2D(State::getResX() / 2.0f + 250.0f, State::getResY() / 2.0f); |
---|
364 | ie->setSize2D(140.0f, 105.0f); |
---|
365 | this->menuLayers[1].screenshootList.push_back(ie); |
---|
366 | } |
---|
367 | } |
---|
368 | } |
---|
369 | |
---|
370 | /** |
---|
371 | * @brief set the Sound to play when switching menu entry. |
---|
372 | * @param selectorSound the sound to load. |
---|
373 | */ |
---|
374 | void SimpleGameMenu::setSelectorSound(const std::string& selectorSound) |
---|
375 | { |
---|
376 | this->selectorSource = OrxSound::SoundEngine::getInstance()->createSource(selectorSound, NULL); |
---|
377 | } |
---|
378 | |
---|
379 | ErrorMessage SimpleGameMenu::unloadData() |
---|
380 | { |
---|
381 | this->unsubscribeEvents(ES_MENU); |
---|
382 | |
---|
383 | std::vector<MenuLayer>::iterator mit; |
---|
384 | for(mit = this->menuLayers.begin(); mit != this->menuLayers.end(); mit++) |
---|
385 | { |
---|
386 | while(!(*mit).menuList.empty()) |
---|
387 | { |
---|
388 | delete (*mit).menuList.back(); |
---|
389 | (*mit).menuList.pop_back(); |
---|
390 | } |
---|
391 | |
---|
392 | (*mit).menuList.clear(); |
---|
393 | (*mit).storyList.clear(); |
---|
394 | (*mit).screenshootList.clear(); |
---|
395 | } |
---|
396 | |
---|
397 | // delete the SoundSource. |
---|
398 | if (this->selectorSource != NULL) |
---|
399 | delete this->selectorSource; |
---|
400 | this->selectorSource = NULL; |
---|
401 | |
---|
402 | GameWorld::unloadData(); |
---|
403 | } |
---|
404 | |
---|
405 | |
---|
406 | /** |
---|
407 | * @brief start the menu |
---|
408 | */ |
---|
409 | bool SimpleGameMenu::start() |
---|
410 | { |
---|
411 | EventHandler::getInstance()->pushState(ES_MENU); |
---|
412 | |
---|
413 | /* now call the underlying*/ |
---|
414 | GameWorld::start(); |
---|
415 | } |
---|
416 | |
---|
417 | |
---|
418 | |
---|
419 | /** |
---|
420 | * stop the menu |
---|
421 | */ |
---|
422 | bool SimpleGameMenu::stop() |
---|
423 | { |
---|
424 | EventHandler::getInstance()->popState(); |
---|
425 | |
---|
426 | /* now call the underlying*/ |
---|
427 | GameWorld::stop(); |
---|
428 | } |
---|
429 | |
---|
430 | |
---|
431 | /** |
---|
432 | * override the standard tick for more functionality |
---|
433 | */ |
---|
434 | void SimpleGameMenu::tick() |
---|
435 | { |
---|
436 | GameWorld::tick(); |
---|
437 | |
---|
438 | // Make the GLGui tick. |
---|
439 | OrxGui::GLGuiHandler::getInstance()->tick(this->dtS); |
---|
440 | |
---|
441 | this->animateScene(this->dtS); |
---|
442 | } |
---|
443 | |
---|
444 | |
---|
445 | /** |
---|
446 | * @brief no collision detection in the menu |
---|
447 | */ |
---|
448 | void SimpleGameMenu::collide() |
---|
449 | { |
---|
450 | // this->dataTank->localCamera-> |
---|
451 | } |
---|
452 | |
---|
453 | |
---|
454 | /** |
---|
455 | * @brief animate the scene |
---|
456 | */ |
---|
457 | void SimpleGameMenu::animateScene(float dt) |
---|
458 | { |
---|
459 | Quaternion q(/*0.00005*/ dt * .1, Vector(0.0, 1.0, 0.0)); |
---|
460 | this->cameraVector = q.apply(this->cameraVector); |
---|
461 | this->dataTank->localCamera->setRelCoor(this->cameraVector); |
---|
462 | this->dataTank->localCamera->getTarget()->setRelCoorSoft(0,0,0); |
---|
463 | } |
---|
464 | |
---|
465 | void SimpleGameMenu::quitMenu() |
---|
466 | { |
---|
467 | this->setNextStoryID(WORLD_ID_GAMEEND); |
---|
468 | this->stop(); |
---|
469 | } |
---|
470 | |
---|
471 | |
---|
472 | /** |
---|
473 | * @brief event dispatcher funciton |
---|
474 | * @param event the incoming event |
---|
475 | */ |
---|
476 | void SimpleGameMenu::process(const Event &event) |
---|
477 | { |
---|
478 | /* ----------------- LAYER 1 ---------------*/ |
---|
479 | if( this->layerIndex == 0) |
---|
480 | { |
---|
481 | if( event.type == SDLK_RETURN && event.bPressed == true) |
---|
482 | { |
---|
483 | if( this->menuSelected == this->menuQuitGame) |
---|
484 | { |
---|
485 | this->setNextStoryID(WORLD_ID_GAMEEND); |
---|
486 | this->stop(); |
---|
487 | } |
---|
488 | if( this->menuSelected == this->menuStartGame) |
---|
489 | { |
---|
490 | // switch to first submenu |
---|
491 | if( this->menuLayers[1].menuList.size() == 0) |
---|
492 | { |
---|
493 | PRINTF(1)("Haven't got any StoryEntities to play!\n"); |
---|
494 | return; |
---|
495 | } |
---|
496 | |
---|
497 | this->switchMenuLayer(this->layerIndex, 1); |
---|
498 | } |
---|
499 | } |
---|
500 | if( event.type == SDLK_ESCAPE && event.bPressed == true) |
---|
501 | { |
---|
502 | this->setNextStoryID(WORLD_ID_GAMEEND); |
---|
503 | this->stop(); |
---|
504 | } |
---|
505 | } /* ----------------- LAYER 2 ---------------*/ |
---|
506 | else if( this->layerIndex == 1) |
---|
507 | { |
---|
508 | if( event.type == SDLK_RETURN && event.bPressed == true) |
---|
509 | { |
---|
510 | this->setNextStoryID( this->menuLayers[1].storyList[this->menuSelectedIndex]->getStoryID()); |
---|
511 | this->stop(); |
---|
512 | } |
---|
513 | if( event.type == SDLK_ESCAPE && event.bPressed == true) |
---|
514 | { |
---|
515 | this->switchMenuLayer(this->layerIndex, 0); |
---|
516 | } |
---|
517 | } |
---|
518 | |
---|
519 | |
---|
520 | |
---|
521 | // The menu selction cursor |
---|
522 | if( event.type == SDLK_DOWN && event.bPressed == true) |
---|
523 | { |
---|
524 | if(this->menuSelectedIndex < (this->menuLayers[this->layerIndex].menuList.size() - 1)) |
---|
525 | { |
---|
526 | this->menuSelected = this->menuLayers[this->layerIndex].menuList[++this->menuSelectedIndex]; |
---|
527 | this->sliderTo(this->menuSelected, 5.0f); |
---|
528 | if (this->selectorSource != NULL) |
---|
529 | this->selectorSource->play(); |
---|
530 | |
---|
531 | if( this->layerIndex == 1) |
---|
532 | { |
---|
533 | this->menuLayers[1].screenshootList[this->menuSelectedIndex]->setVisibility(true); |
---|
534 | this->menuLayers[1].screenshootList[this->menuSelectedIndex-1]->setVisibility(false); |
---|
535 | } |
---|
536 | } |
---|
537 | } |
---|
538 | else if( event.type == SDLK_UP && event.bPressed == true) |
---|
539 | { |
---|
540 | if(this->menuSelectedIndex > 0) |
---|
541 | { |
---|
542 | this->menuSelected = this->menuLayers[this->layerIndex].menuList[--this->menuSelectedIndex]; |
---|
543 | this->sliderTo(this->menuSelected, 5.0f); |
---|
544 | if (this->selectorSource != NULL) |
---|
545 | this->selectorSource->play(); |
---|
546 | |
---|
547 | if( this->layerIndex == 1) |
---|
548 | { |
---|
549 | this->menuLayers[1].screenshootList[this->menuSelectedIndex]->setVisibility(true); |
---|
550 | this->menuLayers[1].screenshootList[this->menuSelectedIndex+1]->setVisibility(false); |
---|
551 | } |
---|
552 | } |
---|
553 | } |
---|
554 | } |
---|
555 | |
---|
556 | |
---|
557 | /** |
---|
558 | * @brief switches to from one meny layer to an other |
---|
559 | * @param layer1 from layer |
---|
560 | * @param layer2 to layer |
---|
561 | */ |
---|
562 | void SimpleGameMenu::switchMenuLayer(int layer1, int layer2) |
---|
563 | { |
---|
564 | // wrong sizes |
---|
565 | if(layer1 >= this->menuLayers.size() || layer2 >= this->menuLayers.size()) |
---|
566 | return; |
---|
567 | |
---|
568 | |
---|
569 | PRINTF(0)("Removing layer %i\n", layer1); |
---|
570 | std::vector<TextElement*>::iterator te; |
---|
571 | // fade old menu |
---|
572 | for( te = this->menuLayers[layer1].menuList.begin(); te != this->menuLayers[layer1].menuList.end(); te++) |
---|
573 | { |
---|
574 | (*te)->setVisibility(false); |
---|
575 | } |
---|
576 | |
---|
577 | std::vector<ImageEntity*>::iterator it; |
---|
578 | |
---|
579 | //also fade the screenshots if in level choosement mode |
---|
580 | for( it = this->menuLayers[layer1].screenshootList.begin(); it != this->menuLayers[layer1].screenshootList.end(); it++) |
---|
581 | { |
---|
582 | (*it)->setVisibility(false); |
---|
583 | } |
---|
584 | |
---|
585 | |
---|
586 | PRINTF(0)("Showing layer %i\n", layer1); |
---|
587 | // beam here the new menu |
---|
588 | for( te = this->menuLayers[layer2].menuList.begin(); te != this->menuLayers[layer2].menuList.end(); te++ ) |
---|
589 | { |
---|
590 | (*te)->setVisibility(true); |
---|
591 | } |
---|
592 | |
---|
593 | |
---|
594 | this->layerIndex = layer2; |
---|
595 | this->menuSelected = this->menuLayers[layer2].menuList[0]; |
---|
596 | this->menuSelector->setAbsCoor2D(this->menuSelected->getAbsCoor2D() + Vector2D(0, this->menuSelected->getSizeY2D() *.5)); |
---|
597 | this->menuSelector->setSize2D(this->menuSelected->getSizeX2D()*.7, this->menuSelected->getSizeY2D()); |
---|
598 | this->menuSelectedIndex = 0; |
---|
599 | |
---|
600 | if( layer2 == 1) |
---|
601 | this->menuLayers[layer2].screenshootList[0]->setVisibility(true); |
---|
602 | } |
---|
603 | |
---|
604 | void SimpleGameMenu::sliderTo(const Element2D* element, float bias) |
---|
605 | { |
---|
606 | if (bias > 0.0) |
---|
607 | { |
---|
608 | this->menuSelector->setAbsCoorSoft2D(element->getAbsCoor2D() + Vector2D(0, element->getSizeY2D() *.5), bias); |
---|
609 | this->menuSelector->setSizeSoft2D(element->getSizeX2D()*.7, element->getSizeY2D(), bias); |
---|
610 | } |
---|
611 | else |
---|
612 | { |
---|
613 | this->menuSelector->setAbsCoor2D(element->getAbsCoor2D() + Vector2D(0, element->getSizeY2D() *.5)); |
---|
614 | this->menuSelector->setSize2D(element->getSizeX2D()*.7, element->getSizeY2D()); |
---|
615 | } |
---|
616 | } |
---|
617 | |
---|
618 | |
---|
619 | |
---|
620 | /********************************************************************************************** |
---|
621 | SimpleGameMenuData |
---|
622 | **********************************************************************************************/ |
---|
623 | |
---|
624 | |
---|
625 | /** |
---|
626 | * SimpleGameMenuData constructor |
---|
627 | */ |
---|
628 | SimpleGameMenuData::SimpleGameMenuData() |
---|
629 | {} |
---|
630 | |
---|
631 | /** |
---|
632 | * SimpleGameMenuData decontructor |
---|
633 | */ |
---|
634 | SimpleGameMenuData::~SimpleGameMenuData() |
---|
635 | {} |
---|
636 | |
---|
637 | |
---|
638 | /** |
---|
639 | * initialize the GameWorldDataData |
---|
640 | */ |
---|
641 | ErrorMessage SimpleGameMenuData::init() |
---|
642 | { |
---|
643 | /* call underlying function */ |
---|
644 | GameWorldData::init(); |
---|
645 | } |
---|
646 | |
---|
647 | |
---|
648 | /** |
---|
649 | * loads the GUI data |
---|
650 | * @param root reference to the xml root element |
---|
651 | */ |
---|
652 | ErrorMessage SimpleGameMenuData::loadGUI(const TiXmlElement* root) |
---|
653 | { |
---|
654 | /* call underlying function */ |
---|
655 | GameWorldData::loadGUI(root); |
---|
656 | } |
---|
657 | |
---|
658 | |
---|
659 | /** |
---|
660 | * unloads the GUI data |
---|
661 | */ |
---|
662 | ErrorMessage SimpleGameMenuData::unloadGUI() |
---|
663 | { |
---|
664 | /* call underlying function */ |
---|
665 | GameWorldData::unloadGUI(); |
---|
666 | } |
---|
667 | |
---|
668 | |
---|
669 | /** |
---|
670 | * overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff) |
---|
671 | * @param root reference to the xml root parameter |
---|
672 | */ |
---|
673 | ErrorMessage SimpleGameMenuData::loadWorldEntities(const TiXmlElement* root) |
---|
674 | { |
---|
675 | GameWorldData::loadWorldEntities(root); |
---|
676 | /* |
---|
677 | const TiXmlElement* element = root->FirstChildElement("WorldEntities"); |
---|
678 | |
---|
679 | if( element != NULL) |
---|
680 | { |
---|
681 | element = element->FirstChildElement(); |
---|
682 | PRINTF(4)("Loading WorldEntities\n"); |
---|
683 | while(element != NULL) |
---|
684 | { |
---|
685 | BaseObject* created = Factory::fabricate(element); |
---|
686 | if( created != NULL ) |
---|
687 | printf("Created a %s: %s\n", created->getClassName(), created->getName()); |
---|
688 | |
---|
689 | if( element->Value() == "SkyBox") |
---|
690 | this->sky = dynamic_cast<WorldEntity*>(created); |
---|
691 | if( element->Value() == "Terrain") |
---|
692 | this->terrain = dynamic_cast<Terrain*>(created); |
---|
693 | element = element->NextSiblingElement(); |
---|
694 | } |
---|
695 | |
---|
696 | PRINTF(4)("Done loading WorldEntities\n"); |
---|
697 | } |
---|
698 | |
---|
699 | // init the pnode tree |
---|
700 | PNode::getNullParent()->init(); |
---|
701 | */ |
---|
702 | } |
---|
703 | |
---|
704 | |
---|
705 | /** |
---|
706 | * unloads the world entities from the xml file |
---|
707 | */ |
---|
708 | ErrorMessage SimpleGameMenuData::unloadWorldEntities() |
---|
709 | { |
---|
710 | /* call underlying function */ |
---|
711 | GameWorldData::unloadWorldEntities(); |
---|
712 | } |
---|
713 | |
---|
714 | |
---|
715 | /** |
---|
716 | * loads the scene data |
---|
717 | * @param root reference to the xml root element |
---|
718 | */ |
---|
719 | ErrorMessage SimpleGameMenuData::loadScene(const TiXmlElement* root) |
---|
720 | { |
---|
721 | /* call underlying function */ |
---|
722 | GameWorldData::loadScene(root); |
---|
723 | } |
---|
724 | |
---|
725 | |
---|
726 | /** |
---|
727 | * unloads the scene data |
---|
728 | */ |
---|
729 | ErrorMessage SimpleGameMenuData::unloadScene() |
---|
730 | { |
---|
731 | /* call underlying function */ |
---|
732 | GameWorldData::unloadScene(); |
---|
733 | } |
---|
734 | |
---|
735 | |
---|
736 | |
---|