Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#5479) xaw: no way to see diplomatic relations of other
Home

[Freeciv-Dev] (PR#5479) xaw: no way to see diplomatic relations of other

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#5479) xaw: no way to see diplomatic relations of other players
From: "Egor Vyscrebentsov" <evyscr@xxxxxxxxx>
Date: Fri, 10 Dec 2004 09:36:49 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=5479 >

> [evyscr - Dec 07 23:57:57 2004]:
> Attached patch (against current CVS HEAD):
> 1. Creates new dialog for player's diplomacy in 'inteldlg.[ch]'
> (with adding window message for (x) button)
> 2. Makes some cleanup of intel_dialog

Second version:
- some fixes by CodingStyle
- popup_intel_diplo_dialog has parameter 'raise' now.

Since (and if) nobody protests, i will commit this patch to both
brances in 24h.
? xaw-intel-diplomacy.diff
? client/gui-xaw/xaw_intel_diplo.diff
Index: client/gui-xaw/actions.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/actions.c,v
retrieving revision 1.24
diff -u -r1.24 actions.c
--- client/gui-xaw/actions.c    25 Nov 2004 06:57:17 -0000      1.24
+++ client/gui-xaw/actions.c    10 Dec 2004 17:29:46 -0000
@@ -35,6 +35,7 @@
 #include "menu.h"
 #include "messagewin.h"
 #include "plrdlg.h"
+#include "inteldlg.h"
 #include "ratesdlg.h"
 #include "repodlgs.h"
 #include "spaceshipdlg.h"
@@ -689,6 +690,12 @@
   plrdlg_msg_close(w);
 }
 
