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