Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/lobby/LobbyPage/PlayerList.js
- This file was added.
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
class PlayerList | |||||
{ | |||||
constructor(xmppMessages, buddyButton, gameList) | |||||
{ | |||||
this.gameList = gameList; | |||||
this.selectedPlayer = undefined; | |||||
this.selectionChangeHandlers = new Set(); | |||||
this.mouseLeftDoubleClickItemHandlers = new Set(); | |||||
this.playersBox = Engine.GetGUIObjectByName("playersBox"); | |||||
this.playersBox.onSelectionChange = this.onPlayerListSelection.bind(this); | |||||
this.playersBox.onSelectionColumnChange = this.rebuildPlayerList.bind(this); | |||||
this.playersBox.onMouseLeftClickItem = this.onMouseLeftClickItem.bind(this); | |||||
Freagarach: +`.` | |||||
this.playersBox.onMouseLeftDoubleClickItem = this.onMouseLeftDoubleClickItem.bind(this); | |||||
buddyButton.registerBuddyChangeHandler(this.onBuddyChange.bind(this)); | |||||
this.registerSelectionChangeHandler(buddyButton.onPlayerSelectionChange.bind(buddyButton)); | |||||
this.registerMouseLeftDoubleClickItemHandler(buddyButton.onPress.bind(buddyButton)); | |||||
xmppMessages.registerMessageBatchProcessedHandler(this.onMessageBatchProcessed.bind(this)); | |||||
this.rebuildPlayerList(); | |||||
} | |||||
registerSelectionChangeHandler(handler) | |||||
{ | |||||
this.selectionChangeHandlers.add(handler); | |||||
} | |||||
registerMouseLeftDoubleClickItemHandler(handler) | |||||
{ | |||||
this.mouseLeftDoubleClickItemHandlers.add(handler); | |||||
} | |||||
onBuddyChange() | |||||
{ | |||||
this.rebuildPlayerList(); | |||||
} | |||||
onMessageBatchProcessed() | |||||
{ | |||||
if (Engine.LobbyGuiPollHasPlayerListUpdate()) | |||||
this.rebuildPlayerList(); | |||||
} | |||||
onMouseLeftDoubleClickItem() | |||||
{ | |||||
for (let handler of this.mouseLeftDoubleClickItemHandlers) | |||||
handler(); | |||||
} | |||||
onMouseLeftClickItem() | |||||
{ | |||||
// In case of clicking on the same player again | |||||
this.gameList.selectGameFromPlayername(this.selectedPlayer); | |||||
} | |||||
onPlayerListSelection() | |||||
{ | |||||
if (this.playersBox.selected == this.playersBox.list.indexOf(this.selectedPlayer)) | |||||
return; | |||||
this.selectedPlayer = this.playersBox.list[this.playersBox.selected]; | |||||
this.gameList.selectGameFromPlayername(this.selectedPlayer); | |||||
Not Done Inline Actions+. Freagarach: +`.` | |||||
for (let handler of this.selectionChangeHandlers) | |||||
handler(this.selectedPlayer); | |||||
} | |||||
getPlayer(player) | |||||
{ | |||||
player.isBuddy = g_Buddies.indexOf(player.name) != -1; | |||||
return player; | |||||
} | |||||
/** | |||||
* Do a full update of the player listing, including ratings from cached C++ information. | |||||
* Important: This should only be performed once if | |||||
* there have been multiple messages received changing this list. | |||||
*/ | |||||
rebuildPlayerList() | |||||
{ | |||||
let buddyStatusList = []; | |||||
let playerList = []; | |||||
let presenceList = []; | |||||
let nickList = []; | |||||
let ratingList = []; | |||||
let cleanPlayerList = Engine.GetPlayerList().map( | |||||
this.getPlayer.bind(this)).sort( | |||||
this.sortPlayers.bind(this)); | |||||
// Colorize list entries | |||||
for (let player of cleanPlayerList) | |||||
{ | |||||
if (player.rating && player.name == g_Username) | |||||
g_UserRating = player.rating; | |||||
// TODO: Set horizontal align in the COlist column | |||||
// CGUIText constructor should receive the EAlign as an argument and | |||||
// perhaps COList columns should be objects | |||||
let rating = player.rating ? (" " + player.rating).substr(-5) : " -"; | |||||
let presence = this.PlayerStatuses[player.presence] ? player.presence : "unknown"; | |||||
if (presence == "unknown") | |||||
warn("Unknown presence:" + player.presence); | |||||
let statusTags = this.PlayerStatuses[presence].tags; | |||||
buddyStatusList.push(player.isBuddy ? setStringTags(g_BuddySymbol, statusTags) : ""); | |||||
playerList.push(PlayerColor.ColorPlayerName( | |||||
(player.role == "moderator" ? g_ModeratorPrefix : "") + player.name)); | |||||
presenceList.push(setStringTags(this.PlayerStatuses[presence].status, statusTags)); | |||||
ratingList.push(setStringTags(rating, statusTags)); | |||||
nickList.push(player.name); | |||||
} | |||||
this.playersBox.list_buddy = buddyStatusList; | |||||
this.playersBox.list_name = playerList; | |||||
this.playersBox.list_status = presenceList; | |||||
this.playersBox.list_rating = ratingList; | |||||
this.playersBox.list = nickList; | |||||
this.playersBox.selected = this.playersBox.list.indexOf(this.selectedPlayer); | |||||
} | |||||
sortPlayers(a, b) | |||||
{ | |||||
let sortA, sortB; | |||||
let statusOrder = Object.keys(this.PlayerStatuses); | |||||
let statusA = statusOrder.indexOf(a.presence) + a.name.toLowerCase(); | |||||
let statusB = statusOrder.indexOf(b.presence) + b.name.toLowerCase(); | |||||
switch (this.playersBox.selected_column) | |||||
{ | |||||
case 'buddy': | |||||
sortA = (a.isBuddy ? 1 : 2) + statusA; | |||||
sortB = (b.isBuddy ? 1 : 2) + statusB; | |||||
break; | |||||
case 'rating': | |||||
sortA = +a.rating; | |||||
sortB = +b.rating; | |||||
break; | |||||
case 'status': | |||||
sortA = statusA; | |||||
sortB = statusB; | |||||
break; | |||||
case 'name': | |||||
default: | |||||
sortA = a.name.toLowerCase(); | |||||
sortB = b.name.toLowerCase(); | |||||
break; | |||||
} | |||||
let sortOrder = this.playersBox.selected_column_order; | |||||
if (sortA < sortB) | |||||
return -sortOrder; | |||||
if (sortA > sortB) | |||||
return +sortOrder; | |||||
return 0; | |||||
} | |||||
} | |||||
/** | |||||
* The playerlist will be assembled using these values. | |||||
*/ | |||||
PlayerList.prototype.PlayerStatuses = { | |||||
"available": { | |||||
"tags": { "color": "0 219 0" }, | |||||
"status": translate("Online") | |||||
}, | |||||
"away": { | |||||
"tags": { "color": "229 76 13" }, | |||||
"status": translate("Away") | |||||
}, | |||||
"playing": { | |||||
"tags": { "color": "200 0 0" }, | |||||
"status": translate("Busy") | |||||
}, | |||||
"offline": { | |||||
"tags": { "color": "0 0 0" }, | |||||
"status": translate("Offline") | |||||
}, | |||||
"unknown": { | |||||
"tags": { "color": "178 178 178" }, | |||||
"status": translateWithContext("lobby presence", "Unknown") | |||||
} | |||||
}; |
Wildfire Games · Phabricator
+.