Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/story_entities/menu/game_menu.cc @ 9161

Last change on this file since 9161 was 9110, checked in by bensch, 18 years ago

orxonox/trunk: merged the Presentation back

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