Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: some more menu work. There is no menu visible yet (only for your info)

File size: 5.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 "world_entity.h"
29#include "terrain.h"
30
31#include "event_handler.h"
32
33#include "cd_engine.h"
34
35
36using namespace std;
37
38
39//! This creates a Factory to fabricate a SimpleGameMenu
40CREATE_FACTORY(SimpleGameMenu, CL_SIMPLE_GAME_MENU);
41
42
43
44SimpleGameMenu::SimpleGameMenu(const TiXmlElement* root)
45  : GameWorld(root)
46{
47  this->setClassID(CL_SIMPLE_GAME_MENU, "SimpleGameMenu");
48  this->setName("SimpleGameMenu uninitialized");
49
50  this->dataTank = new SimpleGameMenuData();
51
52  this->loadParams(root);
53}
54
55
56/**
57 *  remove the SimpleGameMenu from memory
58 *
59 *  delete everything explicitly, that isn't contained in the parenting tree!
60 *  things contained in the tree are deleted automaticaly
61 */
62SimpleGameMenu::~SimpleGameMenu ()
63{
64  PRINTF(3)("SimpleGameMenu::~SimpleGameMenu() - deleting current world\n");
65
66  if( this->dataTank)
67    delete this->dataTank;
68}
69
70
71/**
72 * loads the parameters of a SimpleGameMenu from an XML-element
73 * @param root the XML-element to load from
74 */
75void SimpleGameMenu::loadParams(const TiXmlElement* root)
76{
77  /* skip the GameWorld, since it does not define any useful loadParams for this class */
78  static_cast<GameWorld*>(this)->loadParams(root);
79
80  PRINTF(4)("Loaded SimpleGameMenu specific stuff\n");
81}
82
83
84/**
85 * this is executed just before load
86 *
87 * since the load function sometimes needs data, that has been initialized
88 * before the load and after the proceeding storyentity has finished
89 */
90ErrorMessage SimpleGameMenu::init()
91{
92  /* call underlying init funciton */
93  GameWorld::init();
94
95  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_UP);
96  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_DOWN);
97  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_RETURN);
98  EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_SPACE);
99}
100
101
102
103bool SimpleGameMenu::start()
104{
105  EventHandler::getInstance()->pushState(ES_MENU);
106
107  /* now call the underlying*/
108  GameWorld::start();
109}
110
111
112
113bool SimpleGameMenu::stop()
114{
115  EventHandler::getInstance()->popState();
116
117  /* now call the underlying*/
118  GameWorld::stop();
119}
120
121
122
123/**
124 * no collision detection in the menu
125 */
126void SimpleGameMenu::collide()
127{}
128
129
130/**
131 * event dispatcher funciton
132 * @param event the incoming event
133 */
134void SimpleGameMenu::process(const Event &event)
135{
136  PRINTF(0)("Got Event: %i\n", event.type);
137
138  if( event.type == SDLK_RETURN)
139  {
140    this->stop();
141  }
142}
143
144
145
146
147
148
149/**********************************************************************************************
150    SimpleGameMenuData
151 **********************************************************************************************/
152
153
154/**
155 * SimpleGameMenuData constructor
156 */
157SimpleGameMenuData::SimpleGameMenuData()
158{}
159
160/**
161 * SimpleGameMenuData decontructor
162 */
163SimpleGameMenuData::~SimpleGameMenuData()
164{}
165
166
167/**
168 *  initialize the GameWorldDataData
169 */
170ErrorMessage SimpleGameMenuData::init()
171{
172  /* call underlying function */
173  GameWorldData::init();
174}
175
176
177/**
178 *  loads the GUI data
179 * @param root reference to the xml root element
180 */
181ErrorMessage SimpleGameMenuData::loadGUI(TiXmlElement* root)
182{
183  /* call underlying function */
184  GameWorldData::loadGUI(root);
185}
186
187
188/**
189 *  unloads the GUI data
190 */
191ErrorMessage SimpleGameMenuData::unloadGUI()
192{
193  /* call underlying function */
194  GameWorldData::unloadGUI();
195}
196
197
198/**
199 *  overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff)
200 * @param root reference to the xml root parameter
201 */
202ErrorMessage SimpleGameMenuData::loadWorldEntities(TiXmlElement* root)
203{
204  TiXmlElement* element = root->FirstChildElement("WorldEntities");
205
206  if( element != NULL)
207  {
208    element = element->FirstChildElement();
209    PRINTF(4)("Loading WorldEntities\n");
210    while( element != NULL)
211    {
212      BaseObject* created = Factory::fabricate(element);
213      if( created != NULL )
214        printf("Created a %s: %s\n", created->getClassName(), created->getName());
215
216      if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
217        this->sky = dynamic_cast<WorldEntity*>(created);
218      if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
219        this->terrain = dynamic_cast<Terrain*>(created);
220      element = element->NextSiblingElement();
221    }
222    PRINTF(4)("Done loading WorldEntities\n");
223  }
224
225  /* init the pnode tree */
226  PNode::getNullParent()->init();
227}
228
229
230/**
231 *  unloads the world entities from the xml file
232 */
233ErrorMessage SimpleGameMenuData::unloadWorldEntities()
234{
235  /* call underlying function */
236  GameWorldData::unloadWorldEntities();
237}
238
239
240/**
241 *  loads the scene data
242 * @param root reference to the xml root element
243 */
244ErrorMessage SimpleGameMenuData::loadScene(TiXmlElement* root)
245{
246  /* call underlying function */
247  GameWorldData::loadScene(root);
248}
249
250
251/**
252 *  unloads the scene data
253 */
254ErrorMessage SimpleGameMenuData::unloadScene()
255{
256  /* call underlying function */
257  GameWorldData::unloadScene();
258}
259
260
261
Note: See TracBrowser for help on using the repository browser.