Ticket #1767: 1767.4.diff

File 1767.4.diff, 15.3 KB (added by trompetin17, 9 years ago)

remove trailing space too

  • 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    var bufferPosition = input.buffer_position;
     283    var textTillBufferPosition = text.substring(0, bufferPosition);
     284    warn(textTillBufferPosition);
     285    var newText = tryAutoComplete(textTillBufferPosition, autoCompleteList);
     286    input.caption = newText + text.substring(bufferPosition);
     287    input.buffer_position = bufferPosition + (newText.length - textTillBufferPosition.length);
     288}
     289 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

     
    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
     
    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}
     
    124128            pCaption->insert(m_iBufferPos, text);
    125129
    126130        UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
    127        
     131
    128132        m_iBufferPos += text.length();
     133        UpdateBufferPositionSetting;
    129134        m_iBufferPos_Tail = -1;
    130        
     135
    131136        UpdateAutoScroll();
    132137
    133138        return IN_HANDLED;
     
    140145        const char *rawText = ev->ev.edit.text;
    141146        int rawLength = strlen(rawText);
    142147        std::wstring wtext = wstring_from_utf8(rawText);
    143        
     148
    144149        debug_printf(L"SDL_TEXTEDITING: text=%hs, start=%d, length=%d\n", rawText, ev->ev.edit.start, ev->ev.edit.length);
    145150        m_WantedX=0.0f;
    146151
     
    166171            m_iComposedLength = wtext.length();
    167172            m_iComposedPos = ev->ev.edit.start < m_iComposedLength ? ev->ev.edit.start : m_iComposedLength;
    168173            m_iBufferPos = m_iInsertPos + m_iComposedPos;
    169        
     174
    170175            // TODO: composed text selection - what does ev.edit.length do?
    171176            m_iBufferPos_Tail = -1;
    172177        }
    173        
     178
     179        UpdateBufferPositionSetting;
    174180        UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
    175181
    176182        UpdateAutoScroll();
     
    228234                                        pCaption->Right( (long) pCaption->length()-m_iBufferPos );
    229235
    230236                        --m_iBufferPos;
    231                    
     237
    232238                        UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
    233239                    }
    234240                }
     
    372378                        m_iBufferPos = m_iBufferPos_Tail;
    373379
    374380                    m_iBufferPos_Tail = -1;
    375                 }           
     381                }
    376382
    377383                UpdateAutoScroll();
    378384                break;
     
    414420                    if (m_iBufferPos >= current->m_ListStart &&
    415421                        m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size())
    416422                        break;
    417                    
     423
    418424                    ++current;
    419425                }
    420426
     
    437443                    m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX);
    438444                }
    439445                // else we can't move up
    440                
     446
    441447                UpdateAutoScroll();
    442448            }
    443449                break;
     
    459465                    if (m_iBufferPos >= current->m_ListStart &&
    460466                        m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size())
    461467                        break;
    462                    
     468
    463469                    ++current;
    464470                }
    465471
     
    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        }
     
    644652
    645653                m_iBufferPos--;
    646654            }
    647                
     655
    648656            // If we end up on a puctuation char we just delete it (treat punct like a word)
    649657            if (iswpunct(searchString[m_iBufferPos - 1]))
    650658                m_iBufferPos--;
     
    660668                }
    661669            }
    662670
     671            UpdateBufferPositionSetting;
    663672            DeleteCurSelection();
    664673        }
    665674        return IN_HANDLED;
     
    692701
    693702                m_iBufferPos++;
    694703            }
     704            UpdateBufferPositionSetting;
    695705            DeleteCurSelection();
    696706        }
    697         return IN_HANDLED;         
     707        return IN_HANDLED;
    698708    }
    699709    else if (hotkey == "text.move.left")
    700710    {
    701711        m_WantedX=0.0f;
    702                
     712
    703713        if (shiftKeyPressed || !SelectingText())
    704714        {
    705715            if (!shiftKeyPressed)
     
    723733
    724734                    m_iBufferPos--;
    725735                }
    726                
     736
    727737                // If we end up on a puctuation char we just select it (treat punct like a word)
    728738                if (iswpunct(searchString[m_iBufferPos - 1]))
    729739                    m_iBufferPos--;
     
    748758            m_iBufferPos_Tail = -1;
    749759        }
    750760
     761        UpdateBufferPositionSetting;
    751762        UpdateAutoScroll();
    752763
    753764        return IN_HANDLED;
     
    794805                m_iBufferPos = m_iBufferPos_Tail;
    795806
    796807            m_iBufferPos_Tail = -1;
    797         }           
     808        }
    798809
     810        UpdateBufferPositionSetting;
    799811        UpdateAutoScroll();
    800812
    801813        return IN_HANDLED;
     
    825837            (Message.value == CStr("size") ||
    826838             Message.value == CStr("z") ||
    827839             Message.value == CStr("absolute")))
    828         {       
     840        {
    829841            GetScrollBar(0).SetX(m_CachedActualSize.right);
    830842            GetScrollBar(0).SetY(m_CachedActualSize.top);
    831843            GetScrollBar(0).SetZ(GetBufferedZ());
     
    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") ||
     
    868885
    869886            UpdateText();
    870887        }
    871        
     888
    872889        }break;
    873890
    874891    case GUIM_MOUSE_PRESS_LEFT:
     
    902919        }
    903920
    904921        m_SelectingText = true;
    905        
     922
    906923        UpdateAutoScroll();
    907924
    908925        // If we immediately release the button it will just be seen as a click
     
    10981115    default:
    10991116        break;
    11001117    }
     1118    UpdateBufferPositionSetting;
    11011119}
    11021120
    11031121void CInput::UpdateCachedSize()
     
    11551173    }
    11561174
    11571175    if (GetGUI())
    1158     {   
     1176    {
    11591177        CStrW font_name_w;
    11601178        CColor color, color_selected;
    11611179        //CStrW caption;
     
    11631181        GUI<CColor>::GetSetting(this, "textcolor", color);
    11641182        GUI<CColor>::GetSetting(this, "textcolor_selected", color_selected);
    11651183        CStrIntern font_name(font_name_w.ToUTF8());
    1166        
     1184
    11671185        // Get pointer of caption, it might be very large, and we don't
    11681186        //  want to copy it continuously.
    11691187        CStrW *pCaption = NULL;
     
    11801198
    11811199        CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL;
    11821200        int cell_id;
    1183        
     1201
    11841202        GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
    11851203        GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_selectarea", sprite_selectarea);
    1186    
     1204
    11871205        GUI<int>::GetSetting(this, "cell_id", cell_id);
    11881206
    11891207        GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
     
    12441262        float ls = (float)font.GetLineSpacing();
    12451263
    12461264        CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text);
    1247        
     1265
    12481266        CTextRenderer textRenderer(tech->GetShader());
    12491267        textRenderer.Font(font_name);
    12501268
     
    12541272            (float)(int)(m_CachedActualSize.left) + buffer_zone,
    12551273            (float)(int)(m_CachedActualSize.top+h) + buffer_zone,
    12561274            bz+0.1f);
    1257        
     1275
    12581276        // U+FE33: PRESENTATION FORM FOR VERTICAL LOW LINE
    12591277        // (sort of like a | which is aligned to the left of most characters)
    12601278
     
    14111429
    14121430        // Reset some from previous run
    14131431        buffered_y = -scroll;
    1414        
     1432
    14151433        // Setup initial color (then it might change and change back, when drawing selected area)
    14161434        textRenderer.Color(color);
    14171435
     
    14181436        tech->BeginPass();
    14191437
    14201438        bool using_selected_color = false;
    1421        
     1439
    14221440        for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin();
    14231441             it != m_CharacterPositions.end();
    14241442             ++it, buffered_y += ls)
     
    14321450                }
    14331451
    14341452                CMatrix3D savedTransform = textRenderer.GetTransform();
    1435                
     1453
    14361454                // Text must always be drawn in integer values. So we have to convert scroll
    14371455                if (multiline)
    14381456                    textRenderer.Translate(0.f, -(float)(int)scroll, 0.f);
     
    14921510                    }
    14931511
    14941512                    // check it's now outside a one-liner, then we'll break
    1495                     if (!multiline && i < (int)it->m_ListOfX.size())               
     1513                    if (!multiline && i < (int)it->m_ListOfX.size())
    14961514                    {
    14971515                        if (it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth()-buffer_zone)
    14981516                            break;
     
    15141532                textRenderer.SetTransform(savedTransform);
    15151533            }
    15161534
    1517             textRenderer.Translate(0.f, ls, 0.f);   
     1535            textRenderer.Translate(0.f, ls, 0.f);
    15181536        }
    15191537
    15201538        textRenderer.Render();
     
    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    {
     
    15631582
    15641583    SRow row;
    15651584    row.m_ListStart = 0;
    1566    
     1585
    15671586    int to = 0; // make sure it's initialized
    15681587
    15691588    if (to_before == -1)
     
    16701689        // set 'from' to the row we'll destroy from
    16711690        //  and 'to' to the row we'll destroy to
    16721691        from = destroy_row_from->m_ListStart;
    1673        
     1692
    16741693        if (destroy_row_to != m_CharacterPositions.end())
    16751694            to = destroy_row_to->m_ListStart; // notice it will iterate [from, to), so it will never reach to.
    16761695        else
     
    16841703        --temp_it;
    16851704
    16861705        current_line = m_CharacterPositions.erase(destroy_row_from, destroy_row_to);
    1687        
     1706
    16881707        // If there has been a change in number of characters
    16891708        //  we need to change all m_ListStart that comes after
    16901709        //  the interval we just destroyed. We'll change all
     
    17071726                to += delta;
    17081727        }
    17091728    }
    1710    
     1729
    17111730    int last_word_started=from;
    17121731    //int last_list_start=-1;   // unused
    17131732    float x_pos = 0.f;
     
    17211740        {
    17221741            if (i==to-1 && to != (int)caption.length())
    17231742                break; // it will be added outside
    1724            
     1743
    17251744            current_line = m_CharacterPositions.insert( current_line, row );
    17261745            ++current_line;
    17271746
     
    17601779                    // regular word-wrap
    17611780                    row.m_ListOfX.resize(row.m_ListOfX.size() - (i-last_word_started+1));
    17621781                }
    1763                
     1782
    17641783                // Now, create a new line:
    17651784                //  notice: when we enter a newline, you can stand with the cursor
    17661785                //  both before and after that character, being on different
     
    18681887                // set 'from' to the from row we'll destroy
    18691888                //  and 'to' to 'to_after'
    18701889                from = destroy_row_from->m_ListStart;
    1871                
     1890
    18721891                if (destroy_row_to != m_CharacterPositions.end())
    18731892                    to = destroy_row_to->m_ListStart; // notice it will iterate [from, to[, so it will never reach to.
    18741893                else
     
    19361955        GUI<CStrW>::GetSetting(this, "font", font_name_w);
    19371956        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    19381957        CStrIntern font_name(font_name_w.ToUTF8());
    1939        
     1958
    19401959        float scroll=0.f;
    19411960        if (scrollbar)
    19421961        {
     
    19852004
    19862005    //m_iBufferPos = m_CharacterPositions.get.m_ListStart;
    19872006    retPosition = current->m_ListStart;
    1988    
     2007
    19892008    // Okay, now loop through the glyphs to find the appropriate X position
    19902009    float dummy;
    19912010    retPosition += GetXTextPosition(current, mouse.x, dummy);
     
    20532072    // Remove selection
    20542073    m_iBufferPos_Tail = -1;
    20552074    m_iBufferPos = virtualFrom;
     2075    UpdateBufferPositionSetting;
    20562076}
    20572077
    20582078bool CInput::SelectingText() const
     
    20892109        GUI<CStrW>::GetSetting(this, "font", font_name_w);
    20902110        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    20912111        CStrIntern font_name(font_name_w.ToUTF8());
    2092        
     2112
    20932113        float scroll=0.f;
    20942114        if (!scrollbar)
    20952115            return;
    20962116
    20972117        scroll = GetScrollBar(0).GetPos();
    2098        
     2118
    20992119        // Now get the height of the font.
    21002120                        // TODO: Get the real font
    21012121        CFontMetrics font(font_name);
     
    21122132            if (m_iBufferPos >= current->m_ListStart &&
    21132133                m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size())
    21142134                break;
    2115            
     2135
    21162136            ++current;
    21172137            ++row;
    21182138        }