/* 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 "simple_game_menu.h" #include "state.h" #include "class_list.h" #include "load_param.h" #include "fast_factory.h" #include "factory.h" #include "world_entity.h" #include "terrain.h" #include "event_handler.h" #include "cd_engine.h" using namespace std; //! This creates a Factory to fabricate a SimpleGameMenu CREATE_FACTORY(SimpleGameMenu, CL_SIMPLE_GAME_MENU); SimpleGameMenu::SimpleGameMenu(const TiXmlElement* root) : GameWorld(root) { this->setClassID(CL_SIMPLE_GAME_MENU, "SimpleGameMenu"); this->setName("SimpleGameMenu uninitialized"); this->dataTank = new SimpleGameMenuData(); this->loadParams(root); } /** * remove the SimpleGameMenu from memory * * delete everything explicitly, that isn't contained in the parenting tree! * things contained in the tree are deleted automaticaly */ SimpleGameMenu::~SimpleGameMenu () { PRINTF(3)("SimpleGameMenu::~SimpleGameMenu() - deleting current world\n"); if( this->dataTank) delete this->dataTank; } /** * loads the parameters of a SimpleGameMenu from an XML-element * @param root the XML-element to load from */ void SimpleGameMenu::loadParams(const TiXmlElement* root) { /* skip the GameWorld, since it does not define any useful loadParams for this class */ static_cast(this)->loadParams(root); PRINTF(4)("Loaded SimpleGameMenu specific stuff\n"); } /** * 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 SimpleGameMenu::init() { /* call underlying init funciton */ GameWorld::init(); EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_UP); EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_DOWN); EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_RETURN); EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_SPACE); } bool SimpleGameMenu::start() { EventHandler::getInstance()->pushState(ES_MENU); /* now call the underlying*/ GameWorld::start(); } bool SimpleGameMenu::stop() { EventHandler::getInstance()->popState(); /* now call the underlying*/ GameWorld::stop(); } /** * no collision detection in the menu */ void SimpleGameMenu::collide() {} /** * event dispatcher funciton * @param event the incoming event */ void SimpleGameMenu::process(const Event &event) { PRINTF(0)("Got Event: %i\n", event.type); if( event.type == SDLK_RETURN) { this->stop(); } } /********************************************************************************************** SimpleGameMenuData **********************************************************************************************/ /** * SimpleGameMenuData constructor */ SimpleGameMenuData::SimpleGameMenuData() {} /** * SimpleGameMenuData decontructor */ SimpleGameMenuData::~SimpleGameMenuData() {} /** * initialize the GameWorldDataData */ ErrorMessage SimpleGameMenuData::init() { /* call underlying function */ GameWorldData::init(); } /** * loads the GUI data * @param root reference to the xml root element */ ErrorMessage SimpleGameMenuData::loadGUI(TiXmlElement* root) { /* call underlying function */ GameWorldData::loadGUI(root); } /** * unloads the GUI data */ ErrorMessage SimpleGameMenuData::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 SimpleGameMenuData::loadWorldEntities(TiXmlElement* root) { TiXmlElement* element = root->FirstChildElement("WorldEntities"); if( element != NULL) { element = element->FirstChildElement(); PRINTF(4)("Loading WorldEntities\n"); while( element != NULL) { BaseObject* created = Factory::fabricate(element); if( created != NULL ) printf("Created a %s: %s\n", created->getClassName(), created->getName()); if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) this->sky = dynamic_cast(created); if( element->Value() != NULL && !strcmp( element->Value(), "Terrain")) this->terrain = dynamic_cast(created); element = element->NextSiblingElement(); } PRINTF(4)("Done loading WorldEntities\n"); } /* init the pnode tree */ PNode::getNullParent()->init(); } /** * unloads the world entities from the xml file */ ErrorMessage SimpleGameMenuData::unloadWorldEntities() { /* call underlying function */ GameWorldData::unloadWorldEntities(); } /** * loads the scene data * @param root reference to the xml root element */ ErrorMessage SimpleGameMenuData::loadScene(TiXmlElement* root) { /* call underlying function */ GameWorldData::loadScene(root); } /** * unloads the scene data */ ErrorMessage SimpleGameMenuData::unloadScene() { /* call underlying function */ GameWorldData::unloadScene(); }