Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutorial/src/orxonox/gamestates/GSMainMenu.cc @ 9215

Last change on this file since 9215 was 8051, checked in by dafrick, 14 years ago

Merging latest changes in usability branch into tutorial branch.

  • Property svn:eol-style set to native
File size: 7.5 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
[6417]33#include "core/ConfigValueIncludes.h"
34#include "core/CoreIncludes.h"
[7876]35#include "core/Game.h"
[3370]36#include "core/GraphicsManager.h"
37#include "core/GUIManager.h"
[7284]38#include "core/command/ConsoleCommand.h"
[7876]39#include "core/input/KeyBinderManager.h"
40#include "network/Client.h"
41#include "util/StringUtils.h"
42#include "LevelManager.h"
[5735]43#include "Scene.h"
[5896]44#include "sound/AmbientSound.h"
[6746]45// HACK
46#include "core/input/InputManager.h"
47#include "core/input/InputState.h"
[1661]48
49namespace orxonox
50{
[3280]51    DeclareGameState(GSMainMenu, "mainMenu", false, true);
[2844]52
[7284]53    static const std::string __CC_startStandalone_name      = "startGame";
54    static const std::string __CC_startServer_name          = "startServer";
55    static const std::string __CC_startClient_name          = "startClient";
56    static const std::string __CC_startDedicated_name       = "startDedicated";
57    static const std::string __CC_setMainMenuSoundPath_name = "setMMSoundPath";
58
[7978]59    SetConsoleCommand(__CC_startStandalone_name,      &GSMainMenu::startStandalone).defaultValues("").deactivate();
60    SetConsoleCommand(__CC_startServer_name,          &GSMainMenu::startServer    ).defaultValues("").deactivate();
61    SetConsoleCommand(__CC_startClient_name,          &GSMainMenu::startClient    ).defaultValues("").deactivate();
62    SetConsoleCommand(__CC_startDedicated_name,       &GSMainMenu::startDedicated ).defaultValues("").deactivate();
[7284]63    SetConsoleCommand(__CC_setMainMenuSoundPath_name, &GSMainMenu::setMainMenuSoundPath).hide();
64
[3370]65    GSMainMenu::GSMainMenu(const GameStateInfo& info)
66        : GameState(info)
[1661]67    {
[6417]68        RegisterRootObject(GSMainMenu);
[1688]69
[8051]70        InputManager::getInstance().createInputState("MainMenuHackery")->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
[6746]71
[2850]72        // create an empty Scene
[5876]73        this->scene_ = new Scene(NULL);
[5918]74        this->scene_->setSyncMode( 0x0 );
[2850]75        // and a Camera
76        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
[5878]77        if (GameMode::playsSound())
78        {
79            // Load sound
[7854]80            this->ambient_ = new AmbientSound();
[5878]81        }
[3370]82    }
[2850]83
[3370]84    GSMainMenu::~GSMainMenu()
85    {
[5878]86        if (GameMode::playsSound())
[6417]87            this->ambient_->destroy();
[5878]88
[6746]89        InputManager::getInstance().destroyState("MainMenuHackery");
[3370]90
91        this->scene_->getSceneManager()->destroyCamera(this->camera_);
[5799]92        this->scene_->destroy();
[3370]93    }
94
95    void GSMainMenu::activate()
96    {
[1661]97        // show main menu
[7966]98        GraphicsManager::getInstance().setCamera(this->camera_);
[6746]99        GUIManager::getInstance().showGUI("MainMenu", true);
100        GUIManager::getInstance().setBackgroundImage("MainMenuBackground", "Background");
[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_setMainMenuSoundPath_name).setObject(this);
[2853]109
[5863]110        KeyBinderManager::getInstance().setToDefault();
[3060]111
[6417]112        this->setConfigValues();
113
[5878]114        if (GameMode::playsSound())
115        {
[6417]116            this->ambient_->setLooping(true);
117            this->ambient_->play(); // works without source
[5878]118        }
[1661]119    }
120
[2850]121    void GSMainMenu::deactivate()
[1661]122    {
[5878]123        if (GameMode::playsSound())
124        {
125            this->ambient_->stop();
126        }
[3060]127
[6746]128        InputManager::getInstance().leaveState("MainMenuHackery");
[2850]129
[7966]130        GraphicsManager::getInstance().setCamera(0);
[6746]131        GUIManager::getInstance().setBackgroundImage("");
[6417]132        GUIManager::hideGUI("MainMenu");
[7284]133
134        ModifyConsoleCommand(__CC_startStandalone_name).deactivate();
135        ModifyConsoleCommand(__CC_startServer_name    ).deactivate();
136        ModifyConsoleCommand(__CC_startClient_name    ).deactivate();
137        ModifyConsoleCommand(__CC_startDedicated_name ).deactivate();
138        ModifyConsoleCommand(__CC_setMainMenuSoundPath_name).setObject(0);
[1661]139    }
140
[2850]141    void GSMainMenu::update(const Clock& time)
[1661]142    {
[2844]143    }
[1661]144
[6417]145    void GSMainMenu::setConfigValues()
146    {
147        SetConfigValue(soundPathMain_, "mainmenu.ogg")
148            .description("Contains the path to the main menu sound file.")
149            .callback(this, &GSMainMenu::reloadSound);
150    }
151
152    void GSMainMenu::reloadSound()
153    {
154        if (GameMode::playsSound())
155        {
156            this->ambient_->setAmbientSource(soundPathMain_);
157        }
158    }
159
160    const std::string& GSMainMenu::getMainMenuSoundPath()
161    {
162        return soundPathMain_;
163    }
164
165    void GSMainMenu::setMainMenuSoundPath(const std::string& path)
166    {
167        ModifyConfigValue(soundPathMain_, set, path);
168    }
169
[7876]170    /**
171    @brief
172        Start a level in standalone mode.
173    @param level
174        The filename of the level to be started. If empty, the default level is started.
175    */
176    void GSMainMenu::startStandalone(const std::string& level)
[2844]177    {
[7978]178        if(level != "")
[7876]179            LevelManager::getInstance().setDefaultLevel(level);
180
181        // HACK
[2844]182        Game::getInstance().popState();
[2850]183        Game::getInstance().requestStates("standalone, level");
[1661]184    }
[3094]185
[7876]186    /**
187    @brief
188        Start a level in server mode.
189    @param level
190        The filename of the level to be started. If empty, the default level is started.
191    */
192    void GSMainMenu::startServer(const std::string& level)
[3094]193    {
[7978]194        if(level != "")
[7876]195            LevelManager::getInstance().setDefaultLevel(level);
196
197        // HACK
[3094]198        Game::getInstance().popState();
199        Game::getInstance().requestStates("server, level");
200    }
201
[7876]202    /**
203    @brief
204        Connect to a game as client.
205    @param destination
206        The destination to connect to. If empty, the client connects to the default destination.
207    */
208    void GSMainMenu::startClient(const std::string& destination)
[3094]209    {
[7978]210        if(destination != "")
[7876]211            Client::getInstance()->setDestination(destination, NETWORK_PORT);
212
213        // HACK
[3094]214        Game::getInstance().popState();
215        Game::getInstance().requestStates("client, level");
216    }
217
[7876]218    /**
219    @brief
220        Start a level in dedicated mode.
221    @param level
222        The filename of the level to be started. If empty, the default level is started.
223    */
224    void GSMainMenu::startDedicated(const std::string& level)
[3094]225    {
[7978]226        if(level != "")
[7876]227            LevelManager::getInstance().setDefaultLevel(level);
228
229        // HACK
[3094]230        Game::getInstance().popState();
231        Game::getInstance().popState();
[6105]232        Game::getInstance().requestStates("server, level");
[3094]233    }
[7876]234
[1661]235}
Note: See TracBrowser for help on using the repository browser.