Differential D4262 Diff 19275 ps/trunk/binaries/data/mods/public/gui/lobby/ProfilePage/ProfilePage.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/lobby/ProfilePage/ProfilePage.js
/** | /** | ||||
* The profile page enables the player to lookup statistics of an arbitrary player. | * The profile page enables the player to lookup statistics of an arbitrary player. | ||||
*/ | */ | ||||
class ProfilePage | class ProfilePage | ||||
{ | { | ||||
constructor(xmppMessages) | constructor(xmppMessages) | ||||
{ | { | ||||
this.requestedPlayer = undefined; | this.requestedPlayer = undefined; | ||||
this.closePageHandlers = new Set(); | this.closePageHandlers = new Set(); | ||||
this.profilePage = Engine.GetGUIObjectByName("profilePage"); | this.profilePage = Engine.GetGUIObjectByName("profilePage"); | ||||
this.fetchInput = Engine.GetGUIObjectByName("fetchInput"); | this.fetchInput = Engine.GetGUIObjectByName("fetchInput"); | ||||
this.fetchInput.onPress = this.onPressLookup.bind(this); | this.fetchInput.onPress = this.onPressLookup.bind(this); | ||||
this.fetchInput.onTab = this.autocomplete.bind(this); | |||||
this.fetchInput.tooltip = colorizeAutocompleteHotkey(); | |||||
Engine.GetGUIObjectByName("viewProfileButton").onPress = this.onPressLookup.bind(this); | Engine.GetGUIObjectByName("viewProfileButton").onPress = this.onPressLookup.bind(this); | ||||
Engine.GetGUIObjectByName("profileBackButton").onPress = this.onPressClose.bind(this, true); | Engine.GetGUIObjectByName("profileBackButton").onPress = this.onPressClose.bind(this, true); | ||||
this.profilePlayernameText = Engine.GetGUIObjectByName("profilePlayernameText"); | this.profilePlayernameText = Engine.GetGUIObjectByName("profilePlayernameText"); | ||||
this.profileRankText = Engine.GetGUIObjectByName("profileRankText"); | this.profileRankText = Engine.GetGUIObjectByName("profileRankText"); | ||||
this.profileHighestRatingText = Engine.GetGUIObjectByName("profileHighestRatingText"); | this.profileHighestRatingText = Engine.GetGUIObjectByName("profileHighestRatingText"); | ||||
this.profileTotalGamesText = Engine.GetGUIObjectByName("profileTotalGamesText"); | this.profileTotalGamesText = Engine.GetGUIObjectByName("profileTotalGamesText"); | ||||
Show All 18 Lines | class ProfilePage | ||||
} | } | ||||
onPressLookup() | onPressLookup() | ||||
{ | { | ||||
this.requestedPlayer = this.fetchInput.caption; | this.requestedPlayer = this.fetchInput.caption; | ||||
Engine.SendGetProfile(this.requestedPlayer); | Engine.SendGetProfile(this.requestedPlayer); | ||||
} | } | ||||
autocomplete() | |||||
{ | |||||
const listPlayerNames = Engine.GetPlayerList().map(player => escapeText(player.name)); | |||||
// Remove duplicates with the board list. The board list has lower case names. | |||||
const listPlayerNamesLower = listPlayerNames.map(playerName => playerName.toLowerCase()); | |||||
for (const entry of Engine.GetBoardList()) | |||||
{ | |||||
const escapedName = escapeText(entry.name); | |||||
if (!listPlayerNamesLower.includes(escapedName)) | |||||
listPlayerNames.push(escapedName); | |||||
} | |||||
autoCompleteText(this.fetchInput, listPlayerNames); | |||||
} | |||||
onPressClose() | onPressClose() | ||||
{ | { | ||||
this.profilePage.hidden = true; | this.profilePage.hidden = true; | ||||
for (let handler of this.closePageHandlers) | for (let handler of this.closePageHandlers) | ||||
handler(); | handler(); | ||||
} | } | ||||
Show All 11 Lines | onProfile() | ||||
{ | { | ||||
this.profileErrorText.caption = | this.profileErrorText.caption = | ||||
sprintf(translate("Player \"%(nick)s\" not found."), { | sprintf(translate("Player \"%(nick)s\" not found."), { | ||||
"nick": escapeText(attributes.player) | "nick": escapeText(attributes.player) | ||||
}); | }); | ||||
return; | return; | ||||
} | } | ||||
this.profilePlayernameText.caption = escapeText(attributes.player); | this.profilePlayernameText.caption = PlayerColor.ColorPlayerName(escapeText(attributes.player), attributes.rating); | ||||
this.profileRankText.caption = attributes.rank; | this.profileRankText.caption = attributes.rank; | ||||
this.profileHighestRatingText.caption = attributes.highestRating; | this.profileHighestRatingText.caption = attributes.highestRating; | ||||
this.profileTotalGamesText.caption = attributes.totalGamesPlayed; | this.profileTotalGamesText.caption = attributes.totalGamesPlayed; | ||||
this.profileWinsText.caption = attributes.wins; | this.profileWinsText.caption = attributes.wins; | ||||
this.profileLossesText.caption = attributes.losses; | this.profileLossesText.caption = attributes.losses; | ||||
this.profileRatioText.caption = ProfilePanel.FormatWinRate(attributes); | this.profileRatioText.caption = ProfilePanel.FormatWinRate(attributes); | ||||
} | } | ||||
} | } |
Wildfire Games · Phabricator