+static void xaw_msg_close_intel_diplo(Widget w, XEvent *event, String *argv,
+                                     Cardinal *argc)
+{
+  intel_diplo_dialog_msg_close(w);
+}
+
 static void xaw_msg_close_science_report(Widget w, XEvent *event, String 
*argv, Cardinal *argc)
 {
   sciencereport_msg_close(w);
@@ -802,6 +809,7 @@
   { "msg-close-help", xaw_msg_close_help },
   { "msg-close-messages", xaw_msg_close_messages },
   { "msg-close-players", xaw_msg_close_players },
+  { "msg-close-intel-diplo", xaw_msg_close_intel_diplo },
   { "msg-close-science-report", xaw_msg_close_science_report },
   { "msg-close-spaceship", xaw_msg_close_spaceship },
   { "msg-close-units-report", xaw_msg_close_units_report },
Index: client/gui-xaw/inteldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/inteldlg.c,v
retrieving revision 1.22
diff -u -r1.22 inteldlg.c
--- client/gui-xaw/inteldlg.c   21 Sep 2004 01:03:57 -0000      1.22
+++ client/gui-xaw/inteldlg.c   10 Dec 2004 17:29:46 -0000
@@ -44,132 +44,172 @@
 
 /******************************************************************/
 static Widget intel_dialog_shell;
+static Widget intel_form;
+static Widget intel_label;
+static Widget intel_close_command;
+static Widget intel_diplo_command;
+static bool intel_dialog_shell_is_raised;
+
+static Widget intel_diplo_dialog_shell;
+static Widget intel_diplo_form;
+static Widget intel_diplo_label;
+static Widget intel_diplo_list;
+static Widget intel_diplo_close_command;
+static bool intel_diplo_dialog_shell_is_raised;
 /******************************************************************/
 
+void popdown_intel_dialog(void);
+void create_intel_dialog(struct player *pplayer);
 
-void intel_create_dialog(struct player *p);
-
-void intel_close_command_callback(Widget w, XtPointer client_data, 
-                                 XtPointer call_data);
+void intel_close_callback(Widget w, XtPointer client_data,
+                         XtPointer call_data);
+void intel_diplo_callback(Widget w, XtPointer client_data,
+                         XtPointer call_data);
+
+void popup_intel_diplo_dialog(struct player *pplayer, bool raise);
+void popdown_intel_diplo_dialog(void);
+void create_intel_diplo_dialog(struct player *pplayer, bool raise);
+void update_intel_diplo_dialog(struct player *pplayer);
+void intel_diplo_close_callback(Widget w, XtPointer client_data,
+                               XtPointer call_data);
 
 /****************************************************************
-... 
+  Popup an intelligence dialog for the given player.
 *****************************************************************/
 void popup_intel_dialog(struct player *p)
 {
-  if(!intel_dialog_shell) {
-    intel_create_dialog(p);
-    xaw_set_relative_position(toplevel, intel_dialog_shell, 25, 25);
-    XtPopup(intel_dialog_shell, XtGrabNone);
+  intel_dialog_shell_is_raised = TRUE;
+  if (!intel_dialog_shell) {
+    create_intel_dialog(p);
+  }
+  xaw_set_relative_position(toplevel, intel_dialog_shell, 25, 25);
+  XtPopup(intel_dialog_shell, XtGrabNone);
+  if (intel_dialog_shell_is_raised) {
     XtSetSensitive(main_form, FALSE);
   }
 }
 
-
+/****************************************************************
+  Close an intelligence dialog.
+*****************************************************************/
+void popdown_intel_dialog(void)
+{
+  if (intel_dialog_shell) {
+    if (intel_dialog_shell_is_raised) {
+      XtSetSensitive(main_form, TRUE);
+    }
+    XtDestroyWidget(intel_dialog_shell);
+    intel_dialog_shell = 0;
+  }
+}
 
 /****************************************************************
 ...
 *****************************************************************/
-void intel_create_dialog(struct player *p)
+void create_intel_dialog(struct player *pplayer)
 {
-  Widget form, title, close;
   char buf[64];
   struct city *pcity;
 
   static char *tech_list_names_ptrs[A_LAST+1];
   static char tech_list_names[A_LAST+1][200];
   int i, j;
-  
-  
+
+
   I_T(intel_dialog_shell = XtCreatePopupShell("intelpopup", 
                                              transientShellWidgetClass,
                                              toplevel, NULL, 0));
 
-  form = XtVaCreateManagedWidget("intelform", 
-                                formWidgetClass, 
-                                intel_dialog_shell, NULL);
-  
+  intel_form = XtVaCreateManagedWidget("intelform", 
+                                      formWidgetClass, 
+                                      intel_dialog_shell, NULL);
+
   my_snprintf(buf, sizeof(buf),
              _("Intelligence Information for the %s Empire"), 
-             get_nation_name(p->nation));
-  
-  title=XtVaCreateManagedWidget("inteltitlelabel", 
-                         labelWidgetClass, 
-                         form, 
-                         XtNlabel, buf,
-                         NULL);
-  
+             get_nation_name(pplayer->nation));
+
+  intel_label = I_L(XtVaCreateManagedWidget("inteltitlelabel", 
+                                           labelWidgetClass, 
+                                           intel_form, 
+                                           XtNlabel, buf,
+                                           NULL));
+
   my_snprintf(buf, sizeof(buf), _("Ruler: %s %s"), 
-             get_ruler_title(p->government, p->is_male, p->nation), p->name);
+             get_ruler_title(pplayer->government, pplayer->is_male,
+                             pplayer->nation),
+             pplayer->name);
   XtVaCreateManagedWidget("intelnamelabel", 
                          labelWidgetClass, 
-                         form, 
+                         intel_form, 
                          XtNlabel, buf,
                          NULL);   
-  
+
   my_snprintf(buf, sizeof(buf),
-             _("Government: %s"), get_government_name(p->government));
+             _("Government: %s"), get_government_name(pplayer->government));
   XtVaCreateManagedWidget("intelgovlabel", 
                          labelWidgetClass, 
-                         form, 
+                         intel_form, 
                          XtNlabel, buf,
                          NULL);   
-  
-  my_snprintf(buf, sizeof(buf), _("Gold: %d"), p->economic.gold);
+
+  my_snprintf(buf, sizeof(buf), _("Gold: %d"), pplayer->economic.gold);
   XtVaCreateManagedWidget("intelgoldlabel", 
                          labelWidgetClass, 
-                         form, 
+                         intel_form, 
                          XtNlabel, buf,
                          NULL);   
 
-  my_snprintf(buf, sizeof(buf), _("Tax: %d%%"), p->economic.tax);
+  my_snprintf(buf, sizeof(buf), _("Tax: %d%%"), pplayer->economic.tax);
   XtVaCreateManagedWidget("inteltaxlabel", 
                          labelWidgetClass, 
-                         form, 
+                         intel_form, 
                          XtNlabel, buf,
                          NULL);   
 
-  my_snprintf(buf, sizeof(buf), _("Science: %d%%"), p->economic.science);
+  my_snprintf(buf, sizeof(buf), _("Science: %d%%"),
+             pplayer->economic.science);
   XtVaCreateManagedWidget("intelscilabel", 
                          labelWidgetClass, 
-                         form, 
+                         intel_form, 
                          XtNlabel, buf,
                          NULL);   
 
