Discordify emotes a bit more :chonkbunckle:

- When autocompleting emote with enter, don't send it immediately
- Don't autocomplete after typing 1 character after : (allows text emotes like ":c")
This commit is contained in:
Indev 2025-11-26 22:56:04 +03:00 committed by NepDisk
parent 1979568959
commit 945b5da5a3
2 changed files with 13 additions and 10 deletions

View file

@ -1229,9 +1229,9 @@ boolean HU_Responder(event_t *ev)
&& !G_ControlBoundToKey(0, gc_talkkey, ev->data1, false)) && !G_ControlBoundToKey(0, gc_talkkey, ev->data1, false))
return false; return false;
M_TextInputHandleEmotes(&w_chat, c, &emote_autocomplete); if (M_TextInputHandleEmotes(&w_chat, c, &emote_autocomplete))
; // Do nothing
if (c == KEY_ENTER) else if (c == KEY_ENTER)
{ {
if (!CHAT_MUTE) if (!CHAT_MUTE)
HU_sendChatMessage(); HU_sendChatMessage();
@ -1776,7 +1776,7 @@ static void HU_DrawChat(void)
} }
} }
if (emote_autocomplete.emotestart != -1 && (emote_autocomplete.complete[0] || (w_chat.cursor - emote_autocomplete.emotestart) > 0)) if (emote_autocomplete.emotestart != -1 && (emote_autocomplete.complete[0] || (w_chat.cursor - emote_autocomplete.emotestart) > 1))
{ {
emote_t *suggest; emote_t *suggest;
int skip = 0; int skip = 0;

View file

@ -425,10 +425,10 @@ static int M_TextInputEmoteStart(textinput_t *input)
return emotestart; return emotestart;
} }
static void M_TextInputCompleteEmote(textinput_t *input, emote_autocomplete_t *autocomplete) static boolean M_TextInputCompleteEmote(textinput_t *input, emote_autocomplete_t *autocomplete)
{ {
if (input->cursor == 0) if (input->cursor == 0)
return; return false;
// If we're in "autocomplete" state, delete ':' for latest autocompleted emote // If we're in "autocomplete" state, delete ':' for latest autocompleted emote
if (autocomplete->complete[0]) if (autocomplete->complete[0])
@ -447,8 +447,8 @@ static void M_TextInputCompleteEmote(textinput_t *input, emote_autocomplete_t *a
int emotestart = autocomplete->emotestart; int emotestart = autocomplete->emotestart;
// No emote - no autocomplete // No emote - no autocomplete
if (emotestart == -1 || (size_t)emotestart == input->cursor) if (emotestart == -1 || input->cursor - emotestart < 2)
return; return false;
strlcpy(autocomplete->complete, &input->buffer[emotestart], input->cursor-emotestart+1); strlcpy(autocomplete->complete, &input->buffer[emotestart], input->cursor-emotestart+1);
} }
@ -466,7 +466,7 @@ static void M_TextInputCompleteEmote(textinput_t *input, emote_autocomplete_t *a
{ {
// Clear autocompletion state // Clear autocompletion state
autocomplete->complete[0] = 0; autocomplete->complete[0] = 0;
return; return false;
} }
} }
@ -478,6 +478,8 @@ static void M_TextInputCompleteEmote(textinput_t *input, emote_autocomplete_t *a
M_TextInputAddString(input, completed->name); M_TextInputAddString(input, completed->name);
M_TextInputAddChar(input, ':'); M_TextInputAddChar(input, ':');
return true;
} }
boolean M_TextInputHandleEmotes(textinput_t *input, INT32 key, emote_autocomplete_t *autocomplete) boolean M_TextInputHandleEmotes(textinput_t *input, INT32 key, emote_autocomplete_t *autocomplete)
@ -493,7 +495,8 @@ boolean M_TextInputHandleEmotes(textinput_t *input, INT32 key, emote_autocomplet
if (key == '\t' || (autocomplete->complete[0] == 0 && key == KEY_ENTER)) if (key == '\t' || (autocomplete->complete[0] == 0 && key == KEY_ENTER))
{ {
M_TextInputCompleteEmote(input, autocomplete); if (M_TextInputCompleteEmote(input, autocomplete) && key == KEY_ENTER) // Don't send message if we've autocompleted an emote
ret = true;
} }
else else
{ {