Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gamestates2/src/orxonox/gamestates/GSMainMenu.cc @ 6741

Last change on this file since 6741 was 6741, checked in by rgrieder, 14 years ago

Removed obsolete InputState from GSMainMenu.

  • Property svn:eol-style set to native
File size: 5.4 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"
[2844]35#include "core/ConsoleCommand.h"
[6417]36#include "core/ConfigValueIncludes.h"
37#include "core/CoreIncludes.h"
[3370]38#include "core/GraphicsManager.h"
39#include "core/GUIManager.h"
[5735]40#include "Scene.h"
[5896]41#include "sound/AmbientSound.h"
[1661]42
43namespace orxonox
44{
[3280]45    DeclareGameState(GSMainMenu, "mainMenu", false, true);
[2844]46
[3370]47    GSMainMenu::GSMainMenu(const GameStateInfo& info)
48        : GameState(info)
[1661]49    {
[6417]50        RegisterRootObject(GSMainMenu);
[1688]51
[2850]52        // create an empty Scene
[5876]53        this->scene_ = new Scene(NULL);
[5918]54        this->scene_->setSyncMode( 0x0 );
[2850]55        // and a Camera
56        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
[5878]57        if (GameMode::playsSound())
58        {
59            // Load sound
[5896]60            this->ambient_ = new AmbientSound(0);
[6417]61            this->ambient_->setSyncMode(0x0);
[5878]62        }
[3370]63    }
[2850]64
[3370]65    GSMainMenu::~GSMainMenu()
66    {
[5878]67        if (GameMode::playsSound())
[6417]68            this->ambient_->destroy();
[5878]69
[3370]70        this->scene_->getSceneManager()->destroyCamera(this->camera_);
[5799]71        this->scene_->destroy();
[3370]72    }
73
74    void GSMainMenu::activate()
75    {
[1661]76        // show main menu
[6722]77        GUIManager::getInstance().showGUI("MainMenu", true);
[2850]78        GUIManager::getInstance().setCamera(this->camera_);
[6739]79        GUIManager::getInstance().setBackgroundImage("MainMenuBackground", "Background");
[2850]80        GraphicsManager::getInstance().setCamera(this->camera_);
[2844]81
[5920]82        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startStandalone), "startGame"));
83        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startServer), "startServer"));
84        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startClient), "startClient"));
85        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startDedicated), "startDedicated"));
86        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu), "startMainMenu"));
[2853]87
[6417]88        // create command to change sound path
89        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::setMainMenuSoundPath, this), "setMMSoundPath"));
90
[5863]91        KeyBinderManager::getInstance().setToDefault();
[3060]92
[6417]93        this->setConfigValues();
94
[5878]95        if (GameMode::playsSound())
96        {
[6417]97            this->ambient_->setLooping(true);
98            this->ambient_->play(); // works without source
[5878]99        }
[1661]100    }
101
[2850]102    void GSMainMenu::deactivate()
[1661]103    {
[5878]104        if (GameMode::playsSound())
105        {
106            this->ambient_->stop();
107        }
[3060]108
[2927]109        GUIManager::getInstance().setCamera(0);
[6739]110        GUIManager::getInstance().setBackgroundImage("");
[6417]111        GUIManager::hideGUI("MainMenu");
[2927]112        GraphicsManager::getInstance().setCamera(0);
[1661]113    }
114
[2850]115    void GSMainMenu::update(const Clock& time)
[1661]116    {
[2844]117    }
[1661]118
[6417]119    void GSMainMenu::setConfigValues()
120    {
121        SetConfigValue(soundPathMain_, "mainmenu.ogg")
122            .description("Contains the path to the main menu sound file.")
123            .callback(this, &GSMainMenu::reloadSound);
124    }
125
126    void GSMainMenu::reloadSound()
127    {
128        if (GameMode::playsSound())
129        {
130            this->ambient_->setAmbientSource(soundPathMain_);
131        }
132    }
133
134    const std::string& GSMainMenu::getMainMenuSoundPath()
135    {
136        return soundPathMain_;
137    }
138
139    void GSMainMenu::setMainMenuSoundPath(const std::string& path)
140    {
141        ModifyConfigValue(soundPathMain_, set, path);
142    }
143
[3094]144    void GSMainMenu::startStandalone()
[2844]145    {
146        // HACK - HACK
147        Game::getInstance().popState();
[2850]148        Game::getInstance().requestStates("standalone, level");
[1661]149    }
[3094]150
151    void GSMainMenu::startServer()
152    {
153        // HACK - HACK
154        Game::getInstance().popState();
155        Game::getInstance().requestStates("server, level");
156    }
157
158    void GSMainMenu::startClient()
159    {
160        // HACK - HACK
161        Game::getInstance().popState();
162        Game::getInstance().requestStates("client, level");
163    }
164
165    void GSMainMenu::startDedicated()
166    {
167        // HACK - HACK
168        Game::getInstance().popState();
169        Game::getInstance().popState();
[6105]170        Game::getInstance().requestStates("server, level");
[3094]171    }
[5817]172    void GSMainMenu::startMainMenu()
173    {
174        // HACK - HACK
175        Game::getInstance().popState();
176        Game::getInstance().popState();
177        Game::getInstance().requestStates("mainmenu");
178    }
[1661]179}
Note: See TracBrowser for help on using the repository browser.