-  my_snprintf(buf, sizeof(buf), _("Luxury: %d%%"), p->economic.luxury);
+  my_snprintf(buf, sizeof(buf), _("Luxury: %d%%"), pplayer->economic.luxury);
   XtVaCreateManagedWidget("intelluxlabel", 
                          labelWidgetClass, 
-                         form, 
+                         intel_form, 
                          XtNlabel, buf,
                          NULL);   
 
-  if (p->research.researching == A_UNSET) {
+  if (pplayer->research.researching == A_UNSET) {
     my_snprintf(buf, sizeof(buf), _("Researching: %s(%d/%d)"),
                advances[A_NONE].name,
-               p->research.bulbs_researched, total_bulbs_required(p));
+               pplayer->research.bulbs_researched,
+               total_bulbs_required(pplayer));
   } else {
     my_snprintf(buf, sizeof(buf), _("Researching: %s(%d/%d)"),
-               get_tech_name(p, p->research.researching),
-               p->research.bulbs_researched, total_bulbs_required(p));
+               get_tech_name(pplayer, pplayer->research.researching),
+               pplayer->research.bulbs_researched,
+               total_bulbs_required(pplayer));
   }
 
   XtVaCreateManagedWidget("intelreslabel", 
                          labelWidgetClass, 
-                         form, 
+                         intel_form, 
                          XtNlabel, buf,
                          NULL);   
 
-  pcity = find_palace(p);
+  pcity = find_palace(pplayer);
   my_snprintf(buf, sizeof(buf), _("Capital: %s"),
              (!pcity)?_("(Unknown)"):pcity->name);
   XtVaCreateManagedWidget("intelcapitallabel", 
                          labelWidgetClass, 
-                         form, 
+                         intel_form, 
                          XtNlabel, buf,
                          NULL);   
 
   for(i=A_FIRST, j=0; i<game.num_tech_types; i++)
