Ticket #1767: 1767.diff

File 1767.diff, 4.4 KB (added by trompetin17, 9 years ago)
  • binaries/data/mods/public/gui/common/functions_utility.js

     
    240240    // Limit the length to 20 characters
    241241    return sanitizedName.substr(0,20);
    242242}
     243
     244function tryAutoComplete(text, autoCompleteList)
     245{
     246    if (text.length == 0)
     247        return text;
     248
     249    var wordSplit = text.split(/\s+/g);
     250
     251    if(!wordSplit.length)
     252        return text;
     253
     254    var lastWord = wordSplit.pop();
     255    for (var wordAutoCompletion of autoCompleteList)
     256    {
     257        if (wordAutoCompletion.toLowerCase().indexOf(lastWord.toLowerCase()) == 0)
     258        {
     259            text = wordSplit.join(" ") + " " + wordAutoCompletion;
     260            break;
     261        }
     262    }
     263    return text;
     264}
     265 No newline at end of file
  • binaries/data/mods/public/gui/lobby/lobby.js

     
    753753{
    754754    var input = Engine.GetGUIObjectByName("chatInput");
    755755    var text = escapeText(input.caption);
    756     if (text.length)
     756    if (!text.length)
     757        return;
     758
     759    var autoCompletionList = [];
     760    for each (var playerObj in Engine.GetPlayerList())
    757761    {
    758         var matched = false;
    759         for each (var playerObj in Engine.GetPlayerList())
    760         {
    761             var player = playerObj.name;
    762             var breaks = text.match(/(\s+)/g) || [];
    763             text.split(/\s+/g).reduceRight(function (wordsSoFar, word, index)
    764             {
    765                 if (matched)
    766                     return null;
    767                 var matchCandidate = word + (breaks[index - 1] || "") + wordsSoFar;
    768                 if (player.toUpperCase().indexOf(matchCandidate.toUpperCase().trim()) == 0)
    769                 {
    770                     input.caption = text.replace(matchCandidate.trim(), player);
    771                     matched = true;
    772                 }
    773                 return matchCandidate;
    774             }, "");
    775         if (matched)
    776             break;
    777         }
     762        autoCompletionList.push(playerObj.name);
    778763    }
     764
     765    input.caption = tryAutoComplete(text, autoCompletionList);
    779766}
    780767
    781768function isValidNick(nick)
  • binaries/data/mods/public/gui/session/messages.js

     
    308308    }
    309309}
    310310
     311function autoCompleteNick()
     312{
     313    var input = Engine.GetGUIObjectByName("chatInput");
     314    var text = input.caption;
     315
     316    if (!text.length)
     317        return;
     318
     319    var autoCompletionList = [];
     320    for (var player of g_Players)
     321    {
     322        autoCompletionList.push(player.name);
     323    }
     324
     325    input.caption = tryAutoComplete(text, autoCompletionList);
     326}
     327
    311328function submitChatInput()
    312329{
    313330    var input = Engine.GetGUIObjectByName("chatInput");
     
    612629            msg.hide = true;
    613630        recurse = true;
    614631        break;
     632    case "/allies":
     633        var player = g_Players[Engine.GetPlayerID()];
     634
     635        if (player && player.isAlly[sender])
     636            msg.context = translate("Ally");
     637        else
     638            msg.hide = true;
     639       
     640        recurse = true;
     641        break;
    615642    case "/enemy":
    616643        // Check if we are in a team.
    617644        if (g_Players[Engine.GetPlayerID()] && g_Players[Engine.GetPlayerID()].team != -1)
  • binaries/data/mods/public/gui/session/session.xml

     
    195195    <object name="chatDialogPanel" size="50%-180 50%-48 50%+180 50%+36" type="image" hidden="true" sprite="genericPanel">
    196196        <object name="chatInput" size="16 12 100%-16 36" type="input" style="ModernInput" max_length="80">
    197197            <action on="Press">submitChatInput();</action>
     198            <action on="Tab">autoCompleteNick();</action>
    198199        </object>
    199200
    200201        <object size="16 100%-40 30%+16 100%-12" type="button" style="StoneButton">
  • source/gui/CInput.cpp

     
    840840
    841841            GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
    842842        }
     843       
     844        if (Message.value == CStr("caption"))
     845        {
     846            if (m_iBufferPos > 0)
     847            {
     848                CStrW caption;
     849                GUI<CStrW>::GetSetting(this, "caption", caption);
     850                m_iBufferPos = m_iBufferPos_Tail = (int)caption.size();
     851            }
     852        }
    843853
    844854        if (Message.value == CStr("size") ||
    845855            Message.value == CStr("z") ||