Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6685 was 6634, checked in by bensch, 19 years ago

orxonox/trunk: merged the network-branche back to the trunk

merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r6500:HEAD
minor conflicts in texture and one Makefile resolved to the trunk

also made a small patch to texture, so it Modulates with GL_REPEAT

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