Ticket #1767: 1767.7.diff
File 1767.7.diff, 7.4 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/common/functions_utility.js
240 240 // Limit the length to 20 characters 241 241 return sanitizedName.substr(0,20); 242 242 } 243 244 function 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 273 function 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
752 752 } 753 753 } 754 754 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 784 755 function isValidNick(nick) 785 756 { 786 757 var prohibitedNicks = ["system"]; -
binaries/data/mods/public/gui/lobby/lobby.xml
231 231 <object name="chatText" size="0 0 100% 94%" type="text" style="ChatPanel" font="sans-13"/> 232 232 <object name="chatInput" size="0 94% 100% 100%" type="input" style="ModernInput" font="sans-13"> 233 233 <action on="Press">submitChatInput();</action> 234 <action on="Tab"> completeNick();</action>234 <action on="Tab">autoCompleteNick("chatInput", Engine.GetPlayerList());</action> 235 235 </object> 236 236 </object> 237 237 </object> -
binaries/data/mods/public/gui/session/messages.js
613 614 msg.hide = true; 614 615 recurse = true; 615 616 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; 616 627 case "/enemy": 617 628 // Check if we are in a team. 618 629 if (g_Players[Engine.GetPlayerID()] && g_Players[Engine.GetPlayerID()].team != -1) -
source/gui/CInput.cpp
52 52 { 53 53 AddSetting(GUIST_float, "buffer_zone"); 54 54 AddSetting(GUIST_CStrW, "caption"); 55 AddSetting(GUIST_int, "buffer_position"); 55 56 AddSetting(GUIST_int, "cell_id"); 56 57 AddSetting(GUIST_CStrW, "font"); 57 58 AddSetting(GUIST_CStrW, "mask_char"); … … 79 80 { 80 81 } 81 82 83 void CInput::UpdateBufferPositionSetting() 84 { 85 int* bufferPos = (int*)m_Settings["buffer_position"].m_pSetting; 86 *bufferPos = m_iBufferPos; 87 } 88 82 89 void CInput::ClearComposedText() 83 90 { 84 91 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 85 92 pCaption->erase(m_iInsertPos, m_iComposedLength); 86 93 m_iBufferPos = m_iInsertPos; 94 UpdateBufferPositionSetting(); 87 95 m_iComposedLength = 0; 88 96 m_iComposedPos = 0; 89 97 } … … 126 134 UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); 127 135 128 136 m_iBufferPos += text.length(); 137 UpdateBufferPositionSetting(); 129 138 m_iBufferPos_Tail = -1; 130 139 131 140 UpdateAutoScroll(); … … 171 180 m_iBufferPos_Tail = -1; 172 181 } 173 182 183 UpdateBufferPositionSetting(); 174 184 UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); 175 185 176 186 UpdateAutoScroll(); … … 551 561 break; 552 562 } 553 563 564 UpdateBufferPositionSetting(); 554 565 return IN_HANDLED; 555 566 } 556 567 … … 585 596 UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); 586 597 587 598 m_iBufferPos += (int)wcslen(text); 599 UpdateBufferPositionSetting(); 588 600 589 601 sys_clipboard_free(text); 590 602 } … … 660 672 } 661 673 } 662 674 675 UpdateBufferPositionSetting(); 663 676 DeleteCurSelection(); 664 677 } 665 678 return IN_HANDLED; … … 692 705 693 706 m_iBufferPos++; 694 707 } 708 UpdateBufferPositionSetting(); 695 709 DeleteCurSelection(); 696 710 } 697 711 return IN_HANDLED; … … 748 762 m_iBufferPos_Tail = -1; 749 763 } 750 764 765 UpdateBufferPositionSetting(); 751 766 UpdateAutoScroll(); 752 767 753 768 return IN_HANDLED; … … 796 811 m_iBufferPos_Tail = -1; 797 812 } 798 813 814 UpdateBufferPositionSetting(); 799 815 UpdateAutoScroll(); 800 816 801 817 return IN_HANDLED; … … 841 857 GetScrollBar(0).SetScrollBarStyle(scrollbar_style); 842 858 } 843 859 860 if (Message.value == CStr("buffer_position")) 861 { 862 GUI<int>::GetSetting(this, Message.value, m_iBufferPos); 863 } 864 844 865 if (Message.value == CStr("size") || 845 866 Message.value == CStr("z") || 846 867 Message.value == CStr("font") || … … 1098 1119 default: 1099 1120 break; 1100 1121 } 1122 UpdateBufferPositionSetting(); 1101 1123 } 1102 1124 1103 1125 void CInput::UpdateCachedSize() … … 1552 1574 // Ensure positions are valid after caption changes 1553 1575 m_iBufferPos = std::min(m_iBufferPos, (int)caption.size()); 1554 1576 m_iBufferPos_Tail = std::min(m_iBufferPos_Tail, (int)caption.size()); 1577 UpdateBufferPositionSetting(); 1555 1578 1556 1579 if (font_name.empty()) 1557 1580 { … … 2053 2076 // Remove selection 2054 2077 m_iBufferPos_Tail = -1; 2055 2078 m_iBufferPos = virtualFrom; 2079 UpdateBufferPositionSetting(); 2056 2080 } 2057 2081 2058 2082 bool CInput::SelectingText() const -
source/gui/CInput.h
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 139 139 // Clear composed IME input when supported (SDL2 only). 140 140 void ClearComposedText(); 141 141 142 void UpdateBufferPositionSetting(); 142 143 protected: 143 144 // Cursor position 144 145 // (the second one is for selection of larger areas, -1 if not used)