ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

dialogs.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "base/version.h"
00024 
00025 #include "common/config-manager.h"
00026 #include "common/events.h"
00027 #include "common/str.h"
00028 #include "common/system.h"
00029 #include "common/translation.h"
00030 
00031 #include "gui/about.h"
00032 #include "gui/gui-manager.h"
00033 #include "gui/message.h"
00034 #include "gui/options.h"
00035 #include "gui/saveload.h"
00036 #include "gui/ThemeEngine.h"
00037 #include "gui/ThemeEval.h"
00038 #include "gui/widget.h"
00039 
00040 #include "graphics/font.h"
00041 
00042 #include "engines/dialogs.h"
00043 #include "engines/engine.h"
00044 #include "engines/metaengine.h"
00045 
00046 #ifdef GUI_ENABLE_KEYSDIALOG
00047 #include "gui/KeysDialog.h"
00048 #endif
00049 
00050 class ConfigDialog : public GUI::OptionsDialog {
00051 protected:
00052 #ifdef GUI_ENABLE_KEYSDIALOG
00053     GUI::Dialog     *_keysDialog;
00054 #endif
00055 
00056 public:
00057     ConfigDialog(bool subtitleControls);
00058     ~ConfigDialog();
00059 
00060     virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
00061 };
00062 
00063 MainMenuDialog::MainMenuDialog(Engine *engine)
00064     : GUI::Dialog("GlobalMenu"), _engine(engine) {
00065     _backgroundType = GUI::ThemeEngine::kDialogBackgroundSpecial;
00066 
00067 #ifndef DISABLE_FANCY_THEMES
00068     _logo = 0;
00069     if (g_gui.xmlEval()->getVar("Globals.ShowGlobalMenuLogo", 0) == 1 && g_gui.theme()->supportsImages()) {
00070         _logo = new GUI::GraphicsWidget(this, "GlobalMenu.Logo");
00071         _logo->useThemeTransparency(true);
00072         _logo->setGfx(g_gui.theme()->getImageSurface(GUI::ThemeEngine::kImageLogoSmall));
00073     } else {
00074         GUI::StaticTextWidget *title = new GUI::StaticTextWidget(this, "GlobalMenu.Title", "ResidualVM");
00075         title->setAlign(Graphics::kTextAlignCenter);
00076     }
00077 #else
00078     GUI::StaticTextWidget *title = new GUI::StaticTextWidget(this, "GlobalMenu.Title", "ResidualVM");
00079     title->setAlign(Graphics::kTextAlignCenter);
00080 #endif
00081 
00082     GUI::StaticTextWidget *version = new GUI::StaticTextWidget(this, "GlobalMenu.Version", gScummVMVersionDate);
00083     version->setAlign(Graphics::kTextAlignCenter);
00084 
00085     new GUI::ButtonWidget(this, "GlobalMenu.Resume", _("~R~esume"), 0, kPlayCmd, 'P');
00086 
00087     _loadButton = new GUI::ButtonWidget(this, "GlobalMenu.Load", _("~L~oad"), 0, kLoadCmd);
00088     _loadButton->setVisible(_engine->hasFeature(Engine::kSupportsLoadingDuringRuntime));
00089     _loadButton->setEnabled(_engine->hasFeature(Engine::kSupportsLoadingDuringRuntime));
00090 
00091     _saveButton = new GUI::ButtonWidget(this, "GlobalMenu.Save", _("~S~ave"), 0, kSaveCmd);
00092     _saveButton->setVisible(_engine->hasFeature(Engine::kSupportsSavingDuringRuntime));
00093     _saveButton->setEnabled(_engine->hasFeature(Engine::kSupportsSavingDuringRuntime));
00094 
00095     new GUI::ButtonWidget(this, "GlobalMenu.Options", _("~O~ptions"), 0, kOptionsCmd);
00096 
00097     // The help button is disabled by default.
00098     // To enable "Help", an engine needs to use a subclass of MainMenuDialog
00099     // (at least for now, we might change how this works in the future).
00100     _helpButton = new GUI::ButtonWidget(this, "GlobalMenu.Help", _("~H~elp"), 0, kHelpCmd);
00101 
00102     new GUI::ButtonWidget(this, "GlobalMenu.About", _("~A~bout"), 0, kAboutCmd);
00103 
00104     if (g_system->getOverlayWidth() > 320)
00105         _rtlButton = new GUI::ButtonWidget(this, "GlobalMenu.RTL", _("~R~eturn to Launcher"), 0, kRTLCmd);
00106     else
00107         _rtlButton = new GUI::ButtonWidget(this, "GlobalMenu.RTL", _c("~R~eturn to Launcher", "lowres"), 0, kRTLCmd);
00108     _rtlButton->setEnabled(_engine->hasFeature(Engine::kSupportsRTL));
00109 
00110 
00111     new GUI::ButtonWidget(this, "GlobalMenu.Quit", _("~Q~uit"), 0, kQuitCmd);
00112 
00113     _aboutDialog = new GUI::AboutDialog();
00114     _optionsDialog = new ConfigDialog(_engine->hasFeature(Engine::kSupportsSubtitleOptions));
00115     _loadDialog = new GUI::SaveLoadChooser(_("Load game:"), _("Load"), false);
00116     _saveDialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
00117 }
00118 
00119 MainMenuDialog::~MainMenuDialog() {
00120     delete _aboutDialog;
00121     delete _optionsDialog;
00122     delete _loadDialog;
00123     delete _saveDialog;
00124 }
00125 
00126 void MainMenuDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
00127     switch (cmd) {
00128     case kPlayCmd:
00129         close();
00130         break;
00131     case kLoadCmd:
00132         load();
00133         break;
00134     case kSaveCmd:
00135         save();
00136         break;
00137     case kOptionsCmd:
00138         _optionsDialog->runModal();
00139         break;
00140     case kAboutCmd:
00141         _aboutDialog->runModal();
00142         break;
00143     case kHelpCmd: {
00144         GUI::MessageDialog dialog(
00145                     _("Sorry, this engine does not currently provide in-game help. "
00146                     "Please consult the README for basic information, and for "
00147                     "instructions on how to obtain further assistance."));
00148         dialog.runModal();
00149         }
00150         break;
00151     case kRTLCmd: {
00152         Common::Event eventRTL;
00153         eventRTL.type = Common::EVENT_RTL;
00154         g_system->getEventManager()->pushEvent(eventRTL);
00155         close();
00156         }
00157         break;
00158     case kQuitCmd: {
00159         Common::Event eventQ;
00160         eventQ.type = Common::EVENT_QUIT;
00161         g_system->getEventManager()->pushEvent(eventQ);
00162         close();
00163         }
00164         break;
00165     default:
00166         GUI::Dialog::handleCommand(sender, cmd, data);
00167     }
00168 }
00169 
00170 void MainMenuDialog::reflowLayout() {
00171     if (_engine->hasFeature(Engine::kSupportsLoadingDuringRuntime))
00172         _loadButton->setEnabled(_engine->canLoadGameStateCurrently());
00173     if (_engine->hasFeature(Engine::kSupportsSavingDuringRuntime))
00174         _saveButton->setEnabled(_engine->canSaveGameStateCurrently());
00175 
00176     // Overlay size might have changed since the construction of the dialog.
00177     // Update labels when it might be needed
00178     // FIXME: it might be better to declare GUI::StaticTextWidget::setLabel() virtual
00179     // and to reimplement it in GUI::ButtonWidget to handle the hotkey.
00180     if (g_system->getOverlayWidth() > 320)
00181         _rtlButton->setLabel(_rtlButton->cleanupHotkey(_("~R~eturn to Launcher")));
00182     else
00183         _rtlButton->setLabel(_rtlButton->cleanupHotkey(_c("~R~eturn to Launcher", "lowres")));
00184 
00185 #ifndef DISABLE_FANCY_THEMES
00186     if (g_gui.xmlEval()->getVar("Globals.ShowGlobalMenuLogo", 0) == 1 && g_gui.theme()->supportsImages()) {
00187         if (!_logo)
00188             _logo = new GUI::GraphicsWidget(this, "GlobalMenu.Logo");
00189         _logo->useThemeTransparency(true);
00190         _logo->setGfx(g_gui.theme()->getImageSurface(GUI::ThemeEngine::kImageLogoSmall));
00191 
00192         GUI::StaticTextWidget *title = (GUI::StaticTextWidget *)findWidget("GlobalMenu.Title");
00193         if (title) {
00194             removeWidget(title);
00195             title->setNext(0);
00196             delete title;
00197         }
00198     } else {
00199         GUI::StaticTextWidget *title = (GUI::StaticTextWidget *)findWidget("GlobalMenu.Title");
00200         if (!title) {
00201             title = new GUI::StaticTextWidget(this, "GlobalMenu.Title", "ResidualVM");
00202             title->setAlign(Graphics::kTextAlignCenter);
00203         }
00204 
00205         if (_logo) {
00206             removeWidget(_logo);
00207             _logo->setNext(0);
00208             delete _logo;
00209             _logo = 0;
00210         }
00211     }
00212 #endif
00213 
00214     Dialog::reflowLayout();
00215 }
00216 
00217 void MainMenuDialog::save() {
00218     int slot = _saveDialog->runModalWithCurrentTarget();
00219 
00220     #if defined(__PLAYSTATION2__) && defined(DYNAMIC_MODULES)
00221     char pokeme[32];
00222     snprintf(pokeme,32,"hack");
00223     #endif
00224 
00225     if (slot >= 0) {
00226         Common::String result(_saveDialog->getResultString());
00227         if (result.empty()) {
00228             // If the user was lazy and entered no save name, come up with a default name.
00229             result = _saveDialog->createDefaultSaveDescription(slot);
00230         }
00231 
00232         Common::Error status = _engine->saveGameState(slot, result);
00233         if (status.getCode() != Common::kNoError) {
00234             Common::String failMessage = Common::String::format(_("Failed to save game (%s)! "
00235                   "Please consult the README for basic information, and for "
00236                   "instructions on how to obtain further assistance."), status.getDesc().c_str());
00237             GUI::MessageDialog dialog(failMessage);
00238             dialog.runModal();
00239         }
00240 
00241         close();
00242     }
00243 }
00244 
00245 void MainMenuDialog::load() {
00246     int slot = _loadDialog->runModalWithCurrentTarget();
00247 
00248     _engine->setGameToLoadSlot(slot);
00249 
00250     if (slot >= 0)
00251         close();
00252 }
00253 
00254 enum {
00255     kKeysCmd = 'KEYS'
00256 };
00257 
00258 // FIXME: We use the empty string as domain name here. This tells the
00259 // ConfigManager to use the 'default' domain for all its actions. We do that
00260 // to get as close as possible to editing the 'active' settings.
00261 //
00262 // However, that requires bad & evil hacks in the ConfigManager code,
00263 // and even then still doesn't work quite correctly.
00264 // For example, if the transient domain contains 'false' for the 'fullscreen'
00265 // flag, but the user used a hotkey to switch to windowed mode, then the dialog
00266 // will display the wrong value anyway.
00267 //
00268 // Proposed solution consisting of multiple steps:
00269 // 1) Add special code to the open() code that reads out everything stored
00270 //    in the transient domain that is controlled by this dialog, and updates
00271 //    the dialog accordingly.
00272 // 2) Even more code is added to query the backend for current settings, like
00273 //    the fullscreen mode flag etc., and also updates the dialog accordingly.
00274 // 3) The domain being edited is set to the active game domain.
00275 // 4) If the dialog is closed with the "OK" button, then we remove everything
00276 //    stored in the transient domain (or at least everything corresponding to
00277 //    switches in this dialog.
00278 //    If OTOH the dialog is closed with "Cancel" we do no such thing.
00279 //
00280 // These changes will achieve two things at once: Allow us to get rid of using
00281 //  "" as value for the domain, and in fact provide a somewhat better user
00282 // experience at the same time.
00283 ConfigDialog::ConfigDialog(bool subtitleControls)
00284     : GUI::OptionsDialog("", "GlobalConfig") {
00285 
00286     //
00287     // Sound controllers
00288     //
00289 
00290     addVolumeControls(this, "GlobalConfig.");
00291     setVolumeSettingsState(true); // could disable controls by GUI options
00292 
00293     //
00294     // Subtitle speed and toggle controllers
00295     //
00296 
00297     if (subtitleControls) {
00298         // Global talkspeed range of 0-255
00299         addSubtitleControls(this, "GlobalConfig.", 255);
00300         setSubtitleSettingsState(true); // could disable controls by GUI options
00301     }
00302 
00303     //
00304     // Add the buttons
00305     //
00306 
00307     new GUI::ButtonWidget(this, "GlobalConfig.Ok", _("~O~K"), 0, GUI::kOKCmd);
00308     new GUI::ButtonWidget(this, "GlobalConfig.Cancel", _("~C~ancel"), 0, GUI::kCloseCmd);
00309 
00310 #ifdef GUI_ENABLE_KEYSDIALOG
00311     new GUI::ButtonWidget(this, "GlobalConfig.Keys", _("~K~eys"), 0, kKeysCmd);
00312     _keysDialog = NULL;
00313 #endif
00314 }
00315 
00316 ConfigDialog::~ConfigDialog() {
00317 #ifdef GUI_ENABLE_KEYSDIALOG
00318     delete _keysDialog;
00319 #endif
00320 }
00321 
00322 void ConfigDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
00323     switch (cmd) {
00324     case kKeysCmd:
00325 
00326 #ifdef GUI_ENABLE_KEYSDIALOG
00327     //
00328     // Create the sub dialog(s)
00329     //
00330     _keysDialog = new GUI::KeysDialog();
00331     _keysDialog->runModal();
00332     delete _keysDialog;
00333     _keysDialog = NULL;
00334 #endif
00335         break;
00336     default:
00337         GUI::OptionsDialog::handleCommand (sender, cmd, data);
00338     }
00339 }


Generated on Sat Oct 19 2019 05:01:00 for ResidualVM by doxygen 1.7.1
curved edge   curved edge