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
Line 
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
29#include "GSMainMenu.h"
30
31#include <OgreSceneManager.h>
32
33#include "core/input/KeyBinderManager.h"
34#include "core/Game.h"
35#include "core/ConsoleCommand.h"
36#include "core/ConfigValueIncludes.h"
37#include "core/CoreIncludes.h"
38#include "core/GraphicsManager.h"
39#include "core/GUIManager.h"
40#include "Scene.h"
41#include "sound/AmbientSound.h"
42
43namespace orxonox
44{
45    DeclareGameState(GSMainMenu, "mainMenu", false, true);
46
47    GSMainMenu::GSMainMenu(const GameStateInfo& info)
48        : GameState(info)
49    {
50        RegisterRootObject(GSMainMenu);
51
52        // create an empty Scene
53        this->scene_ = new Scene(NULL);
54        this->scene_->setSyncMode( 0x0 );
55        // and a Camera
56        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
57        if (GameMode::playsSound())
58        {
59            // Load sound
60            this->ambient_ = new AmbientSound(0);
61            this->ambient_->setSyncMode(0x0);
62        }
63    }
64
65    GSMainMenu::~GSMainMenu()
66    {
67        if (GameMode::playsSound())
68            this->ambient_->destroy();
69
70        this->scene_->getSceneManager()->destroyCamera(this->camera_);
71        this->scene_->destroy();
72    }
73
74    void GSMainMenu::activate()
75    {
76        // show main menu
77        GUIManager::getInstance().showGUI("MainMenu", true);
78        GUIManager::getInstance().setCamera(this->camera_);
79        GUIManager::getInstance().setBackgroundImage("MainMenuBackground", "Background");
80        GraphicsManager::getInstance().setCamera(this->camera_);
81
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"));
87
88        // create command to change sound path
89        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::setMainMenuSoundPath, this), "setMMSoundPath"));
90
91        KeyBinderManager::getInstance().setToDefault();
92
93        this->setConfigValues();
94
95        if (GameMode::playsSound())
96        {
97            this->ambient_->setLooping(true);
98            this->ambient_->play(); // works without source
99        }
100    }
101
102    void GSMainMenu::deactivate()
103    {
104        if (GameMode::playsSound())
105        {
106            this->ambient_->stop();
107        }
108
109        GUIManager::getInstance().setCamera(0);
110        GUIManager::getInstance().setBackgroundImage("");
111        GUIManager::hideGUI("MainMenu");
112        GraphicsManager::getInstance().setCamera(0);
113    }
114
115    void GSMainMenu::update(const Clock& time)
116    {
117    }
118
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
144    void GSMainMenu::startStandalone()
145    {
146        // HACK - HACK
147        Game::getInstance().popState();
148        Game::getInstance().requestStates("standalone, level");
149    }
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();
170        Game::getInstance().requestStates("server, level");
171    }
172    void GSMainMenu::startMainMenu()
173    {
174        // HACK - HACK
175        Game::getInstance().popState();
176        Game::getInstance().popState();
177        Game::getInstance().requestStates("mainmenu");
178    }
179}
Note: See TracBrowser for help on using the repository browser.