diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index 66043872544..b269e9789d1 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -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); diff --git a/engines/sci/engine/kernel_tables.h b/engines/sci/engine/kernel_tables.h index 03e56ea559c..19bee359c53 100644 --- a/engines/sci/engine/kernel_tables.h +++ b/engines/sci/engine/kernel_tables.h @@ -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 diff --git a/engines/sci/engine/kgraphics32.cpp b/engines/sci/engine/kgraphics32.cpp index f8ec96c8430..40834147249 100644 --- a/engines/sci/engine/kgraphics32.cpp +++ b/engines/sci/engine/kgraphics32.cpp @@ -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 diff --git a/engines/sci/graphics/controls32.cpp b/engines/sci/graphics/controls32.cpp index 04014154aea..61dfbedfc56 100644 --- a/engines/sci/graphics/controls32.cpp +++ b/engines/sci/graphics/controls32.cpp @@ -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 diff --git a/engines/sci/graphics/controls32.h b/engines/sci/graphics/controls32.h index 62ab90de1f6..460b0b56259 100644 --- a/engines/sci/graphics/controls32.h +++ b/engines/sci/graphics/controls32.h @@ -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