[Freeciv-Dev] (PR#15200) show player stats in the client
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=15200 >
This patch adds the player's record and rating to the conn dialog when
in GGZ mode.
Attached separately is a screenshot.
-jason
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
--- client/gui-gtk-2.0/gui_main.c (revision 11448)
+++ client/gui-gtk-2.0/gui_main.c (working copy)
@@ -1389,10 +1389,14 @@
gtk_stockbutton_set_label(ready_button, text);
}
+ gtk_tree_view_column_set_visible(record_col, (with_ggz || in_ggz));
+ gtk_tree_view_column_set_visible(rating_col, (with_ggz || in_ggz));
+
if (get_client_state() != CLIENT_GAME_RUNNING_STATE) {
bool is_ready;
const char *nation, *leader, *team;
- char name[MAX_LEN_NAME + 4];
+ char name[MAX_LEN_NAME + 4], rating_text[128], record_text[128];
+ int rating, wins, losses, ties, forfeits;
gtk_list_store_clear(conn_model);
players_iterate(pplayer) {
@@ -1433,6 +1437,30 @@
}
team = pplayer->team ? team_get_name(pplayer->team) : "";
+ rating_text[0] = '\0';
+ if ((in_ggz || with_ggz)
+ && !pplayer->ai.control
+ && user_get_rating(pplayer->username, &rating)) {
+ my_snprintf(rating_text, sizeof(rating_text), "%d", rating);
+ }
+
+ record_text[0] = '\0';
+ if ((in_ggz || with_ggz)
+ && !pplayer->ai.control
+ && user_get_record(pplayer->username,
+ &wins, &losses, &ties, &forfeits)) {
+ if (forfeits == 0 && ties == 0) {
+ my_snprintf(record_text, sizeof(record_text), "%d-%d",
+ wins, losses);
+ } else if (forfeits == 0) {
+ my_snprintf(record_text, sizeof(record_text), "%d-%d-%d",
+ wins, losses, ties);
+ } else {
+ my_snprintf(record_text, sizeof(record_text), "%d-%d-%d-%d",
+ wins, losses, ties, forfeits);
+ }
+ }
+
gtk_list_store_append(conn_model, &it);
gtk_list_store_set(conn_model, &it,
0, pplayer->player_no,
@@ -1441,6 +1469,8 @@
3, leader,
4, nation,
5, team,
+ 6, record_text,
+ 7, rating_text,
-1);
} players_iterate_end;
conn_list_iterate(game.est_connections, pconn) {
Index: client/gui-gtk-2.0/pages.c
===================================================================
--- client/gui-gtk-2.0/pages.c (revision 11448)
+++ client/gui-gtk-2.0/pages.c (working copy)
@@ -56,6 +56,7 @@
GtkListStore *conn_model;
static GtkTreeViewColumn *nation_col, *ready_col, *team_col;
+GtkTreeViewColumn *rating_col, *record_col;
static GtkWidget *start_options_table;
GtkWidget *ready_button;
@@ -1223,9 +1224,10 @@
gtk_box_pack_start(GTK_BOX(vbox), align, FALSE, FALSE, 8);
- conn_model = gtk_list_store_new(6, G_TYPE_INT,
+ conn_model = gtk_list_store_new(8, G_TYPE_INT,
G_TYPE_STRING, G_TYPE_BOOLEAN,
G_TYPE_STRING, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING);
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(conn_model));
@@ -1237,6 +1239,16 @@
-1, _("Name"), rend,
"text", 1, NULL);
+ rend = gtk_cell_renderer_text_new();
+ record_col = gtk_tree_view_column_new_with_attributes(_("Record"), rend,
+ "text", 6, NULL);
+ gtk_tree_view_insert_column(GTK_TREE_VIEW(view), record_col, -1);
+
+ rend = gtk_cell_renderer_text_new();
+ rating_col = gtk_tree_view_column_new_with_attributes(_("Rating"), rend,
+ "text", 7, NULL);
+ gtk_tree_view_insert_column(GTK_TREE_VIEW(view), rating_col, -1);
+
/* FIXME: should change to always be minimum-width. */
rend = gtk_cell_renderer_toggle_new();
ready_col = gtk_tree_view_column_new_with_attributes(_("Ready"),
Index: client/gui-gtk-2.0/pages.h
===================================================================
--- client/gui-gtk-2.0/pages.h (revision 11448)
+++ client/gui-gtk-2.0/pages.h (working copy)
@@ -21,6 +21,7 @@
extern GtkWidget *start_message_area;
extern GtkWidget *ready_button;
+extern GtkTreeViewColumn *rating_col, *record_col;
GtkWidget *create_main_page(void);
GtkWidget *create_start_page(void);
Index: client/ggzclient.c
===================================================================
--- client/ggzclient.c (revision 11448)
+++ client/ggzclient.c (working copy)
@@ -49,6 +49,15 @@
}
/****************************************************************************
+ Callback for when the GGZ client tells us player stats.
+****************************************************************************/
+static void handle_ggzmod_stats(GGZMod *ggzmod, GGZModEvent e,
+ const void *data)
+{
+ update_conn_list_dialog();
+}
+
+/****************************************************************************
Connect to the GGZ client, if GGZ is being used.
****************************************************************************/
void ggz_initialize(void)
@@ -58,6 +67,7 @@
/* We're in GGZ mode */
ggzmod = ggzmod_new(GGZMOD_GAME);
ggzmod_set_handler(ggzmod, GGZMOD_EVENT_SERVER, &handle_ggzmod_server);
+ ggzmod_set_handler(ggzmod, GGZMOD_EVENT_STATS, &handle_ggzmod_stats);
if (ggzmod_connect(ggzmod) < 0) {
exit(EXIT_FAILURE);
}
@@ -78,4 +88,56 @@
ggzmod_dispatch(ggzmod);
}
+/****************************************************************************
+ Find the seat for the given player (in the seat parameter), or returns
+ FALSE if no seat is found.
+****************************************************************************/
+static bool user_get_seat(const char *name, GGZSeat *seat)
+{
+ int i;
+ int num = ggzmod_get_num_seats(ggzmod);
+
+ for (i = 0; i < num; i++) {
+ *seat = ggzmod_get_seat(ggzmod, i);
+
+ if (seat->type == GGZ_SEAT_PLAYER
+ && strcasecmp(seat->name, name) == 0) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+/****************************************************************************
+ Find the player's rating, or return FALSE if there is no rating.
+****************************************************************************/
+bool user_get_rating(const char *name, int *rating)
+{
+ GGZSeat seat;
+
+ if (user_get_seat(name, &seat)) {
+ return ggzmod_player_get_rating(ggzmod, &seat, rating);
+ }
+
+ return FALSE;
+}
+
+/****************************************************************************
+ Find the player's record, or return FALSE if there is no record.
+****************************************************************************/
+bool user_get_record(const char *name,
+ int *wins, int *losses, int *ties, int *forfeits)
+{
+ GGZSeat seat;
+
+ if (user_get_seat(name, &seat)) {
+ return ggzmod_player_get_record(ggzmod, &seat,
+ wins, losses, ties, forfeits);
+ }
+
+ return FALSE;
+
+}
+
#endif
Index: client/ggzclient.h
===================================================================
--- client/ggzclient.h (revision 11448)
+++ client/ggzclient.h (working copy)
@@ -22,11 +22,18 @@
void ggz_initialize(void);
void input_from_ggz(int socket);
+bool user_get_rating(const char *name, int *rating);
+bool user_get_record(const char *name,
+ int *wins, int *losses, int *ties, int *forfeits);
+
+
#else
# define with_ggz FALSE
# define ggz_initialize() (void)0
# define input_from_ggz(socket) (void)0
+# define user_get_rating(p, r) (FALSE)
+# define user_get_record(p, w, l, t, f) (FALSE)
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#15200) show player stats in the client,
Jason Short <=
|
|