diff options
author | James Brown | 2003-01-02 10:36:17 +0000 |
---|---|---|
committer | James Brown | 2003-01-02 10:36:17 +0000 |
commit | 9df455ce380f4a7389ca093dfd619761c3bea046 (patch) | |
tree | dd539999845c443a135ed04370e1ca22342cbc7f | |
parent | 3c3c5bb57467d4bcef2c71c923dd9cacc49217f2 (diff) | |
download | scummvm-rg350-9df455ce380f4a7389ca093dfd619761c3bea046.tar.gz scummvm-rg350-9df455ce380f4a7389ca093dfd619761c3bea046.tar.bz2 scummvm-rg350-9df455ce380f4a7389ca093dfd619761c3bea046.zip |
Plop in some better disk switching code for CMI - I have no idea how well this will work transitioning from a disk1 room to a disk2
room in-game, but it works for bootparams and saved games..
svn-id: r6322
-rw-r--r-- | gui/message.cpp | 38 | ||||
-rw-r--r-- | gui/message.h | 3 | ||||
-rw-r--r-- | scumm/resource.cpp | 39 | ||||
-rw-r--r-- | scumm/scumm.h | 4 | ||||
-rw-r--r-- | scumm/scummvm.cpp | 12 | ||||
-rw-r--r-- | scumm/sound.cpp | 14 |
6 files changed, 80 insertions, 30 deletions
diff --git a/gui/message.cpp b/gui/message.cpp index d751fb86b8..06d4ff643a 100644 --- a/gui/message.cpp +++ b/gui/message.cpp @@ -22,8 +22,13 @@ #include "message.h" #include "newgui.h" +enum { + kOkCmd = 'OK ', + kCancelCmd = 'CNCL' +}; -MessageDialog::MessageDialog(NewGui *gui, const String &message, uint32 timer, bool showButton) + +MessageDialog::MessageDialog(NewGui *gui, const String &message, uint32 timer, bool showOkButton, bool showCancelButton) : Dialog(gui, 30, 20, 260, 124) { // First, determine the size the dialog needs. For this we have to break @@ -34,7 +39,7 @@ MessageDialog::MessageDialog(NewGui *gui, const String &message, uint32 timer, b const char *str = message.c_str(); const char *start = str; int lineWidth, maxlineWidth = 0; - int lineCount; + int lineCount, okButtonPos, cancelButtonPos; while (*str) { if (*str == '\n') { @@ -55,7 +60,7 @@ MessageDialog::MessageDialog(NewGui *gui, const String &message, uint32 timer, b _w = maxlineWidth + 20; lineCount = lines.size(); _h = lineCount * kLineHeight + 16; - if (showButton) + if (showOkButton || showCancelButton) _h += 24; if (_h > 180) { @@ -72,8 +77,18 @@ MessageDialog::MessageDialog(NewGui *gui, const String &message, uint32 timer, b // FIXME - allow for multiple buttons, and return in runModal() which one // was selected. - if (showButton) - addButton((_w - kButtonWidth)/2, _h - 24, "OK", kCloseCmd, '\n'); // Confirm dialog + if (showOkButton && showCancelButton) { + okButtonPos = (_w - (kButtonWidth * 2))/2; + cancelButtonPos = ((_w - (kButtonWidth * 2))/2) + kButtonWidth + 10; + } else { + okButtonPos = cancelButtonPos = (_w-kButtonWidth)/2; + } + + if (showOkButton) + addButton(okButtonPos, _h - 24, "OK", kOkCmd, '\n'); // Confirm dialog + + if (showCancelButton) + addButton(cancelButtonPos, _h - 24, "CANCEL", kCancelCmd, '\27'); // Cancel dialog if (timer) _timer = _gui->get_time() + timer; @@ -134,3 +149,16 @@ int MessageDialog::addLine(StringList &lines, const char *line, int size) return maxWidth; } +void MessageDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) +{ + if (cmd == kOkCmd) { + setResult(1); + close(); + } else if (cmd == kCancelCmd) { + setResult(2); + close(); + } else { + Dialog::handleCommand(sender, cmd, data); + } +} + diff --git a/gui/message.h b/gui/message.h index c415b905be..271b1e7939 100644 --- a/gui/message.h +++ b/gui/message.h @@ -29,9 +29,10 @@ class MessageDialog : public Dialog { typedef ScummVM::String String; typedef ScummVM::StringList StringList; public: - MessageDialog(NewGui *gui, const String &message, uint32 timer = 0, bool showButton = true); + MessageDialog(NewGui *gui, const String &message, uint32 timer = 0, bool showOKButton = true, bool showCancelButton = false); void handleTickle(); + void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); protected: uint32 _timer; diff --git a/scumm/resource.cpp b/scumm/resource.cpp index 9788207ff3..0d7d719848 100644 --- a/scumm/resource.cpp +++ b/scumm/resource.cpp @@ -27,9 +27,8 @@ #include "scumm/sound.h" #include "common/map.h" #include "common/str.h" - -#include <stdio.h> - +#include "gui/message.h" +#include "dialogs.h" uint16 newTag2Old(uint32 oldTag); @@ -75,9 +74,11 @@ void Scumm::openRoom(int room) } if (!(_features & GF_SMALL_HEADER)) { - if (_features & GF_AFTER_V7) + if (_features & GF_AFTER_V7) { + if (room > 0) + _vars[VAR_CURRENTDISK] = res.roomno[rtRoom][room]; sprintf(buf, "%s.la%d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]); - else if (_features & GF_HUMONGOUS) + } else if (_features & GF_HUMONGOUS) sprintf(buf, "%s.he%.1d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]); else sprintf(buf, "%s.%.3d", _exe_name, room == 0 ? 0 : res.roomno[rtRoom][room]); @@ -90,10 +91,10 @@ void Scumm::openRoom(int room) if (openResourceFile(buf)) { return; } - askForDisk(buf); + askForDisk(buf, room == 0 ? 0 : res.roomno[rtRoom][room]); } else { - sprintf(buf, "disk%.2d.lec", res.roomno[rtRoom][room]); + sprintf(buf, "disk%.2d.lec", room == 0 ? 0 : res.roomno[rtRoom][room]); _encbyte = 0x69; } } else { @@ -115,7 +116,7 @@ void Scumm::openRoom(int room) error("Room %d not in %s", room, buf); return; } - askForDisk(buf); + askForDisk(buf, room == 0 ? 0 : res.roomno[rtRoom][room]); } do { @@ -123,7 +124,7 @@ void Scumm::openRoom(int room) _encbyte = 0; if (openResourceFile(buf)) break; - askForDisk(buf); + askForDisk(buf, room == 0 ? 0 : res.roomno[rtRoom][room]); } while (1); deleteRoomOffsets(); @@ -199,9 +200,25 @@ bool Scumm::openResourceFile(const char *filename) return _fileHandle.isOpen(); } -void Scumm::askForDisk(const char *filename) +void Scumm::askForDisk(const char *filename, int disknum) { - error("ask Cannot find '%s'", filename); + char buf[128]; + + if (_features & GF_AFTER_V8) { + char result; + + sprintf(buf, "Cannot find file: '%s'\nInsert disk %d into drive %s\nHit Ok to retry, Cancel to exit", filename, disknum, getResDataPath()); + + result = displayError(true, buf); + if (result == 2) + error("Cannot find file: '%s'", filename); + } else { + sprintf(buf, "Cannot find file: '%s'", filename); + InfoDialog* dialog = new InfoDialog(_newgui, this, (char*)buf); + runDialog (dialog); + delete dialog; + error("Cannot find file: '%s'", filename); + } } void Scumm::readIndexFile() diff --git a/scumm/scumm.h b/scumm/scumm.h index 716d94927f..edd0c67d77 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -321,7 +321,7 @@ public: void pauseDialog(); void saveloadDialog(); void optionsDialog(); - void displayError(const char *message, ...); + char displayError(bool showCancel, const char *message, ...); // Misc startup/event functions void main(); @@ -512,7 +512,7 @@ public: void closeRoom(); void deleteRoomOffsets(); void readRoomsOffsets(); - void askForDisk(const char *filename); + void askForDisk(const char *filename, int disknum); bool openResourceFile(const char *filename); void loadPtrToResource(int type, int i, byte *ptr); void readResTypeList(int id, uint32 tag, const char *name); diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp index 7299b046e0..b0c4a53f47 100644 --- a/scumm/scummvm.cpp +++ b/scumm/scummvm.cpp @@ -474,7 +474,7 @@ int Scumm::scummLoop(int delta) makeSavegameName(filename, _saveLoadSlot, _saveLoadCompatible); if (!success) { - displayError(errMsg, filename); + displayError(false, errMsg, filename); } else if (_saveLoadFlag == 1 && _saveLoadSlot != 0 && !_saveLoadCompatible) { // Display "Save succesful" message, except for auto saves char buf[1024]; @@ -1065,18 +1065,20 @@ void Scumm::optionsDialog() runDialog(_optionsDialog); } -void Scumm::displayError(const char *message, ...) +char Scumm::displayError(bool showCancel, const char *message, ...) { - char buf[1024]; + char buf[1024], result; va_list va; va_start(va, message); vsprintf(buf, message, va); va_end(va); - Dialog *dialog = new MessageDialog(_newgui, buf); - runDialog(dialog); + Dialog *dialog = new MessageDialog(_newgui, buf, 0, true, showCancel); + result = runDialog(dialog); delete dialog; + + return result; } void Scumm::shutDown(int i) diff --git a/scumm/sound.cpp b/scumm/sound.cpp index 4d4e30ef13..308ba3a03d 100644 --- a/scumm/sound.cpp +++ b/scumm/sound.cpp @@ -958,8 +958,10 @@ void Sound::playBundleMusic(char * song) { // FIXME: we have MUSDISK1.BUN and MUSDISK2.BUN in COMI. _outputMixerSize = 66150; // ((22050 * 2 * 2) / 4) * 3 if (_scumm->_gameId == GID_CMI) { + char bunfile[20]; + sprintf(bunfile, "musdisk%d.bun", _scumm->_vars[_scumm->VAR_CURRENTDISK]); printf("Opening bundle\n"); - if (_scumm->_bundle->openMusicFile("musdisk1.bun", _scumm->getGameDataPath()) == false) + if (_scumm->_bundle->openMusicFile(bunfile, _scumm->getGameDataPath()) == false) return; _outputMixerSize = 88140; // ((22050 * 2 * 2) } else { @@ -1123,11 +1125,11 @@ int Sound::playBundleSound(char *sound) { byte * ptr; bool result; - if (_scumm->_gameId == GID_CMI) - // FIXME: HACK! There are actually two voice files in COMI... I dunno how to do this - // right, though :-/ - result = _scumm->_bundle->openVoiceFile("voxdisk1.bun", _scumm->getGameDataPath()); - else if (_scumm->_gameId == GID_DIG) + if (_scumm->_gameId == GID_CMI) { + char voxfile[20]; + sprintf(voxfile, "voxdisk%d.bun", _scumm->_vars[_scumm->VAR_CURRENTDISK]); + result = _scumm->_bundle->openVoiceFile(voxfile, _scumm->getGameDataPath()); + } else if (_scumm->_gameId == GID_DIG) result = _scumm->_bundle->openVoiceFile("digvoice.bun", _scumm->getGameDataPath()); else error("Don't know which bundle file to load"); |