-    if(get_invention(p, i)==TECH_KNOWN) {
+    if (get_invention(pplayer, i) == TECH_KNOWN) {
       if(get_invention(game.player_ptr, i)==TECH_KNOWN) {
        sz_strlcpy(tech_list_names[j], advances[i].name);
       } else {
@@ -181,36 +221,53 @@
     }
   tech_list_names_ptrs[j]=0;
 
-  
   XtVaCreateManagedWidget("inteltechlist", 
                          listWidgetClass,
-                         form,
+                         intel_form,
                          XtNlist, tech_list_names_ptrs,
                          NULL);
-  
-  I_L(close = XtVaCreateManagedWidget("intelclosecommand", 
-                                     commandWidgetClass,
-                                     form, NULL));
-  
-  XtAddCallback(close, XtNcallback, intel_close_command_callback, NULL);
+
+  intel_close_command =
+    I_L(XtVaCreateManagedWidget("intelclosecommand", 
+                               commandWidgetClass,
+                               intel_form, NULL));
+
+  intel_diplo_command =
+    I_L(XtVaCreateManagedWidget("inteldiplocommand",
+                               commandWidgetClass,
+                               intel_form, NULL));
+
+  XtAddCallback(intel_close_command, XtNcallback,
+               intel_close_callback, NULL);
+  XtAddCallback(intel_diplo_command, XtNcallback,
+               intel_diplo_callback, INT_TO_XTPOINTER(pplayer->player_no));
   XtRealizeWidget(intel_dialog_shell);
 
-  xaw_horiz_center(title);
+  xaw_horiz_center(intel_label);
 }
 
 
-
-
-
 /**************************************************************************
 ...
 **************************************************************************/
-void intel_close_command_callback(Widget w, XtPointer client_data, 
-                                 XtPointer call_data)
-{ 
-  XtSetSensitive(main_form, TRUE);
+void intel_close_callback(Widget w, XtPointer client_data,
+                         XtPointer call_data)
+{
+/*  XtSetSensitive(main_form, TRUE);
   XtDestroyWidget(intel_dialog_shell);
   intel_dialog_shell=0;
+*/
+  popdown_intel_dialog();
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void intel_diplo_callback(Widget w, XtPointer client_data,
+                         XtPointer call_data)
+{
+  popup_intel_diplo_dialog(&game.players[XTPOINTER_TO_INT(client_data)],
+                          FALSE);
 }
 
 /****************************************************************************
@@ -221,3 +278,147 @@
 {
   /* PORTME */
 }
+
+/****************************************************************
+  Popup a player's relations dialog for the given player.
+*****************************************************************/
+void popup_intel_diplo_dialog(struct player *pplayer, bool raise)
+{
+  if (!intel_diplo_dialog_shell) {
+    intel_diplo_dialog_shell_is_raised = raise;
+    create_intel_diplo_dialog(pplayer, intel_diplo_dialog_shell_is_raised);
+  }
+  xaw_set_relative_position(toplevel, intel_diplo_dialog_shell, 25, 25);
+  XtPopup(intel_diplo_dialog_shell, XtGrabNone);
+  if (intel_diplo_dialog_shell_is_raised) {
+    XtSetSensitive(main_form, FALSE);
+  }
+}
+
+/****************************************************************
+  Close a player's relations dialog.
+*****************************************************************/
+void popdown_intel_diplo_dialog(void)
+{
+  if (intel_diplo_dialog_shell) {
+    if (intel_diplo_dialog_shell_is_raised) {
+      XtSetSensitive(main_form, TRUE);
+    }
+    XtDestroyWidget(intel_diplo_dialog_shell);
+    intel_diplo_dialog_shell = 0;
+  }
+}
+
+/****************************************************************
+  Create a player's relations dialog for the given player.
+*****************************************************************/
+void create_intel_diplo_dialog(struct player *pplayer, bool raise)
+{
+  char buf[64];
+
+  intel_diplo_dialog_shell =
+    I_IN(I_T(XtCreatePopupShell("inteldiplopopup",
+                               raise ? transientShellWidgetClass
+                               : topLevelShellWidgetClass,
+                               toplevel, NULL, 0)));
+
+  intel_diplo_form = XtVaCreateManagedWidget("inteldiploform",
+                                            formWidgetClass,
+                                            intel_diplo_dialog_shell,
+                                            NULL);
+
+  my_snprintf(buf, sizeof(buf),
+             _("Intelligence Diplomacy Information for the %s Empire"),
+             get_nation_name(pplayer->nation));
+
+  intel_diplo_label = I_L(XtVaCreateManagedWidget("inteldiplolabel",
+                                                 labelWidgetClass,
+                                                 intel_diplo_form,
+                                                 XtNlabel, buf,
+                                                 NULL));
+
+   
+  my_snprintf(buf, sizeof(buf), _("Ruler: %s %s"), 
+             get_ruler_title(pplayer->government, pplayer->is_male,
+                             pplayer->nation),
+             pplayer->name);
+  XtVaCreateManagedWidget("inteldiplonamelabel", 
+                         labelWidgetClass, 
+                         intel_diplo_form, 
+                         XtNlabel, buf,
+                         NULL);   
+
+  intel_diplo_list = XtVaCreateManagedWidget("inteldiplolist",
+                                            listWidgetClass,
+                                            intel_diplo_form,
+                                            NULL);
+
+  intel_diplo_close_command =
+    I_L(XtVaCreateManagedWidget("inteldiploclosecommand",
+                               commandWidgetClass,
+                               intel_diplo_form,
+                               NULL));
+
+  XtAddCallback(intel_diplo_close_command, XtNcallback,
+               intel_diplo_close_callback, NULL);
+
+  update_intel_diplo_dialog(pplayer);
+
+  XtRealizeWidget(intel_diplo_dialog_shell);
+  
+  XSetWMProtocols(display, XtWindow(intel_diplo_dialog_shell), 
+                 &wm_delete_window, 1);
+  XtOverrideTranslations(intel_diplo_dialog_shell,
+    XtParseTranslationTable("<Message>WM_PROTOCOLS: msg-close-intel-diplo()"));
+}
+
+/****************************************************************
+  Update a player's relations dialog for the given player.
+*****************************************************************/
+void update_intel_diplo_dialog(struct player *pplayer)
+{
+  int i;
+  Dimension width;
+  static char *namelist_ptrs[MAX_NUM_PLAYERS];
+  static char namelist_text[MAX_NUM_PLAYERS][72];
+  const struct player_diplstate *state;
+
+  if (intel_diplo_dialog_shell) {
+    i = 0;
+    players_iterate(other) {
+      if (other == pplayer) {
+       continue;
+      }
+      state = pplayer_get_diplstate(pplayer, other);
+      my_snprintf(namelist_text[i], sizeof(namelist_text[i]),
+                 "%-32s %-16s %-16s",
+                 other->name,
+                 get_nation_name(other->nation),
+                 diplstate_text(state->type));
+      namelist_ptrs[i] = namelist_text[i];
+      i++;
+    } players_iterate_end;
+
+    XawListChange(intel_diplo_list, namelist_ptrs, i, 0, True);
+
+    XtVaGetValues(intel_diplo_list, XtNwidth, &width, NULL);
+    XtVaSetValues(intel_diplo_label, XtNwidth, width, NULL); 
+  }
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void intel_diplo_close_callback(Widget w, XtPointer client_data,
+                         XtPointer call_data)
+{
+  popdown_intel_diplo_dialog();
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void intel_diplo_dialog_msg_close(Widget w)
+{
+  intel_diplo_close_callback(w, NULL, NULL);
+}
Index: client/gui-xaw/inteldlg.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/inteldlg.h,v
retrieving revision 1.1
diff -u -r1.1 inteldlg.h
--- client/gui-xaw/inteldlg.h   23 Feb 2003 14:11:15 -0000      1.1
+++ client/gui-xaw/inteldlg.h   10 Dec 2004 17:29:46 -0000
@@ -15,6 +15,6 @@
 
 #include "inteldlg_g.h"
 
-/* nothing to add */
+void intel_diplo_dialog_msg_close(Widget w);
 
 #endif                         /* FC__INTELDLG_H */
Index: data/Freeciv.in
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/Freeciv.in,v
retrieving revision 1.4
diff -u -r1.4 Freeciv.in
--- data/Freeciv.in     1 Dec 2004 18:56:53 -0000       1.4
+++ data/Freeciv.in     10 Dec 2004 17:29:49 -0000
@@ -182,18 +182,18 @@
 Freeciv*intelgovlabel.fromHoriz:             intelnamelabel
 Freeciv*intelgovlabel.background:            grey
 
-Freeciv*intelgoldlabel.fromVert:             intelnamelabel
+Freeciv*intelgoldlabel.fromVert:             intelgovlabel
 Freeciv*intelgoldlabel.background:           grey
 
-Freeciv*inteltaxlabel.fromVert:              intelnamelabel
+Freeciv*inteltaxlabel.fromVert:              intelgovlabel
 Freeciv*inteltaxlabel.fromHoriz:             intelgoldlabel
 Freeciv*inteltaxlabel.background:            grey
 
-Freeciv*intelscilabel.fromVert:              intelnamelabel
+Freeciv*intelscilabel.fromVert:              intelgovlabel
 Freeciv*intelscilabel.fromHoriz:             inteltaxlabel
 Freeciv*intelscilabel.background:            grey
 
-Freeciv*intelluxlabel.fromVert:              intelnamelabel
+Freeciv*intelluxlabel.fromVert:              intelgovlabel
 Freeciv*intelluxlabel.fromHoriz:             intelscilabel
 Freeciv*intelluxlabel.background:            grey
 
@@ -212,6 +212,31 @@
 Freeciv*intelclosecommand.label:             _("Close")
 Freeciv*intelclosecommand.fromVert:          inteltechlist
 
+Freeciv*inteldiplocommand.label:             _("Diplomacy")
+Freeciv*inteldiplocommand.fromHoriz:         intelclosecommand
+Freeciv*inteldiplocommand.fromVert:          inteltechlist
+
+
+!
+! inteligence player's relations dialog
+!
+Freeciv*inteldiplopopup.title:                    _("Foreign Intelligence 
Report")
+
+Freeciv*inteldiplolabel.background:         gray84
+Freeciv*inteldiplolabel.borderColor:        gray84
+
+Freeciv*inteldiplonamelabel.fromVert:       inteldiplolabel
+Freeciv*inteldiplonamelabel.background:     grey
+
+Freeciv*inteldiplolist.fromVert:            inteldiplonamelabel
+Freeciv*inteldiplolist.forceColumns:        true
+Freeciv*inteldiplolist.defaultColumns:      1
+Freeciv*inteldiplolist.verticalList:        true
+Freeciv*inteldiplolist.resizable:           true
+
+Freeciv*inteldiploclosecommand.label:             _("Close")
+Freeciv*inteldiploclosecommand.fromVert:          inteldiplolist
+
 
 !
 ! tile info popup dialog

[Prev in Thread] Current Thread [Next in Thread]