Author: jtn
Date: Thu May 28 00:01:14 2015
New Revision: 29142

URL: http://svn.gna.org/viewcvs/freeciv?rev=29142&view=rev
Log:
Add a confirmation dialog when cancelling treaties in the Gtk client.

Reported anonymously.

See gna bug #23411.

Modified:
    branches/S2_5/client/gui-gtk-2.0/plrdlg.c
    branches/S2_5/client/gui-gtk-3.0/plrdlg.c
    branches/S2_5/common/player.c
    branches/S2_5/common/player.h
    branches/S2_5/server/plrhand.c

Modified: branches/S2_5/client/gui-gtk-2.0/plrdlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-2.0/plrdlg.c?rev=29142&r1=29141&r2=29142&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-2.0/plrdlg.c   (original)
+++ branches/S2_5/client/gui-gtk-2.0/plrdlg.c   Thu May 28 00:01:14 2015
@@ -23,6 +23,7 @@
 #include <gdk/gdkkeysyms.h>
 
 /* utility */
+#include "astring.h"
 #include "fcintl.h"
 #include "support.h"
 
@@ -748,7 +749,31 @@
 }
 
 /**************************************************************************
-  Pact cancelled
+  Confirm pact/treaty cancellation.
+  Frees strings passed in.
+**************************************************************************/
+static void confirm_cancel_pact(enum clause_type clause, int plrno,
+                                char *title, char *question)
+{
+  GtkWidget *shell;
+
+  shell = gtk_message_dialog_new(NULL, 0,
+                                 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
+                                 "%s", question);
+  gtk_window_set_title(GTK_WINDOW(shell), title);
+  setup_dialog(shell, toplevel);
+  gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_NO);
+
+  if (gtk_dialog_run(GTK_DIALOG(shell)) == GTK_RESPONSE_YES) {
+    dsend_packet_diplomacy_cancel_pact(&client.conn, plrno, clause);
+  }
+  gtk_widget_destroy(shell);
+  FC_FREE(title);
+  FC_FREE(question);
+}
+
+/**************************************************************************
+  Pact cancellation requested
 **************************************************************************/
 void players_war_callback(GtkMenuItem *item, gpointer data)
 {
@@ -756,13 +781,35 @@
   GtkTreeIter it;
 
   if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
+    struct astring title = ASTRING_INIT, question = ASTRING_INIT;
     gint plrno;
+    struct player *aplayer;
+    enum diplstate_type oldstate, newstate;
 
     gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
+    aplayer = player_by_number(plrno);
+    fc_assert_ret(aplayer != NULL);
+
+    oldstate = player_diplstate_get(client_player(), aplayer)->type;
+    newstate = cancel_pact_result(oldstate);
+
+    /* TRANS: %s is a diplomatic state: "Cancel Cease-fire" */
+    astr_set(&title, _("Cancel %s"), diplstate_text(oldstate));
+
+    if (newstate == DS_WAR) {
+      astr_set(&question, _("Really declare war on the %s?"),
+               nation_plural_for_player(aplayer));
+    } else {
+      /* TRANS: "Cancel Belgian Alliance? ... will be Armistice." */
+      astr_set(&question, _("Cancel %s %s? New diplomatic state will be %s."),
+               nation_adjective_for_player(aplayer),
+               diplstate_text(oldstate),
+               diplstate_text(newstate));
+    }
 
     /* can be any pact clause */
-    dsend_packet_diplomacy_cancel_pact(&client.conn, plrno,
-                                      CLAUSE_CEASEFIRE);
+    confirm_cancel_pact(CLAUSE_CEASEFIRE, plrno,
+                        astr_to_str(&title), astr_to_str(&question));
   }
 }
 
@@ -775,15 +822,26 @@
   GtkTreeIter it;
 
   if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
+    struct astring question = ASTRING_INIT;
     gint plrno;
+    struct player *aplayer;
 
     gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
