Ticket #1767: 1767.7.diff

File 1767.7.diff, 7.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    if (!lastWord.length)
     256        return text;
     257
     258    for (var word of autoCompleteList)
     259    {
     260        if (word.toLowerCase().indexOf(lastWord.toLowerCase()) != 0)
     261            continue;
     262       
     263        text = wordSplit.join(" ")
     264        if (text.length > 0)
     265            text += " ";
     266
     267        text += word;
     268        break;
     269    }
     270    return text;
     271}
     272
     273function autoCompleteNick(guiName, playerList)
     274{
     275    var input = Engine.GetGUIObjectByName(guiName);
     276    var text = input.caption;
     277    if (!text.length)
     278        return;
     279
     280    var autoCompleteList = [];
     281    for (var player of playerList)
     282        autoCompleteList.push(player.name);
     283
     284    var bufferPosition = input.buffer_position;
     285    var textTillBufferPosition = text.substring(0, bufferPosition);
     286    var newText = tryAutoComplete(textTillBufferPosition, autoCompleteList);
     287    input.caption = newText + text.substring(bufferPosition);
     288    input.buffer_position = bufferPosition + (newText.length - textTillBufferPosition.length);
     289}
     290 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

     
    613614            msg.hide = true;
    614615        recurse = true;
    615616        break;
     617    case "/allies":
     618        var player = g_Players[Engine.GetPlayerID()];
     619
     620        if (player && player.isAlly[sender])
     621            msg.context = translate("Ally");
     622        else
     623            msg.hide = true;
     624
     625        recurse = true;
     626        break;
    616627    case "/enemy":
    617628        // Check if we are in a team.
    618629        if (g_Players[Engine.GetPlayerID()] && g_Players[Engine.GetPlayerID()].team != -1)
  • source/gui/CInput.cpp

     
    5252{
    5353    AddSetting(GUIST_float,                 "buffer_zone");
    5454    AddSetting(GUIST_CStrW,                 "caption");
     55    AddSetting(GUIST_int,                   "buffer_position");
    5556    AddSetting(GUIST_int,                   "cell_id");
    5657    AddSetting(GUIST_CStrW,                 "font");
    5758    AddSetting(GUIST_CStrW,                 "mask_char");
     
    7980{
    8081}
    8182
     83void CInput::UpdateBufferPositionSetting()
     84{
     85    int* bufferPos = (int*)m_Settings["buffer_position"].m_pSetting;
     86    *bufferPos = m_iBufferPos;
     87}
     88
    8289void CInput::ClearComposedText()
    8390{
    8491    CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    8592    pCaption->erase(m_iInsertPos, m_iComposedLength);
    8693    m_iBufferPos = m_iInsertPos;
     94    UpdateBufferPositionSetting();
    8795    m_iComposedLength = 0;
    8896    m_iComposedPos = 0;
    8997}
     
    126134        UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
    127135
    128136        m_iBufferPos += text.length();
     137        UpdateBufferPositionSetting();
    129138        m_iBufferPos_Tail = -1;
    130139
    131140        UpdateAutoScroll();
     
    171180            m_iBufferPos_Tail = -1;
    172181        }
    173182
     183        UpdateBufferPositionSetting();
    174184        UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
    175185
    176186        UpdateAutoScroll();
     
    551561                break;
    552562        }
    553563
     564        UpdateBufferPositionSetting();
    554565        return IN_HANDLED;
    555566    }
    556567
     
    585596            UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
    586597
    587598            m_iBufferPos += (int)wcslen(text);
     599            UpdateBufferPositionSetting();
    588600
    589601            sys_clipboard_free(text);
    590602        }
     
    660672                }
    661673            }
    662674
     675            UpdateBufferPositionSetting();
    663676            DeleteCurSelection();
    664677        }
    665678        return IN_HANDLED;
     
    692705
    693706                m_iBufferPos++;
    694707            }
     708            UpdateBufferPositionSetting();
    695709            DeleteCurSelection();
    696710        }
    697711        return IN_HANDLED;
     
    748762            m_iBufferPos_Tail = -1;
    749763        }
    750764
     765        UpdateBufferPositionSetting();
    751766        UpdateAutoScroll();
    752767
    753768        return IN_HANDLED;
     
    796811            m_iBufferPos_Tail = -1;
    797812        }
    798813
     814        UpdateBufferPositionSetting();
    799815        UpdateAutoScroll();
    800816
    801817        return IN_HANDLED;
     
    841857            GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
    842858        }
    843859
     860        if (Message.value == CStr("buffer_position"))
     861        {
     862            GUI<int>::GetSetting(this, Message.value, m_iBufferPos);
     863        }
     864
    844865        if (Message.value == CStr("size") ||
    845866            Message.value == CStr("z") ||
    846867            Message.value == CStr("font") ||
     
    10981119    default:
    10991120        break;
    11001121    }
     1122    UpdateBufferPositionSetting();
    11011123}
    11021124
    11031125void CInput::UpdateCachedSize()
     
    15521574    // Ensure positions are valid after caption changes
    15531575    m_iBufferPos = std::min(m_iBufferPos, (int)caption.size());
    15541576    m_iBufferPos_Tail = std::min(m_iBufferPos_Tail, (int)caption.size());
     1577    UpdateBufferPositionSetting();
    15551578
    15561579    if (font_name.empty())
    15571580    {
     
    20532076    // Remove selection
    20542077    m_iBufferPos_Tail = -1;
    20552078    m_iBufferPos = virtualFrom;
     2079    UpdateBufferPositionSetting();
    20562080}
    20572081
    20582082bool CInput::SelectingText() const
  • source/gui/CInput.h

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    139139    // Clear composed IME input when supported (SDL2 only).
    140140    void ClearComposedText();
    141141
     142    void UpdateBufferPositionSetting();
    142143protected:
    143144    // Cursor position
    144145    //  (the second one is for selection of larger areas, -1 if not used)