Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/common/functions_utility.js
/** | /** | ||||
* Used for acoustic GUI notifications. | * Used for acoustic GUI notifications. | ||||
* Define the soundfile paths and specific time thresholds (avoid spam). | * Define the soundfile paths and specific time thresholds (avoid spam). | ||||
* And store the timestamp of last interaction for each notification. | * And store the timestamp of last interaction for each notification. | ||||
*/ | */ | ||||
var g_SoundNotifications = { | var g_SoundNotifications = { | ||||
"nick": { "soundfile": "audio/interface/ui/chat_alert.ogg", "threshold": 3000 } | "nick": { "soundfile": "audio/interface/ui/chat_alert.ogg", "threshold": 3000 } | ||||
}; | }; | ||||
/** | /** | ||||
* Used to track previous texts from autocompletion to try next autocompletion if multiples apply. | |||||
*/ | |||||
var g_LastAutoComplete = { | |||||
vladislavbelov: Ins't it better to combine all this variables in a one object? Like:
```lang=javascript
var… | |||||
Done Inline Actionsn1. ffffffff: n1. | |||||
"bufferPosition": 0, | |||||
"text": "", | |||||
"tries": 0, | |||||
"newText": "" | |||||
}; | |||||
ImarokUnsubmitted Not Done Inline ActionsWould be nice to add a more extensive comment, that explains all those variables. Imarok: Would be nice to add a more extensive comment, that explains all those variables.
| |||||
/** | |||||
* Returns translated history and gameplay data of all civs, optionally including a mock gaia civ. | * Returns translated history and gameplay data of all civs, optionally including a mock gaia civ. | ||||
*/ | */ | ||||
function loadCivData(selectableOnly, gaia) | function loadCivData(selectableOnly, gaia) | ||||
{ | { | ||||
let civData = loadCivFiles(selectableOnly); | let civData = loadCivFiles(selectableOnly); | ||||
translateObjectKeys(civData, ["Name", "Description", "History", "Special"]); | translateObjectKeys(civData, ["Name", "Description", "History", "Special"]); | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | function singleplayerName() | ||||
return Engine.ConfigDB_GetValue("user", "playername.singleplayer") || Engine.GetSystemUsername(); | return Engine.ConfigDB_GetValue("user", "playername.singleplayer") || Engine.GetSystemUsername(); | ||||
} | } | ||||
function multiplayerName() | function multiplayerName() | ||||
{ | { | ||||
return Engine.ConfigDB_GetValue("user", "playername.multiplayer") || Engine.GetSystemUsername(); | return Engine.ConfigDB_GetValue("user", "playername.multiplayer") || Engine.GetSystemUsername(); | ||||
} | } | ||||
function tryAutoComplete(text, autoCompleteList) | function tryAutoComplete(text, autoCompleteList, tries) | ||||
{ | { | ||||
if (!text.length) | if (!text.length) | ||||
return text; | return text; | ||||
var wordSplit = text.split(/\s/g); | var wordSplit = text.split(/\s/g); | ||||
if (!wordSplit.length) | if (!wordSplit.length) | ||||
return text; | return text; | ||||
var lastWord = wordSplit.pop(); | var lastWord = wordSplit.pop(); | ||||
if (!lastWord.length) | if (!lastWord.length) | ||||
return text; | return text; | ||||
let firstFound = ""; | |||||
for (var word of autoCompleteList) | for (var word of autoCompleteList) | ||||
{ | { | ||||
if (word.toLowerCase().indexOf(lastWord.toLowerCase()) != 0) | if (word.toLowerCase().indexOf(lastWord.toLowerCase()) != 0) | ||||
continue; | continue; | ||||
text = wordSplit.join(" "); | --tries; | ||||
if (text.length > 0) | if (!firstFound) | ||||
text += " "; | firstFound = word; | ||||
text += word; | if (tries < 0) | ||||
break; | break; | ||||
} | } | ||||
if (!firstFound) | |||||
return text; | return text; | ||||
// 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; | |||||
} | |||||
text = wordSplit.join(" "); | |||||
Done Inline ActionsIt could written like: if (!firstFound) vladislavbelov: It could written like:
```lang=javascript
if (!firstFound)
``` | |||||
Done Inline Actionsy i think js interprets value 0 as not? then it wont be matched here correctly if word has value 0 and firstFound also, no? ffffffff: y i think js interprets value 0 as not? then it wont be matched here correctly if word has… | |||||
Done Inline ActionsOk true works. Only strings parsed (playernames) though !firstFound works. tx! ffffffff: Ok true works. Only strings parsed (playernames) though !firstFound works. tx! | |||||
if (text.length > 0) | |||||
text += " "; | |||||
return text + word; | |||||
} | } | ||||
function autoCompleteNick(guiObject, playernames) | function autoCompleteNick(guiObject, playernames) | ||||
{ | { | ||||
let text = guiObject.caption; | let text = guiObject.caption; | ||||
if (!text.length) | if (!text.length) | ||||
return; | return; | ||||
let bufferPosition = guiObject.buffer_position; | let bufferPosition = guiObject.buffer_position; | ||||
let textTillBufferPosition = text.substring(0, bufferPosition); | let sameTry = g_LastAutoComplete.newText == text; | ||||
let newText = tryAutoComplete(textTillBufferPosition, playernames); | if (!sameTry) | ||||
{ | |||||
guiObject.caption = newText + text.substring(bufferPosition); | g_LastAutoComplete.bufferPosition = bufferPosition; | ||||
guiObject.buffer_position = bufferPosition + (newText.length - textTillBufferPosition.length); | 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 + (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() | function clearChatMessages() | ||||
{ | { | ||||
g_ChatMessages.length = 0; | g_ChatMessages.length = 0; | ||||
Engine.GetGUIObjectByName("chatText").caption = ""; | Engine.GetGUIObjectByName("chatText").caption = ""; | ||||
try { | try { | ||||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Ins't it better to combine all this variables in a one object? Like: