From 173a6ad321d44b5a6bcb715605b497e3f670e14c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 1 Apr 2023 05:35:14 +0300 Subject: [PATCH 9/9] gtk3(.22) 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 +++++++++++++++++++++++----------- common/research.c | 14 +++++ common/research.h | 4 +- 4 files changed, 147 insertions(+), 65 deletions(-) diff --git a/client/gui-gtk-3.0/repodlgs.c b/client/gui-gtk-3.0/repodlgs.c index ffb75f38be..db3f6d8237 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 6182460aca..d2ece1c83f 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/common/research.c b/common/research.c index 1444445df9..28bc8531c1 100644 --- a/common/research.c +++ b/common/research.c @@ -1348,3 +1348,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 876bc97c82..0cb7a4b19e 100644 --- a/common/research.h +++ b/common/research.h @@ -173,8 +173,10 @@ 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 */ -#endif /* FC__RESEARCH_H */ +#endif /* FC__RESEARCH_H */ -- 2.39.2