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