Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/story_entities/simple_game_menu.cc @ 6835

Last change on this file since 6835 was 6835, checked in by patrick, 18 years ago

trunk: resturcture of the game menu for multi-level menus

File size: 8.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 "simple_game_menu.h"
20
21#include "state.h"
22#include "class_list.h"
23
24#include "load_param.h"
25#include "fast_factory.h"
26#include "factory.h"
27
28#include "p_node.h"
29#include "world_entity.h"
30#include "image_entity.h"
31#include "terrain.h"
32#include "camera.h"
33
34#include "event_handler.h"
35#include "graphics_engine.h"
36
37#include "cd_engine.h"
38
39
40using namespace std;
41
42
43//! This creates a Factory to fabricate a SimpleGameMenu
44CREATE_FACTORY(SimpleGameMenu, CL_SIMPLE_GAME_MENU);
45
46
47
48SimpleGameMenu::SimpleGameMenu(const TiXmlElement* root)
49  : GameWorld(root)
50{
51  this->setClassID(CL_SIMPLE_GAME_MENU, "SimpleGameMenu");
52  this->setName("SimpleGameMenu uninitialized");
53
54  this->dataTank = new SimpleGameMenuData();
55
56  this->cameraVector = Vector(50.0, 0.0, 0.0);
57  this->menuLayer.push_back(new MenuLayer());
58
59  this->loadParams(root);
60}
61
62
63/**
64 *  remove the SimpleGameMenu from memory
65 *
66 *  delete everything explicitly, that isn't contained in the parenting tree!
67 *  things contained in the tree are deleted automaticaly
68 */
69SimpleGameMenu::~SimpleGameMenu ()
70{
71  PRINTF(3)("SimpleGameMenu::~SimpleGameMenu() - deleting current world\n");
72
73  if( this->dataTank)
74    delete this->dataTank;
75}
76
77
78/**
79 * loads the parameters of a SimpleGameMenu from an XML-element
80 * @param root the XML-element to load from
81 */
82void SimpleGameMenu::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 SimpleGameMenu specific stuff\n");
89}
90
91
92/**
93 * 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 SimpleGameMenu::init()
99{
100  /* call underlying init funciton */
101  GameWorld::init();
102
103  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_UP);
104  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_DOWN);
105  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_RETURN);
106  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_SPACE);
107
108  this->dataTank->localCamera->setRelCoor(this->cameraVector);
109
110  GraphicsEngine::getInstance()->displayFPS(false);
111}
112
113
114/**
115 * load the data
116 */
117ErrorMessage SimpleGameMenu::loadData()
118{
119  GameWorld::loadData();
120
121  /* get the menu list */
122  const std::list<BaseObject*>* imageEntityList = ClassList::getList(CL_IMAGE_ENTITY);
123  std::list<BaseObject*>::const_iterator entity;
124  for (entity = imageEntityList->begin(); entity != imageEntityList->end(); entity++)
125  {
126
127    if( !strcmp("Selector_Menu", (*entity)->getName()))
128    {
129      this->menuSelector = dynamic_cast<ImageEntity*>(*entity);
130    }
131    else if( !strcmp( "StartGame_Menu", (*entity)->getName()))
132    {
133      this->menuStartGame = dynamic_cast<ImageEntity*>(*entity);
134      this->menuLayer[0]->menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
135
136    }
137    else if( !strcmp( "Multiplayer_Menu", (*entity)->getName()))
138    {
139      this->menuStartMultiplayerGame = dynamic_cast<ImageEntity*>(*entity);
140      this->menuLayer[0]->menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
141    }
142    else if( !strcmp( "Quit_Menu", (*entity)->getName()))
143    {
144      this->menuQuitGame = dynamic_cast<ImageEntity*>(*entity);
145      this->menuLayer[0]->menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
146    }
147  }
148  this->menuSelectedIndex = 0;
149  this->menuSelected = this->menuLayer[0]->menuList[this->menuSelectedIndex];
150  this->menuSelector->setAbsCoor(this->menuSelected->getAbsCoor());
151}
152
153
154
155/**
156 * start the menu
157 */
158bool SimpleGameMenu::start()
159{
160  EventHandler::getInstance()->pushState(ES_MENU);
161
162  /* now call the underlying*/
163  GameWorld::start();
164}
165
166
167
168/**
169 * stop the menu
170 */
171bool SimpleGameMenu::stop()
172{
173  EventHandler::getInstance()->popState();
174
175  /* now call the underlying*/
176  GameWorld::stop();
177}
178
179
180/**
181 *  override the standard tick for more functionality
182 */
183void SimpleGameMenu::tick()
184{
185  GameWorld::tick();
186
187  this->animateScene(this->dt);
188}
189
190
191/**
192 *  no collision detection in the menu
193 */
194void SimpleGameMenu::collide()
195{
196//   this->dataTank->localCamera->
197}
198
199
200/**
201 *  animate the scene
202 */
203void SimpleGameMenu::animateScene(float dt)
204{
205  Quaternion q(/*0.00005*/ 0.0001* dt, Vector(0.0, 1.0, 0.0));
206  this->cameraVector = q.apply(this->cameraVector);
207  this->dataTank->localCamera->setRelCoor(this->cameraVector);
208  this->dataTank->localCamera->getTarget()->setRelCoorSoft(0,0,0);
209}
210
211
212/**
213 * event dispatcher funciton
214 * @param event the incoming event
215 */
216void SimpleGameMenu::process(const Event &event)
217{
218  if( event.type == SDLK_RETURN)
219  {
220    if( this->menuSelected == this->menuQuitGame)
221    {
222      this->setNextStoryID(WORLD_ID_GAMEEND);
223      this->stop();
224    }
225    if( this->menuSelected == this->menuStartGame)
226    {
227      this->stop();
228    }
229  }
230  else if( event.type == SDLK_DOWN && event.bPressed == true)
231  {
232//     ImageEntity*
233    if(this->menuSelectedIndex < (this->menuLayer[0]->menuList.size() - 1))
234    {
235      this->menuSelected = this->menuLayer[0]->menuList[++this->menuSelectedIndex];
236      this->menuSelector->setAbsCoor(this->menuSelected->getAbsCoor());
237    }
238  }
239  else if( event.type == SDLK_UP && event.bPressed == true)
240  {
241    if(this->menuSelectedIndex > 0)
242    {
243      this->menuSelected = this->menuLayer[0]->menuList[--this->menuSelectedIndex];
244      this->menuSelector->setAbsCoor(this->menuSelected->getAbsCoor());
245    }
246  }
247}
248
249
250
251
252
253
254/**********************************************************************************************
255    SimpleGameMenuData
256 **********************************************************************************************/
257
258
259/**
260 * SimpleGameMenuData constructor
261 */
262SimpleGameMenuData::SimpleGameMenuData()
263{}
264
265/**
266 * SimpleGameMenuData decontructor
267 */
268SimpleGameMenuData::~SimpleGameMenuData()
269{}
270
271
272/**
273 *  initialize the GameWorldDataData
274 */
275ErrorMessage SimpleGameMenuData::init()
276{
277  /* call underlying function */
278  GameWorldData::init();
279}
280
281
282/**
283 *  loads the GUI data
284 * @param root reference to the xml root element
285 */
286ErrorMessage SimpleGameMenuData::loadGUI(TiXmlElement* root)
287{
288  /* call underlying function */
289  GameWorldData::loadGUI(root);
290}
291
292
293/**
294 *  unloads the GUI data
295 */
296ErrorMessage SimpleGameMenuData::unloadGUI()
297{
298  /* call underlying function */
299  GameWorldData::unloadGUI();
300}
301
302
303/**
304 *  overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff)
305 * @param root reference to the xml root parameter
306 */
307ErrorMessage SimpleGameMenuData::loadWorldEntities(TiXmlElement* root)
308{
309  TiXmlElement* element = root->FirstChildElement("WorldEntities");
310
311  if( element != NULL)
312  {
313    element = element->FirstChildElement();
314    PRINTF(4)("Loading WorldEntities\n");
315    while( element != NULL)
316    {
317      BaseObject* created = Factory::fabricate(element);
318      if( created != NULL )
319        printf("Created a %s: %s\n", created->getClassName(), created->getName());
320
321      if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
322        this->sky = dynamic_cast<WorldEntity*>(created);
323      if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
324        this->terrain = dynamic_cast<Terrain*>(created);
325      element = element->NextSiblingElement();
326    }
327    PRINTF(4)("Done loading WorldEntities\n");
328  }
329
330  /* init the pnode tree */
331  PNode::getNullParent()->init();
332}
333
334
335/**
336 *  unloads the world entities from the xml file
337 */
338ErrorMessage SimpleGameMenuData::unloadWorldEntities()
339{
340  /* call underlying function */
341  GameWorldData::unloadWorldEntities();
342}
343
344
345/**
346 *  loads the scene data
347 * @param root reference to the xml root element
348 */
349ErrorMessage SimpleGameMenuData::loadScene(TiXmlElement* root)
350{
351  /* call underlying function */
352  GameWorldData::loadScene(root);
353}
354
355
356/**
357 *  unloads the scene data
358 */
359ErrorMessage SimpleGameMenuData::unloadScene()
360{
361  /* call underlying function */
362  GameWorldData::unloadScene();
363}
364
365
366
Note: See TracBrowser for help on using the repository browser.