Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: submenu loading work, graphics chaos

File size: 10.4 KB
RevLine 
[6501]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
[6502]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
[6521]28#include "p_node.h"
[6502]29#include "world_entity.h"
[6520]30#include "image_entity.h"
[6502]31#include "terrain.h"
[6521]32#include "camera.h"
[6502]33
[6504]34#include "event_handler.h"
[6524]35#include "graphics_engine.h"
[6841]36#include "object_manager.h"
[6504]37
[6841]38
[6502]39#include "cd_engine.h"
40
41
[6501]42using namespace std;
43
44
[6502]45//! This creates a Factory to fabricate a SimpleGameMenu
46CREATE_FACTORY(SimpleGameMenu, CL_SIMPLE_GAME_MENU);
47
48
49
50SimpleGameMenu::SimpleGameMenu(const TiXmlElement* root)
51  : GameWorld(root)
52{
53  this->setClassID(CL_SIMPLE_GAME_MENU, "SimpleGameMenu");
54  this->setName("SimpleGameMenu uninitialized");
55
56  this->dataTank = new SimpleGameMenuData();
57
[6521]58  this->cameraVector = Vector(50.0, 0.0, 0.0);
[6835]59  this->menuLayer.push_back(new MenuLayer());
[6839]60  this->menuLayer.push_back(new MenuLayer());
[6837]61  this->layerIndex = 0;
[6521]62
[6502]63  this->loadParams(root);
64}
65
66
[6501]67/**
[6502]68 *  remove the SimpleGameMenu from memory
69 *
70 *  delete everything explicitly, that isn't contained in the parenting tree!
71 *  things contained in the tree are deleted automaticaly
[6501]72 */
[6502]73SimpleGameMenu::~SimpleGameMenu ()
74{
75  PRINTF(3)("SimpleGameMenu::~SimpleGameMenu() - deleting current world\n");
[6501]76
[6502]77  if( this->dataTank)
78    delete this->dataTank;
79}
[6501]80
[6502]81
82/**
83 * loads the parameters of a SimpleGameMenu from an XML-element
84 * @param root the XML-element to load from
[6501]85 */
[6502]86void SimpleGameMenu::loadParams(const TiXmlElement* root)
87{
88  /* skip the GameWorld, since it does not define any useful loadParams for this class */
[6696]89  //static_cast<GameWorld*>(this)->loadParams(root);
90  GameWorld::loadParams(root);
[6501]91
[6502]92  PRINTF(4)("Loaded SimpleGameMenu specific stuff\n");
93}
[6501]94
[6502]95
[6501]96/**
[6504]97 * this is executed just before load
98 *
99 * since the load function sometimes needs data, that has been initialized
100 * before the load and after the proceeding storyentity has finished
101 */
102ErrorMessage SimpleGameMenu::init()
103{
104  /* call underlying init funciton */
105  GameWorld::init();
106
107  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_UP);
108  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_DOWN);
109  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_RETURN);
110  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_SPACE);
[6521]111
112  this->dataTank->localCamera->setRelCoor(this->cameraVector);
[6524]113
114  GraphicsEngine::getInstance()->displayFPS(false);
[6504]115}
116
117
[6524]118/**
119 * load the data
120 */
[6521]121ErrorMessage SimpleGameMenu::loadData()
[6504]122{
[6521]123  GameWorld::loadData();
[6504]124
[6520]125  /* get the menu list */
126  const std::list<BaseObject*>* imageEntityList = ClassList::getList(CL_IMAGE_ENTITY);
127  std::list<BaseObject*>::const_iterator entity;
128  for (entity = imageEntityList->begin(); entity != imageEntityList->end(); entity++)
129  {
130
131    if( !strcmp("Selector_Menu", (*entity)->getName()))
132    {
133      this->menuSelector = dynamic_cast<ImageEntity*>(*entity);
134    }
135    else if( !strcmp( "StartGame_Menu", (*entity)->getName()))
136    {
137      this->menuStartGame = dynamic_cast<ImageEntity*>(*entity);
[6835]138      this->menuLayer[0]->menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
139
[6520]140    }
141    else if( !strcmp( "Multiplayer_Menu", (*entity)->getName()))
142    {
143      this->menuStartMultiplayerGame = dynamic_cast<ImageEntity*>(*entity);
[6835]144      this->menuLayer[0]->menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
[6520]145    }
146    else if( !strcmp( "Quit_Menu", (*entity)->getName()))
147    {
148      this->menuQuitGame = dynamic_cast<ImageEntity*>(*entity);
[6835]149      this->menuLayer[0]->menuList.push_back(dynamic_cast<ImageEntity*>(*entity));
[6520]150    }
151  }
152  this->menuSelectedIndex = 0;
[6835]153  this->menuSelected = this->menuLayer[0]->menuList[this->menuSelectedIndex];
[6520]154  this->menuSelector->setAbsCoor(this->menuSelected->getAbsCoor());
[6839]155
156
157  // loading the storyentities submenu (singleplayer)
158  const std::list<BaseObject*>* storyEntities = ClassList::getList(CL_STORY_ENTITY);
159  std::list<BaseObject*>::const_iterator it;
160  for( it = storyEntities->begin(); it != storyEntities->end(); it++)
161  {
162    StoryEntity* se = dynamic_cast<StoryEntity*>(*it);
163    if( se->isContainedInMenu())
164    {
165      this->menuLayer[1]->storyList.push_back(se);
166      PRINTF(0)("Got a new menu entry |%s|\n", se->getName());
[6841]167      ImageEntity* ie = new ImageEntity();
168      ie->setAbsCoor(0.0f, this->menuLayer[1]->menuList.size() * -10.0f, 0.0f);
169      //State::getObjectManager()->toList(dynamic_cast<WorldEntity*>(ie), OM_DEAD);
170      //this->menuLayer[1]->menuList.push_back(ie);
[6839]171    }
172  }
[6521]173}
[6520]174
[6521]175
176
[6524]177/**
178 * start the menu
179 */
[6521]180bool SimpleGameMenu::start()
181{
182  EventHandler::getInstance()->pushState(ES_MENU);
183
[6504]184  /* now call the underlying*/
185  GameWorld::start();
186}
187
188
189
[6524]190/**
191 * stop the menu
192 */
[6504]193bool SimpleGameMenu::stop()
194{
195  EventHandler::getInstance()->popState();
196
197  /* now call the underlying*/
198  GameWorld::stop();
199}
200
201
[6521]202/**
203 *  override the standard tick for more functionality
204 */
205void SimpleGameMenu::tick()
206{
207  GameWorld::tick();
[6504]208
[6521]209  this->animateScene(this->dt);
210}
211
212
[6504]213/**
[6521]214 *  no collision detection in the menu
[6501]215 */
[6502]216void SimpleGameMenu::collide()
[6521]217{
218//   this->dataTank->localCamera->
219}
[6501]220
221
[6504]222/**
[6521]223 *  animate the scene
224 */
225void SimpleGameMenu::animateScene(float dt)
226{
[6524]227  Quaternion q(/*0.00005*/ 0.0001* dt, Vector(0.0, 1.0, 0.0));
[6521]228  this->cameraVector = q.apply(this->cameraVector);
229  this->dataTank->localCamera->setRelCoor(this->cameraVector);
230  this->dataTank->localCamera->getTarget()->setRelCoorSoft(0,0,0);
231}
232
233
234/**
[6504]235 * event dispatcher funciton
236 * @param event the incoming event
237 */
238void SimpleGameMenu::process(const Event &event)
239{
[6839]240  /* ----------------- LAYER 1 ---------------*/
[6837]241  if( this->layerIndex == 0)
[6504]242  {
[6837]243    if( event.type == SDLK_RETURN && event.bPressed == true)
[6520]244    {
[6837]245      if( this->menuSelected == this->menuQuitGame)
246      {
247        this->setNextStoryID(WORLD_ID_GAMEEND);
248        this->stop();
249      }
250      if( this->menuSelected == this->menuStartGame)
251      {
252        //this->stop();
253        // switch to first submenu
[6839]254        if( this->menuLayer[1]->menuList.size() == 0)
[6837]255        {
[6839]256          PRINTF(1)("Haven't got any StoryEntities to play!\n");
[6837]257          return;
258        }
259
260        this->switchMenuLayer(this->layerIndex, 1);
261
262      }
[6520]263    }
[6837]264    else if( event.type == SDLK_DOWN && event.bPressed == true)
[6520]265    {
[6837]266//     ImageEntity*
267      if(this->menuSelectedIndex < (this->menuLayer[this->layerIndex]->menuList.size() - 1))
268      {
269        this->menuSelected = this->menuLayer[this->layerIndex]->menuList[++this->menuSelectedIndex];
270        this->menuSelector->setAbsCoor(this->menuSelected->getAbsCoor());
271      }
[6520]272    }
[6837]273    else if( event.type == SDLK_UP && event.bPressed == true)
[6520]274    {
[6837]275      if(this->menuSelectedIndex > 0)
276      {
277        this->menuSelected = this->menuLayer[this->layerIndex]->menuList[--this->menuSelectedIndex];
278        this->menuSelector->setAbsCoor(this->menuSelected->getAbsCoor());
279      }
[6520]280    }
[6839]281  }  /* ----------------- LAYER 2 ---------------*/
[6837]282  else if( this->layerIndex == 1)
[6520]283  {
[6837]284
[6520]285  }
[6504]286}
[6502]287
288
[6837]289/**
290 *  switches to from one meny layer to an other
291 * @param layer1 from layer
292 * @param layer2 to layer
293 */
294void SimpleGameMenu::switchMenuLayer(int layer1, int layer2)
295{
296  // wrong sizes
297  if(layer1 >= this->menuLayer.size() || layer2 >= this->menuLayer.size())
298    return;
[6502]299
300
[6837]301  PRINTF(0)("Removing layer %i\n", layer1);
302  std::vector<ImageEntity*>::iterator it;
303  // fade old menu
304  for( it = this->menuLayer[layer1]->menuList.begin(); it != this->menuLayer[layer1]->menuList.end(); it++ )
305  {
306    (*it)->setAbsCoor(Vector(-100, -100, -100));
307  }
[6502]308
309
[6837]310  PRINTF(0)("Showing layer %i\n", layer1);
311  // beam here the new menu
312  for( it = this->menuLayer[layer2]->menuList.begin(); it != this->menuLayer[layer2]->menuList.end(); it++ )
313  {}
314
315  this->layerIndex = layer2;
316}
317
318
319
320
[6502]321/**********************************************************************************************
322    SimpleGameMenuData
323 **********************************************************************************************/
324
325
[6501]326/**
[6502]327 * SimpleGameMenuData constructor
[6501]328 */
[6502]329SimpleGameMenuData::SimpleGameMenuData()
[6501]330{}
331
332/**
[6502]333 * SimpleGameMenuData decontructor
[6501]334 */
[6502]335SimpleGameMenuData::~SimpleGameMenuData()
[6501]336{}
337
338
339/**
[6502]340 *  initialize the GameWorldDataData
[6501]341 */
[6502]342ErrorMessage SimpleGameMenuData::init()
343{
344  /* call underlying function */
345  GameWorldData::init();
346}
[6501]347
348
349/**
[6502]350 *  loads the GUI data
351 * @param root reference to the xml root element
[6501]352 */
[6502]353ErrorMessage SimpleGameMenuData::loadGUI(TiXmlElement* root)
354{
355  /* call underlying function */
356  GameWorldData::loadGUI(root);
357}
[6501]358
359
360/**
[6502]361 *  unloads the GUI data
[6501]362 */
[6502]363ErrorMessage SimpleGameMenuData::unloadGUI()
364{
365  /* call underlying function */
366  GameWorldData::unloadGUI();
367}
368
369
370/**
371 *  overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff)
372 * @param root reference to the xml root parameter
373 */
374ErrorMessage SimpleGameMenuData::loadWorldEntities(TiXmlElement* root)
375{
376  TiXmlElement* element = root->FirstChildElement("WorldEntities");
377
378  if( element != NULL)
379  {
380    element = element->FirstChildElement();
381    PRINTF(4)("Loading WorldEntities\n");
382    while( element != NULL)
383    {
384      BaseObject* created = Factory::fabricate(element);
385      if( created != NULL )
386        printf("Created a %s: %s\n", created->getClassName(), created->getName());
387
388      if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
389        this->sky = dynamic_cast<WorldEntity*>(created);
390      if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
391        this->terrain = dynamic_cast<Terrain*>(created);
392      element = element->NextSiblingElement();
393    }
394    PRINTF(4)("Done loading WorldEntities\n");
395  }
396
397  /* init the pnode tree */
398  PNode::getNullParent()->init();
399}
400
401
402/**
403 *  unloads the world entities from the xml file
404 */
405ErrorMessage SimpleGameMenuData::unloadWorldEntities()
406{
407  /* call underlying function */
408  GameWorldData::unloadWorldEntities();
409}
410
411
412/**
413 *  loads the scene data
414 * @param root reference to the xml root element
415 */
416ErrorMessage SimpleGameMenuData::loadScene(TiXmlElement* root)
417{
418  /* call underlying function */
419  GameWorldData::loadScene(root);
420}
421
422
423/**
424 *  unloads the scene data
425 */
426ErrorMessage SimpleGameMenuData::unloadScene()
427{
428  /* call underlying function */
429  GameWorldData::unloadScene();
430}
431
432
433
Note: See TracBrowser for help on using the repository browser.