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