Author: jtn Date: Tue Apr 7 09:25:10 2015 New Revision: 28739 URL: http://svn.gna.org/viewcvs/freeciv?rev=28739&view=rev Log: Add governments to insert_allows().
See gna patch #5813. Modified: trunk/client/gui-gtk-2.0/helpdlg.c trunk/client/gui-gtk-3.0/helpdlg.c trunk/client/helpdata.c Modified: trunk/client/gui-gtk-2.0/helpdlg.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/helpdlg.c?rev=28739&r1=28738&r2=28739&view=diff ============================================================================== --- trunk/client/gui-gtk-2.0/helpdlg.c (original) +++ trunk/client/gui-gtk-2.0/helpdlg.c Tue Apr 7 09:25:10 2015 @@ -982,9 +982,25 @@ gtk_box_pack_start(GTK_BOX(help_vbox), w, TRUE, TRUE, 5); gtk_widget_show(w); - improvement_iterate(pimprove) { + governments_iterate(pgov) { /* FIXME: need a more general mechanism for this, since this * helptext needs to be shown in all possible req source types. */ + requirement_vector_iterate(&pgov->reqs, preq) { + if (VUT_ADVANCE == preq->source.kind + && preq->source.value.advance == padvance) { + hbox = gtk_hbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(help_vbox), hbox); + w = gtk_label_new(_("Allows")); + gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0); + w = help_slink_new(government_name_translation(pgov), + HELP_GOVERNMENT); + gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0); + gtk_widget_show_all(hbox); + } + } requirement_vector_iterate_end; + } governments_iterate_end; + + improvement_iterate(pimprove) { requirement_vector_iterate(&pimprove->reqs, preq) { if (VUT_ADVANCE == preq->source.kind && preq->source.value.advance == padvance) { Modified: trunk/client/gui-gtk-3.0/helpdlg.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/helpdlg.c?rev=28739&r1=28738&r2=28739&view=diff ============================================================================== --- trunk/client/gui-gtk-3.0/helpdlg.c (original) +++ trunk/client/gui-gtk-3.0/helpdlg.c Tue Apr 7 09:25:10 2015 @@ -1007,9 +1007,25 @@ gtk_container_add(GTK_CONTAINER(help_vbox), w); gtk_widget_show(w); - improvement_iterate(pimprove) { + governments_iterate(pgov) { /* FIXME: need a more general mechanism for this, since this * helptext needs to be shown in all possible req source types. */ + requirement_vector_iterate(&pgov->reqs, preq) { + if (VUT_ADVANCE == preq->source.kind + && preq->source.value.advance == padvance) { + hbox = gtk_grid_new(); + gtk_container_add(GTK_CONTAINER(help_vbox), hbox); + w = gtk_label_new(_("Allows")); + gtk_container_add(GTK_CONTAINER(hbox), w); + w = help_slink_new(government_name_translation(pgov), + HELP_GOVERNMENT); + gtk_container_add(GTK_CONTAINER(hbox), w); + gtk_widget_show_all(hbox); + } + } requirement_vector_iterate_end; + } governments_iterate_end; + + improvement_iterate(pimprove) { requirement_vector_iterate(&pimprove->reqs, preq) { if (VUT_ADVANCE == preq->source.kind && preq->source.value.advance == padvance) { Modified: trunk/client/helpdata.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/helpdata.c?rev=28739&r1=28738&r2=28739&view=diff ============================================================================== --- trunk/client/helpdata.c (original) +++ trunk/client/helpdata.c Tue Apr 7 09:25:10 2015 @@ -2623,6 +2623,79 @@ } /**************************************************************************** + Append text to 'buf' if the given requirements list 'subjreqs' contains + 'psource', implying that ability to build the subject 'subjstr' is + affected by 'psource'. + 'strs' is an array of (possibly i18n-qualified) format strings covering + the various cases where additional requirements apply. +****************************************************************************/ +static void insert_allows_single(struct universal *psource, + struct requirement_vector *psubjreqs, + const char *subjstr, + const char *const *strs, + char *buf, size_t bufsz) { + struct strvec *coreqs = strvec_new(); + struct strvec *conoreqs = strvec_new(); + struct astring coreqstr = ASTRING_INIT; + struct astring conoreqstr = ASTRING_INIT; + char buf2[bufsz]; + + /* FIXME: show other data like range and survives. */ + + requirement_vector_iterate(psubjreqs, req) { + if (are_universals_equal(psource, &req->source)) { + if (req->present) { + /* psource enables the subject, but other sources may + * also be required (or required to be absent). */ + requirement_vector_iterate(psubjreqs, coreq) { + if (!are_universals_equal(psource, &coreq->source)) { + universal_name_translation(&coreq->source, buf2, sizeof(buf2)); + strvec_append(coreq->present ? coreqs : conoreqs, buf2); + } + } requirement_vector_iterate_end; + + if (0 < strvec_size(coreqs)) { + if (0 < strvec_size(conoreqs)) { + cat_snprintf(buf, bufsz, + Q_(strs[0]), /* "Allows %s (with %s but no %s)." */ + subjstr, + strvec_to_and_list(coreqs, &coreqstr), + strvec_to_or_list(conoreqs, &conoreqstr)); + } else { + cat_snprintf(buf, bufsz, + Q_(strs[1]), /* "Allows %s (with %s)." */ + subjstr, + strvec_to_and_list(coreqs, &coreqstr)); + } + } else { + if (0 < strvec_size(conoreqs)) { + cat_snprintf(buf, bufsz, + Q_(strs[2]), /* "Allows %s (absent %s)." */ + subjstr, + strvec_to_and_list(conoreqs, &conoreqstr)); + } else { + cat_snprintf(buf, bufsz, + Q_(strs[3]), /* "Allows %s." */ + subjstr); + } + } + } else { + /* psource can, on its own, prevent the subject. */ + cat_snprintf(buf, bufsz, + Q_(strs[4]), /* "Prevents %s." */ + subjstr); + } + cat_snprintf(buf, bufsz, "\n"); + } + } requirement_vector_iterate_end; + + strvec_destroy(coreqs); + strvec_destroy(conoreqs); + astr_free(&coreqstr); + astr_free(&conoreqstr); +} + +/**************************************************************************** Generate text for what this requirement source allows. Something like "Allows Communism (with University).\n" @@ -2631,8 +2704,8 @@ "Prevents Harbor.\n" This should be called to generate helptext for every possible source - type. Note this doesn't handle effects but rather production - requirements (currently only building reqs). + type. Note this doesn't handle effects but rather requirements to + create/maintain things (currently only building/government reqs). NB: This function overwrites any existing buffer contents by writing the generated text to the start of the given 'buf' pointer (i.e. it does @@ -2641,67 +2714,43 @@ static void insert_allows(struct universal *psource, char *buf, size_t bufsz) { - struct strvec *coreqs = strvec_new(); - struct strvec *conoreqs = strvec_new(); - struct astring coreqstr = ASTRING_INIT; - struct astring conoreqstr = ASTRING_INIT; - char buf2[bufsz]; - buf[0] = '\0'; - /* FIXME: show other data like range and survives. */ + governments_iterate(pgov) { + static const char *const govstrs[] = { + /* TRANS: First %s is a government name. */ + N_("?gov:* Allows %s (with %s but no %s)."), + /* TRANS: First %s is a government name. */ + N_("?gov:* Allows %s (with %s)."), + /* TRANS: First %s is a government name. */ + N_("?gov:* Allows %s (absent %s)."), + /* TRANS: %s is a government name. */ + N_("?gov:* Allows %s."), + /* TRANS: %s is a government name. */ + N_("?gov:* Prevents %s.") + }; + insert_allows_single(psource, &pgov->reqs, + government_name_translation(pgov), govstrs, + buf, bufsz); + } governments_iterate_end; improvement_iterate(pimprove) { - requirement_vector_iterate(&pimprove->reqs, req) { - if (are_universals_equal(psource, &req->source)) { - if (req->present) { - /* This source enables a building, but other sources may - * also be required (or required to be absent). */ - strvec_clear(coreqs); - strvec_clear(conoreqs); - - requirement_vector_iterate(&pimprove->reqs, coreq) { - if (!are_universals_equal(psource, &coreq->source)) { - universal_name_translation(&coreq->source, buf2, sizeof(buf2)); - strvec_append(coreq->present ? coreqs : conoreqs, buf2); - } - } requirement_vector_iterate_end; - - if (0 < strvec_size(coreqs)) { - if (0 < strvec_size(conoreqs)) { - cat_snprintf(buf, bufsz, _("Allows %s (with %s but no %s)."), - improvement_name_translation(pimprove), - strvec_to_and_list(coreqs, &coreqstr), - strvec_to_or_list(conoreqs, &conoreqstr)); - } else { - cat_snprintf(buf, bufsz, _("Allows %s (with %s)."), - improvement_name_translation(pimprove), - strvec_to_and_list(coreqs, &coreqstr)); - } - } else { - if (0 < strvec_size(conoreqs)) { - cat_snprintf(buf, bufsz, _("Allows %s (absent %s)."), - improvement_name_translation(pimprove), - strvec_to_and_list(conoreqs, &conoreqstr)); - } else { - cat_snprintf(buf, bufsz, _("Allows %s."), - improvement_name_translation(pimprove)); - } - } - } else { - /* This source can, on its own, prevent a building. */ - cat_snprintf(buf, bufsz, _("Prevents %s."), - improvement_name_translation(pimprove)); - } - cat_snprintf(buf, bufsz, "\n"); - } - } requirement_vector_iterate_end; + static const char *const imprstrs[] = { + /* TRANS: First %s is a building name. */ + N_("?improvement:* Allows %s (with %s but no %s)."), + /* TRANS: First %s is a building name. */ + N_("?improvement:* Allows %s (with %s)."), + /* TRANS: First %s is a building name. */ + N_("?improvement:* Allows %s (absent %s)."), + /* TRANS: %s is a building name. */ + N_("?improvement:* Allows %s."), + /* TRANS: %s is a building name. */ + N_("?improvement:* Prevents %s.") + }; + insert_allows_single(psource, &pimprove->reqs, + improvement_name_translation(pimprove), imprstrs, + buf, bufsz); } improvement_iterate_end; - - strvec_destroy(coreqs); - strvec_destroy(conoreqs); - astr_free(&coreqstr); - astr_free(&conoreqstr); } /**************************************************************** _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits