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