From 05771d28a98db88ac940b4742de34273df36c899 Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Wed, 14 Sep 2011 13:34:30 +0000 Subject: [PATCH] Auto-pass and auto-accept settings. --- .../src/main/webapp/js/gameUi.js | 104 ++++++++++++------ 1 file changed, 71 insertions(+), 33 deletions(-) diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js index a995d6010..cc280e7b9 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js @@ -32,12 +32,13 @@ var GempLotrGameUI = Class.extend({ selectionFunction: null, - swipeOptions: null, - chatBoxDiv: null, chatBox: null, communication: null, + settingsAutoPass: false, + settingsAutoAccept: false, + init: function(communication) { log("ui initialized"); this.communication = communication; @@ -710,13 +711,17 @@ var GempLotrGameUI = Class.extend({ .dialog("option", "width", "600") .dialog("option", "height", "300"); + var finishChoice = function() { + that.dialogInstance.dialog("close"); + $("#arbitraryChoice").html(""); + that.clearSelection(); + that.decisionFunction(id, "" + selectedCardIds); + }; + if (min == 0) { this.dialogInstance.dialog("option", "buttons", { "DONE": function() { - $(this).dialog("close"); - $("#arbitraryChoice").html(""); - that.clearSelection(); - that.decisionFunction(id, "" + selectedCardIds); + finishChoice(); } }); } @@ -741,17 +746,18 @@ var GempLotrGameUI = Class.extend({ if (selectedCardIds.length == min) { this.dialogInstance.dialog("option", "buttons", { "DONE": function() { - $(this).dialog("close"); - $("#arbitraryChoice").html(""); - that.clearSelection(); - that.decisionFunction(id, "" + selectedCardIds); + finishChoice(); } }); } if (selectedCardIds.length == max) { - that.clearSelection(); - $(".card:cardId(" + cardId + ")").addClass("selectedCard"); + if (that.settingsAutoAccept) { + finishChoice(); + } else { + that.clearSelection(); + $(".card:cardId(" + cardId + ")").addClass("selectedCard"); + } } else { $(".card:cardId(" + cardId + ")").removeClass("selectableCard").addClass("selectedCard"); } @@ -775,13 +781,22 @@ var GempLotrGameUI = Class.extend({ var that = this; + if (cardIds.length == 0 && this.settingsAutoPass) { + that.decisionFunction(id, ""); + return; + } + var selectedCardIds = new Array(); - this.alert.html(text + "
"); - $("#DONE").button().click(function() { + var finishChoice = function() { that.alert.html(""); that.clearSelection(); that.decisionFunction(id, "" + selectedCardIds); + }; + + this.alert.html(text + "
"); + $("#DONE").button().click(function() { + finishChoice(); }); for (var i = 0; i < cardIds.length; i++) { @@ -805,7 +820,12 @@ var GempLotrGameUI = Class.extend({ if (actions.length == 1) { var action = actions[0]; selectedCardIds.push(action.actionId); - that.clearSelection(); + if (this.settingsAutoAccept) { + finishChoice(); + } else { + that.clearSelection(); + $(".card:cardId(" + cardId + ")").addClass("selectedCard"); + } } }; @@ -822,6 +842,8 @@ var GempLotrGameUI = Class.extend({ var that = this; + var selectedActionIds = new Array(); + this.dialogInstance .html("
") .dialog("option", "title", text) @@ -831,6 +853,13 @@ var GempLotrGameUI = Class.extend({ var cardIds = new Array(); + var finishChoice = function() { + that.dialogInstance.dialog("close"); + $("#arbitraryChoice").html(""); + that.clearSelection(); + that.decisionFunction(id, "" + selectedActionIds); + }; + for (var i = 0; i < blueprintIds.length; i++) { var blueprintId = blueprintIds[i]; @@ -844,18 +873,21 @@ var GempLotrGameUI = Class.extend({ this.selectionFunction = function(cardId) { var actionId = actionIds[parseInt(cardId.substring(4))]; - - this.dialogInstance.dialog("option", "buttons", { - "DONE": function() { - $(this).dialog("close"); - $("#arbitraryChoice").html(""); - that.clearSelection(); - that.decisionFunction(id, "" + actionId); - } - }); + selectedActionIds.push(actionId); that.clearSelection(); - $(".card:cardId(" + cardId + ")").addClass("selectedCard"); + + if (this.settingsAutoAccept) { + finishChoice(); + } else { + this.dialogInstance.dialog("option", "buttons", { + "DONE": function() { + finishChoice(); + } + }); + + $(".card:cardId(" + cardId + ")").addClass("selectedCard"); + } }; this.attachSelectionFunctions(cardIds); @@ -880,12 +912,16 @@ var GempLotrGameUI = Class.extend({ var selectedCardIds = new Array(); + var finishChoice = function() { + that.alert.html(""); + that.clearSelection(); + that.decisionFunction(id, "" + selectedCardIds); + }; + if (min == 0) { this.alert.append("
"); $("#DONE").button().click(function() { - that.alert.html(""); - that.clearSelection(); - that.decisionFunction(id, "" + selectedCardIds); + finishChoice(); }); } @@ -894,15 +930,17 @@ var GempLotrGameUI = Class.extend({ if (selectedCardIds.length == min) { this.alert.append("
"); $("#DONE").button().click(function() { - that.alert.html(""); - that.clearSelection(); - that.decisionFunction(id, "" + selectedCardIds); + finishChoice(); }); } if (selectedCardIds.length == max) { - $(".selectableCard").removeClass("selectableCard"); - $(".card:cardId(" + cardId + ")").addClass("selectedCard"); + if (this.settingsAutoAccept) { + finishChoice(); + } else { + $(".selectableCard").removeClass("selectableCard"); + $(".card:cardId(" + cardId + ")").addClass("selectedCard"); + } } else { $(".card:cardId(" + cardId + ")").removeClass("selectableCard").addClass("selectedCard"); }