diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6720097..5860e35 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,7 @@ set(SRC_COMMON sdlmain.cpp fileio.cpp utfsjis.cpp + texthook.cpp sys/ags.cpp sys/ags_cursor.cpp sys/ags_draw.cpp diff --git a/src/sys/ags_text.cpp b/src/sys/ags_text.cpp index 008bec2..6a30525 100644 --- a/src/sys/ags_text.cpp +++ b/src/sys/ags_text.cpp @@ -7,6 +7,7 @@ #include #include "ags.h" #include "utfsjis.h" +#include "texthook.h" static bool antialias = false; @@ -52,6 +53,9 @@ void AGS::draw_text(char string[]) if((0xeb9f <= code && code <= 0xebfc) || (0xec40 <= code && code <= 0xec9e)) { draw_gaiji(screen, dest_x, dest_y, code, font_size, font_color); } else { + if (!draw_menu) + texthook_character(nact->get_scenario_page(), sjis_to_unicode(code)); + if (antialias) draw_char_antialias(screen, dest_x, dest_y, code, font_size, font_color, antialias_cache); else diff --git a/src/sys/nact.h b/src/sys/nact.h index 794cb28..e2c15c2 100644 --- a/src/sys/nact.h +++ b/src/sys/nact.h @@ -254,6 +254,8 @@ public: // デバッグログ void output_console(char log[]); + + int get_scenario_page() const { return scenario_page; } }; #endif diff --git a/src/sys/nact_input.cpp b/src/sys/nact_input.cpp index 7e9b3d7..d3a7a03 100644 --- a/src/sys/nact_input.cpp +++ b/src/sys/nact_input.cpp @@ -6,6 +6,7 @@ #include "nact.h" #include "ags.h" +#include "texthook.h" static int mousex, mousey; @@ -37,6 +38,8 @@ uint8 NACT::get_key() { uint8 val = 0; + texthook_keywait(); + if (pump_events(ags->screen_height)) terminate = true; diff --git a/src/sys/nact_sys3.cpp b/src/sys/nact_sys3.cpp index ef02c2a..a489fc0 100644 --- a/src/sys/nact_sys3.cpp +++ b/src/sys/nact_sys3.cpp @@ -11,6 +11,7 @@ #include "mako.h" #include "crc32.h" #include "../fileio.h" +#include "texthook.h" void NACT::cmd_calc() { @@ -423,6 +424,8 @@ void NACT::cmd_open_obj(int verb) void NACT::cmd_a() { + texthook_nextpage(); + #if defined(_DEBUG_CONSOLE) char log[128]; sprintf_s(log, 128, "A\n"); @@ -1139,6 +1142,8 @@ void NACT::cmd_q() void NACT::cmd_r() { + texthook_newline(); + #if defined(_DEBUG_CONSOLE) char log[128]; sprintf_s(log, 128, "R\n"); diff --git a/src/texthook.cpp b/src/texthook.cpp new file mode 100644 index 0000000..a76e5a3 --- /dev/null +++ b/src/texthook.cpp @@ -0,0 +1,77 @@ +#include +#include "texthook.h" + +#ifdef __EMSCRIPTEN__ // ---------------------------------------------- +#include + +void texthook_character(int page, int character) { + EM_ASM_({ xsystem35.texthook.message(String.fromCharCode($0), $1); }, + character, page); +} + +EM_JS(void, texthook_newline, (void), { + xsystem35.texthook.newline(); +}); + +EM_JS(void, texthook_nextpage, (void), { + xsystem35.texthook.nextpage(); +}); + +EM_JS(void, texthook_keywait, (void), { + xsystem35.texthook.keywait(); +}); + +#elif defined(TEXTHOOK_PRINT) // -------------------------------------- + +static int newlines = 0; + +void texthook_character(int page, int c) { + if (newlines) + printf("%d:", page); + newlines = 0; + + if (c <= 0x7f) { + putchar(c); + } else if (c <= 0x7ff) { + putchar(0xc0 | c >> 6); + putchar(0x80 | (c & 0x3f)); + } else { + putchar(0xe0 | c >> 12); + putchar(0x80 | (c >> 6 & 0x3f)); + putchar(0x80 | (c & 0x3f)); + } +} + +void texthook_newline(void) { + if (newlines < 2) { + putchar('\n'); + newlines++; + } +} + +void texthook_nextpage(void) { + while (newlines < 2) { + putchar('\n'); + newlines++; + } +} + +void texthook_keywait(void) { + texthook_newline(); +} + +#else // -------------------------------------------------------------- + +void texthook_character(int page, int c) { +} + +void texthook_newline(void) { +} + +void texthook_nextpage(void) { +} + +void texthook_keywait(void) { +} + +#endif // ------------------------------------------------------------- diff --git a/src/texthook.h b/src/texthook.h new file mode 100644 index 0000000..aba722f --- /dev/null +++ b/src/texthook.h @@ -0,0 +1,13 @@ +#ifndef _TEXTHOOK_H_ +#define _TEXTHOOK_H_ + +extern "C" { + +void texthook_character(int page, int character); +void texthook_newline(void); +void texthook_nextpage(void); +void texthook_keywait(void); + +} + +#endif /* _TEXTHOOK_H_ */