Ticket #1767: 1767.6.diff

File 1767.6.diff, 7.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    if (!lastWord.length)
     256        return text;
     257
     258    for (var wordAutoCompletion of autoCompleteList)
     259    {
     260        if (wordAutoCompletion.toLowerCase().indexOf(lastWord.toLowerCase()) == 0)
     261        {
     262            text = wordSplit.join(" ")
     263            if (text.length > 0)
     264                text += " ";
     265
     266            text += wordAutoCompletion;
     267            break;
     268        }
     269    }
     270    return text;
     271}
     272
     273//listPlayer parameter must be an array and every object with name property
     274function autoCompleteNick(guiName, listPlayer)
     275{
     276    var input = Engine.GetGUIObjectByName(guiName);
     277    var text = input.caption;
     278    if (!text.length)
     279        return;
     280
     281    var autoCompleteList = [];
     282    for (var player of listPlayer)
     283        autoCompleteList.push(player.name);
     284
     285    var bufferPosition = input.buffer_position;
     286    var textTillBufferPosition = text.substring(0, bufferPosition);
     287    var newText = tryAutoComplete(textTillBufferPosition, autoCompleteList);
     288    input.caption = newText + text.substring(bufferPosition);
     289    input.buffer_position = bufferPosition + (newText.length - textTillBufferPosition.length);
     290}
     291 No newline at end of file
  • binaries/data/mods/public/gui/lobby/lobby.js

     
    752752    }
    753753}
    754754
    755 function completeNick()
    756 {
    757     var input = Engine.GetGUIObjectByName("chatInput");
    758     var text = escapeText(input.caption);
    759     if (text.length)
    760     {
    761         var matched = false;
    762         for each (var playerObj in Engine.GetPlayerList())
    763         {
    764             var player = playerObj.name;
    765             var breaks = text.match(/(\s+)/g) || [];
    766             text.split(/\s+/g).reduceRight(function (wordsSoFar, word, index)
    767             {
    768                 if (matched)
    769                     return null;
    770                 var matchCandidate = word + (breaks[index - 1] || "") + wordsSoFar;
    771                 if (player.toUpperCase().indexOf(matchCandidate.toUpperCase().trim()) == 0)
    772                 {
    773                     input.caption = text.replace(matchCandidate.trim(), player);
    774                     matched = true;
    775                 }
    776                 return matchCandidate;
    777             }, "");
    778         if (matched)
    779             break;
    780         }
    781     }
    782 }
    783 
    784755function isValidNick(nick)
    785756{
    786757    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

  • source/gui/CInput.cpp

     			msg.hide = true;
     		recurse = true;
     		break;
    +	case "/allies":
    +		var player = g_Players[Engine.GetPlayerID()];
    +
    +		if (player && player.isAlly[sender])
    +			msg.context = translate("Ally");
    +		else
    +			msg.hide = true;
    +
    +		recurse = true;
    +		break;
     	case "/enemy":
     		// Check if we are in a team.
     		if (g_Players[Engine.GetPlayerID()] && g_Players[Engine.GetPlayerID()].team != -1)
     
    4242
    4343extern int g_yres;
    4444
     45#define UpdateBufferPositionSetting int* bufferPos = (int*)m_Settings["buffer_position"].m_pSetting; *bufferPos = m_iBufferPos;
     46
    4547//-------------------------------------------------------------------
    4648//  Constructor / Destructor
    4749//-------------------------------------------------------------------
     
    5254{
    5355    AddSetting(GUIST_float,                 "buffer_zone");
    5456    AddSetting(GUIST_CStrW,                 "caption");
     57    AddSetting(GUIST_int,                   "buffer_position");
    5558    AddSetting(GUIST_int,                   "cell_id");
    5659    AddSetting(GUIST_CStrW,                 "font");
    5760    AddSetting(GUIST_CStrW,                 "mask_char");
     
    8487    CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    8588    pCaption->erase(m_iInsertPos, m_iComposedLength);
    8689    m_iBufferPos = m_iInsertPos;
     90    UpdateBufferPositionSetting;
    8791    m_iComposedLength = 0;
    8892    m_iComposedPos = 0;
    8993}
     
    126130        UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
    127131
    128132        m_iBufferPos += text.length();
     133        UpdateBufferPositionSetting;
    129134        m_iBufferPos_Tail = -1;
    130135
    131136        UpdateAutoScroll();
     
    171176            m_iBufferPos_Tail = -1;
    172177        }
    173178
     179        UpdateBufferPositionSetting;
    174180        UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
    175181
    176182        UpdateAutoScroll();
     
    551557                break;
    552558        }
    553559
     560        UpdateBufferPositionSetting;
    554561        return IN_HANDLED;
    555562    }
    556563
     
    585592            UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
    586593
    587594            m_iBufferPos += (int)wcslen(text);
     595            UpdateBufferPositionSetting;
    588596
    589597            sys_clipboard_free(text);
    590598        }
     
    660668                }
    661669            }
    662670
     671            UpdateBufferPositionSetting;
    663672            DeleteCurSelection();
    664673        }
    665674        return IN_HANDLED;
     
    692701
    693702                m_iBufferPos++;
    694703            }
     704            UpdateBufferPositionSetting;
    695705            DeleteCurSelection();
    696706        }
    697707        return IN_HANDLED;
     
    748758            m_iBufferPos_Tail = -1;
    749759        }
    750760
     761        UpdateBufferPositionSetting;
    751762        UpdateAutoScroll();
    752763
    753764        return IN_HANDLED;
     
    796807            m_iBufferPos_Tail = -1;
    797808        }
    798809
     810        UpdateBufferPositionSetting;
    799811        UpdateAutoScroll();
    800812
    801813        return IN_HANDLED;
     
    841853            GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
    842854        }
    843855
     856        if (Message.value == CStr("buffer_position"))
     857        {
     858            GUI<int>::GetSetting(this, Message.value, m_iBufferPos);
     859        }
     860
    844861        if (Message.value == CStr("size") ||
    845862            Message.value == CStr("z") ||
    846863            Message.value == CStr("font") ||
     
    10981115    default:
    10991116        break;
    11001117    }
     1118    UpdateBufferPositionSetting;
    11011119}
    11021120
    11031121void CInput::UpdateCachedSize()
     
    15521570    // Ensure positions are valid after caption changes
    15531571    m_iBufferPos = std::min(m_iBufferPos, (int)caption.size());
    15541572    m_iBufferPos_Tail = std::min(m_iBufferPos_Tail, (int)caption.size());
     1573    UpdateBufferPositionSetting;
    15551574
    15561575    if (font_name.empty())
    15571576    {
     
    20532072    // Remove selection
    20542073    m_iBufferPos_Tail = -1;
    20552074    m_iBufferPos = virtualFrom;
     2075    UpdateBufferPositionSetting;
    20562076}
    20572077
    20582078bool CInput::SelectingText() const