Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] (PR#13151) put all players in client pregame list
Home

[Freeciv-Dev] (PR#13151) put all players in client pregame list

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13151) put all players in client pregame list
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 24 May 2005 09:18:04 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Here's an updated version of the patch.  With the other fixes and
changes from a few days ago it now works rather well.

-jason

Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.125
diff -u -r1.125 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       22 May 2005 18:12:53 -0000      1.125
+++ client/gui-gtk-2.0/gui_main.c       24 May 2005 16:16:46 -0000
@@ -1225,29 +1225,53 @@
   GtkTreeIter it;
   
   if (get_client_state() != CLIENT_GAME_RUNNING_STATE) {
-    gtk_list_store_clear(conn_model);
-    conn_list_iterate(game.est_connections, pconn) {
-      bool is_started = pconn->player ? pconn->player->is_started : FALSE;
-      const char *nation;
-      const char *leader;
+    bool is_started;
+    const char *name, *nation, *leader;
 
-      if (!pconn->player) {
-       nation = "";
-       leader = "";
-      } else if (pconn->player->nation == NO_NATION_SELECTED) {
+    gtk_list_store_clear(conn_model);
+    players_iterate(pplayer) {
+      if (pplayer->is_observer) {
+       continue; /* Connections are listed individually. */
+      }
+      if (pplayer->ai.control) {
+       name = _("<AI>");
+      } else {
+       name = pplayer->username;
+      }
+      is_started = pplayer->ai.control ? TRUE: pplayer->is_started;
+      if (pplayer->nation == NO_NATION_SELECTED) {
        nation = _("Random");
        leader = "";
       } else {
-       nation = get_nation_name(pconn->player->nation);
-       leader = pconn->player->name;
+       nation = get_nation_name(pplayer->nation);
+       leader = pplayer->name;
       }
 
       gtk_list_store_append(conn_model, &it);
       gtk_list_store_set(conn_model, &it,
-                        0, pconn->username,
+                        0, name,
                         1, is_started,
                         2, leader,
                         3, nation,
+                        4, pplayer->player_no,
+                        -1);
+    } players_iterate_end;
+    conn_list_iterate(game.est_connections, pconn) {
+      if (pconn->player && !pconn->observer && !pconn->player->is_observer) {
+       continue; /* Already listed above. */
+      }
+      name = pconn->username;
+      is_started = FALSE;
+      nation = "";
+      leader = "";
+
+      gtk_list_store_append(conn_model, &it);
+      gtk_list_store_set(conn_model, &it,
+                        0, name,
+                        1, is_started,
+                        2, leader,
+                        3, nation,
+                        4, -1,
                         -1);
     } conn_list_iterate_end;
   }
@@ -1276,6 +1300,10 @@
   gtk_tree_model_get(GTK_TREE_MODEL(conn_model), &it, 0, &name, -1);
   pconn = find_conn_by_user(name);
 
+  if (!pconn) {
+    return FALSE;
+  }
+
   /* Show popup. */
   popup = gtk_window_new(GTK_WINDOW_POPUP);
   gtk_widget_set_app_paintable(popup, TRUE);
Index: client/gui-gtk-2.0/pages.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/pages.c,v
retrieving revision 1.29
diff -u -r1.29 pages.c
--- client/gui-gtk-2.0/pages.c  22 May 2005 18:05:06 -0000      1.29
+++ client/gui-gtk-2.0/pages.c  24 May 2005 16:16:46 -0000
@@ -959,7 +959,7 @@
   GtkTreeIter iter;
   GtkTreePath *path = NULL;
   GtkTreeViewColumn *column = NULL;
-  char *username;
+  int player_no;
   struct player *pplayer;
 
   if (event->type != GDK_BUTTON_PRESS
@@ -975,15 +975,9 @@
 
   gtk_tree_model_get_iter(model, &iter, path);
   gtk_tree_path_free(path);
-  gtk_tree_model_get(model, &iter, 0, &username, -1);
-#if 0
-  /* This doesn't work because game.info.nplayers is 0 for some reason. */
-  pplayer = find_player_by_user(username);
-#else
-  pplayer = find_conn_by_user(username)->player;
-#endif
+  gtk_tree_model_get(model, &iter, 4, &player_no, -1);
+  pplayer = get_player(player_no);
   if (!pplayer) {
-    freelog(LOG_NORMAL, "No player for '%s'.", username);
     return FALSE;
   }
 
@@ -1090,8 +1084,8 @@
   gtk_box_pack_start(GTK_BOX(vbox), align, FALSE, FALSE, 8);
 
 
-  conn_model = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_BOOLEAN,
-                                 G_TYPE_STRING, G_TYPE_STRING);
+  conn_model = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
+                                 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
 
   view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(conn_model));
   g_object_unref(conn_model);

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