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