Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: more submenu structure

File size: 9.5 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  this->layerIndex = 0;
59
60  this->loadParams(root);
61}
62
63
64/**
65 *  remove the SimpleGameMenu from memory
66 *
67 *  delete everything explicitly, that isn't contained in the parenting tree!
68 *  things contained in the tree are deleted automaticaly
69 */
70SimpleGameMenu::~SimpleGameMenu ()
71{
72  PRINTF(3)("SimpleGameMenu::~SimpleGameMenu() - deleting current world\n");
73
74  if( this->dataTank)
75    delete this->dataTank;
76}
77
78
79/**
80 * loads the parameters of a SimpleGameMenu from an XML-element
81 * @param root the XML-element to load from
82 */
83void SimpleGameMenu::loadParams(const TiXmlElement* root)
84{
85  /* skip the GameWorld, since it does not define any useful loadParams for this class */
86  //static_cast<GameWorld*>(this)->loadParams(root);
87  GameWorld::loadParams(root);
88
89  PRINTF(4)("Loaded SimpleGameMenu specific stuff\n");
90}
91
92
93/**
94 * this is executed just before load
95 *
96 * since the load function sometimes needs data, that has been initialized
97 * before the load and after the proceeding storyentity has finished
98 */
99ErrorMessage SimpleGameMenu::init()
100{
101  /* call underlying init funciton */
102  GameWorld::init();
103
104  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_UP);
105  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_DOWN);
106  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_RETURN);
107  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_SPACE);
108
109  this->dataTank->localCamera->setRelCoor(this->cameraVector);
110
111  GraphicsEngine::getInstance()->displayFPS(false);
112}
113
114
115/**
116 * load the data
117 */
118ErrorMessage SimpleGameMenu::loadData()
119{
120  GameWorld::loadData();
121
122  /* get the menu list */
123  const std::list<BaseObject*>* imageEntityList = ClassList::getList(CL_IMAGE_ENTITY);
124  std::list<BaseObject*>::const_iterator entity;
125  for (entity = imageEntityList->begin(); entity != imageEntityList->end(); entity++)
126  {
127
128    if( !strcmp("Selector_Menu", (*entity)->getName()))
129    {
130      this->menuSelector = dynamic_cast<ImageEntity*>(*entity);
131    }
132    else if( !strcmp( "StartGame_Menu", (*entity)->getName()))
133    {
134      this->menuStartGame = dynamic_cast<ImageEntity*>(*entity);
135      this->menuLayer[0]->menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
136
137    }
138    else if( !strcmp( "Multiplayer_Menu", (*entity)->getName()))
139    {
140      this->menuStartMultiplayerGame = dynamic_cast<ImageEntity*>(*entity);
141      this->menuLayer[0]->menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
142    }
143    else if( !strcmp( "Quit_Menu", (*entity)->getName()))
144    {
145      this->menuQuitGame = dynamic_cast<ImageEntity*>(*entity);
146      this->menuLayer[0]->menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
147    }
148  }
149  this->menuSelectedIndex = 0;
150  this->menuSelected = this->menuLayer[0]->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( this->layerIndex == 0)
220  {
221    if( event.type == SDLK_RETURN && event.bPressed == true)
222    {
223      if( this->menuSelected == this->menuQuitGame)
224      {
225        this->setNextStoryID(WORLD_ID_GAMEEND);
226        this->stop();
227      }
228      if( this->menuSelected == this->menuStartGame)
229      {
230        //this->stop();
231        // switch to first submenu
232        if( this->menuLayer[1] == NULL)
233        {
234          PRINTF(1)("Haven't got any Story Entities to play!\n");
235          return;
236        }
237
238        this->switchMenuLayer(this->layerIndex, 1);
239
240      }
241    }
242    else if( event.type == SDLK_DOWN && event.bPressed == true)
243    {
244//     ImageEntity*
245      if(this->menuSelectedIndex < (this->menuLayer[this->layerIndex]->menuList.size() - 1))
246      {
247        this->menuSelected = this->menuLayer[this->layerIndex]->menuList[++this->menuSelectedIndex];
248        this->menuSelector->setAbsCoor(this->menuSelected->getAbsCoor());
249      }
250    }
251    else if( event.type == SDLK_UP && event.bPressed == true)
252    {
253      if(this->menuSelectedIndex > 0)
254      {
255        this->menuSelected = this->menuLayer[this->layerIndex]->menuList[--this->menuSelectedIndex];
256        this->menuSelector->setAbsCoor(this->menuSelected->getAbsCoor());
257      }
258    }
259  }
260  else if( this->layerIndex == 1)
261  {
262
263  }
264}
265
266
267/**
268 *  switches to from one meny layer to an other
269 * @param layer1 from layer
270 * @param layer2 to layer
271 */
272void SimpleGameMenu::switchMenuLayer(int layer1, int layer2)
273{
274  // wrong sizes
275  if(layer1 >= this->menuLayer.size() || layer2 >= this->menuLayer.size())
276    return;
277
278
279  PRINTF(0)("Removing layer %i\n", layer1);
280  std::vector<ImageEntity*>::iterator it;
281  // fade old menu
282  for( it = this->menuLayer[layer1]->menuList.begin(); it != this->menuLayer[layer1]->menuList.end(); it++ )
283  {
284    (*it)->setAbsCoor(Vector(-100, -100, -100));
285  }
286
287
288  PRINTF(0)("Showing layer %i\n", layer1);
289  // beam here the new menu
290  for( it = this->menuLayer[layer2]->menuList.begin(); it != this->menuLayer[layer2]->menuList.end(); it++ )
291  {}
292
293  this->layerIndex = layer2;
294}
295
296
297
298
299/**********************************************************************************************
300    SimpleGameMenuData
301 **********************************************************************************************/
302
303
304/**
305 * SimpleGameMenuData constructor
306 */
307SimpleGameMenuData::SimpleGameMenuData()
308{}
309
310/**
311 * SimpleGameMenuData decontructor
312 */
313SimpleGameMenuData::~SimpleGameMenuData()
314{}
315
316
317/**
318 *  initialize the GameWorldDataData
319 */
320ErrorMessage SimpleGameMenuData::init()
321{
322  /* call underlying function */
323  GameWorldData::init();
324}
325
326
327/**
328 *  loads the GUI data
329 * @param root reference to the xml root element
330 */
331ErrorMessage SimpleGameMenuData::loadGUI(TiXmlElement* root)
332{
333  /* call underlying function */
334  GameWorldData::loadGUI(root);
335}
336
337
338/**
339 *  unloads the GUI data
340 */
341ErrorMessage SimpleGameMenuData::unloadGUI()
342{
343  /* call underlying function */
344  GameWorldData::unloadGUI();
345}
346
347
348/**
349 *  overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff)
350 * @param root reference to the xml root parameter
351 */
352ErrorMessage SimpleGameMenuData::loadWorldEntities(TiXmlElement* root)
353{
354  TiXmlElement* element = root->FirstChildElement("WorldEntities");
355
356  if( element != NULL)
357  {
358    element = element->FirstChildElement();
359    PRINTF(4)("Loading WorldEntities\n");
360    while( element != NULL)
361    {
362      BaseObject* created = Factory::fabricate(element);
363      if( created != NULL )
364        printf("Created a %s: %s\n", created->getClassName(), created->getName());
365
366      if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
367        this->sky = dynamic_cast<WorldEntity*>(created);
368      if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
369        this->terrain = dynamic_cast<Terrain*>(created);
370      element = element->NextSiblingElement();
371    }
372    PRINTF(4)("Done loading WorldEntities\n");
373  }
374
375  /* init the pnode tree */
376  PNode::getNullParent()->init();
377}
378
379
380/**
381 *  unloads the world entities from the xml file
382 */
383ErrorMessage SimpleGameMenuData::unloadWorldEntities()
384{
385  /* call underlying function */
386  GameWorldData::unloadWorldEntities();
387}
388
389
390/**
391 *  loads the scene data
392 * @param root reference to the xml root element
393 */
394ErrorMessage SimpleGameMenuData::loadScene(TiXmlElement* root)
395{
396  /* call underlying function */
397  GameWorldData::loadScene(root);
398}
399
400
401/**
402 *  unloads the scene data
403 */
404ErrorMessage SimpleGameMenuData::unloadScene()
405{
406  /* call underlying function */
407  GameWorldData::unloadScene();
408}
409
410
411
Note: See TracBrowser for help on using the repository browser.