-    dsend_packet_diplomacy_cancel_pact(&client.conn, plrno, CLAUSE_VISION);
-  }
-}
-
-/**************************************************************************
-  Intelligenze report query
+    aplayer = player_by_number(plrno);
+    fc_assert_ret(aplayer != NULL);
+
+    /* TRANS: "...from the Belgians?" */
+    astr_set(&question, _("Withdraw shared vision from the %s?"),
+             nation_plural_for_player(aplayer));
+
+    confirm_cancel_pact(CLAUSE_VISION, plrno,
+                        fc_strdup(_("Withdraw Shared Vision")),
+                        astr_to_str(&question));
+  }
+}
+
+/**************************************************************************
+  Intelligence report query
 **************************************************************************/
 void players_intel_callback(GtkMenuItem *item, gpointer data)
 {
@@ -866,4 +924,4 @@
     col = gtk_tree_view_get_column(GTK_TREE_VIEW(players_list), i);
     gtk_tree_view_column_set_visible(col, player_dlg_columns[i].show);
   }
-};
+}

Modified: branches/S2_5/client/gui-gtk-3.0/plrdlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-3.0/plrdlg.c?rev=29142&r1=29141&r2=29142&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-3.0/plrdlg.c   (original)
+++ branches/S2_5/client/gui-gtk-3.0/plrdlg.c   Thu May 28 00:01:14 2015
@@ -23,6 +23,7 @@
 #include <gdk/gdkkeysyms.h>
 
 /* utility */
+#include "astring.h"
 #include "fcintl.h"
 #include "support.h"
 
@@ -759,7 +760,31 @@
 }
 
 /**************************************************************************
-  Pact cancelled
+  Confirm pact/treaty cancellation.
+  Frees strings passed in.
+**************************************************************************/
+static void confirm_cancel_pact(enum clause_type clause, int plrno,
+                                char *title, char *question)
+{
+  GtkWidget *shell;
+
+  shell = gtk_message_dialog_new(NULL, 0,
+                                 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
+                                 "%s", question);
+  gtk_window_set_title(GTK_WINDOW(shell), title);
+  setup_dialog(shell, toplevel);
+  gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_NO);
+
+  if (gtk_dialog_run(GTK_DIALOG(shell)) == GTK_RESPONSE_YES) {
+    dsend_packet_diplomacy_cancel_pact(&client.conn, plrno, clause);
+  }
+  gtk_widget_destroy(shell);
+  FC_FREE(title);
+  FC_FREE(question);
+}
+
+/**************************************************************************
+  Pact cancellation requested
 **************************************************************************/
 void players_war_callback(GtkMenuItem *item, gpointer data)
 {
@@ -767,13 +792,35 @@
   GtkTreeIter it;
 
   if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
+    struct astring title = ASTRING_INIT, question = ASTRING_INIT;
     gint plrno;
+    struct player *aplayer;
+    enum diplstate_type oldstate, newstate;
 
     gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
+    aplayer = player_by_number(plrno);
+    fc_assert_ret(aplayer != NULL);
+
+    oldstate = player_diplstate_get(client_player(), aplayer)->type;
+    newstate = cancel_pact_result(oldstate);
+
+    /* TRANS: %s is a diplomatic state: "Cancel Cease-fire" */
+    astr_set(&title, _("Cancel %s"), diplstate_text(oldstate));
+
+    if (newstate == DS_WAR) {
+      astr_set(&question, _("Really declare war on the %s?"),
+               nation_plural_for_player(aplayer));
+    } else {
+      /* TRANS: "Cancel Belgian Alliance? ... will be Armistice." */
+      astr_set(&question, _("Cancel %s %s? New diplomatic state will be %s."),
+               nation_adjective_for_player(aplayer),
+               diplstate_text(oldstate),
+               diplstate_text(newstate));
+    }
 
     /* can be any pact clause */
-    dsend_packet_diplomacy_cancel_pact(&client.conn, plrno,
-                                      CLAUSE_CEASEFIRE);
+    confirm_cancel_pact(CLAUSE_CEASEFIRE, plrno,
+                        astr_to_str(&title), astr_to_str(&question));
   }
 }
 
