From ec722475b6a9f9c3a440b275e5d5d129b48746f7 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Tue, 30 May 2023 14:21:50 +0300 Subject: [PATCH] Add op_create_message_window See #200 --- src/sfall_opcodes.cc | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/sfall_opcodes.cc b/src/sfall_opcodes.cc index 3b101ce..307a65b 100644 --- a/src/sfall_opcodes.cc +++ b/src/sfall_opcodes.cc @@ -4,13 +4,16 @@ #include "animation.h" #include "art.h" +#include "color.h" #include "combat.h" +#include "dbox.h" #include "debug.h" #include "game.h" #include "input.h" #include "interface.h" #include "interpreter.h" #include "item.h" +#include "memory.h" #include "message.h" #include "mouse.h" #include "object.h" @@ -448,6 +451,47 @@ static void opGetScreenHeight(Program* program) programStackPushInteger(program, screenGetHeight()); } +// create_message_window +static void op_create_message_window(Program* program) +{ + static bool showing = false; + + if (showing) { + return; + } + + const char* string = programStackPopString(program); + if (string == nullptr || string[0] == '\0') { + return; + } + + char* copy = internal_strdup(string); + + const char* body[4]; + int count = 0; + + char* pch = strchr(copy, '\n'); + while (pch != nullptr && count < 4) { + *pch = '\0'; + body[count++] = pch + 1; + pch = strchr(pch + 1, '\n'); + } + + showing = true; + showDialogBox(copy, + body, + count, + 192, + 116, + _colorTable[32328], + nullptr, + _colorTable[32328], + DIALOG_BOX_LARGE); + showing = false; + + internal_free(copy); +} + // get_attack_type static void op_get_attack_type(Program* program) { @@ -838,6 +882,7 @@ void sfallOpcodesInit() interpreterRegisterOpcode(0x821E, op_get_mouse_buttons); interpreterRegisterOpcode(0x8220, opGetScreenWidth); interpreterRegisterOpcode(0x8221, opGetScreenHeight); + interpreterRegisterOpcode(0x8224, op_create_message_window); interpreterRegisterOpcode(0x8228, op_get_attack_type); interpreterRegisterOpcode(0x822D, opCreateArray); interpreterRegisterOpcode(0x822E, opSetArray);