| 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.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 | OrxGui::GLGuiPushButton* pb = new OrxGui::GLGuiPushButton("PUSH ME"); |
|---|
| 66 | pb->show(); |
|---|
| 67 | pb->setAbsCoor2D(50, 50); |
|---|
| 68 | |
|---|
| 69 | OrxGui::GLGuiCursor* cursor = new OrxGui::GLGuiCursor(); |
|---|
| 70 | cursor->show(); |
|---|
| 71 | |
|---|
| 72 | if (root != NULL) |
|---|
| 73 | this->loadParams(root); |
|---|
| 74 | |
|---|
| 75 | State::setMenuID(this->getNextStoryID()); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | * @brief remove the SimpleGameMenu from memory |
|---|
| 81 | * |
|---|
| 82 | * delete everything explicitly, that isn't contained in the parenting tree! |
|---|
| 83 | * things contained in the tree are deleted automaticaly |
|---|
| 84 | */ |
|---|
| 85 | SimpleGameMenu::~SimpleGameMenu () |
|---|
| 86 | { |
|---|
| 87 | PRINTF(3)("SimpleGameMenu::~SimpleGameMenu() - deleting current world\n"); |
|---|
| 88 | |
|---|
| 89 | if( this->dataTank) |
|---|
| 90 | delete this->dataTank; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * @brief loads the parameters of a SimpleGameMenu from an XML-element |
|---|
| 96 | * @param root the XML-element to load from |
|---|
| 97 | */ |
|---|
| 98 | void SimpleGameMenu::loadParams(const TiXmlElement* root) |
|---|
| 99 | { |
|---|
| 100 | /* skip the GameWorld, since it does not define any useful loadParams for this class */ |
|---|
| 101 | //static_cast<GameWorld*>(this)->loadParams(root); |
|---|
| 102 | GameWorld::loadParams(root); |
|---|
| 103 | |
|---|
| 104 | PRINTF(4)("Loaded SimpleGameMenu specific stuff\n"); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | /** |
|---|
| 109 | * @brief this is executed just before load |
|---|
| 110 | * |
|---|
| 111 | * since the load function sometimes needs data, that has been initialized |
|---|
| 112 | * before the load and after the proceeding storyentity has finished |
|---|
| 113 | */ |
|---|
| 114 | ErrorMessage SimpleGameMenu::init() |
|---|
| 115 | { |
|---|
| 116 | /* call underlying init funciton */ |
|---|
| 117 | GameWorld::init(); |
|---|
| 118 | |
|---|
| 119 | this->subscribeEvent(ES_MENU, SDLK_UP); |
|---|
| 120 | this->subscribeEvent(ES_MENU, SDLK_DOWN); |
|---|
| 121 | this->subscribeEvent(ES_MENU, SDLK_RETURN); |
|---|
| 122 | this->subscribeEvent(ES_MENU, SDLK_SPACE); |
|---|
| 123 | this->subscribeEvent(ES_MENU, SDLK_ESCAPE); |
|---|
| 124 | |
|---|
| 125 | this->dataTank->localCamera->setRelCoor(this->cameraVector); |
|---|
| 126 | |
|---|
| 127 | GraphicsEngine::getInstance()->displayFPS(false); |
|---|
| 128 | |
|---|
| 129 | this->layerIndex = 0; |
|---|
| 130 | this->menuSelectedIndex = 0; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | /** |
|---|
| 135 | * @brief load the data |
|---|
| 136 | */ |
|---|
| 137 | ErrorMessage SimpleGameMenu::loadData() |
|---|
| 138 | { |
|---|
| 139 | GameWorld::loadData(); |
|---|
| 140 | |
|---|
| 141 | if (this->dataXML != NULL) |
|---|
| 142 | { |
|---|
| 143 | LoadParam(dataXML, "selector-sound", this, SimpleGameMenu, setSelectorSound); |
|---|
| 144 | |
|---|
| 145 | TiXmlElement* element = this->dataXML->FirstChildElement("Elements"); |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | if( element == NULL) |
|---|
| 149 | { |
|---|
| 150 | PRINTF(1)("SimpleGameMenu is missing 'Elements'\n"); |
|---|
| 151 | } |
|---|
| 152 | else |
|---|
| 153 | { |
|---|
| 154 | element = element->FirstChildElement(); |
|---|
| 155 | // load Players/Objects/Whatever |
|---|
| 156 | PRINTF(4)("Loading Elements\n"); |
|---|
| 157 | while( element != NULL) |
|---|
| 158 | { |
|---|
| 159 | BaseObject* created = Factory::fabricate(element); |
|---|
| 160 | if( created != NULL ) |
|---|
| 161 | { |
|---|
| 162 | PRINTF(4)("Created a %s::%s\n", created->getClassName(), created->getName()); |
|---|
| 163 | if (!created->isA(CL_ELEMENT_2D)) |
|---|
| 164 | PRINTF(2)("Error the Created Entity is not an Element2D but an %s::%s\n", created->getClassName(), created->getName()); |
|---|
| 165 | } |
|---|
| 166 | element = element->NextSiblingElement(); |
|---|
| 167 | } |
|---|
| 168 | PRINTF(4)("Done loading Elements\n"); |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | /* get the menu list */ |
|---|
| 173 | const std::list<BaseObject*>* imageEntityList = ClassList::getList(CL_IMAGE_ENTITY); |
|---|
| 174 | std::list<BaseObject*>::const_iterator entity; |
|---|
| 175 | for (entity = imageEntityList->begin(); entity != imageEntityList->end(); entity++) |
|---|
| 176 | { |
|---|
| 177 | |
|---|
| 178 | if( !strcmp("Selector_Menu", (*entity)->getName())) |
|---|
| 179 | { |
|---|
| 180 | this->menuSelector = dynamic_cast<ImageEntity*>(*entity); |
|---|
| 181 | this->menuSelector->setBindNode((const PNode*)NULL); |
|---|
| 182 | } |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | imageEntityList = ClassList::getList(CL_TEXT_ELEMENT); |
|---|
| 186 | for (entity = imageEntityList->begin(); entity != imageEntityList->end(); entity++) |
|---|
| 187 | { |
|---|
| 188 | if( !strcmp( "StartGame_Menu", (*entity)->getName())) |
|---|
| 189 | { |
|---|
| 190 | this->menuStartGame = dynamic_cast<TextElement*>(*entity); |
|---|
| 191 | this->menuStartGame->setBindNode((const PNode*)NULL); |
|---|
| 192 | this->menuStartGame->setRelCoor2D(State::getResX() / 2.0f, |
|---|
| 193 | State::getResY() / 2.0f - 60.0f); |
|---|
| 194 | this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity)); |
|---|
| 195 | |
|---|
| 196 | } |
|---|
| 197 | else if( !strcmp( "Multiplayer_Menu", (*entity)->getName())) |
|---|
| 198 | { |
|---|
| 199 | this->menuStartMultiplayerGame = dynamic_cast<TextElement*>(*entity); |
|---|
| 200 | this->menuStartMultiplayerGame->setBindNode((const PNode*)NULL); |
|---|
| 201 | this->menuStartMultiplayerGame->setRelCoor2D(State::getResX() / 2.0f, |
|---|
| 202 | State::getResY() / 2.0f + ((this->menuLayers[0].menuList.size() -1 ) * 60.0f)); |
|---|
| 203 | this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity)); |
|---|
| 204 | } |
|---|
| 205 | else if( !strcmp( "Quit_Menu", (*entity)->getName())) |
|---|
| 206 | { |
|---|
| 207 | this->menuQuitGame = dynamic_cast<TextElement*>(*entity); |
|---|
| 208 | this->menuQuitGame->setBindNode((const PNode*)NULL); |
|---|
| 209 | this->menuQuitGame->setRelCoor2D(State::getResX() / 2.0f, |
|---|
| 210 | State::getResY() / 2.0f + ((this->menuLayers[0].menuList.size() -1 )* 60.0f)); |
|---|
| 211 | this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity)); |
|---|
| 212 | } |
|---|
| 213 | } |
|---|
| 214 | this->menuSelected->getNullElement()->update2D(0.1f); |
|---|
| 215 | this->menuSelectedIndex = 0; |
|---|
| 216 | this->menuSelected = this->menuLayers[0].menuList[this->menuSelectedIndex]; |
|---|
| 217 | this->sliderTo(this->menuSelected, 0.0f); |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | // loading the storyentities submenu (singleplayer) |
|---|
| 221 | const std::list<BaseObject*>* storyEntities = ClassList::getList(CL_STORY_ENTITY); |
|---|
| 222 | std::list<BaseObject*>::const_iterator it; |
|---|
| 223 | for( it = storyEntities->begin(); it != storyEntities->end(); it++) |
|---|
| 224 | { |
|---|
| 225 | StoryEntity* se = dynamic_cast<StoryEntity*>(*it); |
|---|
| 226 | if( se->isContainedInMenu()) |
|---|
| 227 | { |
|---|
| 228 | this->menuLayers[1].storyList.push_back(se); |
|---|
| 229 | |
|---|
| 230 | // generating menu item |
|---|
| 231 | TextElement* te = new TextElement(); |
|---|
| 232 | te->setVisibility(false); |
|---|
| 233 | te->setText(se->getName()); |
|---|
| 234 | te->setRelCoor2D(State::getResX() / 2.0f - 200.0f, State::getResY() / 2.0f + ((this->menuLayers[1].menuList.size() - 2.0f) * 60.0f)); |
|---|
| 235 | this->menuLayers[1].menuList.push_back(te); |
|---|
| 236 | |
|---|
| 237 | // generating screenshoot item |
|---|
| 238 | ImageEntity* ie = new ImageEntity(); |
|---|
| 239 | ie->setVisibility(false); |
|---|
| 240 | ie->setBindNode((const PNode*)NULL); |
|---|
| 241 | ie->setTexture(se->getMenuScreenshoot()); |
|---|
| 242 | ie->setRelCoor2D(State::getResX() / 2.0f + 250.0f, State::getResY() / 2.0f); |
|---|
| 243 | ie->setSize2D(140.0f, 105.0f); |
|---|
| 244 | this->menuLayers[1].screenshootList.push_back(ie); |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | /** |
|---|
| 250 | * @brief set the Sound to play when switching menu entry. |
|---|
| 251 | * @param selectorSound the sound to load. |
|---|
| 252 | */ |
|---|
| 253 | void SimpleGameMenu::setSelectorSound(const std::string& selectorSound) |
|---|
| 254 | { |
|---|
| 255 | this->selectorSource = OrxSound::SoundEngine::getInstance()->createSource(selectorSound, NULL); |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | ErrorMessage SimpleGameMenu::unloadData() |
|---|
| 259 | { |
|---|
| 260 | this->unsubscribeEvents(ES_MENU); |
|---|
| 261 | |
|---|
| 262 | std::vector<MenuLayer>::iterator mit; |
|---|
| 263 | for(mit = this->menuLayers.begin(); mit != this->menuLayers.end(); mit++) |
|---|
| 264 | { |
|---|
| 265 | while(!(*mit).menuList.empty()) |
|---|
| 266 | { |
|---|
| 267 | delete (*mit).menuList.back(); |
|---|
| 268 | (*mit).menuList.pop_back(); |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | (*mit).menuList.clear(); |
|---|
| 272 | (*mit).storyList.clear(); |
|---|
| 273 | (*mit).screenshootList.clear(); |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | // delete the SoundSource. |
|---|
| 277 | if (this->selectorSource != NULL) |
|---|
| 278 | delete this->selectorSource; |
|---|
| 279 | this->selectorSource = NULL; |
|---|
| 280 | |
|---|
| 281 | GameWorld::unloadData(); |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | /** |
|---|
| 286 | * @brief start the menu |
|---|
| 287 | */ |
|---|
| 288 | bool SimpleGameMenu::start() |
|---|
| 289 | { |
|---|
| 290 | EventHandler::getInstance()->pushState(ES_MENU); |
|---|
| 291 | |
|---|
| 292 | /* now call the underlying*/ |
|---|
| 293 | GameWorld::start(); |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | /** |
|---|
| 299 | * stop the menu |
|---|
| 300 | */ |
|---|
| 301 | bool SimpleGameMenu::stop() |
|---|
| 302 | { |
|---|
| 303 | EventHandler::getInstance()->popState(); |
|---|
| 304 | |
|---|
| 305 | /* now call the underlying*/ |
|---|
| 306 | GameWorld::stop(); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | /** |
|---|
| 311 | * override the standard tick for more functionality |
|---|
| 312 | */ |
|---|
| 313 | void SimpleGameMenu::tick() |
|---|
| 314 | { |
|---|
| 315 | GameWorld::tick(); |
|---|
| 316 | |
|---|
| 317 | this->animateScene(this->dtS); |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | /** |
|---|
| 322 | * @brief no collision detection in the menu |
|---|
| 323 | */ |
|---|
| 324 | void SimpleGameMenu::collide() |
|---|
| 325 | { |
|---|
| 326 | // this->dataTank->localCamera-> |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | /** |
|---|
| 331 | * @brief animate the scene |
|---|
| 332 | */ |
|---|
| 333 | void SimpleGameMenu::animateScene(float dt) |
|---|
| 334 | { |
|---|
| 335 | Quaternion q(/*0.00005*/ dt * .1, Vector(0.0, 1.0, 0.0)); |
|---|
| 336 | this->cameraVector = q.apply(this->cameraVector); |
|---|
| 337 | this->dataTank->localCamera->setRelCoor(this->cameraVector); |
|---|
| 338 | this->dataTank->localCamera->getTarget()->setRelCoorSoft(0,0,0); |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | /** |
|---|
| 343 | * @brief event dispatcher funciton |
|---|
| 344 | * @param event the incoming event |
|---|
| 345 | */ |
|---|
| 346 | void SimpleGameMenu::process(const Event &event) |
|---|
| 347 | { |
|---|
| 348 | /* ----------------- LAYER 1 ---------------*/ |
|---|
| 349 | if( this->layerIndex == 0) |
|---|
| 350 | { |
|---|
| 351 | if( event.type == SDLK_RETURN && event.bPressed == true) |
|---|
| 352 | { |
|---|
| 353 | if( this->menuSelected == this->menuQuitGame) |
|---|
| 354 | { |
|---|
| 355 | this->setNextStoryID(WORLD_ID_GAMEEND); |
|---|
| 356 | this->stop(); |
|---|
| 357 | } |
|---|
| 358 | if( this->menuSelected == this->menuStartGame) |
|---|
| 359 | { |
|---|
| 360 | // switch to first submenu |
|---|
| 361 | if( this->menuLayers[1].menuList.size() == 0) |
|---|
| 362 | { |
|---|
| 363 | PRINTF(1)("Haven't got any StoryEntities to play!\n"); |
|---|
| 364 | return; |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | this->switchMenuLayer(this->layerIndex, 1); |
|---|
| 368 | } |
|---|
| 369 | } |
|---|
| 370 | if( event.type == SDLK_ESCAPE && event.bPressed == true) |
|---|
| 371 | { |
|---|
| 372 | this->setNextStoryID(WORLD_ID_GAMEEND); |
|---|
| 373 | this->stop(); |
|---|
| 374 | } |
|---|
| 375 | } /* ----------------- LAYER 2 ---------------*/ |
|---|
| 376 | else if( this->layerIndex == 1) |
|---|
| 377 | { |
|---|
| 378 | if( event.type == SDLK_RETURN && event.bPressed == true) |
|---|
| 379 | { |
|---|
| 380 | this->setNextStoryID( this->menuLayers[1].storyList[this->menuSelectedIndex]->getStoryID()); |
|---|
| 381 | this->stop(); |
|---|
| 382 | } |
|---|
| 383 | if( event.type == SDLK_ESCAPE && event.bPressed == true) |
|---|
| 384 | { |
|---|
| 385 | this->switchMenuLayer(this->layerIndex, 0); |
|---|
| 386 | } |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | // The menu selction cursor |
|---|
| 392 | if( event.type == SDLK_DOWN && event.bPressed == true) |
|---|
| 393 | { |
|---|
| 394 | if(this->menuSelectedIndex < (this->menuLayers[this->layerIndex].menuList.size() - 1)) |
|---|
| 395 | { |
|---|
| 396 | this->menuSelected = this->menuLayers[this->layerIndex].menuList[++this->menuSelectedIndex]; |
|---|
| 397 | this->sliderTo(this->menuSelected, 5.0f); |
|---|
| 398 | if (this->selectorSource != NULL) |
|---|
| 399 | this->selectorSource->play(); |
|---|
| 400 | |
|---|
| 401 | if( this->layerIndex == 1) |
|---|
| 402 | { |
|---|
| 403 | this->menuLayers[1].screenshootList[this->menuSelectedIndex]->setVisibility(true); |
|---|
| 404 | this->menuLayers[1].screenshootList[this->menuSelectedIndex-1]->setVisibility(false); |
|---|
| 405 | } |
|---|
| 406 | } |
|---|
| 407 | } |
|---|
| 408 | else if( event.type == SDLK_UP && event.bPressed == true) |
|---|
| 409 | { |
|---|
| 410 | if(this->menuSelectedIndex > 0) |
|---|
| 411 | { |
|---|
| 412 | this->menuSelected = this->menuLayers[this->layerIndex].menuList[--this->menuSelectedIndex]; |
|---|
| 413 | this->sliderTo(this->menuSelected, 5.0f); |
|---|
| 414 | if (this->selectorSource != NULL) |
|---|
| 415 | this->selectorSource->play(); |
|---|
| 416 | |
|---|
| 417 | if( this->layerIndex == 1) |
|---|
| 418 | { |
|---|
| 419 | this->menuLayers[1].screenshootList[this->menuSelectedIndex]->setVisibility(true); |
|---|
| 420 | this->menuLayers[1].screenshootList[this->menuSelectedIndex+1]->setVisibility(false); |
|---|
| 421 | } |
|---|
| 422 | } |
|---|
| 423 | } |
|---|
| 424 | } |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | /** |
|---|
| 428 | * @brief switches to from one meny layer to an other |
|---|
| 429 | * @param layer1 from layer |
|---|
| 430 | * @param layer2 to layer |
|---|
| 431 | */ |
|---|
| 432 | void SimpleGameMenu::switchMenuLayer(int layer1, int layer2) |
|---|
| 433 | { |
|---|
| 434 | // wrong sizes |
|---|
| 435 | if(layer1 >= this->menuLayers.size() || layer2 >= this->menuLayers.size()) |
|---|
| 436 | return; |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | PRINTF(0)("Removing layer %i\n", layer1); |
|---|
| 440 | std::vector<TextElement*>::iterator te; |
|---|
| 441 | // fade old menu |
|---|
| 442 | for( te = this->menuLayers[layer1].menuList.begin(); te != this->menuLayers[layer1].menuList.end(); te++) |
|---|
| 443 | { |
|---|
| 444 | (*te)->setVisibility(false); |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | std::vector<ImageEntity*>::iterator it; |
|---|
| 448 | |
|---|
| 449 | //also fade the screenshots if in level choosement mode |
|---|
| 450 | for( it = this->menuLayers[layer1].screenshootList.begin(); it != this->menuLayers[layer1].screenshootList.end(); it++) |
|---|
| 451 | { |
|---|
| 452 | (*it)->setVisibility(false); |
|---|
| 453 | } |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | PRINTF(0)("Showing layer %i\n", layer1); |
|---|
| 457 | // beam here the new menu |
|---|
| 458 | for( te = this->menuLayers[layer2].menuList.begin(); te != this->menuLayers[layer2].menuList.end(); te++ ) |
|---|
| 459 | { |
|---|
| 460 | (*te)->setVisibility(true); |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | this->layerIndex = layer2; |
|---|
| 465 | this->menuSelected = this->menuLayers[layer2].menuList[0]; |
|---|
| 466 | this->menuSelector->setAbsCoor2D(this->menuSelected->getAbsCoor2D() + Vector2D(0, this->menuSelected->getSizeY2D() *.5)); |
|---|
| 467 | this->menuSelector->setSize2D(this->menuSelected->getSizeX2D()*.7, this->menuSelected->getSizeY2D()); |
|---|
| 468 | this->menuSelectedIndex = 0; |
|---|
| 469 | |
|---|
| 470 | if( layer2 == 1) |
|---|
| 471 | this->menuLayers[layer2].screenshootList[0]->setVisibility(true); |
|---|
| 472 | } |
|---|
| 473 | |
|---|
| 474 | void SimpleGameMenu::sliderTo(const Element2D* element, float bias) |
|---|
| 475 | { |
|---|
| 476 | if (bias > 0.0) |
|---|
| 477 | { |
|---|
| 478 | this->menuSelector->setAbsCoorSoft2D(element->getAbsCoor2D() + Vector2D(0, element->getSizeY2D() *.5), bias); |
|---|
| 479 | this->menuSelector->setSizeSoft2D(element->getSizeX2D()*.7, element->getSizeY2D(), bias); |
|---|
| 480 | } |
|---|
| 481 | else |
|---|
| 482 | { |
|---|
| 483 | this->menuSelector->setAbsCoor2D(element->getAbsCoor2D() + Vector2D(0, element->getSizeY2D() *.5)); |
|---|
| 484 | this->menuSelector->setSize2D(element->getSizeX2D()*.7, element->getSizeY2D()); |
|---|
| 485 | } |
|---|
| 486 | } |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | /********************************************************************************************** |
|---|
| 491 | SimpleGameMenuData |
|---|
| 492 | **********************************************************************************************/ |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | /** |
|---|
| 496 | * SimpleGameMenuData constructor |
|---|
| 497 | */ |
|---|
| 498 | SimpleGameMenuData::SimpleGameMenuData() |
|---|
| 499 | {} |
|---|
| 500 | |
|---|
| 501 | /** |
|---|
| 502 | * SimpleGameMenuData decontructor |
|---|
| 503 | */ |
|---|
| 504 | SimpleGameMenuData::~SimpleGameMenuData() |
|---|
| 505 | {} |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | /** |
|---|
| 509 | * initialize the GameWorldDataData |
|---|
| 510 | */ |
|---|
| 511 | ErrorMessage SimpleGameMenuData::init() |
|---|
| 512 | { |
|---|
| 513 | /* call underlying function */ |
|---|
| 514 | GameWorldData::init(); |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | |
|---|
| 518 | /** |
|---|
| 519 | * loads the GUI data |
|---|
| 520 | * @param root reference to the xml root element |
|---|
| 521 | */ |
|---|
| 522 | ErrorMessage SimpleGameMenuData::loadGUI(const TiXmlElement* root) |
|---|
| 523 | { |
|---|
| 524 | /* call underlying function */ |
|---|
| 525 | GameWorldData::loadGUI(root); |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | /** |
|---|
| 530 | * unloads the GUI data |
|---|
| 531 | */ |
|---|
| 532 | ErrorMessage SimpleGameMenuData::unloadGUI() |
|---|
| 533 | { |
|---|
| 534 | /* call underlying function */ |
|---|
| 535 | GameWorldData::unloadGUI(); |
|---|
| 536 | } |
|---|
| 537 | |
|---|
| 538 | |
|---|
| 539 | /** |
|---|
| 540 | * overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff) |
|---|
| 541 | * @param root reference to the xml root parameter |
|---|
| 542 | */ |
|---|
| 543 | ErrorMessage SimpleGameMenuData::loadWorldEntities(const TiXmlElement* root) |
|---|
| 544 | { |
|---|
| 545 | GameWorldData::loadWorldEntities(root); |
|---|
| 546 | /* |
|---|
| 547 | const TiXmlElement* element = root->FirstChildElement("WorldEntities"); |
|---|
| 548 | |
|---|
| 549 | if( element != NULL) |
|---|
| 550 | { |
|---|
| 551 | element = element->FirstChildElement(); |
|---|
| 552 | PRINTF(4)("Loading WorldEntities\n"); |
|---|
| 553 | while(element != NULL) |
|---|
| 554 | { |
|---|
| 555 | BaseObject* created = Factory::fabricate(element); |
|---|
| 556 | if( created != NULL ) |
|---|
| 557 | printf("Created a %s: %s\n", created->getClassName(), created->getName()); |
|---|
| 558 | |
|---|
| 559 | if( element->Value() == "SkyBox") |
|---|
| 560 | this->sky = dynamic_cast<WorldEntity*>(created); |
|---|
| 561 | if( element->Value() == "Terrain") |
|---|
| 562 | this->terrain = dynamic_cast<Terrain*>(created); |
|---|
| 563 | element = element->NextSiblingElement(); |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | PRINTF(4)("Done loading WorldEntities\n"); |
|---|
| 567 | } |
|---|
| 568 | |
|---|
| 569 | // init the pnode tree |
|---|
| 570 | PNode::getNullParent()->init(); |
|---|
| 571 | */ |
|---|
| 572 | } |
|---|
| 573 | |
|---|
| 574 | |
|---|
| 575 | /** |
|---|
| 576 | * unloads the world entities from the xml file |
|---|
| 577 | */ |
|---|
| 578 | ErrorMessage SimpleGameMenuData::unloadWorldEntities() |
|---|
| 579 | { |
|---|
| 580 | /* call underlying function */ |
|---|
| 581 | GameWorldData::unloadWorldEntities(); |
|---|
| 582 | } |
|---|
| 583 | |
|---|
| 584 | |
|---|
| 585 | /** |
|---|
| 586 | * loads the scene data |
|---|
| 587 | * @param root reference to the xml root element |
|---|
| 588 | */ |
|---|
| 589 | ErrorMessage SimpleGameMenuData::loadScene(const TiXmlElement* root) |
|---|
| 590 | { |
|---|
| 591 | /* call underlying function */ |
|---|
| 592 | GameWorldData::loadScene(root); |
|---|
| 593 | } |
|---|
| 594 | |
|---|
| 595 | |
|---|
| 596 | /** |
|---|
| 597 | * unloads the scene data |
|---|
| 598 | */ |
|---|
| 599 | ErrorMessage SimpleGameMenuData::unloadScene() |
|---|
| 600 | { |
|---|
| 601 | /* call underlying function */ |
|---|
| 602 | GameWorldData::unloadScene(); |
|---|
| 603 | } |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | |
|---|