Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: the simple menu now works. now i need more graphics, more effects and more sound

File size: 7.7 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 "world_entity.h"
29#include "image_entity.h"
30#include "terrain.h"
31
32#include "event_handler.h"
33
34#include "cd_engine.h"
35
36
37using namespace std;
38
39
40//! This creates a Factory to fabricate a SimpleGameMenu
41CREATE_FACTORY(SimpleGameMenu, CL_SIMPLE_GAME_MENU);
42
43
44
45SimpleGameMenu::SimpleGameMenu(const TiXmlElement* root)
46  : GameWorld(root)
47{
48  this->setClassID(CL_SIMPLE_GAME_MENU, "SimpleGameMenu");
49  this->setName("SimpleGameMenu uninitialized");
50
51  this->dataTank = new SimpleGameMenuData();
52
53  this->loadParams(root);
54}
55
56
57/**
58 *  remove the SimpleGameMenu from memory
59 *
60 *  delete everything explicitly, that isn't contained in the parenting tree!
61 *  things contained in the tree are deleted automaticaly
62 */
63SimpleGameMenu::~SimpleGameMenu ()
64{
65  PRINTF(3)("SimpleGameMenu::~SimpleGameMenu() - deleting current world\n");
66
67  if( this->dataTank)
68    delete this->dataTank;
69}
70
71
72/**
73 * loads the parameters of a SimpleGameMenu from an XML-element
74 * @param root the XML-element to load from
75 */
76void SimpleGameMenu::loadParams(const TiXmlElement* root)
77{
78  /* skip the GameWorld, since it does not define any useful loadParams for this class */
79  static_cast<GameWorld*>(this)->loadParams(root);
80
81  PRINTF(4)("Loaded SimpleGameMenu specific stuff\n");
82}
83
84
85/**
86 * this is executed just before load
87 *
88 * since the load function sometimes needs data, that has been initialized
89 * before the load and after the proceeding storyentity has finished
90 */
91ErrorMessage SimpleGameMenu::init()
92{
93  /* call underlying init funciton */
94  GameWorld::init();
95
96  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_UP);
97  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_DOWN);
98  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_RETURN);
99  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_SPACE);
100}
101
102
103
104bool SimpleGameMenu::start()
105{
106  EventHandler::getInstance()->pushState(ES_MENU);
107
108
109//   const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
110//   assert(playableList != NULL);
111//   std::list<BaseObject*>::const_iterator entity;
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  /* now call the underlying*/
148  GameWorld::start();
149}
150
151
152
153bool SimpleGameMenu::stop()
154{
155  EventHandler::getInstance()->popState();
156
157  /* now call the underlying*/
158  GameWorld::stop();
159}
160
161
162
163/**
164 * no collision detection in the menu
165 */
166void SimpleGameMenu::collide()
167{}
168
169
170/**
171 * event dispatcher funciton
172 * @param event the incoming event
173 */
174void SimpleGameMenu::process(const Event &event)
175{
176  PRINTF(0)("Got Event: %i\n", event.type);
177
178  if( event.type == SDLK_RETURN)
179  {
180    if( this->menuSelected == this->menuQuitGame)
181    {
182      this->setNextStoryID(999);
183      this->stop();
184    }
185    if( this->menuSelected == this->menuStartGame)
186    {
187      this->stop();
188    }
189  }
190  else if( event.type == SDLK_DOWN && event.bPressed == true)
191  {
192//     ImageEntity*
193    if(this->menuSelectedIndex < (this->menuList.size() - 1))
194    {
195      this->menuSelected = this->menuList[++this->menuSelectedIndex];
196      this->menuSelector->setAbsCoor(this->menuSelected->getAbsCoor());
197    }
198  }
199  else if( event.type == SDLK_UP && event.bPressed == true)
200  {
201    if(this->menuSelectedIndex > 0)
202    {
203      this->menuSelected = this->menuList[--this->menuSelectedIndex];
204      this->menuSelector->setAbsCoor(this->menuSelected->getAbsCoor());
205    }
206  }
207}
208
209
210
211
212
213
214/**********************************************************************************************
215    SimpleGameMenuData
216 **********************************************************************************************/
217
218
219/**
220 * SimpleGameMenuData constructor
221 */
222SimpleGameMenuData::SimpleGameMenuData()
223{}
224
225/**
226 * SimpleGameMenuData decontructor
227 */
228SimpleGameMenuData::~SimpleGameMenuData()
229{}
230
231
232/**
233 *  initialize the GameWorldDataData
234 */
235ErrorMessage SimpleGameMenuData::init()
236{
237  /* call underlying function */
238  GameWorldData::init();
239}
240
241
242/**
243 *  loads the GUI data
244 * @param root reference to the xml root element
245 */
246ErrorMessage SimpleGameMenuData::loadGUI(TiXmlElement* root)
247{
248  /* call underlying function */
249  GameWorldData::loadGUI(root);
250}
251
252
253/**
254 *  unloads the GUI data
255 */
256ErrorMessage SimpleGameMenuData::unloadGUI()
257{
258  /* call underlying function */
259  GameWorldData::unloadGUI();
260}
261
262
263/**
264 *  overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff)
265 * @param root reference to the xml root parameter
266 */
267ErrorMessage SimpleGameMenuData::loadWorldEntities(TiXmlElement* root)
268{
269  TiXmlElement* element = root->FirstChildElement("WorldEntities");
270
271  if( element != NULL)
272  {
273    element = element->FirstChildElement();
274    PRINTF(4)("Loading WorldEntities\n");
275    while( element != NULL)
276    {
277      BaseObject* created = Factory::fabricate(element);
278      if( created != NULL )
279        printf("Created a %s: %s\n", created->getClassName(), created->getName());
280
281      if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
282        this->sky = dynamic_cast<WorldEntity*>(created);
283      if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
284        this->terrain = dynamic_cast<Terrain*>(created);
285      element = element->NextSiblingElement();
286    }
287    PRINTF(4)("Done loading WorldEntities\n");
288  }
289
290  /* init the pnode tree */
291  PNode::getNullParent()->init();
292}
293
294
295/**
296 *  unloads the world entities from the xml file
297 */
298ErrorMessage SimpleGameMenuData::unloadWorldEntities()
299{
300  /* call underlying function */
301  GameWorldData::unloadWorldEntities();
302}
303
304
305/**
306 *  loads the scene data
307 * @param root reference to the xml root element
308 */
309ErrorMessage SimpleGameMenuData::loadScene(TiXmlElement* root)
310{
311  /* call underlying function */
312  GameWorldData::loadScene(root);
313}
314
315
316/**
317 *  unloads the scene data
318 */
319ErrorMessage SimpleGameMenuData::unloadScene()
320{
321  /* call underlying function */
322  GameWorldData::unloadScene();
323}
324
325
326
Note: See TracBrowser for help on using the repository browser.