From: Mario Date: Sun, 12 Mar 2017 00:21:24 +0000 (+1000) Subject: Merge branch 'div0-stable' into Mario/advanced_chat X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=refs%2Fheads%2FMario%2Fadvanced_chat;p=xonotic%2Fdarkplaces.git Merge branch 'div0-stable' into Mario/advanced_chat # Conflicts: # console.c # keys.c --- d0b450f13eb5b9ab2694049f0df390183b1b8f27 diff --cc console.c index 96653a58,51a1a123..b40ccfee --- a/console.c +++ b/console.c @@@ -714,7 -714,7 +714,7 @@@ static void Con_MessageMode_f (void if(Cmd_Argc() > 1) { dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args()); - chat_bufferlen = chat_cursor = strlen(chat_buffer); // Izy's patch - chat_bufferlen = (unsigned int)strlen(chat_buffer); ++ chat_bufferlen = chat_cursor = (unsigned int)strlen(chat_buffer); // Izy's patch } } @@@ -731,7 -731,7 +731,7 @@@ static void Con_MessageMode2_f (void if(Cmd_Argc() > 1) { dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args()); - chat_bufferlen = chat_cursor = strlen(chat_buffer); // Izy's patch - chat_bufferlen = (unsigned int)strlen(chat_buffer); ++ chat_bufferlen = chat_cursor = (unsigned int)strlen(chat_buffer); // Izy's patch } } @@@ -746,9 -746,9 +746,9 @@@ static void Con_CommandMode_f (void if(Cmd_Argc() > 1) { dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args()); - chat_bufferlen = chat_cursor = strlen(chat_buffer); // Izy's patch - chat_bufferlen = (unsigned int)strlen(chat_buffer); ++ chat_bufferlen = chat_cursor = (unsigned int)strlen(chat_buffer); // Izy's patch } - chat_mode = -1; // command + chat_mode = DP_CHAT_MODE_COMMAND; // command } /* diff --cc keys.c index 2d21aab4,d233471b..2f7fc159 --- a/keys.c +++ b/keys.c @@@ -1201,81 -1190,24 +1190,81 @@@ Key_Console (int key, int unicode //============================================================================ -int chat_mode; +dp_chat_mode_t chat_mode; char chat_buffer[MAX_INPUTLINE]; unsigned int chat_bufferlen = 0; +unsigned int chat_cursor = 0; +dp_chat_modifiers_t chat_modifiers = DP_CHAT_MODIFIERS_OFF; static void -Key_Message (int key, int ascii) +dp_chat_modifiers_cloning_tool(dp_chat_modifiers_t *dest, const dp_chat_modifiers_t *src) +{ + *dest = *src; +} + +static void +Key_Message_Reset_All_Modifiers (void) // Added by Izy (izy from izysoftware.com) +{ + const dp_chat_modifiers_t off = DP_CHAT_MODIFIERS_OFF; + chat_modifiers = off; +} + +static qboolean +Key_Message_Modifiers_Enabled (void) // Added by Izy (izy from izysoftware.com) +{ + const dp_chat_modifiers_t off = DP_CHAT_MODIFIERS_OFF; + return memcmp(&chat_modifiers, &off, sizeof(off)) != 0; +} + +typedef struct +{ + int key; + int ascii; + qboolean down; +} dp_chat_fakekey_t; + +static void Key_Message_SendFakeKeys(const dp_chat_fakekey_t *fakekeys, const size_t count); + +static void +Key_Message (int key, int ascii, qboolean down) { char vabuf[1024]; + unsigned int inc; /* Added by Izy (izy from izysoftware.com) - uint */ + size_t dec; /* Added by Izy (izy from izysoftware.com) - size_t */ + unsigned charscounter; + size_t sizeofchar_to_replace; + const dp_chat_fakekey_t fake_backspace[] = {{K_LEFTARROW, 0, true}, {K_DEL, 0, true}}; + const dp_chat_fakekey_t fake_del[] = {{K_DEL, 0, true}}; + + if(key == 133 && ascii == 0) // Added by Izy (izy from izysoftware.com) + chat_modifiers.ctrl = down; + if(key == 147 && ascii == 0 && down) // Added by Izy (izy from izysoftware.com) + chat_modifiers.ins = chat_modifiers.ins == false; + + if(down == false) // Izy's Patch + return; + - if (key == K_ENTER || ascii == 10 || ascii == 13) + if (key == K_ENTER || key == K_KP_ENTER || ascii == 10 || ascii == 13) { - if(chat_mode < 0) - Cmd_ExecuteString(chat_buffer, src_command, true); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases! - else - Cmd_ForwardStringToServer(va(vabuf, sizeof(vabuf), "%s %s", chat_mode ? "say_team" : "say ", chat_buffer)); + + switch(chat_mode) + { + case DP_CHAT_MODE_COMMAND: + // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases! + Cmd_ExecuteString(chat_buffer, src_command, true); + break; + case DP_CHAT_MODE_SAY: + Cmd_ForwardStringToServer(va(vabuf, sizeof(vabuf), "%s %s", "say", chat_buffer)); + break; + case DP_CHAT_MODE_SAYTEAM: + Cmd_ForwardStringToServer(va(vabuf, sizeof(vabuf), "%s %s", "say_team", chat_buffer)); + break; + } key_dest = key_game; - chat_bufferlen = 0; + chat_bufferlen = chat_cursor = 0; chat_buffer[0] = 0; + Key_Message_Reset_All_Modifiers(); // Izy return; } @@@ -1287,21 -1220,10 +1276,17 @@@ return; } - // delete char before cursor - if (key == K_BACKSPACE) // Added by Izy (izy from izysoftware.com) - { - if (key == K_BACKSPACE) { - if (chat_bufferlen) { - chat_bufferlen = (unsigned int)u8_prevbyte(chat_buffer, chat_bufferlen); - chat_buffer[chat_bufferlen] = 0; ++ if (key == K_BACKSPACE) ++ { + if(chat_cursor > 0) - { - // Backspace is always equivalent to K_LEFTARROW + K_DEL - #if 1 // ok, allow the quick fast case - if(chat_cursor == chat_bufferlen) - { - chat_bufferlen = chat_cursor = u8_prevbyte(chat_buffer, chat_bufferlen); - chat_buffer[chat_bufferlen] = 0; - return; - } - #endif - Key_Message_SendFakeKeys(fake_backspace, sizeof(fake_backspace)/sizeof(fake_backspace[0])); ++ { ++ if (chat_cursor == chat_bufferlen) ++ { ++ chat_bufferlen = chat_cursor = (unsigned int)u8_prevbyte(chat_buffer, chat_bufferlen); ++ chat_buffer[chat_bufferlen] = 0; ++ return; ++ } ++ Key_Message_SendFakeKeys(fake_backspace, sizeof(fake_backspace)/sizeof(fake_backspace[0])); } return; }