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