Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/orxonox/gamestates/GSMainMenu.cc @ 6829

Last change on this file since 6829 was 6387, checked in by rgrieder, 15 years ago

Found some non empty new lines.

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