Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/story_entities/simple_game_menu.cc @ 6521

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

network: the background of the menu is now rotating (or the other way around :D )

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