[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 | |
---|
[8673] | 19 | #include "game_menu.h" |
---|
[6501] | 20 | |
---|
[7868] | 21 | #include "event_handler.h" |
---|
| 22 | |
---|
[6502] | 23 | #include "state.h" |
---|
| 24 | |
---|
[7193] | 25 | #include "util/loading/load_param.h" |
---|
| 26 | #include "util/loading/factory.h" |
---|
[6502] | 27 | |
---|
[8688] | 28 | #include "graphics_engine.h" |
---|
[6521] | 29 | #include "camera.h" |
---|
[8688] | 30 | #include "sound_engine.h" |
---|
[6502] | 31 | |
---|
[7318] | 32 | #include "sound_source.h" |
---|
[6504] | 33 | |
---|
[7919] | 34 | #include "glgui.h" |
---|
[8691] | 35 | #include "menu/glgui_imagebutton.h" |
---|
[6502] | 36 | |
---|
[9059] | 37 | #include "glgui_text.h" |
---|
| 38 | |
---|
| 39 | #include "network_manager.h" |
---|
| 40 | |
---|
[9869] | 41 | #include "parser/preferences/preferences.h" |
---|
[9235] | 42 | |
---|
[9869] | 43 | #include "class_id_DEPRECATED.h" |
---|
[8673] | 44 | //! This creates a Factory to fabricate a GameMenu |
---|
[9869] | 45 | ObjectListDefinitionID(GameMenu, CL_GAME_MENU); |
---|
| 46 | CREATE_FACTORY(GameMenu); |
---|
[6502] | 47 | |
---|
| 48 | |
---|
[8673] | 49 | GameMenu::GameMenu(const TiXmlElement* root) |
---|
[7919] | 50 | : GameWorld() |
---|
[6502] | 51 | { |
---|
[9869] | 52 | this->registerObject(this, GameMenu::_objectList); |
---|
[8673] | 53 | this->setName("GameMenu uninitialized"); |
---|
[6502] | 54 | |
---|
[8673] | 55 | this->dataTank = new GameMenuData(); |
---|
[6502] | 56 | |
---|
[6521] | 57 | this->cameraVector = Vector(50.0, 0.0, 0.0); |
---|
[6862] | 58 | |
---|
[7221] | 59 | if (root != NULL) |
---|
| 60 | this->loadParams(root); |
---|
[6878] | 61 | |
---|
[7032] | 62 | State::setMenuID(this->getNextStoryID()); |
---|
[6502] | 63 | } |
---|
| 64 | |
---|
[6501] | 65 | /** |
---|
[8673] | 66 | * @brief remove the GameMenu from memory |
---|
[7919] | 67 | * |
---|
| 68 | * delete everything explicitly, that isn't contained in the parenting tree! |
---|
| 69 | * things contained in the tree are deleted automaticaly |
---|
| 70 | */ |
---|
[8673] | 71 | GameMenu::~GameMenu () |
---|
[6502] | 72 | { |
---|
[8673] | 73 | PRINTF(3)("GameMenu::~GameMenu() - deleting current world\n"); |
---|
[7287] | 74 | |
---|
| 75 | if( this->dataTank) |
---|
| 76 | delete this->dataTank; |
---|
[9656] | 77 | OrxGui::GLGuiHandler::deleteInstance( ); |
---|
[6502] | 78 | } |
---|
[6501] | 79 | |
---|
[6502] | 80 | |
---|
| 81 | /** |
---|
[8673] | 82 | * @brief loads the parameters of a GameMenu from an XML-element |
---|
[7919] | 83 | * @param root the XML-element to load from |
---|
| 84 | */ |
---|
[8673] | 85 | void GameMenu::loadParams(const TiXmlElement* root) |
---|
[6502] | 86 | { |
---|
| 87 | /* skip the GameWorld, since it does not define any useful loadParams for this class */ |
---|
[6696] | 88 | //static_cast<GameWorld*>(this)->loadParams(root); |
---|
| 89 | GameWorld::loadParams(root); |
---|
[6501] | 90 | |
---|
[8673] | 91 | PRINTF(4)("Loaded GameMenu specific stuff\n"); |
---|
[6502] | 92 | } |
---|
[6501] | 93 | |
---|
[6502] | 94 | |
---|
[6501] | 95 | /** |
---|
[7919] | 96 | * @brief this is executed just before load |
---|
| 97 | * |
---|
| 98 | * since the load function sometimes needs data, that has been initialized |
---|
| 99 | * before the load and after the proceeding storyentity has finished |
---|
| 100 | */ |
---|
[8673] | 101 | ErrorMessage GameMenu::init() |
---|
[6504] | 102 | { |
---|
| 103 | /* call underlying init funciton */ |
---|
| 104 | GameWorld::init(); |
---|
| 105 | |
---|
[7868] | 106 | this->subscribeEvent(ES_MENU, SDLK_UP); |
---|
| 107 | this->subscribeEvent(ES_MENU, SDLK_DOWN); |
---|
| 108 | this->subscribeEvent(ES_MENU, SDLK_RETURN); |
---|
| 109 | this->subscribeEvent(ES_MENU, SDLK_SPACE); |
---|
| 110 | this->subscribeEvent(ES_MENU, SDLK_ESCAPE); |
---|
[6521] | 111 | |
---|
| 112 | this->dataTank->localCamera->setRelCoor(this->cameraVector); |
---|
[6524] | 113 | |
---|
| 114 | GraphicsEngine::getInstance()->displayFPS(false); |
---|
[6862] | 115 | |
---|
[8677] | 116 | return ErrorMessage(); |
---|
[6504] | 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
[6524] | 120 | /** |
---|
[7919] | 121 | * @brief load the data |
---|
| 122 | */ |
---|
[8673] | 123 | ErrorMessage GameMenu::loadData() |
---|
[6504] | 124 | { |
---|
[8677] | 125 | this->mainMenuBox = NULL; |
---|
| 126 | |
---|
| 127 | this->levelsBox = NULL; |
---|
| 128 | this->networkBox = NULL; |
---|
[9235] | 129 | |
---|
[9059] | 130 | this->clientNetworkBox = NULL; |
---|
| 131 | this->serverNetworkBox = NULL; |
---|
[8677] | 132 | |
---|
| 133 | this->optionsBox = NULL; |
---|
[8688] | 134 | this->generalBox = NULL; |
---|
[8677] | 135 | this->audioBox = NULL; |
---|
| 136 | this->videoBox = NULL; |
---|
| 137 | this->controlBox = NULL; |
---|
| 138 | this->levelsBox = NULL; |
---|
| 139 | |
---|
[8688] | 140 | this->currentlyOpened = NULL; |
---|
| 141 | |
---|
[8677] | 142 | return GameWorld::loadData(); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | void GameMenu::showMainMenu() |
---|
| 147 | { |
---|
| 148 | if (mainMenuBox == NULL) |
---|
[8674] | 149 | { |
---|
[8677] | 150 | this->mainMenuBox = new OrxGui::GLGuiBox(); |
---|
| 151 | { |
---|
| 152 | OrxGui::GLGuiButton* startButton = new OrxGui::GLGuiPushButton("Play"); |
---|
[9406] | 153 | startButton->released.connect(this, &GameMenu::showCampaigns); |
---|
[8677] | 154 | this->mainMenuBox->pack(startButton); |
---|
[9014] | 155 | startButton->select(); |
---|
[8674] | 156 | |
---|
[8677] | 157 | OrxGui::GLGuiButton* networkButton = new OrxGui::GLGuiPushButton("MultiPlayer"); |
---|
[9406] | 158 | networkButton->released.connect(this, &GameMenu::showMultiPlayer); |
---|
[8677] | 159 | this->mainMenuBox->pack(networkButton); |
---|
[8674] | 160 | |
---|
[8677] | 161 | OrxGui::GLGuiButton* optionsButton = new OrxGui::GLGuiPushButton("Options"); |
---|
[9406] | 162 | optionsButton->released.connect(this, &GameMenu::showOptionsMenu); |
---|
[8677] | 163 | this->mainMenuBox->pack(optionsButton); |
---|
[8674] | 164 | |
---|
| 165 | |
---|
[8677] | 166 | OrxGui::GLGuiButton* quitButton = new OrxGui::GLGuiPushButton("Quit"); |
---|
| 167 | this->mainMenuBox->pack(quitButton); |
---|
[9406] | 168 | quitButton->released.connect(this, &GameMenu::quitMenu); |
---|
[8677] | 169 | } |
---|
[8674] | 170 | } |
---|
[8677] | 171 | this->mainMenuBox->showAll(); |
---|
[8674] | 172 | |
---|
[9014] | 173 | |
---|
[8677] | 174 | this->mainMenuBox->setRelCoor2D(200, 100); |
---|
| 175 | } |
---|
[8674] | 176 | |
---|
[8688] | 177 | |
---|
[8677] | 178 | void GameMenu::showCampaigns() |
---|
| 179 | { |
---|
| 180 | if (this->levelsBox == NULL) |
---|
| 181 | { |
---|
[8696] | 182 | this->levelsBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
[8677] | 183 | { |
---|
[8696] | 184 | OrxGui::GLGuiBox* labelBox = new OrxGui::GLGuiBox(); |
---|
| 185 | |
---|
| 186 | OrxGui::GLGuiImage* image = new OrxGui::GLGuiImage(); |
---|
| 187 | image->show(); |
---|
| 188 | image->setWidgetSize( 250, 200); |
---|
| 189 | image->setAbsCoor2D(400, 150); |
---|
[8719] | 190 | image->setForegroundColor(Color( 1,1,1,.6)); |
---|
[8696] | 191 | |
---|
[9014] | 192 | bool first = true; |
---|
[9869] | 193 | for(ObjectList<StoryEntity>::const_iterator it = StoryEntity::objectList().begin(); |
---|
| 194 | it != StoryEntity::objectList().end(); |
---|
| 195 | ++it) |
---|
[8677] | 196 | { |
---|
[9869] | 197 | StoryEntity* se = *it; |
---|
[8677] | 198 | if( se->isContainedInMenu()) |
---|
| 199 | { |
---|
[8691] | 200 | |
---|
[9869] | 201 | PRINTF(3)("Load image %s\n", se->getMenuScreenshoot().c_str()); |
---|
[8691] | 202 | OrxGui::GLGuiImageButton* button = new OrxGui::GLGuiImageButton(se->getName(), se->getStoryID(), se->getMenuScreenshoot(), image); |
---|
[9406] | 203 | button->startLevel.connect(this, &GameMenu::startLevel); |
---|
[8696] | 204 | labelBox->pack(button); |
---|
[8677] | 205 | |
---|
[9014] | 206 | if (first) |
---|
| 207 | { |
---|
| 208 | first = !first; |
---|
| 209 | button->select(); |
---|
| 210 | } |
---|
| 211 | |
---|
[8677] | 212 | // generating screenshoot item |
---|
| 213 | /* |
---|
| 214 | ImageEntity* ie = new ImageEntity(); |
---|
| 215 | ie->setVisibility(false); |
---|
| 216 | ie->setBindNode((const PNode*)NULL); |
---|
| 217 | ie->setTexture(se->getMenuScreenshoot()); |
---|
| 218 | ie->setRelCoor2D(State::getResX() / 2.0f + 250.0f, State::getResY() / 2.0f); |
---|
| 219 | ie->setSize2D(140.0f, 105.0f); |
---|
| 220 | this->menuLayers[1].screenshootList.push_back(ie); |
---|
| 221 | */ |
---|
| 222 | } |
---|
| 223 | } |
---|
[8696] | 224 | |
---|
| 225 | this->levelsBox->pack(labelBox); |
---|
| 226 | this->levelsBox->pack(image); |
---|
[8677] | 227 | } |
---|
[8696] | 228 | |
---|
[8677] | 229 | } |
---|
| 230 | |
---|
[8688] | 231 | this->showSecondLevelElement(this->levelsBox); |
---|
[8677] | 232 | |
---|
[6521] | 233 | } |
---|
[6520] | 234 | |
---|
[8677] | 235 | void GameMenu::showMultiPlayer() |
---|
[8742] | 236 | { |
---|
| 237 | if (this->networkBox == NULL) |
---|
| 238 | { |
---|
[9110] | 239 | this->networkBox = new OrxGui::GLGuiBox( OrxGui::Horizontal ); |
---|
[8742] | 240 | { |
---|
[9110] | 241 | OrxGui::GLGuiBox * box = new OrxGui::GLGuiBox(); |
---|
[9235] | 242 | |
---|
[8742] | 243 | OrxGui::GLGuiButton* clientButton = new OrxGui::GLGuiPushButton("Client"); |
---|
[9110] | 244 | box->pack(clientButton); |
---|
[9406] | 245 | clientButton->released.connect(this, &GameMenu::showClientMenu); |
---|
[8677] | 246 | |
---|
[8742] | 247 | OrxGui::GLGuiButton* serverButton = new OrxGui::GLGuiPushButton("Server"); |
---|
[9110] | 248 | box->pack(serverButton); |
---|
[9406] | 249 | serverButton->released.connect(this, &GameMenu::showServerMenu); |
---|
[9235] | 250 | |
---|
[9110] | 251 | networkBox->pack( box ); |
---|
[8742] | 252 | } |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | this->showSecondLevelElement(this->networkBox); |
---|
| 256 | |
---|
| 257 | } |
---|
| 258 | |
---|
[8677] | 259 | void GameMenu::showOptionsMenu() |
---|
| 260 | { |
---|
| 261 | if (this->optionsBox == NULL) |
---|
| 262 | { |
---|
| 263 | this->optionsBox = new OrxGui::GLGuiBox(); |
---|
| 264 | { |
---|
[9015] | 265 | OrxGui::GLGuiTextfield* WARNtext = new OrxGui::GLGuiTextfield(); |
---|
| 266 | WARNtext->setText("PLEASE USE THE EXTERNAL GUI\n FOR ORXONOX CONFIGURATION\n (start with './orxonox -g')"); |
---|
| 267 | optionsBox->pack(WARNtext); |
---|
| 268 | |
---|
| 269 | |
---|
[8677] | 270 | OrxGui::GLGuiButton* generalButton = new OrxGui::GLGuiPushButton("General"); |
---|
| 271 | optionsBox->pack(generalButton); |
---|
| 272 | |
---|
| 273 | OrxGui::GLGuiButton* audioButton = new OrxGui::GLGuiPushButton("Audio"); |
---|
| 274 | optionsBox->pack(audioButton); |
---|
| 275 | |
---|
| 276 | OrxGui::GLGuiButton* videoButton = new OrxGui::GLGuiPushButton("Video"); |
---|
| 277 | optionsBox->pack(videoButton); |
---|
| 278 | |
---|
| 279 | OrxGui::GLGuiButton* controlButton = new OrxGui::GLGuiPushButton("Control"); |
---|
| 280 | optionsBox->pack(controlButton); |
---|
| 281 | |
---|
| 282 | |
---|
| 283 | // for (unsigned int i = 0; i < |
---|
| 284 | //OrxGui::GLGuiButton* |
---|
| 285 | |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | |
---|
[8688] | 289 | this->showSecondLevelElement(this->optionsBox); |
---|
[8677] | 290 | } |
---|
| 291 | |
---|
| 292 | |
---|
[8688] | 293 | void GameMenu::showSecondLevelElement(OrxGui::GLGuiBox* element) |
---|
| 294 | { |
---|
| 295 | if (this->currentlyOpened != NULL && this->currentlyOpened != element) |
---|
| 296 | this->currentlyOpened->hideAll(); |
---|
[8677] | 297 | |
---|
[8688] | 298 | element->showAll(); |
---|
| 299 | element->setRelCoor2D(200, 100); |
---|
[8677] | 300 | |
---|
[8688] | 301 | this->currentlyOpened = element; |
---|
[8677] | 302 | |
---|
[8688] | 303 | this->mainMenuBox->setRelCoorSoft2D(50, 100, 5); |
---|
| 304 | } |
---|
[8677] | 305 | |
---|
| 306 | |
---|
| 307 | |
---|
| 308 | |
---|
| 309 | |
---|
[8691] | 310 | void GameMenu::startLevel(int levelID) |
---|
| 311 | { |
---|
| 312 | this->setNextStoryID( levelID); |
---|
| 313 | this->stop(); |
---|
| 314 | } |
---|
[8688] | 315 | |
---|
[7318] | 316 | /** |
---|
[7919] | 317 | * @brief set the Sound to play when switching menu entry. |
---|
| 318 | * @param selectorSound the sound to load. |
---|
| 319 | */ |
---|
[8673] | 320 | void GameMenu::setSelectorSound(const std::string& selectorSound) |
---|
[7318] | 321 | { |
---|
[7460] | 322 | this->selectorSource = OrxSound::SoundEngine::getInstance()->createSource(selectorSound, NULL); |
---|
[7318] | 323 | } |
---|
[6521] | 324 | |
---|
[8673] | 325 | ErrorMessage GameMenu::unloadData() |
---|
[6862] | 326 | { |
---|
[7868] | 327 | this->unsubscribeEvents(ES_MENU); |
---|
[6862] | 328 | |
---|
[8677] | 329 | return GameWorld::unloadData(); |
---|
[6862] | 330 | } |
---|
| 331 | |
---|
| 332 | |
---|
[6524] | 333 | /** |
---|
[7919] | 334 | * @brief start the menu |
---|
| 335 | */ |
---|
[8673] | 336 | bool GameMenu::start() |
---|
[6521] | 337 | { |
---|
| 338 | EventHandler::getInstance()->pushState(ES_MENU); |
---|
| 339 | |
---|
[8677] | 340 | this->showMainMenu(); |
---|
[8689] | 341 | OrxGui::GLGuiHandler::getInstance()->activateCursor(); |
---|
| 342 | OrxGui::GLGuiHandler::getInstance()->activate(); |
---|
[8674] | 343 | |
---|
[6504] | 344 | /* now call the underlying*/ |
---|
[8677] | 345 | return GameWorld::start(); |
---|
[6504] | 346 | } |
---|
| 347 | |
---|
| 348 | |
---|
| 349 | |
---|
[6524] | 350 | /** |
---|
[7919] | 351 | * stop the menu |
---|
| 352 | */ |
---|
[8673] | 353 | bool GameMenu::stop() |
---|
[6504] | 354 | { |
---|
| 355 | EventHandler::getInstance()->popState(); |
---|
| 356 | |
---|
| 357 | /* now call the underlying*/ |
---|
[8677] | 358 | return GameWorld::stop(); |
---|
[6504] | 359 | } |
---|
| 360 | |
---|
| 361 | |
---|
[6521] | 362 | /** |
---|
[7919] | 363 | * override the standard tick for more functionality |
---|
| 364 | */ |
---|
[8673] | 365 | void GameMenu::tick() |
---|
[6521] | 366 | { |
---|
| 367 | GameWorld::tick(); |
---|
[6504] | 368 | |
---|
[7919] | 369 | // Make the GLGui tick. |
---|
| 370 | OrxGui::GLGuiHandler::getInstance()->tick(this->dtS); |
---|
| 371 | |
---|
[7131] | 372 | this->animateScene(this->dtS); |
---|
[6521] | 373 | } |
---|
| 374 | |
---|
| 375 | |
---|
[6504] | 376 | /** |
---|
[7919] | 377 | * @brief no collision detection in the menu |
---|
| 378 | */ |
---|
[8673] | 379 | void GameMenu::collide() |
---|
[6521] | 380 | { |
---|
[7919] | 381 | // this->dataTank->localCamera-> |
---|
[6521] | 382 | } |
---|
[6501] | 383 | |
---|
| 384 | |
---|
[6504] | 385 | /** |
---|
[7919] | 386 | * @brief animate the scene |
---|
| 387 | */ |
---|
[8673] | 388 | void GameMenu::animateScene(float dt) |
---|
[6521] | 389 | { |
---|
[7131] | 390 | Quaternion q(/*0.00005*/ dt * .1, Vector(0.0, 1.0, 0.0)); |
---|
[6521] | 391 | this->cameraVector = q.apply(this->cameraVector); |
---|
| 392 | this->dataTank->localCamera->setRelCoor(this->cameraVector); |
---|
| 393 | this->dataTank->localCamera->getTarget()->setRelCoorSoft(0,0,0); |
---|
| 394 | } |
---|
| 395 | |
---|
[8673] | 396 | void GameMenu::quitMenu() |
---|
[7919] | 397 | { |
---|
| 398 | this->setNextStoryID(WORLD_ID_GAMEEND); |
---|
| 399 | this->stop(); |
---|
| 400 | } |
---|
[6521] | 401 | |
---|
[7919] | 402 | |
---|
[6521] | 403 | /** |
---|
[7919] | 404 | * @brief event dispatcher funciton |
---|
| 405 | * @param event the incoming event |
---|
| 406 | */ |
---|
[8673] | 407 | void GameMenu::process(const Event &event) |
---|
[6504] | 408 | { |
---|
[8674] | 409 | if( event.type == SDLK_ESCAPE && event.bPressed == true) |
---|
| 410 | { |
---|
| 411 | this->setNextStoryID(WORLD_ID_GAMEEND); |
---|
| 412 | this->stop(); |
---|
| 413 | } |
---|
| 414 | |
---|
[6504] | 415 | } |
---|
[6502] | 416 | |
---|
| 417 | |
---|
| 418 | |
---|
| 419 | /********************************************************************************************** |
---|
[8673] | 420 | GameMenuData |
---|
[7919] | 421 | **********************************************************************************************/ |
---|
[6502] | 422 | |
---|
| 423 | |
---|
[6501] | 424 | /** |
---|
[8673] | 425 | * GameMenuData constructor |
---|
[7919] | 426 | */ |
---|
[8673] | 427 | GameMenuData::GameMenuData() |
---|
[6501] | 428 | {} |
---|
| 429 | |
---|
| 430 | /** |
---|
[8673] | 431 | * GameMenuData decontructor |
---|
[7919] | 432 | */ |
---|
[8673] | 433 | GameMenuData::~GameMenuData() |
---|
[6501] | 434 | {} |
---|
| 435 | |
---|
| 436 | |
---|
| 437 | /** |
---|
[7919] | 438 | * initialize the GameWorldDataData |
---|
| 439 | */ |
---|
[8673] | 440 | ErrorMessage GameMenuData::init() |
---|
[6502] | 441 | { |
---|
| 442 | /* call underlying function */ |
---|
[8677] | 443 | return GameWorldData::init(); |
---|
[6502] | 444 | } |
---|
[6501] | 445 | |
---|
| 446 | |
---|
| 447 | /** |
---|
[7919] | 448 | * loads the GUI data |
---|
| 449 | * @param root reference to the xml root element |
---|
| 450 | */ |
---|
[8673] | 451 | ErrorMessage GameMenuData::loadGUI(const TiXmlElement* root) |
---|
[6502] | 452 | { |
---|
| 453 | /* call underlying function */ |
---|
[8677] | 454 | return GameWorldData::loadGUI(root); |
---|
[6502] | 455 | } |
---|
[6501] | 456 | |
---|
| 457 | |
---|
| 458 | /** |
---|
[7919] | 459 | * unloads the GUI data |
---|
| 460 | */ |
---|
[8673] | 461 | ErrorMessage GameMenuData::unloadGUI() |
---|
[6502] | 462 | { |
---|
| 463 | /* call underlying function */ |
---|
[8677] | 464 | return GameWorldData::unloadGUI(); |
---|
[6502] | 465 | } |
---|
| 466 | |
---|
| 467 | |
---|
| 468 | /** |
---|
[7919] | 469 | * overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff) |
---|
| 470 | * @param root reference to the xml root parameter |
---|
| 471 | */ |
---|
[8673] | 472 | ErrorMessage GameMenuData::loadWorldEntities(const TiXmlElement* root) |
---|
[6502] | 473 | { |
---|
[8677] | 474 | return GameWorldData::loadWorldEntities(root); |
---|
[6502] | 475 | } |
---|
| 476 | |
---|
| 477 | |
---|
| 478 | /** |
---|
[7919] | 479 | * unloads the world entities from the xml file |
---|
| 480 | */ |
---|
[8673] | 481 | ErrorMessage GameMenuData::unloadWorldEntities() |
---|
[6502] | 482 | { |
---|
| 483 | /* call underlying function */ |
---|
[8677] | 484 | return GameWorldData::unloadWorldEntities(); |
---|
[6502] | 485 | } |
---|
| 486 | |
---|
| 487 | |
---|
| 488 | /** |
---|
[7919] | 489 | * loads the scene data |
---|
| 490 | * @param root reference to the xml root element |
---|
| 491 | */ |
---|
[8673] | 492 | ErrorMessage GameMenuData::loadScene(const TiXmlElement* root) |
---|
[6502] | 493 | { |
---|
| 494 | /* call underlying function */ |
---|
[8677] | 495 | return GameWorldData::loadScene(root); |
---|
[6502] | 496 | } |
---|
| 497 | |
---|
| 498 | |
---|
| 499 | /** |
---|
[7919] | 500 | * unloads the scene data |
---|
| 501 | */ |
---|
[8673] | 502 | ErrorMessage GameMenuData::unloadScene() |
---|
[6502] | 503 | { |
---|
| 504 | /* call underlying function */ |
---|
[8677] | 505 | return GameWorldData::unloadScene(); |
---|
[6502] | 506 | } |
---|
| 507 | |
---|
[9059] | 508 | /** |
---|
| 509 | * show controls to join network game |
---|
| 510 | */ |
---|
| 511 | void GameMenu::showClientMenu( ) |
---|
| 512 | { |
---|
| 513 | if ( this->serverNetworkBox ) |
---|
| 514 | { |
---|
[9110] | 515 | this->networkBox->unpack( this->serverNetworkBox ); |
---|
| 516 | this->serverNetworkBox->hideAll(); |
---|
| 517 | //delete this->serverNetworkBox; |
---|
| 518 | //this->serverNetworkBox = NULL; |
---|
[9059] | 519 | } |
---|
[9235] | 520 | |
---|
[9059] | 521 | if ( !this->clientNetworkBox ) |
---|
| 522 | { |
---|
| 523 | this->clientNetworkBox = new OrxGui::GLGuiBox(); |
---|
| 524 | { |
---|
| 525 | OrxGui::GLGuiText * text = new OrxGui::GLGuiText(); |
---|
| 526 | text->setText( "Host:" ); |
---|
| 527 | this->clientNetworkBox->pack( text ); |
---|
[9235] | 528 | |
---|
[9059] | 529 | this->ipInputLine = new OrxGui::GLGuiInputLine( ); |
---|
[9235] | 530 | this->ipInputLine->setText( Preferences::getInstance()->getString( "multiplayer", "lastVisitedServer", "localhost" ) ); |
---|
[9059] | 531 | this->clientNetworkBox->pack( this->ipInputLine ); |
---|
[9406] | 532 | //this->ipInputLine->enterPushed.connect(this, &GameMenu::connectToServer); /// redo this. |
---|
[9059] | 533 | this->ipInputLine->select(); |
---|
[9235] | 534 | |
---|
[9059] | 535 | OrxGui::GLGuiButton* connectButton = new OrxGui::GLGuiPushButton("Connect"); |
---|
| 536 | clientNetworkBox->pack(connectButton); |
---|
[9406] | 537 | connectButton->released.connect(this, &GameMenu::connectToServer); |
---|
[9059] | 538 | } |
---|
| 539 | } |
---|
[9235] | 540 | |
---|
[9110] | 541 | this->networkBox->pack( this->clientNetworkBox ); |
---|
[9235] | 542 | |
---|
[9059] | 543 | this->clientNetworkBox->showAll(); |
---|
[9235] | 544 | |
---|
[9110] | 545 | //this->clientNetworkBox->setAbsCoor2D( 300.0f, 100.0f ); |
---|
[9059] | 546 | } |
---|
[6502] | 547 | |
---|
[9059] | 548 | /** |
---|
| 549 | * show controls to create new network game |
---|
| 550 | */ |
---|
| 551 | void GameMenu::showServerMenu( ) |
---|
| 552 | { |
---|
| 553 | if ( this->clientNetworkBox ) |
---|
| 554 | { |
---|
[9110] | 555 | this->networkBox->unpack( this->clientNetworkBox ); |
---|
| 556 | this->clientNetworkBox->hideAll(); |
---|
| 557 | //delete this->clientNetworkBox; |
---|
| 558 | //this->clientNetworkBox = NULL; |
---|
[9059] | 559 | } |
---|
[9235] | 560 | |
---|
[9059] | 561 | if ( !this->serverNetworkBox ) |
---|
| 562 | { |
---|
| 563 | this->serverNetworkBox = new OrxGui::GLGuiBox(); |
---|
| 564 | { |
---|
| 565 | OrxGui::GLGuiText * text = new OrxGui::GLGuiText(); |
---|
| 566 | text->setText( "Map:" ); |
---|
| 567 | this->serverNetworkBox->pack( text ); |
---|
[9235] | 568 | |
---|
[9059] | 569 | OrxGui::GLGuiText * text2 = new OrxGui::GLGuiText(); |
---|
| 570 | text2->setText( "Multiplayer TeamDeathMatch Arena" ); |
---|
| 571 | this->serverNetworkBox->pack( text2 ); |
---|
[9235] | 572 | |
---|
[9059] | 573 | OrxGui::GLGuiButton* createButton = new OrxGui::GLGuiPushButton("Create Server"); |
---|
| 574 | serverNetworkBox->pack(createButton); |
---|
[9406] | 575 | createButton->released.connect(this, &GameMenu::createMasterServer); |
---|
[9059] | 576 | } |
---|
| 577 | } |
---|
[9235] | 578 | |
---|
[9110] | 579 | this->networkBox->pack( this->serverNetworkBox ); |
---|
[9235] | 580 | |
---|
[9059] | 581 | this->serverNetworkBox->showAll(); |
---|
[9235] | 582 | |
---|
[9110] | 583 | //this->serverNetworkBox->setAbsCoor2D( 300.0f, 100.0f ); |
---|
[9059] | 584 | } |
---|
[6502] | 585 | |
---|
[9059] | 586 | /** |
---|
| 587 | * connect to host |
---|
| 588 | */ |
---|
| 589 | void GameMenu::connectToServer( ) |
---|
| 590 | { |
---|
| 591 | PRINTF(0)("Connecting to %s\n", this->ipInputLine->_getText().c_str() ); |
---|
[9235] | 592 | |
---|
[9059] | 593 | State::setOnline(true); |
---|
[9406] | 594 | NetworkManager::getInstance()->createClient( this->ipInputLine->_getText(), 9999 ); |
---|
[9235] | 595 | |
---|
| 596 | Preferences::getInstance()->setString( "multiplayer", "lastVisitedServer", this->ipInputLine->_getText() ); |
---|
| 597 | |
---|
[9059] | 598 | this->startLevel( 5 ); |
---|
| 599 | } |
---|
| 600 | |
---|
[9406] | 601 | void GameMenu::createMasterServer( ) |
---|
[9059] | 602 | { |
---|
| 603 | PRINTF(0)("Create server\n" ); |
---|
[9235] | 604 | |
---|
[9059] | 605 | State::setOnline(true); |
---|
[9406] | 606 | NetworkManager::getInstance()->createMasterServer( 9999 ); |
---|
[9235] | 607 | |
---|
[9059] | 608 | this->startLevel( 5 ); |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | |
---|
| 612 | |
---|