From 65317501db50fa0ffe648a39b50558f7130a7d7d Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 18 Mar 2024 00:43:06 +0200 Subject: [PATCH 27/27] Introduce is_regular_advance() See osdn #48588 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/helpdlg.c | 5 +- client/gui-gtk-4.0/helpdlg.c | 6 +- client/gui-gtk-5.0/helpdlg.c | 6 +- client/gui-qt/helpdlg.cpp | 154 +++++++++++++++++----------------- common/tech.c | 10 +++ common/tech.h | 1 + 6 files changed, 96 insertions(+), 86 deletions(-) diff --git a/client/gui-gtk-3.22/helpdlg.c b/client/gui-gtk-3.22/helpdlg.c index ca0deb946c..84625e1b72 100644 --- a/client/gui-gtk-3.22/helpdlg.c +++ b/client/gui-gtk-3.22/helpdlg.c @@ -1073,14 +1073,15 @@ static char *fc_chomp(char *str, size_t len) **************************************************************************/ static void help_update_tech(const struct help_item *pitem, char *title) { - int i, j; + int j; GtkWidget *w, *hbox; char buf[8192]; struct advance *padvance = advance_by_translated_name(title); - if (padvance && !is_future_tech(i = advance_number(padvance))) { + if (is_regular_advance(padvance)) { GtkTextBuffer *txt; size_t len; + Tech_type_id i = advance_number(padvance); gtk_container_foreach(GTK_CONTAINER(help_vbox), (GtkCallback)gtk_widget_destroy, NULL); diff --git a/client/gui-gtk-4.0/helpdlg.c b/client/gui-gtk-4.0/helpdlg.c index 739fc2de73..36260815e1 100644 --- a/client/gui-gtk-4.0/helpdlg.c +++ b/client/gui-gtk-4.0/helpdlg.c @@ -1110,15 +1110,15 @@ static char *fc_chomp(char *str, size_t len) **************************************************************************/ static void help_update_tech(const struct help_item *pitem, char *title) { - int i, j; + int j; GtkWidget *w, *hbox; char buf[8192]; struct advance *padvance = advance_by_translated_name(title); - if (padvance != NULL - && !is_future_tech(i = advance_number(padvance))) { + if (is_regular_advance(padvance)) { GtkTextBuffer *txt; size_t len; + Tech_type_id i = advance_number(padvance); help_box_clear(); diff --git a/client/gui-gtk-5.0/helpdlg.c b/client/gui-gtk-5.0/helpdlg.c index 232c9d5538..8278fe924e 100644 --- a/client/gui-gtk-5.0/helpdlg.c +++ b/client/gui-gtk-5.0/helpdlg.c @@ -1110,15 +1110,15 @@ static char *fc_chomp(char *str, size_t len) **************************************************************************/ static void help_update_tech(const struct help_item *pitem, char *title) { - int i, j; + int j; GtkWidget *w, *hbox; char buf[8192]; struct advance *padvance = advance_by_translated_name(title); - if (padvance != NULL - && !is_future_tech(i = advance_number(padvance))) { + if (is_regular_advance(padvance)) { GtkTextBuffer *txt; size_t len; + Tech_type_id i = advance_number(padvance); help_box_clear(); diff --git a/client/gui-qt/helpdlg.cpp b/client/gui-qt/helpdlg.cpp index ac0ab4191b..af2378c94a 100644 --- a/client/gui-qt/helpdlg.cpp +++ b/client/gui-qt/helpdlg.cpp @@ -233,7 +233,6 @@ void help_dialog::make_tree() { char *title; int dep; - int i; QHash hash; QIcon icon; QTreeWidgetItem *item; @@ -300,7 +299,9 @@ void help_dialog::make_tree() break; case HELP_TECH: padvance = advance_by_translated_name(s); - if (padvance && !is_future_tech(i = advance_number(padvance))) { + if (is_regular_advance(padvance)) { + Tech_type_id i = advance_number(padvance); + spite = get_tech_sprite(tileset, i); if (spite) { icon = QIcon(*spite->pm); @@ -1099,102 +1100,99 @@ void help_widget::set_topic_tech(const help_item *topic, struct advance *padvance = advance_by_translated_name(title); QString str; - if (padvance) { + if (is_regular_advance(padvance)) { int n = advance_number(padvance); - if (!is_future_tech(n)) { - show_info_panel(); - spr = get_tech_sprite(tileset, n); - if (spr) { - add_info_pixmap(spr->pm); - } + show_info_panel(); + spr = get_tech_sprite(tileset, n); + if (spr) { + add_info_pixmap(spr->pm); + } - governments_iterate(pgov) { - requirement_vector_iterate(&pgov->reqs, preq) { + governments_iterate(pgov) { + requirement_vector_iterate(&pgov->reqs, preq) { + if (VUT_ADVANCE == preq->source.kind + && preq->source.value.advance == padvance) { + tb = new QLabel(this); + tb->setProperty(fonts::help_label, "true"); + tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse); + tb->setTextFormat(Qt::RichText); + str = _("Allows"); + str = "" + str + " " + + link_me(government_name_translation(pgov), HELP_GOVERNMENT); + tb->setText(str.trimmed()); + connect(tb, &QLabel::linkActivated, + this, &help_widget::anchor_clicked); + info_layout->addWidget(tb); + } + } requirement_vector_iterate_end; + } governments_iterate_end; + + improvement_iterate(pimprove) { + if (valid_improvement(pimprove)) { + requirement_vector_iterate(&pimprove->reqs, preq) { if (VUT_ADVANCE == preq->source.kind && preq->source.value.advance == padvance) { + str = _("Allows"); + str = "" + str + " " + + link_me(improvement_name_translation(pimprove), + is_great_wonder(pimprove) ? HELP_WONDER + : HELP_IMPROVEMENT); tb = new QLabel(this); tb->setProperty(fonts::help_label, "true"); tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse); tb->setTextFormat(Qt::RichText); - str = _("Allows"); + tb->setText(str.trimmed()); + connect(tb, &QLabel::linkActivated, + this, &help_widget::anchor_clicked); + info_layout->addWidget(tb); + } + } requirement_vector_iterate_end; + + requirement_vector_iterate(&pimprove->obsolete_by, pobs) { + if (pobs->source.kind == VUT_ADVANCE + && pobs->source.value.advance == padvance) { + str = _("Obsoletes"); str = "" + str + " " - + link_me(government_name_translation(pgov), HELP_GOVERNMENT); + + link_me(improvement_name_translation(pimprove), + is_great_wonder(pimprove) ? HELP_WONDER + : HELP_IMPROVEMENT); + tb = new QLabel(this); + tb->setProperty(fonts::help_label, "true"); + tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse); + tb->setTextFormat(Qt::RichText); tb->setText(str.trimmed()); connect(tb, &QLabel::linkActivated, this, &help_widget::anchor_clicked); info_layout->addWidget(tb); } } requirement_vector_iterate_end; - } governments_iterate_end; - - improvement_iterate(pimprove) { - if (valid_improvement(pimprove)) { - requirement_vector_iterate(&pimprove->reqs, preq) { - if (VUT_ADVANCE == preq->source.kind - && preq->source.value.advance == padvance) { - str = _("Allows"); - str = "" + str + " " - + link_me(improvement_name_translation(pimprove), - is_great_wonder(pimprove) ? HELP_WONDER - : HELP_IMPROVEMENT); - tb = new QLabel(this); - tb->setProperty(fonts::help_label, "true"); - tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse); - tb->setTextFormat(Qt::RichText); - tb->setText(str.trimmed()); - connect(tb, &QLabel::linkActivated, - this, &help_widget::anchor_clicked); - info_layout->addWidget(tb); - } - } requirement_vector_iterate_end; - - requirement_vector_iterate(&pimprove->obsolete_by, pobs) { - if (pobs->source.kind == VUT_ADVANCE - && pobs->source.value.advance == padvance) { - str = _("Obsoletes"); - str = "" + str + " " - + link_me(improvement_name_translation(pimprove), - is_great_wonder(pimprove) ? HELP_WONDER - : HELP_IMPROVEMENT); - tb = new QLabel(this); - tb->setProperty(fonts::help_label, "true"); - tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse); - tb->setTextFormat(Qt::RichText); - tb->setText(str.trimmed()); - connect(tb, &QLabel::linkActivated, - this, &help_widget::anchor_clicked); - info_layout->addWidget(tb); - } - } requirement_vector_iterate_end; - } - } improvement_iterate_end; + } + } improvement_iterate_end; - unit_type_iterate(punittype) { + unit_type_iterate(punittype) { - if (!is_tech_req_for_utype(punittype, padvance)) { - continue; - } - - str = _("Allows"); - str = "" + str + " " - + link_me(utype_name_translation(punittype), HELP_UNIT); - tb = new QLabel(this); - tb->setProperty(fonts::help_label, "true"); - tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse); - tb->setTextFormat(Qt::RichText); - tb->setText(str.trimmed()); - connect(tb, &QLabel::linkActivated, - this, &help_widget::anchor_clicked); - info_layout->addWidget(tb); - } unit_type_iterate_end; + if (!is_tech_req_for_utype(punittype, padvance)) { + continue; + } - info_panel_done(); - helptext_advance(buffer, sizeof(buffer), client.conn.playing, - topic->text, n); - text_browser->setPlainText(buffer); + str = _("Allows"); + str = "" + str + " " + + link_me(utype_name_translation(punittype), HELP_UNIT); + tb = new QLabel(this); + tb->setProperty(fonts::help_label, "true"); + tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse); + tb->setTextFormat(Qt::RichText); + tb->setText(str.trimmed()); + connect(tb, &QLabel::linkActivated, + this, &help_widget::anchor_clicked); + info_layout->addWidget(tb); + } unit_type_iterate_end; - } + info_panel_done(); + helptext_advance(buffer, sizeof(buffer), client.conn.playing, + topic->text, n); + text_browser->setPlainText(buffer); } else { set_topic_other(topic, title); } diff --git a/common/tech.c b/common/tech.c index 5d0042f79b..bae1394fb0 100644 --- a/common/tech.c +++ b/common/tech.c @@ -283,6 +283,16 @@ bool is_future_tech(Tech_type_id tech) return tech == A_FUTURE; } +/**********************************************************************//** + Is the given tech an regular advance. "None" counts as regular advance, + Future Tech does not. +**************************************************************************/ +bool is_regular_advance(struct advance *padvance) +{ + return valid_advance(padvance) != nullptr + && padvance->item_number != A_FUTURE; +} + /**********************************************************************//** Return the (translated) name of the given advance/technology. You don't have to free the return pointer. diff --git a/common/tech.h b/common/tech.h index f45aaac056..56ece0517e 100644 --- a/common/tech.h +++ b/common/tech.h @@ -229,6 +229,7 @@ struct advance *advance_requires(const struct advance *padvance, bool techs_have_fixed_costs(void); bool is_future_tech(Tech_type_id tech); +bool is_regular_advance(struct advance *padvance); /* Initialization */ void techs_init(void); -- 2.43.0