Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc @ 5896

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

Added some basic sound classes: WorldSound (to be used for 3D sound, is a WorldEntity) and AmbientSound (BaseObject, just add it somewhere and it will play with playOnLoad=true).
Also moved the sound listener device updating to the HumanController. We might want to modify this again so that the listener is at the camera position again, not at the space ship.

  • Property svn:eol-style set to native
File size: 4.9 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/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        , inputState_(0)
50    {
51        inputState_ = InputManager::getInstance().createInputState("mainMenu");
52        inputState_->setHandler(GUIManager::getInstancePtr());
53        inputState_->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
54        inputState_->setJoyStickHandler(&InputHandler::EMPTY);
55        inputState_->setIsExclusiveMouse(false);
56
57        // create an empty Scene
58        this->scene_ = new Scene(NULL);
59        // and a Camera
60        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
61        if (GameMode::playsSound())
62        {
63            // Load sound
64            this->ambient_ = new AmbientSound(0);
65            this->ambient_->setSoundFile("ambient/mainmenu.wav");
66        }
67    }
68
69    GSMainMenu::~GSMainMenu()
70    {
71        if (GameMode::playsSound())
72            delete this->ambient_;
73
74        InputManager::getInstance().destroyState("mainMenu");
75
76        this->scene_->getSceneManager()->destroyCamera(this->camera_);
77        this->scene_->destroy();
78    }
79
80    void GSMainMenu::activate()
81    {
82        // show main menu
83        GUIManager::getInstance().showGUI("MainMenu");
84        GUIManager::getInstance().setCamera(this->camera_);
85        GraphicsManager::getInstance().setCamera(this->camera_);
86
87        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startStandalone, this), "startGame"));
88        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startServer, this), "startServer"));
89        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startClient, this), "startClient"));
90        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startDedicated, this), "startDedicated"));
91        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu, this), "startMainMenu"));
92
93        KeyBinderManager::getInstance().setToDefault();
94        InputManager::getInstance().enterState("mainMenu");
95
96        if (GameMode::playsSound())
97        {
98            this->ambient_->setLoop(true);
99            this->ambient_->play();
100        }
101    }
102
103    void GSMainMenu::deactivate()
104    {
105        if (GameMode::playsSound())
106        {
107            this->ambient_->stop();
108        }
109
110        InputManager::getInstance().leaveState("mainMenu");
111
112        GUIManager::getInstance().setCamera(0);
113        GraphicsManager::getInstance().setCamera(0);
114    }
115
116    void GSMainMenu::update(const Clock& time)
117    {
118    }
119
120    void GSMainMenu::startStandalone()
121    {
122        // HACK - HACK
123        Game::getInstance().popState();
124        Game::getInstance().requestStates("standalone, level");
125    }
126
127    void GSMainMenu::startServer()
128    {
129        // HACK - HACK
130        Game::getInstance().popState();
131        Game::getInstance().requestStates("server, level");
132    }
133
134    void GSMainMenu::startClient()
135    {
136        // HACK - HACK
137        Game::getInstance().popState();
138        Game::getInstance().requestStates("client, level");
139    }
140
141    void GSMainMenu::startDedicated()
142    {
143        // HACK - HACK
144        Game::getInstance().popState();
145        Game::getInstance().popState();
146        Game::getInstance().requestStates("dedicated, level");
147    }
148    void GSMainMenu::startMainMenu()
149    {
150        // HACK - HACK
151        Game::getInstance().popState();
152        Game::getInstance().popState();
153        Game::getInstance().requestStates("mainmenu");
154    }
155}
Note: See TracBrowser for help on using the repository browser.