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.
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"
49 using GUI::CommandSender
;
50 using GUI::StaticTextWidget
;
52 using GUI::WIDGET_ENABLED
;
54 typedef GUI::OptionsDialog GUI_OptionsDialog
;
55 typedef GUI::Dialog GUI_Dialog
;
69 MainMenuDialog::MainMenuDialog(Engine
*engine
)
70 : GUI::Dialog("GlobalMenu"), _engine(engine
) {
71 _backgroundType
= GUI::ThemeEngine::kDialogBackgroundSpecial
;
73 #ifndef DISABLE_FANCY_THEMES
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
));
80 StaticTextWidget
*title
= new StaticTextWidget(this, "GlobalMenu.Title", "ScummVM");
81 title
->setAlign(Graphics::kTextAlignCenter
);
84 StaticTextWidget
*title
= new StaticTextWidget(this, "GlobalMenu.Title", "ScummVM");
85 title
->setAlign(Graphics::kTextAlignCenter
);
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() {
121 delete _optionsDialog
;
126 void MainMenuDialog::handleCommand(CommandSender
*sender
, uint32 cmd
, uint32 data
) {
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());
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
);
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());
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.
165 snprintf(buf
, 20, "Save %d", slot
+ 1);
166 _engine
->saveGameState(slot
, buf
);
168 _engine
->saveGameState(slot
, result
.c_str());
177 _optionsDialog
->runModal();
180 _aboutDialog
->runModal();
183 Common::Event eventRTL
;
184 eventRTL
.type
= Common::EVENT_RTL
;
185 g_system
->getEventManager()->pushEvent(eventRTL
);
190 Common::Event eventQ
;
191 eventQ
.type
= Common::EVENT_QUIT
;
192 g_system
->getEventManager()->pushEvent(eventQ
);
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()) {
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");
221 GUI::StaticTextWidget
*title
= (StaticTextWidget
*)findWidget("GlobalMenu.Title");
223 title
= new StaticTextWidget(this, "GlobalMenu.Title", "ScummVM");
224 title
->setAlign(Graphics::kTextAlignCenter
);
236 Dialog::reflowLayout();
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") {
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
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');
305 ConfigDialog::~ConfigDialog() {
306 #ifdef SMALL_SCREEN_DEVICE
311 void ConfigDialog::handleCommand(CommandSender
*sender
, uint32 cmd
, uint32 data
) {
315 #ifdef SMALL_SCREEN_DEVICE
317 // Create the sub dialog(s)
319 _keysDialog
= new GUI::KeysDialog();
320 _keysDialog
->runModal();
326 GUI_OptionsDialog::handleCommand (sender
, cmd
, data
);