Ticket #1767: 1767.3.diff

File 1767.3.diff, 5.0 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(" ")
     260            if (text.length > 0)
     261                text += " ";
     262
     263            text += wordAutoCompletion;
     264            break;
     265        }
     266    }
     267    return text;
     268}
     269
     270//listPlayer parameter must be an array and every object with name property
     271function autoCompleteNick(guiName, listPlayer)
     272{
     273    var input = Engine.GetGUIObjectByName(guiName);
     274    var text = escapeText(input.caption);
     275    if (!text.length)
     276        return;
     277
     278    var autoCompleteList = [];
     279    for (var player of listPlayer)
     280        autoCompleteList.push(player.name);
     281
     282    input.caption = tryAutoComplete(text, autoCompleteList);
     283}
     284 No newline at end of file
  • binaries/data/mods/public/gui/lobby/lobby.js

     
    749749    }
    750750}
    751751
    752 function completeNick()
    753 {
    754     var input = Engine.GetGUIObjectByName("chatInput");
    755     var text = escapeText(input.caption);
    756     if (text.length)
    757     {
    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         }
    778     }
    779 }
    780 
    781752function isValidNick(nick)
    782753{
    783754    var prohibitedNicks = ["system"];
  • binaries/data/mods/public/gui/lobby/lobby.xml

     
    231231                <object name="chatText" size="0 0 100% 94%" type="text" style="ChatPanel" font="sans-13"/>
    232232                <object name="chatInput" size="0 94% 100% 100%" type="input" style="ModernInput" font="sans-13">
    233233                    <action on="Press">submitChatInput();</action>
    234                     <action on="Tab">completeNick();</action>
     234                    <action on="Tab">autoCompleteNick("chatInput", Engine.GetPlayerList());</action>
    235235                </object>
    236236            </object>
    237237        </object>
  • binaries/data/mods/public/gui/session/messages.js

     
    612612            msg.hide = true;
    613613        recurse = true;
    614614        break;
     615    case "/allies":
     616        var player = g_Players[Engine.GetPlayerID()];
     617
     618        if (player && player.isAlly[sender])
     619            msg.context = translate("Ally");
     620        else
     621            msg.hide = true;
     622
     623        recurse = true;
     624        break;
    615625    case "/enemy":
    616626        // Check if we are in a team.
    617627        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("chatInput", g_Players);</action>
    198199        </object>
    199200
    200201        <object size="16 100%-40 30%+16 100%-12" type="button" style="StoneButton">
  • source/gui/CInput.cpp

     
    841841            GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
    842842        }
    843843
     844        if (Message.value == CStr("caption") && m_iBufferPos > 0)
     845        {
     846                CStrW caption;
     847                GUI<CStrW>::GetSetting(this, "caption", caption);
     848                m_iBufferPos = m_iBufferPos_Tail = (int)caption.size();
     849        }
     850
    844851        if (Message.value == CStr("size") ||
    845852            Message.value == CStr("z") ||
    846853            Message.value == CStr("font") ||