Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

New class: KeyBinderManager (yes, it really was necessary, I'm not such a Fan of zillions of classes as well) and moved the keybind command to it from GSLevel.
This new Singleton simply maps the keybind command to the right KeyBinder, selected by KeyBinderManager::setCurrent().
There is also a default KeyBinder (with keybindings.ini as file), which should do the Trick for now. Other Keybinders should only server special purposes (like in mini games or so).

DELETE YOUR keybindings.ini FILE! =
  • 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 "util/Clock.h"
34#include "core/input/InputManager.h"
35#include "core/input/InputState.h"
36#include "core/input/KeyBinderManager.h"
37#include "core/Game.h"
38#include "core/ConsoleCommand.h"
39#include "core/GraphicsManager.h"
40#include "core/GUIManager.h"
41#include "Scene.h"
42#include "sound/SoundMainMenu.h"
43
44namespace orxonox
45{
46    DeclareGameState(GSMainMenu, "mainMenu", false, true);
47
48    GSMainMenu::GSMainMenu(const GameStateInfo& info)
49        : GameState(info)
50        , inputState_(0)
51    {
52        inputState_ = InputManager::getInstance().createInputState("mainMenu");
53        inputState_->setHandler(GUIManager::getInstancePtr());
54        inputState_->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
55        inputState_->setJoyStickHandler(&InputHandler::EMPTY);
56        inputState_->setIsExclusiveMouse(false);
57
58        // create an empty Scene
59        this->scene_ = new Scene(0);
60        // and a Camera
61        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
62    }
63
64    GSMainMenu::~GSMainMenu()
65    {
66        InputManager::getInstance().destroyState("mainMenu");
67
68        this->scene_->getSceneManager()->destroyCamera(this->camera_);
69        this->scene_->destroy();
70    }
71
72    void GSMainMenu::activate()
73    {
74        // show main menu
75        GUIManager::getInstance().showGUI("MainMenu");
76        GUIManager::getInstance().setCamera(this->camera_);
77        GraphicsManager::getInstance().setCamera(this->camera_);
78
79        this->ccStartStandalone_ = createConsoleCommand(createFunctor(&GSMainMenu::startStandalone, this), "startGame");
80        CommandExecutor::addConsoleCommandShortcut(this->ccStartStandalone_);
81        this->ccStartServer_ = createConsoleCommand(createFunctor(&GSMainMenu::startServer, this), "startServer");
82        CommandExecutor::addConsoleCommandShortcut(this->ccStartServer_);
83        this->ccStartClient_ = createConsoleCommand(createFunctor(&GSMainMenu::startClient, this), "startClient");
84        CommandExecutor::addConsoleCommandShortcut(this->ccStartClient_);
85        this->ccStartDedicated_ = createConsoleCommand(createFunctor(&GSMainMenu::startDedicated, this), "startDedicated");
86        CommandExecutor::addConsoleCommandShortcut(this->ccStartDedicated_);
87        this->ccStartMainMenu_ = createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu, this), "startMainMenu");
88        CommandExecutor::addConsoleCommandShortcut(this->ccStartMainMenu_);
89
90        KeyBinderManager::getInstance().setToDefault();
91        InputManager::getInstance().enterState("mainMenu");
92
93        this->ambient_ = new SoundMainMenu();
94        this->ambient_->play(true);
95    }
96
97    void GSMainMenu::deactivate()
98    {
99        this->ambient_->destroy();
100
101        InputManager::getInstance().leaveState("mainMenu");
102
103        GUIManager::getInstance().setCamera(0);
104        GraphicsManager::getInstance().setCamera(0);
105
106/*
107        if (this->ccStartGame_)
108        {
109            delete this->ccStartGame_;
110            this->ccStartGame_ = 0;
111        }
112*/
113    }
114
115    void GSMainMenu::update(const Clock& time)
116    {
117    }
118
119    void GSMainMenu::startStandalone()
120    {
121        // HACK - HACK
122        Game::getInstance().popState();
123        Game::getInstance().requestStates("standalone, level");
124    }
125
126    void GSMainMenu::startServer()
127    {
128        // HACK - HACK
129        Game::getInstance().popState();
130        Game::getInstance().requestStates("server, level");
131    }
132
133    void GSMainMenu::startClient()
134    {
135        // HACK - HACK
136        Game::getInstance().popState();
137        Game::getInstance().requestStates("client, level");
138    }
139
140    void GSMainMenu::startDedicated()
141    {
142        // HACK - HACK
143        Game::getInstance().popState();
144        Game::getInstance().popState();
145        Game::getInstance().requestStates("dedicated, level");
146    }
147    void GSMainMenu::startMainMenu()
148    {
149        // HACK - HACK
150        Game::getInstance().popState();
151        Game::getInstance().popState();
152        Game::getInstance().requestStates("mainmenu");
153    }
154}
Note: See TracBrowser for help on using the repository browser.