Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-gtk-3.22/cma_fe.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
cma_fe.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2001 - R. Falke, M. Kaufman
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <gdk/gdkkeysyms.h>
19
20/* utility */
21#include "fcintl.h"
22#include "log.h"
23#include "mem.h"
24#include "support.h"
25
26/* common */
27#include "events.h"
28#include "game.h"
29
30/* client */
31#include "chatline_g.h"
32#include "citydlg_g.h"
33#include "client_main.h"
34#include "cma_fec.h"
35#include "messagewin_g.h"
36#include "options.h"
37
38/* client/gui-gtk-3.22 */
39#include "cityrep.h"
40#include "dialogs.h"
41#include "gui_main.h"
42#include "gui_stuff.h"
43#include "helpdlg.h"
44#include "inputdlg.h"
45
46#include "cma_fe.h"
47
48#define BUFFER_SIZE 64
49
50#define SPECLIST_TAG dialog
51#define SPECLIST_TYPE struct cma_dialog
52#include "speclist.h"
53
54#define dialog_list_iterate(dialoglist, pdialog) \
55 TYPED_LIST_ITERATE(struct cma_dialog, dialoglist, pdialog)
56#define dialog_list_iterate_end LIST_ITERATE_END
57
58 static struct dialog_list *dialog_list;
59
60 static int allow_refreshes = 1;
61
62static struct cma_dialog *get_cma_dialog(struct city *pcity);
63
64static void update_cma_preset_list(struct cma_dialog *pdialog);
65
66static gboolean cma_preset_key_pressed_callback(GtkWidget *w, GdkEventKey *ev,
67 gpointer data);
68static void cma_del_preset_callback(GtkWidget *w, gpointer data);
69static void cma_preset_remove(struct cma_dialog *pdialog, int preset_index);
70static void cma_preset_remove_response(GtkWidget *w, gint response,
71 gpointer data);
72
73static void cma_add_preset_callback(GtkWidget *w, gpointer data);
74static void cma_preset_add_popup_callback(gpointer data, gint response,
75 const char *input);
76
77static void cma_active_callback(GtkWidget *w, gpointer data);
78static void cma_activate_preset_callback(GtkTreeView *view, GtkTreePath *path,
79 GtkTreeViewColumn *col, gpointer data);
80
81static void hscale_changed(GtkWidget *get, gpointer data);
82static void set_hscales(const struct cm_parameter *const parameter,
83 struct cma_dialog *pdialog);
84
85/**********************************************************************/
88 void cma_fe_init(void)
89{
90 dialog_list = dialog_list_new();
91}
92
93/**********************************************************************/
96 void cma_fe_done(void)
97{
98 dialog_list_destroy(dialog_list);
99}
100
101/**********************************************************************/
104 void close_cma_dialog(struct city *pcity)
105{
106 struct cma_dialog *pdialog = get_cma_dialog(pcity);
107
108 if (pdialog == NULL) {
109 /* A city which is being investigated doesn't contain cma dialog */
110 return;
111 }
112 gtk_widget_destroy(pdialog->shell);
113}
114
115/**********************************************************************/
118 static void cma_dialog_destroy_callback(GtkWidget *w, gpointer data)
119{
120 struct cma_dialog *pdialog = (struct cma_dialog *) data;
121
122 dialog_list_remove(dialog_list, pdialog);
123 free(pdialog);
124}
125
126/**********************************************************************/
129 struct cma_dialog *get_cma_dialog(struct city *pcity)
130{
131 dialog_list_iterate(dialog_list, pdialog) {
132 if (pdialog->pcity == pcity) {
133 return pdialog;
134 }
135 } dialog_list_iterate_end;
136
137 return NULL;
138}
139
140/**********************************************************************/
143 static gboolean button_press_callback(GtkTreeView *view, GdkEventButton *ev,
144 gpointer data)
145{
146 GtkTreePath *path;
147 GtkTreeViewColumn *column;
148
149 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(view),
150 ev->x, ev->y, &path, &column, NULL, NULL)) {
151 if (ev->type == GDK_BUTTON_PRESS) {
152 cma_activate_preset_callback(view, path, column, data);
153 } else if (ev->type == GDK_2BUTTON_PRESS) {
154 struct cma_dialog *pdialog = (struct cma_dialog *) data;
155 struct cm_parameter param;
156
157 cmafec_get_fe_parameter(pdialog->pcity, &param);
158 cma_put_city_under_agent(pdialog->pcity, &param);
159 refresh_city_dialog(pdialog->pcity);
160 }
161 }
162 gtk_tree_path_free(path);
163
164 return FALSE;
165}
166
167/**********************************************************************/
170 static void help_callback(GtkWidget *w, gpointer data)
171{
172 popup_help_dialog_string(HELP_CMA_ITEM);
173}
174
175/**********************************************************************/
178 static void cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *cell,
179 GtkTreeModel *model, GtkTreeIter *it, gpointer data)
180{
181 struct cma_dialog *pdialog = (struct cma_dialog *) data;
182 char *s1;
183 const char *s2;
184 int i1, i2;
185 struct cm_parameter param;
186 GtkTreePath *path;
187
188 gtk_tree_model_get(model, it, 0, &s1, -1);
189 if (s1 == NULL) {
190 return;
191 }
192 path = gtk_tree_model_get_path(model, it);
193 i1 = gtk_tree_path_get_indices(path)[0];
194 gtk_tree_path_free(path);
195
196 cmafec_get_fe_parameter(pdialog->pcity, &param);
197 s2 = cmafec_get_short_descr(&param);
198 i2 = cmafec_preset_get_index_of_parameter(&param);
199
200 if (!strcmp(s1, s2) && i1 == i2) {
201 g_object_set(G_OBJECT(cell), "style", PANGO_STYLE_ITALIC,
202 "weight", PANGO_WEIGHT_BOLD, NULL);
203 } else {
204 g_object_set(G_OBJECT(cell), "style", PANGO_STYLE_NORMAL,
205 "weight", PANGO_WEIGHT_NORMAL, NULL);
206 }
207
208 g_free(s1);
209}
210
211/**********************************************************************/
214 struct cma_dialog *create_cma_dialog(struct city *pcity, bool tiny)
215{
216 struct cma_dialog *pdialog;
217 struct cm_parameter param;
218 GtkWidget *frame, *page, *hbox, *label, *table;
219 GtkWidget *vbox, *sw, *hscale, *button;
220 GtkListStore *store;
221 GtkCellRenderer *rend;
222 GtkWidget *view;
223 GtkTreeViewColumn *column;
224 gint layout_width;
225
226 cmafec_get_fe_parameter(pcity, &param);
227 pdialog = fc_malloc(sizeof(struct cma_dialog));
228 pdialog->pcity = pcity;
229 pdialog->shell = gtk_grid_new();
230 gtk_orientable_set_orientation(GTK_ORIENTABLE(pdialog->shell),
231 GTK_ORIENTATION_VERTICAL);
232 gtk_grid_set_row_spacing(GTK_GRID(pdialog->shell), 8);
233 gtk_container_set_border_width(GTK_CONTAINER(pdialog->shell), 8);
234 g_signal_connect(pdialog->shell, "destroy",
235 G_CALLBACK(cma_dialog_destroy_callback), pdialog);
236
237 page = gtk_grid_new();
238 gtk_grid_set_column_spacing(GTK_GRID(page), 12);
239 gtk_container_add(GTK_CONTAINER(pdialog->shell), page);
240
241 vbox = gtk_grid_new();
242 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
243 GTK_ORIENTATION_VERTICAL);
244 gtk_grid_set_row_spacing(GTK_GRID(pdialog->shell), 2);
245 gtk_container_add(GTK_CONTAINER(page), vbox);
246
247 sw = gtk_scrolled_window_new(NULL, NULL);
248 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
249 GTK_SHADOW_ETCHED_IN);
250 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
251 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
252
253 store = gtk_list_store_new(1, G_TYPE_STRING);
254 pdialog->store = store;
255
256 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
257 gtk_widget_set_hexpand(view, TRUE);
258 gtk_widget_set_vexpand(view, TRUE);
259 g_object_unref(store);
260 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
261 pdialog->preset_list = view;
262 pdialog->selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
263
264 g_signal_connect(pdialog->preset_list, "button_press_event",
265 G_CALLBACK(button_press_callback), pdialog);
266
267 gtk_widget_set_tooltip_text(view,
268 _("For information on\n"
269 "the citizen governor and governor presets,\n"
270 "including sample presets,\n"
271 "see README.governor."));
272
273 rend = gtk_cell_renderer_text_new();
274 column = gtk_tree_view_column_new_with_attributes(NULL, rend,
275 "text", 0, NULL);
276 gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
277 gtk_tree_view_column_set_cell_data_func(column, rend, cell_data_func,
278 pdialog, NULL);
279
280 label = g_object_new(GTK_TYPE_LABEL,
281 "use-underline", TRUE,
282 "mnemonic-widget", view,
283 "label", _("Prese_ts:"),
284 "xalign", 0.0, "yalign", 0.5, NULL);
285 gtk_container_add(GTK_CONTAINER(vbox), label);
286
287 gtk_container_add(GTK_CONTAINER(sw), view);
288 gtk_container_add(GTK_CONTAINER(vbox), sw);
289
290 g_signal_connect(view, "row_activated",
291 G_CALLBACK(cma_activate_preset_callback), pdialog);
292 g_signal_connect(view, "key-press-event",
293 G_CALLBACK(cma_preset_key_pressed_callback), pdialog);
294
295 hbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
296 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_EDGE);
297 gtk_container_add(GTK_CONTAINER(vbox), hbox);
298
299 button = icon_label_button_new("document-new", _("Ne_w"));
300 gtk_container_add(GTK_CONTAINER(hbox), button);
301 g_signal_connect(button, "clicked",
302 G_CALLBACK(cma_add_preset_callback), pdialog);
303 pdialog->add_preset_command = button;
304
305 pdialog->del_preset_command = icon_label_button_new("edit-delete",
306 _("_Delete"));
307 gtk_container_add(GTK_CONTAINER(hbox), pdialog->del_preset_command);
308 g_signal_connect(pdialog->del_preset_command, "clicked",
309 G_CALLBACK(cma_del_preset_callback), pdialog);
310
311 /* the right-hand side */
312
313 vbox = gtk_grid_new();
314 g_object_set(vbox, "margin", 2, NULL);
315 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
316 GTK_ORIENTATION_VERTICAL);
317 gtk_container_add(GTK_CONTAINER(page), vbox);
318
319 /* Result */
320 if (!tiny) {
321 frame = gtk_frame_new(_("Results"));
322 gtk_widget_set_vexpand(frame, TRUE);
323 gtk_widget_set_valign(frame, GTK_ALIGN_CENTER);
324 gtk_container_add(GTK_CONTAINER(vbox), frame);
325
326 pdialog->result_label =
327 gtk_label_new("food\n prod\n trade\n\n people\n grow\n prod\n name");
328 gtk_widget_set_name(pdialog->result_label, "city_label");
329 gtk_container_add(GTK_CONTAINER(frame), pdialog->result_label);
330 gtk_label_set_justify(GTK_LABEL(pdialog->result_label), GTK_JUSTIFY_LEFT);
331 } else {
332 pdialog->result_label = NULL;
333 }
334
335 /* Minimal Surplus and Factor */
336
337 table = gtk_grid_new();
338 g_object_set(table, "margin", 2, NULL);
339 gtk_container_add(GTK_CONTAINER(vbox), table);
340
341 label = gtk_label_new(_("Minimal Surplus"));
342 gtk_widget_set_halign(label, GTK_ALIGN_START);
343 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
344 gtk_grid_attach(GTK_GRID(table), label, 1, 0, 1, 1);
345 label = gtk_label_new(_("Factor"));
346 gtk_widget_set_halign(label, GTK_ALIGN_START);
347 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
348 gtk_grid_attach(GTK_GRID(table), label, 2, 0, 1, 1);
349
350 output_type_iterate(i) {
351 label = gtk_label_new(get_output_name(i));
352 gtk_grid_attach(GTK_GRID(table), label, 0, i + 1, 1, 1);
353 gtk_widget_set_halign(label, GTK_ALIGN_START);
354 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
355
356 pdialog->minimal_surplus[i] = hscale =
357 gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, NULL);
358 gtk_range_set_range(GTK_RANGE(hscale),
359 GUI_GTK_OPTION(governor_range_min),
360 GUI_GTK_OPTION(governor_range_max));
361 gtk_range_set_increments(GTK_RANGE(hscale), 1, 1);
362 pango_layout_get_pixel_size(gtk_scale_get_layout(GTK_SCALE(hscale)),
363 &layout_width, NULL);
364 gtk_widget_set_size_request(hscale, layout_width + 51 * 2, -1);
365
366 gtk_grid_attach(GTK_GRID(table), hscale, 1, i + 1, 1, 1);
367 gtk_scale_set_digits(GTK_SCALE(hscale), 0);
368 gtk_scale_set_value_pos(GTK_SCALE(hscale), GTK_POS_LEFT);
369
370 g_signal_connect(pdialog->minimal_surplus[i],
371 "value-changed",
372 G_CALLBACK(hscale_changed), pdialog);
373
374 pdialog->factor[i] = hscale =
375 gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, NULL);
376 gtk_range_set_range(GTK_RANGE(hscale), 0, 25);
377 gtk_range_set_increments(GTK_RANGE(hscale), 1, 1);
378 pango_layout_get_pixel_size(gtk_scale_get_layout(GTK_SCALE(hscale)),
379 &layout_width, NULL);
380 gtk_widget_set_size_request(hscale, layout_width + 26 * 2, -1);
381
382 gtk_grid_attach(GTK_GRID(table), hscale, 2, i + 1, 1, 1);
383 gtk_scale_set_digits(GTK_SCALE(hscale), 0);
384 gtk_scale_set_value_pos(GTK_SCALE(hscale), GTK_POS_LEFT);
385
386 g_signal_connect(pdialog->factor[i], "value-changed",
387 G_CALLBACK(hscale_changed), pdialog);
388 } output_type_iterate_end;
389
390 /* Happy Surplus and Factor */
391 label = gtk_label_new(_("Celebrate"));
392 gtk_grid_attach(GTK_GRID(table), label, 0, O_LAST + 1, 1, 1);
393 gtk_widget_set_halign(label, GTK_ALIGN_START);
394 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
395
396 pdialog->happy_button = gtk_check_button_new();
397 gtk_widget_set_halign(pdialog->happy_button, GTK_ALIGN_END);
398 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->happy_button),
399 FALSE);
400 gtk_grid_attach(GTK_GRID(table), pdialog->happy_button, 1, O_LAST + 1, 1, 1);
401
402 g_signal_connect(pdialog->happy_button, "toggled",
403 G_CALLBACK(hscale_changed), pdialog);
404
405 pdialog->factor[O_LAST] = hscale =
406 gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, NULL);
407 gtk_range_set_range(GTK_RANGE(hscale), 0, 50);
408 gtk_range_set_increments(GTK_RANGE(hscale), 1, 1);
409 pango_layout_get_pixel_size(gtk_scale_get_layout(GTK_SCALE(hscale)),
410 &layout_width, NULL);
411 gtk_widget_set_size_request(hscale, layout_width + 51 * 2, -1);
412
413 gtk_grid_attach(GTK_GRID(table), hscale, 2, O_LAST + 1, 1, 1);
414 gtk_scale_set_digits(GTK_SCALE(hscale), 0);
415 gtk_scale_set_value_pos(GTK_SCALE(hscale), GTK_POS_LEFT);
416
417 g_signal_connect(pdialog->factor[O_LAST],
418 "value-changed",
419 G_CALLBACK(hscale_changed), pdialog);
420
421 /* Maximize Growth */
422 label = gtk_label_new(_("Maximize growth"));
423 gtk_grid_attach(GTK_GRID(table), label, 0, O_LAST + 2, 1, 1);
424 gtk_widget_set_halign(label, GTK_ALIGN_START);
425 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
426
427 pdialog->growth_button = gtk_check_button_new();
428 gtk_widget_set_halign(pdialog->growth_button, GTK_ALIGN_END);
429 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->growth_button),
430 FALSE);
431 gtk_grid_attach(GTK_GRID(table), pdialog->growth_button, 1, O_LAST + 2, 1, 1);
432
433 g_signal_connect(pdialog->growth_button, "toggled",
434 G_CALLBACK(hscale_changed), pdialog);
435
436 /* Buttons */
437 hbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
438 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_EDGE);
439 gtk_container_add(GTK_CONTAINER(vbox), hbox);
440
441 button = icon_label_button_new("help-browser", _("Help"));
442 g_signal_connect(button, "clicked",
443 G_CALLBACK(help_callback), NULL);
444 gtk_container_add(GTK_CONTAINER(hbox), button);
445 gtk_button_box_set_child_non_homogeneous(GTK_BUTTON_BOX(hbox),
446 button, TRUE);
447
448 pdialog->active_command = gtk_toggle_button_new();
449 gtk_button_set_use_underline(GTK_BUTTON(pdialog->active_command), TRUE);
450 gtk_button_set_image_position(GTK_BUTTON(pdialog->active_command),
451 GTK_POS_TOP);
452 gtk_widget_set_name(pdialog->active_command, "comment_label");
453 gtk_container_add(GTK_CONTAINER(hbox), pdialog->active_command);
454
455 gtk_widget_show_all(pdialog->shell);
456
457 dialog_list_prepend(dialog_list, pdialog);
458
459 update_cma_preset_list(pdialog);
460
461 gtk_tree_view_focus(GTK_TREE_VIEW(view));
462
463 /* refresh is done in refresh_city_dialog */
464
465 return pdialog;
466}
467
468/**********************************************************************/
471 void refresh_cma_dialog(struct city *pcity, enum cma_refresh refresh)
472{
473 struct cm_result *result = cm_result_new(pcity);
474 struct cm_parameter param;
475 struct cma_dialog *pdialog = get_cma_dialog(pcity);
476 int controlled = cma_is_city_under_agent(pcity, NULL);
477
478 cmafec_get_fe_parameter(pcity, &param);
479
480 if (pdialog->result_label != NULL) {
481 /* fill in result label */
482 cm_result_from_main_map(result, pcity);
483 gtk_label_set_text(GTK_LABEL(pdialog->result_label),
484 cmafec_get_result_descr(pcity, result, &param));
485 }
486
487 /* if called from a hscale, we _don't_ want to do this */
488 if (refresh != DONT_REFRESH_HSCALES) {
489 set_hscales(&param, pdialog);
490 }
491
492 gtk_widget_queue_draw(pdialog->preset_list);
493
494 gtk_widget_set_sensitive(pdialog->active_command, can_client_issue_orders());
495
496 g_signal_handlers_disconnect_matched(pdialog->active_command,
497 G_SIGNAL_MATCH_FUNC,
498 0, 0, NULL, cma_active_callback, NULL);
499 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->active_command),
500 controlled);
501 g_signal_connect(pdialog->active_command, "clicked",
502 G_CALLBACK(cma_active_callback), pdialog);
503
504 if (controlled) {
505 gtk_button_set_label(GTK_BUTTON(pdialog->active_command),
506 _("Governor Enabl_ed"));
507 } else {
508 gtk_button_set_label(GTK_BUTTON(pdialog->active_command),
509 _("Governor Disabl_ed"));
510 }
511
512 if (pdialog->result_label != NULL) {
513 gtk_widget_set_sensitive(pdialog->result_label, controlled);
514 }
515
516 cm_result_destroy(result);
517}
518
519/**********************************************************************/
522 static void update_cma_preset_list(struct cma_dialog *pdialog)
523{
524 char buf[BUFFER_SIZE];
525 GtkTreeIter it;
526 int i;
527
528 /* Fill preset list */
529 gtk_list_store_clear(pdialog->store);
530
531 /* Append the presets */
532 if (cmafec_preset_num()) {
533 for (i = 0; i < cmafec_preset_num(); i++) {
534 fc_strlcpy(buf, cmafec_preset_get_descr(i), sizeof(buf));
535 gtk_list_store_append(pdialog->store, &it);
536 gtk_list_store_set(pdialog->store, &it, 0, buf, -1);
537 }
538 }
539}
540
541/**********************************************************************/
544 static void cma_activate_preset_callback(GtkTreeView *view, GtkTreePath *path,
545 GtkTreeViewColumn *col, gpointer data)
546{
547 struct cma_dialog *pdialog = (struct cma_dialog *) data;
548 int preset_index;
549 const struct cm_parameter *pparam;
550
551 preset_index = gtk_tree_path_get_indices(path) [0];
552
553 pparam = cmafec_preset_get_parameter(preset_index);
554
555 /* Save the change */
556 cmafec_set_fe_parameter(pdialog->pcity, pparam);
557
558 if (cma_is_city_under_agent(pdialog->pcity, NULL)) {
559 cma_release_city(pdialog->pcity);
560 cma_put_city_under_agent(pdialog->pcity, pparam);
561 }
562 refresh_city_dialog(pdialog->pcity);
563}
564
565/**********************************************************************/
568 static void cma_add_preset_callback(GtkWidget *w, gpointer data)
569{
570 struct cma_dialog *pdialog = (struct cma_dialog *) data;
571 const char *default_name;
572 GtkWidget *parent = gtk_widget_get_toplevel(pdialog->shell);
573 int index;
574
575 if ((index = gtk_tree_selection_get_row(pdialog->selection)) != -1) {
576 default_name = cmafec_preset_get_descr(index);
577 } else {
578 default_name = _("new preset");
579 }
580
581 pdialog->name_shell = input_dialog_create(GTK_WINDOW(parent),
582 _("Name new preset"),
583 _("What should we name the preset?"),
584 default_name,
585 cma_preset_add_popup_callback, pdialog);
586}
587
588/**********************************************************************/
591 static void cma_preset_add_popup_callback(gpointer data, gint response,
592 const char *input)
593{
594 struct cma_dialog *pdialog = (struct cma_dialog *) data;
595
596 if (pdialog) {
597 if (response == GTK_RESPONSE_OK) {
598 struct cm_parameter param;
599
600 cmafec_get_fe_parameter(pdialog->pcity, &param);
601 cmafec_preset_add(input, &param);
602 update_cma_preset_list(pdialog);
603 refresh_cma_dialog(pdialog->pcity, DONT_REFRESH_HSCALES);
604 /* If this or other cities have this set as "custom" */
605 city_report_dialog_update();
606 } /* else CANCEL or DELETE_EVENT */
607
608 pdialog->name_shell = NULL;
609 }
610}
611
612/**********************************************************************/
615 static gboolean cma_preset_key_pressed_callback(GtkWidget *w, GdkEventKey *ev,
616 gpointer data)
617{
618 struct cma_dialog *pdialog = (struct cma_dialog *) data;
619 int index;
620
621 if ((index = gtk_tree_selection_get_row(pdialog->selection)) == -1) {
622 return FALSE;
623 }
624
625 if (ev->type == GDK_KEY_PRESS) {
626 switch (ev->keyval) {
627 case GDK_KEY_Delete:
628 cma_preset_remove(pdialog, index);
629 break;
630 case GDK_KEY_Insert:
631 cma_add_preset_callback(NULL, pdialog);
632 break;
633 default:
634 return FALSE;
635 }
636 return TRUE;
637 }
638 return FALSE;
639}
640
641/**********************************************************************/
644 static void cma_del_preset_callback(GtkWidget *w, gpointer data)
645{
646 struct cma_dialog *pdialog = (struct cma_dialog *) data;
647 int index;
648
649 if ((index = gtk_tree_selection_get_row(pdialog->selection)) == -1) {
650 return;
651 }
652
653 cma_preset_remove(pdialog, index);
654}
655
656/**********************************************************************/
659 static void cma_preset_remove(struct cma_dialog *pdialog, int preset_index)
660{
661 GtkWidget *parent = gtk_widget_get_toplevel(pdialog->shell), *shl;
662
663 pdialog->id = preset_index;
664 shl = gtk_message_dialog_new(NULL,
665 GTK_DIALOG_DESTROY_WITH_PARENT,
666 GTK_MESSAGE_QUESTION,
667 GTK_BUTTONS_YES_NO,
668 _("Remove this preset?"));
669 setup_dialog(shl, parent);
670 pdialog->preset_remove_shell = shl;
671
672 gtk_window_set_title(GTK_WINDOW(shl), cmafec_preset_get_descr(preset_index));
673 gtk_window_set_position(GTK_WINDOW(shl), GTK_WIN_POS_CENTER_ON_PARENT);
674
675 g_signal_connect(shl, "response",
676 G_CALLBACK(cma_preset_remove_response), pdialog);
677
678 gtk_window_present(GTK_WINDOW(shl));
679}
680
681/**********************************************************************/
684 static void cma_preset_remove_response(GtkWidget *w, gint response,
685 gpointer data)
686{
687 struct cma_dialog *pdialog = (struct cma_dialog *) data;
688
689 if (response == GTK_RESPONSE_YES) {
690 cmafec_preset_remove(pdialog->id);
691 pdialog->id = -1;
692 update_cma_preset_list(pdialog);
693 refresh_cma_dialog(pdialog->pcity, DONT_REFRESH_HSCALES);
694 /* if this or other cities have this set, reset to "custom" */
695 city_report_dialog_update();
696 }
697 gtk_widget_destroy(w);
698
699 pdialog->preset_remove_shell = NULL;
700}
701
702/**********************************************************************/
705 static void cma_active_callback(GtkWidget *w, gpointer data)
706{
707 struct cma_dialog *pdialog = (struct cma_dialog *) data;
708
709 if (cma_is_city_under_agent(pdialog->pcity, NULL)) {
710 cma_release_city(pdialog->pcity);
711 } else {
712 struct cm_parameter param;
713
714 cmafec_get_fe_parameter(pdialog->pcity, &param);
715 cma_put_city_under_agent(pdialog->pcity, &param);
716 }
717 refresh_city_dialog(pdialog->pcity);
718}
719
720/**********************************************************************/
724 static void set_hscales(const struct cm_parameter *const parameter,
725 struct cma_dialog *pdialog)
726{
727 allow_refreshes = 0;
728 output_type_iterate(i) {
729 gtk_range_set_value(GTK_RANGE(pdialog->minimal_surplus[i]),
730 parameter->minimal_surplus[i]);
731 gtk_range_set_value(GTK_RANGE(pdialog->factor[i]), parameter->factor[i]);
732 } output_type_iterate_end;
733 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->happy_button),
734 parameter->require_happy);
735 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->growth_button),
736 parameter->max_growth);
737 gtk_range_set_value(GTK_RANGE(pdialog->factor[O_LAST]),
738 parameter->happy_factor);
739 allow_refreshes = 1;
740}
741
742/**********************************************************************/
745 static void hscale_changed(GtkWidget *get, gpointer data)
746{
747 struct cma_dialog *pdialog = (struct cma_dialog *) data;
748 struct cm_parameter param;
749
750 if (!allow_refreshes) {
751 return;
752 }
753
754 cmafec_get_fe_parameter(pdialog->pcity, &param);
755 output_type_iterate(i) {
756 param.minimal_surplus[i] =
757 (int) (gtk_range_get_value(GTK_RANGE(pdialog->minimal_surplus[i])));
758 param.factor[i] =
759 (int) (gtk_range_get_value(GTK_RANGE(pdialog->factor[i])));
760 } output_type_iterate_end;
761 param.require_happy =
762 (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pdialog->happy_button))
763 ? TRUE : FALSE);
764 param.max_growth =
765 (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pdialog->growth_button))
766 ? TRUE : FALSE);
767 param.happy_factor =
768 (int) (gtk_range_get_value(GTK_RANGE(pdialog->factor[O_LAST])));
769
770 /* Save the change */
771 cmafec_set_fe_parameter(pdialog->pcity, &param);
772
773 /* Refreshes the cma */
774 if (cma_is_city_under_agent(pdialog->pcity, NULL)) {
775 cma_release_city(pdialog->pcity);
776 cma_put_city_under_agent(pdialog->pcity, &param);
777 refresh_city_dialog(pdialog->pcity);
778 } else {
779 refresh_cma_dialog(pdialog->pcity, DONT_REFRESH_HSCALES);
780 }
781}
chatline_g.h
get_output_name
const char * get_output_name(Output_type_id output)
Definition city.c:624
output_type_iterate
#define output_type_iterate(output)
Definition city.h:812
output_type_iterate_end
#define output_type_iterate_end
Definition city.h:818
citydlg_g.h
refresh_city_dialog
void refresh_city_dialog(struct city *pcity)
Definition update_queue.c:632
city_report_dialog_update
void city_report_dialog_update(void)
Definition update_queue.c:666
can_client_issue_orders
bool can_client_issue_orders(void)
Definition client_main.c:1265
client_main.h
cm_result_new
struct cm_result * cm_result_new(struct city *pcity)
Definition cm.c:343
cm_result_from_main_map
void cm_result_from_main_map(struct cm_result *result, const struct city *pcity)
Definition cm.c:2256
cm_result_destroy
void cm_result_destroy(struct cm_result *result)
Definition cm.c:366
cma_is_city_under_agent
bool cma_is_city_under_agent(const struct city *pcity, struct cm_parameter *parameter)
Definition cma_core.c:550
cma_put_city_under_agent
void cma_put_city_under_agent(struct city *pcity, const struct cm_parameter *const parameter)
Definition cma_core.c:522
cma_release_city
void cma_release_city(struct city *pcity)
Definition cma_core.c:540
cmafec_get_short_descr
const char * cmafec_get_short_descr(const struct cm_parameter *const parameter)
Definition cma_fec.c:236
cmafec_set_fe_parameter
void cmafec_set_fe_parameter(struct city *pcity, const struct cm_parameter *const parameter)
Definition cma_fec.c:105
cmafec_preset_get_descr
char * cmafec_preset_get_descr(int idx)
Definition cma_fec.c:169
cmafec_get_result_descr
const char * cmafec_get_result_descr(struct city *pcity, const struct cm_result *result, const struct cm_parameter *const parameter)
Definition cma_fec.c:322
cmafec_preset_get_parameter
const struct cm_parameter * cmafec_preset_get_parameter(int idx)
Definition cma_fec.c:182
cmafec_preset_add
void cmafec_preset_add(const char *descr_name, struct cm_parameter *pparam)
Definition cma_fec.c:136
cmafec_preset_get_index_of_parameter
int cmafec_preset_get_index_of_parameter(const struct cm_parameter *const parameter)
Definition cma_fec.c:196
cmafec_preset_remove
void cmafec_preset_remove(int idx)
Definition cma_fec.c:153
cmafec_preset_num
int cmafec_preset_num(void)
Definition cma_fec.c:213
cmafec_get_fe_parameter
void cmafec_get_fe_parameter(struct city *pcity, struct cm_parameter *dest)
Definition cma_fec.c:115
cma_fec.h
events.h
O_LAST
@ O_LAST
Definition fc_types.h:91
fcintl.h
_
#define _(String)
Definition fcintl.h:67
game.h
button_press_callback
static gboolean button_press_callback(GtkTreeView *view, GdkEventButton *ev, gpointer data)
Definition cma_fe.c:143
cma_preset_key_pressed_callback
static gboolean cma_preset_key_pressed_callback(GtkWidget *w, GdkEventKey *ev, gpointer data)
Definition cma_fe.c:625
cma_preset_remove
static void cma_preset_remove(struct cma_dialog *pdialog, int preset_index)
Definition cma_fe.c:669
close_cma_dialog
void close_cma_dialog(struct city *pcity)
Definition cma_fe.c:104
create_cma_dialog
struct cma_dialog * create_cma_dialog(struct city *pcity, bool tiny)
Definition cma_fe.c:214
refresh_cma_dialog
void refresh_cma_dialog(struct city *pcity, enum cma_refresh refresh)
Definition cma_fe.c:472
cma_del_preset_callback
static void cma_del_preset_callback(GtkWidget *w, gpointer data)
Definition cma_fe.c:654
cma_dialog_destroy_callback
static void cma_dialog_destroy_callback(GtkWidget *w, gpointer data)
Definition cma_fe.c:118
cma_fe_init
void cma_fe_init(void)
Definition cma_fe.c:88
cma_add_preset_callback
static void cma_add_preset_callback(GtkWidget *w, gpointer data)
Definition cma_fe.c:578
help_callback
static void help_callback(GtkWidget *w, gpointer data)
Definition cma_fe.c:170
update_cma_preset_list
static void update_cma_preset_list(struct cma_dialog *pdialog)
Definition cma_fe.c:532
BUFFER_SIZE
#define BUFFER_SIZE
Definition cma_fe.c:48
dialog_list_iterate_end
#define dialog_list_iterate_end
Definition cma_fe.c:56
hscale_changed
static void hscale_changed(GtkWidget *get, gpointer data)
Definition cma_fe.c:755
cell_data_func
static void cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *it, gpointer data)
Definition cma_fe.c:178
cma_preset_add_popup_callback
static void cma_preset_add_popup_callback(gpointer data, gint response, const char *input)
Definition cma_fe.c:601
get_cma_dialog
static struct cma_dialog * get_cma_dialog(struct city *pcity)
Definition cma_fe.c:129
dialog_list_iterate
#define dialog_list_iterate(dialoglist, pdialog)
Definition cma_fe.c:54
dialog_list
static struct dialog_list * dialog_list
Definition cma_fe.c:58
cma_preset_remove_response
static void cma_preset_remove_response(GtkWidget *w, gint response, gpointer data)
Definition cma_fe.c:694
cma_activate_preset_callback
static void cma_activate_preset_callback(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
Definition cma_fe.c:554
cma_active_callback
static void cma_active_callback(GtkWidget *w, gpointer data)
Definition cma_fe.c:715
set_hscales
static void set_hscales(const struct cm_parameter *const parameter, struct cma_dialog *pdialog)
Definition cma_fe.c:734
cma_fe_done
void cma_fe_done(void)
Definition cma_fe.c:96
allow_refreshes
static int allow_refreshes
Definition cma_fe.c:60
cma_refresh
cma_refresh
Definition cma_fe.h:25
DONT_REFRESH_HSCALES
@ DONT_REFRESH_HSCALES
Definition cma_fe.h:28
GUI_GTK_OPTION
#define GUI_GTK_OPTION(optname)
Definition gui_main.h:25
gtk_tree_view_focus
void gtk_tree_view_focus(GtkTreeView *view)
Definition gui_stuff.c:230
gtk_tree_selection_get_row
gint gtk_tree_selection_get_row(GtkTreeSelection *selection)
Definition gui_stuff.c:209
setup_dialog
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:281
popup_help_dialog_string
void popup_help_dialog_string(const char *item)
Definition helpdlg.c:211
input_dialog_create
GtkWidget * input_dialog_create(GtkWindow *parent, const char *dialogname, const char *text, const char *postinputtest, input_dialog_callback_t response_callback, gpointer response_cli_data)
Definition inputdlg.c:66
icon_label_button_new
GtkWidget * icon_label_button_new(const gchar *icon_name, const gchar *label_text)
Definition gui_stuff.c:76
gui_stuff.h
inputdlg.h
cma_fe.h
cityrep.h
dialogs.h
gui_main.h
helpdlg.h
HELP_CMA_ITEM
#define HELP_CMA_ITEM
log.h
mem.h
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
messagewin_g.h
options.h
speclist.h
city
Definition city.h:309
cm_parameter
Definition cm.h:40
cm_parameter::factor
int factor[O_LAST]
Definition cm.h:47
cm_parameter::max_growth
bool max_growth
Definition cm.h:42
cm_parameter::require_happy
bool require_happy
Definition cm.h:43
cm_parameter::minimal_surplus
int minimal_surplus[O_LAST]
Definition cm.h:41
cm_parameter::happy_factor
int happy_factor
Definition cm.h:48
cm_result
Definition cm.h:52
cma_dialog
Definition cma_fe.h:31
cma_dialog::preset_list
GtkWidget * preset_list
Definition cma_fe.h:36
cma_dialog::active_command
GtkWidget * active_command
Definition cma_fe.h:40
cma_dialog::factor
GtkWidget * factor[O_LAST+1]
Definition cma_fe.h:44
cma_dialog::shell
GtkWidget * shell
Definition cma_fe.h:33
cma_dialog::happy_button
GtkWidget * happy_button
Definition cma_fe.h:42
cma_dialog::del_preset_command
GtkWidget * del_preset_command
Definition cma_fe.h:39
cma_dialog::growth_button
GtkWidget * growth_button
Definition cma_fe.h:43
cma_dialog::result_label
GtkWidget * result_label
Definition cma_fe.h:37
cma_dialog::add_preset_command
GtkWidget * add_preset_command
Definition cma_fe.h:38
cma_dialog::minimal_surplus
GtkWidget * minimal_surplus[O_LAST]
Definition cma_fe.h:41
cma_dialog::store
GtkListStore * store
Definition cma_fe.h:46
cma_dialog::name_shell
GtkWidget * name_shell
Definition cma_fe.h:34
cma_dialog::preset_remove_shell
GtkWidget * preset_remove_shell
Definition cma_fe.h:35
cma_dialog::id
int id
Definition cma_fe.h:47
cma_dialog::pcity
struct city * pcity
Definition cma_fe.h:32
cma_dialog::selection
GtkTreeSelection * selection
Definition cma_fe.h:45
view
Definition mapview_common.h:36
fc_strlcpy
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:787
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47