From 1841f61befad991f266a916b341003e17dd1a1fa Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 28 Aug 2022 02:56:54 +0300 Subject: [PATCH 48/48] gtk: Add tooltip for endgame score display rows See osdn #45461 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/repodlgs.c | 19 ++++++++++++++----- client/gui-gtk-4.0/repodlgs.c | 19 ++++++++++++++----- client/text.c | 21 +++++++++++++++++++++ client/text.h | 2 ++ 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/client/gui-gtk-3.22/repodlgs.c b/client/gui-gtk-3.22/repodlgs.c index 6b888b4c0e..b38b82a73a 100644 --- a/client/gui-gtk-3.22/repodlgs.c +++ b/client/gui-gtk-3.22/repodlgs.c @@ -1779,6 +1779,7 @@ enum endgame_report_columns { FRD_COL_PLAYER, FRD_COL_NATION, FRD_COL_SCORE, + FRD_COL_TOOLTIP, FRD_COL_NUM }; @@ -1798,6 +1799,7 @@ endgame_report_column_name(enum endgame_report_columns col) return _("Nation\n"); case FRD_COL_SCORE: return _("Score\n"); + case FRD_COL_TOOLTIP: case FRD_COL_NUM: break; } @@ -1828,6 +1830,7 @@ static void endgame_report_update(struct endgame_report *preport, col_types[FRD_COL_PLAYER] = G_TYPE_STRING; col_types[FRD_COL_NATION] = GDK_TYPE_PIXBUF; col_types[FRD_COL_SCORE] = G_TYPE_INT; + col_types[FRD_COL_TOOLTIP] = G_TYPE_STRING; for (i = FRD_COL_NUM; (guint)i < col_num; i++) { col_types[i] = G_TYPE_INT; } @@ -1855,14 +1858,19 @@ static void endgame_report_update(struct endgame_report *preport, title = packet->category_name[i - FRD_COL_NUM]; } - col = gtk_tree_view_column_new_with_attributes(Q_(title), renderer, - attribute, i, NULL); - gtk_tree_view_append_column(preport->tree_view, col); - if (GDK_TYPE_PIXBUF != col_types[i]) { - gtk_tree_view_column_set_sort_column_id(col, i); + if (title != NULL) { + col = gtk_tree_view_column_new_with_attributes(Q_(title), renderer, + attribute, i, NULL); + gtk_tree_view_append_column(preport->tree_view, col); + if (GDK_TYPE_PIXBUF != col_types[i]) { + gtk_tree_view_column_set_sort_column_id(col, i); + } } } + gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(preport->tree_view), + FRD_COL_TOOLTIP); + preport->store = store; preport->player_count = packet->player_num; preport->players_received = 0; @@ -1884,6 +1892,7 @@ void endgame_report_dialog_player(const struct packet_endgame_player *packet) FRD_COL_PLAYER, player_name(pplayer), FRD_COL_NATION, get_flag(nation_of_player(pplayer)), FRD_COL_SCORE, packet->score, + FRD_COL_TOOLTIP, score_tooltip(pplayer, packet->score), -1); for (i = 0; i < packet->category_num; i++) { gtk_list_store_set(preport->store, &iter, diff --git a/client/gui-gtk-4.0/repodlgs.c b/client/gui-gtk-4.0/repodlgs.c index 4a5f707581..e89c31f7c8 100644 --- a/client/gui-gtk-4.0/repodlgs.c +++ b/client/gui-gtk-4.0/repodlgs.c @@ -1808,6 +1808,7 @@ enum endgame_report_columns { FRD_COL_PLAYER, FRD_COL_NATION, FRD_COL_SCORE, + FRD_COL_TOOLTIP, FRD_COL_NUM }; @@ -1827,6 +1828,7 @@ endgame_report_column_name(enum endgame_report_columns col) return _("Nation\n"); case FRD_COL_SCORE: return _("Score\n"); + case FRD_COL_TOOLTIP: case FRD_COL_NUM: break; } @@ -1857,6 +1859,7 @@ static void endgame_report_update(struct endgame_report *preport, col_types[FRD_COL_PLAYER] = G_TYPE_STRING; col_types[FRD_COL_NATION] = GDK_TYPE_PIXBUF; col_types[FRD_COL_SCORE] = G_TYPE_INT; + col_types[FRD_COL_TOOLTIP] = G_TYPE_STRING; for (i = FRD_COL_NUM; (guint)i < col_num; i++) { col_types[i] = G_TYPE_INT; } @@ -1884,14 +1887,19 @@ static void endgame_report_update(struct endgame_report *preport, title = packet->category_name[i - FRD_COL_NUM]; } - col = gtk_tree_view_column_new_with_attributes(Q_(title), renderer, - attribute, i, NULL); - gtk_tree_view_append_column(preport->tree_view, col); - if (GDK_TYPE_PIXBUF != col_types[i]) { - gtk_tree_view_column_set_sort_column_id(col, i); + if (title != NULL) { + col = gtk_tree_view_column_new_with_attributes(Q_(title), renderer, + attribute, i, NULL); + gtk_tree_view_append_column(preport->tree_view, col); + if (GDK_TYPE_PIXBUF != col_types[i]) { + gtk_tree_view_column_set_sort_column_id(col, i); + } } } + gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(preport->tree_view), + FRD_COL_TOOLTIP); + preport->store = store; preport->player_count = packet->player_num; preport->players_received = 0; @@ -1913,6 +1921,7 @@ void endgame_report_dialog_player(const struct packet_endgame_player *packet) FRD_COL_PLAYER, player_name(pplayer), FRD_COL_NATION, get_flag(nation_of_player(pplayer)), FRD_COL_SCORE, packet->score, + FRD_COL_TOOLTIP, score_tooltip(pplayer, packet->score), -1); for (i = 0; i < packet->category_num; i++) { gtk_list_store_set(preport->store, &iter, diff --git a/client/text.c b/client/text.c index fe0cd4ebd4..5d7de4ee7f 100644 --- a/client/text.c +++ b/client/text.c @@ -2075,3 +2075,24 @@ const char *production_help(const struct universal *uni, char *buf, return buf; } + +/************************************************************************//** + Tooltip for the player row on reports. + Negative score is not shown. + + Returns static buffer that gets overwritten on next call. +****************************************************************************/ +const char *score_tooltip(const struct player *pplayer, int score) +{ + static char buf[1024]; + + if (score >= 0) { + /* TRANS: %s is a Nation */ + fc_snprintf(buf, sizeof(buf), _("%s: score %d"), nation_adjective_for_player(pplayer), + score); + } else { + fc_snprintf(buf, sizeof(buf), "%s", nation_adjective_for_player(pplayer)); + } + + return buf; +} diff --git a/client/text.h b/client/text.h index b5ecf7bd95..9cab7046c6 100644 --- a/client/text.h +++ b/client/text.h @@ -71,6 +71,8 @@ const char *text_happiness_wonders(const struct city *pcity); const char *production_help(const struct universal *uni, char *buf, size_t bufsize); +const char *score_tooltip(const struct player *pplayer, int score); + #ifdef __cplusplus } #endif /* __cplusplus */ -- 2.35.1