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

[Freeciv-Dev] (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] (PR#3736) Pregame player list
From: "andrearo@xxxxxxxxxxxx" <andrearo@xxxxxxxxxxxx>
Date: Sun, 16 Mar 2003 02:18:19 -0800
Reply-to: rt@xxxxxxxxxxxxxx

I'm trying to improve the usability of the "pregame state",
by adding a list of the currently connected players to the
client window. Currently, there is no way of knowing who
is connected without using the list command. This list is
always up-to-date when in pregame state, and is replaced
by the regular civilization info when the game starts.

The list could be extended to allow players to use it
to send messages to each other, assign teams etc.
It's for gtk-2.0, but I'd be happy to port it to gtk-1.0.

As far as I could tell, the current send_conn_info() doesn't
send conn_info packets to all the connected clients. For this
patch to work, I had to change it to send conn_info packets
to all the connections when in pregame state.

A small screenshot can be found here:
ftp://www.freeciv.org/freeciv/incoming/pregame.jpg

Andreas Røsdal


diff -Nur -Xfreeciv/diff_ignore freeciv-cvs-Mar/client/gui-gtk-2.0/gui_main.c 
freeciv/client/gui-gtk-2.0/gui_main.c
--- freeciv-cvs-Mar/client/gui-gtk-2.0/gui_main.c       2003-03-16 
10:33:49.000000000 +0100
+++ freeciv/client/gui-gtk-2.0/gui_main.c       2003-03-16 10:30:36.000000000 
+0100
@@ -103,6 +103,16 @@
 
 GtkWidget *main_frame_civ_name;
 GtkWidget *main_label_info;
+static GtkWidget *avbox, *ahbox, *vbox;
+
+static GtkListStore *con_list_model;       
+static GtkWidget *con_list_view;           
+static GtkCellRenderer *con_list_prenderer; 
+static GtkCellRenderer *con_list_trenderer;
+static GtkTreeViewColumn *con_list_column; 
+static GtkTreeIter con_list_iter;
+static GtkWidget* scroll_list;
+static GdkPixbuf *playerpix;
 
 GtkWidget *econ_label[10];
 GtkWidget *bulb_label;
@@ -139,7 +149,8 @@
 static void get_net_input(gpointer data, gint fid, GdkInputCondition 
condition);
 static void set_wait_for_writable_socket(struct connection *pc,
                                          bool socket_writable);
-
+void update_con_list(void);
+void hide_con_list(void);
 static void print_usage(const char *argv0);
 static void parse_options(int argc, char **argv);
 static gboolean keyboard_handler(GtkWidget *w, GdkEventKey *ev, gpointer data);
@@ -621,12 +632,14 @@
 **************************************************************************/
 static void setup_widgets(void)
 {
-  GtkWidget *box, *ebox, *hbox, *vbox;
-  GtkWidget *avbox, *ahbox;
+  GtkWidget *box, *ebox, *hbox, *sbox;
   GtkWidget *frame, *table, *paned, *menubar, *sw, *text;
   GtkStyle *style;
   int i;
   struct Sprite *sprite;
+  static char *con_list_titles[2] = { (NULL), N_("Connected Players:") };
+  static GType con_list_types[2] = { G_TYPE_NONE, G_TYPE_STRING };
+      
 
   /* the window is divided into two panes. "top" and "message window" */ 
   paned = gtk_vpaned_new();
@@ -667,13 +680,40 @@
   g_signal_connect(overview_canvas, "button_press_event",
                   G_CALLBACK(butt_down_overviewcanvas), NULL);
 
+  /* Create Model/View/Controller for Connected Players. */
+  con_list_types[0] = GDK_TYPE_PIXBUF;
+  con_list_model = gtk_list_store_newv(2, con_list_types); 
+  con_list_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(con_list_model));
+  
+  /*  Add the image column. */
+  con_list_prenderer = gtk_cell_renderer_pixbuf_new();
+  con_list_column = 
gtk_tree_view_column_new_with_attributes(con_list_titles[0], 
+                 con_list_prenderer, "pixbuf", 0, NULL);
+  gtk_tree_view_append_column(GTK_TREE_VIEW(con_list_view), con_list_column);  
+
+  /*  Add the player name column.  */
+  con_list_trenderer = gtk_cell_renderer_text_new();
+  con_list_column = 
gtk_tree_view_column_new_with_attributes(con_list_titles[1], 
+                 con_list_trenderer, "text", 1,  NULL);
+  gtk_tree_view_append_column(GTK_TREE_VIEW(con_list_view), con_list_column);
+  g_object_set(con_list_trenderer, "weight", "bold", NULL);
+  gtk_list_store_append(con_list_model, &con_list_iter);
+  
+  /* Display the list. */
+  scroll_list = gtk_scrolled_window_new(NULL,NULL);
+  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_list),
+                 GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
+  gtk_container_add(GTK_CONTAINER(avbox), scroll_list);
+  gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll_list), 
+                 con_list_view);
+  
   /* The Rest */
 
   ahbox = detached_widget_new();
   gtk_container_add(GTK_CONTAINER(vbox), ahbox);
   avbox = detached_widget_fill(ahbox);
 
