From c48f30d80a679dff8788500ef96f58d8d060db8e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 1 Apr 2023 05:28:40 +0300 Subject: [PATCH 21/21] 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.22/repodlgs.c | 97 +++++++++++++++++++++++----------- client/gui-gtk-4.0/repodlgs.c | 97 +++++++++++++++++++++++----------- common/research.c | 14 +++++ common/research.h | 2 + 4 files changed, 146 insertions(+), 64 deletions(-) diff --git a/client/gui-gtk-3.22/repodlgs.c b/client/gui-gtk-3.22/repodlgs.c index c5840919f1..cde20c895f 100644 --- a/client/gui-gtk-3.22/repodlgs.c +++ b/client/gui-gtk-3.22/repodlgs.c @@ -412,12 +412,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_max(A_FIRST, i, ac) { @@ -426,20 +420,43 @@ static void science_report_update(struct science_report *preport) } } advance_index_iterate_max_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); @@ -447,12 +464,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_max(A_FIRST, i, ac) { if (research_invention_reachable(presearch, i) @@ -463,19 +474,41 @@ static void science_report_update(struct science_report *preport) } } advance_index_iterate_max_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 a166d5a2ec..a9820ddf58 100644 --- a/client/gui-gtk-4.0/repodlgs.c +++ b/client/gui-gtk-4.0/repodlgs.c @@ -451,12 +451,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_max(A_FIRST, i, ac) { @@ -465,20 +459,43 @@ static void science_report_update(struct science_report *preport) } } advance_index_iterate_max_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); @@ -486,12 +503,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_max(A_FIRST, i, ac) { if (research_invention_reachable(presearch, i) @@ -502,19 +513,41 @@ static void science_report_update(struct science_report *preport) } } advance_index_iterate_max_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 3ec1a41bba..5345eea944 100644 --- a/common/research.c +++ b/common/research.c @@ -1354,3 +1354,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 a44b54da94..6edccb6c28 100644 --- a/common/research.h +++ b/common/research.h @@ -173,6 +173,8 @@ int research_count(void); int recalculate_techs_researched(const struct research *presearch); +bool research_future_next(const struct research *presearch); + #ifdef __cplusplus } #endif /* __cplusplus */ -- 2.39.2