2008-06-24 23:19:23 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
2009-01-01 15:06:43 +00:00
|
|
|
* $Id$
|
2008-06-24 23:19:23 +00:00
|
|
|
*/
|
|
|
|
|
2008-08-17 02:02:22 +00:00
|
|
|
#include "base/version.h"
|
|
|
|
|
2008-06-24 23:19:23 +00:00
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/savefile.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/events.h"
|
|
|
|
|
|
|
|
#include "graphics/scaler.h"
|
|
|
|
|
|
|
|
#include "gui/about.h"
|
2009-01-02 03:21:40 +00:00
|
|
|
#include "gui/GuiManager.h"
|
2008-11-03 18:32:16 +00:00
|
|
|
#include "gui/launcher.h"
|
2008-06-24 23:19:23 +00:00
|
|
|
#include "gui/ListWidget.h"
|
2008-11-08 01:30:32 +00:00
|
|
|
#include "gui/ThemeEval.h"
|
2008-11-11 12:13:55 +00:00
|
|
|
#include "gui/saveload.h"
|
2008-06-24 23:19:23 +00:00
|
|
|
|
|
|
|
#include "engines/dialogs.h"
|
|
|
|
#include "engines/engine.h"
|
2008-08-16 02:53:16 +00:00
|
|
|
#include "engines/metaengine.h"
|
2008-06-24 23:19:23 +00:00
|
|
|
|
|
|
|
#ifdef SMALL_SCREEN_DEVICE
|
|
|
|
#include "gui/KeysDialog.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using GUI::CommandSender;
|
|
|
|
using GUI::StaticTextWidget;
|
|
|
|
using GUI::kCloseCmd;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kSaveCmd = 'SAVE',
|
|
|
|
kLoadCmd = 'LOAD',
|
|
|
|
kPlayCmd = 'PLAY',
|
|
|
|
kOptionsCmd = 'OPTN',
|
|
|
|
kHelpCmd = 'HELP',
|
|
|
|
kAboutCmd = 'ABOU',
|
|
|
|
kQuitCmd = 'QUIT',
|
2008-09-05 14:11:23 +00:00
|
|
|
kRTLCmd = 'RTL ',
|
2008-06-24 23:19:23 +00:00
|
|
|
kChooseCmd = 'CHOS'
|
|
|
|
};
|
|
|
|
|
|
|
|
MainMenuDialog::MainMenuDialog(Engine *engine)
|
2008-11-12 12:50:21 +00:00
|
|
|
: GUI::Dialog("GlobalMenu"), _engine(engine) {
|
2008-11-10 11:24:55 +00:00
|
|
|
_backgroundType = GUI::ThemeEngine::kDialogBackgroundSpecial;
|
2008-06-24 23:19:23 +00:00
|
|
|
|
2008-09-14 20:42:50 +00:00
|
|
|
#ifndef DISABLE_FANCY_THEMES
|
|
|
|
_logo = 0;
|
2008-09-20 12:36:58 +00:00
|
|
|
if (g_gui.xmlEval()->getVar("Globals.ShowGlobalMenuLogo", 0) == 1 && g_gui.theme()->supportsImages()) {
|
|
|
|
_logo = new GUI::GraphicsWidget(this, "GlobalMenu.Logo");
|
2008-09-14 20:42:50 +00:00
|
|
|
_logo->useThemeTransparency(true);
|
2008-11-10 11:24:55 +00:00
|
|
|
_logo->setGfx(g_gui.theme()->getImageSurface(GUI::ThemeEngine::kImageLogoSmall));
|
2008-09-14 20:42:50 +00:00
|
|
|
} else {
|
2008-09-20 16:07:00 +00:00
|
|
|
StaticTextWidget *title = new StaticTextWidget(this, "GlobalMenu.Title", "ScummVM");
|
2008-11-12 14:30:16 +00:00
|
|
|
title->setAlign(Graphics::kTextAlignCenter);
|
2008-09-14 20:42:50 +00:00
|
|
|
}
|
|
|
|
#else
|
2008-09-20 16:07:00 +00:00
|
|
|
StaticTextWidget *title = new StaticTextWidget(this, "GlobalMenu.Title", "ScummVM");
|
2008-11-12 14:30:16 +00:00
|
|
|
title->setAlign(Graphics::kTextAlignCenter);
|
2008-09-14 20:42:50 +00:00
|
|
|
#endif
|
2008-08-17 02:02:22 +00:00
|
|
|
|
2008-09-20 16:07:00 +00:00
|
|
|
StaticTextWidget *version = new StaticTextWidget(this, "GlobalMenu.Version", gScummVMVersionDate);
|
2008-11-12 14:30:16 +00:00
|
|
|
version->setAlign(Graphics::kTextAlignCenter);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-20 12:36:58 +00:00
|
|
|
new GUI::ButtonWidget(this, "GlobalMenu.Resume", "Resume", kPlayCmd, 'P');
|
2008-06-24 23:19:23 +00:00
|
|
|
|
2008-11-03 18:32:16 +00:00
|
|
|
_loadButton = new GUI::ButtonWidget(this, "GlobalMenu.Load", "Load", kLoadCmd, 'L');
|
|
|
|
// TODO: setEnabled -> setVisible
|
2008-11-04 16:11:40 +00:00
|
|
|
_loadButton->setEnabled(_engine->hasFeature(Engine::kSupportsLoadingDuringRuntime));
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-11-03 18:32:16 +00:00
|
|
|
_saveButton = new GUI::ButtonWidget(this, "GlobalMenu.Save", "Save", kSaveCmd, 'S');
|
|
|
|
// TODO: setEnabled -> setVisible
|
2008-11-04 16:11:40 +00:00
|
|
|
_saveButton->setEnabled(_engine->hasFeature(Engine::kSupportsSavingDuringRuntime));
|
2008-06-24 23:19:23 +00:00
|
|
|
|
2008-09-20 12:36:58 +00:00
|
|
|
new GUI::ButtonWidget(this, "GlobalMenu.Options", "Options", kOptionsCmd, 'O');
|
2008-06-24 23:19:23 +00:00
|
|
|
|
2008-09-20 12:36:58 +00:00
|
|
|
new GUI::ButtonWidget(this, "GlobalMenu.About", "About", kAboutCmd, 'A');
|
2008-06-24 23:19:23 +00:00
|
|
|
|
2009-01-01 15:06:43 +00:00
|
|
|
_rtlButton = new GUI::ButtonWidget(this, "GlobalMenu.RTL", "Return to Launcher", kRTLCmd, 'R');
|
2008-10-06 12:48:52 +00:00
|
|
|
_rtlButton->setEnabled(_engine->hasFeature(Engine::kSupportsRTL));
|
2008-08-16 02:53:16 +00:00
|
|
|
|
|
|
|
|
2008-09-20 12:36:58 +00:00
|
|
|
new GUI::ButtonWidget(this, "GlobalMenu.Quit", "Quit", kQuitCmd, 'Q');
|
2008-06-24 23:19:23 +00:00
|
|
|
|
|
|
|
_aboutDialog = new GUI::AboutDialog();
|
2009-02-07 06:47:19 +00:00
|
|
|
_optionsDialog = new ConfigDialog(_engine->hasFeature(Engine::kSupportsSubtitleOptions));
|
2008-11-03 18:32:16 +00:00
|
|
|
_loadDialog = new GUI::SaveLoadChooser("Load game:", "Load");
|
2008-11-07 19:43:01 +00:00
|
|
|
_loadDialog->setSaveMode(false);
|
2008-11-06 20:26:19 +00:00
|
|
|
_saveDialog = new GUI::SaveLoadChooser("Save game:", "Save");
|
|
|
|
_saveDialog->setSaveMode(true);
|
2008-06-24 23:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainMenuDialog::~MainMenuDialog() {
|
|
|
|
delete _aboutDialog;
|
|
|
|
delete _optionsDialog;
|
2008-11-03 18:32:16 +00:00
|
|
|
delete _loadDialog;
|
2008-11-06 20:26:19 +00:00
|
|
|
delete _saveDialog;
|
2008-06-24 23:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
|
|
|
switch (cmd) {
|
|
|
|
case kPlayCmd:
|
|
|
|
close();
|
|
|
|
break;
|
2008-11-03 18:32:16 +00:00
|
|
|
case kLoadCmd:
|
|
|
|
{
|
2008-11-06 15:41:38 +00:00
|
|
|
Common::String gameId = ConfMan.get("gameid");
|
2008-11-03 18:32:16 +00:00
|
|
|
|
|
|
|
const EnginePlugin *plugin = 0;
|
|
|
|
EngineMan.findGame(gameId, &plugin);
|
|
|
|
|
|
|
|
int slot = _loadDialog->runModal(plugin, ConfMan.getActiveDomainName());
|
|
|
|
|
|
|
|
if (slot >= 0) {
|
2008-11-03 20:00:36 +00:00
|
|
|
// FIXME: For now we just ignore the return
|
|
|
|
// value, which is quite bad since it could
|
|
|
|
// be a fatal loading error, which renders
|
|
|
|
// the engine unusable.
|
2008-11-03 18:32:16 +00:00
|
|
|
_engine->loadGameState(slot);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kSaveCmd:
|
2008-11-06 20:26:19 +00:00
|
|
|
{
|
2008-11-06 15:41:38 +00:00
|
|
|
Common::String gameId = ConfMan.get("gameid");
|
2008-11-03 18:32:16 +00:00
|
|
|
|
|
|
|
const EnginePlugin *plugin = 0;
|
|
|
|
EngineMan.findGame(gameId, &plugin);
|
|
|
|
|
|
|
|
int slot = _saveDialog->runModal(plugin, ConfMan.getActiveDomainName());
|
|
|
|
|
|
|
|
if (slot >= 0) {
|
2008-11-09 17:53:37 +00:00
|
|
|
Common::String result(_saveDialog->getResultString());
|
2008-11-06 20:26:19 +00:00
|
|
|
if (result.empty()) {
|
|
|
|
// If the user was lazy and entered no save name, come up with a default name.
|
2008-11-09 09:58:59 +00:00
|
|
|
char buf[20];
|
2008-11-09 12:16:51 +00:00
|
|
|
snprintf(buf, 20, "Save %d", slot + 1);
|
|
|
|
_engine->saveGameState(slot, buf);
|
2008-11-06 20:26:19 +00:00
|
|
|
} else {
|
2008-11-09 12:16:51 +00:00
|
|
|
_engine->saveGameState(slot, result.c_str());
|
2008-11-06 20:26:19 +00:00
|
|
|
}
|
|
|
|
|
2008-11-03 18:32:16 +00:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
2008-06-24 23:19:23 +00:00
|
|
|
case kOptionsCmd:
|
|
|
|
_optionsDialog->runModal();
|
|
|
|
break;
|
|
|
|
case kAboutCmd:
|
|
|
|
_aboutDialog->runModal();
|
|
|
|
break;
|
2008-07-09 02:27:05 +00:00
|
|
|
case kRTLCmd: {
|
|
|
|
Common::Event eventRTL;
|
|
|
|
eventRTL.type = Common::EVENT_RTL;
|
|
|
|
g_system->getEventManager()->pushEvent(eventRTL);
|
2008-06-24 23:19:23 +00:00
|
|
|
close();
|
2009-01-01 15:06:43 +00:00
|
|
|
}
|
2008-06-24 23:19:23 +00:00
|
|
|
break;
|
2008-07-09 02:27:05 +00:00
|
|
|
case kQuitCmd: {
|
|
|
|
Common::Event eventQ;
|
|
|
|
eventQ.type = Common::EVENT_QUIT;
|
|
|
|
g_system->getEventManager()->pushEvent(eventQ);
|
2008-06-24 23:19:23 +00:00
|
|
|
close();
|
2008-07-09 02:27:05 +00:00
|
|
|
}
|
2008-06-24 23:19:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-11-12 12:50:21 +00:00
|
|
|
GUI::Dialog::handleCommand(sender, cmd, data);
|
2008-06-24 23:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-14 20:42:50 +00:00
|
|
|
void MainMenuDialog::reflowLayout() {
|
2009-01-01 15:06:43 +00:00
|
|
|
if (_engine->hasFeature(Engine::kSupportsLoadingDuringRuntime))
|
2008-11-04 16:11:40 +00:00
|
|
|
_loadButton->setEnabled(_engine->canLoadGameStateCurrently());
|
|
|
|
if (_engine->hasFeature(Engine::kSupportsSavingDuringRuntime))
|
|
|
|
_saveButton->setEnabled(_engine->canSaveGameStateCurrently());
|
2008-11-03 18:32:16 +00:00
|
|
|
|
2008-09-14 20:42:50 +00:00
|
|
|
#ifndef DISABLE_FANCY_THEMES
|
2008-09-20 12:36:58 +00:00
|
|
|
if (g_gui.xmlEval()->getVar("Globals.ShowGlobalMenuLogo", 0) == 1 && g_gui.theme()->supportsImages()) {
|
2008-09-14 20:42:50 +00:00
|
|
|
if (!_logo)
|
2008-09-20 12:36:58 +00:00
|
|
|
_logo = new GUI::GraphicsWidget(this, "GlobalMenu.Logo");
|
2008-09-14 20:42:50 +00:00
|
|
|
_logo->useThemeTransparency(true);
|
2008-11-10 11:24:55 +00:00
|
|
|
_logo->setGfx(g_gui.theme()->getImageSurface(GUI::ThemeEngine::kImageLogoSmall));
|
2008-09-14 20:42:50 +00:00
|
|
|
|
2008-09-20 12:36:58 +00:00
|
|
|
GUI::StaticTextWidget *title = (StaticTextWidget *)findWidget("GlobalMenu.Title");
|
2008-09-14 20:42:50 +00:00
|
|
|
if (title) {
|
|
|
|
removeWidget(title);
|
|
|
|
title->setNext(0);
|
|
|
|
delete title;
|
|
|
|
}
|
|
|
|
} else {
|
2008-09-20 12:36:58 +00:00
|
|
|
GUI::StaticTextWidget *title = (StaticTextWidget *)findWidget("GlobalMenu.Title");
|
2008-09-20 16:07:00 +00:00
|
|
|
if (!title) {
|
|
|
|
title = new StaticTextWidget(this, "GlobalMenu.Title", "ScummVM");
|
2008-11-12 14:30:16 +00:00
|
|
|
title->setAlign(Graphics::kTextAlignCenter);
|
2008-09-20 16:07:00 +00:00
|
|
|
}
|
2008-09-14 20:42:50 +00:00
|
|
|
|
|
|
|
if (_logo) {
|
|
|
|
removeWidget(_logo);
|
|
|
|
_logo->setNext(0);
|
|
|
|
delete _logo;
|
|
|
|
_logo = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Dialog::reflowLayout();
|
|
|
|
}
|
|
|
|
|
2008-06-24 23:19:23 +00:00
|
|
|
enum {
|
|
|
|
kOKCmd = 'ok '
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kKeysCmd = 'KEYS'
|
|
|
|
};
|
|
|
|
|
2008-08-05 22:02:24 +00:00
|
|
|
// FIXME: We use the empty string as domain name here. This tells the
|
|
|
|
// ConfigManager to use the 'default' domain for all its actions. We do that
|
|
|
|
// to get as close as possible to editing the 'active' settings.
|
|
|
|
//
|
|
|
|
// However, that requires bad & evil hacks in the ConfigManager code,
|
|
|
|
// and even then still doesn't work quite correctly.
|
|
|
|
// For example, if the transient domain contains 'false' for the 'fullscreen'
|
|
|
|
// flag, but the user used a hotkey to switch to windowed mode, then the dialog
|
|
|
|
// will display the wrong value anyway.
|
|
|
|
//
|
|
|
|
// Proposed solution consisting of multiple steps:
|
|
|
|
// 1) Add special code to the open() code that reads out everything stored
|
|
|
|
// in the transient domain that is controlled by this dialog, and updates
|
|
|
|
// the dialog accordingly.
|
|
|
|
// 2) Even more code is added to query the backend for current settings, like
|
|
|
|
// the fullscreen mode flag etc., and also updates the dialog accordingly.
|
|
|
|
// 3) The domain being edited is set to the active game domain.
|
|
|
|
// 4) If the dialog is closed with the "OK" button, then we remove everything
|
|
|
|
// stored in the transient domain (or at least everything corresponding to
|
|
|
|
// switches in this dialog.
|
|
|
|
// If OTOH the dialog is closed with "Cancel" we do no such thing.
|
|
|
|
//
|
|
|
|
// These changes will achieve two things at once: Allow us to get rid of using
|
|
|
|
// "" as value for the domain, and in fact provide a somewhat better user
|
|
|
|
// experience at the same time.
|
2009-02-07 06:47:19 +00:00
|
|
|
ConfigDialog::ConfigDialog(bool subtitleControls)
|
2008-09-20 12:36:58 +00:00
|
|
|
: GUI::OptionsDialog("", "ScummConfig") {
|
2008-06-24 23:19:23 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Sound controllers
|
|
|
|
//
|
|
|
|
|
2008-09-20 12:36:58 +00:00
|
|
|
addVolumeControls(this, "ScummConfig.");
|
2009-06-06 17:58:08 +00:00
|
|
|
setVolumeSettingsState(true); // could disable controls by GUI options
|
2008-06-24 23:19:23 +00:00
|
|
|
|
|
|
|
//
|
2009-02-07 06:47:19 +00:00
|
|
|
// Subtitle speed and toggle controllers
|
2008-06-24 23:19:23 +00:00
|
|
|
//
|
|
|
|
|
2009-02-07 06:47:19 +00:00
|
|
|
if (subtitleControls) {
|
|
|
|
// Global talkspeed range of 0-255
|
|
|
|
addSubtitleControls(this, "ScummConfig.", 255);
|
2009-06-06 17:58:08 +00:00
|
|
|
setSubtitleSettingsState(true); // could disable controls by GUI options
|
2009-02-07 06:47:19 +00:00
|
|
|
}
|
2008-06-24 23:19:23 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Add the buttons
|
|
|
|
//
|
|
|
|
|
2008-09-20 12:36:58 +00:00
|
|
|
new GUI::ButtonWidget(this, "ScummConfig.Ok", "OK", GUI::OptionsDialog::kOKCmd, 'O');
|
|
|
|
new GUI::ButtonWidget(this, "ScummConfig.Cancel", "Cancel", kCloseCmd, 'C');
|
2008-06-24 23:19:23 +00:00
|
|
|
|
|
|
|
#ifdef SMALL_SCREEN_DEVICE
|
2008-09-20 12:36:58 +00:00
|
|
|
new GUI::ButtonWidget(this, "ScummConfig.Keys", "Keys", kKeysCmd, 'K');
|
2009-02-28 21:05:21 +00:00
|
|
|
_keysDialog = NULL;
|
2008-06-24 23:19:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigDialog::~ConfigDialog() {
|
|
|
|
#ifdef SMALL_SCREEN_DEVICE
|
|
|
|
delete _keysDialog;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
|
|
|
switch (cmd) {
|
|
|
|
case kKeysCmd:
|
|
|
|
|
|
|
|
#ifdef SMALL_SCREEN_DEVICE
|
2009-02-12 22:05:07 +00:00
|
|
|
//
|
|
|
|
// Create the sub dialog(s)
|
|
|
|
//
|
|
|
|
_keysDialog = new GUI::KeysDialog();
|
|
|
|
_keysDialog->runModal();
|
|
|
|
delete _keysDialog;
|
|
|
|
_keysDialog = NULL;
|
2008-06-24 23:19:23 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
2010-04-06 09:25:44 +00:00
|
|
|
GUI::OptionsDialog::handleCommand (sender, cmd, data);
|
2008-06-24 23:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|