Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/story_entities/game_menu.cc @ 8688

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

added image-button a speciality of glgui to display buttons, that on push show a new Image inside a ImageWidget

File size: 9.9 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 "gui/gl/specials/glgui_notifier.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
55  OrxGui::GLGuiHandler::getInstance()->activateCursor();
56  OrxGui::GLGuiHandler::getInstance()->activate();
57  OrxGui::GLGuiHandler::getInstance()->cursor()->loadTextureSequence(ResourceManager::getInstance()->getDataDir() + "/" + "maps/reap_mouse/reap_mouse_##.png", 1, 49);
58
59  if (root != NULL)
60    this->loadParams(root);
61
62  State::setMenuID(this->getNextStoryID());
63}
64
65/**
66*  @brief remove the GameMenu from memory
67*
68*  delete everything explicitly, that isn't contained in the parenting tree!
69*  things contained in the tree are deleted automaticaly
70*/
71GameMenu::~GameMenu ()
72{
73  PRINTF(3)("GameMenu::~GameMenu() - deleting current world\n");
74
75  if( this->dataTank)
76    delete this->dataTank;
77  delete OrxGui::GLGuiHandler::getInstance( );
78}
79
80
81/**
82* @brief loads the parameters of a GameMenu from an XML-element
83* @param root the XML-element to load from
84*/
85void GameMenu::loadParams(const TiXmlElement* root)
86{
87  /* skip the GameWorld, since it does not define any useful loadParams for this class */
88  //static_cast<GameWorld*>(this)->loadParams(root);
89  GameWorld::loadParams(root);
90
91  PRINTF(4)("Loaded GameMenu specific stuff\n");
92}
93
94
95/**
96* @brief this is executed just before load
97*
98* since the load function sometimes needs data, that has been initialized
99* before the load and after the proceeding storyentity has finished
100*/
101ErrorMessage GameMenu::init()
102{
103  /* call underlying init funciton */
104  GameWorld::init();
105
106  this->subscribeEvent(ES_MENU, SDLK_UP);
107  this->subscribeEvent(ES_MENU, SDLK_DOWN);
108  this->subscribeEvent(ES_MENU, SDLK_RETURN);
109  this->subscribeEvent(ES_MENU, SDLK_SPACE);
110  this->subscribeEvent(ES_MENU, SDLK_ESCAPE);
111
112  this->dataTank->localCamera->setRelCoor(this->cameraVector);
113
114  GraphicsEngine::getInstance()->displayFPS(false);
115
116  return ErrorMessage();
117}
118
119
120/**
121* @brief load the data
122*/
123ErrorMessage GameMenu::loadData()
124{
125  this->mainMenuBox = NULL;
126
127  this->levelsBox = NULL;
128  this->networkBox = 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();
178    {
179      const std::list<BaseObject*>* storyEntities = ClassList::getList(CL_STORY_ENTITY);
180      std::list<BaseObject*>::const_iterator it;
181      for( it = storyEntities->begin(); it != storyEntities->end(); it++)
182      {
183        StoryEntity* se = dynamic_cast<StoryEntity*>(*it);
184        if( se->isContainedInMenu())
185        {
186          OrxGui::GLGuiWidget* button = new OrxGui::GLGuiPushButton(se->getName());
187          levelsBox->pack(button);
188
189          // generating screenshoot item
190          /*
191          ImageEntity* ie = new ImageEntity();
192          ie->setVisibility(false);
193          ie->setBindNode((const PNode*)NULL);
194          ie->setTexture(se->getMenuScreenshoot());
195          ie->setRelCoor2D(State::getResX() / 2.0f + 250.0f, State::getResY() / 2.0f);
196          ie->setSize2D(140.0f, 105.0f);
197          this->menuLayers[1].screenshootList.push_back(ie);
198          */
199        }
200      }
201    }
202  }
203
204  this->showSecondLevelElement(this->levelsBox);
205
206}
207
208void GameMenu::showMultiPlayer()
209{}
210
211void GameMenu::showOptionsMenu()
212{
213  if (this->optionsBox == NULL)
214  {
215    this->optionsBox = new OrxGui::GLGuiBox();
216    {
217      OrxGui::GLGuiButton* generalButton = new OrxGui::GLGuiPushButton("General");
218      optionsBox->pack(generalButton);
219
220      OrxGui::GLGuiButton* audioButton = new OrxGui::GLGuiPushButton("Audio");
221      optionsBox->pack(audioButton);
222
223      OrxGui::GLGuiButton* videoButton = new OrxGui::GLGuiPushButton("Video");
224      optionsBox->pack(videoButton);
225
226      OrxGui::GLGuiButton* controlButton = new OrxGui::GLGuiPushButton("Control");
227      optionsBox->pack(controlButton);
228
229
230      //      for (unsigned int i = 0; i <
231      //OrxGui::GLGuiButton*
232
233    }
234  }
235
236  this->showSecondLevelElement(this->optionsBox);
237}
238
239
240void GameMenu::showSecondLevelElement(OrxGui::GLGuiBox* element)
241{
242  if (this->currentlyOpened != NULL && this->currentlyOpened != element)
243    this->currentlyOpened->hideAll();
244
245  element->showAll();
246  element->setRelCoor2D(200, 100);
247
248  this->currentlyOpened = element;
249
250  this->mainMenuBox->setRelCoorSoft2D(50, 100, 5);
251}
252
253
254
255
256
257
258
259/**
260* @brief set the Sound to play when switching menu entry.
261* @param selectorSound the sound to load.
262*/
263void GameMenu::setSelectorSound(const std::string& selectorSound)
264{
265  this->selectorSource = OrxSound::SoundEngine::getInstance()->createSource(selectorSound, NULL);
266}
267
268ErrorMessage GameMenu::unloadData()
269{
270  this->unsubscribeEvents(ES_MENU);
271
272  return GameWorld::unloadData();
273}
274
275
276/**
277* @brief start the menu
278*/
279bool GameMenu::start()
280{
281  EventHandler::getInstance()->pushState(ES_MENU);
282
283  this->showMainMenu();
284
285  /* now call the underlying*/
286  return GameWorld::start();
287}
288
289
290
291/**
292* stop the menu
293*/
294bool GameMenu::stop()
295{
296  EventHandler::getInstance()->popState();
297
298  /* now call the underlying*/
299  return GameWorld::stop();
300}
301
302
303/**
304*  override the standard tick for more functionality
305*/
306void GameMenu::tick()
307{
308  GameWorld::tick();
309
310  // Make the GLGui tick.
311  OrxGui::GLGuiHandler::getInstance()->tick(this->dtS);
312
313  this->animateScene(this->dtS);
314}
315
316
317/**
318* @brief no collision detection in the menu
319*/
320void GameMenu::collide()
321{
322  //   this->dataTank->localCamera->
323}
324
325
326/**
327* @brief animate the scene
328*/
329void GameMenu::animateScene(float dt)
330{
331  Quaternion q(/*0.00005*/ dt * .1, Vector(0.0, 1.0, 0.0));
332  this->cameraVector = q.apply(this->cameraVector);
333  this->dataTank->localCamera->setRelCoor(this->cameraVector);
334  this->dataTank->localCamera->getTarget()->setRelCoorSoft(0,0,0);
335}
336
337void GameMenu::quitMenu()
338{
339  this->setNextStoryID(WORLD_ID_GAMEEND);
340  this->stop();
341}
342
343
344/**
345* @brief event dispatcher funciton
346* @param event the incoming event
347*/
348void GameMenu::process(const Event &event)
349{
350  if( event.type == SDLK_ESCAPE && event.bPressed == true)
351  {
352    this->setNextStoryID(WORLD_ID_GAMEEND);
353    this->stop();
354  }
355
356}
357
358
359
360/**********************************************************************************************
361GameMenuData
362**********************************************************************************************/
363
364
365/**
366* GameMenuData constructor
367*/
368GameMenuData::GameMenuData()
369{}
370
371/**
372* GameMenuData decontructor
373*/
374GameMenuData::~GameMenuData()
375{}
376
377
378/**
379*  initialize the GameWorldDataData
380*/
381ErrorMessage GameMenuData::init()
382{
383  /* call underlying function */
384  return GameWorldData::init();
385}
386
387
388/**
389*  loads the GUI data
390* @param root reference to the xml root element
391*/
392ErrorMessage GameMenuData::loadGUI(const TiXmlElement* root)
393{
394  /* call underlying function */
395  return GameWorldData::loadGUI(root);
396}
397
398
399/**
400*  unloads the GUI data
401*/
402ErrorMessage GameMenuData::unloadGUI()
403{
404  /* call underlying function */
405  return GameWorldData::unloadGUI();
406}
407
408
409/**
410*  overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff)
411* @param root reference to the xml root parameter
412*/
413ErrorMessage GameMenuData::loadWorldEntities(const TiXmlElement* root)
414{
415  return GameWorldData::loadWorldEntities(root);
416}
417
418
419/**
420*  unloads the world entities from the xml file
421*/
422ErrorMessage GameMenuData::unloadWorldEntities()
423{
424  /* call underlying function */
425  return GameWorldData::unloadWorldEntities();
426}
427
428
429/**
430*  loads the scene data
431* @param root reference to the xml root element
432*/
433ErrorMessage GameMenuData::loadScene(const TiXmlElement* root)
434{
435  /* call underlying function */
436  return GameWorldData::loadScene(root);
437}
438
439
440/**
441*  unloads the scene data
442*/
443ErrorMessage GameMenuData::unloadScene()
444{
445  /* call underlying function */
446  return GameWorldData::unloadScene();
447}
448
449
450
Note: See TracBrowser for help on using the repository browser.