Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/modules/gamestates/GSMainMenu.cc @ 5831

Last change on this file since 5831 was 5829, checked in by landauf, 15 years ago

replaced most occurrences of setObject(o) in combination with createFunctor(f) with the more convenient createFunctor(f, o)

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