Turn HU_queueChatChar into HU_sendChatMessage

# Conflicts:
#	src/hu_stuff.c
This commit is contained in:
LJ Sonic 2022-01-02 17:55:14 +01:00 committed by toaster
parent 4fc770aa7b
commit 4c59bb3b2b

View file

@ -978,10 +978,8 @@ static boolean HU_chatboxContainsOnlySpaces(void)
return true; return true;
} }
static void HU_queueChatChar(char c) static void HU_sendChatMessage(void)
{ {
if (c == KEY_ENTER)
{
char buf[2+256]; char buf[2+256];
char *msg = &buf[2]; char *msg = &buf[2];
size_t ci; size_t ci;
@ -994,7 +992,7 @@ static void HU_queueChatChar(char c)
// copy printable characters and terminating '\0' only. // copy printable characters and terminating '\0' only.
for (ci = 2; w_chat[ci-2]; ci++) for (ci = 2; w_chat[ci-2]; ci++)
{ {
c = w_chat[ci-2]; char c = w_chat[ci-2];
if (c >= ' ' && !(c & 0x80)) if (c >= ' ' && !(c & 0x80))
buf[ci] = c; buf[ci] = c;
}; };
@ -1027,7 +1025,6 @@ static void HU_queueChatChar(char c)
} }
strncpy(playernum, msg+3, 3); strncpy(playernum, msg+3, 3);
// check for undesirable characters in our "number" // check for undesirable characters in our "number"
if (!(isdigit(playernum[0]) && isdigit(playernum[1]))) if (!(isdigit(playernum[0]) && isdigit(playernum[1])))
{ {
@ -1069,13 +1066,11 @@ static void HU_queueChatChar(char c)
buf[1] = 0; // flags buf[1] = 0; // flags
SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1);
} }
return;
}
} }
// Handles key input and string input // Handles key input and string input
// //
static inline boolean HU_keyInChatString(char *s, char ch) static inline void HU_keyInChatString(char *s, char ch)
{ {
size_t l; size_t l;
@ -1106,25 +1101,25 @@ static inline boolean HU_keyInChatString(char *s, char ch)
s[c_input] = ch; // and replace this. s[c_input] = ch; // and replace this.
} }
c_input++; c_input++;
return true; return;
} }
return false; return;
} }
else if (ch == KEY_BACKSPACE) else if (ch == KEY_BACKSPACE)
{ {
size_t i = c_input; size_t i = c_input;
if (c_input <= 0) if (c_input <= 0)
return false; return;
if (!s[i-1]) if (!s[i-1])
return false; return;
if (i >= strlen(s)-1) if (i >= strlen(s)-1)
{ {
s[strlen(s)-1] = 0; s[strlen(s)-1] = 0;
c_input--; c_input--;
return false; return;
} }
for (; (i < HU_MAXMSGLEN); i++) for (; (i < HU_MAXMSGLEN); i++)
@ -1133,10 +1128,6 @@ static inline boolean HU_keyInChatString(char *s, char ch)
} }
c_input--; c_input--;
} }
else if (ch != KEY_ENTER)
return false; // did not eat key
return true; // ate the key
} }
#endif #endif
@ -1246,11 +1237,6 @@ boolean HU_Responder(event_t *ev)
{ {
memcpy(&w_chat[chatlen], paste, pastelen); // copy all of that. memcpy(&w_chat[chatlen], paste, pastelen); // copy all of that.
c_input += pastelen; c_input += pastelen;
/*size_t i = 0;
for (;i<pastelen;i++)
{
HU_queueChatChar(paste[i]); // queue it so that it's actually sent. (this chat write thing is REALLY messy.)
}*/
return true; return true;
} }
else // otherwise, we need to shift everything and make space, etc etc else // otherwise, we need to shift everything and make space, etc etc
@ -1270,12 +1256,11 @@ boolean HU_Responder(event_t *ev)
} }
} }
if (!CHAT_MUTE && HU_keyInChatString(w_chat,c))
{
HU_queueChatChar(c);
}
if (c == KEY_ENTER) if (c == KEY_ENTER)
{ {
if (!CHAT_MUTE)
HU_sendChatMessage();
chat_on = false; chat_on = false;
c_input = 0; // reset input cursor c_input = 0; // reset input cursor
chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :) chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :)
@ -1316,6 +1301,9 @@ boolean HU_Responder(event_t *ev)
else else
c_input++; c_input++;
} }
else if (!CHAT_MUTE)
HU_keyInChatString(w_chat, c);
return true; return true;
} }
#endif #endif