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