[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 | |
---|
[9667] | 33 | #include "core/config/ConfigValueIncludes.h" |
---|
[6417] | 34 | #include "core/CoreIncludes.h" |
---|
[7876] | 35 | #include "core/Game.h" |
---|
[3370] | 36 | #include "core/GraphicsManager.h" |
---|
| 37 | #include "core/GUIManager.h" |
---|
[10624] | 38 | #include "core/command/ConsoleCommandIncludes.h" |
---|
[7876] | 39 | #include "core/input/KeyBinderManager.h" |
---|
| 40 | #include "network/Client.h" |
---|
| 41 | #include "util/StringUtils.h" |
---|
| 42 | #include "LevelManager.h" |
---|
[5735] | 43 | #include "Scene.h" |
---|
[5896] | 44 | #include "sound/AmbientSound.h" |
---|
[6746] | 45 | // HACK |
---|
| 46 | #include "core/input/InputManager.h" |
---|
| 47 | #include "core/input/InputState.h" |
---|
[1661] | 48 | |
---|
| 49 | namespace orxonox |
---|
| 50 | { |
---|
[3280] | 51 | DeclareGameState(GSMainMenu, "mainMenu", false, true); |
---|
[2844] | 52 | |
---|
[7284] | 53 | static const std::string __CC_startStandalone_name = "startGame"; |
---|
| 54 | static const std::string __CC_startServer_name = "startServer"; |
---|
| 55 | static const std::string __CC_startClient_name = "startClient"; |
---|
| 56 | static const std::string __CC_startDedicated_name = "startDedicated"; |
---|
| 57 | static const std::string __CC_setMainMenuSoundPath_name = "setMMSoundPath"; |
---|
| 58 | |
---|
[8079] | 59 | SetConsoleCommand(__CC_startStandalone_name, &GSMainMenu::startStandalone).defaultValues("").deactivate(); |
---|
| 60 | SetConsoleCommand(__CC_startServer_name, &GSMainMenu::startServer ).defaultValues("").deactivate(); |
---|
| 61 | SetConsoleCommand(__CC_startClient_name, &GSMainMenu::startClient ).defaultValues("").deactivate(); |
---|
| 62 | SetConsoleCommand(__CC_startDedicated_name, &GSMainMenu::startDedicated ).defaultValues("").deactivate(); |
---|
[7284] | 63 | SetConsoleCommand(__CC_setMainMenuSoundPath_name, &GSMainMenu::setMainMenuSoundPath).hide(); |
---|
| 64 | |
---|
[10624] | 65 | RegisterAbstractClass(GSMainMenu).inheritsFrom<Configurable>(); |
---|
| 66 | |
---|
[3370] | 67 | GSMainMenu::GSMainMenu(const GameStateInfo& info) |
---|
| 68 | : GameState(info) |
---|
[1661] | 69 | { |
---|
[9667] | 70 | RegisterObject(GSMainMenu); |
---|
[1688] | 71 | |
---|
[7689] | 72 | InputManager::getInstance().createInputState("MainMenuHackery", true, true)->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler()); |
---|
[6746] | 73 | |
---|
[2850] | 74 | // create an empty Scene |
---|
[11071] | 75 | this->scene_ = new Scene(nullptr); |
---|
[5918] | 76 | this->scene_->setSyncMode( 0x0 ); |
---|
[2850] | 77 | // and a Camera |
---|
| 78 | this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera"); |
---|
[5878] | 79 | if (GameMode::playsSound()) |
---|
| 80 | { |
---|
| 81 | // Load sound |
---|
[7854] | 82 | this->ambient_ = new AmbientSound(); |
---|
[5878] | 83 | } |
---|
[3370] | 84 | } |
---|
[2850] | 85 | |
---|
[3370] | 86 | GSMainMenu::~GSMainMenu() |
---|
| 87 | { |
---|
[5878] | 88 | if (GameMode::playsSound()) |
---|
[9944] | 89 | this->ambient_->destroy(); |
---|
[5878] | 90 | |
---|
[6746] | 91 | InputManager::getInstance().destroyState("MainMenuHackery"); |
---|
[3370] | 92 | |
---|
| 93 | this->scene_->getSceneManager()->destroyCamera(this->camera_); |
---|
[5799] | 94 | this->scene_->destroy(); |
---|
[3370] | 95 | } |
---|
| 96 | |
---|
| 97 | void GSMainMenu::activate() |
---|
| 98 | { |
---|
[8858] | 99 | orxout(user_status) << "Loading main menu" << endl; |
---|
| 100 | |
---|
[1661] | 101 | // show main menu |
---|
[8079] | 102 | GraphicsManager::getInstance().setCamera(this->camera_); |
---|
[6746] | 103 | GUIManager::getInstance().showGUI("MainMenu", true); |
---|
| 104 | GUIManager::getInstance().setBackgroundImage("MainMenuBackground", "Background"); |
---|
[2844] | 105 | |
---|
[6746] | 106 | InputManager::getInstance().enterState("MainMenuHackery"); |
---|
| 107 | |
---|
[7284] | 108 | ModifyConsoleCommand(__CC_startStandalone_name).activate(); |
---|
| 109 | ModifyConsoleCommand(__CC_startServer_name ).activate(); |
---|
| 110 | ModifyConsoleCommand(__CC_startClient_name ).activate(); |
---|
| 111 | ModifyConsoleCommand(__CC_startDedicated_name ).activate(); |
---|
| 112 | ModifyConsoleCommand(__CC_setMainMenuSoundPath_name).setObject(this); |
---|
[2853] | 113 | |
---|
[5863] | 114 | KeyBinderManager::getInstance().setToDefault(); |
---|
[3060] | 115 | |
---|
[6417] | 116 | this->setConfigValues(); |
---|
| 117 | |
---|
[5878] | 118 | if (GameMode::playsSound()) |
---|
| 119 | { |
---|
[6417] | 120 | this->ambient_->setLooping(true); |
---|
| 121 | this->ambient_->play(); // works without source |
---|
[5878] | 122 | } |
---|
[1661] | 123 | } |
---|
| 124 | |
---|
[2850] | 125 | void GSMainMenu::deactivate() |
---|
[1661] | 126 | { |
---|
[5878] | 127 | if (GameMode::playsSound()) |
---|
| 128 | { |
---|
| 129 | this->ambient_->stop(); |
---|
| 130 | } |
---|
[3060] | 131 | |
---|
[6746] | 132 | InputManager::getInstance().leaveState("MainMenuHackery"); |
---|
[2850] | 133 | |
---|
[11071] | 134 | GraphicsManager::getInstance().setCamera(nullptr); |
---|
[6746] | 135 | GUIManager::getInstance().setBackgroundImage(""); |
---|
[6417] | 136 | GUIManager::hideGUI("MainMenu"); |
---|
[7284] | 137 | |
---|
| 138 | ModifyConsoleCommand(__CC_startStandalone_name).deactivate(); |
---|
| 139 | ModifyConsoleCommand(__CC_startServer_name ).deactivate(); |
---|
| 140 | ModifyConsoleCommand(__CC_startClient_name ).deactivate(); |
---|
| 141 | ModifyConsoleCommand(__CC_startDedicated_name ).deactivate(); |
---|
[11071] | 142 | ModifyConsoleCommand(__CC_setMainMenuSoundPath_name).setObject(nullptr); |
---|
[1661] | 143 | } |
---|
| 144 | |
---|
[2850] | 145 | void GSMainMenu::update(const Clock& time) |
---|
[1661] | 146 | { |
---|
[2844] | 147 | } |
---|
[1661] | 148 | |
---|
[6417] | 149 | void GSMainMenu::setConfigValues() |
---|
| 150 | { |
---|
| 151 | SetConfigValue(soundPathMain_, "mainmenu.ogg") |
---|
| 152 | .description("Contains the path to the main menu sound file.") |
---|
| 153 | .callback(this, &GSMainMenu::reloadSound); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | void GSMainMenu::reloadSound() |
---|
| 157 | { |
---|
| 158 | if (GameMode::playsSound()) |
---|
| 159 | { |
---|
| 160 | this->ambient_->setAmbientSource(soundPathMain_); |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | const std::string& GSMainMenu::getMainMenuSoundPath() |
---|
| 165 | { |
---|
| 166 | return soundPathMain_; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | void GSMainMenu::setMainMenuSoundPath(const std::string& path) |
---|
| 170 | { |
---|
| 171 | ModifyConfigValue(soundPathMain_, set, path); |
---|
| 172 | } |
---|
| 173 | |
---|
[7876] | 174 | /** |
---|
| 175 | @brief |
---|
| 176 | Start a level in standalone mode. |
---|
| 177 | @param level |
---|
| 178 | The filename of the level to be started. If empty, the default level is started. |
---|
| 179 | */ |
---|
| 180 | void GSMainMenu::startStandalone(const std::string& level) |
---|
[2844] | 181 | { |
---|
[8079] | 182 | if(level != "") |
---|
[7876] | 183 | LevelManager::getInstance().setDefaultLevel(level); |
---|
| 184 | |
---|
| 185 | // HACK |
---|
[2844] | 186 | Game::getInstance().popState(); |
---|
[2850] | 187 | Game::getInstance().requestStates("standalone, level"); |
---|
[1661] | 188 | } |
---|
[3094] | 189 | |
---|
[7876] | 190 | /** |
---|
| 191 | @brief |
---|
| 192 | Start a level in server mode. |
---|
| 193 | @param level |
---|
| 194 | The filename of the level to be started. If empty, the default level is started. |
---|
| 195 | */ |
---|
| 196 | void GSMainMenu::startServer(const std::string& level) |
---|
[3094] | 197 | { |
---|
[8079] | 198 | if(level != "") |
---|
[7876] | 199 | LevelManager::getInstance().setDefaultLevel(level); |
---|
| 200 | |
---|
| 201 | // HACK |
---|
[3094] | 202 | Game::getInstance().popState(); |
---|
| 203 | Game::getInstance().requestStates("server, level"); |
---|
| 204 | } |
---|
| 205 | |
---|
[7876] | 206 | /** |
---|
| 207 | @brief |
---|
| 208 | Connect to a game as client. |
---|
| 209 | @param destination |
---|
| 210 | The destination to connect to. If empty, the client connects to the default destination. |
---|
| 211 | */ |
---|
| 212 | void GSMainMenu::startClient(const std::string& destination) |
---|
[3094] | 213 | { |
---|
[8079] | 214 | if(destination != "") |
---|
[7876] | 215 | Client::getInstance()->setDestination(destination, NETWORK_PORT); |
---|
| 216 | |
---|
| 217 | // HACK |
---|
[3094] | 218 | Game::getInstance().popState(); |
---|
| 219 | Game::getInstance().requestStates("client, level"); |
---|
| 220 | } |
---|
| 221 | |
---|
[7876] | 222 | /** |
---|
| 223 | @brief |
---|
| 224 | Start a level in dedicated mode. |
---|
| 225 | @param level |
---|
| 226 | The filename of the level to be started. If empty, the default level is started. |
---|
| 227 | */ |
---|
| 228 | void GSMainMenu::startDedicated(const std::string& level) |
---|
[3094] | 229 | { |
---|
[8079] | 230 | if(level != "") |
---|
[7876] | 231 | LevelManager::getInstance().setDefaultLevel(level); |
---|
| 232 | |
---|
| 233 | // HACK |
---|
[3094] | 234 | Game::getInstance().popState(); |
---|
| 235 | Game::getInstance().popState(); |
---|
[6105] | 236 | Game::getInstance().requestStates("server, level"); |
---|
[3094] | 237 | } |
---|
[7876] | 238 | |
---|
[1661] | 239 | } |
---|