[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 | |
---|
| 33 | #include "core/input/InputManager.h" |
---|
[3327] | 34 | #include "core/input/InputState.h" |
---|
[5863] | 35 | #include "core/input/KeyBinderManager.h" |
---|
[3196] | 36 | #include "core/Game.h" |
---|
[2844] | 37 | #include "core/ConsoleCommand.h" |
---|
[3370] | 38 | #include "core/GraphicsManager.h" |
---|
| 39 | #include "core/GUIManager.h" |
---|
[5735] | 40 | #include "Scene.h" |
---|
[5896] | 41 | #include "sound/AmbientSound.h" |
---|
[1661] | 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
[3280] | 45 | DeclareGameState(GSMainMenu, "mainMenu", false, true); |
---|
[2844] | 46 | |
---|
[3370] | 47 | GSMainMenu::GSMainMenu(const GameStateInfo& info) |
---|
| 48 | : GameState(info) |
---|
[2850] | 49 | , inputState_(0) |
---|
[1661] | 50 | { |
---|
[3327] | 51 | inputState_ = InputManager::getInstance().createInputState("mainMenu"); |
---|
[5910] | 52 | inputState_->setMouseMode(MouseMode::Nonexclusive); |
---|
[2850] | 53 | inputState_->setHandler(GUIManager::getInstancePtr()); |
---|
[5863] | 54 | inputState_->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler()); |
---|
[3327] | 55 | inputState_->setJoyStickHandler(&InputHandler::EMPTY); |
---|
[1688] | 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); |
---|
[5899] | 66 | this->ambient_->setSource("ambient/mainmenu.wav"); |
---|
[5878] | 67 | } |
---|
[3370] | 68 | } |
---|
[2850] | 69 | |
---|
[3370] | 70 | GSMainMenu::~GSMainMenu() |
---|
| 71 | { |
---|
[5878] | 72 | if (GameMode::playsSound()) |
---|
[5892] | 73 | delete this->ambient_; |
---|
[5878] | 74 | |
---|
[3370] | 75 | InputManager::getInstance().destroyState("mainMenu"); |
---|
| 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 |
---|
[6032] | 84 | GUIManager::getInstance().showGUI("MainMenu", true, false); |
---|
[2850] | 85 | GUIManager::getInstance().setCamera(this->camera_); |
---|
[6032] | 86 | GUIManager::getInstance().setBackground("MainMenuBackground"); |
---|
| 87 | // GUIManager::getInstance().setBackground(""); |
---|
[2850] | 88 | GraphicsManager::getInstance().setCamera(this->camera_); |
---|
[2844] | 89 | |
---|
[5920] | 90 | CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startStandalone), "startGame")); |
---|
| 91 | CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startServer), "startServer")); |
---|
| 92 | CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startClient), "startClient")); |
---|
| 93 | CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startDedicated), "startDedicated")); |
---|
| 94 | CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu), "startMainMenu")); |
---|
| 95 | CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startIOConsole), "startIOConsole")); |
---|
[2853] | 96 | |
---|
[5863] | 97 | KeyBinderManager::getInstance().setToDefault(); |
---|
[3327] | 98 | InputManager::getInstance().enterState("mainMenu"); |
---|
[3060] | 99 | |
---|
[5878] | 100 | if (GameMode::playsSound()) |
---|
| 101 | { |
---|
[5896] | 102 | this->ambient_->setLoop(true); |
---|
| 103 | this->ambient_->play(); |
---|
[5878] | 104 | } |
---|
[1661] | 105 | } |
---|
| 106 | |
---|
[2850] | 107 | void GSMainMenu::deactivate() |
---|
[1661] | 108 | { |
---|
[5878] | 109 | if (GameMode::playsSound()) |
---|
| 110 | { |
---|
| 111 | this->ambient_->stop(); |
---|
| 112 | } |
---|
[3060] | 113 | |
---|
[3327] | 114 | InputManager::getInstance().leaveState("mainMenu"); |
---|
[2850] | 115 | |
---|
[2927] | 116 | GUIManager::getInstance().setCamera(0); |
---|
[6032] | 117 | GUIManager::getInstance().setBackground(""); |
---|
[6024] | 118 | GUIManager::hideGUI("MainMenu"); |
---|
[2927] | 119 | GraphicsManager::getInstance().setCamera(0); |
---|
[1661] | 120 | } |
---|
| 121 | |
---|
[2850] | 122 | void GSMainMenu::update(const Clock& time) |
---|
[1661] | 123 | { |
---|
[2844] | 124 | } |
---|
[1661] | 125 | |
---|
[3094] | 126 | void GSMainMenu::startStandalone() |
---|
[2844] | 127 | { |
---|
| 128 | // HACK - HACK |
---|
| 129 | Game::getInstance().popState(); |
---|
[2850] | 130 | Game::getInstance().requestStates("standalone, level"); |
---|
[1661] | 131 | } |
---|
[3094] | 132 | |
---|
| 133 | void GSMainMenu::startServer() |
---|
| 134 | { |
---|
| 135 | // HACK - HACK |
---|
| 136 | Game::getInstance().popState(); |
---|
| 137 | Game::getInstance().requestStates("server, level"); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | void GSMainMenu::startClient() |
---|
| 141 | { |
---|
| 142 | // HACK - HACK |
---|
| 143 | Game::getInstance().popState(); |
---|
| 144 | Game::getInstance().requestStates("client, level"); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | void GSMainMenu::startDedicated() |
---|
| 148 | { |
---|
| 149 | // HACK - HACK |
---|
| 150 | Game::getInstance().popState(); |
---|
| 151 | Game::getInstance().popState(); |
---|
| 152 | Game::getInstance().requestStates("dedicated, level"); |
---|
| 153 | } |
---|
[5817] | 154 | void GSMainMenu::startMainMenu() |
---|
| 155 | { |
---|
| 156 | // HACK - HACK |
---|
| 157 | Game::getInstance().popState(); |
---|
| 158 | Game::getInstance().popState(); |
---|
| 159 | Game::getInstance().requestStates("mainmenu"); |
---|
| 160 | } |
---|
[5918] | 161 | void GSMainMenu::startIOConsole() |
---|
| 162 | { |
---|
| 163 | // HACK - HACK |
---|
| 164 | Game::getInstance().popState(); |
---|
| 165 | Game::getInstance().popState(); |
---|
| 166 | Game::getInstance().requestStates("ioConsole"); |
---|
| 167 | } |
---|
[1661] | 168 | } |
---|