71 struct unit_list *potential_tgt_units,
72 struct unit *suggested_tgt_unit,
73 const gchar *dlg_title,
74 const gchar *actor_label,
75 const gchar *tgt_label,
76 const gchar *do_label,
77 GCallback do_callback)
86 GtkWidget *default_option = NULL;
87 GtkWidget *first_option = NULL;
91 const struct unit *default_unit = NULL;
93 dlg = gtk_dialog_new_with_buttons(dlg_title, NULL, 0,
94 _(
"Close"), GTK_RESPONSE_NO,
95 do_label, GTK_RESPONSE_YES,
98 gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_NO);
99 gtk_window_set_destroy_with_parent(GTK_WINDOW(dlg),
TRUE);
101 main_box = gtk_grid_new();
102 gtk_orientable_set_orientation(GTK_ORIENTABLE(main_box),
103 GTK_ORIENTATION_VERTICAL);
104 box = gtk_grid_new();
105 gtk_orientable_set_orientation(GTK_ORIENTABLE(box),
106 GTK_ORIENTATION_HORIZONTAL);
108 lbl = gtk_label_new(actor_label);
109 gtk_grid_attach(GTK_GRID(box), lbl, 0, 0, 1, 1);
115 icon = gtk_image_new();
117 gtk_grid_attach(GTK_GRID(box), icon, 1, 0, 1, 1);
120 gtk_grid_attach(GTK_GRID(box), lbl, 2, 0, 1, 1);
122 gtk_container_add(GTK_CONTAINER(main_box), box);
124 sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
125 gtk_container_add(GTK_CONTAINER(main_box), sep);
127 lbl = gtk_label_new(tgt_label);
128 gtk_container_add(GTK_CONTAINER(main_box), lbl);
130 box = gtk_grid_new();
139 cbdata->
tp_id = ptgt->id;
142 radio = gtk_radio_button_new_from_widget(
143 GTK_RADIO_BUTTON(first_option));
144 if (first_option == NULL) {
145 first_option = radio;
146 default_option = first_option;
152 GTK_RADIO_BUTTON(radio)))
153 == g_slist_length(gtk_radio_button_get_group(
154 GTK_RADIO_BUTTON(first_option))),
155 "The radio button for '%s' is broken.",
157 g_signal_connect(radio,
"toggled",
159 g_signal_connect(radio,
"destroy",
161 if (ptgt == suggested_tgt_unit) {
162 default_option = radio;
163 default_unit = suggested_tgt_unit;
165 gtk_grid_attach(GTK_GRID(box), radio, 0, tcount, 1, 1);
169 icon = gtk_image_new_from_pixbuf(tubuf);
170 g_object_unref(tubuf);
172 icon = gtk_image_new();
174 gtk_grid_attach(GTK_GRID(box), icon, 1, tcount, 1, 1);
177 gtk_grid_attach(GTK_GRID(box), lbl, 2, tcount, 1, 1);
181 gtk_container_add(GTK_CONTAINER(main_box), box);
184 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(default_option),
TRUE);
187 GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(
dlg))),
190 g_object_set_data(G_OBJECT(
dlg),
"actor", GINT_TO_POINTER(
actor->
id));
191 g_object_set_data(G_OBJECT(
dlg),
"tile", ptile);
196 if (default_unit != NULL) {
197 g_object_set_data(G_OBJECT(
dlg),
"target", GINT_TO_POINTER(default_unit->
id));
200 g_signal_connect(
dlg,
"response", do_callback,
actor);
202 gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(
dlg)));
203 gtk_widget_show(
dlg);
bool select_tgt_unit(struct unit *actor, struct tile *ptile, struct unit_list *potential_tgt_units, struct unit *suggested_tgt_unit, const gchar *dlg_title, const gchar *actor_label, const gchar *tgt_label, const gchar *do_label, GCallback do_callback)