[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" |
---|
[6117] | 38 | #include "core/ConfigValueIncludes.h" |
---|
[3370] | 39 | #include "core/GraphicsManager.h" |
---|
| 40 | #include "core/GUIManager.h" |
---|
[5735] | 41 | #include "Scene.h" |
---|
[5896] | 42 | #include "sound/AmbientSound.h" |
---|
[1661] | 43 | |
---|
| 44 | namespace orxonox |
---|
| 45 | { |
---|
[3280] | 46 | DeclareGameState(GSMainMenu, "mainMenu", false, true); |
---|
[2844] | 47 | |
---|
[3370] | 48 | GSMainMenu::GSMainMenu(const GameStateInfo& info) |
---|
| 49 | : GameState(info) |
---|
[2850] | 50 | , inputState_(0) |
---|
[1661] | 51 | { |
---|
[6117] | 52 | RegisterRootObject(GSMainMenu); |
---|
[3327] | 53 | inputState_ = InputManager::getInstance().createInputState("mainMenu"); |
---|
[5910] | 54 | inputState_->setMouseMode(MouseMode::Nonexclusive); |
---|
[2850] | 55 | inputState_->setHandler(GUIManager::getInstancePtr()); |
---|
[5863] | 56 | inputState_->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler()); |
---|
[3327] | 57 | inputState_->setJoyStickHandler(&InputHandler::EMPTY); |
---|
[1688] | 58 | |
---|
[2850] | 59 | // create an empty Scene |
---|
[5876] | 60 | this->scene_ = new Scene(NULL); |
---|
[5918] | 61 | this->scene_->setSyncMode( 0x0 ); |
---|
[2850] | 62 | // and a Camera |
---|
| 63 | this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera"); |
---|
[5878] | 64 | if (GameMode::playsSound()) |
---|
| 65 | { |
---|
| 66 | // Load sound |
---|
[5896] | 67 | this->ambient_ = new AmbientSound(0); |
---|
[5878] | 68 | } |
---|
[3370] | 69 | } |
---|
[2850] | 70 | |
---|
[3370] | 71 | GSMainMenu::~GSMainMenu() |
---|
| 72 | { |
---|
[5878] | 73 | if (GameMode::playsSound()) |
---|
[5892] | 74 | delete this->ambient_; |
---|
[5878] | 75 | |
---|
[3370] | 76 | InputManager::getInstance().destroyState("mainMenu"); |
---|
| 77 | |
---|
| 78 | this->scene_->getSceneManager()->destroyCamera(this->camera_); |
---|
[5799] | 79 | this->scene_->destroy(); |
---|
[3370] | 80 | } |
---|
| 81 | |
---|
| 82 | void GSMainMenu::activate() |
---|
| 83 | { |
---|
[1661] | 84 | // show main menu |
---|
[6150] | 85 | GUIManager::getInstance().showGUI("MainMenu", true, false); |
---|
[2850] | 86 | GUIManager::getInstance().setCamera(this->camera_); |
---|
[6150] | 87 | GUIManager::getInstance().setBackground("MainMenuBackground"); |
---|
| 88 | // GUIManager::getInstance().setBackground(""); |
---|
[2850] | 89 | GraphicsManager::getInstance().setCamera(this->camera_); |
---|
[2844] | 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")); |
---|
[6117] | 96 | |
---|
| 97 | // create command to change sound path |
---|
| 98 | CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::setMainMenuSoundPath, this), "setMMSoundPath")); |
---|
[2853] | 99 | |
---|
[5863] | 100 | KeyBinderManager::getInstance().setToDefault(); |
---|
[3327] | 101 | InputManager::getInstance().enterState("mainMenu"); |
---|
[3060] | 102 | |
---|
[6234] | 103 | this->setConfigValues(); |
---|
| 104 | |
---|
[5878] | 105 | if (GameMode::playsSound()) |
---|
| 106 | { |
---|
[6117] | 107 | this->ambient_->setLooping(true); |
---|
[6234] | 108 | this->ambient_->play(); // works without source |
---|
[5878] | 109 | } |
---|
[1661] | 110 | } |
---|
| 111 | |
---|
[2850] | 112 | void GSMainMenu::deactivate() |
---|
[1661] | 113 | { |
---|
[5878] | 114 | if (GameMode::playsSound()) |
---|
| 115 | { |
---|
| 116 | this->ambient_->stop(); |
---|
| 117 | } |
---|
[3060] | 118 | |
---|
[3327] | 119 | InputManager::getInstance().leaveState("mainMenu"); |
---|
[2850] | 120 | |
---|
[2927] | 121 | GUIManager::getInstance().setCamera(0); |
---|
[6150] | 122 | GUIManager::getInstance().setBackground(""); |
---|
| 123 | GUIManager::hideGUI("MainMenu"); |
---|
[2927] | 124 | GraphicsManager::getInstance().setCamera(0); |
---|
[1661] | 125 | } |
---|
| 126 | |
---|
[2850] | 127 | void GSMainMenu::update(const Clock& time) |
---|
[1661] | 128 | { |
---|
[2844] | 129 | } |
---|
[1661] | 130 | |
---|
[6117] | 131 | void GSMainMenu::setConfigValues() |
---|
| 132 | { |
---|
| 133 | SetConfigValue(soundPathMain_, "mainmenu.ogg") |
---|
| 134 | .description("Contains the path to the main menu sound file.") |
---|
| 135 | .callback(this, &GSMainMenu::reloadSound); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | void GSMainMenu::reloadSound() |
---|
| 139 | { |
---|
| 140 | if (GameMode::playsSound()) |
---|
| 141 | { |
---|
| 142 | this->ambient_->setAmbientSource(soundPathMain_); |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | const std::string& GSMainMenu::getMainMenuSoundPath() |
---|
| 147 | { |
---|
| 148 | return soundPathMain_; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | void GSMainMenu::setMainMenuSoundPath(const std::string& path) |
---|
| 152 | { |
---|
| 153 | ModifyConfigValue(soundPathMain_, set, path); |
---|
| 154 | } |
---|
| 155 | |
---|
[3094] | 156 | void GSMainMenu::startStandalone() |
---|
[2844] | 157 | { |
---|
| 158 | // HACK - HACK |
---|
| 159 | Game::getInstance().popState(); |
---|
[2850] | 160 | Game::getInstance().requestStates("standalone, level"); |
---|
[1661] | 161 | } |
---|
[3094] | 162 | |
---|
| 163 | void GSMainMenu::startServer() |
---|
| 164 | { |
---|
| 165 | // HACK - HACK |
---|
| 166 | Game::getInstance().popState(); |
---|
| 167 | Game::getInstance().requestStates("server, level"); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | void GSMainMenu::startClient() |
---|
| 171 | { |
---|
| 172 | // HACK - HACK |
---|
| 173 | Game::getInstance().popState(); |
---|
| 174 | Game::getInstance().requestStates("client, level"); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | void GSMainMenu::startDedicated() |
---|
| 178 | { |
---|
| 179 | // HACK - HACK |
---|
| 180 | Game::getInstance().popState(); |
---|
| 181 | Game::getInstance().popState(); |
---|
[6105] | 182 | Game::getInstance().requestStates("server, level"); |
---|
[3094] | 183 | } |
---|
[5817] | 184 | void GSMainMenu::startMainMenu() |
---|
| 185 | { |
---|
| 186 | // HACK - HACK |
---|
| 187 | Game::getInstance().popState(); |
---|
| 188 | Game::getInstance().popState(); |
---|
| 189 | Game::getInstance().requestStates("mainmenu"); |
---|
| 190 | } |
---|
[1661] | 191 | } |
---|