SCI32: Implement basic kMessageBox

This kernel call seems only to be used by KQ7 1.51 (which was
Windows-only) to send warnings to the user.

It was easy enough to do a basic implementation in the ScummVM
GUI rather than just make it an empty call, so now it is a thing.
This commit is contained in:
Colin Snover 2016-06-18 21:06:16 -05:00
parent ceee33ba2c
commit 52505dc57f
5 changed files with 61 additions and 1 deletions

View File

@ -566,6 +566,7 @@ reg_t kMoveToFront(EngineState *s, int argc, reg_t *argv);
reg_t kMoveToEnd(EngineState *s, int argc, reg_t *argv);
reg_t kGetWindowsOption(EngineState *s, int argc, reg_t *argv);
reg_t kWinHelp(EngineState *s, int argc, reg_t *argv);
reg_t kMessageBox(EngineState *s, int argc, reg_t *argv);
reg_t kGetConfig(EngineState *s, int argc, reg_t *argv);
reg_t kGetSierraProfileInt(EngineState *s, int argc, reg_t *argv);
reg_t kCelInfo(EngineState *s, int argc, reg_t *argv);

View File

@ -728,6 +728,8 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_CALL(ListEachElementDo), SIG_EVERYWHERE, "li(.*)", NULL, NULL },
{ MAP_CALL(ListFirstTrue), SIG_EVERYWHERE, "li(.*)", NULL, NULL },
{ MAP_CALL(ListIndexOf), SIG_EVERYWHERE, "l[o0]", NULL, NULL },
// kMessageBox is used only by KQ7 1.51
{ MAP_CALL(MessageBox), SIG_SCI32, SIGFOR_ALL, "rri", NULL, NULL },
{ "OnMe", kIsOnMe, SIG_EVERYWHERE, "iioi", NULL, NULL },
// Purge is used by the memory manager in SSCI to ensure that X number of bytes (the so called "unmovable
// memory") are available when the current room changes. This is similar to the SCI0-SCI1.1 FlushResources

View File

@ -254,6 +254,10 @@ reg_t kWinHelp(EngineState *s, int argc, reg_t *argv) {
return s->r_acc;
}
reg_t kMessageBox(EngineState *s, int argc, reg_t *argv) {
return g_sci->_gfxControls32->kernelMessageBox(s->_segMan->getString(argv[0]), s->_segMan->getString(argv[1]), argv[2].toUint16());
}
/**
* Causes an immediate plane transition with an optional transition
* effect

View File

@ -21,7 +21,8 @@
*/
#include "common/system.h"
#include "common/translation.h"
#include "gui/message.h"
#include "sci/sci.h"
#include "sci/console.h"
#include "sci/event.h"
@ -807,4 +808,37 @@ void GfxControls32::destroyScrollWindow(const reg_t id) {
delete scrollWindow;
}
#pragma mark -
#pragma mark Message box
int16 GfxControls32::showMessageBox(const Common::String &message, const char *const okLabel, const char *const altLabel, const int16 okValue, const int16 altValue) {
GUI::MessageDialog dialog(message, okLabel, altLabel);
return (dialog.runModal() == GUI::kMessageOK) ? okValue : altValue;
}
reg_t GfxControls32::kernelMessageBox(const Common::String &message, const Common::String &title, const uint16 style) {
if (g_engine) {
g_engine->pauseEngine(true);
}
int16 result;
switch (style & 0xF) {
case kMessageBoxOK:
result = showMessageBox(message, _("OK"), NULL, 1, 1);
break;
case kMessageBoxYesNo:
result = showMessageBox(message, _("Yes"), _("No"), 6, 7);
break;
default:
error("Unsupported MessageBox style 0x%x", style & 0xF);
}
if (g_engine) {
g_engine->pauseEngine(false);
}
return make_reg(0, result);
}
} // End of namespace Sci

View File

@ -31,6 +31,10 @@ class GfxCache;
class GfxScreen;
class GfxText32;
enum MessageBoxStyle {
kMessageBoxOK = 0x0,
kMessageBoxYesNo = 0x4
};
struct TextEditor {
/**
@ -485,6 +489,21 @@ private:
* A lookup table for registered ScrollWindow instances.
*/
ScrollWindowMap _scrollWindows;
#pragma mark -
#pragma mark Message box
public:
/**
* Displays an OS-level message dialog.
*/
reg_t kernelMessageBox(const Common::String &message, const Common::String &title, const uint16 style);
private:
/**
* Convenience function for creating and showing a
* message box.
*/
int16 showMessageBox(const Common::String &message, const char *const okLabel, const char *const altLabel, const int16 okValue, const int16 altValue);
};
} // End of namespace Sci