From 2a459264b0e72c009afee242479592dc269b1efe Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 1 Aug 2022 06:29:55 +0300 Subject: [PATCH 17/17] gtk: Add tooltips to citydlg/production tab build targets Requested by ddeanbrown See osdn #45257 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/wldlg.c | 22 ++++++++++++++++++---- client/gui-gtk-3.22/citydlg.c | 2 +- client/gui-gtk-3.22/wldlg.c | 26 +++++++++++++++++++------- client/text.c | 35 +++++++++++++++++++++++++++++++++++ client/text.h | 3 +++ 5 files changed, 76 insertions(+), 12 deletions(-) diff --git a/client/gui-gtk-3.0/wldlg.c b/client/gui-gtk-3.0/wldlg.c index 6732aa7f55..696c37669b 100644 --- a/client/gui-gtk-3.0/wldlg.c +++ b/client/gui-gtk-3.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-3.0 */ @@ -476,11 +477,15 @@ 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); @@ -1070,8 +1075,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; @@ -1108,6 +1113,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); @@ -1200,6 +1206,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); @@ -1370,11 +1377,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); @@ -1424,12 +1435,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-3.22/citydlg.c b/client/gui-gtk-3.22/citydlg.c index 05c53c7701..3fc2a89460 100644 --- a/client/gui-gtk-3.22/citydlg.c +++ b/client/gui-gtk-3.22/citydlg.c @@ -2074,7 +2074,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 526c2ad456..47320e0dd7 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 */ @@ -476,11 +477,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); @@ -1029,8 +1033,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)); @@ -1068,8 +1071,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; @@ -1106,6 +1109,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); @@ -1198,6 +1202,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); @@ -1366,11 +1371,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); @@ -1420,12 +1429,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 085b9e0f22..19a6f4b7d1 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" @@ -2028,3 +2029,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