From b1e0f53c4644125d37a1231160cbc9e638126871 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 1 Apr 2023 05:28:40 +0300 Subject: [PATCH 15/15] gtk research dialog: Set Future Tech to menu immediately When last regular tech got researched, the old code listed only current research, which at that point was "None" in the research target menus. Make it Future Tech instead. See osdn #45434 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/repodlgs.c | 97 +++++++++++++++++++++++----------- client/gui-gtk-3.22/repodlgs.c | 97 +++++++++++++++++++++++----------- client/gui-gtk-4.0/repodlgs.c | 97 +++++++++++++++++++++++----------- common/research.c | 14 +++++ common/research.h | 2 + 5 files changed, 211 insertions(+), 96 deletions(-) diff --git a/client/gui-gtk-3.0/repodlgs.c b/client/gui-gtk-3.0/repodlgs.c index ec2fdb0bfd..a58e5df2d1 100644 --- a/client/gui-gtk-3.0/repodlgs.c +++ b/client/gui-gtk-3.0/repodlgs.c @@ -413,12 +413,6 @@ static void science_report_update(struct science_report *preport) store = GTK_LIST_STORE(gtk_combo_box_get_model(preport->reachable_techs)); gtk_list_store_clear(store); sorting_list = NULL; - if (A_UNSET == presearch->researching - || is_future_tech(presearch->researching)) { - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, presearch->researching); - gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); - } /* Collect all techs which are reachable in the next step. */ advance_index_iterate(A_FIRST, i) { @@ -427,20 +421,43 @@ static void science_report_update(struct science_report *preport) } } advance_index_iterate_end; - /* Sort the list, append it to the store. */ - sorting_list = g_list_sort(sorting_list, cmp_func); - for (item = sorting_list; NULL != item; item = g_list_next(item)) { - tech = GPOINTER_TO_INT(item->data); - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, tech); - if (tech == presearch->researching) { + if (sorting_list != NULL) { + if (A_UNSET == presearch->researching + || is_future_tech(presearch->researching)) { + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, presearch->researching); gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); } + + /* Sort the list, append it to the store. */ + sorting_list = g_list_sort(sorting_list, cmp_func); + for (item = sorting_list; NULL != item; item = g_list_next(item)) { + tech = GPOINTER_TO_INT(item->data); + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, tech); + if (tech == presearch->researching) { + gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); + } + } + + /* Free, re-init. */ + g_list_free(sorting_list); + sorting_list = NULL; + } else { + /* No reachable normal techs. Can we select Future Tech? */ + Tech_type_id next; + + gtk_list_store_append(store, &iter); + if (research_future_next(presearch)) { + next = A_FUTURE; + } else { + next = presearch->researching; + } + science_report_store_set(store, &iter, next); + + gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); } - /* Free, re-init. */ - g_list_free(sorting_list); - sorting_list = NULL; store = GTK_LIST_STORE(gtk_combo_box_get_model(preport->reachable_goals)); gtk_list_store_clear(store); @@ -448,12 +465,6 @@ static void science_report_update(struct science_report *preport) gtk_label_set_text(preport->goal_label, get_science_goal_text(presearch->tech_goal)); - if (A_UNSET == presearch->tech_goal) { - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, A_UNSET); - gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); - } - /* Collect all techs which are reachable in next 10 steps. */ advance_index_iterate(A_FIRST, i) { if (research_invention_reachable(presearch, i) @@ -464,19 +475,41 @@ static void science_report_update(struct science_report *preport) } } advance_index_iterate_end; - /* Sort the list, append it to the store. */ - sorting_list = g_list_sort(sorting_list, cmp_func); - for (item = sorting_list; NULL != item; item = g_list_next(item)) { - tech = GPOINTER_TO_INT(item->data); - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, tech); - if (tech == presearch->tech_goal) { + if (sorting_list != NULL) { + if (A_UNSET == presearch->tech_goal) { + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, A_UNSET); gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); } - } - /* Free. */ - g_list_free(sorting_list); + /* Sort the list, append it to the store. */ + sorting_list = g_list_sort(sorting_list, cmp_func); + for (item = sorting_list; NULL != item; item = g_list_next(item)) { + tech = GPOINTER_TO_INT(item->data); + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, tech); + if (tech == presearch->tech_goal) { + gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); + } + } + + /* Free. */ + g_list_free(sorting_list); + } else { + /* No reachable normal techs. Can we select Future Tech? */ + Tech_type_id goal; + + gtk_list_store_append(store, &iter); + + if (research_future_next(presearch)) { + goal = A_FUTURE; + } else { + goal = A_UNSET; + } + + science_report_store_set(store, &iter, goal); + gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); + } /* Re-enable callbacks. */ science_report_no_combo_callback = FALSE; diff --git a/client/gui-gtk-3.22/repodlgs.c b/client/gui-gtk-3.22/repodlgs.c index 1057c644f8..f29d2da17f 100644 --- a/client/gui-gtk-3.22/repodlgs.c +++ b/client/gui-gtk-3.22/repodlgs.c @@ -411,12 +411,6 @@ static void science_report_update(struct science_report *preport) store = GTK_LIST_STORE(gtk_combo_box_get_model(preport->reachable_techs)); gtk_list_store_clear(store); sorting_list = NULL; - if (A_UNSET == presearch->researching - || is_future_tech(presearch->researching)) { - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, presearch->researching); - gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); - } /* Collect all techs which are reachable in the next step. */ advance_index_iterate(A_FIRST, i) { @@ -425,20 +419,43 @@ static void science_report_update(struct science_report *preport) } } advance_index_iterate_end; - /* Sort the list, append it to the store. */ - sorting_list = g_list_sort(sorting_list, cmp_func); - for (item = sorting_list; NULL != item; item = g_list_next(item)) { - tech = GPOINTER_TO_INT(item->data); - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, tech); - if (tech == presearch->researching) { + if (sorting_list != NULL) { + if (A_UNSET == presearch->researching + || is_future_tech(presearch->researching)) { + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, presearch->researching); gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); } + + /* Sort the list, append it to the store. */ + sorting_list = g_list_sort(sorting_list, cmp_func); + for (item = sorting_list; NULL != item; item = g_list_next(item)) { + tech = GPOINTER_TO_INT(item->data); + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, tech); + if (tech == presearch->researching) { + gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); + } + } + + /* Free, re-init. */ + g_list_free(sorting_list); + sorting_list = NULL; + } else { + /* No reachable normal techs. Can we select Future Tech? */ + Tech_type_id next; + + gtk_list_store_append(store, &iter); + if (research_future_next(presearch)) { + next = A_FUTURE; + } else { + next = presearch->researching; + } + science_report_store_set(store, &iter, next); + + gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); } - /* Free, re-init. */ - g_list_free(sorting_list); - sorting_list = NULL; store = GTK_LIST_STORE(gtk_combo_box_get_model(preport->reachable_goals)); gtk_list_store_clear(store); @@ -446,12 +463,6 @@ static void science_report_update(struct science_report *preport) gtk_label_set_text(preport->goal_label, get_science_goal_text(presearch->tech_goal)); - if (A_UNSET == presearch->tech_goal) { - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, A_UNSET); - gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); - } - /* Collect all techs which are reachable in next 10 steps. */ advance_index_iterate(A_FIRST, i) { if (research_invention_reachable(presearch, i) @@ -462,19 +473,41 @@ static void science_report_update(struct science_report *preport) } } advance_index_iterate_end; - /* Sort the list, append it to the store. */ - sorting_list = g_list_sort(sorting_list, cmp_func); - for (item = sorting_list; NULL != item; item = g_list_next(item)) { - tech = GPOINTER_TO_INT(item->data); - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, tech); - if (tech == presearch->tech_goal) { + if (sorting_list != NULL) { + if (A_UNSET == presearch->tech_goal) { + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, A_UNSET); gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); } - } - /* Free. */ - g_list_free(sorting_list); + /* Sort the list, append it to the store. */ + sorting_list = g_list_sort(sorting_list, cmp_func); + for (item = sorting_list; NULL != item; item = g_list_next(item)) { + tech = GPOINTER_TO_INT(item->data); + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, tech); + if (tech == presearch->tech_goal) { + gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); + } + } + + /* Free. */ + g_list_free(sorting_list); + } else { + /* No reachable normal techs. Can we select Future Tech? */ + Tech_type_id goal; + + gtk_list_store_append(store, &iter); + + if (research_future_next(presearch)) { + goal = A_FUTURE; + } else { + goal = A_UNSET; + } + + science_report_store_set(store, &iter, goal); + gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); + } /* Re-enable callbacks. */ science_report_no_combo_callback = FALSE; diff --git a/client/gui-gtk-4.0/repodlgs.c b/client/gui-gtk-4.0/repodlgs.c index e1815c7e6a..cfbe78aec7 100644 --- a/client/gui-gtk-4.0/repodlgs.c +++ b/client/gui-gtk-4.0/repodlgs.c @@ -450,12 +450,6 @@ static void science_report_update(struct science_report *preport) store = GTK_LIST_STORE(gtk_combo_box_get_model(preport->reachable_techs)); gtk_list_store_clear(store); sorting_list = NULL; - if (A_UNSET == presearch->researching - || is_future_tech(presearch->researching)) { - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, presearch->researching); - gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); - } /* Collect all techs which are reachable in the next step. */ advance_index_iterate(A_FIRST, i) { @@ -464,20 +458,43 @@ static void science_report_update(struct science_report *preport) } } advance_index_iterate_end; - /* Sort the list, append it to the store. */ - sorting_list = g_list_sort(sorting_list, cmp_func); - for (item = sorting_list; NULL != item; item = g_list_next(item)) { - tech = GPOINTER_TO_INT(item->data); - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, tech); - if (tech == presearch->researching) { + if (sorting_list != NULL) { + if (A_UNSET == presearch->researching + || is_future_tech(presearch->researching)) { + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, presearch->researching); gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); } + + /* Sort the list, append it to the store. */ + sorting_list = g_list_sort(sorting_list, cmp_func); + for (item = sorting_list; NULL != item; item = g_list_next(item)) { + tech = GPOINTER_TO_INT(item->data); + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, tech); + if (tech == presearch->researching) { + gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); + } + } + + /* Free, re-init. */ + g_list_free(sorting_list); + sorting_list = NULL; + } else { + /* No reachable normal techs. Can we select Future Tech? */ + Tech_type_id next; + + gtk_list_store_append(store, &iter); + if (research_future_next(presearch)) { + next = A_FUTURE; + } else { + next = presearch->researching; + } + science_report_store_set(store, &iter, next); + + gtk_combo_box_set_active_iter(preport->reachable_techs, &iter); } - /* Free, re-init. */ - g_list_free(sorting_list); - sorting_list = NULL; store = GTK_LIST_STORE(gtk_combo_box_get_model(preport->reachable_goals)); gtk_list_store_clear(store); @@ -485,12 +502,6 @@ static void science_report_update(struct science_report *preport) gtk_label_set_text(preport->goal_label, get_science_goal_text(presearch->tech_goal)); - if (A_UNSET == presearch->tech_goal) { - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, A_UNSET); - gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); - } - /* Collect all techs which are reachable in next 10 steps. */ advance_index_iterate(A_FIRST, i) { if (research_invention_reachable(presearch, i) @@ -501,19 +512,41 @@ static void science_report_update(struct science_report *preport) } } advance_index_iterate_end; - /* Sort the list, append it to the store. */ - sorting_list = g_list_sort(sorting_list, cmp_func); - for (item = sorting_list; NULL != item; item = g_list_next(item)) { - tech = GPOINTER_TO_INT(item->data); - gtk_list_store_append(store, &iter); - science_report_store_set(store, &iter, tech); - if (tech == presearch->tech_goal) { + if (sorting_list != NULL) { + if (A_UNSET == presearch->tech_goal) { + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, A_UNSET); gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); } - } - /* Free. */ - g_list_free(sorting_list); + /* Sort the list, append it to the store. */ + sorting_list = g_list_sort(sorting_list, cmp_func); + for (item = sorting_list; NULL != item; item = g_list_next(item)) { + tech = GPOINTER_TO_INT(item->data); + gtk_list_store_append(store, &iter); + science_report_store_set(store, &iter, tech); + if (tech == presearch->tech_goal) { + gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); + } + } + + /* Free. */ + g_list_free(sorting_list); + } else { + /* No reachable normal techs. Can we select Future Tech? */ + Tech_type_id goal; + + gtk_list_store_append(store, &iter); + + if (research_future_next(presearch)) { + goal = A_FUTURE; + } else { + goal = A_UNSET; + } + + science_report_store_set(store, &iter, goal); + gtk_combo_box_set_active_iter(preport->reachable_goals, &iter); + } /* Re-enable callbacks. */ science_report_no_combo_callback = FALSE; diff --git a/common/research.c b/common/research.c index 48380d5425..ca90582342 100644 --- a/common/research.c +++ b/common/research.c @@ -1328,3 +1328,17 @@ int recalculate_techs_researched(const struct research *presearch) return techs + presearch->future_tech; } + +/************************************************************************//** + Is this research group going to research some Future Tech next? +****************************************************************************/ +bool research_future_next(const struct research *presearch) +{ + advance_index_iterate(A_FIRST, i) { + if (research_invention_state(presearch, i) != TECH_KNOWN) { + return FALSE; + } + } advance_index_iterate_end; + + return TRUE; +} diff --git a/common/research.h b/common/research.h index 558b5c00cc..0002c4595b 100644 --- a/common/research.h +++ b/common/research.h @@ -173,6 +173,8 @@ struct iterator *research_player_iter_init(struct research_player_iter *it, int recalculate_techs_researched(const struct research *presearch); +bool research_future_next(const struct research *presearch); + #ifdef __cplusplus } #endif /* __cplusplus */ -- 2.39.2