diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index d4bfef008..31fc886cd 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -2,6 +2,11 @@ #include #include +#ifdef USE_SDL1 +#include +#include +#include +#endif #include "DiabloUI/art_draw.h" #include "DiabloUI/button.h" @@ -223,13 +228,13 @@ void UiFocusPageDown() } } -void SelheroCatToName(char *inBuf, char *outBuf, int cnt) +void SelheroCatToName(const char *inBuf, char *outBuf, int cnt) { strncat(outBuf, inBuf, cnt - strlen(outBuf)); } #ifdef __vita__ -void selhero_SetName(char *in_buf, char *out_buf, int cnt) +void selhero_SetName(const char *in_buf, char *out_buf, int cnt) { strncpy(out_buf, in_buf, cnt); } @@ -337,12 +342,9 @@ void UiFocusNavigation(SDL_Event *event) #ifdef USE_SDL1 if ((event->key.keysym.mod & KMOD_CTRL) == 0) { Uint16 unicode = event->key.keysym.unicode; - if (unicode && (unicode & 0xFF80) == 0) { - char utf8[SDL_TEXTINPUTEVENT_TEXT_SIZE]; - utf8[0] = (char)unicode; - utf8[1] = '\0'; - SelheroCatToName(utf8, UiTextInput, UiTextInputLen); - } + std::wstring_convert, char32_t> convert; + std::string utf8 = convert.to_bytes(unicode); + SelheroCatToName(utf8.c_str(), UiTextInput, UiTextInputLen); } #endif break; diff --git a/Source/control.cpp b/Source/control.cpp index 39d8dc7ea..5f401d8bb 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1774,7 +1774,7 @@ void control_reset_talk() force_redraw = 255; } -bool control_talk_last_key(char vkey) +bool IsTalkActive() { if (!IsChatAvailable()) return false; @@ -1782,28 +1782,11 @@ bool control_talk_last_key(char vkey) if (!talkflag) return false; -#ifdef USE_SDL1 - if (vkey >= 0 && vkey < DVL_VK_SPACE) - return false; - - std::size_t result = strlen(TalkMessage); - if (result < 78) { - TalkMessage[result] = vkey; - TalkMessage[result + 1] = '\0'; - } -#endif - return true; } void control_new_text(string_view text) { - if (!IsChatAvailable()) - return; - - if (!talkflag) - return; - strncat(TalkMessage, text.data(), sizeof(TalkMessage) - strlen(TalkMessage) - 1); } diff --git a/Source/control.h b/Source/control.h index acc434bde..2d62a7bfd 100644 --- a/Source/control.h +++ b/Source/control.h @@ -176,7 +176,7 @@ bool control_check_talk_btn(); void control_release_talk_btn(); void control_type_message(); void control_reset_talk(); -bool control_talk_last_key(char vkey); +bool IsTalkActive(); void control_new_text(string_view text); bool control_presskeys(int vkey); void DiabloHotkeyMsg(uint32_t dwMsg); diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 8d81ca674..ed8e93127 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -537,7 +537,7 @@ void PressKey(int vkey) */ void PressChar(char vkey) { - if (gmenu_is_active() || control_talk_last_key(vkey) || sgnTimeoutCurs != CURSOR_NONE || MyPlayerIsDead) { + if (gmenu_is_active() || IsTalkActive() || sgnTimeoutCurs != CURSOR_NONE || MyPlayerIsDead) { return; } if (vkey == 'p' || vkey == 'P') { diff --git a/Source/miniwin/misc_msg.cpp b/Source/miniwin/misc_msg.cpp index 0ce5bf4a5..9a0722084 100644 --- a/Source/miniwin/misc_msg.cpp +++ b/Source/miniwin/misc_msg.cpp @@ -2,6 +2,11 @@ #include #include #include +#ifdef USE_SDL1 +#include +#include +#include +#endif #include "control.h" #include "controls/controller.h" @@ -474,6 +479,16 @@ bool FetchMessage_Real(tagMSG *lpMsg) break; case SDL_KEYDOWN: case SDL_KEYUP: { +#ifdef USE_SDL1 + if (gbRunGame && IsTalkActive()) { + Uint16 unicode = e.key.keysym.unicode; + if (unicode >= ' ') { + std::wstring_convert, char32_t> convert; + std::string utf8 = convert.to_bytes(unicode); + control_new_text(utf8); + } + } +#endif int key = TranslateSdlKey(e.key.keysym); if (key == -1) return FalseAvail(e.type == SDL_KEYDOWN ? "SDL_KEYDOWN" : "SDL_KEYUP", e.key.keysym.sym); @@ -537,7 +552,7 @@ bool FetchMessage_Real(tagMSG *lpMsg) break; return FalseAvail("SDL_TEXTEDITING", e.edit.length); case SDL_TEXTINPUT: - if (gbRunGame) { + if (gbRunGame && IsTalkActive()) { control_new_text(e.text.text); break; }