From 69bec4130d713c6ac687763ec3addfea1bc304db Mon Sep 17 00:00:00 2001 From: Dino Date: Sat, 19 Jul 2025 18:30:49 -0400 Subject: [PATCH] #1605 make help -> units show all tech requirements --- client/gui-gtk-3.22/helpdlg.c | 77 ++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 6 deletions(-) diff --git a/client/gui-gtk-3.22/helpdlg.c b/client/gui-gtk-3.22/helpdlg.c index 9a2a7a6918..4b10e9aeda 100644 --- a/client/gui-gtk-3.22/helpdlg.c +++ b/client/gui-gtk-3.22/helpdlg.c @@ -662,11 +662,11 @@ static void create_help_dialog(void) gtk_label_new(help_ulabel_name[j][i] ? _(help_ulabel_name[j][i]) : ""); gtk_widget_set_hexpand(help_ulabel[j][i], TRUE); - if (j == 4 && (i == 1 || i == 4)) { - if (i == 1) { - button = help_hyperlink_new_page(help_ulabel[j][i], HELP_TECH); - } else { + if (j == 4 && (i == 1 || i == 2 || i == 4)) { + if (i == 4) { button = help_hyperlink_new_page(help_ulabel[j][i], HELP_UNIT); + } else { + button = help_hyperlink_new_page(help_ulabel[j][i], HELP_TECH); } gtk_grid_attach(GTK_GRID(help_utable), button, i, j, 1, 1); @@ -993,6 +993,10 @@ static void help_update_unit_type(const struct help_item *pitem, { char buf[8192]; struct unit_type *utype = unit_type_by_translated_name(title); + int row_num, col_num, req_num; + GtkWidget *button2, *button; + GtkWidget *label; + static int num_rows_in_grid = 5; if (utype) { sprintf(buf, "%d", utype_build_shield_cost_base(utype)); @@ -1011,8 +1015,69 @@ static void help_update_unit_type(const struct help_item *pitem, helptext_unit_upkeep_str(utype)); sprintf(buf, "%d", (int)sqrt((double)utype->vision_radius_sq)); gtk_label_set_text(GTK_LABEL(help_ulabel[3][4]), buf); - gtk_label_set_text(GTK_LABEL(help_ulabel[4][1]), - advance_name_translation(utype_primary_tech_req(utype))); + + /* requirements */ + + /* need to make the 2nd requirement button go away until it's needed */ + button2 = gtk_grid_get_child_at(GTK_GRID(help_utable), 2, 4); + gtk_widget_set_visible(button2, FALSE); + + /* also make the extra rows (if any) go away for now */ + for (row_num = num_rows_in_grid; row_num >=5; row_num--) + gtk_grid_remove_row(GTK_GRID(help_utable), row_num); + num_rows_in_grid = 5; + + /* About memory management - the docs don't say anything + * about gtk_grid_remove_row(), and say about gtk_grid_attach() that + * "The data is owned by the caller of the method." + * The source code for gtk_grid_remove_row() shows it calling + * gtk_container_remove(), and the doc for that says - + * "Note that container will own a reference to widget, and that this + * may be the last reference held; so removing a widget from its container + * can destroy that widget." + * I also did some testing that showed the buttons in the removed row + * are destroyed and not leaked. + */ + + /* see if any reqs */ + if (utype->build_reqs.size == 0) { + gtk_label_set_text(GTK_LABEL(help_ulabel[4][1]), + skip_intl_qualifier_prefix(REQ_LABEL_NONE)); + } else { + row_num = 5; + col_num = 0; + req_num = 1; + // iterate the reqs + unit_tech_reqs_iterate(utype, padv) { + switch (req_num++) { + case 1: + gtk_label_set_text(GTK_LABEL(help_ulabel[4][1]), + advance_name_translation(padv)); + break; + case 2: + /* bring back the 2nd requirement button */ + gtk_label_set_text(GTK_LABEL(help_ulabel[4][2]), + advance_name_translation(padv)); + gtk_widget_set_visible(button2, TRUE); + break; + default: + /* make and add another requirement button */ + label = gtk_label_new(advance_name_translation(padv)); + gtk_widget_set_hexpand(label, TRUE); + gtk_widget_set_visible(label, TRUE); + button = help_hyperlink_new_page(label, HELP_TECH); + gtk_grid_attach(GTK_GRID(help_utable), button, col_num, row_num, + 1, 1); + if (++col_num == 3) { + col_num = 0; + ++row_num; + ++num_rows_in_grid; + } + break; + } /* end switch */ + } unit_tech_reqs_iterate_end; + } + /* create_tech_tree(help_improvement_tree, 0, advance_number(utype->require_advance), 3);*/ if (U_NOT_OBSOLETED == utype->obsoleted_by) { gtk_label_set_text(GTK_LABEL(help_ulabel[4][4]), skip_intl_qualifier_prefix(REQ_LABEL_NONE)); -- 2.31.0