Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/story_entities/simple_game_menu.cc @ 6762

Last change on this file since 6762 was 6696, checked in by patrick, 19 years ago

trunk: works again

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