From 11f055b3d54406c66fa75e28ebe3e82e88a538b8 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 28 Aug 2022 02:56:54 +0300 Subject: [PATCH 34/34] gtk: Add tooltip for endgame score display rows See osdn #45461 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/repodlgs.c | 19 ++++++++++++++----- client/gui-gtk-3.22/repodlgs.c | 19 ++++++++++++++----- client/gui-gtk-4.0/repodlgs.c | 19 ++++++++++++++----- client/text.c | 21 +++++++++++++++++++++ client/text.h | 2 ++ 5 files changed, 65 insertions(+), 15 deletions(-) diff --git a/client/gui-gtk-3.0/repodlgs.c b/client/gui-gtk-3.0/repodlgs.c index 8b6dfb4947..b1b4b0c423 100644 --- a/client/gui-gtk-3.0/repodlgs.c +++ b/client/gui-gtk-3.0/repodlgs.c @@ -1778,6 +1778,7 @@ enum endgame_report_columns { FRD_COL_PLAYER, FRD_COL_NATION, FRD_COL_SCORE, + FRD_COL_TOOLTIP, FRD_COL_NUM }; @@ -1797,6 +1798,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; } @@ -1827,6 +1829,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; } @@ -1854,14 +1857,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; @@ -1883,6 +1891,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-3.22/repodlgs.c b/client/gui-gtk-3.22/repodlgs.c index 1c7c456e94..da0a76ceb0 100644 --- a/client/gui-gtk-3.22/repodlgs.c +++ b/client/gui-gtk-3.22/repodlgs.c @@ -1778,6 +1778,7 @@ enum endgame_report_columns { FRD_COL_PLAYER, FRD_COL_NATION, FRD_COL_SCORE, + FRD_COL_TOOLTIP, FRD_COL_NUM }; @@ -1797,6 +1798,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; } @@ -1827,6 +1829,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; } @@ -1854,14 +1857,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; @@ -1883,6 +1891,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 54303c0ea2..0daaf40492 100644 --- a/client/gui-gtk-4.0/repodlgs.c +++ b/client/gui-gtk-4.0/repodlgs.c @@ -1807,6 +1807,7 @@ enum endgame_report_columns { FRD_COL_PLAYER, FRD_COL_NATION, FRD_COL_SCORE, + FRD_COL_TOOLTIP, FRD_COL_NUM }; @@ -1826,6 +1827,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; } @@ -1856,6 +1858,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; } @@ -1883,14 +1886,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; @@ -1912,6 +1920,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 232f7c7847..36c1c3cba5 100644 --- a/client/text.c +++ b/client/text.c @@ -2072,3 +2072,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