Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/lobby/lobby.js
Show First 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | "help": { | ||||
"description": translate("Show this help."), | "description": translate("Show this help."), | ||||
"handler": args => { | "handler": args => { | ||||
let isModerator = Engine.LobbyGetPlayerRole(g_Username) == "moderator"; | let isModerator = Engine.LobbyGetPlayerRole(g_Username) == "moderator"; | ||||
let text = translate("Chat commands:"); | let text = translate("Chat commands:"); | ||||
for (let command in g_ChatCommands) | for (let command in g_ChatCommands) | ||||
if (!g_ChatCommands[command].moderatorOnly || isModerator) | if (!g_ChatCommands[command].moderatorOnly || isModerator) | ||||
// Translation: Chat command help format | // Translation: Chat command help format | ||||
text += "\n" + sprintf(translate("%(command)s - %(description)s"), { | text += "\n" + sprintf(translate("%(command)s - %(description)s"), { | ||||
"command": '[color="' + g_ChatCommandColor + '"]' + command + '[/color]', | "command": coloredText(command, g_ChatCommandColor), | ||||
"description": g_ChatCommands[command].description | "description": g_ChatCommands[command].description | ||||
}); | }); | ||||
addChatMessage({ | addChatMessage({ | ||||
"from": "system", | "from": "system", | ||||
"text": text | "text": text | ||||
}); | }); | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 306 Lines • ▼ Show 20 Lines | 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); | ||||
let statusColor = g_PlayerStatuses[presence].color; | let statusColor = g_PlayerStatuses[presence].color; | ||||
let coloredName = colorPlayerName((player.role == "moderator" ? g_ModeratorPrefix : "") + player.name); | buddyStatusList.push(player.isBuddy ? coloredText(g_BuddySymbol, statusColor) : ""); | ||||
let coloredPresence = '[color="' + statusColor + '"]' + g_PlayerStatuses[presence].status + "[/color]"; | playerList.push(colorPlayerName((player.role == "moderator" ? g_ModeratorPrefix : "") + player.name)); | ||||
let coloredRating = '[color="' + statusColor + '"]' + rating + "[/color]"; | presenceList.push(coloredText(g_PlayerStatuses[presence].status, statusColor)); | ||||
ratingList.push(coloredText(rating, statusColor)); | |||||
buddyStatusList.push(player.isBuddy ? '[color="' + statusColor + '"]' + g_BuddySymbol + '[/color]' : ""); | |||||
playerList.push(coloredName); | |||||
presenceList.push(coloredPresence); | |||||
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; | ||||
▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Lines | function updateGameList() | ||||
{ | { | ||||
let game = g_GameList[i]; | let game = g_GameList[i]; | ||||
let gameName = escapeText(game.name); | let gameName = escapeText(game.name); | ||||
let mapTypeIdx = g_MapTypes.Name.indexOf(game.mapType); | let mapTypeIdx = g_MapTypes.Name.indexOf(game.mapType); | ||||
if (game.ip == g_SelectedGameIP && game.port == g_SelectedGamePort) | if (game.ip == g_SelectedGameIP && game.port == g_SelectedGamePort) | ||||
selectedGameIndex = +i; | selectedGameIndex = +i; | ||||
list_buddy.push(game.hasBuddies ? '[color="' + g_GameColors[game.state] + '"]' + g_BuddySymbol + '[/color]' : ""); | list_buddy.push(game.hasBuddies ? coloredText(g_BuddySymbol, g_GameColors[game.state]) : ""); | ||||
list_name.push('[color="' + g_GameColors[game.state] + '"]' + gameName); | list_name.push(coloredText(gameName, g_GameColors[game.state])); | ||||
list_mapName.push(translateMapTitle(game.niceMapName)); | list_mapName.push(translateMapTitle(game.niceMapName)); | ||||
list_mapSize.push(translateMapSize(game.mapSize)); | list_mapSize.push(translateMapSize(game.mapSize)); | ||||
list_mapType.push(g_MapTypes.Title[mapTypeIdx] || ""); | list_mapType.push(g_MapTypes.Title[mapTypeIdx] || ""); | ||||
list_nPlayers.push(game.nbp + "/" + game.maxnbp); | list_nPlayers.push(game.nbp + "/" + game.maxnbp); | ||||
list_gameRating.push(game.gameRating); | list_gameRating.push(game.gameRating); | ||||
list.push(gameName); | list.push(gameName); | ||||
list_data.push(i); | list_data.push(i); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | function handleChatCommand(text) | ||||
args = ircSplit("/" + args); | args = ircSplit("/" + args); | ||||
if (!g_ChatCommands[cmd]) | if (!g_ChatCommands[cmd]) | ||||
{ | { | ||||
addChatMessage({ | addChatMessage({ | ||||
"from": "system", | "from": "system", | ||||
"text": sprintf( | "text": sprintf( | ||||
translate("The command '%(cmd)s' is not supported."), { | translate("The command '%(cmd)s' is not supported."), { | ||||
"cmd": '[color="' + g_ChatCommandColor + '"]' + cmd + '[/color]' | "cmd": coloredText(cmd, g_ChatCommandColor) | ||||
}) | }) | ||||
}); | }); | ||||
return false; | return false; | ||||
} | } | ||||
if (g_ChatCommands[cmd].moderatorOnly && Engine.LobbyGetPlayerRole(g_Username) != "moderator") | if (g_ChatCommands[cmd].moderatorOnly && Engine.LobbyGetPlayerRole(g_Username) != "moderator") | ||||
{ | { | ||||
addChatMessage({ | addChatMessage({ | ||||
"from": "system", | "from": "system", | ||||
"text": sprintf( | "text": sprintf( | ||||
translate("The command '%(cmd)s' is restricted to moderators."), { | translate("The command '%(cmd)s' is restricted to moderators."), { | ||||
"cmd": '[color="' + g_ChatCommandColor + '"]' + cmd + '[/color]' | "cmd": coloredText(cmd, g_ChatCommandColor) | ||||
}) | }) | ||||
}); | }); | ||||
return false; | return false; | ||||
} | } | ||||
return g_ChatCommands[cmd].handler(args); | return g_ChatCommands[cmd].handler(args); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | function ircFormat(msg) | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
let senderString; | let senderString; | ||||
// Translation: IRC message prefix. | // Translation: IRC message prefix. | ||||
if (msg.private) | if (msg.private) | ||||
senderString = sprintf(translateWithContext("lobby private message", "(%(private)s) <%(sender)s>"), { | senderString = sprintf(translateWithContext("lobby private message", "(%(private)s) <%(sender)s>"), { | ||||
"private": '[color="' + g_PrivateMessageColor + '"]' + | "private": coloredText(translate("Private"), g_PrivateMessageColor), | ||||
translate("Private") + '[/color]', | |||||
"sender": coloredFrom | "sender": coloredFrom | ||||
}); | }); | ||||
else | else | ||||
senderString = sprintf(translate("<%(sender)s>"), { | senderString = sprintf(translate("<%(sender)s>"), { | ||||
"sender": coloredFrom | "sender": coloredFrom | ||||
}); | }); | ||||
// Translation: IRC message. | // Translation: IRC message. | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Returns the given playername wrapped in an appropriate color-tag. | * Returns the given playername wrapped in an appropriate color-tag. | ||||
* | * | ||||
* @param {string} playername | * @param {string} playername | ||||
* @param {string} rating | * @param {string} rating | ||||
*/ | */ | ||||
function colorPlayerName(playername, rating) | function colorPlayerName(playername, rating) | ||||
{ | { | ||||
return '[color="' + getPlayerColor(playername.replace(g_ModeratorPrefix, "")) + '"]' + | return coloredText( | ||||
(rating ? sprintf( | (rating ? sprintf( | ||||
translate("%(nick)s (%(rating)s)"), { | translate("%(nick)s (%(rating)s)"), { | ||||
"nick": playername, | "nick": playername, | ||||
"rating": rating | "rating": rating | ||||
}) : playername | }) : playername | ||||
) + '[/color]'; | ), | ||||
getPlayerColor(playername.replace(g_ModeratorPrefix, ""))); | |||||
} | } | ||||
function senderFont(text) | function senderFont(text) | ||||
{ | { | ||||
return '[font="' + g_SenderFont + '"]' + text + "[/font]"; | return '[font="' + g_SenderFont + '"]' + text + "[/font]"; | ||||
} | } | ||||
function formatWinRate(attr) | function formatWinRate(attr) | ||||
{ | { | ||||
if (!attr.totalGamesPlayed) | if (!attr.totalGamesPlayed) | ||||
return translateWithContext("Used for an undefined winning rate", "-"); | return translateWithContext("Used for an undefined winning rate", "-"); | ||||
return sprintf(translate("%(percentage)s%%"), { | return sprintf(translate("%(percentage)s%%"), { | ||||
"percentage": (attr.wins / attr.totalGamesPlayed * 100).toFixed(2) | "percentage": (attr.wins / attr.totalGamesPlayed * 100).toFixed(2) | ||||
}); | }); | ||||
} | } |
Wildfire Games · Phabricator