Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9040 was 9015, checked in by bensch, 19 years ago

orxonox/trunk: text-field

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