Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/gamestates/GSMainMenu.cc @ 6916

Last change on this file since 6916 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
RevLine 
[1661]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
[2850]29#include "GSMainMenu.h"
[1661]30
[2850]31#include <OgreSceneManager.h>
[3196]32
[5863]33#include "core/input/KeyBinderManager.h"
[3196]34#include "core/Game.h"
[2844]35#include "core/ConsoleCommand.h"
[6417]36#include "core/ConfigValueIncludes.h"
37#include "core/CoreIncludes.h"
[3370]38#include "core/GraphicsManager.h"
39#include "core/GUIManager.h"
[5735]40#include "Scene.h"
[5896]41#include "sound/AmbientSound.h"
[6746]42// HACK
43#include "core/input/InputManager.h"
44#include "core/input/InputState.h"
[1661]45
46namespace orxonox
47{
[3280]48    DeclareGameState(GSMainMenu, "mainMenu", false, true);
[2844]49
[3370]50    GSMainMenu::GSMainMenu(const GameStateInfo& info)
51        : GameState(info)
[1661]52    {
[6417]53        RegisterRootObject(GSMainMenu);
[1688]54
[6746]55        InputManager::getInstance().createInputState("MainMenuHackery")->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
56
[2850]57        // create an empty Scene
[5876]58        this->scene_ = new Scene(NULL);
[5918]59        this->scene_->setSyncMode( 0x0 );
[2850]60        // and a Camera
61        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
[5878]62        if (GameMode::playsSound())
63        {
64            // Load sound
[5896]65            this->ambient_ = new AmbientSound(0);
[6417]66            this->ambient_->setSyncMode(0x0);
[5878]67        }
[3370]68    }
[2850]69
[3370]70    GSMainMenu::~GSMainMenu()
71    {
[5878]72        if (GameMode::playsSound())
[6417]73            this->ambient_->destroy();
[5878]74
[6746]75        InputManager::getInstance().destroyState("MainMenuHackery");
[3370]76
77        this->scene_->getSceneManager()->destroyCamera(this->camera_);
[5799]78        this->scene_->destroy();
[3370]79    }
80
81    void GSMainMenu::activate()
82    {
[1661]83        // show main menu
[6746]84        GUIManager::getInstance().showGUI("MainMenu", true);
[2850]85        GUIManager::getInstance().setCamera(this->camera_);
[6746]86        GUIManager::getInstance().setBackgroundImage("MainMenuBackground", "Background");
[2850]87        GraphicsManager::getInstance().setCamera(this->camera_);
[2844]88
[6746]89        InputManager::getInstance().enterState("MainMenuHackery");
90
[5920]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"));
[2853]96
[6417]97        // create command to change sound path
98        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::setMainMenuSoundPath, this), "setMMSoundPath"));
99
[5863]100        KeyBinderManager::getInstance().setToDefault();
[3060]101
[6417]102        this->setConfigValues();
103
[5878]104        if (GameMode::playsSound())
105        {
[6417]106            this->ambient_->setLooping(true);
107            this->ambient_->play(); // works without source
[5878]108        }
[1661]109    }
110
[2850]111    void GSMainMenu::deactivate()
[1661]112    {
[5878]113        if (GameMode::playsSound())
114        {
115            this->ambient_->stop();
116        }
[3060]117
[6746]118        InputManager::getInstance().leaveState("MainMenuHackery");
[2850]119
[2927]120        GUIManager::getInstance().setCamera(0);
[6746]121        GUIManager::getInstance().setBackgroundImage("");
[6417]122        GUIManager::hideGUI("MainMenu");
[2927]123        GraphicsManager::getInstance().setCamera(0);
[1661]124    }
125
[2850]126    void GSMainMenu::update(const Clock& time)
[1661]127    {
[2844]128    }
[1661]129
[6417]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
[3094]155    void GSMainMenu::startStandalone()
[2844]156    {
157        // HACK - HACK
158        Game::getInstance().popState();
[2850]159        Game::getInstance().requestStates("standalone, level");
[1661]160    }
[3094]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();
[6105]181        Game::getInstance().requestStates("server, level");
[3094]182    }
[5817]183    void GSMainMenu::startMainMenu()
184    {
185        // HACK - HACK
186        Game::getInstance().popState();
187        Game::getInstance().popState();
188        Game::getInstance().requestStates("mainmenu");
189    }
[1661]190}
Note: See TracBrowser for help on using the repository browser.