Index: binaries/data/mods/public/gui/common/functions_utility.js =================================================================== --- binaries/data/mods/public/gui/common/functions_utility.js +++ binaries/data/mods/public/gui/common/functions_utility.js @@ -8,6 +8,16 @@ }; /** + * Used to track previous texts from autocompletion to try next autocompletion if multiples apply. + */ +var g_LastAutoComplete = { + "bufferPosition": 0, + "text": "", + "tries": 0, + "newText": "" +}; + +/** * Returns translated history and gameplay data of all civs, optionally including a mock gaia civ. */ function loadCivData(selectableOnly, gaia) @@ -126,7 +136,7 @@ return Engine.ConfigDB_GetValue("user", "playername.multiplayer") || Engine.GetSystemUsername(); } -function tryAutoComplete(text, autoCompleteList) +function tryAutoComplete(text, autoCompleteList, tries) { if (!text.length) return text; @@ -139,19 +149,35 @@ if (!lastWord.length) return text; + let firstFound = ""; for (var word of autoCompleteList) { if (word.toLowerCase().indexOf(lastWord.toLowerCase()) != 0) continue; - text = wordSplit.join(" "); - if (text.length > 0) - text += " "; + --tries; + if (!firstFound) + firstFound = word; + + if (tries < 0) + break; + } + + if (!firstFound) + return text; - text += word; - break; + // Wrap search to start, cause tries could not complete to 0, means there are no more matches as tries in list. + if (tries >= 0) + { + g_LastAutoComplete.tries = 1; + word = firstFound; } - return text; + + text = wordSplit.join(" "); + if (text.length > 0) + text += " "; + + return text + word; } function autoCompleteNick(guiObject, playernames) @@ -161,11 +187,23 @@ return; let bufferPosition = guiObject.buffer_position; - let textTillBufferPosition = text.substring(0, bufferPosition); - let newText = tryAutoComplete(textTillBufferPosition, playernames); + let sameTry = g_LastAutoComplete.newText == text; + if (!sameTry) + { + g_LastAutoComplete.bufferPosition = bufferPosition; + g_LastAutoComplete.text = text; + g_LastAutoComplete.newText = ""; + g_LastAutoComplete.tries = 0; + } + + let textTillBufferPosition = sameTry ? g_LastAutoComplete.text.substring(0, g_LastAutoComplete.bufferPosition) : text.substring(0, bufferPosition); + let newText = tryAutoComplete(textTillBufferPosition, playernames, g_LastAutoComplete.tries++); - guiObject.caption = newText + text.substring(bufferPosition); - guiObject.buffer_position = bufferPosition + (newText.length - textTillBufferPosition.length); + guiObject.caption = newText + (sameTry ? g_LastAutoComplete.text.substring(g_LastAutoComplete.bufferPosition) : text.substring(bufferPosition)); + if (g_LastAutoComplete.newText == "" || sameTry) + g_LastAutoComplete.newText = guiObject.caption; + guiObject.buffer_position = (sameTry ? g_LastAutoComplete.bufferPosition : bufferPosition) + (newText.length - textTillBufferPosition.length); + return; } function clearChatMessages() Index: binaries/data/mods/public/gui/lobby/lobby.js =================================================================== --- binaries/data/mods/public/gui/lobby/lobby.js +++ binaries/data/mods/public/gui/lobby/lobby.js @@ -596,6 +596,8 @@ toggleBuddyButton.enabled = playerName && playerName != g_Username; } +var g_PlayerList = [{name:"fpre", presence:"available", rating:"1700", role:"participant", isBuddy:false}, {name:"nigel87", presence:"available", rating:"1560", role:"participant", isBuddy:true}, {name:"phoenixdesk", presence:"available", rating:"1229", role:"participant", isBuddy:true}, {name:"Achelao", presence:"playing", rating:"1547", role:"participant", isBuddy:true}, {name:"borg-", presence:"playing", rating:"2159", role:"participant", isBuddy:true}, {name:"chrstgtr", presence:"playing", rating:"1641", role:"participant", isBuddy:true}, {name:"elexis", presence:"playing", rating:"", role:"moderator", isBuddy:true}, {name:"iApprove", presence:"playing", rating:"1464", role:"participant", isBuddy:true}, {name:"LeGenDz", presence:"playing", rating:"1471", role:"participant", isBuddy:true}, {name:"Pretension", presence:"playing", rating:"", role:"participant", isBuddy:true}, {name:"user1", presence:"playing", rating:"", role:"moderator", isBuddy:true}, {name:"fsvn", presence:"available", rating:"1175", role:"participant", isBuddy:false}, {name:"GoodBay", presence:"available", rating:"1135", role:"participant", isBuddy:false}, {name:"MadMeatBallMan", presence:"available", rating:"", role:"participant", isBuddy:false}, {name:"Ratings", presence:"available", rating:"", role:"moderator", isBuddy:false}, {name:"roxanne", presence:"available", rating:"909", role:"participant", isBuddy:false}, {name:"WFGbot", presence:"available", rating:"", role:"moderator", isBuddy:false}, {name:"ahmedteling", presence:"playing", rating:"1030", role:"participant", isBuddy:false}, {name:"Andresfcb2003", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"Bolvar", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"CaptIsler", presence:"playing", rating:"1100", role:"participant", isBuddy:false}, {name:"cleuberjs", presence:"playing", rating:"1064", role:"participant", isBuddy:false}, {name:"Crowley", presence:"playing", rating:"1135", role:"participant", isBuddy:false}, {name:"Emilio2006", presence:"playing", rating:"1089", role:"participant", isBuddy:false}, {name:"Ferhat_C", presence:"playing", rating:"961", role:"participant", isBuddy:false}, {name:"gaetheboss", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"good", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"HirnWolf", presence:"playing", rating:"1311", role:"participant", isBuddy:false}, {name:"iceblendedmocha", presence:"playing", rating:"1253", role:"participant", isBuddy:false}, {name:"imperator3", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"josavatar", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"K4OS", presence:"playing", rating:"1353", role:"participant", isBuddy:false}, {name:"kazutoo", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"Kuchen", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"Lombave", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"lucasbr788", presence:"playing", rating:"1202", role:"participant", isBuddy:false}, {name:"marciofly1", presence:"playing", rating:"1185", role:"participant", isBuddy:false}, {name:"markeloff_1.6", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"MTT123", presence:"playing", rating:"1283", role:"participant", isBuddy:false}, {name:"OutLander1", presence:"playing", rating:"1265", role:"participant", isBuddy:false}, {name:"outlander384", presence:"playing", rating:"1226", role:"participant", isBuddy:false}, {name:"Outlaw_7", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"Pale.May", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"playsofty", presence:"playing", rating:"1109", role:"participant", isBuddy:false}, {name:"protolich", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"Quicksilver", presence:"playing", rating:"1277", role:"participant", isBuddy:false}, {name:"Ragnark-", presence:"playing", rating:"1222", role:"participant", isBuddy:false}, {name:"Resul-55", presence:"playing", rating:"1335", role:"participant", isBuddy:false}, {name:"silius117", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"softcase", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"thatazoreanguy", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"thered", presence:"playing", rating:"", role:"participant", isBuddy:false}]; + /** * Do a full update of the player listing, including ratings from cached C++ information. */ @@ -611,7 +613,7 @@ let nickList = []; let ratingList = []; - let cleanPlayerList = Engine.GetPlayerList().map(player => { + let cleanPlayerList = g_PlayerList.map(player => { player.isBuddy = g_Buddies.indexOf(player.name) != -1; return player; }).sort((a, b) => { Index: binaries/data/mods/public/gui/lobby/lobby_panels.xml =================================================================== --- binaries/data/mods/public/gui/lobby/lobby_panels.xml +++ binaries/data/mods/public/gui/lobby/lobby_panels.xml @@ -259,7 +259,7 @@ submitChatInput(); - autoCompleteNick(this, Engine.GetPlayerList().map(player => player.name)); + autoCompleteNick(this, g_PlayerList.map(player => player.name));