From b59a791c5ef362b60136246e511c40018ef5e661 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 29 Apr 2006 23:23:32 +0000 Subject: Moved queryResString from class ScummDialog to class InfoDialog; some cleanup svn-id: r22234 --- engines/scumm/dialogs.cpp | 122 +++++++++++++++++++++++----------------------- engines/scumm/dialogs.h | 25 ++++++---- 2 files changed, 76 insertions(+), 71 deletions(-) (limited to 'engines') diff --git a/engines/scumm/dialogs.cpp b/engines/scumm/dialogs.cpp index c44c8cfa2d..18e2d3e3e1 100644 --- a/engines/scumm/dialogs.cpp +++ b/engines/scumm/dialogs.cpp @@ -212,51 +212,11 @@ static ResString string_map_table_v345[] = { #pragma mark - -ScummDialog::ScummDialog(ScummEngine *scumm, String name) - : GUI::Dialog(name), _vm(scumm) { +ScummDialog::ScummDialog(String name) + : GUI::Dialog(name) { _drawingHints |= GUI::THEME_HINT_SPECIAL_COLOR; } -const Common::String ScummDialog::queryResString(int stringno) { - byte buf[256]; - byte *result; - - if (stringno == 0) - return String(); - - if (_vm->_game.version == 8) - result = (byte *)string_map_table_v8[stringno - 1].string; - else if (_vm->_game.version == 7) - result = _vm->getStringAddressVar(string_map_table_v7[stringno - 1].num); - else if (_vm->_game.version == 6) - result = _vm->getStringAddressVar(string_map_table_v6[stringno - 1].num); - else if (_vm->_game.version >= 3) - result = _vm->getStringAddress(string_map_table_v345[stringno - 1].num); - else - return string_map_table_v345[stringno - 1].string; - - if (result && *result == '/') { - _vm->translateText(result, buf); - result = buf; - } - - if (!result || *result == '\0') { // Gracelessly degrade to english :) - return string_map_table_v345[stringno - 1].string; - } - - // Convert to a proper string (take care of FF codes) - byte chr; - String tmp; - while ((chr = *result++)) { - if (chr == 0xFF) { - result += 3; - } else if (chr != '@') { - tmp += chr; - } - } - return tmp; -} - #pragma mark - Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode); @@ -273,7 +233,7 @@ enum { }; SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode, ScummEngine *engine) - : Dialog("scummsaveload"), _saveMode(saveMode), _list(0), _chooseButton(0), _gfxWidget(0), _scumm(engine) { + : Dialog("scummsaveload"), _saveMode(saveMode), _list(0), _chooseButton(0), _gfxWidget(0), _vm(engine) { _drawingHints |= GUI::THEME_HINT_SPECIAL_COLOR; @@ -292,10 +252,10 @@ SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, _gfxWidget = new GUI::GraphicsWidget(this, thumbX, thumbY, kThumbnailWidth + 8, - ((_scumm->_system->getHeight() % 200 && _scumm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8); + ((_vm->_system->getHeight() % 200 && _vm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8); _gfxWidget->setFlags(GUI::WIDGET_BORDER); - int height = thumbY + ((_scumm->_system->getHeight() % 200 && _scumm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8; + int height = thumbY + ((_vm->_system->getHeight() % 200 && _vm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8; _date = new StaticTextWidget(this, thumbX, @@ -405,9 +365,9 @@ void SaveLoadChooser::handleScreenChanged() { _gfxWidget->setFlags(GUI::WIDGET_BORDER); } _gfxWidget->resize(thumbX, thumbY, kThumbnailWidth + 8, - ((_scumm->_system->getHeight() % 200 && _scumm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8); + ((_vm->_system->getHeight() % 200 && _vm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8); - int height = thumbY + ((_scumm->_system->getHeight() % 200 && _scumm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8; + int height = thumbY + ((_vm->_system->getHeight() % 200 && _vm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8; if (!_date) _date = new StaticTextWidget(this, 0, 0, 0, 0, "", kTextAlignCenter); @@ -462,7 +422,7 @@ void SaveLoadChooser::handleScreenChanged() { void SaveLoadChooser::updateInfos() { int selItem = _list->getSelected(); Graphics::Surface *thumb; - thumb = _scumm->loadThumbnailFromSlot(_saveMode ? selItem + 1 : selItem); + thumb = _vm->loadThumbnailFromSlot(_saveMode ? selItem + 1 : selItem); _gfxWidget->setGfx(thumb); if (thumb) thumb->free(); @@ -472,7 +432,7 @@ void SaveLoadChooser::updateInfos() { InfoStuff infos; memset(&infos, 0, sizeof(InfoStuff)); char buffer[32]; - if (_scumm->loadInfosFromSlot(_saveMode ? selItem + 1 : selItem, &infos)) { + if (_vm->loadInfosFromSlot(_saveMode ? selItem + 1 : selItem, &infos)) { snprintf(buffer, 32, "Date: %.2d.%.2d.%.4d", (infos.date >> 24) & 0xFF, (infos.date >> 16) & 0xFF, infos.date & 0xFFFF); @@ -529,7 +489,7 @@ Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) { } MainMenuDialog::MainMenuDialog(ScummEngine *scumm) - : ScummDialog(scumm, "scummmain") { + : ScummDialog("scummmain"), _vm(scumm) { new GUI::ButtonWidget(this, "scummmain_resume", "Resume", kPlayCmd, 'P'); @@ -548,9 +508,9 @@ MainMenuDialog::MainMenuDialog(ScummEngine *scumm) // Create the sub dialog(s) // _aboutDialog = new GUI::AboutDialog(); - _optionsDialog = new ConfigDialog(scumm); + _optionsDialog = new ConfigDialog(); #ifndef DISABLE_HELP - _helpDialog = new HelpDialog(scumm); + _helpDialog = new HelpDialog(scumm->_game); #endif _saveDialog = new SaveLoadChooser("Save game:", "Save", true, scumm); _loadDialog = new SaveLoadChooser("Load game:", "Load", false, scumm); @@ -680,8 +640,8 @@ enum { // 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. -ConfigDialog::ConfigDialog(ScummEngine *scumm) - : GUI::OptionsDialog("", "scummconfig"), _vm(scumm) { +ConfigDialog::ConfigDialog() + : GUI::OptionsDialog("", "scummconfig") { // // Sound controllers @@ -760,8 +720,8 @@ enum { kPrevCmd = 'PREV' }; -HelpDialog::HelpDialog(ScummEngine *scumm) - : ScummDialog(scumm, "scummhelp") { +HelpDialog::HelpDialog(const GameSettings &game) + : ScummDialog("scummhelp"), _game(game) { _drawingHints &= ~GUI::THEME_HINT_SPECIAL_COLOR; int lineHeight = g_gui.getFontHeight(); @@ -782,7 +742,7 @@ HelpDialog::HelpDialog(ScummEngine *scumm) } _page = 1; - _numPages = ScummHelp::numPages(scumm->_game.id); + _numPages = ScummHelp::numPages(game.id); _prevButton = new GUI::ButtonWidget(this, "scummhelp_prev", "Previous", kPrevCmd, 'P'); _nextButton = new GUI::ButtonWidget(this, "scummhelp_next", "Next", kNextCmd, 'N'); @@ -796,7 +756,7 @@ void HelpDialog::displayKeyBindings() { String titleStr, *keyStr, *dscStr; - ScummHelp::updateStrings(_vm->_game.id, _vm->_game.version, _vm->_game.platform, _page, titleStr, keyStr, dscStr); + ScummHelp::updateStrings(_game.id, _game.version, _game.platform, _page, titleStr, keyStr, dscStr); _title->setLabel(titleStr); for (int i = 0; i < HELP_NUM_LINES; i++) { @@ -843,12 +803,12 @@ void HelpDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { #pragma mark - InfoDialog::InfoDialog(ScummEngine *scumm, int res) -: ScummDialog(scumm, "scummDummyDialog") { // dummy x and w - setInfoText(queryResString (res)); +: ScummDialog("scummDummyDialog"), _vm(scumm) { // dummy x and w + setInfoText(queryResString(res)); } InfoDialog::InfoDialog(ScummEngine *scumm, const String& message) -: ScummDialog(scumm, "scummDummyDialog") { // dummy x and w +: ScummDialog("scummDummyDialog"), _vm(scumm) { // dummy x and w setInfoText(message); } @@ -867,6 +827,46 @@ void InfoDialog::setInfoText(const String& message) { new StaticTextWidget(this, 4, 4, _w - 8, _h, message, kTextAlignCenter); } +const Common::String InfoDialog::queryResString(int stringno) { + byte buf[256]; + byte *result; + + if (stringno == 0) + return String(); + + if (_vm->_game.version == 8) + result = (byte *)string_map_table_v8[stringno - 1].string; + else if (_vm->_game.version == 7) + result = _vm->getStringAddressVar(string_map_table_v7[stringno - 1].num); + else if (_vm->_game.version == 6) + result = _vm->getStringAddressVar(string_map_table_v6[stringno - 1].num); + else if (_vm->_game.version >= 3) + result = _vm->getStringAddress(string_map_table_v345[stringno - 1].num); + else + return string_map_table_v345[stringno - 1].string; + + if (result && *result == '/') { + _vm->translateText(result, buf); + result = buf; + } + + if (!result || *result == '\0') { // Gracelessly degrade to english :) + return string_map_table_v345[stringno - 1].string; + } + + // Convert to a proper string (take care of FF codes) + byte chr; + String tmp; + while ((chr = *result++)) { + if (chr == 0xFF) { + result += 3; + } else if (chr != '@') { + tmp += chr; + } + } + return tmp; +} + #pragma mark - PauseDialog::PauseDialog(ScummEngine *scumm, int res) diff --git a/engines/scumm/dialogs.h b/engines/scumm/dialogs.h index 42f0cbf309..33ef7ebd23 100644 --- a/engines/scumm/dialogs.h +++ b/engines/scumm/dialogs.h @@ -27,6 +27,7 @@ #include "gui/options.h" #include "gui/widget.h" +#include "scumm/plugin.h" #ifndef DISABLE_HELP #include "scumm/help.h" #endif @@ -43,15 +44,10 @@ class ScummEngine; class ScummDialog : public GUI::Dialog { public: - ScummDialog(ScummEngine *scumm, Common::String name); + ScummDialog(Common::String name); protected: typedef Common::String String; - - ScummEngine *_vm; - - // Query a string from the resources - const String queryResString(int stringno); }; class SaveLoadChooser : public GUI::Dialog { @@ -65,7 +61,7 @@ protected: GUI::StaticTextWidget *_date; GUI::StaticTextWidget *_time; GUI::StaticTextWidget *_playtime; - ScummEngine *_scumm; + ScummEngine *_vm; void updateInfos(); public: @@ -89,6 +85,8 @@ public: virtual void handleScreenChanged(); protected: + ScummEngine *_vm; + GUI::Dialog *_aboutDialog; GUI::Dialog *_optionsDialog; #ifndef DISABLE_HELP @@ -106,7 +104,7 @@ protected: class HelpDialog : public ScummDialog { public: - HelpDialog(ScummEngine *scumm); + HelpDialog(const GameSettings &game); virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); protected: @@ -121,6 +119,8 @@ protected: int _page; int _numPages; + + const GameSettings _game; void displayKeyBindings(); }; @@ -129,13 +129,12 @@ protected: class ConfigDialog : public GUI::OptionsDialog { protected: - ScummEngine *_vm; #ifdef SMALL_SCREEN_DEVICE GUI::Dialog *_keysDialog; #endif public: - ConfigDialog(ScummEngine *scumm); + ConfigDialog(); ~ConfigDialog(); virtual void open(); @@ -154,6 +153,9 @@ protected: * click closed the dialog). */ class InfoDialog : public ScummDialog { +protected: + ScummEngine *_vm; + public: // arbitrary message InfoDialog(ScummEngine *scumm, const String& message); @@ -171,6 +173,9 @@ public: protected: void setInfoText (const String& message); + + // Query a string from the resources + const String queryResString(int stringno); }; /** -- cgit v1.2.3