]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Merge branch 'div0-stable' into Mario/advanced_chat Mario/advanced_chat
authorMario <mario@smbclan.net>
Sun, 12 Mar 2017 00:21:24 +0000 (10:21 +1000)
committerMario <mario@smbclan.net>
Sun, 12 Mar 2017 00:21:24 +0000 (10:21 +1000)
# Conflicts:
# console.c
# keys.c

1  2 
console.c
keys.c

diff --cc console.c
index 96653a582a6907a1170eb3f9ab0b2eca4118e1c4,51a1a1233d3bf1d4ec96027bcec445309a86548c..b40ccfeec44a6296e75a2d1288d30be69c9a4ae2
+++ 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 2d21aab4ffdc1d0ae019f9eef81bf640e0542c2a,d233471b1618fbcc929343cdd8f0d11070d47fce..2f7fc159f3c8c09814d0fe31ded0b504b7b133eb
--- 1/keys.c
--- 2/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];
-       if (key == K_ENTER || ascii == 10 || ascii == 13)
 +    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 || 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;
        }
  
                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;
        }