Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2003:
[Freeciv-Dev] Re: (PR#3736) Pregame player list
Home

[Freeciv-Dev] Re: (PR#3736) Pregame player list

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] Re: (PR#3736) Pregame player list
From: "andrearo@xxxxxxxxxxxx" <andrearo@xxxxxxxxxxxx>
Date: Thu, 15 May 2003 16:07:33 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Sorry, I found the solution to the gtk1.2 reparenting bug I talked about 
earlied, more info here:
http://mail.gnome.org/archives/gtk-list/1999-July/msg00453.html
I've corrected the patch accordingly.

Andreas Røsdal




--- freeciv-cvs-May-14/client/gui-gtk/gui_main.c        2003-05-04 
06:57:50.000000000 +0200
+++ freeciv-changed/client/gui-gtk/gui_main.c   2003-05-16 00:58:39.000000000 
+0200
@@ -103,6 +103,9 @@
 GtkWidget *main_frame_civ_name;
 GtkWidget *main_label_info;
 
+GtkWidget *avbox, *ahbox, *vbox, *conn_box;
+GtkWidget* conn_list;
+
 GtkWidget *econ_label[10];
 GtkWidget *bulb_label;
 GtkWidget *sun_label;
@@ -151,6 +154,8 @@
 
 static void select_unit_pixmap_callback(GtkWidget *w, GdkEvent *ev, 
                                         gpointer data);
+static gboolean show_conn_popup(GtkWidget *list, 
+                               GdkEventButton *event, gpointer data);
 static gint timer_callback(gpointer data);
 
 /**************************************************************************
@@ -241,6 +246,18 @@
       gtk_signal_emit_stop_by_name(GTK_OBJECT(w), "key_press_event");
 
     return keypress;
+  } 
+
+  /* connected users list */ 
+  if (GTK_CLIST_CHILD_HAS_FOCUS(conn_list)){
+    if (ev->keyval == GDK_Up && (GTK_CLIST(conn_list)->selection)) {    
+      gint row = (gint)(GTK_CLIST(conn_list)->selection->data);
+      gtk_clist_select_row(GTK_CLIST(conn_list),row-1,0);
+    }
+    if (ev->keyval == GDK_Down && (GTK_CLIST(conn_list)->selection)) {
+      gint row = (gint)(GTK_CLIST(conn_list)->selection->data);
+      gtk_clist_select_row(GTK_CLIST(conn_list),row+1,0);
+    }
   }
 
   if (!client_is_observer()) {
@@ -357,7 +374,11 @@
   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(p), FALSE);
 
   p = gtk_object_get_user_data(GTK_OBJECT(w));
-  gtk_widget_reparent(box, p);
+
+  gtk_object_ref(GTK_OBJECT(box));
+  gtk_container_remove(GTK_CONTAINER(box->parent), box);
+  gtk_container_add(GTK_CONTAINER(p), box);
+  gtk_object_unref(GTK_OBJECT(box));
   return TRUE;
 }
 
@@ -520,8 +541,7 @@
 **************************************************************************/
 static void setup_widgets(void)
 {
-  GtkWidget *box, *ebox, *hbox, *vbox;
-  GtkWidget *avbox, *ahbox;
+  GtkWidget *box, *ebox, *hbox, *vbox, *sbox, *label, *sw;
   GtkWidget *frame, *table, *paned, *menubar, *text;
   GtkStyle  *text_style, *style;
   int i;
@@ -557,7 +577,7 @@
                                       | GDK_BUTTON_PRESS_MASK );
 
   gtk_drawing_area_size(GTK_DRAWING_AREA(overview_canvas), 160, 100);
-  gtk_box_pack_start(GTK_BOX(avbox), overview_canvas, FALSE, FALSE, 0);
+  gtk_box_pack_start(GTK_BOX(avbox), overview_canvas, FALSE, TRUE, 0);
 
   gtk_signal_connect(GTK_OBJECT(overview_canvas), "expose_event",
                      (GtkSignalFunc) overview_canvas_expose, NULL);
@@ -565,6 +585,32 @@
   gtk_signal_connect(GTK_OBJECT(overview_canvas), "button_press_event",
                      (GtkSignalFunc) butt_down_overviewcanvas, NULL);
 
+  /* prepare list of connected users in the pregame state. */
+  conn_list = gtk_clist_new(1);
+  gtk_clist_set_column_auto_resize (GTK_CLIST(conn_list), 1, TRUE);
+  gtk_clist_set_column_width(GTK_CLIST(conn_list), 0,
+                            GTK_CLIST(conn_list)->clist_window_width);
+
+  /* display the list of connected users. */
+  conn_box = gtk_vbox_new(FALSE, 2);
+  label=gtk_widget_new(GTK_TYPE_LABEL,
+                      "GtkLabel::label", _("Connected Users:"),
+                      "GtkWidget::visible", TRUE,
+                      "xalign", 0.0, "yalign", 0.5, 
+                      NULL);
+  sw = gtk_scrolled_window_new(NULL,NULL);
+  gtk_widget_set_usize(sw, 160, 300);
+
+  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
+                                GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
+  gtk_container_add(GTK_CONTAINER(sw), conn_list);
+  gtk_box_pack_start(GTK_BOX(conn_box), label, FALSE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(conn_box), sw, TRUE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(avbox), conn_box, TRUE, TRUE, 0);
+
+  gtk_signal_connect(GTK_OBJECT(conn_list), "button-press-event",
+                    GTK_SIGNAL_FUNC(show_conn_popup), NULL);
+
   /* The Rest */
 
   ahbox = detached_widget_new();
@@ -732,9 +778,9 @@
 
   /* *** The message window -- this is a detachable widget *** */
 
-  ahbox = detached_widget_new();
-  gtk_paned_pack2(GTK_PANED(paned), ahbox, TRUE, TRUE);
-  avbox = detached_widget_fill(ahbox);
+  sbox = detached_widget_new();
+  gtk_paned_pack2(GTK_PANED(paned), sbox, TRUE, TRUE);
+  avbox = detached_widget_fill(sbox);
 
   hbox = gtk_hbox_new(FALSE, 0);
   gtk_box_pack_start(GTK_BOX(avbox), hbox, TRUE, TRUE, 0);
@@ -780,6 +826,7 @@
     gtk_widget_hide(map_horizontal_scrollbar);
     gtk_widget_hide(map_vertical_scrollbar);
   }
