diff --git a/src/openrct2/input.c b/src/openrct2/input.c index 19474acc90..f9a627d6e2 100644 --- a/src/openrct2/input.c +++ b/src/openrct2/input.c @@ -1419,6 +1419,22 @@ static void input_handle_console(sint32 key) } } +static void input_handle_chat(sint32 key) +{ + CHAT_INPUT input = CHAT_INPUT_NONE; + switch (key) { + case SDL_SCANCODE_ESCAPE: + input = CHAT_INPUT_CLOSE; + break; + case SDL_SCANCODE_RETURN: + input = CHAT_INPUT_SEND; + break; + } + if (input != CHAT_INPUT_NONE) { + chat_input(input); + } +} + /** * * rct2: 0x006E3B43 @@ -1540,7 +1556,7 @@ void game_handle_keyboard_input() input_handle_console(key); continue; } else if (gChatOpen) { - chat_input(key); + input_handle_chat(key); continue; } diff --git a/src/openrct2/interface/chat.c b/src/openrct2/interface/chat.c index e49038cbd3..f98906e165 100644 --- a/src/openrct2/interface/chat.c +++ b/src/openrct2/interface/chat.c @@ -215,19 +215,21 @@ void chat_history_add(const char * src) Mixer_Play_Effect(SOUND_NEWS_ITEM, 0, SDL_MIX_MAXVOLUME, 0, 1.5f, true); } -void chat_input(sint32 c) +void chat_input(CHAT_INPUT input) { - switch (c) { - case SDL_SCANCODE_RETURN: + switch (input) { + case CHAT_INPUT_SEND: if (strlen(_chatCurrentLine) > 0) { network_send_chat(_chatCurrentLine); } chat_clear_input(); chat_close(); - return; - case SDL_SCANCODE_ESCAPE: + break; + case CHAT_INPUT_CLOSE: chat_close(); - return; + break; + default: + break; } } diff --git a/src/openrct2/interface/chat.h b/src/openrct2/interface/chat.h index e3c17febb1..946dbd7c56 100644 --- a/src/openrct2/interface/chat.h +++ b/src/openrct2/interface/chat.h @@ -25,6 +25,13 @@ #define CHAT_MAX_MESSAGE_LENGTH 200 #define CHAT_MAX_WINDOW_WIDTH 600 +typedef enum CHAT_INPUT +{ + CHAT_INPUT_NONE, + CHAT_INPUT_SEND, + CHAT_INPUT_CLOSE, +} CHAT_INPUT; + extern bool gChatOpen; void chat_open(); @@ -36,7 +43,7 @@ void chat_update(); void chat_draw(rct_drawpixelinfo * dpi); void chat_history_add(const char *src); -void chat_input(sint32 c); +void chat_input(CHAT_INPUT input); sint32 chat_string_wrapped_get_height(void *args, sint32 width); sint32 chat_history_draw_string(rct_drawpixelinfo *dpi, void *args, sint32 x, sint32 y, sint32 width);