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