From 21e0aea9a3b1950c95f5795dacdbcd5d521fbc3e Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Sun, 18 Mar 2012 21:38:24 -0700 Subject: [PATCH] add button to display game options in middle of game. do not allow host to change options in middle of game (on client, server should check this too) --- WebContent/cah.css | 2 +- WebContent/game.jsp | 3 ++- WebContent/js/cah.game.js | 27 ++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/WebContent/cah.css b/WebContent/cah.css index 73a56cb..9ee39cb 100644 --- a/WebContent/cah.css +++ b/WebContent/cah.css @@ -314,7 +314,7 @@ span.debug { padding: 5px; } -.game_show_last_round { +.game_menu_bar { float: right; } diff --git a/WebContent/game.jsp b/WebContent/game.jsp index 7d2b4f4..b41fac8 100644 --- a/WebContent/game.jsp +++ b/WebContent/game.jsp @@ -187,8 +187,9 @@ HttpSession hSession = request.getSession(true); class="hide">
- +
Waiting for server...
diff --git a/WebContent/js/cah.game.js b/WebContent/js/cah.game.js index 141083b..8668d62 100644 --- a/WebContent/js/cah.game.js +++ b/WebContent/js/cah.game.js @@ -231,10 +231,19 @@ cah.Game = function(id) { */ this.showingLastRound_ = false; + /** + * Whether we are showing the options or the game. + * + * @type {Boolean} + * @private + */ + this.showingOptions_ = true; + $("#leave_game").click(cah.bind(this, this.leaveGameClick_)); $("#start_game").click(cah.bind(this, this.startGameClick_)); $(".confirm_card", this.element_).click(cah.bind(this, this.confirmClick_)); $(".game_show_last_round", this.element_).click(cah.bind(this, this.showLastRoundClick_)); + $(".game_show_options", this.element_).click(cah.bind(this, this.showOptionsClick_)); $("select", this.optionsElement_).change(cah.bind(this, this.optionChanged_)); $("input", this.optionsElement_).blur(cah.bind(this, this.optionChanged_)); @@ -281,6 +290,20 @@ cah.Game.prototype.showLastRoundClick_ = function() { this.showingLastRound_ = !this.showingLastRound_; }; +/** + * Toggle showing the game's options. + * + * @private + */ +cah.Game.prototype.showOptionsClick_ = function() { + if (this.showingOptions_) { + this.showOptions_(); + } else { + this.hideOptions_(); + } + this.showingOptions_ = !this.showingOptions_; +}; + /** * @return {HTMLDivElement} This object's element. */ @@ -1053,6 +1076,7 @@ cah.Game.prototype.stateChange = function(data) { * @private */ cah.Game.prototype.hideOptions_ = function() { + $(".game_show_options", this.element_).val("Show Game Options"); $(".game_options", this.element_).addClass("hide"); $(".game_right_side", this.element_).removeClass("hide"); }; @@ -1063,6 +1087,7 @@ cah.Game.prototype.hideOptions_ = function() { * @private */ cah.Game.prototype.showOptions_ = function() { + $(".game_show_options", this.element_).val("Hide Game Options"); $(".game_options", this.element_).removeClass("hide"); $(".game_right_side", this.element_).addClass("hide"); this.updateOptionsEnabled_(); @@ -1074,7 +1099,7 @@ cah.Game.prototype.showOptions_ = function() { * @private */ cah.Game.prototype.updateOptionsEnabled_ = function() { - if (this.host_ == cah.nickname) { + if (this.host_ == cah.nickname && this.state_ == cah.$.GameState.LOBBY) { $("select", this.optionsElement_).removeAttr("disabled"); $("input", this.optionsElement_).removeAttr("disabled"); $(".options_host_only", this.optionsElement_).addClass("hide");