Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ingamemenu/src/orxonox/gamestates/GSMainMenu.cc @ 6020

Last change on this file since 6020 was 6020, checked in by scheusso, 15 years ago

fixed an issue with the OS/CEGUI mouse pointer

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