[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 | |
---|
[7876] | 69 | OrxGui::GLGuiCursor* cursor = new OrxGui::GLGuiCursor(); |
---|
| 70 | cursor->show(); |
---|
| 71 | |
---|
[7221] | 72 | if (root != NULL) |
---|
| 73 | this->loadParams(root); |
---|
[6878] | 74 | |
---|
[7032] | 75 | State::setMenuID(this->getNextStoryID()); |
---|
[6502] | 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
[6501] | 79 | /** |
---|
[7221] | 80 | * @brief remove the SimpleGameMenu from memory |
---|
[6502] | 81 | * |
---|
| 82 | * delete everything explicitly, that isn't contained in the parenting tree! |
---|
| 83 | * things contained in the tree are deleted automaticaly |
---|
[6501] | 84 | */ |
---|
[6502] | 85 | SimpleGameMenu::~SimpleGameMenu () |
---|
| 86 | { |
---|
| 87 | PRINTF(3)("SimpleGameMenu::~SimpleGameMenu() - deleting current world\n"); |
---|
[7287] | 88 | |
---|
| 89 | if( this->dataTank) |
---|
| 90 | delete this->dataTank; |
---|
[6502] | 91 | } |
---|
[6501] | 92 | |
---|
[6502] | 93 | |
---|
| 94 | /** |
---|
[7221] | 95 | * @brief loads the parameters of a SimpleGameMenu from an XML-element |
---|
[6502] | 96 | * @param root the XML-element to load from |
---|
[6501] | 97 | */ |
---|
[6502] | 98 | void SimpleGameMenu::loadParams(const TiXmlElement* root) |
---|
| 99 | { |
---|
| 100 | /* skip the GameWorld, since it does not define any useful loadParams for this class */ |
---|
[6696] | 101 | //static_cast<GameWorld*>(this)->loadParams(root); |
---|
| 102 | GameWorld::loadParams(root); |
---|
[6501] | 103 | |
---|
[6502] | 104 | PRINTF(4)("Loaded SimpleGameMenu specific stuff\n"); |
---|
| 105 | } |
---|
[6501] | 106 | |
---|
[6502] | 107 | |
---|
[6501] | 108 | /** |
---|
[7221] | 109 | * @brief this is executed just before load |
---|
[6504] | 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 | |
---|
[7868] | 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); |
---|
[6521] | 124 | |
---|
| 125 | this->dataTank->localCamera->setRelCoor(this->cameraVector); |
---|
[6524] | 126 | |
---|
| 127 | GraphicsEngine::getInstance()->displayFPS(false); |
---|
[6862] | 128 | |
---|
| 129 | this->layerIndex = 0; |
---|
| 130 | this->menuSelectedIndex = 0; |
---|
[6504] | 131 | } |
---|
| 132 | |
---|
| 133 | |
---|
[6524] | 134 | /** |
---|
[7221] | 135 | * @brief load the data |
---|
[6524] | 136 | */ |
---|
[6521] | 137 | ErrorMessage SimpleGameMenu::loadData() |
---|
[6504] | 138 | { |
---|
[6521] | 139 | GameWorld::loadData(); |
---|
[6504] | 140 | |
---|
[6845] | 141 | if (this->dataXML != NULL) |
---|
| 142 | { |
---|
[7318] | 143 | LoadParam(dataXML, "selector-sound", this, SimpleGameMenu, setSelectorSound); |
---|
| 144 | |
---|
[6845] | 145 | TiXmlElement* element = this->dataXML->FirstChildElement("Elements"); |
---|
| 146 | |
---|
[7318] | 147 | |
---|
[6845] | 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 ) |
---|
[6852] | 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 | } |
---|
[6851] | 166 | element = element->NextSiblingElement(); |
---|
[6845] | 167 | } |
---|
| 168 | PRINTF(4)("Done loading Elements\n"); |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | |
---|
[6520] | 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); |
---|
[6878] | 181 | this->menuSelector->setBindNode((const PNode*)NULL); |
---|
[6520] | 182 | } |
---|
[7019] | 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())) |
---|
[6520] | 189 | { |
---|
[7019] | 190 | this->menuStartGame = dynamic_cast<TextElement*>(*entity); |
---|
[6878] | 191 | this->menuStartGame->setBindNode((const PNode*)NULL); |
---|
[6883] | 192 | this->menuStartGame->setRelCoor2D(State::getResX() / 2.0f, |
---|
[7316] | 193 | State::getResY() / 2.0f - 60.0f); |
---|
[7019] | 194 | this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity)); |
---|
[6835] | 195 | |
---|
[6520] | 196 | } |
---|
| 197 | else if( !strcmp( "Multiplayer_Menu", (*entity)->getName())) |
---|
| 198 | { |
---|
[7019] | 199 | this->menuStartMultiplayerGame = dynamic_cast<TextElement*>(*entity); |
---|
[6878] | 200 | this->menuStartMultiplayerGame->setBindNode((const PNode*)NULL); |
---|
[6883] | 201 | this->menuStartMultiplayerGame->setRelCoor2D(State::getResX() / 2.0f, |
---|
[7316] | 202 | State::getResY() / 2.0f + ((this->menuLayers[0].menuList.size() -1 ) * 60.0f)); |
---|
[7019] | 203 | this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity)); |
---|
[6520] | 204 | } |
---|
| 205 | else if( !strcmp( "Quit_Menu", (*entity)->getName())) |
---|
| 206 | { |
---|
[7019] | 207 | this->menuQuitGame = dynamic_cast<TextElement*>(*entity); |
---|
[6878] | 208 | this->menuQuitGame->setBindNode((const PNode*)NULL); |
---|
[6883] | 209 | this->menuQuitGame->setRelCoor2D(State::getResX() / 2.0f, |
---|
[7316] | 210 | State::getResY() / 2.0f + ((this->menuLayers[0].menuList.size() -1 )* 60.0f)); |
---|
[7019] | 211 | this->menuLayers[0].menuList.push_back(dynamic_cast<TextElement*>(*entity)); |
---|
[6520] | 212 | } |
---|
| 213 | } |
---|
[6980] | 214 | this->menuSelected->getNullElement()->update2D(0.1f); |
---|
[6520] | 215 | this->menuSelectedIndex = 0; |
---|
[6991] | 216 | this->menuSelected = this->menuLayers[0].menuList[this->menuSelectedIndex]; |
---|
[7063] | 217 | this->sliderTo(this->menuSelected, 0.0f); |
---|
[6839] | 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 | { |
---|
[6991] | 228 | this->menuLayers[1].storyList.push_back(se); |
---|
[6874] | 229 | |
---|
| 230 | // generating menu item |
---|
[7019] | 231 | TextElement* te = new TextElement(); |
---|
| 232 | te->setVisibility(false); |
---|
| 233 | te->setText(se->getName()); |
---|
[7316] | 234 | te->setRelCoor2D(State::getResX() / 2.0f - 200.0f, State::getResY() / 2.0f + ((this->menuLayers[1].menuList.size() - 2.0f) * 60.0f)); |
---|
[7019] | 235 | this->menuLayers[1].menuList.push_back(te); |
---|
| 236 | |
---|
| 237 | // generating screenshoot item |
---|
[6841] | 238 | ImageEntity* ie = new ImageEntity(); |
---|
[6848] | 239 | ie->setVisibility(false); |
---|
[6878] | 240 | ie->setBindNode((const PNode*)NULL); |
---|
| 241 | ie->setTexture(se->getMenuScreenshoot()); |
---|
[7316] | 242 | ie->setRelCoor2D(State::getResX() / 2.0f + 250.0f, State::getResY() / 2.0f); |
---|
[6884] | 243 | ie->setSize2D(140.0f, 105.0f); |
---|
[6991] | 244 | this->menuLayers[1].screenshootList.push_back(ie); |
---|
[6839] | 245 | } |
---|
| 246 | } |
---|
[6521] | 247 | } |
---|
[6520] | 248 | |
---|
[7318] | 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 | { |
---|
[7460] | 255 | this->selectorSource = OrxSound::SoundEngine::getInstance()->createSource(selectorSound, NULL); |
---|
[7318] | 256 | } |
---|
[6521] | 257 | |
---|
[6862] | 258 | ErrorMessage SimpleGameMenu::unloadData() |
---|
| 259 | { |
---|
[7868] | 260 | this->unsubscribeEvents(ES_MENU); |
---|
[6862] | 261 | |
---|
[6991] | 262 | std::vector<MenuLayer>::iterator mit; |
---|
| 263 | for(mit = this->menuLayers.begin(); mit != this->menuLayers.end(); mit++) |
---|
[6862] | 264 | { |
---|
[7019] | 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(); |
---|
[6991] | 273 | (*mit).screenshootList.clear(); |
---|
[6862] | 274 | } |
---|
[7029] | 275 | |
---|
[7318] | 276 | // delete the SoundSource. |
---|
| 277 | if (this->selectorSource != NULL) |
---|
| 278 | delete this->selectorSource; |
---|
| 279 | this->selectorSource = NULL; |
---|
[7029] | 280 | |
---|
| 281 | GameWorld::unloadData(); |
---|
[6862] | 282 | } |
---|
| 283 | |
---|
| 284 | |
---|
[6524] | 285 | /** |
---|
[7221] | 286 | * @brief start the menu |
---|
[6524] | 287 | */ |
---|
[6521] | 288 | bool SimpleGameMenu::start() |
---|
| 289 | { |
---|
| 290 | EventHandler::getInstance()->pushState(ES_MENU); |
---|
| 291 | |
---|
[6504] | 292 | /* now call the underlying*/ |
---|
| 293 | GameWorld::start(); |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | |
---|
| 297 | |
---|
[6524] | 298 | /** |
---|
| 299 | * stop the menu |
---|
| 300 | */ |
---|
[6504] | 301 | bool SimpleGameMenu::stop() |
---|
| 302 | { |
---|
| 303 | EventHandler::getInstance()->popState(); |
---|
| 304 | |
---|
| 305 | /* now call the underlying*/ |
---|
| 306 | GameWorld::stop(); |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | |
---|
[6521] | 310 | /** |
---|
| 311 | * override the standard tick for more functionality |
---|
| 312 | */ |
---|
| 313 | void SimpleGameMenu::tick() |
---|
| 314 | { |
---|
| 315 | GameWorld::tick(); |
---|
[6504] | 316 | |
---|
[7131] | 317 | this->animateScene(this->dtS); |
---|
[6521] | 318 | } |
---|
| 319 | |
---|
| 320 | |
---|
[6504] | 321 | /** |
---|
[7370] | 322 | * @brief no collision detection in the menu |
---|
[6501] | 323 | */ |
---|
[6502] | 324 | void SimpleGameMenu::collide() |
---|
[6521] | 325 | { |
---|
| 326 | // this->dataTank->localCamera-> |
---|
| 327 | } |
---|
[6501] | 328 | |
---|
| 329 | |
---|
[6504] | 330 | /** |
---|
[7370] | 331 | * @brief animate the scene |
---|
[6521] | 332 | */ |
---|
| 333 | void SimpleGameMenu::animateScene(float dt) |
---|
| 334 | { |
---|
[7131] | 335 | Quaternion q(/*0.00005*/ dt * .1, Vector(0.0, 1.0, 0.0)); |
---|
[6521] | 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 | /** |
---|
[7370] | 343 | * @brief event dispatcher funciton |
---|
[6504] | 344 | * @param event the incoming event |
---|
| 345 | */ |
---|
| 346 | void SimpleGameMenu::process(const Event &event) |
---|
| 347 | { |
---|
[6839] | 348 | /* ----------------- LAYER 1 ---------------*/ |
---|
[6837] | 349 | if( this->layerIndex == 0) |
---|
[6504] | 350 | { |
---|
[6837] | 351 | if( event.type == SDLK_RETURN && event.bPressed == true) |
---|
[6520] | 352 | { |
---|
[6837] | 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 |
---|
[6991] | 361 | if( this->menuLayers[1].menuList.size() == 0) |
---|
[6837] | 362 | { |
---|
[6839] | 363 | PRINTF(1)("Haven't got any StoryEntities to play!\n"); |
---|
[6837] | 364 | return; |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | this->switchMenuLayer(this->layerIndex, 1); |
---|
| 368 | } |
---|
[6520] | 369 | } |
---|
[6854] | 370 | if( event.type == SDLK_ESCAPE && event.bPressed == true) |
---|
| 371 | { |
---|
| 372 | this->setNextStoryID(WORLD_ID_GAMEEND); |
---|
| 373 | this->stop(); |
---|
| 374 | } |
---|
[6839] | 375 | } /* ----------------- LAYER 2 ---------------*/ |
---|
[6837] | 376 | else if( this->layerIndex == 1) |
---|
[6520] | 377 | { |
---|
[6848] | 378 | if( event.type == SDLK_RETURN && event.bPressed == true) |
---|
| 379 | { |
---|
[6991] | 380 | this->setNextStoryID( this->menuLayers[1].storyList[this->menuSelectedIndex]->getStoryID()); |
---|
[6848] | 381 | this->stop(); |
---|
| 382 | } |
---|
[6854] | 383 | if( event.type == SDLK_ESCAPE && event.bPressed == true) |
---|
| 384 | { |
---|
| 385 | this->switchMenuLayer(this->layerIndex, 0); |
---|
| 386 | } |
---|
[6520] | 387 | } |
---|
[6853] | 388 | |
---|
| 389 | |
---|
| 390 | |
---|
| 391 | // The menu selction cursor |
---|
| 392 | if( event.type == SDLK_DOWN && event.bPressed == true) |
---|
| 393 | { |
---|
[6991] | 394 | if(this->menuSelectedIndex < (this->menuLayers[this->layerIndex].menuList.size() - 1)) |
---|
[6853] | 395 | { |
---|
[6991] | 396 | this->menuSelected = this->menuLayers[this->layerIndex].menuList[++this->menuSelectedIndex]; |
---|
[7063] | 397 | this->sliderTo(this->menuSelected, 5.0f); |
---|
[7318] | 398 | if (this->selectorSource != NULL) |
---|
| 399 | this->selectorSource->play(); |
---|
[6883] | 400 | |
---|
| 401 | if( this->layerIndex == 1) |
---|
| 402 | { |
---|
[6991] | 403 | this->menuLayers[1].screenshootList[this->menuSelectedIndex]->setVisibility(true); |
---|
| 404 | this->menuLayers[1].screenshootList[this->menuSelectedIndex-1]->setVisibility(false); |
---|
[6883] | 405 | } |
---|
[6853] | 406 | } |
---|
| 407 | } |
---|
| 408 | else if( event.type == SDLK_UP && event.bPressed == true) |
---|
| 409 | { |
---|
| 410 | if(this->menuSelectedIndex > 0) |
---|
| 411 | { |
---|
[6991] | 412 | this->menuSelected = this->menuLayers[this->layerIndex].menuList[--this->menuSelectedIndex]; |
---|
[7063] | 413 | this->sliderTo(this->menuSelected, 5.0f); |
---|
[7318] | 414 | if (this->selectorSource != NULL) |
---|
| 415 | this->selectorSource->play(); |
---|
[6883] | 416 | |
---|
| 417 | if( this->layerIndex == 1) |
---|
| 418 | { |
---|
[6991] | 419 | this->menuLayers[1].screenshootList[this->menuSelectedIndex]->setVisibility(true); |
---|
| 420 | this->menuLayers[1].screenshootList[this->menuSelectedIndex+1]->setVisibility(false); |
---|
[6883] | 421 | } |
---|
[6853] | 422 | } |
---|
| 423 | } |
---|
[6504] | 424 | } |
---|
[6502] | 425 | |
---|
| 426 | |
---|
[6837] | 427 | /** |
---|
[7317] | 428 | * @brief switches to from one meny layer to an other |
---|
[6837] | 429 | * @param layer1 from layer |
---|
| 430 | * @param layer2 to layer |
---|
| 431 | */ |
---|
| 432 | void SimpleGameMenu::switchMenuLayer(int layer1, int layer2) |
---|
| 433 | { |
---|
| 434 | // wrong sizes |
---|
[6991] | 435 | if(layer1 >= this->menuLayers.size() || layer2 >= this->menuLayers.size()) |
---|
[6837] | 436 | return; |
---|
[6502] | 437 | |
---|
| 438 | |
---|
[6837] | 439 | PRINTF(0)("Removing layer %i\n", layer1); |
---|
[7019] | 440 | std::vector<TextElement*>::iterator te; |
---|
[6837] | 441 | // fade old menu |
---|
[7019] | 442 | for( te = this->menuLayers[layer1].menuList.begin(); te != this->menuLayers[layer1].menuList.end(); te++) |
---|
[6837] | 443 | { |
---|
[7019] | 444 | (*te)->setVisibility(false); |
---|
[6837] | 445 | } |
---|
[7019] | 446 | |
---|
| 447 | std::vector<ImageEntity*>::iterator it; |
---|
| 448 | |
---|
[6878] | 449 | //also fade the screenshots if in level choosement mode |
---|
[6991] | 450 | for( it = this->menuLayers[layer1].screenshootList.begin(); it != this->menuLayers[layer1].screenshootList.end(); it++) |
---|
[6878] | 451 | { |
---|
| 452 | (*it)->setVisibility(false); |
---|
| 453 | } |
---|
[6502] | 454 | |
---|
| 455 | |
---|
[6837] | 456 | PRINTF(0)("Showing layer %i\n", layer1); |
---|
| 457 | // beam here the new menu |
---|
[7019] | 458 | for( te = this->menuLayers[layer2].menuList.begin(); te != this->menuLayers[layer2].menuList.end(); te++ ) |
---|
[6848] | 459 | { |
---|
[7019] | 460 | (*te)->setVisibility(true); |
---|
[6848] | 461 | } |
---|
[6837] | 462 | |
---|
[6878] | 463 | |
---|
[6837] | 464 | this->layerIndex = layer2; |
---|
[6991] | 465 | this->menuSelected = this->menuLayers[layer2].menuList[0]; |
---|
[7765] | 466 | this->menuSelector->setAbsCoor2D(this->menuSelected->getAbsCoor2D() + Vector2D(0, this->menuSelected->getSizeY2D() *.5)); |
---|
| 467 | this->menuSelector->setSize2D(this->menuSelected->getSizeX2D()*.7, this->menuSelected->getSizeY2D()); |
---|
[6855] | 468 | this->menuSelectedIndex = 0; |
---|
[6883] | 469 | |
---|
| 470 | if( layer2 == 1) |
---|
[6991] | 471 | this->menuLayers[layer2].screenshootList[0]->setVisibility(true); |
---|
[6837] | 472 | } |
---|
| 473 | |
---|
[7063] | 474 | void SimpleGameMenu::sliderTo(const Element2D* element, float bias) |
---|
| 475 | { |
---|
| 476 | if (bias > 0.0) |
---|
| 477 | { |
---|
[7316] | 478 | this->menuSelector->setAbsCoorSoft2D(element->getAbsCoor2D() + Vector2D(0, element->getSizeY2D() *.5), bias); |
---|
[7764] | 479 | this->menuSelector->setSizeSoft2D(element->getSizeX2D()*.7, element->getSizeY2D(), bias); |
---|
[7063] | 480 | } |
---|
| 481 | else |
---|
| 482 | { |
---|
[7316] | 483 | this->menuSelector->setAbsCoor2D(element->getAbsCoor2D() + Vector2D(0, element->getSizeY2D() *.5)); |
---|
[7764] | 484 | this->menuSelector->setSize2D(element->getSizeX2D()*.7, element->getSizeY2D()); |
---|
[7063] | 485 | } |
---|
| 486 | } |
---|
[6837] | 487 | |
---|
| 488 | |
---|
| 489 | |
---|
[6502] | 490 | /********************************************************************************************** |
---|
| 491 | SimpleGameMenuData |
---|
| 492 | **********************************************************************************************/ |
---|
| 493 | |
---|
| 494 | |
---|
[6501] | 495 | /** |
---|
[6502] | 496 | * SimpleGameMenuData constructor |
---|
[6501] | 497 | */ |
---|
[6502] | 498 | SimpleGameMenuData::SimpleGameMenuData() |
---|
[6501] | 499 | {} |
---|
| 500 | |
---|
| 501 | /** |
---|
[6502] | 502 | * SimpleGameMenuData decontructor |
---|
[6501] | 503 | */ |
---|
[6502] | 504 | SimpleGameMenuData::~SimpleGameMenuData() |
---|
[6501] | 505 | {} |
---|
| 506 | |
---|
| 507 | |
---|
| 508 | /** |
---|
[6502] | 509 | * initialize the GameWorldDataData |
---|
[6501] | 510 | */ |
---|
[6502] | 511 | ErrorMessage SimpleGameMenuData::init() |
---|
| 512 | { |
---|
| 513 | /* call underlying function */ |
---|
| 514 | GameWorldData::init(); |
---|
| 515 | } |
---|
[6501] | 516 | |
---|
| 517 | |
---|
| 518 | /** |
---|
[6502] | 519 | * loads the GUI data |
---|
| 520 | * @param root reference to the xml root element |
---|
[6501] | 521 | */ |
---|
[7370] | 522 | ErrorMessage SimpleGameMenuData::loadGUI(const TiXmlElement* root) |
---|
[6502] | 523 | { |
---|
| 524 | /* call underlying function */ |
---|
| 525 | GameWorldData::loadGUI(root); |
---|
| 526 | } |
---|
[6501] | 527 | |
---|
| 528 | |
---|
| 529 | /** |
---|
[6502] | 530 | * unloads the GUI data |
---|
[6501] | 531 | */ |
---|
[6502] | 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 | */ |
---|
[7370] | 543 | ErrorMessage SimpleGameMenuData::loadWorldEntities(const TiXmlElement* root) |
---|
[6502] | 544 | { |
---|
[7370] | 545 | GameWorldData::loadWorldEntities(root); |
---|
| 546 | /* |
---|
| 547 | const TiXmlElement* element = root->FirstChildElement("WorldEntities"); |
---|
[6502] | 548 | |
---|
| 549 | if( element != NULL) |
---|
| 550 | { |
---|
| 551 | element = element->FirstChildElement(); |
---|
| 552 | PRINTF(4)("Loading WorldEntities\n"); |
---|
[7370] | 553 | while(element != NULL) |
---|
[6502] | 554 | { |
---|
| 555 | BaseObject* created = Factory::fabricate(element); |
---|
| 556 | if( created != NULL ) |
---|
| 557 | printf("Created a %s: %s\n", created->getClassName(), created->getName()); |
---|
| 558 | |
---|
[7370] | 559 | if( element->Value() == "SkyBox") |
---|
[6502] | 560 | this->sky = dynamic_cast<WorldEntity*>(created); |
---|
[7370] | 561 | if( element->Value() == "Terrain") |
---|
[6502] | 562 | this->terrain = dynamic_cast<Terrain*>(created); |
---|
| 563 | element = element->NextSiblingElement(); |
---|
| 564 | } |
---|
[7370] | 565 | |
---|
[6502] | 566 | PRINTF(4)("Done loading WorldEntities\n"); |
---|
| 567 | } |
---|
| 568 | |
---|
[7370] | 569 | // init the pnode tree |
---|
[6502] | 570 | PNode::getNullParent()->init(); |
---|
[7370] | 571 | */ |
---|
[6502] | 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 | */ |
---|
[7370] | 589 | ErrorMessage SimpleGameMenuData::loadScene(const TiXmlElement* root) |
---|
[6502] | 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 | |
---|