Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/lobby/lobby.js
Show First 20 Lines • Show All 330 Lines • ▼ Show 20 Lines | "quit": { | ||||
"handler": args => { | "handler": args => { | ||||
returnToMainMenu(); | returnToMainMenu(); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* Informations about players presences and messages | |||||
*/ | |||||
let g_Players = {}; | |||||
/** | |||||
* Called after the XmppConnection succeeded and when returning from a game. | * Called after the XmppConnection succeeded and when returning from a game. | ||||
* | * | ||||
* @param {Object} attribs | * @param {Object} attribs | ||||
*/ | */ | ||||
function init(attribs) | function init(attribs) | ||||
{ | { | ||||
if (!g_Settings) | if (!g_Settings) | ||||
{ | { | ||||
Show All 11 Lines | function init(attribs) | ||||
// When rejoining the lobby after a game, we don't need to process presence changes | // When rejoining the lobby after a game, we don't need to process presence changes | ||||
Engine.LobbyClearPresenceUpdates(); | Engine.LobbyClearPresenceUpdates(); | ||||
updatePlayerList(); | updatePlayerList(); | ||||
updateSubject(Engine.LobbyGetRoomSubject()); | updateSubject(Engine.LobbyGetRoomSubject()); | ||||
updateLobbyColumns(); | updateLobbyColumns(); | ||||
updateToggleBuddy(); | updateToggleBuddy(); | ||||
Engine.GetGUIObjectByName("chatInput").tooltip = colorizeAutocompleteHotkey(); | Engine.GetGUIObjectByName("chatInput").tooltip = colorizeAutocompleteHotkey(); | ||||
// test pings put your username in | |||||
addChatMessage({ | |||||
"from": escapeText("your username"), | |||||
"text": escapeText("PING"), | |||||
"time": 0 | |||||
}); | |||||
addChatMessage({ | |||||
"from": escapeText("your username"), | |||||
"text": escapeText("PING2"), | |||||
"time": 0 | |||||
}); | |||||
addChatMessage({ | |||||
"from": escapeText("your username"), | |||||
"text": escapeText("PING3"), | |||||
"time": 0 | |||||
}); | |||||
// after try go lobby type /away and /back to see switching | |||||
} | } | ||||
function updateLobbyColumns() | function updateLobbyColumns() | ||||
{ | { | ||||
let gameRating = Engine.ConfigDB_GetValue("user", "lobby.columns.gamerating") == "true"; | let gameRating = Engine.ConfigDB_GetValue("user", "lobby.columns.gamerating") == "true"; | ||||
// Only show the selected columns | // Only show the selected columns | ||||
let gamesBox = Engine.GetGUIObjectByName("gamesBox"); | let gamesBox = Engine.GetGUIObjectByName("gamesBox"); | ||||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | default: | ||||
sortB = b.name.toLowerCase(); | sortB = b.name.toLowerCase(); | ||||
break; | break; | ||||
} | } | ||||
if (sortA < sortB) return -sortOrder; | if (sortA < sortB) return -sortOrder; | ||||
if (sortA > sortB) return +sortOrder; | if (sortA > sortB) return +sortOrder; | ||||
return 0; | return 0; | ||||
}); | }); | ||||
let presencesUpdated = false; | |||||
// Colorize list entries | // Colorize list entries | ||||
for (let player of cleanPlayerList) | for (let player of cleanPlayerList) | ||||
{ | { | ||||
if (player.rating && player.name == g_Username) | if (player.rating && player.name == g_Username) | ||||
g_UserRating = player.rating; | g_UserRating = player.rating; | ||||
let rating = player.rating ? (" " + player.rating).substr(-5) : " -"; | let rating = player.rating ? (" " + player.rating).substr(-5) : " -"; | ||||
let presence = g_PlayerStatuses[player.presence] ? player.presence : "unknown"; | let presence = g_PlayerStatuses[player.presence] ? player.presence : "unknown"; | ||||
if (presence == "unknown") | if (presence == "unknown") | ||||
warn("Unknown presence:" + player.presence); | warn("Unknown presence:" + player.presence); | ||||
if (updatePlayerPresence(player.name, player.presence)) | |||||
presencesUpdated = true; | |||||
let statusColor = g_PlayerStatuses[presence].color; | let statusColor = g_PlayerStatuses[presence].color; | ||||
let coloredName = colorPlayerName((player.role == "moderator" ? g_ModeratorPrefix : "") + player.name); | let coloredName = colorPlayerName((player.role == "moderator" ? g_ModeratorPrefix : "") + player.name); | ||||
let coloredPresence = '[color="' + statusColor + '"]' + g_PlayerStatuses[presence].status + "[/color]"; | let coloredPresence = '[color="' + statusColor + '"]' + g_PlayerStatuses[presence].status + "[/color]"; | ||||
let coloredRating = '[color="' + statusColor + '"]' + rating + "[/color]"; | let coloredRating = '[color="' + statusColor + '"]' + rating + "[/color]"; | ||||
buddyStatusList.push(player.isBuddy ? '[color="' + statusColor + '"]' + g_BuddySymbol + '[/color]' : ""); | buddyStatusList.push(player.isBuddy ? '[color="' + statusColor + '"]' + g_BuddySymbol + '[/color]' : ""); | ||||
playerList.push(coloredName); | playerList.push(coloredName); | ||||
presenceList.push(coloredPresence); | presenceList.push(coloredPresence); | ||||
ratingList.push(coloredRating); | ratingList.push(coloredRating); | ||||
nickList.push(player.name); | nickList.push(player.name); | ||||
} | } | ||||
playersBox.list_buddy = buddyStatusList; | playersBox.list_buddy = buddyStatusList; | ||||
playersBox.list_name = playerList; | playersBox.list_name = playerList; | ||||
playersBox.list_status = presenceList; | playersBox.list_status = presenceList; | ||||
playersBox.list_rating = ratingList; | playersBox.list_rating = ratingList; | ||||
playersBox.list = nickList; | playersBox.list = nickList; | ||||
playersBox.selected = playersBox.list.indexOf(g_SelectedPlayer); | playersBox.selected = playersBox.list.indexOf(g_SelectedPlayer); | ||||
if (presencesUpdated) | |||||
updateChat(); | |||||
} | |||||
/* | |||||
* Update player's presence in g_Players | |||||
* return: | |||||
* true - presence changed | |||||
* false - presence up-to-date | |||||
*/ | |||||
function updatePlayerPresence(name, presence) | |||||
{ | |||||
if (!g_Players[name]) | |||||
g_Players[name] = { "presence": presence }; | |||||
else | |||||
if (g_Players[name].presence != presence) | |||||
{ | |||||
g_Players[name].presence = presence; | |||||
if (g_Players[name].messages) | |||||
for (let msg of g_Players[name].messages) | |||||
ircFormat(msg); | |||||
} | |||||
else | |||||
return false; | |||||
return true; | |||||
} | } | ||||
/** | /** | ||||
* Toggle buddy state for a player in playerlist within the user config | * Toggle buddy state for a player in playerlist within the user config | ||||
*/ | */ | ||||
function toggleBuddy() | function toggleBuddy() | ||||
{ | { | ||||
let playerList = Engine.GetGUIObjectByName("playersBox"); | let playerList = Engine.GetGUIObjectByName("playersBox"); | ||||
▲ Show 20 Lines • Show All 575 Lines • ▼ Show 20 Lines | |||||
* Process and if appropriate, display a formatted message. | * Process and if appropriate, display a formatted message. | ||||
* | * | ||||
* @param {Object} msg - The message to be processed. | * @param {Object} msg - The message to be processed. | ||||
*/ | */ | ||||
function addChatMessage(msg) | function addChatMessage(msg) | ||||
{ | { | ||||
if (msg.from) | if (msg.from) | ||||
{ | { | ||||
if (Engine.LobbyGetPlayerRole(msg.from) == "moderator") | |||||
msg.from = g_ModeratorPrefix + msg.from; | |||||
// Highlight local user's nick | // Highlight local user's nick | ||||
if (g_Username != msg.from) | if (g_Username != msg.from) | ||||
{ | { | ||||
msg.text = msg.text.replace(g_Username, colorPlayerName(g_Username)); | msg.text = msg.text.replace(g_Username, colorPlayerName(g_Username)); | ||||
notifyUser(g_Username, msg.text); | notifyUser(g_Username, msg.text); | ||||
} | } | ||||
if (!g_Players[msg.from] || g_Players[msg.from]["presence"] == undefined) | |||||
g_Players[msg.from] = { "presence": "unknown" }; | |||||
if (g_Players[msg.from].messages == undefined) | |||||
g_Players[msg.from].messages = []; | |||||
} | } | ||||
let formatted = ircFormat(msg); | ircFormat(msg); | ||||
if (!formatted) | if (!msg.formatted) | ||||
return; | return; | ||||
g_ChatMessages.push(formatted); | if (msg.from) | ||||
g_Players[msg.from].messages.push(msg); | |||||
g_ChatMessages.push(msg); | |||||
updateChat(); | |||||
} | |||||
function updateChat() | |||||
{ | |||||
Engine.GetGUIObjectByName("chatText").caption = g_ChatMessages.join("\n"); | Engine.GetGUIObjectByName("chatText").caption = g_ChatMessages.join("\n"); | ||||
} | } | ||||
/** | /** | ||||
* Splits given input into command and argument. | * Splits given input into command and argument. | ||||
*/ | */ | ||||
function ircSplit(string) | function ircSplit(string) | ||||
{ | { | ||||
Show All 11 Lines | |||||
* @param {Object} msg - Received chat message. | * @param {Object} msg - Received chat message. | ||||
* @returns {string} - Formatted text. | * @returns {string} - Formatted text. | ||||
*/ | */ | ||||
function ircFormat(msg) | function ircFormat(msg) | ||||
{ | { | ||||
let formattedMessage = ""; | let formattedMessage = ""; | ||||
let coloredFrom = msg.from && colorPlayerName(msg.from); | let coloredFrom = msg.from && colorPlayerName(msg.from); | ||||
if (msg.from) | |||||
{ | |||||
coloredFrom = '[color="' + g_PlayerStatuses[g_Players[msg.from].presence].color + | |||||
'"] ' + g_BuddySymbol + ' [/color]' + | |||||
colorPlayerName((Engine.LobbyGetPlayerRole(msg.from) == "moderator" ? g_ModeratorPrefix : "") | |||||
+ msg.from); | |||||
} | |||||
// Handle commands allowed past handleChatCommand. | // Handle commands allowed past handleChatCommand. | ||||
if (msg.text[0] == '/') | if (msg.text[0] == '/') | ||||
{ | { | ||||
let [command, message] = ircSplit(msg.text); | let [command, message] = ircSplit(msg.text); | ||||
switch (command) | switch (command) | ||||
{ | { | ||||
case "me": | case "me": | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | else | ||||
// Translation: IRC message. | // Translation: IRC message. | ||||
formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | ||||
"sender": senderFont(senderString), | "sender": senderFont(senderString), | ||||
"message": msg.text | "message": msg.text | ||||
}); | }); | ||||
} | } | ||||
msg.formatted = formattedMessage; | |||||
msg.toString = () => { return msg.formatted; }; | |||||
// Add chat message timestamp | // Add chat message timestamp | ||||
if (Engine.ConfigDB_GetValue("user", "chat.timestamp") != "true") | if (Engine.ConfigDB_GetValue("user", "chat.timestamp") != "true") | ||||
return formattedMessage; | return; | ||||
// Translation: Time as shown in the multiplayer lobby (when you enable it in the options page). | // Translation: Time as shown in the multiplayer lobby (when you enable it in the options page). | ||||
// For a list of symbols that you can use, see: | // For a list of symbols that you can use, see: | ||||
// https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table | // https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table | ||||
let timeString = Engine.FormatMillisecondsIntoDateStringLocal(msg.time ? msg.time * 1000 : Date.now(), translate("HH:mm")); | let timeString = Engine.FormatMillisecondsIntoDateStringLocal(msg.time ? msg.time * 1000 : Date.now(), translate("HH:mm")); | ||||
// Translation: Time prefix as shown in the multiplayer lobby (when you enable it in the options page). | // Translation: Time prefix as shown in the multiplayer lobby (when you enable it in the options page). | ||||
let timePrefixString = sprintf(translate("\\[%(time)s]"), { | let timePrefixString = sprintf(translate("\\[%(time)s]"), { | ||||
"time": timeString | "time": timeString | ||||
}); | }); | ||||
// Translation: IRC message format when there is a time prefix. | // Translation: IRC message format when there is a time prefix. | ||||
return sprintf(translate("%(time)s %(message)s"), { | msg.formatted = sprintf(translate("%(time)s %(message)s"), { | ||||
"time": senderFont(timePrefixString), | "time": senderFont(timePrefixString), | ||||
"message": formattedMessage | "message": formattedMessage | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Generate a (mostly) unique color for this player based on their name. | * Generate a (mostly) unique color for this player based on their name. | ||||
* @see http://stackoverflow.com/questions/3426404/create-a-hexadecimal-colour-based-on-a-string-with-jquery-javascript | * @see http://stackoverflow.com/questions/3426404/create-a-hexadecimal-colour-based-on-a-string-with-jquery-javascript | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator