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: Mon, 5 May 2003 11:18:04 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Vasco Alexandre da Silva Costa wrote:

>[andrearo@xxxxxxxxxxxx - Thu Apr 24 16:37:29 2003]:
>
>I changed the popup to have more decent padding and did some minor
>cleanups. This means the GTK+ 1.2 piece needs changing and I didn't make
>the changes to it yet. Please feel free to do so. :-)
>
I think this gtk1.2 part is ready. The vertical scrollbar will never be 
hidden, since gtk 1.2 doesn't support reparenting hidden widgets. Other 
than that, the list behaves exactly like in gtk2.

Andreas Røsdal

diff -Nur -Xfreeciv-changed/diff_ignore 
freeciv-cvs-May-03/client/gui-gtk/gui_main.c 
freeciv-changed/client/gui-gtk/gui_main.c
--- freeciv-cvs-May-03/client/gui-gtk/gui_main.c        2003-05-04 
06:57:50.000000000 +0200
+++ freeciv-changed/client/gui-gtk/gui_main.c   2003-05-05 19:46:39.000000000 
+0200
@@ -103,6 +103,9 @@
 GtkWidget *main_frame_civ_name;
 GtkWidget *main_label_info;
 
+GtkWidget *avbox, *ahbox, *vbox, *conn_box;
+GtkWidget *users_list, *conn_scroll;
+
 GtkWidget *econ_label[10];
 GtkWidget *bulb_label;
 GtkWidget *sun_label;
@@ -151,6 +154,10 @@
 
 static void select_unit_pixmap_callback(GtkWidget *w, GdkEvent *ev, 
                                         gpointer data);
+static gboolean show_conn_popup(GtkWidget *view, 
+                       GdkEventButton *event, gpointer data);
+static void conn_scroll_callback(GtkWidget *view, 
+                       GdkEventButton *event, gpointer data);
 static gint timer_callback(gpointer data);
 
 /**************************************************************************
@@ -520,10 +527,10 @@
 **************************************************************************/
 static void setup_widgets(void)
 {
-  GtkWidget *box, *ebox, *hbox, *vbox;
-  GtkWidget *avbox, *ahbox;
+  GtkWidget *box, *ebox, *hbox, *vbox, *sbox, *label, *cvbox;
   GtkWidget *frame, *table, *paned, *menubar, *text;
   GtkStyle  *text_style, *style;
+  GtkAdjustment *adj;
   int i;
 
   /* the window is divided into two panes. "top" and "message window" */ 
@@ -557,7 +564,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 +572,38 @@
   gtk_signal_connect(GTK_OBJECT(overview_canvas), "button_press_event",
                      (GtkSignalFunc) butt_down_overviewcanvas, NULL);
 
+  /* prepare list of connected users in the pregame state. */
+  users_list = gtk_clist_new(1);
+  gtk_clist_set_column_auto_resize (GTK_CLIST(users_list), 1, TRUE);
+  gtk_clist_set_column_width(GTK_CLIST(users_list), 0,
+       GTK_CLIST(users_list)->clist_window_width);
+  conn_box = gtk_vbox_new(FALSE, 2);
+  cvbox = gtk_hbox_new(FALSE, 2);
+  label=gtk_widget_new(GTK_TYPE_LABEL,
+                       "GtkLabel::label", _("Connected Users:"),
+                       "GtkWidget::visible", TRUE,
+                       "xalign", 0.0, "yalign", 0.5, 
+                       NULL);
+
+  /* create a vertial scrollbar for the list of connected users. */
+  gtk_widget_set_usize(conn_box, 160, 300);
+  adj = GTK_ADJUSTMENT(gtk_adjustment_new(1,1,10,1,10,10));
+  gtk_clist_set_vadjustment(GTK_CLIST(users_list), GTK_ADJUSTMENT(adj));
+  conn_scroll = gtk_vscrollbar_new(NULL);
+  gtk_object_set(GTK_OBJECT(conn_scroll), "adjustment", adj, NULL);
+
+  /* display the list of connected users. */
+  gtk_box_pack_start(GTK_BOX(cvbox), users_list, TRUE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(cvbox), conn_scroll, FALSE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(conn_box), label, FALSE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(conn_box), cvbox, TRUE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(avbox), conn_box, TRUE, TRUE, 0);
+
+  gtk_signal_connect(GTK_OBJECT(conn_scroll), "button-press-event",
+                     GTK_SIGNAL_FUNC(conn_scroll_callback), NULL);
+  gtk_signal_connect(GTK_OBJECT(users_list), "button-press-event",
+                     GTK_SIGNAL_FUNC(show_conn_popup), NULL);
+
   /* The Rest */
 
   ahbox = detached_widget_new();
@@ -732,9 +771,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 +819,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 +1000,91 @@
 ***************************************************************************/
 void update_conn_list_dialog(void)
 {
-  /* PORTME */
+  gchar *row[1];
+  GtkAdjustment *adj;
+  if (get_client_state() != CLIENT_GAME_RUNNING_STATE) {
+    gtk_clist_freeze(GTK_CLIST(users_list));
+    gtk_clist_clear(GTK_CLIST(users_list));
+    conn_list_iterate(game.est_connections, pconn)
+      row[0] = pconn->username;
+      gtk_clist_append(GTK_CLIST(users_list), row);
+    conn_list_iterate_end;
+    gtk_clist_thaw(GTK_CLIST(users_list));
+    gtk_widget_hide(ahbox);
+    gtk_widget_show(conn_box);
+    adj = gtk_clist_get_vadjustment(GTK_CLIST(users_list));
+    gtk_object_set(GTK_OBJECT(conn_scroll), "adjustment", adj, NULL);
+  } 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 *view, 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(users_list),
+                                   ev->x, ev->y, &row ,NULL)) {
+    return FALSE;
+  }
+  gtk_clist_select_row(GTK_CLIST(users_list), row, 0);
+  gtk_clist_get_text(GTK_CLIST(users_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;
+}
+
+/**************************************************************************
+ Callback for scrollbar to Connected Users List
+**************************************************************************/
+static void conn_scroll_callback(GtkWidget *view, GdkEventButton *ev,
+                               gpointer data)
+{
+  GtkAdjustment *adj;
+  gtk_object_get(GTK_OBJECT(conn_scroll), "adjustment", &adj, NULL);
+  gtk_clist_moveto(GTK_CLIST(users_list),adj->value,0,0,0);
 }
 
 /**************************************************************************

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