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