0x47 stub
[scummvm-innocent.git] / engines / dialogs.cpp
bloba923379c814e26a2f2f3547f73a63f0a6d7464c2
1 /* ScummVM - Graphic Adventure Engine
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * $URL$
22 * $Id$
25 #include "base/version.h"
27 #include "common/config-manager.h"
28 #include "common/savefile.h"
29 #include "common/system.h"
30 #include "common/events.h"
32 #include "graphics/scaler.h"
34 #include "gui/about.h"
35 #include "gui/GuiManager.h"
36 #include "gui/launcher.h"
37 #include "gui/ListWidget.h"
38 #include "gui/ThemeEval.h"
39 #include "gui/saveload.h"
41 #include "engines/dialogs.h"
42 #include "engines/engine.h"
43 #include "engines/metaengine.h"
45 #ifdef SMALL_SCREEN_DEVICE
46 #include "gui/KeysDialog.h"
47 #endif
49 using GUI::CommandSender;
50 using GUI::StaticTextWidget;
51 using GUI::kCloseCmd;
52 using GUI::WIDGET_ENABLED;
54 typedef GUI::OptionsDialog GUI_OptionsDialog;
55 typedef GUI::Dialog GUI_Dialog;
57 enum {
58 kSaveCmd = 'SAVE',
59 kLoadCmd = 'LOAD',
60 kPlayCmd = 'PLAY',
61 kOptionsCmd = 'OPTN',
62 kHelpCmd = 'HELP',
63 kAboutCmd = 'ABOU',
64 kQuitCmd = 'QUIT',
65 kRTLCmd = 'RTL ',
66 kChooseCmd = 'CHOS'
69 MainMenuDialog::MainMenuDialog(Engine *engine)
70 : GUI::Dialog("GlobalMenu"), _engine(engine) {
71 _backgroundType = GUI::ThemeEngine::kDialogBackgroundSpecial;
73 #ifndef DISABLE_FANCY_THEMES
74 _logo = 0;
75 if (g_gui.xmlEval()->getVar("Globals.ShowGlobalMenuLogo", 0) == 1 && g_gui.theme()->supportsImages()) {
76 _logo = new GUI::GraphicsWidget(this, "GlobalMenu.Logo");
77 _logo->useThemeTransparency(true);
78 _logo->setGfx(g_gui.theme()->getImageSurface(GUI::ThemeEngine::kImageLogoSmall));
79 } else {
80 StaticTextWidget *title = new StaticTextWidget(this, "GlobalMenu.Title", "ScummVM");
81 title->setAlign(Graphics::kTextAlignCenter);
83 #else
84 StaticTextWidget *title = new StaticTextWidget(this, "GlobalMenu.Title", "ScummVM");
85 title->setAlign(Graphics::kTextAlignCenter);
86 #endif
88 StaticTextWidget *version = new StaticTextWidget(this, "GlobalMenu.Version", gScummVMVersionDate);
89 version->setAlign(Graphics::kTextAlignCenter);
91 new GUI::ButtonWidget(this, "GlobalMenu.Resume", "Resume", kPlayCmd, 'P');
93 _loadButton = new GUI::ButtonWidget(this, "GlobalMenu.Load", "Load", kLoadCmd, 'L');
94 // TODO: setEnabled -> setVisible
95 _loadButton->setEnabled(_engine->hasFeature(Engine::kSupportsLoadingDuringRuntime));
97 _saveButton = new GUI::ButtonWidget(this, "GlobalMenu.Save", "Save", kSaveCmd, 'S');
98 // TODO: setEnabled -> setVisible
99 _saveButton->setEnabled(_engine->hasFeature(Engine::kSupportsSavingDuringRuntime));
101 new GUI::ButtonWidget(this, "GlobalMenu.Options", "Options", kOptionsCmd, 'O');
103 new GUI::ButtonWidget(this, "GlobalMenu.About", "About", kAboutCmd, 'A');
105 _rtlButton = new GUI::ButtonWidget(this, "GlobalMenu.RTL", "Return to Launcher", kRTLCmd, 'R');
106 _rtlButton->setEnabled(_engine->hasFeature(Engine::kSupportsRTL));
109 new GUI::ButtonWidget(this, "GlobalMenu.Quit", "Quit", kQuitCmd, 'Q');
111 _aboutDialog = new GUI::AboutDialog();
112 _optionsDialog = new ConfigDialog(_engine->hasFeature(Engine::kSupportsSubtitleOptions));
113 _loadDialog = new GUI::SaveLoadChooser("Load game:", "Load");
114 _loadDialog->setSaveMode(false);
115 _saveDialog = new GUI::SaveLoadChooser("Save game:", "Save");
116 _saveDialog->setSaveMode(true);
119 MainMenuDialog::~MainMenuDialog() {
120 delete _aboutDialog;
121 delete _optionsDialog;
122 delete _loadDialog;
123 delete _saveDialog;
126 void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
127 switch (cmd) {
128 case kPlayCmd:
129 close();
130 break;
131 case kLoadCmd:
133 Common::String gameId = ConfMan.get("gameid");
135 const EnginePlugin *plugin = 0;
136 EngineMan.findGame(gameId, &plugin);
138 int slot = _loadDialog->runModal(plugin, ConfMan.getActiveDomainName());
140 if (slot >= 0) {
141 // FIXME: For now we just ignore the return
142 // value, which is quite bad since it could
143 // be a fatal loading error, which renders
144 // the engine unusable.
145 _engine->loadGameState(slot);
146 close();
150 break;
151 case kSaveCmd:
153 Common::String gameId = ConfMan.get("gameid");
155 const EnginePlugin *plugin = 0;
156 EngineMan.findGame(gameId, &plugin);
158 int slot = _saveDialog->runModal(plugin, ConfMan.getActiveDomainName());
160 if (slot >= 0) {
161 Common::String result(_saveDialog->getResultString());
162 if (result.empty()) {
163 // If the user was lazy and entered no save name, come up with a default name.
164 char buf[20];
165 snprintf(buf, 20, "Save %d", slot + 1);
166 _engine->saveGameState(slot, buf);
167 } else {
168 _engine->saveGameState(slot, result.c_str());
171 close();
175 break;
176 case kOptionsCmd:
177 _optionsDialog->runModal();
178 break;
179 case kAboutCmd:
180 _aboutDialog->runModal();
181 break;
182 case kRTLCmd: {
183 Common::Event eventRTL;
184 eventRTL.type = Common::EVENT_RTL;
185 g_system->getEventManager()->pushEvent(eventRTL);
186 close();
188 break;
189 case kQuitCmd: {
190 Common::Event eventQ;
191 eventQ.type = Common::EVENT_QUIT;
192 g_system->getEventManager()->pushEvent(eventQ);
193 close();
195 break;
196 default:
197 GUI::Dialog::handleCommand(sender, cmd, data);
201 void MainMenuDialog::reflowLayout() {
202 if (_engine->hasFeature(Engine::kSupportsLoadingDuringRuntime))
203 _loadButton->setEnabled(_engine->canLoadGameStateCurrently());
204 if (_engine->hasFeature(Engine::kSupportsSavingDuringRuntime))
205 _saveButton->setEnabled(_engine->canSaveGameStateCurrently());
207 #ifndef DISABLE_FANCY_THEMES
208 if (g_gui.xmlEval()->getVar("Globals.ShowGlobalMenuLogo", 0) == 1 && g_gui.theme()->supportsImages()) {
209 if (!_logo)
210 _logo = new GUI::GraphicsWidget(this, "GlobalMenu.Logo");
211 _logo->useThemeTransparency(true);
212 _logo->setGfx(g_gui.theme()->getImageSurface(GUI::ThemeEngine::kImageLogoSmall));
214 GUI::StaticTextWidget *title = (StaticTextWidget *)findWidget("GlobalMenu.Title");
215 if (title) {
216 removeWidget(title);
217 title->setNext(0);
218 delete title;
220 } else {
221 GUI::StaticTextWidget *title = (StaticTextWidget *)findWidget("GlobalMenu.Title");
222 if (!title) {
223 title = new StaticTextWidget(this, "GlobalMenu.Title", "ScummVM");
224 title->setAlign(Graphics::kTextAlignCenter);
227 if (_logo) {
228 removeWidget(_logo);
229 _logo->setNext(0);
230 delete _logo;
231 _logo = 0;
234 #endif
236 Dialog::reflowLayout();
239 enum {
240 kOKCmd = 'ok '
243 enum {
244 kKeysCmd = 'KEYS'
247 // FIXME: We use the empty string as domain name here. This tells the
248 // ConfigManager to use the 'default' domain for all its actions. We do that
249 // to get as close as possible to editing the 'active' settings.
251 // However, that requires bad & evil hacks in the ConfigManager code,
252 // and even then still doesn't work quite correctly.
253 // For example, if the transient domain contains 'false' for the 'fullscreen'
254 // flag, but the user used a hotkey to switch to windowed mode, then the dialog
255 // will display the wrong value anyway.
257 // Proposed solution consisting of multiple steps:
258 // 1) Add special code to the open() code that reads out everything stored
259 // in the transient domain that is controlled by this dialog, and updates
260 // the dialog accordingly.
261 // 2) Even more code is added to query the backend for current settings, like
262 // the fullscreen mode flag etc., and also updates the dialog accordingly.
263 // 3) The domain being edited is set to the active game domain.
264 // 4) If the dialog is closed with the "OK" button, then we remove everything
265 // stored in the transient domain (or at least everything corresponding to
266 // switches in this dialog.
267 // If OTOH the dialog is closed with "Cancel" we do no such thing.
269 // These changes will achieve two things at once: Allow us to get rid of using
270 // "" as value for the domain, and in fact provide a somewhat better user
271 // experience at the same time.
272 ConfigDialog::ConfigDialog(bool subtitleControls)
273 : GUI::OptionsDialog("", "ScummConfig") {
276 // Sound controllers
279 addVolumeControls(this, "ScummConfig.");
280 setVolumeSettingsState(true); // could disable controls by GUI options
283 // Subtitle speed and toggle controllers
286 if (subtitleControls) {
287 // Global talkspeed range of 0-255
288 addSubtitleControls(this, "ScummConfig.", 255);
289 setSubtitleSettingsState(true); // could disable controls by GUI options
293 // Add the buttons
296 new GUI::ButtonWidget(this, "ScummConfig.Ok", "OK", GUI::OptionsDialog::kOKCmd, 'O');
297 new GUI::ButtonWidget(this, "ScummConfig.Cancel", "Cancel", kCloseCmd, 'C');
299 #ifdef SMALL_SCREEN_DEVICE
300 new GUI::ButtonWidget(this, "ScummConfig.Keys", "Keys", kKeysCmd, 'K');
301 _keysDialog = NULL;
302 #endif
305 ConfigDialog::~ConfigDialog() {
306 #ifdef SMALL_SCREEN_DEVICE
307 delete _keysDialog;
308 #endif
311 void ConfigDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
312 switch (cmd) {
313 case kKeysCmd:
315 #ifdef SMALL_SCREEN_DEVICE
317 // Create the sub dialog(s)
319 _keysDialog = new GUI::KeysDialog();
320 _keysDialog->runModal();
321 delete _keysDialog;
322 _keysDialog = NULL;
323 #endif
324 break;
325 default:
326 GUI_OptionsDialog::handleCommand (sender, cmd, data);