Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/multi_player_map/src/story_entities/menu/game_menu.cc @ 9029

Last change on this file since 9029 was 9029, checked in by rennerc, 18 years ago

implemented network game menu

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