Skip to content

Commit

Permalink
Bug Fixes:
Browse files Browse the repository at this point in the history
 * Show html for dialogs before instantiating.
  Previously, calling close() on a dialog was
  setting display:none on the element, so if
  the same dialog needed to show up there
  would be no text.

 * Return draggable control to user after
  choose treasure.

 * Don't open a dialog if one is already
  open. Previously background refreshes were
  causing multiple copies of windows to pop
  up.
  • Loading branch information
chellmuth committed Oct 7, 2008
1 parent 578b262 commit ddc15ad
Showing 1 changed file with 48 additions and 20 deletions.
68 changes: 48 additions & 20 deletions templates/board_test.html
Expand Up @@ -327,14 +327,17 @@

function setmode(type) {
if (type == 'CHOOSE_COLOR') {
if ($("#choose_battle").dialog("isOpen")) {
return;
}
button_colors = {};
$.each(state['war_choices'], function(i, civ) {
button_colors[civ] = function() {
$.getJSON("/choose_color/{{ game_id }}/{{ player_no }}/" + civ + "/", function (data) { json_callback(data); });
$(this).dialog("destroy");
}
});
$("#choose_battle").dialog({
$("#choose_battle").show().dialog({
dialogClass: "flora",
buttons: button_colors,
draggable: true,
Expand All @@ -344,6 +347,9 @@
}
//XXX code duplication
else if (type.match(/^ATTACK/)) {
if ($("#commit_choices").dialog("isOpen")) {
return;
}
button_choices = [];

// had some problems with closures using for-loop variables
Expand All @@ -359,7 +365,7 @@
}});

$("#commit_choices").html("You have "+state['attack']['attack_board'].length+" tiles on the board</br>Your opponent has "+state['attack']['defend_board'].length+" tiles on the board</br>You have "+state['attack']['tiles_available']+" tiles in your hand you can contribute" );
$("#commit_choices").dialog({
$("#commit_choices").show().dialog({
dialogClass: "flora",
buttons: button_choices,
draggable: true,
Expand All @@ -368,6 +374,10 @@
});
}
else if (type.match(/^DEFEND/)) {
if ($("#commit_choices").dialog('isOpen')) {
return;
}

button_choices = [];

// had some problems with closures using for-loop variables
Expand All @@ -383,7 +393,7 @@
}});

$("#commit_choices").html("You have "+state['defend']['defend_board'].length+" tiles on the board</br>Your opponent has "+state['defend']['attack_board'].length+" + "+state['defend']['attack_committed']+" tiles</br>You have "+state['defend']['tiles_available']+" tiles in your hand you can contribute" );
$("#commit_choices").dialog({
$("#commit_choices").show().dialog({
dialogClass: "flora",
buttons: button_choices,
draggable: true,
Expand All @@ -392,6 +402,9 @@
});
}
else if (type.match(/^INTERNAL/)) {
if ($("#commit_choices").dialog("isOpen")) {
return;
}
button_choices = [];

// had some problems with closures using for-loop variables
Expand All @@ -407,7 +420,7 @@
}});

$("#commit_choices").html("You have "+state['defend_internal']['defend_board']+" tiles on the board</br>Your opponent has "+state['defend_internal']['attack_board']+" + "+state['defend_internal']['attack_committed']+" tiles</br>You have "+state['defend_internal']['tiles_available']+" tiles in your hand you can contribute" );
$("#commit_choices").dialog({
$("#commit_choices").show().dialog({
dialogClass: "flora",
buttons: button_choices,
draggable: true,
Expand All @@ -419,19 +432,21 @@
set_draggables(false);
$.each(state['treasure_info']['can_choose'],
function(i, cell_no) {
$("#drop" + cell_no).bind("click", function(e) {
var total_treasure = state['treasure_info']['must_choose'].length +
state['treasure_info']['num_choose'];
if ($(this).hasClass('selected-treasure')) {
$(this).removeClass('selected-treasure');
}
else {
if (total_treasure > $(".selected-treasure").length) {
$(this).addClass('selected-treasure');
check_selected_treasure();
}
}
});
$("#drop" + cell_no).bind(
"click",
function(e) {
var total_treasure = state['treasure_info']['must_choose'].length +
state['treasure_info']['num_choose'];
if ($(this).hasClass('selected-treasure')) {
$(this).removeClass('selected-treasure');
}
else {
if (total_treasure > $(".selected-treasure").length) {
$(this).addClass('selected-treasure');
check_selected_treasure();
}
}
});
});
$.each(state['treasure_info']['must_choose'],
function(i, cell_no) {
Expand All @@ -445,17 +460,22 @@
var total_treasure = state['treasure_info']['must_choose'].length +
state['treasure_info']['num_choose'];
if (total_treasure == $(".selected-treasure").length) {
if ($("#confirm_treasure").dialog("isOpen")) {
return;
}

var button_choices = {};
button_choices['yes'] = function() {
$.getJSON("/choose_treasure/{{ game_id }}/{{ player_no }}/" + jquery_to_list($(".selected-treasure")) + "/", function (data) { json_callback(data); });
set_draggables(true);
$(this).dialog("destroy");
};

button_choices['no'] = function() {
$(this).dialog("destroy");
};

$("#confirm_treasure").dialog({
$("#confirm_treasure").show().dialog({
dialogClass: "flora",
buttons: button_choices,
draggable: true,
Expand Down Expand Up @@ -608,7 +628,11 @@
$.getJSON("/drop_civ/{{ game_id }}/{{ player_no }}/" + piece + "/" + cell_no + "/", function (data) { json_callback(data); });
}
else if (war_index >= 0) {
$("#external_confirm").dialog({
if ($("#external_confirm").dialog('isOpen')) {
return;
}

$("#external_confirm").show().dialog({
dialogClass: "flora",
buttons: {
"LET'S DO THIS": function() {
Expand Down Expand Up @@ -666,6 +690,10 @@
});

function confirm_internal_battle(cell_no, civ_type, attack_board, tiles_available, defend_board, is_reposition) {
if ($("#commit_choices").dialog("isOpen")) {
return;
}

var url = is_reposition ? 'reposition_ruler_war' : 'internal_attack';
button_choices = {};

Expand All @@ -685,7 +713,7 @@
};

$("#commit_choices").html("You have "+attack_board+" tiles on the board</br>Your opponent has "+defend_board+" tiles</br>You have "+tiles_available+" tiles in your hand you can contribute");
$("#commit_choices").dialog({
$("#commit_choices").show().dialog({
dialogClass: "flora",
buttons: button_choices,
draggable: true,
Expand Down

0 comments on commit ddc15ad

Please sign in to comment.