Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/gamestates/GSMainMenu.cc @ 7856

Last change on this file since 7856 was 7854, checked in by landauf, 14 years ago

detached AmbientSound from BaseObject - AmbientSound can not be placed directly in a level file anymore
instead added WorldAmbientSound, a BaseObject which can be placed in a level file to create and control ambient sound

with this change, the level can be destroyed completely because WorldAmbientSound can be deleted immediately at the end of the level, while the AmbientSound remains active until it faded out.

  • Property svn:eol-style set to native
File size: 6.9 KB
RevLine 
[1661]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[2850]29#include "GSMainMenu.h"
[1661]30
[2850]31#include <OgreSceneManager.h>
[3196]32
[5863]33#include "core/input/KeyBinderManager.h"
[3196]34#include "core/Game.h"
[6417]35#include "core/ConfigValueIncludes.h"
36#include "core/CoreIncludes.h"
[3370]37#include "core/GraphicsManager.h"
38#include "core/GUIManager.h"
[7284]39#include "core/command/ConsoleCommand.h"
[5735]40#include "Scene.h"
[5896]41#include "sound/AmbientSound.h"
[6746]42// HACK
43#include "core/input/InputManager.h"
44#include "core/input/InputState.h"
[1661]45
46namespace orxonox
47{
[3280]48    DeclareGameState(GSMainMenu, "mainMenu", false, true);
[2844]49
[7284]50    static const std::string __CC_startStandalone_name      = "startGame";
51    static const std::string __CC_startServer_name          = "startServer";
52    static const std::string __CC_startClient_name          = "startClient";
53    static const std::string __CC_startDedicated_name       = "startDedicated";
54    static const std::string __CC_startMainMenu_name        = "startMainMenu";
55    static const std::string __CC_setMainMenuSoundPath_name = "setMMSoundPath";
56
57    SetConsoleCommand(__CC_startStandalone_name,      &GSMainMenu::startStandalone).deactivate();
58    SetConsoleCommand(__CC_startServer_name,          &GSMainMenu::startServer    ).deactivate();
59    SetConsoleCommand(__CC_startClient_name,          &GSMainMenu::startClient    ).deactivate();
60    SetConsoleCommand(__CC_startDedicated_name,       &GSMainMenu::startDedicated ).deactivate();
61    SetConsoleCommand(__CC_startMainMenu_name,        &GSMainMenu::startMainMenu  ).deactivate();
62    SetConsoleCommand(__CC_setMainMenuSoundPath_name, &GSMainMenu::setMainMenuSoundPath).hide();
63
[3370]64    GSMainMenu::GSMainMenu(const GameStateInfo& info)
65        : GameState(info)
[1661]66    {
[6417]67        RegisterRootObject(GSMainMenu);
[1688]68
[7689]69        InputManager::getInstance().createInputState("MainMenuHackery", true, true)->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
[6746]70
[2850]71        // create an empty Scene
[5876]72        this->scene_ = new Scene(NULL);
[5918]73        this->scene_->setSyncMode( 0x0 );
[2850]74        // and a Camera
75        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
[5878]76        if (GameMode::playsSound())
77        {
78            // Load sound
[7854]79            this->ambient_ = new AmbientSound();
[5878]80        }
[3370]81    }
[2850]82
[3370]83    GSMainMenu::~GSMainMenu()
84    {
[5878]85        if (GameMode::playsSound())
[6417]86            this->ambient_->destroy();
[5878]87
[6746]88        InputManager::getInstance().destroyState("MainMenuHackery");
[3370]89
90        this->scene_->getSceneManager()->destroyCamera(this->camera_);
[5799]91        this->scene_->destroy();
[3370]92    }
93
94    void GSMainMenu::activate()
95    {
[1661]96        // show main menu
[6746]97        GUIManager::getInstance().showGUI("MainMenu", true);
[2850]98        GUIManager::getInstance().setCamera(this->camera_);
[6746]99        GUIManager::getInstance().setBackgroundImage("MainMenuBackground", "Background");
[2850]100        GraphicsManager::getInstance().setCamera(this->camera_);
[2844]101
[6746]102        InputManager::getInstance().enterState("MainMenuHackery");
103
[7284]104        ModifyConsoleCommand(__CC_startStandalone_name).activate();
105        ModifyConsoleCommand(__CC_startServer_name    ).activate();
106        ModifyConsoleCommand(__CC_startClient_name    ).activate();
107        ModifyConsoleCommand(__CC_startDedicated_name ).activate();
108        ModifyConsoleCommand(__CC_startMainMenu_name  ).activate();
109        ModifyConsoleCommand(__CC_setMainMenuSoundPath_name).setObject(this);
[2853]110
[5863]111        KeyBinderManager::getInstance().setToDefault();
[3060]112
[6417]113        this->setConfigValues();
114
[5878]115        if (GameMode::playsSound())
116        {
[6417]117            this->ambient_->setLooping(true);
118            this->ambient_->play(); // works without source
[5878]119        }
[1661]120    }
121
[2850]122    void GSMainMenu::deactivate()
[1661]123    {
[5878]124        if (GameMode::playsSound())
125        {
126            this->ambient_->stop();
127        }
[3060]128
[6746]129        InputManager::getInstance().leaveState("MainMenuHackery");
[2850]130
[2927]131        GUIManager::getInstance().setCamera(0);
[6746]132        GUIManager::getInstance().setBackgroundImage("");
[6417]133        GUIManager::hideGUI("MainMenu");
[2927]134        GraphicsManager::getInstance().setCamera(0);
[7284]135
136        ModifyConsoleCommand(__CC_startStandalone_name).deactivate();
137        ModifyConsoleCommand(__CC_startServer_name    ).deactivate();
138        ModifyConsoleCommand(__CC_startClient_name    ).deactivate();
139        ModifyConsoleCommand(__CC_startDedicated_name ).deactivate();
140        ModifyConsoleCommand(__CC_startMainMenu_name  ).deactivate();
141        ModifyConsoleCommand(__CC_setMainMenuSoundPath_name).setObject(0);
[1661]142    }
143
[2850]144    void GSMainMenu::update(const Clock& time)
[1661]145    {
[2844]146    }
[1661]147
[6417]148    void GSMainMenu::setConfigValues()
149    {
150        SetConfigValue(soundPathMain_, "mainmenu.ogg")
151            .description("Contains the path to the main menu sound file.")
152            .callback(this, &GSMainMenu::reloadSound);
153    }
154
155    void GSMainMenu::reloadSound()
156    {
157        if (GameMode::playsSound())
158        {
159            this->ambient_->setAmbientSource(soundPathMain_);
160        }
161    }
162
163    const std::string& GSMainMenu::getMainMenuSoundPath()
164    {
165        return soundPathMain_;
166    }
167
168    void GSMainMenu::setMainMenuSoundPath(const std::string& path)
169    {
170        ModifyConfigValue(soundPathMain_, set, path);
171    }
172
[3094]173    void GSMainMenu::startStandalone()
[2844]174    {
175        // HACK - HACK
176        Game::getInstance().popState();
[2850]177        Game::getInstance().requestStates("standalone, level");
[1661]178    }
[3094]179
180    void GSMainMenu::startServer()
181    {
182        // HACK - HACK
183        Game::getInstance().popState();
184        Game::getInstance().requestStates("server, level");
185    }
186
187    void GSMainMenu::startClient()
188    {
189        // HACK - HACK
190        Game::getInstance().popState();
191        Game::getInstance().requestStates("client, level");
192    }
193
194    void GSMainMenu::startDedicated()
195    {
196        // HACK - HACK
197        Game::getInstance().popState();
198        Game::getInstance().popState();
[6105]199        Game::getInstance().requestStates("server, level");
[3094]200    }
[5817]201    void GSMainMenu::startMainMenu()
202    {
203        // HACK - HACK
204        Game::getInstance().popState();
205        Game::getInstance().popState();
206        Game::getInstance().requestStates("mainmenu");
207    }
[1661]208}
Note: See TracBrowser for help on using the repository browser.