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