+  gtk_widget_hide(ahbox);  /* Hide info on player's civ in pregame */
 }
 
 /**************************************************************************
@@ -960,7 +1007,77 @@
 ***************************************************************************/
 void update_conn_list_dialog(void)
 {
-  /* PORTME */
+  gchar *row[1];
+  if (get_client_state() != CLIENT_GAME_RUNNING_STATE) {
+    gtk_clist_freeze(GTK_CLIST(conn_list));
+    gtk_clist_clear(GTK_CLIST(conn_list));
+    conn_list_iterate(game.est_connections, pconn)
+      row[0] = pconn->username;
+      gtk_clist_append(GTK_CLIST(conn_list), row);
+    conn_list_iterate_end;
+    gtk_clist_thaw(GTK_CLIST(conn_list));
+    gtk_widget_hide(ahbox);
+    gtk_widget_show(conn_box);
+  } else {
+    gtk_widget_hide(conn_box);
+    gtk_widget_show(ahbox);
+  } 
+}
+
+/**************************************************************************
+ Show details about a user in the Connected Users dialog in a popup
+**************************************************************************/
+static gboolean show_conn_popup(GtkWidget *list, GdkEventButton *ev,
+                               gpointer data)
+{
+  GtkWidget *popup, *table, *label;
+  gchar *name;
+  struct connection *pconn;
+  gint row;
+
+  /* Get the current selection in the Connected Users list */
+  if (!gtk_clist_get_selection_info(GTK_CLIST(conn_list),
+                                   ev->x, ev->y, &row ,NULL)) {
+    return FALSE;
+  }
+  gtk_clist_select_row(GTK_CLIST(conn_list), row, 0);
+  gtk_clist_get_text(GTK_CLIST(conn_list), row, 0, &name); 
+  pconn = find_conn_by_user(name);
+  ev->button=3; 
+
+  /* Show popup. */
+  popup = gtk_window_new(GTK_WINDOW_POPUP);
+  gtk_widget_set_app_paintable(popup, TRUE);
+  gtk_container_set_border_width(GTK_CONTAINER(popup), 4);
+  gtk_window_set_position(GTK_WINDOW(popup), GTK_WIN_POS_MOUSE);
+
+  table = gtk_table_new(2, 2, FALSE);
+  gtk_table_set_col_spacings(GTK_TABLE(table), 6);
+  gtk_container_add(GTK_CONTAINER(popup), table);
+
+  label = gtk_label_new(_("Name:"));
+  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+  gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
+  label = gtk_label_new(pconn->username);
+  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+  gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 0, 1);
+
+  label = gtk_label_new(_("Host:"));
+  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+  gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
+  label = gtk_label_new(pconn->addr);
+  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+  gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 1, 2);
+
+  gtk_widget_show_all(table);
+  gtk_widget_show(popup);
+
+  gdk_pointer_grab(popup->window, TRUE, GDK_BUTTON_RELEASE_MASK,
+                  NULL, NULL, ev->time);
+  gtk_grab_add(popup);
+  gtk_signal_connect_after(GTK_OBJECT(popup), "button_release_event",
+                        GTK_SIGNAL_FUNC(show_info_button_release), NULL);
+  return FALSE;
 }
 
 /**************************************************************************

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