Improve spectator scoreboard panels

Players will now always be inserted above spectators (ie. spectators
will always appear last), making it easier to see who is actually
playing.
This commit is contained in:
Gavin Lambert 2013-06-12 22:04:33 +12:00
parent 4ac0de4ff6
commit 81268d9e1d
1 changed files with 23 additions and 5 deletions

View File

@ -57,6 +57,14 @@ cah.Game = function(id) {
this.scoreboardElement_ = $("#scoreboard_template").clone()[0]; this.scoreboardElement_ = $("#scoreboard_template").clone()[0];
this.scoreboardElement_.id = "scoreboard_" + id; this.scoreboardElement_.id = "scoreboard_" + id;
$(this.scoreboardElement_).removeClass("hide"); $(this.scoreboardElement_).removeClass("hide");
/**
* The first spectator element within the scoreboard.
*
* @type {HTMLDivElement}
* @private
*/
this.firstSpectatorElement_ = null;
/** /**
* The element for the chat room for this game * The element for the chat room for this game
@ -786,7 +794,11 @@ cah.Game.prototype.updateUserStatus = function(playerInfo) {
if (!panel) { if (!panel) {
// new score panel // new score panel
panel = new cah.GameScorePanel(playerName); panel = new cah.GameScorePanel(playerName);
$(this.scoreboardElement_).append(panel.getElement()); if (this.firstSpectatorElement_) {
$(this.firstSpectatorElement_).before(panel.getElement());
} else {
$(this.scoreboardElement_).append(panel.getElement());
}
this.scoreCards_[playerName] = panel; this.scoreCards_[playerName] = panel;
} }
var oldStatus = panel.getStatus(); var oldStatus = panel.getStatus();
@ -858,6 +870,9 @@ cah.Game.prototype.updateSpectator = function(spectator) {
panel = new cah.GameScorePanel(spectator); panel = new cah.GameScorePanel(spectator);
$(this.scoreboardElement_).append(panel.getElement()); $(this.scoreboardElement_).append(panel.getElement());
this.scoreCards_[spectator] = panel; this.scoreCards_[spectator] = panel;
if (!this.firstSpectatorElement_) {
this.firstSpectatorElement_ = panel.getElement();
}
} }
panel.update(-1, cah.$.GamePlayerStatus.SPECTATOR); panel.update(-1, cah.$.GamePlayerStatus.SPECTATOR);
@ -1198,6 +1213,9 @@ cah.Game.prototype.spectatorLeave = function(spectator) {
} }
var scorecard = this.scoreCards_[spectator]; var scorecard = this.scoreCards_[spectator];
if (scorecard) { if (scorecard) {
if (this.firstSpectatorElement_ == scorecard.getElement()) {
this.firstSpectatorElement_ = this.firstSpectatorElement_.nextSibling;
}
$(scorecard.getElement()).remove(); $(scorecard.getElement()).remove();
} }
delete this.scoreCards_[spectator]; delete this.scoreCards_[spectator];
@ -1407,10 +1425,10 @@ cah.GameScorePanel.prototype.update = function(score, status) {
+ cah.$.GamePlayerStatus_msg[status]); + cah.$.GamePlayerStatus_msg[status]);
} else { } else {
$(".scorecard_points", this.element_).removeClass("hide"); $(".scorecard_points", this.element_).removeClass("hide");
$(this.element_).attr( $(this.element_).attr(
"aria-label", "aria-label",
this.player_ + " has " + score + " Awesome Point" + (score == 1 ? "" : "s") + ". " this.player_ + " has " + score + " Awesome Point" + (score == 1 ? "" : "s") + ". "
+ cah.$.GamePlayerStatus_msg[status]); + cah.$.GamePlayerStatus_msg[status]);
} }
}; };