/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD #include "game_menu.h" #include "event_handler.h" #include "state.h" #include "class_list.h" #include "util/loading/load_param.h" #include "fast_factory.h" #include "util/loading/factory.h" #include "loading/resource_manager.h" #include "world_entity.h" #include "elements/image_entity.h" #include "terrain.h" #include "camera.h" #include "graphics_engine.h" #include "object_manager.h" #include "sound_engine.h" #include "sound_source.h" #include "cd_engine.h" #include "glgui.h" #include "gui/gl/specials/glgui_notifier.h" //! This creates a Factory to fabricate a GameMenu CREATE_FACTORY(GameMenu, CL_GAME_MENU); GameMenu::GameMenu(const TiXmlElement* root) : GameWorld() { this->setClassID(CL_GAME_MENU, "GameMenu"); this->setName("GameMenu uninitialized"); this->dataTank = new GameMenuData(); this->cameraVector = Vector(50.0, 0.0, 0.0); OrxGui::GLGuiHandler::getInstance()->activateCursor(); OrxGui::GLGuiHandler::getInstance()->activate(); OrxGui::GLGuiHandler::getInstance()->cursor()->loadTextureSequence(ResourceManager::getInstance()->getDataDir() + "/" + "maps/reap_mouse/reap_mouse_##.png", 1, 49); if (root != NULL) this->loadParams(root); State::setMenuID(this->getNextStoryID()); } /// HACK only for testing. void GameMenu::enterGui() { } /** * @brief remove the GameMenu from memory * * delete everything explicitly, that isn't contained in the parenting tree! * things contained in the tree are deleted automaticaly */ GameMenu::~GameMenu () { PRINTF(3)("GameMenu::~GameMenu() - deleting current world\n"); if( this->dataTank) delete this->dataTank; delete OrxGui::GLGuiHandler::getInstance( ); } /** * @brief loads the parameters of a GameMenu from an XML-element * @param root the XML-element to load from */ void GameMenu::loadParams(const TiXmlElement* root) { /* skip the GameWorld, since it does not define any useful loadParams for this class */ //static_cast(this)->loadParams(root); GameWorld::loadParams(root); PRINTF(4)("Loaded GameMenu specific stuff\n"); } /** * @brief this is executed just before load * * since the load function sometimes needs data, that has been initialized * before the load and after the proceeding storyentity has finished */ ErrorMessage GameMenu::init() { /* call underlying init funciton */ GameWorld::init(); this->subscribeEvent(ES_MENU, SDLK_UP); this->subscribeEvent(ES_MENU, SDLK_DOWN); this->subscribeEvent(ES_MENU, SDLK_RETURN); this->subscribeEvent(ES_MENU, SDLK_SPACE); this->subscribeEvent(ES_MENU, SDLK_ESCAPE); this->dataTank->localCamera->setRelCoor(this->cameraVector); GraphicsEngine::getInstance()->displayFPS(false); } /** * @brief load the data */ ErrorMessage GameMenu::loadData() { GameWorld::loadData(); } /** * @brief set the Sound to play when switching menu entry. * @param selectorSound the sound to load. */ void GameMenu::setSelectorSound(const std::string& selectorSound) { this->selectorSource = OrxSound::SoundEngine::getInstance()->createSource(selectorSound, NULL); } ErrorMessage GameMenu::unloadData() { this->unsubscribeEvents(ES_MENU); GameWorld::unloadData(); } /** * @brief start the menu */ bool GameMenu::start() { EventHandler::getInstance()->pushState(ES_MENU); /* now call the underlying*/ GameWorld::start(); } /** * stop the menu */ bool GameMenu::stop() { EventHandler::getInstance()->popState(); /* now call the underlying*/ GameWorld::stop(); } /** * override the standard tick for more functionality */ void GameMenu::tick() { GameWorld::tick(); // Make the GLGui tick. OrxGui::GLGuiHandler::getInstance()->tick(this->dtS); this->animateScene(this->dtS); } /** * @brief no collision detection in the menu */ void GameMenu::collide() { // this->dataTank->localCamera-> } /** * @brief animate the scene */ void GameMenu::animateScene(float dt) { Quaternion q(/*0.00005*/ dt * .1, Vector(0.0, 1.0, 0.0)); this->cameraVector = q.apply(this->cameraVector); this->dataTank->localCamera->setRelCoor(this->cameraVector); this->dataTank->localCamera->getTarget()->setRelCoorSoft(0,0,0); } void GameMenu::quitMenu() { this->setNextStoryID(WORLD_ID_GAMEEND); this->stop(); } /** * @brief event dispatcher funciton * @param event the incoming event */ void GameMenu::process(const Event &event) { } /********************************************************************************************** GameMenuData **********************************************************************************************/ /** * GameMenuData constructor */ GameMenuData::GameMenuData() {} /** * GameMenuData decontructor */ GameMenuData::~GameMenuData() {} /** * initialize the GameWorldDataData */ ErrorMessage GameMenuData::init() { /* call underlying function */ GameWorldData::init(); } /** * loads the GUI data * @param root reference to the xml root element */ ErrorMessage GameMenuData::loadGUI(const TiXmlElement* root) { /* call underlying function */ GameWorldData::loadGUI(root); } /** * unloads the GUI data */ ErrorMessage GameMenuData::unloadGUI() { /* call underlying function */ GameWorldData::unloadGUI(); } /** * overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff) * @param root reference to the xml root parameter */ ErrorMessage GameMenuData::loadWorldEntities(const TiXmlElement* root) { GameWorldData::loadWorldEntities(root); } /** * unloads the world entities from the xml file */ ErrorMessage GameMenuData::unloadWorldEntities() { /* call underlying function */ GameWorldData::unloadWorldEntities(); } /** * loads the scene data * @param root reference to the xml root element */ ErrorMessage GameMenuData::loadScene(const TiXmlElement* root) { /* call underlying function */ GameWorldData::loadScene(root); } /** * unloads the scene data */ ErrorMessage GameMenuData::unloadScene() { /* call underlying function */ GameWorldData::unloadScene(); }