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