diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8b67cd7..3054577 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,7 +44,7 @@ target_sources(xsystem35 PRIVATE # Scenario target_sources(xsystem35 PRIVATE cali.c scenario.c variable.c cmd_check.c hankana2sjis.c nact.c - selection.c message.c savedata.c hankaku.c s39ain.c) + selection.c message.c savedata.c hankaku.c s39ain.c texthook.c) # Graphics target_sources(xsystem35 PRIVATE diff --git a/src/message.c b/src/message.c index 0aa12e9..c82e59a 100644 --- a/src/message.c +++ b/src/message.c @@ -35,6 +35,7 @@ #include "imput.h" #include "ags.h" #include "nact.h" +#include "texthook.h" /* ショートカット */ #define msg nact->msg @@ -116,6 +117,8 @@ void msg_putMessage(char *m) { msg_nextPage(TRUE); } + texthook_message(m); + /* 表示文字列を文字列変数にコピーする */ if (msg.mg_getString) { copyMsgToStrVar(m); @@ -188,6 +191,8 @@ void msg_putMessage(char *m) { } void msg_nextLine() { + texthook_newline(); + // puts("next Line"); if (msg.mg_getString) { msgget_at_r(); @@ -203,6 +208,8 @@ void msg_nextLine() { } void msg_nextPage(boolean innerclear) { + texthook_nextpage(); + // puts("next Page"); if (innerclear) { if (msg.WinBackgroundTransparent == 255) { @@ -297,6 +304,7 @@ void msg_openWindow(int W, int C1, int C2, int N, int M) { } void msg_setMessageLocation(int x, int y) { + texthook_newline(); msgcur.x = x; msgcur.y = y; nextLineIsAfterKaigyou = FALSE; diff --git a/src/sdl_event.c b/src/sdl_event.c index d9b40b3..e8a7f7f 100644 --- a/src/sdl_event.c +++ b/src/sdl_event.c @@ -38,6 +38,7 @@ #include "imput.h" #include "joystick.h" #include "sdl_input.c" +#include "texthook.h" static void sdl_getEvent(void); static void keyEventProsess(SDL_KeyboardEvent *e, boolean bool); @@ -238,6 +239,7 @@ static void sdl_getEvent(void) { int sdl_keywait(int msec, boolean cancel) { int key=0, n; int end = msec == INT_MAX ? INT_MAX : get_high_counter(SYSTEMCOUNTER_MSEC) + msec; + texthook_keywait(); while ((n = end - get_high_counter(SYSTEMCOUNTER_MSEC)) > 0) { if (n <= 16) diff --git a/src/texthook.c b/src/texthook.c new file mode 100644 index 0000000..8e3c237 --- /dev/null +++ b/src/texthook.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2019 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * +*/ + +#include +#include +#include "scenario.h" +#include "texthook.h" +#include "utfsjis.h" + +#ifdef __EMSCRIPTEN__ // ---------------------------------------------- +#include + +void texthook_message(const char *m) { + BYTE* s = sjis2lang((BYTE*)m); + EM_ASM_({ xsystem35.texthook.message(UTF8ToString($0), $1); }, + s, sl_getPage()); + free(s); +} + +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_message(const char *m) { + if (newlines) + printf("%d:", sl_getPage()); + BYTE* s = sjis2lang((BYTE*)m); + printf("%s", s); + free(s); + newlines = 0; +} + +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_message(const char *m) { +} + +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..41c2837 --- /dev/null +++ b/src/texthook.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2019 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * +*/ + +#ifndef __TEXTHOOK__ +#define __TEXTHOOK__ + +void texthook_message(const char *m); +void texthook_newline(void); +void texthook_nextpage(void); +void texthook_keywait(void); + +#endif /* __TEXTHOOK__ */