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