From 4cdc03f827e984c248d38369e3c7649f2dddaad4 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 10 Dec 2022 03:57:22 +0200 Subject: [PATCH 40/40] gtk4: Add max_growth CMA setting support See osdn #46234 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/cma_fe.c | 49 +++++++++++++++++++++++++------------ client/gui-gtk-4.0/cma_fe.h | 3 ++- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/client/gui-gtk-4.0/cma_fe.c b/client/gui-gtk-4.0/cma_fe.c index e306b94707..46039e764f 100644 --- a/client/gui-gtk-4.0/cma_fe.c +++ b/client/gui-gtk-4.0/cma_fe.c @@ -68,7 +68,7 @@ static gboolean cma_preset_key_pressed_callback(GtkWidget *w, GdkEvent *ev, static void cma_del_preset_callback(GtkWidget *w, gpointer data); static void cma_preset_remove(struct cma_dialog *pdialog, int preset_index); static void cma_preset_remove_response(GtkWidget *w, gint response, - gpointer data); + gpointer data); static void cma_add_preset_callback(GtkWidget *w, gpointer data); static void cma_preset_add_popup_callback(gpointer data, gint response, @@ -76,11 +76,11 @@ static void cma_preset_add_popup_callback(gpointer data, gint response, static void cma_active_callback(GtkWidget *w, gpointer data); static void cma_activate_preset_callback(GtkTreeView *view, GtkTreePath *path, - GtkTreeViewColumn *col, gpointer data); + GtkTreeViewColumn *col, gpointer data); static void hscale_changed(GtkWidget *get, gpointer data); static void set_hscales(const struct cm_parameter *const parameter, - struct cma_dialog *pdialog); + struct cma_dialog *pdialog); /**********************************************************************//** Initialize cma front end system @@ -413,7 +413,6 @@ struct cma_dialog *create_cma_dialog(struct city *pcity, bool tiny) } output_type_iterate_end; /* Happy Surplus and Factor */ - label = gtk_label_new(_("Celebrate")); gtk_grid_attach(GTK_GRID(table), label, 0, O_LAST + 1, 1, 1); gtk_widget_set_halign(label, GTK_ALIGN_START); @@ -446,8 +445,22 @@ struct cma_dialog *create_cma_dialog(struct city *pcity, bool tiny) "value-changed", G_CALLBACK(hscale_changed), pdialog); - /* Buttons */ + /* Maximize Growth */ + label = gtk_label_new(_("Maximize growth")); + gtk_grid_attach(GTK_GRID(table), label, 0, O_LAST + 2, 1, 1); + gtk_widget_set_halign(label, GTK_ALIGN_START); + gtk_widget_set_valign(label, GTK_ALIGN_CENTER); + pdialog->growth_button = gtk_check_button_new(); + gtk_widget_set_halign(pdialog->growth_button, GTK_ALIGN_END); + gtk_check_button_set_active(GTK_CHECK_BUTTON(pdialog->growth_button), + FALSE); + gtk_grid_attach(GTK_GRID(table), pdialog->growth_button, 1, O_LAST + 2, 1, 1); + + g_signal_connect(pdialog->growth_button, "toggled", + G_CALLBACK(hscale_changed), pdialog); + + /* Buttons */ hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2); gtk_grid_attach(GTK_GRID(vgrid), hbox, 0, grid_row++, 1, 1); @@ -561,7 +574,7 @@ static void cma_activate_preset_callback(GtkTreeView *view, GtkTreePath *path, pparam = cmafec_preset_get_parameter(preset_index); - /* save the change */ + /* Save the change */ cmafec_set_fe_parameter(pdialog->pcity, pparam); if (cma_is_city_under_agent(pdialog->pcity, NULL)) { @@ -610,7 +623,7 @@ static void cma_preset_add_popup_callback(gpointer data, gint response, cmafec_preset_add(input, ¶m); update_cma_preset_list(pdialog); refresh_cma_dialog(pdialog->pcity, DONT_REFRESH_HSCALES); - /* if this or other cities have this set as "custom" */ + /* If this or other cities have this set as "custom" */ city_report_dialog_update(); } /* else CANCEL or DELETE_EVENT */ @@ -676,17 +689,17 @@ static void cma_preset_remove(struct cma_dialog *pdialog, int preset_index) pdialog->id = preset_index; shl = gtk_message_dialog_new(NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - _("Remove this preset?")); + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + _("Remove this preset?")); setup_dialog(shl, parent); pdialog->preset_remove_shell = shl; gtk_window_set_title(GTK_WINDOW(shl), cmafec_preset_get_descr(preset_index)); g_signal_connect(shl, "response", - G_CALLBACK(cma_preset_remove_response), pdialog); + G_CALLBACK(cma_preset_remove_response), pdialog); gtk_window_present(GTK_WINDOW(shl)); } @@ -735,7 +748,7 @@ static void cma_active_callback(GtkWidget *w, gpointer data) notice that we don't want to call update_result here. **************************************************************************/ static void set_hscales(const struct cm_parameter *const parameter, - struct cma_dialog *pdialog) + struct cma_dialog *pdialog) { allow_refreshes = 0; output_type_iterate(i) { @@ -745,6 +758,8 @@ static void set_hscales(const struct cm_parameter *const parameter, } output_type_iterate_end; gtk_check_button_set_active(GTK_CHECK_BUTTON(pdialog->happy_button), parameter->require_happy); + gtk_check_button_set_active(GTK_CHECK_BUTTON(pdialog->growth_button), + parameter->max_growth); gtk_range_set_value(GTK_RANGE(pdialog->factor[O_LAST]), parameter->happy_factor); allow_refreshes = 1; @@ -770,14 +785,16 @@ static void hscale_changed(GtkWidget *get, gpointer data) (int) (gtk_range_get_value(GTK_RANGE(pdialog->factor[i]))); } output_type_iterate_end; param.require_happy = - (gtk_check_button_get_active(GTK_CHECK_BUTTON(pdialog->happy_button)) ? 1 : 0); + (gtk_check_button_get_active(GTK_CHECK_BUTTON(pdialog->happy_button)) ? TRUE : FALSE); + param.max_growth = + (gtk_check_button_get_active(GTK_CHECK_BUTTON(pdialog->growth_button)) ? TRUE : FALSE); param.happy_factor = (int) (gtk_range_get_value(GTK_RANGE(pdialog->factor[O_LAST]))); - /* save the change */ + /* Save the change */ cmafec_set_fe_parameter(pdialog->pcity, ¶m); - /* refreshes the cma */ + /* Refreshes the cma */ if (cma_is_city_under_agent(pdialog->pcity, NULL)) { cma_release_city(pdialog->pcity); cma_put_city_under_agent(pdialog->pcity, ¶m); diff --git a/client/gui-gtk-4.0/cma_fe.h b/client/gui-gtk-4.0/cma_fe.h index 751a8feda0..b7e0825a4e 100644 --- a/client/gui-gtk-4.0/cma_fe.h +++ b/client/gui-gtk-4.0/cma_fe.h @@ -40,10 +40,11 @@ struct cma_dialog { GtkWidget *active_command; GtkWidget *minimal_surplus[O_LAST]; GtkWidget *happy_button; + GtkWidget *growth_button; GtkWidget *factor[O_LAST + 1]; GtkTreeSelection *selection; GtkListStore *store; - int id; /* needed to pass a preset_index */ + int id; /* Needed to pass a preset_index */ }; void cma_fe_init(void); -- 2.35.1