From a679a7a36cb2d342d44d6649365c7141e9a965ee Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Thu, 15 Mar 2012 13:50:42 -0700 Subject: [PATCH] - confirm leaving game - initial game options. it never displays it right now since it isn't done --- WebContent/cah.css | 2 +- WebContent/game.jsp | 43 ++++++++++++++++++++- WebContent/js/cah.game.js | 79 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 120 insertions(+), 4 deletions(-) diff --git a/WebContent/cah.css b/WebContent/cah.css index 9ea70b3..5318771 100644 --- a/WebContent/cah.css +++ b/WebContent/cah.css @@ -346,7 +346,7 @@ span.debug { padding-top: 10px; } -.game_right_side { +.game_right_side, .game_options { position: absolute; left: 246px; width: 700px; diff --git a/WebContent/game.jsp b/WebContent/game.jsp index 087989d..9a49550 100644 --- a/WebContent/game.jsp +++ b/WebContent/game.jsp @@ -197,7 +197,9 @@ HttpSession hSession = request.getSession(true); -
+
+
+
The white cards played this round are:
@@ -253,5 +255,44 @@ HttpSession hSession = request.getSession(true);
+ +
+
+ Only the game host can change options. +

+ Game options: +
+ + +
+ + +
+ + +
+
+ diff --git a/WebContent/js/cah.game.js b/WebContent/js/cah.game.js index 7ad3711..fef74d9 100644 --- a/WebContent/js/cah.game.js +++ b/WebContent/js/cah.game.js @@ -58,6 +58,32 @@ cah.Game = function(id) { this.scoreboardElement_.id = "scoreboard_" + id; $(this.scoreboardElement_).removeClass("hide"); + /** + * The element for the game options for this game. + * + * @type {HTMLDivElement} + * @private + */ + this.optionsElement_ = $("#game_options_template").clone()[0]; + this.optionsElement_.id = "game_options_" + id; + $("#score_limit_template_label", this.optionsElement_).attr("for", "score_limit_" + id); + $("#player_limit_template_label", this.optionsElement_).attr("for", "player_limit_" + id); + $("#version_template_label", this.optionsElement_).attr("for", "version_" + id); + $("#score_limit_template", this.optionsElement_).attr("id", "score_limit_" + id); + $("#player_limit_template", this.optionsElement_).attr("id", "player_limit_" + id); + $("#version_template", this.optionsElement_).attr("id", "version_" + id); + $("label", this.optionsElement_).removeAttr("id"); + $(".game_options", this.element_).replaceWith(this.optionsElement_); + this.hideOptions_(); + + /** + * The nickname of the host of this game. + * + * @type {String} + * @private + */ + this.host_ = ""; + /** * User->value mapping of scorecards in the scoreboard. * @@ -591,15 +617,24 @@ cah.Game.prototype.insertIntoDocument = function() { * data Game data returned from server. */ cah.Game.prototype.updateGameStatus = function(data) { - if (data[cah.$.AjaxResponse.GAME_INFO][cah.$.GameInfo.HOST] == cah.nickname + this.host_ = data[cah.$.AjaxResponse.GAME_INFO][cah.$.GameInfo.HOST]; + + if (this.host_ == cah.nickname && data[cah.$.AjaxResponse.GAME_INFO][cah.$.GameInfo.STATE] == cah.$.GameState.LOBBY) { $("#start_game").show(); } else { $("#start_game").hide(); } + if (data[cah.$.AjaxResponse.GAME_INFO][cah.$.GameInfo.STATE] == cah.$.GameState.LOBBY) { + this.showOptions_(); + } else { + this.hideOptions_(); + } + if (data[cah.$.AjaxResponse.GAME_INFO][cah.$.GameInfo.STATE] == cah.$.GameState.PLAYING) { // TODO this is the cause of the cards blanking when someone joins or leaves + // store the last state somewhere too? $(".game_white_cards", this.element_).empty(); } @@ -818,7 +853,9 @@ cah.Game.prototype.roundCardClick_ = function(e) { cah.Game.prototype.leaveGameClick_ = function() { // TODO make sure everything cleans up right, I got an error when I tried to start a different // game after leaving one - cah.Ajax.build(cah.$.AjaxOperation.LEAVE_GAME).withGameId(this.id_).run(); + if (confirm("Are you sure you wish to leave the game?")) { + cah.Ajax.build(cah.$.AjaxOperation.LEAVE_GAME).withGameId(this.id_).run(); + } }; /** @@ -931,9 +968,13 @@ cah.Game.prototype.stateChange = function(data) { } this.roundCards_ = {}; $(".game_white_cards", this.element_).empty(); + + this.showOptions_(); + break; case cah.$.GameState.PLAYING: + this.hideOptions_(); this.refreshGameStatus(); this.setBlackCard(data[cah.$.LongPollResponse.BLACK_CARD]); break; @@ -949,6 +990,40 @@ cah.Game.prototype.stateChange = function(data) { } }; +/** + * Show the options panel. Enables or disables the controls based on whether we are the host. + * + * @private + */ +cah.Game.prototype.showOptions_ = function() { + // $(".game_options", this.element_).removeClass("hide"); + // $(".game_right_side", this.element_).addClass("hide"); + this.updateOptionsEnabled_(); +}; + +/** + * Enable or disable the option controls depending on whether we are the host. + * + * @private + */ +cah.Game.prototype.updateOptionsEnabled_ = function() { + if (this.host_ == cah.nickname) { + $("select", this.optionsElement_).removeAttr("disabled"); + } else { + $("select", this.optionsElement_).attr("disabled", "disabled"); + } +}; + +/** + * Hide the options panel. + * + * @private + */ +cah.Game.prototype.hideOptions_ = function() { + $(".game_options", this.element_).addClass("hide"); + $(".game_right_side", this.element_).removeClass("hide"); +}; + // /////////////////////////////////////////////// /**