Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickup5/src/orxonox/gamestates/GSMainMenu.cc @ 6858

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

Merged gamestates2 branch back to trunk.
This brings in some heavy changes in the GUI framework.
It should also fix problems with triggered asserts in the InputManager.

Note: PickupInventory does not seem to work —> Segfault when showing because before, the owner in GUIOverlay::setGUIName is already NULL.
I haven't tested it before, so I can't tell whether it's my changes.

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