Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added game_menu.cc

File size: 6.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 "fast_factory.h"
28#include "util/loading/factory.h"
29#include "loading/resource_manager.h"
30
31#include "world_entity.h"
32#include "elements/image_entity.h"
33#include "terrain.h"
34#include "camera.h"
35
36#include "graphics_engine.h"
37#include "object_manager.h"
38#include "sound_engine.h"
39#include "sound_source.h"
40
41#include "cd_engine.h"
42
43#include "glgui.h"
44#include "gui/gl/specials/glgui_notifier.h"
45
46//! This creates a Factory to fabricate a GameMenu
47CREATE_FACTORY(GameMenu, CL_GAME_MENU);
48
49
50
51GameMenu::GameMenu(const TiXmlElement* root)
52    : GameWorld()
53{
54  this->setClassID(CL_GAME_MENU, "GameMenu");
55  this->setName("GameMenu uninitialized");
56
57  this->dataTank = new GameMenuData();
58
59  this->cameraVector = Vector(50.0, 0.0, 0.0);
60
61
62  OrxGui::GLGuiHandler::getInstance()->activateCursor();
63  OrxGui::GLGuiHandler::getInstance()->activate();
64  OrxGui::GLGuiHandler::getInstance()->cursor()->loadTextureSequence(ResourceManager::getInstance()->getDataDir() + "/" + "maps/reap_mouse/reap_mouse_##.png", 1, 49);
65
66  if (root != NULL)
67    this->loadParams(root);
68
69  State::setMenuID(this->getNextStoryID());
70}
71
72/// HACK only for testing.
73void GameMenu::enterGui()
74{
75}
76
77/**
78*  @brief remove the GameMenu from memory
79*
80*  delete everything explicitly, that isn't contained in the parenting tree!
81*  things contained in the tree are deleted automaticaly
82*/
83GameMenu::~GameMenu ()
84{
85  PRINTF(3)("GameMenu::~GameMenu() - deleting current world\n");
86
87  if( this->dataTank)
88    delete this->dataTank;
89  delete OrxGui::GLGuiHandler::getInstance( );
90}
91
92
93/**
94* @brief loads the parameters of a GameMenu from an XML-element
95* @param root the XML-element to load from
96*/
97void GameMenu::loadParams(const TiXmlElement* root)
98{
99  /* skip the GameWorld, since it does not define any useful loadParams for this class */
100  //static_cast<GameWorld*>(this)->loadParams(root);
101  GameWorld::loadParams(root);
102
103  PRINTF(4)("Loaded GameMenu specific stuff\n");
104}
105
106
107/**
108* @brief this is executed just before load
109*
110* since the load function sometimes needs data, that has been initialized
111* before the load and after the proceeding storyentity has finished
112*/
113ErrorMessage GameMenu::init()
114{
115  /* call underlying init funciton */
116  GameWorld::init();
117
118  this->subscribeEvent(ES_MENU, SDLK_UP);
119  this->subscribeEvent(ES_MENU, SDLK_DOWN);
120  this->subscribeEvent(ES_MENU, SDLK_RETURN);
121  this->subscribeEvent(ES_MENU, SDLK_SPACE);
122  this->subscribeEvent(ES_MENU, SDLK_ESCAPE);
123
124  this->dataTank->localCamera->setRelCoor(this->cameraVector);
125
126  GraphicsEngine::getInstance()->displayFPS(false);
127
128}
129
130
131/**
132* @brief load the data
133*/
134ErrorMessage GameMenu::loadData()
135{
136  GameWorld::loadData();
137}
138
139/**
140* @brief set the Sound to play when switching menu entry.
141* @param selectorSound the sound to load.
142*/
143void GameMenu::setSelectorSound(const std::string& selectorSound)
144{
145  this->selectorSource = OrxSound::SoundEngine::getInstance()->createSource(selectorSound, NULL);
146}
147
148ErrorMessage GameMenu::unloadData()
149{
150  this->unsubscribeEvents(ES_MENU);
151
152  GameWorld::unloadData();
153}
154
155
156/**
157* @brief start the menu
158*/
159bool GameMenu::start()
160{
161  EventHandler::getInstance()->pushState(ES_MENU);
162
163  /* now call the underlying*/
164  GameWorld::start();
165}
166
167
168
169/**
170* stop the menu
171*/
172bool GameMenu::stop()
173{
174  EventHandler::getInstance()->popState();
175
176  /* now call the underlying*/
177  GameWorld::stop();
178}
179
180
181/**
182*  override the standard tick for more functionality
183*/
184void GameMenu::tick()
185{
186  GameWorld::tick();
187
188  // Make the GLGui tick.
189  OrxGui::GLGuiHandler::getInstance()->tick(this->dtS);
190
191  this->animateScene(this->dtS);
192}
193
194
195/**
196* @brief no collision detection in the menu
197*/
198void GameMenu::collide()
199{
200  //   this->dataTank->localCamera->
201}
202
203
204/**
205* @brief animate the scene
206*/
207void GameMenu::animateScene(float dt)
208{
209  Quaternion q(/*0.00005*/ dt * .1, Vector(0.0, 1.0, 0.0));
210  this->cameraVector = q.apply(this->cameraVector);
211  this->dataTank->localCamera->setRelCoor(this->cameraVector);
212  this->dataTank->localCamera->getTarget()->setRelCoorSoft(0,0,0);
213}
214
215void GameMenu::quitMenu()
216{
217  this->setNextStoryID(WORLD_ID_GAMEEND);
218  this->stop();
219}
220
221
222/**
223* @brief event dispatcher funciton
224* @param event the incoming event
225*/
226void GameMenu::process(const Event &event)
227{
228}
229
230
231
232/**********************************************************************************************
233GameMenuData
234**********************************************************************************************/
235
236
237/**
238* GameMenuData constructor
239*/
240GameMenuData::GameMenuData()
241{}
242
243/**
244* GameMenuData decontructor
245*/
246GameMenuData::~GameMenuData()
247{}
248
249
250/**
251*  initialize the GameWorldDataData
252*/
253ErrorMessage GameMenuData::init()
254{
255  /* call underlying function */
256  GameWorldData::init();
257}
258
259
260/**
261*  loads the GUI data
262* @param root reference to the xml root element
263*/
264ErrorMessage GameMenuData::loadGUI(const TiXmlElement* root)
265{
266  /* call underlying function */
267  GameWorldData::loadGUI(root);
268}
269
270
271/**
272*  unloads the GUI data
273*/
274ErrorMessage GameMenuData::unloadGUI()
275{
276  /* call underlying function */
277  GameWorldData::unloadGUI();
278}
279
280
281/**
282*  overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff)
283* @param root reference to the xml root parameter
284*/
285ErrorMessage GameMenuData::loadWorldEntities(const TiXmlElement* root)
286{
287  GameWorldData::loadWorldEntities(root);
288}
289
290
291/**
292*  unloads the world entities from the xml file
293*/
294ErrorMessage GameMenuData::unloadWorldEntities()
295{
296  /* call underlying function */
297  GameWorldData::unloadWorldEntities();
298}
299
300
301/**
302*  loads the scene data
303* @param root reference to the xml root element
304*/
305ErrorMessage GameMenuData::loadScene(const TiXmlElement* root)
306{
307  /* call underlying function */
308  GameWorldData::loadScene(root);
309}
310
311
312/**
313*  unloads the scene data
314*/
315ErrorMessage GameMenuData::unloadScene()
316{
317  /* call underlying function */
318  GameWorldData::unloadScene();
319}
320
321
322
Note: See TracBrowser for help on using the repository browser.