Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2005:
[Freeciv-Dev] (PR#13208) GUI interface for configuring teams
Home

[Freeciv-Dev] (PR#13208) GUI interface for configuring teams

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13208) GUI interface for configuring teams
From: "Jason Dorje Short" <jdorje@xxxxxxxxx>
Date: Fri, 3 Jun 2005 10:46:08 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch adds a GUI interface for the GTK client that allows
configuring teams.

-jason

? diff
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.127
diff -u -r1.127 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       1 Jun 2005 01:02:33 -0000       1.127
+++ client/gui-gtk-2.0/gui_main.c       3 Jun 2005 17:45:02 -0000
@@ -1249,7 +1249,7 @@
   
   if (get_client_state() != CLIENT_GAME_RUNNING_STATE) {
     bool is_ready;
-    const char *name, *nation, *leader;
+    const char *name, *nation, *leader, *team;
 
     gtk_list_store_clear(conn_model);
     players_iterate(pplayer) {
@@ -1269,14 +1269,16 @@
        nation = get_nation_name(pplayer->nation);
        leader = pplayer->name;
       }
+      team = pplayer->team ? _(pplayer->team->name) : "";
 
       gtk_list_store_append(conn_model, &it);
       gtk_list_store_set(conn_model, &it,
-                        0, name,
-                        1, is_ready,
-                        2, leader,
-                        3, nation,
-                        4, pplayer->player_no,
+                        0, pplayer->player_no,
+                        1, name,
+                        2, is_ready,
+                        3, leader,
+                        4, nation,
+                        5, team,
                         -1);
     } players_iterate_end;
     conn_list_iterate(game.est_connections, pconn) {
@@ -1287,14 +1289,16 @@
       is_ready = FALSE;
       nation = "";
       leader = "";
+      team = "";
 
       gtk_list_store_append(conn_model, &it);
       gtk_list_store_set(conn_model, &it,
-                        0, name,
-                        1, is_ready,
-                        2, leader,
-                        3, nation,
-                        4, -1,
+                        0, -1,
+                        1, name,
+                        2, is_ready,
+                        3, leader,
+                        4, nation,
+                        5, team,
                         -1);
     } conn_list_iterate_end;
   }
@@ -1320,7 +1324,7 @@
   gtk_tree_model_get_iter(GTK_TREE_MODEL(conn_model), &it, path);
   gtk_tree_path_free(path);
 
-  gtk_tree_model_get(GTK_TREE_MODEL(conn_model), &it, 0, &name, -1);
+  gtk_tree_model_get(GTK_TREE_MODEL(conn_model), &it, 1, &name, -1);
   pconn = find_conn_by_user(name);
 
   if (!pconn) {
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.32
diff -u -r1.32 pages.c
--- client/gui-gtk-2.0/pages.c  3 Jun 2005 16:46:16 -0000       1.32
+++ client/gui-gtk-2.0/pages.c  3 Jun 2005 17:45:03 -0000
@@ -49,7 +49,7 @@
 GtkWidget *start_message_area;
 
 GtkListStore *conn_model;
-static GtkTreeViewColumn *nation_col, *ready_col;
+static GtkTreeViewColumn *nation_col, *ready_col, *team_col;
 
 static GtkWidget *start_options_table;
 GtkWidget *ready_button;
@@ -950,6 +950,63 @@
   gtk_spin_button_set_value(GTK_SPIN_BUTTON(start_aifill_spin), 5);
 }
 
+static struct player *team_menu_player;
+
+/****************************************************************************
+  Callback for when a team is chosen from the team menu.
+****************************************************************************/
+static void team_menu_entry_chosen(GtkMenuItem *menuitem, gpointer data)
+{
+  struct team *pteam = data;
+  char buf[1024];
+
+  if (pteam != team_menu_player->team) {
+    my_snprintf(buf, sizeof(buf), "/team \"%s\" \"%s\"",
+               team_menu_player->name, pteam->name);
+    send_chat(buf);
+  }
+}
+
+/****************************************************************************
+  Called when you click on a player's team; this function pops up a menu
+  to allow changing the team.
+****************************************************************************/
+static GtkWidget *create_team_menu(struct player *pplayer)
+{
+  GtkWidget *menu;
+  GtkWidget *entry;
+  const int count = pplayer->team ? pplayer->team->players : 0;
+  bool need_empty_team = (count != 1);
+  int index;
+
+  menu = gtk_menu_new();
+
+  /* Can't use team_iterate here since it skips empty teams. */
+  for (index = 0; index < MAX_NUM_TEAMS; index++) {
+    struct team *pteam = team_get_by_id(index);
+
+    if (pteam->players == 0) {
+      if (!need_empty_team) {
+       continue;
+      }
+      need_empty_team = FALSE;
+    }
+
+    entry = gtk_menu_item_new_with_label(_(pteam->name));
+    g_object_set_data_full(G_OBJECT(menu), pteam->name, entry,
+                          (GtkDestroyNotify) gtk_widget_unref);
+    gtk_widget_show(entry);
+    gtk_container_add(GTK_CONTAINER(menu), entry);
+    g_signal_connect(GTK_OBJECT(entry), "activate",
+                    GTK_SIGNAL_FUNC(team_menu_entry_chosen),
+                    pteam);
+  }
+
+  team_menu_player = pplayer;
+
+  return menu;
+}
+
 /**************************************************************************
   Called on a button event on the pregame player list.
 **************************************************************************/
