[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" |
---|
[6502] | 27 | #include "fast_factory.h" |
---|
[7193] | 28 | #include "util/loading/factory.h" |
---|
[8324] | 29 | #include "loading/resource_manager.h" |
---|
[6502] | 30 | |
---|
| 31 | #include "world_entity.h" |
---|
[7016] | 32 | #include "elements/image_entity.h" |
---|
[6502] | 33 | #include "terrain.h" |
---|
[6521] | 34 | #include "camera.h" |
---|
[6502] | 35 | |
---|
[6524] | 36 | #include "graphics_engine.h" |
---|
[6841] | 37 | #include "object_manager.h" |
---|
[7318] | 38 | #include "sound_engine.h" |
---|
| 39 | #include "sound_source.h" |
---|
[6504] | 40 | |
---|
[6502] | 41 | #include "cd_engine.h" |
---|
| 42 | |
---|
[7919] | 43 | #include "glgui.h" |
---|
[8518] | 44 | #include "gui/gl/specials/glgui_notifier.h" |
---|
[6502] | 45 | |
---|
[8673] | 46 | //! This creates a Factory to fabricate a GameMenu |
---|
| 47 | CREATE_FACTORY(GameMenu, CL_GAME_MENU); |
---|
[6502] | 48 | |
---|
| 49 | |
---|
| 50 | |
---|
[8673] | 51 | GameMenu::GameMenu(const TiXmlElement* root) |
---|
[7919] | 52 | : GameWorld() |
---|
[6502] | 53 | { |
---|
[8673] | 54 | this->setClassID(CL_GAME_MENU, "GameMenu"); |
---|
| 55 | this->setName("GameMenu uninitialized"); |
---|
[6502] | 56 | |
---|
[8673] | 57 | this->dataTank = new GameMenuData(); |
---|
[6502] | 58 | |
---|
[6521] | 59 | this->cameraVector = Vector(50.0, 0.0, 0.0); |
---|
[6862] | 60 | |
---|
[6521] | 61 | |
---|
[7919] | 62 | OrxGui::GLGuiHandler::getInstance()->activateCursor(); |
---|
| 63 | OrxGui::GLGuiHandler::getInstance()->activate(); |
---|
[8376] | 64 | OrxGui::GLGuiHandler::getInstance()->cursor()->loadTextureSequence(ResourceManager::getInstance()->getDataDir() + "/" + "maps/reap_mouse/reap_mouse_##.png", 1, 49); |
---|
[7919] | 65 | |
---|
[7221] | 66 | if (root != NULL) |
---|
| 67 | this->loadParams(root); |
---|
[6878] | 68 | |
---|
[7032] | 69 | State::setMenuID(this->getNextStoryID()); |
---|
[6502] | 70 | } |
---|
| 71 | |
---|
[7919] | 72 | /// HACK only for testing. |
---|
[8673] | 73 | void GameMenu::enterGui() |
---|
[7919] | 74 | { |
---|
| 75 | } |
---|
| 76 | |
---|
[6501] | 77 | /** |
---|
[8673] | 78 | * @brief remove the GameMenu from memory |
---|
[7919] | 79 | * |
---|
| 80 | * delete everything explicitly, that isn't contained in the parenting tree! |
---|
| 81 | * things contained in the tree are deleted automaticaly |
---|
| 82 | */ |
---|
[8673] | 83 | GameMenu::~GameMenu () |
---|
[6502] | 84 | { |
---|
[8673] | 85 | PRINTF(3)("GameMenu::~GameMenu() - deleting current world\n"); |
---|
[7287] | 86 | |
---|
| 87 | if( this->dataTank) |
---|
| 88 | delete this->dataTank; |
---|
[7919] | 89 | delete OrxGui::GLGuiHandler::getInstance( ); |
---|
[6502] | 90 | } |
---|
[6501] | 91 | |
---|
[6502] | 92 | |
---|
| 93 | /** |
---|
[8673] | 94 | * @brief loads the parameters of a GameMenu from an XML-element |
---|
[7919] | 95 | * @param root the XML-element to load from |
---|
| 96 | */ |
---|
[8673] | 97 | void GameMenu::loadParams(const TiXmlElement* root) |
---|
[6502] | 98 | { |
---|
| 99 | /* skip the GameWorld, since it does not define any useful loadParams for this class */ |
---|
[6696] | 100 | //static_cast<GameWorld*>(this)->loadParams(root); |
---|
| 101 | GameWorld::loadParams(root); |
---|
[6501] | 102 | |
---|
[8673] | 103 | PRINTF(4)("Loaded GameMenu specific stuff\n"); |
---|
[6502] | 104 | } |
---|
[6501] | 105 | |
---|
[6502] | 106 | |
---|
[6501] | 107 | /** |
---|
[7919] | 108 | * @brief this is executed just before load |
---|
| 109 | * |
---|
| 110 | * since the load function sometimes needs data, that has been initialized |
---|
| 111 | * before the load and after the proceeding storyentity has finished |
---|
| 112 | */ |
---|
[8673] | 113 | ErrorMessage GameMenu::init() |
---|
[6504] | 114 | { |
---|
| 115 | /* call underlying init funciton */ |
---|
| 116 | GameWorld::init(); |
---|
| 117 | |
---|
[7868] | 118 | this->subscribeEvent(ES_MENU, SDLK_UP); |
---|
| 119 | this->subscribeEvent(ES_MENU, SDLK_DOWN); |
---|
| 120 | this->subscribeEvent(ES_MENU, SDLK_RETURN); |
---|
| 121 | this->subscribeEvent(ES_MENU, SDLK_SPACE); |
---|
| 122 | this->subscribeEvent(ES_MENU, SDLK_ESCAPE); |
---|
[6521] | 123 | |
---|
| 124 | this->dataTank->localCamera->setRelCoor(this->cameraVector); |
---|
[6524] | 125 | |
---|
| 126 | GraphicsEngine::getInstance()->displayFPS(false); |
---|
[6862] | 127 | |
---|
[6504] | 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
[6524] | 131 | /** |
---|
[7919] | 132 | * @brief load the data |
---|
| 133 | */ |
---|
[8673] | 134 | ErrorMessage GameMenu::loadData() |
---|
[6504] | 135 | { |
---|
[6521] | 136 | GameWorld::loadData(); |
---|
| 137 | } |
---|
[6520] | 138 | |
---|
[7318] | 139 | /** |
---|
[7919] | 140 | * @brief set the Sound to play when switching menu entry. |
---|
| 141 | * @param selectorSound the sound to load. |
---|
| 142 | */ |
---|
[8673] | 143 | void GameMenu::setSelectorSound(const std::string& selectorSound) |
---|
[7318] | 144 | { |
---|
[7460] | 145 | this->selectorSource = OrxSound::SoundEngine::getInstance()->createSource(selectorSound, NULL); |
---|
[7318] | 146 | } |
---|
[6521] | 147 | |
---|
[8673] | 148 | ErrorMessage GameMenu::unloadData() |
---|
[6862] | 149 | { |
---|
[7868] | 150 | this->unsubscribeEvents(ES_MENU); |
---|
[6862] | 151 | |
---|
[7029] | 152 | GameWorld::unloadData(); |
---|
[6862] | 153 | } |
---|
| 154 | |
---|
| 155 | |
---|
[6524] | 156 | /** |
---|
[7919] | 157 | * @brief start the menu |
---|
| 158 | */ |
---|
[8673] | 159 | bool GameMenu::start() |
---|
[6521] | 160 | { |
---|
| 161 | EventHandler::getInstance()->pushState(ES_MENU); |
---|
| 162 | |
---|
[6504] | 163 | /* now call the underlying*/ |
---|
| 164 | GameWorld::start(); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | |
---|
| 168 | |
---|
[6524] | 169 | /** |
---|
[7919] | 170 | * stop the menu |
---|
| 171 | */ |
---|
[8673] | 172 | bool GameMenu::stop() |
---|
[6504] | 173 | { |
---|
| 174 | EventHandler::getInstance()->popState(); |
---|
| 175 | |
---|
| 176 | /* now call the underlying*/ |
---|
| 177 | GameWorld::stop(); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | |
---|
[6521] | 181 | /** |
---|
[7919] | 182 | * override the standard tick for more functionality |
---|
| 183 | */ |
---|
[8673] | 184 | void GameMenu::tick() |
---|
[6521] | 185 | { |
---|
| 186 | GameWorld::tick(); |
---|
[6504] | 187 | |
---|
[7919] | 188 | // Make the GLGui tick. |
---|
| 189 | OrxGui::GLGuiHandler::getInstance()->tick(this->dtS); |
---|
| 190 | |
---|
[7131] | 191 | this->animateScene(this->dtS); |
---|
[6521] | 192 | } |
---|
| 193 | |
---|
| 194 | |
---|
[6504] | 195 | /** |
---|
[7919] | 196 | * @brief no collision detection in the menu |
---|
| 197 | */ |
---|
[8673] | 198 | void GameMenu::collide() |
---|
[6521] | 199 | { |
---|
[7919] | 200 | // this->dataTank->localCamera-> |
---|
[6521] | 201 | } |
---|
[6501] | 202 | |
---|
| 203 | |
---|
[6504] | 204 | /** |
---|
[7919] | 205 | * @brief animate the scene |
---|
| 206 | */ |
---|
[8673] | 207 | void GameMenu::animateScene(float dt) |
---|
[6521] | 208 | { |
---|
[7131] | 209 | Quaternion q(/*0.00005*/ dt * .1, Vector(0.0, 1.0, 0.0)); |
---|
[6521] | 210 | this->cameraVector = q.apply(this->cameraVector); |
---|
| 211 | this->dataTank->localCamera->setRelCoor(this->cameraVector); |
---|
| 212 | this->dataTank->localCamera->getTarget()->setRelCoorSoft(0,0,0); |
---|
| 213 | } |
---|
| 214 | |
---|
[8673] | 215 | void GameMenu::quitMenu() |
---|
[7919] | 216 | { |
---|
| 217 | this->setNextStoryID(WORLD_ID_GAMEEND); |
---|
| 218 | this->stop(); |
---|
| 219 | } |
---|
[6521] | 220 | |
---|
[7919] | 221 | |
---|
[6521] | 222 | /** |
---|
[7919] | 223 | * @brief event dispatcher funciton |
---|
| 224 | * @param event the incoming event |
---|
| 225 | */ |
---|
[8673] | 226 | void GameMenu::process(const Event &event) |
---|
[6504] | 227 | { |
---|
| 228 | } |
---|
[6502] | 229 | |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | /********************************************************************************************** |
---|
[8673] | 233 | GameMenuData |
---|
[7919] | 234 | **********************************************************************************************/ |
---|
[6502] | 235 | |
---|
| 236 | |
---|
[6501] | 237 | /** |
---|
[8673] | 238 | * GameMenuData constructor |
---|
[7919] | 239 | */ |
---|
[8673] | 240 | GameMenuData::GameMenuData() |
---|
[6501] | 241 | {} |
---|
| 242 | |
---|
| 243 | /** |
---|
[8673] | 244 | * GameMenuData decontructor |
---|
[7919] | 245 | */ |
---|
[8673] | 246 | GameMenuData::~GameMenuData() |
---|
[6501] | 247 | {} |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | /** |
---|
[7919] | 251 | * initialize the GameWorldDataData |
---|
| 252 | */ |
---|
[8673] | 253 | ErrorMessage GameMenuData::init() |
---|
[6502] | 254 | { |
---|
| 255 | /* call underlying function */ |
---|
| 256 | GameWorldData::init(); |
---|
| 257 | } |
---|
[6501] | 258 | |
---|
| 259 | |
---|
| 260 | /** |
---|
[7919] | 261 | * loads the GUI data |
---|
| 262 | * @param root reference to the xml root element |
---|
| 263 | */ |
---|
[8673] | 264 | ErrorMessage GameMenuData::loadGUI(const TiXmlElement* root) |
---|
[6502] | 265 | { |
---|
| 266 | /* call underlying function */ |
---|
| 267 | GameWorldData::loadGUI(root); |
---|
| 268 | } |
---|
[6501] | 269 | |
---|
| 270 | |
---|
| 271 | /** |
---|
[7919] | 272 | * unloads the GUI data |
---|
| 273 | */ |
---|
[8673] | 274 | ErrorMessage GameMenuData::unloadGUI() |
---|
[6502] | 275 | { |
---|
| 276 | /* call underlying function */ |
---|
| 277 | GameWorldData::unloadGUI(); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | |
---|
| 281 | /** |
---|
[7919] | 282 | * overloads the GameWorld::loadWorldEntities(...) class since the menu WorldEntity loading is different (less loading stuff) |
---|
| 283 | * @param root reference to the xml root parameter |
---|
| 284 | */ |
---|
[8673] | 285 | ErrorMessage GameMenuData::loadWorldEntities(const TiXmlElement* root) |
---|
[6502] | 286 | { |
---|
[7370] | 287 | GameWorldData::loadWorldEntities(root); |
---|
[6502] | 288 | } |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | /** |
---|
[7919] | 292 | * unloads the world entities from the xml file |
---|
| 293 | */ |
---|
[8673] | 294 | ErrorMessage GameMenuData::unloadWorldEntities() |
---|
[6502] | 295 | { |
---|
| 296 | /* call underlying function */ |
---|
| 297 | GameWorldData::unloadWorldEntities(); |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | |
---|
| 301 | /** |
---|
[7919] | 302 | * loads the scene data |
---|
| 303 | * @param root reference to the xml root element |
---|
| 304 | */ |
---|
[8673] | 305 | ErrorMessage GameMenuData::loadScene(const TiXmlElement* root) |
---|
[6502] | 306 | { |
---|
| 307 | /* call underlying function */ |
---|
| 308 | GameWorldData::loadScene(root); |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | |
---|
| 312 | /** |
---|
[7919] | 313 | * unloads the scene data |
---|
| 314 | */ |
---|
[8673] | 315 | ErrorMessage GameMenuData::unloadScene() |
---|
[6502] | 316 | { |
---|
| 317 | /* call underlying function */ |
---|
| 318 | GameWorldData::unloadScene(); |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | |
---|
| 322 | |
---|