@@ -786,15 +833,26 @@
   GtkTreeIter it;
 
   if (gtk_tree_selection_get_selected(players_selection, &model, &it)) {
+    struct astring question = ASTRING_INIT;
     gint plrno;
+    struct player *aplayer;
 
     gtk_tree_model_get(model, &it, PLR_DLG_COL_ID, &plrno, -1);
-    dsend_packet_diplomacy_cancel_pact(&client.conn, plrno, CLAUSE_VISION);
-  }
-}
-
-/**************************************************************************
-  Intelligenze report query
+    aplayer = player_by_number(plrno);
+    fc_assert_ret(aplayer != NULL);
+
+    /* TRANS: "...from the Belgians?" */
+    astr_set(&question, _("Withdraw shared vision from the %s?"),
+             nation_plural_for_player(aplayer));
+
+    confirm_cancel_pact(CLAUSE_VISION, plrno,
+                        fc_strdup(_("Withdraw Shared Vision")),
+                        astr_to_str(&question));
+  }
+}
+
+/**************************************************************************
+  Intelligence report query
 **************************************************************************/
 void players_intel_callback(GtkMenuItem *item, gpointer data)
 {
@@ -877,4 +935,4 @@
     col = gtk_tree_view_get_column(GTK_TREE_VIEW(players_list), i);
     gtk_tree_view_column_set_visible(col, player_dlg_columns[i].show);
   }
-};
+}

Modified: branches/S2_5/common/player.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/player.c?rev=29142&r1=29141&r2=29142&view=diff
==============================================================================
--- branches/S2_5/common/player.c       (original)
+++ branches/S2_5/common/player.c       Thu May 28 00:01:14 2015
@@ -67,6 +67,29 @@
   NULL, N_("Away"), N_("Novice"), N_("Easy"), NULL, N_("Normal"),
   NULL, N_("Hard"), N_("Cheating"), NULL, N_("Experimental")
 };
+
+/***************************************************************
+  Return the diplomatic state that cancelling a pact will
+  end up in.
+***************************************************************/
+enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
+{
+  switch(oldstate) {
+  case DS_NO_CONTACT: /* possible if someone declares war on our ally */
+  case DS_WAR: /* no change */
+  case DS_ARMISTICE:
+  case DS_CEASEFIRE:
+  case DS_PEACE:
+    return DS_WAR;
+  case DS_ALLIANCE:
+    return DS_ARMISTICE;
+  case DS_TEAM: /* no change */
+    return DS_TEAM;
+  default:
+    log_error("non-pact diplstate %d in cancel_pact_result", oldstate);
+    return DS_WAR; /* arbitrary */
+  }
+}
 
 /***************************************************************
   Returns true iff p1 can cancel treaty on p2.

Modified: branches/S2_5/common/player.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/player.h?rev=29142&r1=29141&r2=29142&view=diff
==============================================================================
--- branches/S2_5/common/player.h       (original)
+++ branches/S2_5/common/player.h       Thu May 28 00:01:14 2015
@@ -365,6 +365,8 @@
 const char *diplstate_text(const enum diplstate_type type);
 const char *love_text(const int love);
 
+enum diplstate_type cancel_pact_result(enum diplstate_type oldstate);
+
 struct player_diplstate *player_diplstate_get(const struct player *plr1,
                                               const struct player *plr2);
 bool are_diplstates_equal(const struct player_diplstate *pds1,

Modified: branches/S2_5/server/plrhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/plrhand.c?rev=29142&r1=29141&r2=29142&view=diff
==============================================================================
--- branches/S2_5/server/plrhand.c      (original)
+++ branches/S2_5/server/plrhand.c      Thu May 28 00:01:14 2015
@@ -642,20 +642,7 @@
   /* else, breaking a treaty */
 
   /* check what the new status will be */
-  switch(old_type) {
-  case DS_NO_CONTACT: /* possible if someone declares war on our ally */
-  case DS_ARMISTICE:
-  case DS_CEASEFIRE:
-  case DS_PEACE:
-    new_type = DS_WAR;
-    break;
-  case DS_ALLIANCE:
-    new_type = DS_ARMISTICE;
-    break;
-  default:
-    log_error("non-pact diplstate in handle_player_cancel_pact");
-    return;
-  }
+  new_type = cancel_pact_result(old_type);
 
   ds_plrplr2 = player_diplstate_get(pplayer, pplayer2);
   ds_plr2plr = player_diplstate_get(pplayer2, pplayer);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to