@@ -973,7 +1030,7 @@
 
   gtk_tree_model_get_iter(model, &iter, path);
   gtk_tree_path_free(path);
-  gtk_tree_model_get(model, &iter, 4, &player_no, -1);
+  gtk_tree_model_get(model, &iter, 0, &player_no, -1);
   pplayer = get_player(player_no);
 
   if (column == nation_col) {
@@ -990,9 +1047,18 @@
       return FALSE;
     }
 
-    gtk_tree_model_get(model, &iter, 1, &is_ready, -1);
+    gtk_tree_model_get(model, &iter, 2, &is_ready, -1);
     dsend_packet_player_ready(&aconnection, pplayer->player_no, !is_ready);
     return TRUE;
+  } else if (column == team_col) {
+    if (pplayer) {
+      GtkWidget *menu = create_team_menu(pplayer);
+
+      gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
+                    event->button, 0);
+      return TRUE;
+    }
+    return FALSE;
   } else {
     return show_conn_popup(widget, event, data);
   }
@@ -1097,8 +1163,10 @@
   gtk_box_pack_start(GTK_BOX(vbox), align, FALSE, FALSE, 8);
 
 
-  conn_model = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
-                                 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
+  conn_model = gtk_list_store_new(6, G_TYPE_INT,
+                                 G_TYPE_STRING, G_TYPE_BOOLEAN,
+                                 G_TYPE_STRING, G_TYPE_STRING,
+                                 G_TYPE_STRING);
 
   view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(conn_model));
   g_object_unref(conn_model);
@@ -1107,26 +1175,32 @@
   rend = gtk_cell_renderer_text_new();
   gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
                                              -1, _("Name"), rend,
-                                             "text", 0, NULL);
+                                             "text", 1, NULL);
 
   /* FIXME: should change to always be minimum-width. */
   rend = gtk_cell_renderer_toggle_new();
   ready_col = gtk_tree_view_column_new_with_attributes(_("Ready"),
                                                       rend,
-                                                      "active", 1, NULL);
+                                                      "active", 2, NULL);
   gtk_tree_view_insert_column(GTK_TREE_VIEW(view), ready_col, -1);
 
   rend = gtk_cell_renderer_text_new();
   gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
                                              -1, _("Leader"), rend,
-                                             "text", 2, NULL);
+                                             "text", 3, NULL);
 
   rend = gtk_cell_renderer_text_new();
   nation_col = gtk_tree_view_column_new_with_attributes(_("Nation"),
                                                        rend,
-                                                       "text", 3, NULL);
+                                                       "text", 4, NULL);
   gtk_tree_view_insert_column(GTK_TREE_VIEW(view), nation_col, -1);
 
+  rend = gtk_cell_renderer_text_new();
+  team_col = gtk_tree_view_column_new_with_attributes(_("Team"),
+                                                     rend,
+                                                     "text", 5, NULL);
+  gtk_tree_view_insert_column(GTK_TREE_VIEW(view), team_col, -1);
+
   g_signal_connect(view, "button-press-event",
                   G_CALLBACK(playerlist_event), NULL);
 
Index: common/team.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/team.c,v
retrieving revision 1.3
diff -u -r1.3 team.c
--- common/team.c       28 May 2005 02:19:36 -0000      1.3
+++ common/team.c       3 Jun 2005 17:45:04 -0000
@@ -38,13 +38,18 @@
 ****************************************************************************/
 struct team *team_find_by_name(const char *team_name)
 {
+  int index;
+
   assert(team_name != NULL);
 
-  team_iterate(pteam) {
+  /* Can't use team_iterate here since it skips empty teams. */
+  for (index = 0; index < MAX_NUM_TEAMS; index++) {
+    struct team *pteam = team_get_by_id(index);
+
     if (mystrcasecmp(team_name, pteam->name) == 0) {
       return pteam;
     }
-  } team_iterate_end;
+  }
 
   return NULL;
 }
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.415
diff -u -r1.415 stdinhand.c
--- server/stdinhand.c  1 Jun 2005 01:02:34 -0000       1.415
+++ server/stdinhand.c  3 Jun 2005 17:45:05 -0000
@@ -2099,6 +2099,7 @@
   }
   if (!check) {
     team_add_player(pplayer, pteam);
+    send_player_info(pplayer, NULL);
     cmd_reply(CMD_TEAM, caller, C_OK, _("Player %s set to team %s."),
              pplayer->name, _(pteam->name));
   }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13208) GUI interface for configuring teams, Jason Dorje Short <=