From e65fc5af0022ec3307475d38d7d93aa6b4aa9a3e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 1 Aug 2022 06:16:54 +0300 Subject: [PATCH 56/56] gtk: Add tooltips to citydlg/production tab build targets Requested by ddeanbrown See osdn #45257 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/citydlg.c | 2 +- client/gui-gtk-3.22/wldlg.c | 26 +++++++++++++++++++------- client/gui-gtk-4.0/citydlg.c | 2 +- client/gui-gtk-4.0/wldlg.c | 25 +++++++++++++++++++------ client/text.c | 35 +++++++++++++++++++++++++++++++++++ client/text.h | 3 +++ 6 files changed, 78 insertions(+), 15 deletions(-) diff --git a/client/gui-gtk-3.22/citydlg.c b/client/gui-gtk-3.22/citydlg.c index 363d4c48d3..6dfbc2b7c8 100644 --- a/client/gui-gtk-3.22/citydlg.c +++ b/client/gui-gtk-3.22/citydlg.c @@ -2064,7 +2064,7 @@ static void city_dialog_update_building(struct city_dialog *pdialog) gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, pix, 1, name, 3, useless, - 2, (gint)cid_encode(items[item].item),-1); + 2, (gint)cid_encode(items[item].item), -1); g_object_unref(G_OBJECT(pix)); } } diff --git a/client/gui-gtk-3.22/wldlg.c b/client/gui-gtk-3.22/wldlg.c index b1b817637b..2970b96ee4 100644 --- a/client/gui-gtk-3.22/wldlg.c +++ b/client/gui-gtk-3.22/wldlg.c @@ -38,6 +38,7 @@ #include "climisc.h" #include "global_worklist.h" #include "options.h" +#include "text.h" #include "tilespec.h" /* client/gui-gtk-3.22 */ @@ -473,11 +474,14 @@ static void menu_item_callback(GtkMenuItem *item, struct worklist_data *ptr) for (i = 0; i < (size_t) worklist_length(pwl); i++) { GtkTreeIter it; cid id; + char buf[8192]; id = cid_encode(pwl->entries[i]); gtk_list_store_append(ptr->dst, &it); - gtk_list_store_set(ptr->dst, &it, 0, (gint) id, -1); + gtk_list_store_set(ptr->dst, &it, 0, (gint)id, + 1, production_help(&(pwl->entries[i]), + buf, sizeof(buf)), -1); } commit_worklist(ptr); @@ -1026,8 +1030,7 @@ static void populate_view(GtkTreeView *view, struct city **ppcity, } for (i = 1; i < ARRAY_SIZE(titles); i++) { - - gint pos = i-1; + gint pos = i - 1; rend = gtk_cell_renderer_text_new(); g_object_set_data(G_OBJECT(rend), "column", GINT_TO_POINTER(pos)); @@ -1065,8 +1068,8 @@ GtkWidget *create_worklist(void) ptr = fc_malloc(sizeof(*ptr)); - src_store = gtk_list_store_new(1, G_TYPE_INT); - dst_store = gtk_list_store_new(1, G_TYPE_INT); + src_store = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING); + dst_store = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING); ptr->global_worklist_id = -1; ptr->pcity = NULL; @@ -1103,6 +1106,7 @@ GtkWidget *create_worklist(void) g_object_unref(src_store); gtk_size_group_add_widget(group, src_view); gtk_widget_set_name(src_view, "small_font"); + gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(src_view), 1); populate_view(GTK_TREE_VIEW(src_view), &ptr->pcity, &ptr->src_col); gtk_container_add(GTK_CONTAINER(sw), src_view); @@ -1195,6 +1199,7 @@ GtkWidget *create_worklist(void) g_object_unref(dst_store); gtk_size_group_add_widget(group, dst_view); gtk_widget_set_name(dst_view, "small_font"); + gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(dst_view), 1); populate_view(GTK_TREE_VIEW(dst_view), &ptr->pcity, &ptr->dst_col); gtk_container_add(GTK_CONTAINER(sw), dst_view); @@ -1362,11 +1367,15 @@ void refresh_worklist(GtkWidget *editor) path = NULL; for (i = 0; i < targets_used; i++) { + char buf[8192]; + if (!exists) { gtk_list_store_append(ptr->src, &it); } - gtk_list_store_set(ptr->src, &it, 0, (gint) cid_encode(items[i].item), -1); + gtk_list_store_set(ptr->src, &it, 0, (gint)cid_encode(items[i].item), + 1, production_help(&(items[i].item), + buf, sizeof(buf)), -1); if (selected && cid_encode(items[i].item) == id) { path = gtk_tree_model_get_path(GTK_TREE_MODEL(ptr->src), &it); @@ -1416,12 +1425,15 @@ void refresh_worklist(GtkWidget *editor) for (i = 0; i < worklist_length(&queue); i++) { struct universal target = queue.entries[i]; + char buf[8192]; if (!exists) { gtk_list_store_append(ptr->dst, &it); } - gtk_list_store_set(ptr->dst, &it, 0, (gint) cid_encode(target), -1); + gtk_list_store_set(ptr->dst, &it, 0, (gint)cid_encode(target), + 1, production_help(&target, + buf, sizeof(buf)), -1); if (exists) { exists = gtk_tree_model_iter_next(model, &it); diff --git a/client/gui-gtk-4.0/citydlg.c b/client/gui-gtk-4.0/citydlg.c index 124c8c6422..576f4d87b7 100644 --- a/client/gui-gtk-4.0/citydlg.c +++ b/client/gui-gtk-4.0/citydlg.c @@ -2089,7 +2089,7 @@ static void city_dialog_update_building(struct city_dialog *pdialog) gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, pix, 1, name, 3, useless, - 2, (gint)cid_encode(items[item].item),-1); + 2, (gint)cid_encode(items[item].item), -1); g_object_unref(G_OBJECT(pix)); } } diff --git a/client/gui-gtk-4.0/wldlg.c b/client/gui-gtk-4.0/wldlg.c index f64f6258bd..49e3539f71 100644 --- a/client/gui-gtk-4.0/wldlg.c +++ b/client/gui-gtk-4.0/wldlg.c @@ -38,6 +38,7 @@ #include "climisc.h" #include "global_worklist.h" #include "options.h" +#include "text.h" #include "tilespec.h" /* client/gui-gtk-4.0 */ @@ -473,11 +474,14 @@ static void menu_item_callback(GtkMenuItem *item, struct worklist_data *ptr) for (i = 0; i < (size_t) worklist_length(pwl); i++) { GtkTreeIter it; cid id; + char buf[8192]; id = cid_encode(pwl->entries[i]); gtk_list_store_append(ptr->dst, &it); - gtk_list_store_set(ptr->dst, &it, 0, (gint) id, -1); + gtk_list_store_set(ptr->dst, &it, 0, (gint)id, + 1, production_help(&(pwl->entries[i]), + buf, sizeof(buf)), -1); } commit_worklist(ptr); @@ -1038,7 +1042,7 @@ static void populate_view(GtkTreeView *view, struct city **ppcity, } for (i = 1; i < ARRAY_SIZE(titles); i++) { - gint pos = i-1; + gint pos = i - 1; rend = gtk_cell_renderer_text_new(); g_object_set_data(G_OBJECT(rend), "column", GINT_TO_POINTER(pos)); @@ -1081,8 +1085,8 @@ GtkWidget *create_worklist(void) ptr = fc_malloc(sizeof(*ptr)); - src_store = gtk_list_store_new(1, G_TYPE_INT); - dst_store = gtk_list_store_new(1, G_TYPE_INT); + src_store = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING); + dst_store = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING); ptr->global_worklist_id = -1; ptr->pcity = NULL; @@ -1118,6 +1122,7 @@ GtkWidget *create_worklist(void) g_object_unref(src_store); gtk_size_group_add_widget(group, src_view); gtk_widget_set_name(src_view, "small_font"); + gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(src_view), 1); populate_view(GTK_TREE_VIEW(src_view), &ptr->pcity, &ptr->src_col); gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), src_view); @@ -1209,6 +1214,7 @@ GtkWidget *create_worklist(void) g_object_unref(dst_store); gtk_size_group_add_widget(group, dst_view); gtk_widget_set_name(dst_view, "small_font"); + gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(dst_view), 1); populate_view(GTK_TREE_VIEW(dst_view), &ptr->pcity, &ptr->dst_col); gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), dst_view); @@ -1384,11 +1390,15 @@ void refresh_worklist(GtkWidget *editor) path = NULL; for (i = 0; i < targets_used; i++) { + char buf[8192]; + if (!exists) { gtk_list_store_append(ptr->src, &it); } - gtk_list_store_set(ptr->src, &it, 0, (gint) cid_encode(items[i].item), -1); + gtk_list_store_set(ptr->src, &it, 0, (gint)cid_encode(items[i].item), + 1, production_help(&(items[i].item), + buf, sizeof(buf)), -1); if (selected && cid_encode(items[i].item) == id) { path = gtk_tree_model_get_path(GTK_TREE_MODEL(ptr->src), &it); @@ -1438,12 +1448,15 @@ void refresh_worklist(GtkWidget *editor) for (i = 0; i < worklist_length(&queue); i++) { struct universal target = queue.entries[i]; + char buf[8192]; if (!exists) { gtk_list_store_append(ptr->dst, &it); } - gtk_list_store_set(ptr->dst, &it, 0, (gint) cid_encode(target), -1); + gtk_list_store_set(ptr->dst, &it, 0, (gint)cid_encode(target), + 1, production_help(&target, + buf, sizeof(buf)), -1); if (exists) { exists = gtk_tree_model_iter_next(model, &it); diff --git a/client/text.c b/client/text.c index 66fc6173d3..fe0cd4ebd4 100644 --- a/client/text.c +++ b/client/text.c @@ -46,6 +46,7 @@ #include "climisc.h" #include "control.h" #include "goto.h" +#include "helpdata.h" #include "text.h" @@ -2040,3 +2041,37 @@ const char *text_happiness_luxuries(const struct city *pcity) pcity->prod[O_LUXURY]); return astr_str(&str); } + +/************************************************************************//** + Fill provided buffer with relatively short (not full) helptext + of the universal. +****************************************************************************/ +const char *production_help(const struct universal *uni, char *buf, + size_t bufsize) +{ + buf[0] = '\0'; + int segments = 0; + + if (uni->kind == VUT_UTYPE) { + if (uni->value.utype->helptext != NULL) { + strvec_iterate(uni->value.utype->helptext, text) { + if (segments++) { + cat_snprintf(buf, bufsize, "\n\n"); + } + cat_snprintf(buf, bufsize, "%s", _(text)); + } strvec_iterate_end; + } + } else { + fc_assert(uni->kind == VUT_IMPROVEMENT); + if (uni->value.building->helptext != NULL) { + strvec_iterate(uni->value.building->helptext, text) { + if (segments++) { + cat_snprintf(buf, bufsize, "\n\n"); + } + cat_snprintf(buf, bufsize, "%s", _(text)); + } strvec_iterate_end; + } + } + + return buf; +} diff --git a/client/text.h b/client/text.h index 9f4055ed78..b5ecf7bd95 100644 --- a/client/text.h +++ b/client/text.h @@ -68,6 +68,9 @@ const char *text_happiness_luxuries(const struct city *pcity); const char *text_happiness_units(const struct city *pcity); const char *text_happiness_wonders(const struct city *pcity); +const char *production_help(const struct universal *uni, char *buf, + size_t bufsize); + #ifdef __cplusplus } #endif /* __cplusplus */ -- 2.35.1