Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/story_entities/game_menu.cc @ 8691

Last change on this file since 8691 was 8691, checked in by bensch, 18 years ago

orxonox/trunk: now one can enter levels with the GUI, and Images should be shown as Well

File size: 10.3 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
[8673]19#include "game_menu.h"
[6501]20
[7868]21#include "event_handler.h"
22
[6502]23#include "state.h"
24#include "class_list.h"
25
[7193]26#include "util/loading/load_param.h"
27#include "util/loading/factory.h"
[8688]28#include "util/loading/resource_manager.h"
[6502]29
[8688]30#include "graphics_engine.h"
[6521]31#include "camera.h"
[8688]32#include "sound_engine.h"
[6502]33
[7318]34#include "sound_source.h"
[6504]35
[7919]36#include "glgui.h"
[8691]37#include "menu/glgui_imagebutton.h"
[6502]38
[8673]39//! This creates a Factory to fabricate a GameMenu
40CREATE_FACTORY(GameMenu, CL_GAME_MENU);
[6502]41
42
43
[8673]44GameMenu::GameMenu(const TiXmlElement* root)
[7919]45    : GameWorld()
[6502]46{
[8673]47  this->setClassID(CL_GAME_MENU, "GameMenu");
48  this->setName("GameMenu uninitialized");
[6502]49
[8673]50  this->dataTank = new GameMenuData();
[6502]51
[6521]52  this->cameraVector = Vector(50.0, 0.0, 0.0);
[6862]53
[7221]54  if (root != NULL)
55    this->loadParams(root);
[6878]56
[7032]57  State::setMenuID(this->getNextStoryID());
[6502]58}
59
[6501]60/**
[8673]61*  @brief remove the GameMenu from memory
[7919]62*
63*  delete everything explicitly, that isn't contained in the parenting tree!
64*  things contained in the tree are deleted automaticaly
65*/
[8673]66GameMenu::~GameMenu ()
[6502]67{
[8673]68  PRINTF(3)("GameMenu::~GameMenu() - deleting current world\n");
[7287]69
70  if( this->dataTank)
71    delete this->dataTank;
[7919]72  delete OrxGui::GLGuiHandler::getInstance( );
[6502]73}
[6501]74
[6502]75
76/**
[8673]77* @brief loads the parameters of a GameMenu from an XML-element
[7919]78* @param root the XML-element to load from
79*/
[8673]80void GameMenu::loadParams(const TiXmlElement* root)
[6502]81{
82  /* skip the GameWorld, since it does not define any useful loadParams for this class */
[6696]83  //static_cast<GameWorld*>(this)->loadParams(root);
84  GameWorld::loadParams(root);
[6501]85
[8673]86  PRINTF(4)("Loaded GameMenu specific stuff\n");
[6502]87}
[6501]88
[6502]89
[6501]90/**
[7919]91* @brief 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*/
[8673]96ErrorMessage GameMenu::init()
[6504]97{
98  /* call underlying init funciton */
99  GameWorld::init();
100
[7868]101  this->subscribeEvent(ES_MENU, SDLK_UP);
102  this->subscribeEvent(ES_MENU, SDLK_DOWN);
103  this->subscribeEvent(ES_MENU, SDLK_RETURN);
104  this->subscribeEvent(ES_MENU, SDLK_SPACE);
105  this->subscribeEvent(ES_MENU, SDLK_ESCAPE);
[6521]106
107  this->dataTank->localCamera->setRelCoor(this->cameraVector);
[6524]108
109  GraphicsEngine::getInstance()->displayFPS(false);
[6862]110
[8677]111  return ErrorMessage();
[6504]112}
113
114
[6524]115/**
[7919]116* @brief load the data
117*/
[8673]118ErrorMessage GameMenu::loadData()
[6504]119{
[8677]120  this->mainMenuBox = NULL;
121
122  this->levelsBox = NULL;
123  this->networkBox = NULL;
124
125  this->optionsBox = NULL;
[8688]126  this->generalBox = NULL;
[8677]127  this->audioBox = NULL;
128  this->videoBox = NULL;
129  this->controlBox = NULL;
130  this->levelsBox = NULL;
131
[8688]132  this->currentlyOpened = NULL;
133
[8677]134  return GameWorld::loadData();
135}
136
137
138void GameMenu::showMainMenu()
139{
140  if (mainMenuBox == NULL)
[8674]141  {
[8677]142    this->mainMenuBox = new OrxGui::GLGuiBox();
143    {
144      OrxGui::GLGuiButton* startButton = new OrxGui::GLGuiPushButton("Play");
145      startButton->connect(SIGNAL(startButton, released), this, SLOT(GameMenu, showCampaigns));
146      this->mainMenuBox->pack(startButton);
[8674]147
[8677]148      OrxGui::GLGuiButton* networkButton = new OrxGui::GLGuiPushButton("MultiPlayer");
149      networkButton->connect(SIGNAL(networkButton, released), this, SLOT(GameMenu, showMultiPlayer));
150      this->mainMenuBox->pack(networkButton);
[8674]151
[8677]152      OrxGui::GLGuiButton* optionsButton = new OrxGui::GLGuiPushButton("Options");
153      optionsButton->connect(SIGNAL(optionsButton, released), this, SLOT(GameMenu, showOptionsMenu));
154      this->mainMenuBox->pack(optionsButton);
[8674]155
156
[8677]157      OrxGui::GLGuiButton* quitButton = new OrxGui::GLGuiPushButton("Quit");
158      this->mainMenuBox->pack(quitButton);
159      quitButton->connect(SIGNAL(quitButton, released), this, SLOT(GameMenu, quitMenu));
160    }
[8674]161  }
[8677]162  this->mainMenuBox->showAll();
[8674]163
[8677]164  this->mainMenuBox->setRelCoor2D(200, 100);
165}
[8674]166
[8688]167
[8677]168void GameMenu::showCampaigns()
169{
170  if (this->levelsBox == NULL)
171  {
172    this->levelsBox = new OrxGui::GLGuiBox();
173    {
174      const std::list<BaseObject*>* storyEntities = ClassList::getList(CL_STORY_ENTITY);
175      std::list<BaseObject*>::const_iterator it;
176      for( it = storyEntities->begin(); it != storyEntities->end(); it++)
177      {
178        StoryEntity* se = dynamic_cast<StoryEntity*>(*it);
179        if( se->isContainedInMenu())
180        {
[8691]181          OrxGui::GLGuiImage* image = new OrxGui::GLGuiImage();
182          image->show();
183          image->setWidgetSize( 100, 100);
184
185          printf("%s\n", se->getMenuScreenshoot().c_str());
186          OrxGui::GLGuiImageButton* button = new OrxGui::GLGuiImageButton(se->getName(), se->getStoryID(), se->getMenuScreenshoot(), image);
187          button->connect(SIGNAL(button, startLevel), this, SLOT(GameMenu, startLevel));
[8677]188          levelsBox->pack(button);
189
190          // generating screenshoot item
191          /*
192          ImageEntity* ie = new ImageEntity();
193          ie->setVisibility(false);
194          ie->setBindNode((const PNode*)NULL);
195          ie->setTexture(se->getMenuScreenshoot());
196          ie->setRelCoor2D(State::getResX() / 2.0f + 250.0f, State::getResY() / 2.0f);
197          ie->setSize2D(140.0f, 105.0f);
198          this->menuLayers[1].screenshootList.push_back(ie);
199          */
200        }
201      }
202    }
203  }
204
[8688]205  this->showSecondLevelElement(this->levelsBox);
[8677]206
[6521]207}
[6520]208
[8677]209void GameMenu::showMultiPlayer()
[8688]210{}
[8677]211
212void GameMenu::showOptionsMenu()
213{
214  if (this->optionsBox == NULL)
215  {
216    this->optionsBox = new OrxGui::GLGuiBox();
217    {
218      OrxGui::GLGuiButton* generalButton = new OrxGui::GLGuiPushButton("General");
219      optionsBox->pack(generalButton);
220
221      OrxGui::GLGuiButton* audioButton = new OrxGui::GLGuiPushButton("Audio");
222      optionsBox->pack(audioButton);
223
224      OrxGui::GLGuiButton* videoButton = new OrxGui::GLGuiPushButton("Video");
225      optionsBox->pack(videoButton);
226
227      OrxGui::GLGuiButton* controlButton = new OrxGui::GLGuiPushButton("Control");
228      optionsBox->pack(controlButton);
229
230
231      //      for (unsigned int i = 0; i <
232      //OrxGui::GLGuiButton*
233
234    }
235  }
236
[8688]237  this->showSecondLevelElement(this->optionsBox);
[8677]238}
239
240
[8688]241void GameMenu::showSecondLevelElement(OrxGui::GLGuiBox* element)
242{
243  if (this->currentlyOpened != NULL && this->currentlyOpened != element)
244    this->currentlyOpened->hideAll();
[8677]245
[8688]246  element->showAll();
247  element->setRelCoor2D(200, 100);
[8677]248
[8688]249  this->currentlyOpened = element;
[8677]250
[8688]251  this->mainMenuBox->setRelCoorSoft2D(50, 100, 5);
252}
[8677]253
254
255
256
257
[8691]258void GameMenu::startLevel(int levelID)
259{
260  this->setNextStoryID( levelID);
261  this->stop();
262}
[8688]263
[7318]264/**
[7919]265* @brief set the Sound to play when switching menu entry.
266* @param selectorSound the sound to load.
267*/
[8673]268void GameMenu::setSelectorSound(const std::string& selectorSound)
[7318]269{
[7460]270  this->selectorSource = OrxSound::SoundEngine::getInstance()->createSource(selectorSound, NULL);
[7318]271}
[6521]272
[8673]273ErrorMessage GameMenu::unloadData()
[6862]274{
[7868]275  this->unsubscribeEvents(ES_MENU);
[6862]276
[8677]277  return GameWorld::unloadData();
[6862]278}
279
280
[6524]281/**
[7919]282* @brief start the menu
283*/
[8673]284bool GameMenu::start()
[6521]285{
286  EventHandler::getInstance()->pushState(ES_MENU);
287
[8677]288  this->showMainMenu();
[8689]289  OrxGui::GLGuiHandler::getInstance()->activateCursor();
290  OrxGui::GLGuiHandler::getInstance()->activate();
291  OrxGui::GLGuiHandler::getInstance()->cursor()->loadTextureSequence(ResourceManager::getInstance()->getDataDir() + "/" + "maps/reap_mouse/reap_mouse_##.png", 1, 49);
[8674]292
[6504]293  /* now call the underlying*/
[8677]294  return GameWorld::start();
[6504]295}
296
297
298
[6524]299/**
[7919]300* stop the menu
301*/
[8673]302bool GameMenu::stop()
[6504]303{
304  EventHandler::getInstance()->popState();
305
306  /* now call the underlying*/
[8677]307  return GameWorld::stop();
[6504]308}
309
310
[6521]311/**
[7919]312*  override the standard tick for more functionality
313*/
[8673]314void GameMenu::tick()
[6521]315{
316  GameWorld::tick();
[6504]317
[7919]318  // Make the GLGui tick.
319  OrxGui::GLGuiHandler::getInstance()->tick(this->dtS);
320
[7131]321  this->animateScene(this->dtS);
[6521]322}
323
324
[6504]325/**
[7919]326* @brief no collision detection in the menu
327*/
[8673]328void GameMenu::collide()
[6521]329{
[7919]330  //   this->dataTank->localCamera->
[6521]331}
[6501]332
333
[6504]334/**
[7919]335* @brief animate the scene
336*/
[8673]337void GameMenu::animateScene(float dt)
[6521]338{
[7131]339  Quaternion q(/*0.00005*/ dt * .1, Vector(0.0, 1.0, 0.0));
[6521]340  this->cameraVector = q.apply(this->cameraVector);
341  this->dataTank->localCamera->setRelCoor(this->cameraVector);
342  this->dataTank->localCamera->getTarget()->setRelCoorSoft(0,0,0);
343}
344
[8673]345void GameMenu::quitMenu()
[7919]346{
347  this->setNextStoryID(WORLD_ID_GAMEEND);
348  this->stop();
349}
[6521]350
[7919]351
[6521]352/**
[7919]353* @brief event dispatcher funciton
354* @param event the incoming event
355*/
[8673]356void GameMenu::process(const Event &event)
[6504]357{
[8674]358  if( event.type == SDLK_ESCAPE && event.bPressed == true)
359  {
360    this->setNextStoryID(WORLD_ID_GAMEEND);
361    this->stop();
362  }
363
[6504]364}
[6502]365
366
367
368/**********************************************************************************************
[8673]369GameMenuData
[7919]370**********************************************************************************************/
[6502]371
372
[6501]373/**
[8673]374* GameMenuData constructor
[7919]375*/
[8673]376GameMenuData::GameMenuData()
[6501]377{}
378
379/**
[8673]380* GameMenuData decontructor
[7919]381*/
[8673]382GameMenuData::~GameMenuData()
[6501]383{}
384
385
386/**
[7919]387*  initialize the GameWorldDataData
388*/
[8673]389ErrorMessage GameMenuData::init()
[6502]390{
391  /* call underlying function */
[8677]392  return GameWorldData::init();
[6502]393}
[6501]394
395
396/**
[7919]397*  loads the GUI data
398* @param root reference to the xml root element
399*/
[8673]400ErrorMessage GameMenuData::loadGUI(const TiXmlElement* root)
[6502]401{
402  /* call underlying function */
[8677]403  return GameWorldData::loadGUI(root);
[6502]404}
[6501]405
406
407/**
[7919]408*  unloads the GUI data
409*/
[8673]410ErrorMessage GameMenuData::unloadGUI()
[6502]411{
412  /* call underlying function */
[8677]413  return GameWorldData::unloadGUI();
[6502]414}
415
416
417/**
[7919]418*  overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff)
419* @param root reference to the xml root parameter
420*/
[8673]421ErrorMessage GameMenuData::loadWorldEntities(const TiXmlElement* root)
[6502]422{
[8677]423  return GameWorldData::loadWorldEntities(root);
[6502]424}
425
426
427/**
[7919]428*  unloads the world entities from the xml file
429*/
[8673]430ErrorMessage GameMenuData::unloadWorldEntities()
[6502]431{
432  /* call underlying function */
[8677]433  return GameWorldData::unloadWorldEntities();
[6502]434}
435
436
437/**
[7919]438*  loads the scene data
439* @param root reference to the xml root element
440*/
[8673]441ErrorMessage GameMenuData::loadScene(const TiXmlElement* root)
[6502]442{
443  /* call underlying function */
[8677]444  return GameWorldData::loadScene(root);
[6502]445}
446
447
448/**
[7919]449*  unloads the scene data
450*/
[8673]451ErrorMessage GameMenuData::unloadScene()
[6502]452{
453  /* call underlying function */
[8677]454  return GameWorldData::unloadScene();
[6502]455}
456
457
458
Note: See TracBrowser for help on using the repository browser.