-  /* Info on player's civilization */
+  /* Info on player's civilization, displayed when game is running. */
   frame = gtk_frame_new(NULL);
   gtk_box_pack_start(GTK_BOX(avbox), frame, FALSE, FALSE, 0);
 
@@ -843,9 +883,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);
 
   frame = gtk_frame_new(NULL);
   gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
@@ -896,9 +936,69 @@
     gtk_widget_hide(map_horizontal_scrollbar);
     gtk_widget_hide(map_vertical_scrollbar);
   }
+  gtk_widget_hide(ahbox);  /* Hide info on player's civilization */
 }
 
 /**************************************************************************
+ Update the list model of connections in the pregame state.
+**************************************************************************/
+void update_con_list(void)
+{
+  struct Sprite *sprite;
+  int x0, y0, x1, y1, w, h, playerpix_iter=0;
+  gtk_list_store_clear(con_list_model);
+  conn_list_iterate(game.est_connections, pconn)
+    if (playerpix_iter==5) {
+      playerpix_iter=0;
+    }
+    playerpix_iter++;
+    /* selects a image for each connected player  */
+    switch (playerpix_iter) {
+    case 2: 
+      sprite = get_citizen_sprite(CITIZEN_SCIENTIST, 0, NULL);
+      break;
+    case 3: 
+      sprite = get_citizen_sprite(CITIZEN_ELVIS, 0, NULL);
+      break;
+    case 4: 
+      sprite = get_citizen_sprite(CITIZEN_HAPPY, 0, NULL);
+      break;       
+    case 5: sprite = get_citizen_sprite(CITIZEN_CONTENT, 0, NULL);
+      break;
+    default:
+      sprite = get_citizen_sprite(CITIZEN_TAXMAN, 0, NULL);
+      break;
+    }
+    sprite_get_bounding_box(sprite, &x0, &y0, &x1, &y1);
+    w = (x1 - x0) + 1;
+    h = (y1 - y0) + 1;
+    playerpix = gdk_pixbuf_get_from_drawable(NULL,
+                  sprite->pixmap,
+                  gdk_colormap_get_system(),
+                   x0, y0,
+                  0, 0,
+                   w, h);
+    gtk_list_store_append(con_list_model, &con_list_iter);
+    gtk_list_store_set(con_list_model, &con_list_iter,
+                    0, playerpix,
+                    1, pconn->name,      -1);
+  conn_list_iterate_end;
+  /* Show view for connected players, hide info about civ. */
+  gtk_widget_hide(ahbox);   
+  gtk_widget_show(scroll_list);
+}
+
+/**************************************************************************
+  Hide the view for connected players when the game starts.
+**************************************************************************/
+void hide_con_list(void)
+{
+  gtk_widget_hide(scroll_list);
+  gtk_widget_show(ahbox);
+}
+
+
+/**************************************************************************
  called from main().
 **************************************************************************/
 void ui_init(void)
@@ -1285,6 +1385,9 @@
 **************************************************************************/
 void remove_net_input(void)
 {
+  conn_list_init(&game.all_connections);
+  conn_list_init(&game.est_connections);
+  conn_list_init(&game.game_connections);
   gdk_input_remove(gdk_input_id);
   gdk_window_set_cursor(root_window, NULL);
 }
diff -Nur -Xfreeciv/diff_ignore freeciv-cvs-Mar/client/gui-gtk-2.0/plrdlg.c 
freeciv/client/gui-gtk-2.0/plrdlg.c
--- freeciv-cvs-Mar/client/gui-gtk-2.0/plrdlg.c 2003-03-16 10:33:49.000000000 
+0100
+++ freeciv/client/gui-gtk-2.0/plrdlg.c 2003-03-16 10:19:52.000000000 +0100
@@ -56,6 +56,8 @@
 
 static GdkPixbuf *flags[MAX_NUM_NATIONS];
 
+void update_con_list(void);
+void hide_con_list(void);
 static void create_players_dialog(void);
 static void players_meet_callback(GtkMenuItem *item, gpointer data);
 static void players_war_callback(GtkMenuItem *item, gpointer data);
@@ -551,6 +553,13 @@
         build_row(&iter, i);
       }
     }
+  } else {
+    /* update list of connected players in gui_main.c */
+    if(get_client_state() != CLIENT_GAME_RUNNING_STATE) {
+      update_con_list();       
+    } else {
+      hide_con_list();
+    }
   }
 }
 
diff -Nur -Xfreeciv/diff_ignore freeciv-cvs-Mar/server/srv_main.c 
freeciv/server/srv_main.c
--- freeciv-cvs-Mar/server/srv_main.c   2003-03-16 10:33:50.000000000 +0100
+++ freeciv/server/srv_main.c   2003-03-16 10:20:48.000000000 +0100
@@ -1125,7 +1125,11 @@
   conn_list_insert_back(&game.est_connections, pconn);
   conn_list_insert_back(&game.game_connections, pconn);
 
-  send_conn_info(&pconn->self, &game.est_connections);
+  if(server_state==PRE_GAME_STATE) {
+    send_conn_info(&game.est_connections, &game.est_connections);
+  } else {
+    send_conn_info(&pconn->self, &game.est_connections);
+  }
 
   freelog(LOG_NORMAL, _("%s has joined as player %s."),
          pconn->name, pplayer->name);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#3736) Pregame player list, andrearo@xxxxxxxxxxxx <=