Freeciv-3.1
Loading...
Searching...
No Matches
citydlg.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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 <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21
22#include <gtk/gtk.h>
23#include <gdk/gdkkeysyms.h>
24
25/* utility */
26#include "bitvector.h"
27#include "fcintl.h"
28#include "log.h"
29#include "mem.h"
30#include "shared.h"
31#include "support.h"
32
33/* common */
34#include "city.h"
35#include "game.h"
36#include "map.h"
37#include "movement.h"
38#include "packets.h"
39#include "player.h"
40#include "unitlist.h"
41
42/* client */
43#include "chatline_common.h"
44#include "client_main.h"
45#include "colors.h"
46#include "control.h"
47#include "climap.h"
48#include "options.h"
49#include "text.h"
50#include "tilespec.h"
51
52/* client/agents */
53#include "cma_fec.h"
54
55/* client/gui-gtk-3.22 */
56#include "choice_dialog.h"
57#include "citizensinfo.h"
58#include "cityrep.h"
59#include "cma_fe.h"
60#include "dialogs.h"
61#include "graphics.h"
62#include "gui_main.h"
63#include "gui_stuff.h"
64#include "happiness.h"
65#include "helpdlg.h"
66#include "inputdlg.h"
67#include "mapview.h"
68#include "repodlgs.h"
69#include "wldlg.h"
70
71#include "citydlg.h"
72
73#define CITYMAP_WIDTH MIN(512, canvas_width)
74#define CITYMAP_HEIGHT (CITYMAP_WIDTH * canvas_height / canvas_width)
75#define CITYMAP_SCALE ((double)CITYMAP_WIDTH / (double)canvas_width)
76
77#define TINYSCREEN_MAX_HEIGHT (500 - 1)
78
79/* Only CDLGR_UNITS button currently uses these, others have
80 * direct callback. */
82
83struct city_dialog;
84
85/* get 'struct dialog_list' and related function */
86#define SPECLIST_TAG dialog
87#define SPECLIST_TYPE struct city_dialog
88#include "speclist.h"
89
90#define dialog_list_iterate(dialoglist, pdialog) \
91 TYPED_LIST_ITERATE(struct city_dialog, dialoglist, pdialog)
92#define dialog_list_iterate_end LIST_ITERATE_END
93
94struct unit_node {
95 GtkWidget *cmd;
96 GtkWidget *pix;
97 int height;
98};
99
100/* get 'struct unit_node' and related function */
101#define SPECVEC_TAG unit_node
102#define SPECVEC_TYPE struct unit_node
103#include "specvec.h"
104
105#define unit_node_vector_iterate(list, elt) \
106 TYPED_VECTOR_ITERATE(struct unit_node, list, elt)
107#define unit_node_vector_iterate_end VECTOR_ITERATE_END
108
109#define NUM_CITIZENS_SHOWN 30
110
113 NUM_PAGES /* the number of pages in city dialog notebook
114 * must match the entries in misc_whichtab_label[] */
116
117enum {
122 NUM_INFO_FIELDS /* number of fields in city_info panel
123 * must match entries in output_label[] */
125
126/* minimal size for the city map scrolling windows*/
127#define CITY_MAP_MIN_SIZE_X 200
128#define CITY_MAP_MIN_SIZE_Y 150
129
130struct city_map_canvas {
131 GtkWidget *sw;
132 GtkWidget *ebox;
133 GtkWidget *darea;
134};
135
136struct city_dialog {
137 struct city *pcity;
138
139 GtkWidget *shell;
140 GtkWidget *name_label;
141 cairo_surface_t *map_canvas_store_unscaled;
142 GtkWidget *notebook;
143
144 GtkWidget *popup_menu;
145 GtkWidget *citizen_images;
146 cairo_surface_t *citizen_surface;
147
148 struct {
150
151 GtkWidget *production_bar;
152 GtkWidget *production_combo;
153 GtkWidget *buy_command;
154 GtkWidget *improvement_list;
155
156 GtkWidget *supported_units_frame;
157 GtkWidget *supported_unit_table;
158
159 GtkWidget *present_units_frame;
160 GtkWidget *present_unit_table;
161
162 struct unit_node_vector supported_units;
163 struct unit_node_vector present_units;
164
165 GtkWidget *info_ebox[NUM_INFO_FIELDS];
166 GtkWidget *info_label[NUM_INFO_FIELDS];
167
168 GtkListStore* change_production_store;
170
171 struct {
172 GtkWidget *production_label;
173 GtkWidget *production_bar;
174 GtkWidget *buy_command;
175 GtkWidget *worklist;
177
178 struct {
180
181 GtkWidget *widget;
182 GtkWidget *info_ebox[NUM_INFO_FIELDS];
183 GtkWidget *info_label[NUM_INFO_FIELDS];
184 GtkWidget *citizens;
186
187 struct cma_dialog *cma_editor;
188
189 struct {
190 GtkWidget *rename_command;
191 GtkWidget *new_citizens_radio[3];
192 GtkWidget *disband_on_settler;
193 GtkWidget *whichtab_radio[NUM_PAGES];
194 short block_signal;
196
197 GtkWidget *sell_shell;
198 GtkTreeSelection *change_selection;
199 GtkWidget *rename_shell;
200
201 GtkWidget *show_units_command;
202 GtkWidget *prev_command;
203 GtkWidget *next_command;
204
206
207 int cwidth;
208};
209
215
217
218static struct
219{
220 struct city *owner;
221 struct tile *loc;
223
224static bool low_citydlg;
225
226/****************************************/
227
228static void initialize_city_dialogs(void);
229static void city_dialog_map_create(struct city_dialog *pdialog,
230 struct city_map_canvas *cmap_canvas);
231static void city_dialog_map_recenter(GtkWidget *map_canvas_sw);
232
233static struct city_dialog *get_city_dialog(struct city *pcity);
234static gboolean keyboard_handler(GtkWidget * widget, GdkEventKey * event,
235 struct city_dialog *pdialog);
236
237static GtkWidget *create_city_info_table(struct city_dialog *pdialog,
238 GtkWidget **info_ebox,
239 GtkWidget **info_label);
240static void create_and_append_overview_page(struct city_dialog *pdialog);
241static void create_and_append_map_page(struct city_dialog *pdialog);
242static void create_and_append_buildings_page(struct city_dialog *pdialog);
243static void create_and_append_worklist_page(struct city_dialog *pdialog);
244static void create_and_append_happiness_page(struct city_dialog *pdialog);
245static void create_and_append_cma_page(struct city_dialog *pdialog);
246static void create_and_append_settings_page(struct city_dialog *pdialog);
247
248static struct city_dialog *create_city_dialog(struct city *pcity);
249
250static void city_dialog_update_title(struct city_dialog *pdialog);
251static void city_dialog_update_citizens(struct city_dialog *pdialog);
252static void city_dialog_update_information(GtkWidget **info_ebox,
253 GtkWidget **info_label,
254 struct city_dialog *pdialog);
255static void city_dialog_update_map(struct city_dialog *pdialog);
256static void city_dialog_update_building(struct city_dialog *pdialog);
258 *pdialog);
260 *pdialog);
261static void city_dialog_update_present_units(struct city_dialog *pdialog);
262static void city_dialog_update_prev_next(void);
263
264static void show_units_response(void *data);
265
266static gboolean supported_unit_callback(GtkWidget * w, GdkEventButton * ev,
267 gpointer data);
268static gboolean present_unit_callback(GtkWidget * w, GdkEventButton * ev,
269 gpointer data);
270static gboolean supported_unit_middle_callback(GtkWidget * w,
271 GdkEventButton * ev,
272 gpointer data);
273static gboolean present_unit_middle_callback(GtkWidget * w,
274 GdkEventButton * ev,
275 gpointer data);
276
277static void unit_center_callback(GtkWidget * w, gpointer data);
278static void unit_activate_callback(GtkWidget * w, gpointer data);
279static void supported_unit_activate_close_callback(GtkWidget * w,
280 gpointer data);
281static void present_unit_activate_close_callback(GtkWidget * w,
282 gpointer data);
283static void unit_load_callback(GtkWidget * w, gpointer data);
284static void unit_unload_callback(GtkWidget * w, gpointer data);
285static void unit_sentry_callback(GtkWidget * w, gpointer data);
286static void unit_fortify_callback(GtkWidget * w, gpointer data);
287static void unit_disband_callback(GtkWidget * w, gpointer data);
288static void unit_homecity_callback(GtkWidget * w, gpointer data);
289static void unit_upgrade_callback(GtkWidget * w, gpointer data);
290
291static gboolean citizens_callback(GtkWidget * w, GdkEventButton * ev,
292 gpointer data);
293static gboolean button_down_citymap(GtkWidget * w, GdkEventButton * ev,
294 gpointer data);
295static void draw_map_canvas(struct city_dialog *pdialog);
296
297static void buy_callback(GtkWidget * w, gpointer data);
298static void change_production_callback(GtkComboBox *combo,
299 struct city_dialog *pdialog);
300
301static void sell_callback(struct impr_type *pimprove, gpointer data);
302static void sell_callback_response(GtkWidget *w, gint response, gpointer data);
303
304static void impr_callback(GtkTreeView *view, GtkTreePath *path,
305 GtkTreeViewColumn *col, gpointer data);
306
307static void rename_callback(GtkWidget * w, gpointer data);
308static void rename_popup_callback(gpointer data, gint response,
309 const char *input);
310static void set_cityopt_values(struct city_dialog *pdialog);
311static void cityopt_callback(GtkWidget * w, gpointer data);
312static void misc_whichtab_callback(GtkWidget * w, gpointer data);
313
314static void city_destroy_callback(GtkWidget *w, gpointer data);
315static void close_city_dialog(struct city_dialog *pdialog);
316static void citydlg_response_callback(GtkDialog *dlg, gint response,
317 void *data);
318static void close_callback(GtkWidget *w, gpointer data);
319static void switch_city_callback(GtkWidget *w, gpointer data);
320
321/**********************************************************************/
330
331/**********************************************************************/
334static void initialize_city_dialogs(void)
335{
336 int height;
337
339
340 dialog_list = dialog_list_new();
343
344 /* Use default layout when height cannot be determined
345 * (when height == 0) */
346 if (height > 0 && height <= TINYSCREEN_MAX_HEIGHT) {
348 } else {
350 }
351
353}
354
355/**********************************************************************/
359{
361 return;
362 }
363
365
367 /* There's no reasonable way to resize a GtkImage, so we don't try.
368 Instead we just redraw the overview within the existing area. The
369 player has to close and reopen the dialog to fix this. */
370 city_dialog_update_map(pdialog);
372
374}
375
376/**********************************************************************/
380static struct city_dialog *get_city_dialog(struct city *pcity)
381{
384 }
385
387 if (pdialog->pcity == pcity)
388 return pdialog;
389 }
391 return NULL;
392}
393
394/**********************************************************************/
397static gboolean canvas_exposed_cb(GtkWidget *w, cairo_t *cr,
398 gpointer data)
399{
400 struct city_dialog *pdialog = data;
401
402 cairo_scale(cr, CITYMAP_SCALE, CITYMAP_SCALE);
403 cairo_set_source_surface(cr, pdialog->map_canvas_store_unscaled, 0, 0);
404 if (cma_is_city_under_agent(pdialog->pcity, NULL)) {
405 cairo_paint_with_alpha(cr, 0.5);
406 } else {
407 cairo_paint(cr);
408 }
409
410 return TRUE;
411}
412
413/**********************************************************************/
416static void city_dialog_map_create(struct city_dialog *pdialog,
417 struct city_map_canvas *cmap_canvas)
418{
419 GtkWidget *sw, *ebox, *darea;
420
421 sw = gtk_scrolled_window_new(NULL, NULL);
422 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(sw),
424 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(sw),
426 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
427 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
428 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
429 GTK_SHADOW_NONE);
430
431 ebox = gtk_event_box_new();
432 gtk_widget_set_halign(ebox, GTK_ALIGN_CENTER);
433 gtk_widget_set_valign(ebox, GTK_ALIGN_CENTER);
434 gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE);
435 gtk_container_add(GTK_CONTAINER(sw), ebox);
436
437 darea = gtk_drawing_area_new();
438 gtk_widget_add_events(darea, GDK_BUTTON_PRESS_MASK);
439 gtk_widget_set_size_request(darea, CITYMAP_WIDTH, CITYMAP_HEIGHT);
440 g_signal_connect(ebox, "button-press-event",
441 G_CALLBACK(button_down_citymap), pdialog);
442 g_signal_connect(darea, "draw",
443 G_CALLBACK(canvas_exposed_cb), pdialog);
444 gtk_container_add(GTK_CONTAINER(ebox), darea);
445
446 /* save all widgets for the city map */
447 cmap_canvas->sw = sw;
448 cmap_canvas->ebox = ebox;
449 cmap_canvas->darea = darea;
450}
451
452/**********************************************************************/
455static void city_dialog_map_recenter(GtkWidget *map_canvas_sw)
456{
457 GtkAdjustment *adjust = NULL;
458 gdouble value;
459
460 fc_assert_ret(map_canvas_sw != NULL);
461
462 adjust = gtk_scrolled_window_get_hadjustment(
463 GTK_SCROLLED_WINDOW(map_canvas_sw));
464 value = (gtk_adjustment_get_lower(adjust)
465 + gtk_adjustment_get_upper(adjust)
466 - gtk_adjustment_get_page_size(adjust)) / 2;
467 gtk_adjustment_set_value(adjust, value);
468
469 adjust = gtk_scrolled_window_get_vadjustment(
470 GTK_SCROLLED_WINDOW(map_canvas_sw));
471 value = (gtk_adjustment_get_lower(adjust)
472 + gtk_adjustment_get_upper(adjust)
473 - gtk_adjustment_get_page_size(adjust)) / 2;
474 gtk_adjustment_set_value(adjust, value);
475}
476
477/**********************************************************************/
481{
482 struct city_dialog *pdialog = get_city_dialog(pcity);
483
484 log_debug("CITYMAP_WIDTH: %d", CITYMAP_WIDTH);
485 log_debug("CITYMAP_HEIGHT: %d", CITYMAP_HEIGHT);
486 log_debug("CITYMAP_SCALE: %.3f", CITYMAP_SCALE);
487
491 }
492
493 if (!pdialog) {
494 return;
495 }
496
500 pdialog->overview.info_label, pdialog);
501 city_dialog_update_map(pdialog);
506
508 bool have_present_units = (unit_list_size(pcity->tile->units) > 0);
509
511
512 if (!low_citydlg) {
514 pdialog->happiness.info_label, pdialog);
515 }
519 }
520
521 if (!client_is_observer()) {
523 }
524
525 gtk_widget_set_sensitive(pdialog->show_units_command,
527 && have_present_units);
528 } else {
529 /* Set the buttons we do not want live while a Diplomat investigates */
530 gtk_widget_set_sensitive(pdialog->show_units_command, FALSE);
531 }
532}
533
534/**********************************************************************/
539{
540 struct city *pcity_sup, *pcity_pre;
541 struct city_dialog *pdialog;
542
543 pcity_sup = game_city_by_number(punit->homecity);
544 pcity_pre = tile_city(unit_tile(punit));
545
546 if (pcity_sup && (pdialog = get_city_dialog(pcity_sup))) {
548 }
549
550 if (pcity_pre && (pdialog = get_city_dialog(pcity_pre))) {
552 }
553}
554
555/**********************************************************************/
559{
560 struct city_dialog *pdialog;
561
562 if (!(pdialog = get_city_dialog(pcity))) {
563 pdialog = create_city_dialog(pcity);
564 }
565
566 gtk_window_present(GTK_WINDOW(pdialog->shell));
567
568 /* center the city map(s); this must be *after* the city dialog was drawn
569 * else the size information is missing! */
571 if (pdialog->happiness.map_canvas.sw) {
573 }
574}
575
576/**********************************************************************/
580{
581 return get_city_dialog(pcity) != NULL;
582}
583
584/**********************************************************************/
588{
589 struct city_dialog *pdialog = get_city_dialog(pcity);
590
591 if (pdialog) {
592 close_city_dialog(pdialog);
593 }
594}
595
596/**********************************************************************/
600{
602 return;
603 }
604
605 while (dialog_list_size(dialog_list)) {
606 close_city_dialog(dialog_list_get(dialog_list, 0));
607 }
608 dialog_list_destroy(dialog_list);
609
611}
612
613/**********************************************************************/
616static gboolean keyboard_handler(GtkWidget * widget, GdkEventKey * event,
617 struct city_dialog *pdialog)
618{
619 if (event->state & GDK_CONTROL_MASK) {
620 switch (event->keyval) {
621 case GDK_KEY_Left:
622 gtk_notebook_prev_page(GTK_NOTEBOOK(pdialog->notebook));
623 return TRUE;
624
625 case GDK_KEY_Right:
626 gtk_notebook_next_page(GTK_NOTEBOOK(pdialog->notebook));
627 return TRUE;
628
629 default:
630 break;
631 }
632 }
633
634 return FALSE;
635}
636
637/**********************************************************************/
640static gboolean show_info_button_release(GtkWidget *w, GdkEventButton *ev,
641 gpointer data)
642{
643 gtk_grab_remove(w);
644 gdk_seat_ungrab(gdk_device_get_seat(ev->device));
645 gtk_widget_destroy(w);
646
647 return FALSE;
648}
649
650/**********************************************************************/
653static gboolean show_info_popup(GtkWidget *w, GdkEventButton *ev,
654 gpointer data)
655{
656 struct city_dialog *pdialog = g_object_get_data(G_OBJECT(w), "pdialog");
657
658 if (ev->button == 1) {
659 GtkWidget *p, *label, *frame;
660 char buf[1024];
661
662 switch (GPOINTER_TO_UINT(data)) {
663 case INFO_SIZE:
664 fc_snprintf(buf, sizeof(buf), _("Population: %d, Specialists: %d"),
665 pdialog->pcity->size, city_specialists(pdialog->pcity));
666 break;
667 case INFO_FOOD:
668 get_city_dialog_output_text(pdialog->pcity, O_FOOD, buf, sizeof(buf));
669 break;
670 case INFO_SHIELD:
672 buf, sizeof(buf));
673 break;
674 case INFO_TRADE:
675 get_city_dialog_output_text(pdialog->pcity, O_TRADE, buf, sizeof(buf));
676 break;
677 case INFO_GOLD:
678 get_city_dialog_output_text(pdialog->pcity, O_GOLD, buf, sizeof(buf));
679 break;
680 case INFO_SCIENCE:
682 buf, sizeof(buf));
683 break;
684 case INFO_LUXURY:
686 buf, sizeof(buf));
687 break;
688 case INFO_CULTURE:
689 get_city_dialog_culture_text(pdialog->pcity, buf, sizeof(buf));
690 break;
691 case INFO_POLLUTION:
692 get_city_dialog_pollution_text(pdialog->pcity, buf, sizeof(buf));
693 break;
694 case INFO_ILLNESS:
695 get_city_dialog_illness_text(pdialog->pcity, buf, sizeof(buf));
696 break;
697 case INFO_AIRLIFT:
698 get_city_dialog_airlift_text(pdialog->pcity, buf, sizeof(buf));
699 break;
700 default:
701 return TRUE;
702 }
703
704 p = gtk_window_new(GTK_WINDOW_POPUP);
705 gtk_widget_set_name(p, "Freeciv");
706 gtk_container_set_border_width(GTK_CONTAINER(p), 2);
707 gtk_window_set_transient_for(GTK_WINDOW(p), GTK_WINDOW(pdialog->shell));
708 gtk_window_set_position(GTK_WINDOW(p), GTK_WIN_POS_MOUSE);
709
710 frame = gtk_frame_new(NULL);
711 gtk_container_add(GTK_CONTAINER(p), frame);
712
713 label = gtk_label_new(buf);
714 gtk_widget_set_name(label, "city_label");
715 gtk_widget_set_margin_start(label, 4);
716 gtk_widget_set_margin_end(label, 4);
717 gtk_widget_set_margin_top(label, 4);
718 gtk_widget_set_margin_bottom(label, 4);
719 gtk_container_add(GTK_CONTAINER(frame), label);
720 gtk_widget_show_all(p);
721
722 gdk_seat_grab(gdk_device_get_seat(ev->device), gtk_widget_get_window(p),
723 GDK_SEAT_CAPABILITY_ALL_POINTING,
724 TRUE, NULL, (GdkEvent *)ev, NULL, NULL);
725 gtk_grab_add(p);
726
727 g_signal_connect_after(p, "button_release_event",
728 G_CALLBACK(show_info_button_release), NULL);
729 }
730 return TRUE;
731}
732
733/**********************************************************************/
737static GtkWidget *create_city_info_table(struct city_dialog *pdialog,
738 GtkWidget **info_ebox,
739 GtkWidget **info_label)
740{
741 int i;
742 GtkWidget *table, *label, *ebox;
743
744 static const char *output_label[NUM_INFO_FIELDS] = {
745 N_("Size:"),
746 N_("Food:"),
747 N_("Prod:"),
748 N_("Trade:"),
749 N_("Gold:"),
750 N_("Luxury:"),
751 N_("Science:"),
752 N_("Granary:"),
753 N_("Change in:"),
754 N_("Corruption:"),
755 N_("Waste:"),
756 N_("Culture:"),
757 N_("Pollution:"),
758 N_("Plague risk:"),
759 N_("Tech Stolen:"),
760 N_("Airlift:"),
761 };
762 static bool output_label_done;
763
764 table = gtk_grid_new();
765 g_object_set(table, "margin", 4, NULL);
766
767 intl_slist(ARRAY_SIZE(output_label), output_label, &output_label_done);
768
769 for (i = 0; i < NUM_INFO_FIELDS; i++) {
770 label = gtk_label_new(output_label[i]);
771 switch (i) {
772 case INFO_SIZE:
773 case INFO_TRADE:
774 case INFO_SCIENCE:
775 case INFO_GROWTH:
776 gtk_widget_set_margin_bottom(label, 5);
777 break;
778
779 case INFO_FOOD:
780 case INFO_GOLD:
781 case INFO_GRANARY:
782 case INFO_CORRUPTION:
783 gtk_widget_set_margin_top(label, 5);
784 break;
785 default:
786 break;
787 }
788 gtk_widget_set_margin_end(label, 5);
789 gtk_widget_set_name(label, "city_label"); /* for font style? */
790 gtk_widget_set_halign(label, GTK_ALIGN_START);
791 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
792 gtk_grid_attach(GTK_GRID(table), label, 0, i, 1, 1);
793
794 ebox = gtk_event_box_new();
795 switch (i) {
796 case INFO_TRADE:
797 case INFO_SCIENCE:
798 case INFO_GROWTH:
799 gtk_widget_set_margin_bottom(ebox, 5);
800 break;
801
802 case INFO_GOLD:
803 case INFO_GRANARY:
804 case INFO_CORRUPTION:
805 gtk_widget_set_margin_top(ebox, 5);
806 break;
807 default:
808 break;
809 }
810 gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE);
811 g_object_set_data(G_OBJECT(ebox), "pdialog", pdialog);
812 g_signal_connect(ebox, "button_press_event",
813 G_CALLBACK(show_info_popup), GUINT_TO_POINTER(i));
814 info_ebox[i] = ebox;
815
816 label = gtk_label_new("");
817 info_label[i] = label;
818 gtk_widget_set_name(label, "city_label"); /* ditto */
819 gtk_widget_set_halign(label, GTK_ALIGN_START);
820 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
821
822 gtk_container_add(GTK_CONTAINER(ebox), label);
823
824 gtk_grid_attach(GTK_GRID(table), ebox, 1, i, 1, 1);
825 }
826
827 /*
828 * Allow special highlighting of emergencies for granary etc by
829 * city_dialog_update_information().
830 */
831 {
832 /* This will persist, and can be shared between overview and happiness
833 * pages. */
834 static GtkCssProvider *emergency_provider = NULL;
835
836 if (emergency_provider == NULL) {
837 emergency_provider = gtk_css_provider_new();
838
839 gtk_css_provider_load_from_data(emergency_provider,
840 ".emergency {\n"
841 " color: rgba(255, 0.0, 0.0, 255);\n"
842 "}",
843 -1, NULL);
844 }
845
846 /* GRANARY */
847 gtk_style_context_add_provider(gtk_widget_get_style_context(info_label[INFO_GRANARY]),
848 GTK_STYLE_PROVIDER(emergency_provider),
849 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
850 /* GROWTH */
851 gtk_style_context_add_provider(gtk_widget_get_style_context(info_label[INFO_GROWTH]),
852 GTK_STYLE_PROVIDER(emergency_provider),
853 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
854 /* POLLUTION */
855 gtk_style_context_add_provider(gtk_widget_get_style_context(info_label[INFO_POLLUTION]),
856 GTK_STYLE_PROVIDER(emergency_provider),
857 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
858 /* ILLNESS */
859 gtk_style_context_add_provider(gtk_widget_get_style_context(info_label[INFO_ILLNESS]),
860 GTK_STYLE_PROVIDER(emergency_provider),
861 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
862 }
863
864 gtk_widget_show_all(table);
865
866 return table;
867}
868
869/**********************************************************************/
872static void create_citydlg_main_map(struct city_dialog *pdialog,
873 GtkWidget *container)
874{
875 GtkWidget *frame;
876
877 frame = gtk_frame_new(_("City map"));
878 gtk_widget_set_size_request(frame, CITY_MAP_MIN_SIZE_X,
880 gtk_container_add(GTK_CONTAINER(container), frame);
881
882 city_dialog_map_create(pdialog, &pdialog->overview.map_canvas);
883 gtk_container_add(GTK_CONTAINER(frame), pdialog->overview.map_canvas.sw);
884}
885
886/**********************************************************************/
889static GtkWidget *create_citydlg_improvement_list(struct city_dialog *pdialog,
890 GtkWidget *vbox)
891{
892 GtkWidget *view;
893 GtkListStore *store;
894 GtkCellRenderer *rend;
895
896 /* improvements */
897 /* gtk list store columns: 0 - sell value, 1 - sprite,
898 2 - description, 3 - upkeep, 4 - is redundant, 5 - tooltip */
899 store = gtk_list_store_new(6, G_TYPE_POINTER, GDK_TYPE_PIXBUF,
900 G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN,
901 G_TYPE_STRING);
902
903 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
904 gtk_widget_set_hexpand(view, TRUE);
905 gtk_widget_set_vexpand(view, TRUE);
906 g_object_unref(store);
907 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
908 gtk_widget_set_name(view, "small_font");
909 pdialog->overview.improvement_list = view;
910
911 rend = gtk_cell_renderer_pixbuf_new();
912 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, NULL,
913 rend, "pixbuf", 1, NULL);
914 rend = gtk_cell_renderer_text_new();
915 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, NULL,
916 rend, "text", 2,
917 "strikethrough", 4, NULL);
918 rend = gtk_cell_renderer_text_new();
919 g_object_set(rend, "xalign", 1.0, NULL);
920 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, NULL,
921 rend, "text", 3,
922 "strikethrough", 4, NULL);
923
924 gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(view), 5);
925
926 g_signal_connect(view, "row_activated", G_CALLBACK(impr_callback),
927 pdialog);
928
929 return view;
930}
931
932/**********************************************************************/
949{
950 GtkWidget *page, *bottom;
951 GtkWidget *hbox, *right, *vbox, *frame, *table;
952 GtkWidget *label, *sw, *view, *bar, *production_combo;
953 GtkCellRenderer *rend;
954 GtkListStore *production_store;
955 /* TRANS: Overview tab in city dialog */
956 const char *tab_title = _("_Overview");
957 int unit_height = tileset_unit_with_upkeep_height(tileset);
958
959 /* main page */
960 page = gtk_grid_new();
961 gtk_orientable_set_orientation(GTK_ORIENTABLE(page),
962 GTK_ORIENTATION_VERTICAL);
963 gtk_container_set_border_width(GTK_CONTAINER(page), 8);
964 label = gtk_label_new_with_mnemonic(tab_title);
965 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->notebook), page, label);
966
967 if (!low_citydlg) {
968 GtkWidget *middle;
969
970 /* middle: city map, improvements */
971 middle = gtk_grid_new();
972 gtk_grid_set_column_spacing(GTK_GRID(middle), 6);
973 gtk_container_add(GTK_CONTAINER(page), middle);
974
975 /* city map */
976 create_citydlg_main_map(pdialog, middle);
977
978 /* improvements */
979 vbox = gtk_grid_new();
980 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
981 GTK_ORIENTATION_VERTICAL);
982 gtk_container_add(GTK_CONTAINER(middle), vbox);
983
984 view = create_citydlg_improvement_list(pdialog, middle);
985
986 label = g_object_new(GTK_TYPE_LABEL, "label", _("Production:"),
987 "xalign", 0.0, "yalign", 0.5, NULL);
988 gtk_container_add(GTK_CONTAINER(vbox), label);
989
990 hbox = gtk_grid_new();
991 gtk_grid_set_column_spacing(GTK_GRID(hbox), 10);
992 gtk_container_add(GTK_CONTAINER(vbox), hbox);
993
994 production_store = gtk_list_store_new(4, GDK_TYPE_PIXBUF, G_TYPE_STRING,
995 G_TYPE_INT, G_TYPE_BOOLEAN);
996 pdialog->overview.change_production_store = production_store;
997
999 gtk_combo_box_new_with_model(GTK_TREE_MODEL(production_store));
1000 gtk_widget_set_hexpand(production_combo, TRUE);
1002 gtk_container_add(GTK_CONTAINER(hbox), production_combo);
1003 g_object_unref(production_store);
1004 g_signal_connect(production_combo, "changed",
1005 G_CALLBACK(change_production_callback), pdialog);
1006
1007 gtk_cell_layout_clear(GTK_CELL_LAYOUT(production_combo));
1008 rend = gtk_cell_renderer_pixbuf_new();
1009 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(production_combo), rend, TRUE);
1010 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(production_combo),
1011 rend, "pixbuf", 0, NULL);
1012 g_object_set(rend, "xalign", 0.0, NULL);
1013
1014 rend = gtk_cell_renderer_text_new();
1015 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(production_combo), rend, TRUE);
1016 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(production_combo),
1017 rend, "text", 1, "strikethrough", 3, NULL);
1018
1019 bar = gtk_progress_bar_new();
1020 gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(bar), TRUE);
1021 pdialog->overview.production_bar = bar;
1022 gtk_container_add(GTK_CONTAINER(production_combo), bar);
1023 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(production_combo), 3);
1024
1025 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(bar), _("%d/%d %d turns"));
1026
1027 pdialog->overview.buy_command
1028 = icon_label_button_new("system-run", _("_Buy"));
1029 gtk_container_add(GTK_CONTAINER(hbox), GTK_WIDGET(pdialog->overview.buy_command));
1030 g_signal_connect(pdialog->overview.buy_command, "clicked",
1031 G_CALLBACK(buy_callback), pdialog);
1032
1033 label = g_object_new(GTK_TYPE_LABEL, "use-underline", TRUE,
1034 "mnemonic-widget", view,
1035 "label", _("I_mprovements:"),
1036 "xalign", 0.0, "yalign", 0.5, NULL);
1037 gtk_container_add(GTK_CONTAINER(vbox), label);
1038
1039 sw = gtk_scrolled_window_new(NULL, NULL);
1040 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
1041 GTK_SHADOW_ETCHED_IN);
1042 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
1043 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1044 gtk_container_add(GTK_CONTAINER(vbox), sw);
1045
1046 gtk_container_add(GTK_CONTAINER(sw), view);
1047 } else {
1048 pdialog->overview.buy_command = NULL;
1049 pdialog->overview.production_bar = NULL;
1050 pdialog->overview.production_combo = NULL;
1051 pdialog->overview.change_production_store = NULL;
1052 }
1053
1054 /* bottom: info, units */
1055 bottom = gtk_grid_new();
1056 gtk_grid_set_column_spacing(GTK_GRID(bottom), 6);
1057 gtk_container_add(GTK_CONTAINER(page), bottom);
1058
1059 /* info */
1060 frame = gtk_frame_new(_("Info"));
1061 gtk_container_add(GTK_CONTAINER(bottom), frame);
1062
1063 table = create_city_info_table(pdialog,
1064 pdialog->overview.info_ebox,
1065 pdialog->overview.info_label);
1066 gtk_widget_set_halign(table, GTK_ALIGN_CENTER);
1067 gtk_widget_set_valign(table, GTK_ALIGN_CENTER);
1068 gtk_container_add(GTK_CONTAINER(frame), table);
1069
1070 /* right: present and supported units (overview page) */
1071 right = gtk_grid_new();
1072 gtk_orientable_set_orientation(GTK_ORIENTABLE(right),
1073 GTK_ORIENTATION_VERTICAL);
1074 gtk_container_add(GTK_CONTAINER(bottom), right);
1075
1076 pdialog->overview.supported_units_frame = gtk_frame_new("");
1077 gtk_container_add(GTK_CONTAINER(right),
1079 pdialog->overview.present_units_frame = gtk_frame_new("");
1080 gtk_container_add(GTK_CONTAINER(right),
1081 pdialog->overview.present_units_frame);
1082
1083 /* supported units */
1084 sw = gtk_scrolled_window_new(NULL, NULL);
1085 gtk_widget_set_hexpand(sw, TRUE);
1086 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
1087 GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
1088 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
1089 GTK_SHADOW_NONE);
1090 gtk_container_add(GTK_CONTAINER(pdialog->overview.supported_units_frame),
1091 sw);
1092
1093
1094 table = gtk_grid_new();
1095 gtk_grid_set_column_spacing(GTK_GRID(table), 2);
1096 gtk_widget_set_size_request(table, -1, unit_height);
1097 gtk_container_add(GTK_CONTAINER(sw), table);
1098
1099 gtk_container_set_focus_hadjustment(GTK_CONTAINER(table),
1100 gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(sw)));
1101 gtk_container_set_focus_vadjustment(GTK_CONTAINER(table),
1102 gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(sw)));
1103
1104 pdialog->overview.supported_unit_table = table;
1105 unit_node_vector_init(&pdialog->overview.supported_units);
1106
1107 /* present units */
1108 sw = gtk_scrolled_window_new(NULL, NULL);
1109 gtk_widget_set_hexpand(sw, TRUE);
1110 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
1111 GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
1112 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
1113 GTK_SHADOW_NONE);
1114 gtk_container_add(GTK_CONTAINER(pdialog->overview.present_units_frame), sw);
1115
1116 table = gtk_grid_new();
1117 gtk_grid_set_column_spacing(GTK_GRID(table), 2);
1118 gtk_widget_set_size_request(table, -1, unit_height);
1119 gtk_container_add(GTK_CONTAINER(sw), table);
1120
1121 gtk_container_set_focus_hadjustment(GTK_CONTAINER(table),
1122 gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(sw)));
1123 gtk_container_set_focus_vadjustment(GTK_CONTAINER(table),
1124 gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(sw)));
1125
1126 pdialog->overview.present_unit_table = table;
1127 unit_node_vector_init(&pdialog->overview.present_units);
1128
1129 /* show page */
1130 gtk_widget_show_all(page);
1131}
1132
1133/**********************************************************************/
1136static void create_and_append_map_page(struct city_dialog *pdialog)
1137{
1138 if (low_citydlg) {
1139 GtkWidget *page;
1140 GtkWidget *label;
1141 const char *tab_title = _("Citymap");
1142
1143 page = gtk_grid_new();
1144 gtk_orientable_set_orientation(GTK_ORIENTABLE(page),
1145 GTK_ORIENTATION_VERTICAL);
1146 gtk_container_set_border_width(GTK_CONTAINER(page), 8);
1147 label = gtk_label_new_with_mnemonic(tab_title);
1148 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->notebook), page, label);
1149
1150 create_citydlg_main_map(pdialog, page);
1151
1152 gtk_widget_show_all(page);
1153 }
1154}
1155
1156/**********************************************************************/
1159static void target_drag_data_received(GtkWidget *w,
1160 GdkDragContext *context,
1161 gint x, gint y,
1162 GtkSelectionData *data,
1163 guint info, guint time,
1164 gpointer user_data)
1165{
1166 struct city_dialog *pdialog = (struct city_dialog *) user_data;
1167 GtkTreeModel *model;
1168 GtkTreePath *path;
1169
1170 if (NULL != client.conn.playing
1171 && city_owner(pdialog->pcity) != client.conn.playing) {
1172 gtk_drag_finish(context, FALSE, FALSE, time);
1173 }
1174
1175 if (gtk_tree_get_row_drag_data(data, &model, &path)) {
1176 GtkTreeIter it;
1177
1178 if (gtk_tree_model_get_iter(model, &it, path)) {
1179 cid id;
1180 struct universal univ;
1181
1182 gtk_tree_model_get(model, &it, 0, &id, -1);
1183 univ = cid_production(id);
1184 city_change_production(pdialog->pcity, &univ);
1185 gtk_drag_finish(context, TRUE, FALSE, time);
1186 }
1187 gtk_tree_path_free(path);
1188 }
1189
1190 gtk_drag_finish(context, FALSE, FALSE, time);
1191}
1192
1193/**********************************************************************/
1197static void create_production_header(struct city_dialog *pdialog, GtkContainer *contain)
1198{
1199 GtkWidget *hbox, *bar;
1200
1201 hbox = gtk_grid_new();
1202 g_object_set(hbox, "margin", 2, NULL);
1203 gtk_grid_set_column_spacing(GTK_GRID(hbox), 10);
1204 gtk_container_add(contain, hbox);
1205
1206 /* The label is set in city_dialog_update_building() */
1207 bar = gtk_progress_bar_new();
1208 gtk_widget_set_hexpand(bar, TRUE);
1209 gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(bar), TRUE);
1210 pdialog->production.production_bar = bar;
1211 gtk_container_add(GTK_CONTAINER(hbox), bar);
1212 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(bar), _("%d/%d %d turns"));
1213
1215
1216 g_signal_connect(bar, "drag_data_received",
1217 G_CALLBACK(target_drag_data_received), pdialog);
1218
1219 pdialog->production.buy_command
1220 = icon_label_button_new("system-run", _("_Buy"));
1221 gtk_container_add(GTK_CONTAINER(hbox), GTK_WIDGET(pdialog->production.buy_command));
1222
1223 g_signal_connect(pdialog->production.buy_command, "clicked",
1224 G_CALLBACK(buy_callback), pdialog);
1225}
1226
1227/**********************************************************************/
1231{
1232 if (low_citydlg) {
1233 GtkWidget *page;
1234 GtkWidget *label;
1235 GtkWidget *vbox;
1236 GtkWidget *view;
1237 const char *tab_title = _("Buildings");
1238
1239 page = gtk_grid_new();
1240 gtk_orientable_set_orientation(GTK_ORIENTABLE(page),
1241 GTK_ORIENTATION_VERTICAL);
1242 gtk_container_set_border_width(GTK_CONTAINER(page), 8);
1243 label = gtk_label_new_with_mnemonic(tab_title);
1244
1245 create_production_header(pdialog, GTK_CONTAINER(page));
1246 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->notebook), page, label);
1247
1248 vbox = gtk_grid_new();
1249 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
1250 GTK_ORIENTATION_VERTICAL);
1251 gtk_container_add(GTK_CONTAINER(page), vbox);
1252
1253 view = create_citydlg_improvement_list(pdialog, vbox);
1254
1255 gtk_container_add(GTK_CONTAINER(vbox), view);
1256
1257 gtk_widget_show_all(page);
1258 }
1259}
1260
1261/**********************************************************************/
1265{
1266 const char *tab_title = _("P_roduction");
1267 GtkWidget *label = gtk_label_new_with_mnemonic(tab_title);
1268 GtkWidget *page, *editor;
1269
1270 page = gtk_grid_new();
1271 gtk_orientable_set_orientation(GTK_ORIENTABLE(page),
1272 GTK_ORIENTATION_VERTICAL);
1273 gtk_container_set_border_width(GTK_CONTAINER(page), 8);
1274 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->notebook), page, label);
1275
1276 /* stuff that's being currently built */
1277 if (!low_citydlg) {
1278 label = g_object_new(GTK_TYPE_LABEL,
1279 "label", _("Production:"),
1280 "xalign", 0.0, "yalign", 0.5, NULL);
1281 pdialog->production.production_label = label;
1282 gtk_container_add(GTK_CONTAINER(page), label);
1283
1284 create_production_header(pdialog, GTK_CONTAINER(page));
1285 } else {
1286 pdialog->production.production_label = NULL;
1287 }
1288
1290 g_object_set(editor, "margin", 6, NULL);
1291 reset_city_worklist(editor, pdialog->pcity);
1292 gtk_container_add(GTK_CONTAINER(page), editor);
1293 pdialog->production.worklist = editor;
1294
1295 gtk_widget_show_all(page);
1296}
1297
1298/**********************************************************************/
1309{
1310 GtkWidget *page, *label, *table, *right, *left, *frame;
1311 const char *tab_title = _("Happ_iness");
1312
1313 /* main page */
1314 page = gtk_grid_new();
1315 gtk_grid_set_column_spacing(GTK_GRID(page), 6);
1316 gtk_container_set_border_width(GTK_CONTAINER(page), 8);
1317 label = gtk_label_new_with_mnemonic(tab_title);
1318 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->notebook), page, label);
1319
1320 /* left: info, citizens */
1321 left = gtk_grid_new();
1322 gtk_orientable_set_orientation(GTK_ORIENTABLE(left),
1323 GTK_ORIENTATION_VERTICAL);
1324 gtk_container_add(GTK_CONTAINER(page), left);
1325
1326 if (!low_citydlg) {
1327 /* upper left: info */
1328 frame = gtk_frame_new(_("Info"));
1329 gtk_container_add(GTK_CONTAINER(left), frame);
1330
1331 table = create_city_info_table(pdialog,
1332 pdialog->happiness.info_ebox,
1333 pdialog->happiness.info_label);
1334 gtk_widget_set_halign(table, GTK_ALIGN_CENTER);
1335 gtk_container_add(GTK_CONTAINER(frame), table);
1336 }
1337
1338 /* lower left: citizens */
1340 pdialog->happiness.citizens = gtk_grid_new();
1341 gtk_orientable_set_orientation(
1342 GTK_ORIENTABLE(pdialog->happiness.citizens),
1343 GTK_ORIENTATION_VERTICAL);
1344 gtk_container_add(GTK_CONTAINER(left), pdialog->happiness.citizens);
1345 gtk_container_add(GTK_CONTAINER(pdialog->happiness.citizens),
1346 citizens_dialog_display(pdialog->pcity));
1347 }
1348
1349 /* right: city map, happiness */
1350 right = gtk_grid_new();
1351 gtk_orientable_set_orientation(GTK_ORIENTABLE(right),
1352 GTK_ORIENTATION_VERTICAL);
1353 gtk_container_add(GTK_CONTAINER(page), right);
1354
1355 if (!low_citydlg) {
1356 /* upper right: city map */
1357 frame = gtk_frame_new(_("City map"));
1358 gtk_widget_set_size_request(frame, CITY_MAP_MIN_SIZE_X,
1360 gtk_container_add(GTK_CONTAINER(right), frame);
1361
1362 city_dialog_map_create(pdialog, &pdialog->happiness.map_canvas);
1363 gtk_container_add(GTK_CONTAINER(frame), pdialog->happiness.map_canvas.sw);
1364 }
1365
1366 /* lower right: happiness */
1367 pdialog->happiness.widget = gtk_grid_new();
1368 gtk_orientable_set_orientation(GTK_ORIENTABLE(pdialog->happiness.widget),
1369 GTK_ORIENTATION_VERTICAL);
1370 gtk_container_add(GTK_CONTAINER(right), pdialog->happiness.widget);
1371 gtk_container_add(GTK_CONTAINER(pdialog->happiness.widget),
1372 get_top_happiness_display(pdialog->pcity, low_citydlg, pdialog->shell));
1373
1374 /* show page */
1375 gtk_widget_show_all(page);
1376}
1377
1378/**********************************************************************/
1381static void create_and_append_cma_page(struct city_dialog *pdialog)
1382{
1383 GtkWidget *page, *label;
1384 const char *tab_title = _("_Governor");
1385
1386 page = gtk_grid_new();
1387
1388 label = gtk_label_new_with_mnemonic(tab_title);
1389
1390 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->notebook), page, label);
1391
1392 pdialog->cma_editor = create_cma_dialog(pdialog->pcity, low_citydlg);
1393 gtk_container_add(GTK_CONTAINER(page), pdialog->cma_editor->shell);
1394
1395 gtk_widget_show(page);
1396}
1397
1398/**********************************************************************/
1402{
1403 int i;
1404 GtkWidget *vbox2, *page, *frame, *label, *button;
1405 GtkSizeGroup *size;
1406 GSList *group;
1407 const char *tab_title = _("_Settings");
1408
1409 static const char *new_citizens_output_label[] = {
1410 N_("Luxury"),
1411 N_("Science"),
1412 N_("Gold")
1413 };
1414
1415 static const char *disband_label
1416 = N_("Allow unit production to disband city");
1417
1418 static const char *misc_whichtab_label[NUM_PAGES] = {
1419 N_("Overview page"),
1420 N_("Production page"),
1421 N_("Happiness page"),
1422 N_("Governor page"),
1423 N_("This Settings page"),
1424 N_("Last active page")
1425 };
1426
1427 static bool new_citizens_label_done;
1428 static bool misc_whichtab_label_done;
1429
1430 /* initialize signal_blocker */
1431 pdialog->misc.block_signal = 0;
1432
1433
1434 page = gtk_grid_new();
1435 gtk_grid_set_column_spacing(GTK_GRID(page), 18);
1436 gtk_container_set_border_width(GTK_CONTAINER(page), 8);
1437
1438 size = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
1439
1440 label = gtk_label_new_with_mnemonic(tab_title);
1441
1442 gtk_notebook_append_page(GTK_NOTEBOOK(pdialog->notebook), page, label);
1443
1444 /* new_citizens radio */
1445 frame = gtk_frame_new(_("New citizens produce"));
1446 gtk_grid_attach(GTK_GRID(page), frame, 0, 0, 1, 1);
1447 gtk_size_group_add_widget(size, frame);
1448
1449 vbox2 = gtk_grid_new();
1450 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox2),
1451 GTK_ORIENTATION_VERTICAL);
1452 gtk_container_add(GTK_CONTAINER(frame), vbox2);
1453
1454 intl_slist(ARRAY_SIZE(new_citizens_output_label), new_citizens_output_label,
1455 &new_citizens_label_done);
1456
1457 group = NULL;
1458 for (i = 0; i < ARRAY_SIZE(new_citizens_output_label); i++) {
1459 button = gtk_radio_button_new_with_mnemonic(group, new_citizens_output_label[i]);
1460 pdialog->misc.new_citizens_radio[i] = button;
1461 gtk_container_add(GTK_CONTAINER(vbox2), button);
1462 g_signal_connect(button, "toggled",
1463 G_CALLBACK(cityopt_callback), pdialog);
1464 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button));
1465 }
1466
1467 /* next is the next-time-open radio group in the right column */
1468 frame = gtk_frame_new(_("Next time open"));
1469 gtk_grid_attach(GTK_GRID(page), frame, 1, 0, 1, 1);
1470 gtk_size_group_add_widget(size, frame);
1471
1472 vbox2 = gtk_grid_new();
1473 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox2),
1474 GTK_ORIENTATION_VERTICAL);
1475 gtk_container_add(GTK_CONTAINER(frame), vbox2);
1476
1477 intl_slist(ARRAY_SIZE(misc_whichtab_label), misc_whichtab_label,
1478 &misc_whichtab_label_done);
1479
1480 group = NULL;
1481 for (i = 0; i < ARRAY_SIZE(misc_whichtab_label); i++) {
1482 button = gtk_radio_button_new_with_mnemonic(group, misc_whichtab_label[i]);
1483 pdialog->misc.whichtab_radio[i] = button;
1484 gtk_container_add(GTK_CONTAINER(vbox2), button);
1485 g_signal_connect(button, "toggled",
1486 G_CALLBACK(misc_whichtab_callback), GINT_TO_POINTER(i));
1487 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button));
1488 }
1489
1490 /* now we go back and fill the hbox rename */
1491 frame = gtk_frame_new(_("City"));
1492 gtk_widget_set_margin_top(frame, 12);
1493 gtk_widget_set_margin_bottom(frame, 12);
1494 gtk_grid_attach(GTK_GRID(page), frame, 0, 1, 1, 1);
1495
1496 vbox2 = gtk_grid_new();
1497 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox2),
1498 GTK_ORIENTATION_VERTICAL);
1499 gtk_container_add(GTK_CONTAINER(frame), vbox2);
1500
1501 button = gtk_button_new_with_mnemonic(_("R_ename..."));
1502 pdialog->misc.rename_command = button;
1503 gtk_container_add(GTK_CONTAINER(vbox2), button);
1504 g_signal_connect(button, "clicked",
1505 G_CALLBACK(rename_callback), pdialog);
1506
1507 gtk_widget_set_sensitive(button, can_client_issue_orders());
1508
1509 /* the disband-city-on-unit-production button */
1510 button = gtk_check_button_new_with_mnemonic(_(disband_label));
1511 pdialog->misc.disband_on_settler = button;
1512 gtk_container_add(GTK_CONTAINER(vbox2), button);
1513 g_signal_connect(button, "toggled",
1514 G_CALLBACK(cityopt_callback), pdialog);
1515
1516 /* we choose which page to popup by default */
1517 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
1518 (pdialog->
1520 TRUE);
1521
1522 set_cityopt_values(pdialog);
1523
1524 gtk_widget_show_all(page);
1525
1526 if (new_dialog_def_page == (NUM_PAGES - 1)) {
1527 gtk_notebook_set_current_page(GTK_NOTEBOOK(pdialog->notebook),
1528 last_page);
1529 } else {
1530 gtk_notebook_set_current_page(GTK_NOTEBOOK(pdialog->notebook),
1532 }
1533}
1534
1535/**********************************************************************/
1544{
1545 struct city_dialog *pdialog;
1546 GtkWidget *close_command;
1547 GtkWidget *vbox, *hbox, *cbox, *ebox;
1548 int citizen_bar_width;
1549 int citizen_bar_height;
1550 struct player *owner;
1551
1554 }
1555
1556 pdialog = fc_malloc(sizeof(struct city_dialog));
1557 pdialog->pcity = pcity;
1558 pdialog->sell_shell = NULL;
1559 pdialog->rename_shell = NULL;
1560 pdialog->happiness.map_canvas.sw = NULL; /* make sure NULL if spy */
1561 pdialog->happiness.map_canvas.ebox = NULL; /* ditto */
1562 pdialog->happiness.map_canvas.darea = NULL; /* ditto */
1563 pdialog->happiness.citizens = NULL; /* ditto */
1564 pdialog->production.buy_command = NULL;
1565 pdialog->production.production_label = NULL;
1566 pdialog->production.production_bar = NULL;
1567 pdialog->cma_editor = NULL;
1569 = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1571
1572 pdialog->shell = gtk_dialog_new();
1573 gtk_window_set_title(GTK_WINDOW(pdialog->shell), city_name_get(pcity));
1574 setup_dialog(pdialog->shell, toplevel);
1575 gtk_window_set_role(GTK_WINDOW(pdialog->shell), "city");
1576
1577 g_signal_connect(pdialog->shell, "destroy",
1578 G_CALLBACK(city_destroy_callback), pdialog);
1579 gtk_window_set_position(GTK_WINDOW(pdialog->shell), GTK_WIN_POS_MOUSE);
1580 gtk_widget_set_name(pdialog->shell, "Freeciv");
1581
1582 gtk_widget_realize(pdialog->shell);
1583
1584 /* keep the icon of the executable on Windows (see PR#36491) */
1585#ifndef FREECIV_MSWINDOWS
1586 {
1588
1589 /* Only call this after tileset_load_tiles is called. */
1590 gtk_window_set_icon(GTK_WINDOW(pdialog->shell), pixbuf);
1591 g_object_unref(pixbuf);
1592 }
1593#endif /* FREECIV_MSWINDOWS */
1594
1595 /* Restore size of the city dialog. */
1596 gtk_window_set_default_size(GTK_WINDOW(pdialog->shell),
1597 GUI_GTK_OPTION(citydlg_xsize),
1598 GUI_GTK_OPTION(citydlg_ysize));
1599
1600 pdialog->popup_menu = gtk_menu_new();
1601
1602 vbox = gtk_dialog_get_content_area(GTK_DIALOG(pdialog->shell));
1603 hbox = gtk_grid_new();
1604 gtk_grid_set_column_homogeneous(GTK_GRID(hbox), TRUE);
1605 gtk_container_add(GTK_CONTAINER(vbox), hbox);
1606
1607 /**** Citizens bar here ****/
1608 cbox = gtk_grid_new();
1609 gtk_container_add(GTK_CONTAINER(hbox), cbox);
1610
1611 ebox = gtk_event_box_new();
1612 gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE);
1613 gtk_container_add(GTK_CONTAINER(cbox), ebox);
1614
1616 citizen_bar_height = tileset_small_sprite_height(tileset);
1617
1618 pdialog->citizen_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1619 citizen_bar_width, citizen_bar_height);
1620 pdialog->citizen_images = gtk_image_new_from_surface(pdialog->citizen_surface);
1621
1622 gtk_widget_add_events(pdialog->citizen_images, GDK_BUTTON_PRESS_MASK);
1623 gtk_widget_set_margin_start(pdialog->citizen_images, 2);
1624 gtk_widget_set_margin_end(pdialog->citizen_images, 2);
1625 gtk_widget_set_margin_top(pdialog->citizen_images, 2);
1626 gtk_widget_set_margin_bottom(pdialog->citizen_images, 2);
1627 gtk_widget_set_halign(pdialog->citizen_images, GTK_ALIGN_START);
1628 gtk_widget_set_valign(pdialog->citizen_images, GTK_ALIGN_CENTER);
1629 gtk_container_add(GTK_CONTAINER(ebox), pdialog->citizen_images);
1630 g_signal_connect(G_OBJECT(ebox), "button-press-event",
1631 G_CALLBACK(citizens_callback), pdialog);
1632
1633 /**** City name label here ****/
1634 pdialog->name_label = gtk_label_new(NULL);
1635 gtk_widget_set_hexpand(pdialog->name_label, TRUE);
1636 gtk_widget_set_halign(pdialog->name_label, GTK_ALIGN_START);
1637 gtk_widget_set_valign(pdialog->name_label, GTK_ALIGN_CENTER);
1638 gtk_container_add(GTK_CONTAINER(hbox), pdialog->name_label);
1639
1640 /**** -Start of Notebook- ****/
1641
1642 pdialog->notebook = gtk_notebook_new();
1643 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(pdialog->notebook),
1644 GTK_POS_BOTTOM);
1645 gtk_container_add(GTK_CONTAINER(vbox), pdialog->notebook);
1646
1650
1651 owner = city_owner(pcity);
1652
1653 /* Only create these tabs if not a spy */
1657 }
1658
1659 if (owner == client_player()
1660 && !client_is_observer()) {
1663 } else {
1664 gtk_notebook_set_current_page(GTK_NOTEBOOK(pdialog->notebook),
1666 }
1667
1668 /**** End of Notebook ****/
1669
1670 /* bottom buttons */
1671
1672 pdialog->show_units_command =
1673 gtk_dialog_add_button(GTK_DIALOG(pdialog->shell), _("_List present units..."), CDLGR_UNITS);
1674
1675 g_signal_connect(GTK_DIALOG(pdialog->shell), "response",
1676 G_CALLBACK(citydlg_response_callback), pdialog);
1677
1678 pdialog->prev_command = gtk_button_new_from_icon_name("go-previous", 0);
1679 gtk_dialog_add_action_widget(GTK_DIALOG(pdialog->shell),
1680 GTK_WIDGET(pdialog->prev_command), 1);
1681
1682 pdialog->next_command = gtk_button_new_from_icon_name("go-next", 0);
1683 gtk_dialog_add_action_widget(GTK_DIALOG(pdialog->shell),
1684 GTK_WIDGET(pdialog->next_command), 2);
1685
1686 if (owner != client_player()) {
1687 gtk_widget_set_sensitive(GTK_WIDGET(pdialog->prev_command), FALSE);
1688 gtk_widget_set_sensitive(GTK_WIDGET(pdialog->next_command), FALSE);
1689 }
1690
1691 close_command = gtk_dialog_add_button(GTK_DIALOG(pdialog->shell),
1692 _("_Close"), GTK_RESPONSE_CLOSE);
1693
1694 gtk_dialog_set_default_response(GTK_DIALOG(pdialog->shell),
1695 GTK_RESPONSE_CLOSE);
1696
1697 g_signal_connect(close_command, "clicked",
1698 G_CALLBACK(close_callback), pdialog);
1699
1700 g_signal_connect(pdialog->prev_command, "clicked",
1701 G_CALLBACK(switch_city_callback), pdialog);
1702
1703 g_signal_connect(pdialog->next_command, "clicked",
1704 G_CALLBACK(switch_city_callback), pdialog);
1705
1706 /* some other things we gotta do */
1707
1708 g_signal_connect(pdialog->shell, "key_press_event",
1709 G_CALLBACK(keyboard_handler), pdialog);
1710
1711 dialog_list_prepend(dialog_list, pdialog);
1712
1714
1715 /* need to do this every time a new dialog is opened. */
1717
1718 gtk_widget_show_all(pdialog->shell);
1719
1720 gtk_window_set_focus(GTK_WINDOW(pdialog->shell), close_command);
1721
1722 return pdialog;
1723}
1724
1725/**************** Functions to update parts of the dialog ****************/
1726/**********************************************************************/
1729static void city_dialog_update_title(struct city_dialog *pdialog)
1730{
1731 gchar *buf;
1732 const gchar *now;
1733
1734 if (city_unhappy(pdialog->pcity)) {
1735 /* TRANS: city dialog title */
1736 buf = g_strdup_printf(_("<b>%s</b> - %s citizens - DISORDER"),
1737 city_name_get(pdialog->pcity),
1739 } else if (city_celebrating(pdialog->pcity)) {
1740 /* TRANS: city dialog title */
1741 buf = g_strdup_printf(_("<b>%s</b> - %s citizens - celebrating"),
1742 city_name_get(pdialog->pcity),
1744 } else if (city_happy(pdialog->pcity)) {
1745 /* TRANS: city dialog title */
1746 buf = g_strdup_printf(_("<b>%s</b> - %s citizens - happy"),
1747 city_name_get(pdialog->pcity),
1749 } else {
1750 /* TRANS: city dialog title */
1751 buf = g_strdup_printf(_("<b>%s</b> - %s citizens"),
1752 city_name_get(pdialog->pcity),
1754 }
1755
1756 now = gtk_label_get_text(GTK_LABEL(pdialog->name_label));
1757 if (strcmp(now, buf) != 0) {
1758 gtk_window_set_title(GTK_WINDOW(pdialog->shell), city_name_get(pdialog->pcity));
1759 gtk_label_set_markup(GTK_LABEL(pdialog->name_label), buf);
1760 }
1761
1762 g_free(buf);
1763}
1764
1765/**********************************************************************/
1768static void city_dialog_update_citizens(struct city_dialog *pdialog)
1769{
1770 enum citizen_category categories[MAX_CITY_SIZE];
1771 int i, width, full_width, total_used_width;
1772 int citizen_bar_width, citizen_bar_height;
1773 struct city *pcity = pdialog->pcity;
1774 int num_citizens = get_city_citizen_types(pcity, FEELING_FINAL, categories);
1775 cairo_t *cr;
1776
1777 /* If there is not enough space we stack the icons. We draw from left to */
1778 /* right. width is how far we go to the right for each drawn pixmap. The */
1779 /* last icon is always drawn in full, and so has reserved */
1780 /* tileset_small_sprite_width(tileset) pixels. */
1781
1782 full_width = tileset_small_sprite_width(tileset);
1783 if (num_citizens > 1) {
1784 width = MIN(full_width, ((NUM_CITIZENS_SHOWN - 1) * full_width)
1785 / (num_citizens - 1));
1786 } else {
1787 width = full_width;
1788 }
1789 pdialog->cwidth = width;
1790
1791 /* overview page */
1792 /* keep these values in sync with create_city_dialog */
1793 citizen_bar_width = full_width * NUM_CITIZENS_SHOWN;
1794 citizen_bar_height = tileset_small_sprite_height(tileset);
1795
1796 cr = cairo_create(pdialog->citizen_surface);
1797
1798 for (i = 0; i < num_citizens; i++) {
1799 cairo_set_source_surface(cr,
1800 get_citizen_sprite(tileset, categories[i], i, pcity)->surface,
1801 i * width, 0);
1802 cairo_rectangle(cr, i * width, 0,
1803 /* Always draw last citizen in full */
1804 i + 1 < num_citizens ? width : full_width,
1805 citizen_bar_height);
1806 cairo_fill(cr);
1807 }
1808
1809 total_used_width = (i - 1) * width + full_width;
1810
1811 if (total_used_width < citizen_bar_width) {
1812 /* Clear the rest of the area.
1813 * Note that this might still be necessary even in cases where
1814 * num_citizens > NUM_CITIZENS_SHOWN, if the available width cannot be
1815 * divided perfectly. */
1816 cairo_rectangle(cr, total_used_width, 0,
1817 citizen_bar_width - total_used_width,
1818 citizen_bar_height);
1819 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
1820 cairo_fill(cr);
1821 }
1822
1823 cairo_destroy(cr);
1824
1825 gtk_widget_queue_draw(pdialog->citizen_images);
1826}
1827
1828/**********************************************************************/
1831static void city_dialog_update_information(GtkWidget **info_ebox,
1832 GtkWidget **info_label,
1833 struct city_dialog *pdialog)
1834{
1835 int i, illness = 0;
1836 char buf[NUM_INFO_FIELDS][512];
1837 struct city *pcity = pdialog->pcity;
1838 int granaryturns;
1839 int non_workers = city_specialists(pcity);
1840
1841 /* fill the buffers with the necessary info */
1842 if (non_workers) {
1843 fc_snprintf(buf[INFO_SIZE], sizeof(buf[INFO_SIZE]), "%3d (%3d)",
1844 pcity->size, non_workers);
1845 } else {
1846 fc_snprintf(buf[INFO_SIZE], sizeof(buf[INFO_SIZE]), "%3d", pcity->size);
1847 }
1848 fc_snprintf(buf[INFO_FOOD], sizeof(buf[INFO_FOOD]), "%3d (%+4d)",
1849 pcity->prod[O_FOOD], pcity->surplus[O_FOOD]);
1850 fc_snprintf(buf[INFO_SHIELD], sizeof(buf[INFO_SHIELD]), "%3d (%+4d)",
1851 pcity->prod[O_SHIELD] + pcity->waste[O_SHIELD],
1852 pcity->surplus[O_SHIELD]);
1853 fc_snprintf(buf[INFO_TRADE], sizeof(buf[INFO_TRADE]), "%3d (%+4d)",
1854 pcity->surplus[O_TRADE] + pcity->waste[O_TRADE],
1855 pcity->surplus[O_TRADE]);
1856 fc_snprintf(buf[INFO_GOLD], sizeof(buf[INFO_GOLD]), "%3d (%+4d)",
1857 pcity->prod[O_GOLD], pcity->surplus[O_GOLD]);
1858 fc_snprintf(buf[INFO_LUXURY], sizeof(buf[INFO_LUXURY]), "%3d",
1859 pcity->prod[O_LUXURY]);
1860 fc_snprintf(buf[INFO_SCIENCE], sizeof(buf[INFO_SCIENCE]), "%3d",
1861 pcity->prod[O_SCIENCE]);
1862 fc_snprintf(buf[INFO_GRANARY], sizeof(buf[INFO_GRANARY]), "%4d/%-4d",
1864
1865 granaryturns = city_turns_to_grow(pcity);
1866 if (granaryturns == 0) {
1867 /* TRANS: city growth is blocked. Keep short. */
1868 fc_snprintf(buf[INFO_GROWTH], sizeof(buf[INFO_GROWTH]), _("blocked"));
1869 } else if (granaryturns == FC_INFINITY) {
1870 /* TRANS: city is not growing. Keep short. */
1871 fc_snprintf(buf[INFO_GROWTH], sizeof(buf[INFO_GROWTH]), _("never"));
1872 } else {
1873 /* A negative value means we'll have famine in that many turns.
1874 But that's handled down below. */
1875 /* TRANS: city growth turns. Keep short. */
1876 fc_snprintf(buf[INFO_GROWTH], sizeof(buf[INFO_GROWTH]),
1877 PL_("%d turn", "%d turns", abs(granaryturns)),
1878 abs(granaryturns));
1879 }
1880 fc_snprintf(buf[INFO_CORRUPTION], sizeof(buf[INFO_CORRUPTION]), "%4d",
1881 pcity->waste[O_TRADE]);
1882 fc_snprintf(buf[INFO_WASTE], sizeof(buf[INFO_WASTE]), "%4d",
1883 pcity->waste[O_SHIELD]);
1884 fc_snprintf(buf[INFO_CULTURE], sizeof(buf[INFO_CULTURE]), "%4d",
1885 pcity->client.culture);
1886 fc_snprintf(buf[INFO_POLLUTION], sizeof(buf[INFO_POLLUTION]), "%4d",
1887 pcity->pollution);
1888 if (!game.info.illness_on) {
1889 fc_snprintf(buf[INFO_ILLNESS], sizeof(buf[INFO_ILLNESS]), " -.-");
1890 } else {
1891 illness = city_illness_calc(pcity, NULL, NULL, NULL, NULL);
1892 /* illness is in tenth of percent */
1893 fc_snprintf(buf[INFO_ILLNESS], sizeof(buf[INFO_ILLNESS]), "%5.1f%%",
1894 (float)illness / 10.0);
1895 }
1896 if (pcity->steal) {
1897 fc_snprintf(buf[INFO_STEAL], sizeof(buf[INFO_STEAL]), PL_("%d time", "%d times", pcity->steal),
1898 pcity->steal);
1899 } else {
1900 fc_snprintf(buf[INFO_STEAL], sizeof(buf[INFO_STEAL]), _("Not stolen"));
1901 }
1902
1903 get_city_dialog_airlift_value(pcity, buf[INFO_AIRLIFT], sizeof(buf[INFO_AIRLIFT]));
1904
1905 /* stick 'em in the labels */
1906 for (i = 0; i < NUM_INFO_FIELDS; i++) {
1907 gtk_label_set_text(GTK_LABEL(info_label[i]), buf[i]);
1908 }
1909
1910 /*
1911 * Make use of the emergency-indicating styles set up for certain labels
1912 * in create_city_info_table().
1913 */
1914 /* For starvation, the "4" below is arbitrary. 3 turns should be enough
1915 * of a warning. */
1916 if (granaryturns > -4 && granaryturns < 0) {
1917 gtk_style_context_add_class(gtk_widget_get_style_context(info_label[INFO_GRANARY]), "emergency");
1918 } else {
1919 gtk_style_context_remove_class(gtk_widget_get_style_context(info_label[INFO_GRANARY]), "emergency");
1920 }
1921
1922 if (granaryturns == 0 || pcity->surplus[O_FOOD] < 0) {
1923 gtk_style_context_add_class(gtk_widget_get_style_context(info_label[INFO_GROWTH]), "emergency");
1924 } else {
1925 gtk_style_context_remove_class(gtk_widget_get_style_context(info_label[INFO_GROWTH]), "emergency");
1926 }
1927
1928 /* someone could add the color &orange for better granularity here */
1929 if (pcity->pollution >= 10) {
1930 gtk_style_context_add_class(gtk_widget_get_style_context(info_label[INFO_POLLUTION]), "emergency");
1931 } else {
1932 gtk_style_context_remove_class(gtk_widget_get_style_context(info_label[INFO_POLLUTION]), "emergency");
1933 }
1934
1935 /* illness is in tenth of percent, i.e 100 == 10.0% */
1936 if (illness >= 100) {
1937 gtk_style_context_add_class(gtk_widget_get_style_context(info_label[INFO_ILLNESS]), "emergency");
1938 } else {
1939 gtk_style_context_remove_class(gtk_widget_get_style_context(info_label[INFO_ILLNESS]), "emergency");
1940 }
1941}
1942
1943/**********************************************************************/
1946static void city_dialog_update_map(struct city_dialog *pdialog)
1947{
1948 struct canvas store = FC_STATIC_CANVAS_INIT;
1949
1950 store.surface = pdialog->map_canvas_store_unscaled;
1951
1952 /* The drawing is done in three steps.
1953 * 1. First we render to a pixmap with the appropriate canvas size.
1954 * 2. Then the pixmap is rendered into a pixbuf of equal size.
1955 * 3. Finally this pixbuf is composited and scaled onto the GtkImage's
1956 * target pixbuf.
1957 */
1958
1959 city_dialog_redraw_map(pdialog->pcity, &store);
1960
1961 /* draw to real window */
1962 draw_map_canvas(pdialog);
1963}
1964
1965/**********************************************************************/
1968static void city_dialog_update_building(struct city_dialog *pdialog)
1969{
1970 char buf[32], buf2[200];
1971 gdouble pct;
1972
1973 GtkListStore* store;
1974 GtkTreeIter iter;
1975 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
1976 struct item items[MAX_NUM_PRODUCTION_TARGETS];
1977 int targets_used, item;
1978 struct city *pcity = pdialog->pcity;
1979 gboolean sensitive = city_can_buy(pcity);
1980 const char *descr = city_production_name_translation(pcity);
1982
1983 if (pdialog->overview.buy_command != NULL) {
1984 gtk_widget_set_sensitive(GTK_WIDGET(pdialog->overview.buy_command), sensitive);
1985 }
1986 if (pdialog->production.buy_command != NULL) {
1987 gtk_widget_set_sensitive(GTK_WIDGET(pdialog->production.buy_command), sensitive);
1988 }
1989
1990 /* Make sure build slots info is up to date */
1991 if (pdialog->production.production_label != NULL) {
1992 int build_slots = city_build_slots(pcity);
1993
1994 /* Only display extra info if more than one slot is available */
1995 if (build_slots > 1) {
1996 fc_snprintf(buf2, sizeof(buf2),
1997 /* TRANS: never actually used with built_slots <= 1 */
1998 PL_("Production (up to %d unit per turn):",
1999 "Production (up to %d units per turn):", build_slots),
2000 build_slots);
2001 gtk_label_set_text(
2002 GTK_LABEL(pdialog->production.production_label), buf2);
2003 } else {
2004 gtk_label_set_text(
2005 GTK_LABEL(pdialog->production.production_label), _("Production:"));
2006 }
2007 }
2008
2009 /* Update what the city is working on */
2010 get_city_dialog_production(pcity, buf, sizeof(buf));
2011
2012 if (cost > 0) {
2013 pct = (gdouble) pcity->shield_stock / (gdouble) cost;
2014 pct = CLAMP(pct, 0.0, 1.0);
2015 } else {
2016 pct = 1.0;
2017 }
2018
2019 if (pdialog->overview.production_bar != NULL) {
2020 fc_snprintf(buf2, sizeof(buf2), "%s%s\n%s", descr,
2021 worklist_is_empty(&pcity->worklist) ? "" : " (+)", buf);
2022 gtk_progress_bar_set_text(
2023 GTK_PROGRESS_BAR(pdialog->overview.production_bar), buf2);
2024 gtk_progress_bar_set_fraction(
2025 GTK_PROGRESS_BAR(pdialog->overview.production_bar), pct);
2026 }
2027
2028 if (pdialog->production.production_bar != NULL) {
2029 fc_snprintf(buf2, sizeof(buf2), "%s%s: %s", descr,
2030 worklist_is_empty(&pcity->worklist) ? "" : " (+)", buf);
2031 gtk_progress_bar_set_text(
2032 GTK_PROGRESS_BAR(pdialog->production.production_bar), buf2);
2033 gtk_progress_bar_set_fraction(
2034 GTK_PROGRESS_BAR(pdialog->production.production_bar), pct);
2035 }
2036
2037 if (pdialog->overview.production_combo != NULL) {
2038 gtk_combo_box_set_active(GTK_COMBO_BOX(pdialog->overview.production_combo),
2039 -1);
2040 }
2041
2042 store = pdialog->overview.change_production_store;
2043 if (store != NULL) {
2044 gtk_list_store_clear(pdialog->overview.change_production_store);
2045
2046 targets_used
2047 = collect_eventually_buildable_targets(targets, pdialog->pcity, FALSE);
2048 name_and_sort_items(targets, targets_used, items, FALSE, pcity);
2049
2050 for (item = 0; item < targets_used; item++) {
2051 if (can_city_build_now(&(wld.map), pcity, &items[item].item)) {
2052 const char *name;
2053 struct sprite* sprite;
2054 GdkPixbuf *pix;
2055 struct universal target = items[item].item;
2056 bool useless;
2057
2058 if (VUT_UTYPE == target.kind) {
2061 direction8_invalid());
2062 useless = FALSE;
2063 } else {
2066 useless = is_improvement_redundant(pcity, target.value.building);
2067 }
2069 gtk_list_store_append(store, &iter);
2070 gtk_list_store_set(store, &iter, 0, pix,
2071 1, name, 3, useless,
2072 2, (gint)cid_encode(items[item].item), -1);
2073 g_object_unref(G_OBJECT(pix));
2074 }
2075 }
2076 }
2077
2078 /* work around GTK+ refresh bug. */
2079 if (pdialog->overview.production_bar != NULL) {
2080 gtk_widget_queue_resize(pdialog->overview.production_bar);
2081 }
2082 if (pdialog->production.production_bar != NULL) {
2083 gtk_widget_queue_resize(pdialog->production.production_bar);
2084 }
2085}
2086
2087/**********************************************************************/
2091{
2092 int item, targets_used;
2093 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
2094 struct item items[MAX_NUM_PRODUCTION_TARGETS];
2095 GtkTreeModel *model;
2096 GtkListStore *store;
2097
2098 const char *tooltip_sellable = _("Press <b>ENTER</b> or double-click to "
2099 "sell an improvement.");
2100 const char *tooltip_great_wonder = _("Great Wonder - cannot be sold.");
2101 const char *tooltip_small_wonder = _("Small Wonder - cannot be sold.");
2102
2103 model =
2104 gtk_tree_view_get_model(GTK_TREE_VIEW(pdialog->overview.improvement_list));
2105 store = GTK_LIST_STORE(model);
2106
2107 targets_used = collect_already_built_targets(targets, pdialog->pcity);
2108 name_and_sort_items(targets, targets_used, items, FALSE, pdialog->pcity);
2109
2110 gtk_list_store_clear(store);
2111
2112 for (item = 0; item < targets_used; item++) {
2113 GdkPixbuf *pix;
2114 GtkTreeIter it;
2115 int upkeep;
2116 struct sprite *sprite;
2117 struct universal target = items[item].item;
2118
2119 fc_assert_action(VUT_IMPROVEMENT == target.kind, continue);
2120 /* This takes effects (like Adam Smith's) into account. */
2121 upkeep = city_improvement_upkeep(pdialog->pcity, target.value.building);
2123
2125 gtk_list_store_append(store, &it);
2126 gtk_list_store_set(store, &it,
2127 0, target.value.building,
2128 1, pix,
2129 2, items[item].descr,
2130 3, upkeep,
2131 4,
2133 target.value.building),
2134 5,
2136 tooltip_great_wonder :
2137 (is_small_wonder(target.value.building) ?
2138 tooltip_small_wonder : tooltip_sellable),
2139 -1);
2140 g_object_unref(G_OBJECT(pix));
2141 }
2142}
2143
2144/**********************************************************************/
2148{
2149 struct unit_list *units;
2150 struct unit_node_vector *nodes;
2151 int n, m, i;
2152 gchar *buf;
2153 int free_unhappy = get_city_bonus(pdialog->pcity, EFT_MAKE_CONTENT_MIL);
2154 const struct civ_map *nmap = &(wld.map);
2155
2156 if (NULL != client.conn.playing
2157 && city_owner(pdialog->pcity) != client.conn.playing) {
2158 units = pdialog->pcity->client.info_units_supported;
2159 } else {
2160 units = pdialog->pcity->units_supported;
2161 }
2162
2163 nodes = &pdialog->overview.supported_units;
2164
2165 n = unit_list_size(units);
2166 m = unit_node_vector_size(nodes);
2167
2168 if (m > n) {
2169 i = 0;
2170 unit_node_vector_iterate(nodes, elt) {
2171 if (i++ >= n) {
2172 gtk_widget_destroy(elt->cmd);
2173 }
2175
2176 unit_node_vector_reserve(nodes, n);
2177 } else {
2178 for (i = m; i < n; i++) {
2179 GtkWidget *cmd, *pix;
2180 struct unit_node node;
2181
2182 cmd = gtk_button_new();
2183 node.cmd = cmd;
2184
2185 gtk_button_set_relief(GTK_BUTTON(cmd), GTK_RELIEF_NONE);
2186 gtk_widget_add_events(cmd,
2187 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
2188
2189 pix = gtk_image_new();
2190 node.pix = pix;
2192
2193 gtk_container_add(GTK_CONTAINER(cmd), pix);
2194
2195 gtk_grid_attach(GTK_GRID(pdialog->overview.supported_unit_table),
2196 cmd, i, 0, 1, 1);
2197 unit_node_vector_append(nodes, node);
2198 }
2199 }
2200
2201 i = 0;
2202 unit_list_iterate(units, punit) {
2203 struct unit_node *pnode;
2204 int happy_cost = city_unit_unhappiness(nmap, punit, &free_unhappy);
2205
2206 pnode = unit_node_vector_get(nodes, i);
2207 if (pnode) {
2208 GtkWidget *cmd, *pix;
2209
2210 cmd = pnode->cmd;
2211 pix = pnode->pix;
2212
2213 put_unit_image_city_overlays(punit, GTK_IMAGE(pix), pnode->height,
2214 punit->upkeep, happy_cost);
2215
2216 g_signal_handlers_disconnect_matched(cmd,
2217 G_SIGNAL_MATCH_FUNC,
2218 0, 0, NULL, supported_unit_callback, NULL);
2219
2220 g_signal_handlers_disconnect_matched(cmd,
2221 G_SIGNAL_MATCH_FUNC,
2222 0, 0, NULL, supported_unit_middle_callback, NULL);
2223
2224 gtk_widget_set_tooltip_text(cmd, unit_description(punit));
2225
2226 g_signal_connect(cmd, "button_press_event",
2227 G_CALLBACK(supported_unit_callback),
2228 GINT_TO_POINTER(punit->id));
2229
2230 g_signal_connect(cmd, "button_release_event",
2232 GINT_TO_POINTER(punit->id));
2233
2234 if (city_owner(pdialog->pcity) != client.conn.playing) {
2235 gtk_widget_set_sensitive(cmd, FALSE);
2236 } else {
2237 gtk_widget_set_sensitive(cmd, TRUE);
2238 }
2239
2240 gtk_widget_show(pix);
2241 gtk_widget_show(cmd);
2242 }
2243 i++;
2245
2246 buf = g_strdup_printf(_("Supported units %d"), n);
2247 gtk_frame_set_label(GTK_FRAME(pdialog->overview.supported_units_frame), buf);
2248 g_free(buf);
2249}
2250
2251/**********************************************************************/
2255{
2256 struct unit_list *units;
2257 struct unit_node_vector *nodes;
2258 int n, m, i;
2259 gchar *buf;
2260
2261 if (NULL != client.conn.playing
2262 && city_owner(pdialog->pcity) != client.conn.playing) {
2263 units = pdialog->pcity->client.info_units_present;
2264 } else {
2265 units = pdialog->pcity->tile->units;
2266 }
2267
2268 nodes = &pdialog->overview.present_units;
2269
2270 n = unit_list_size(units);
2271 m = unit_node_vector_size(nodes);
2272
2273 if (m > n) {
2274 i = 0;
2275 unit_node_vector_iterate(nodes, elt) {
2276 if (i++ >= n) {
2277 gtk_widget_destroy(elt->cmd);
2278 }
2280
2281 unit_node_vector_reserve(nodes, n);
2282 } else {
2283 for (i = m; i < n; i++) {
2284 GtkWidget *cmd, *pix;
2285 struct unit_node node;
2286
2287 cmd = gtk_button_new();
2288 node.cmd = cmd;
2289
2290 gtk_button_set_relief(GTK_BUTTON(cmd), GTK_RELIEF_NONE);
2291 gtk_widget_add_events(cmd,
2292 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
2293
2294 pix = gtk_image_new();
2295 node.pix = pix;
2297
2298 gtk_container_add(GTK_CONTAINER(cmd), pix);
2299
2300 gtk_grid_attach(GTK_GRID(pdialog->overview.present_unit_table),
2301 cmd, i, 0, 1, 1);
2302 unit_node_vector_append(nodes, node);
2303 }
2304 }
2305
2306 i = 0;
2307 unit_list_iterate(units, punit) {
2308 struct unit_node *pnode;
2309
2310 pnode = unit_node_vector_get(nodes, i);
2311 if (pnode) {
2312 GtkWidget *cmd, *pix;
2313
2314 cmd = pnode->cmd;
2315 pix = pnode->pix;
2316
2317 put_unit_image(punit, GTK_IMAGE(pix), pnode->height);
2318
2319 g_signal_handlers_disconnect_matched(cmd,
2320 G_SIGNAL_MATCH_FUNC,
2321 0, 0, NULL, present_unit_callback, NULL);
2322
2323 g_signal_handlers_disconnect_matched(cmd,
2324 G_SIGNAL_MATCH_FUNC,
2325 0, 0, NULL, present_unit_middle_callback, NULL);
2326
2327 gtk_widget_set_tooltip_text(cmd, unit_description(punit));
2328
2329 g_signal_connect(cmd, "button_press_event",
2330 G_CALLBACK(present_unit_callback),
2331 GINT_TO_POINTER(punit->id));
2332
2333 g_signal_connect(cmd, "button_release_event",
2334 G_CALLBACK(present_unit_middle_callback),
2335 GINT_TO_POINTER(punit->id));
2336
2337 if (city_owner(pdialog->pcity) != client.conn.playing) {
2338 gtk_widget_set_sensitive(cmd, FALSE);
2339 } else {
2340 gtk_widget_set_sensitive(cmd, TRUE);
2341 }
2342
2343 gtk_widget_show(pix);
2344 gtk_widget_show(cmd);
2345 }
2346 i++;
2348
2349 buf = g_strdup_printf(_("Present units %d"), n);
2350 gtk_frame_set_label(GTK_FRAME(pdialog->overview.present_units_frame), buf);
2351 g_free(buf);
2352}
2353
2354/**********************************************************************/
2362{
2363 int count = 0;
2364 int city_number;
2365
2366 if (NULL != client.conn.playing) {
2367 city_number = city_list_size(client.conn.playing->cities);
2368 } else {
2369 city_number = FC_INFINITY; /* ? */
2370 }
2371
2372 /* the first time, we see if all the city dialogs are open */
2373
2375 if (city_owner(pdialog->pcity) == client.conn.playing)
2376 count++;
2377 }
2379
2380 if (count == city_number) { /* all are open, shouldn't prev/next */
2382 gtk_widget_set_sensitive(GTK_WIDGET(pdialog->prev_command), FALSE);
2383 gtk_widget_set_sensitive(GTK_WIDGET(pdialog->next_command), FALSE);
2384 }
2386 } else {
2388 if (city_owner(pdialog->pcity) == client.conn.playing) {
2389 gtk_widget_set_sensitive(GTK_WIDGET(pdialog->prev_command), TRUE);
2390 gtk_widget_set_sensitive(GTK_WIDGET(pdialog->next_command), TRUE);
2391 }
2392 }
2394 }
2395}
2396
2397/**********************************************************************/
2400static void citydlg_response_callback(GtkDialog *dlg, gint response,
2401 void *data)
2402{
2403 switch (response) {
2404 case CDLGR_UNITS:
2405 show_units_response(data);
2406 break;
2407 }
2408}
2409
2410/**********************************************************************/
2413static void show_units_response(void *data)
2414{
2415 struct city_dialog *pdialog = (struct city_dialog *) data;
2416 struct tile *ptile = pdialog->pcity->tile;
2417
2418 if (unit_list_size(ptile->units)) {
2420 }
2421}
2422
2423/**********************************************************************/
2426static void destroy_func(GtkWidget *w, gpointer data)
2427{
2428 gtk_widget_destroy(w);
2429}
2430
2431/**********************************************************************/
2434static gboolean supported_unit_callback(GtkWidget *w, GdkEventButton *ev,
2435 gpointer data)
2436{
2437 GtkWidget *menu, *item;
2438 struct city_dialog *pdialog;
2439 struct city *pcity;
2440 struct unit *punit =
2441 player_unit_by_number(client_player(), (size_t) data);
2442
2443 if (NULL != punit
2444 && NULL != (pcity = game_city_by_number(punit->homecity))
2445 && NULL != (pdialog = get_city_dialog(pcity))) {
2446
2447 if (ev->type != GDK_BUTTON_PRESS || ev->button == 2 || ev->button == 3
2449 return FALSE;
2450 }
2451
2452 menu = pdialog->popup_menu;
2453
2454 gtk_menu_popdown(GTK_MENU(menu));
2455 gtk_container_foreach(GTK_CONTAINER(menu), destroy_func, NULL);
2456
2457 item = gtk_menu_item_new_with_mnemonic(_("Cen_ter"));
2458 g_signal_connect(item, "activate",
2459 G_CALLBACK(unit_center_callback),
2460 GINT_TO_POINTER(punit->id));
2461 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2462
2463 item = gtk_menu_item_new_with_mnemonic(_("_Activate unit"));
2464 g_signal_connect(item, "activate",
2465 G_CALLBACK(unit_activate_callback),
2466 GINT_TO_POINTER(punit->id));
2467 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2468
2469 item = gtk_menu_item_new_with_mnemonic(_("Activate unit, _close dialog"));
2470 g_signal_connect(item, "activate",
2472 GINT_TO_POINTER(punit->id));
2473 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2474
2475 item = gtk_menu_item_new_with_mnemonic(_("_Disband unit"));
2476 g_signal_connect(item, "activate",
2477 G_CALLBACK(unit_disband_callback),
2478 GINT_TO_POINTER(punit->id));
2479 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2480
2481 if (!unit_can_do_action(punit, ACTION_DISBAND_UNIT)) {
2482 gtk_widget_set_sensitive(item, FALSE);
2483 }
2484
2485 gtk_widget_show_all(menu);
2486
2487 gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL);
2488 }
2489
2490 return TRUE;
2491}
2492
2493/**********************************************************************/
2496static gboolean present_unit_callback(GtkWidget *w, GdkEventButton *ev,
2497 gpointer data)
2498{
2499 GtkWidget *menu, *item;
2500 struct city_dialog *pdialog;
2501 struct city *pcity;
2502 struct unit *punit =
2503 player_unit_by_number(client_player(), (size_t) data);
2504
2505 if (NULL != punit
2506 && NULL != (pcity = tile_city(unit_tile(punit)))
2507 && NULL != (pdialog = get_city_dialog(pcity))) {
2508
2509 if (ev->type != GDK_BUTTON_PRESS || ev->button == 2 || ev->button == 3
2511 return FALSE;
2512 }
2513
2514 menu = pdialog->popup_menu;
2515
2516 gtk_menu_popdown(GTK_MENU(menu));
2517 gtk_container_foreach(GTK_CONTAINER(menu), destroy_func, NULL);
2518
2519 item = gtk_menu_item_new_with_mnemonic(_("_Activate unit"));
2520 g_signal_connect(item, "activate",
2521 G_CALLBACK(unit_activate_callback),
2522 GINT_TO_POINTER(punit->id));
2523 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2524
2525 item = gtk_menu_item_new_with_mnemonic(_("Activate unit, _close dialog"));
2526 g_signal_connect(item, "activate",
2528 GINT_TO_POINTER(punit->id));
2529 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2530
2531 item = gtk_menu_item_new_with_mnemonic(_("_Load unit"));
2532 g_signal_connect(item, "activate",
2533 G_CALLBACK(unit_load_callback),
2534 GINT_TO_POINTER(punit->id));
2535 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2536
2537 if (!unit_can_load(punit)) {
2538 gtk_widget_set_sensitive(item, FALSE);
2539 }
2540
2541 item = gtk_menu_item_new_with_mnemonic(_("_Unload unit"));
2542 g_signal_connect(item, "activate",
2543 G_CALLBACK(unit_unload_callback),
2544 GINT_TO_POINTER(punit->id));
2545 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2546
2549 gtk_widget_set_sensitive(item, FALSE);
2550 }
2551
2552 item = gtk_menu_item_new_with_mnemonic(_("_Sentry unit"));
2553 g_signal_connect(item, "activate",
2554 G_CALLBACK(unit_sentry_callback),
2555 GINT_TO_POINTER(punit->id));
2556 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2557
2558 if (punit->activity == ACTIVITY_SENTRY
2559 || !can_unit_do_activity_client(punit, ACTIVITY_SENTRY)) {
2560 gtk_widget_set_sensitive(item, FALSE);
2561 }
2562
2563 item = gtk_menu_item_new_with_mnemonic(_("_Fortify unit"));
2564 g_signal_connect(item, "activate",
2565 G_CALLBACK(unit_fortify_callback),
2566 GINT_TO_POINTER(punit->id));
2567 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2568
2569 if (punit->activity == ACTIVITY_FORTIFYING
2570 || !can_unit_do_activity_client(punit, ACTIVITY_FORTIFYING)) {
2571 gtk_widget_set_sensitive(item, FALSE);
2572 }
2573
2574 item = gtk_menu_item_new_with_mnemonic(_("_Disband unit"));
2575 g_signal_connect(item, "activate",
2576 G_CALLBACK(unit_disband_callback),
2577 GINT_TO_POINTER(punit->id));
2578 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2579
2580 if (!unit_can_do_action(punit, ACTION_DISBAND_UNIT)) {
2581 gtk_widget_set_sensitive(item, FALSE);
2582 }
2583
2584 item = gtk_menu_item_new_with_mnemonic(
2585 action_id_name_translation(ACTION_HOME_CITY));
2586 g_signal_connect(item, "activate",
2587 G_CALLBACK(unit_homecity_callback),
2588 GINT_TO_POINTER(punit->id));
2589 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2590 gtk_widget_set_sensitive(item, can_unit_change_homecity_to(&(wld.map),
2591 punit, pcity));
2592
2593 item = gtk_menu_item_new_with_mnemonic(_("U_pgrade unit"));
2594 gtk_widget_set_sensitive(item, action_ever_possible(ACTION_UPGRADE_UNIT));
2595 g_signal_connect(item, "activate",
2596 G_CALLBACK(unit_upgrade_callback),
2597 GINT_TO_POINTER(punit->id));
2598 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2599
2602 unit_type_get(punit))) {
2603 gtk_widget_set_sensitive(item, FALSE);
2604 }
2605
2606 gtk_widget_show_all(menu);
2607
2608 gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL);
2609 }
2610
2611 return TRUE;
2612}
2613
2614/**********************************************************************/
2617static gboolean present_unit_middle_callback(GtkWidget *w,
2618 GdkEventButton *ev,
2619 gpointer data)
2620{
2621 struct city_dialog *pdialog;
2622 struct city *pcity;
2623 struct unit *punit =
2624 player_unit_by_number(client_player(), (size_t) data);
2625
2626 if (NULL != punit
2627 && NULL != (pcity = tile_city(unit_tile(punit)))
2628 && NULL != (pdialog = get_city_dialog(pcity))
2630
2631 if (ev->button == 3) {
2633 } else if (ev->button == 2) {
2635 close_city_dialog(pdialog);
2636 }
2637 }
2638
2639 return TRUE;
2640}
2641
2642/**********************************************************************/
2645static gboolean supported_unit_middle_callback(GtkWidget *w,
2646 GdkEventButton *ev,
2647 gpointer data)
2648{
2649 struct city_dialog *pdialog;
2650 struct city *pcity;
2651 struct unit *punit =
2652 player_unit_by_number(client_player(), (size_t) data);
2653
2654 if (NULL != punit
2655 && NULL != (pcity = game_city_by_number(punit->homecity))
2656 && NULL != (pdialog = get_city_dialog(pcity))
2658
2659 if (ev->button == 3) {
2661 } else if (ev->button == 2) {
2663 close_city_dialog(pdialog);
2664 }
2665 }
2666
2667 return TRUE;
2668}
2669
2670/**********************************************************************/
2673static void unit_center_callback(GtkWidget *w, gpointer data)
2674{
2675 struct unit *punit =
2676 player_unit_by_number(client_player(), (size_t)data);
2677
2678 if (NULL != punit) {
2680 }
2681}
2682
2683/**********************************************************************/
2686static void unit_activate_callback(GtkWidget *w, gpointer data)
2687{
2688 struct unit *punit =
2689 player_unit_by_number(client_player(), (size_t)data);
2690
2691 if (NULL != punit) {
2693 }
2694}
2695
2696/**********************************************************************/
2701 gpointer data)
2702{
2703 struct unit *punit =
2704 player_unit_by_number(client_player(), (size_t)data);
2705
2706 if (NULL != punit) {
2707 struct city *pcity =
2709
2711 if (NULL != pcity) {
2712 struct city_dialog *pdialog = get_city_dialog(pcity);
2713
2714 if (NULL != pdialog) {
2715 close_city_dialog(pdialog);
2716 }
2717 }
2718 }
2719}
2720
2721/**********************************************************************/
2726 gpointer data)
2727{
2728 struct unit *punit =
2729 player_unit_by_number(client_player(), (size_t)data);
2730
2731 if (NULL != punit) {
2732 struct city *pcity = tile_city(unit_tile(punit));
2733
2735 if (NULL != pcity) {
2736 struct city_dialog *pdialog = get_city_dialog(pcity);
2737
2738 if (NULL != pdialog) {
2739 close_city_dialog(pdialog);
2740 }
2741 }
2742 }
2743}
2744
2745/**********************************************************************/
2748static void unit_load_callback(GtkWidget *w, gpointer data)
2749{
2750 struct unit *punit =
2751 player_unit_by_number(client_player(), (size_t)data);
2752
2753 if (NULL != punit) {
2755 }
2756}
2757
2758/**********************************************************************/
2761static void unit_unload_callback(GtkWidget *w, gpointer data)
2762{
2763 struct unit *punit =
2764 player_unit_by_number(client_player(), (size_t)data);
2765
2766 if (NULL != punit) {
2768 }
2769}
2770
2771/**********************************************************************/
2774static void unit_sentry_callback(GtkWidget *w, gpointer data)
2775{
2776 struct unit *punit =
2777 player_unit_by_number(client_player(), (size_t)data);
2778
2779 if (NULL != punit) {
2781 }
2782}
2783
2784/**********************************************************************/
2787static void unit_fortify_callback(GtkWidget *w, gpointer data)
2788{
2789 struct unit *punit =
2790 player_unit_by_number(client_player(), (size_t)data);
2791
2792 if (NULL != punit) {
2794 }
2795}
2796
2797/**********************************************************************/
2800static void unit_disband_callback(GtkWidget *w, gpointer data)
2801{
2802 struct unit_list *punits;
2803 struct unit *punit =
2804 player_unit_by_number(client_player(), (size_t)data);
2805
2806 if (NULL == punit) {
2807 return;
2808 }
2809
2810 punits = unit_list_new();
2811 unit_list_append(punits, punit);
2812 popup_disband_dialog(punits);
2813 unit_list_destroy(punits);
2814}
2815
2816/**********************************************************************/
2820static void unit_homecity_callback(GtkWidget *w, gpointer data)
2821{
2822 struct unit *punit =
2823 player_unit_by_number(client_player(), (size_t)data);
2824
2825 if (NULL != punit) {
2827 }
2828}
2829
2830/**********************************************************************/
2833static void unit_upgrade_callback(GtkWidget *w, gpointer data)
2834{
2835 struct unit_list *punits;
2836 struct unit *punit =
2837 player_unit_by_number(client_player(), (size_t)data);
2838
2839 if (NULL == punit) {
2840 return;
2841 }
2842
2843 punits = unit_list_new();
2844 unit_list_append(punits, punit);
2845 popup_upgrade_dialog(punits);
2846 unit_list_destroy(punits);
2847}
2848
2849/******** Callbacks for citizen bar, map funcs that are not update *******/
2850/**********************************************************************/
2854static gboolean citizens_callback(GtkWidget *w, GdkEventButton *ev,
2855 gpointer data)
2856{
2857 struct city_dialog *pdialog = data;
2858 struct city *pcity = pdialog->pcity;
2859 int citnum, tlen, len;
2860
2861 if (!can_client_issue_orders()) {
2862 return FALSE;
2863 }
2864
2866 len = (city_size_get(pcity) - 1) * pdialog->cwidth + tlen;
2867 if (ev->x > len) {
2868 /* no citizen that far to the right */
2869 return FALSE;
2870 }
2871 citnum = MIN(city_size_get(pcity) - 1, ev->x / pdialog->cwidth);
2872
2873 city_rotate_specialist(pcity, citnum);
2874
2875 return TRUE;
2876}
2877
2878/**********************************************************************/
2881static void set_city_workertask(GtkWidget *w, gpointer data)
2882{
2883 enum unit_activity act = (enum unit_activity)GPOINTER_TO_INT(data);
2884 struct city *pcity = workertask_req.owner;
2885 struct tile *ptile = workertask_req.loc;
2886 struct packet_worker_task task;
2887
2888 task.city_id32 = pcity->id;
2889 task.city_id16 = task.city_id32;
2890
2891 if (act == ACTIVITY_LAST) {
2892 task.tgt = -1;
2893 task.want = 0;
2894 } else {
2895 enum extra_cause cause = activity_to_extra_cause(act);
2896 enum extra_rmcause rmcause = activity_to_extra_rmcause(act);
2897 struct extra_type *tgt;
2898
2899 if (cause != EC_NONE) {
2900 tgt = next_extra_for_tile(ptile, cause, city_owner(pcity), NULL);
2901 } else if (rmcause != ERM_NONE) {
2902 tgt = prev_extra_in_tile(ptile, rmcause, city_owner(pcity), NULL);
2903 } else {
2904 tgt = NULL;
2905 }
2906
2907 if (tgt == NULL) {
2908 struct terrain *pterr = tile_terrain(ptile);
2909
2910 if ((act != ACTIVITY_TRANSFORM
2911 || pterr->transform_result == NULL || pterr->transform_result == pterr)
2912 && (act != ACTIVITY_CULTIVATE || pterr->cultivate_result == NULL)
2913 && (act != ACTIVITY_PLANT || pterr->plant_result == NULL)) {
2914 /* No extra to order */
2915 output_window_append(ftc_client, _("There's no suitable extra to order."));
2916
2917 return;
2918 }
2919
2920 task.tgt = -1;
2921 } else {
2922 task.tgt = extra_index(tgt);
2923 }
2924
2925 task.want = 100;
2926 }
2927
2928 task.tile_id = ptile->index;
2929 task.activity = act;
2930
2932}
2933
2934/**********************************************************************/
2937static void workertask_dlg_destroy(GtkWidget *w, gpointer data)
2938{
2940}
2941
2942/**********************************************************************/
2945static void popup_workertask_dlg(struct city *pcity, struct tile *ptile)
2946{
2948 GtkWidget *shl;
2949 struct terrain *pterr = tile_terrain(ptile);
2950 struct universal for_terr = { .kind = VUT_TERRAIN,
2951 .value = { .terrain = pterr }};
2952 struct worker_task *ptask;
2953
2955 workertask_req.owner = pcity;
2956 workertask_req.loc = ptile;
2957
2958 shl = choice_dialog_start(GTK_WINDOW(toplevel),
2959 _("What Action to Request"),
2960 _("Select autosettler activity:"));
2961
2962 ptask = worker_task_list_get(pcity->task_reqs, 0);
2963 if (ptask != NULL) {
2964 choice_dialog_add(shl, _("Clear request"),
2965 G_CALLBACK(set_city_workertask),
2966 GINT_TO_POINTER(ACTIVITY_LAST), FALSE, NULL);
2967 }
2968
2969 if (action_id_univs_not_blocking(ACTION_MINE, NULL, &for_terr)) {
2970 choice_dialog_add(shl, Q_("?act:Mine"),
2971 G_CALLBACK(set_city_workertask),
2972 GINT_TO_POINTER(ACTIVITY_MINE), FALSE, NULL);
2973 }
2974 if (pterr->plant_result != NULL
2975 && action_id_univs_not_blocking(ACTION_PLANT,
2976 NULL, &for_terr)) {
2977 choice_dialog_add(shl, _("Plant"),
2978 G_CALLBACK(set_city_workertask),
2979 GINT_TO_POINTER(ACTIVITY_PLANT), FALSE, NULL);
2980 }
2981 if (action_id_univs_not_blocking(ACTION_IRRIGATE, NULL, &for_terr)) {
2982 choice_dialog_add(shl, _("Irrigate"),
2983 G_CALLBACK(set_city_workertask),
2984 GINT_TO_POINTER(ACTIVITY_IRRIGATE), FALSE, NULL);
2985 }
2986 if (pterr->cultivate_result != NULL
2987 && action_id_univs_not_blocking(ACTION_CULTIVATE,
2988 NULL, &for_terr)) {
2989 choice_dialog_add(shl, _("Cultivate"),
2990 G_CALLBACK(set_city_workertask),
2991 GINT_TO_POINTER(ACTIVITY_CULTIVATE), FALSE, NULL);
2992 }
2993 if (next_extra_for_tile(ptile, EC_ROAD, city_owner(pcity), NULL) != NULL) {
2994 choice_dialog_add(shl, _("Road"),
2995 G_CALLBACK(set_city_workertask),
2996 GINT_TO_POINTER(ACTIVITY_GEN_ROAD), FALSE, NULL);
2997 }
2998 if (pterr->transform_result != pterr && pterr->transform_result != NULL
2999 && action_id_univs_not_blocking(ACTION_TRANSFORM_TERRAIN,
3000 NULL, &for_terr)) {
3001 choice_dialog_add(shl, _("Transform"),
3002 G_CALLBACK(set_city_workertask),
3003 GINT_TO_POINTER(ACTIVITY_TRANSFORM), FALSE, NULL);
3004 }
3005 if (prev_extra_in_tile(ptile, ERM_CLEANPOLLUTION,
3006 city_owner(pcity), NULL) != NULL) {
3007 choice_dialog_add(shl, _("Clean Pollution"),
3008 G_CALLBACK(set_city_workertask),
3009 GINT_TO_POINTER(ACTIVITY_POLLUTION), FALSE, NULL);
3010 }
3011 if (prev_extra_in_tile(ptile, ERM_CLEANFALLOUT,
3012 city_owner(pcity), NULL) != NULL) {
3013 choice_dialog_add(shl, _("Clean Fallout"),
3014 G_CALLBACK(set_city_workertask),
3015 GINT_TO_POINTER(ACTIVITY_FALLOUT), FALSE, NULL);
3016 }
3017
3018 choice_dialog_add(shl, _("_Cancel"), 0, 0, FALSE, NULL);
3019 choice_dialog_end(shl);
3020
3021 g_signal_connect(shl, "destroy", G_CALLBACK(workertask_dlg_destroy),
3022 NULL);
3023 }
3024}
3025
3026/**********************************************************************/
3029static gboolean button_down_citymap(GtkWidget *w, GdkEventButton *ev,
3030 gpointer data)
3031{
3032 struct city_dialog *pdialog = data;
3033 int canvas_x, canvas_y, city_x, city_y;
3034
3035 if (!can_client_issue_orders()) {
3036 return FALSE;
3037 }
3038
3039 if (ev->button == 1 && cma_is_city_under_agent(pdialog->pcity, NULL)) {
3040 return FALSE;
3041 }
3042
3043 canvas_x = ev->x * (double)canvas_width / (double)CITYMAP_WIDTH;
3044 canvas_y = ev->y * (double)canvas_height / (double)CITYMAP_HEIGHT;
3045
3046 if (canvas_to_city_pos(&city_x, &city_y,
3047 city_map_radius_sq_get(pdialog->pcity),
3048 canvas_x, canvas_y)) {
3049 if (ev->button == 1) {
3050 city_toggle_worker(pdialog->pcity, city_x, city_y);
3051 } else if (ev->button == 3) {
3052 struct city *pcity = pdialog->pcity;
3053
3054 popup_workertask_dlg(pdialog->pcity,
3055 city_map_to_tile(&(wld.map), pcity->tile,
3057 city_x, city_y));
3058 }
3059 }
3060
3061 return TRUE;
3062}
3063
3064/**********************************************************************/
3067static void draw_map_canvas(struct city_dialog *pdialog)
3068{
3069 gtk_widget_queue_draw(pdialog->overview.map_canvas.darea);
3070 if (pdialog->happiness.map_canvas.darea) { /* in case of spy */
3071 gtk_widget_queue_draw(pdialog->happiness.map_canvas.darea);
3072 }
3073}
3074
3075/************** Callbacks for Buy, Change, Sell, Worklist ****************/
3076/**********************************************************************/
3079static void buy_callback_response(GtkWidget *w, gint response, gpointer data)
3080{
3081 struct city_dialog *pdialog = data;
3082
3083 if (response == GTK_RESPONSE_YES) {
3084 city_buy_production(pdialog->pcity);
3085 }
3086 gtk_widget_destroy(w);
3087}
3088
3089/**********************************************************************/
3092static void buy_callback(GtkWidget *w, gpointer data)
3093{
3094 GtkWidget *shell;
3095 struct city_dialog *pdialog = data;
3096 const char *name = city_production_name_translation(pdialog->pcity);
3097 int value = pdialog->pcity->client.buy_cost;
3098 char buf[1024];
3099
3100 if (!can_client_issue_orders()) {
3101 return;
3102 }
3103
3104 fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Treasury contains %d gold.",
3105 "Treasury contains %d gold.",
3106 client_player()->economic.gold),
3107 client_player()->economic.gold);
3108
3109 if (value <= client_player()->economic.gold) {
3110 shell = gtk_message_dialog_new(NULL,
3111 GTK_DIALOG_DESTROY_WITH_PARENT,
3112 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
3113 /* TRANS: Last %s is pre-pluralised "Treasury contains %d gold." */
3114 PL_("Buy %s for %d gold?\n%s",
3115 "Buy %s for %d gold?\n%s", value),
3116 name, value, buf);
3117 setup_dialog(shell, pdialog->shell);
3118 gtk_window_set_title(GTK_WINDOW(shell), _("Buy It!"));
3119 gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_NO);
3120 g_signal_connect(shell, "response", G_CALLBACK(buy_callback_response),
3121 pdialog);
3122 gtk_window_present(GTK_WINDOW(shell));
3123 } else {
3124 shell = gtk_message_dialog_new(NULL,
3125 GTK_DIALOG_DESTROY_WITH_PARENT,
3126 GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
3127 /* TRANS: Last %s is pre-pluralised "Treasury contains %d gold." */
3128 PL_("%s costs %d gold.\n%s",
3129 "%s costs %d gold.\n%s", value),
3130 name, value, buf);
3131 setup_dialog(shell, pdialog->shell);
3132 gtk_window_set_title(GTK_WINDOW(shell), _("Buy It!"));
3133 g_signal_connect(shell, "response", G_CALLBACK(gtk_widget_destroy),
3134 NULL);
3135 gtk_window_present(GTK_WINDOW(shell));
3136 }
3137}
3138
3139/**********************************************************************/
3142static void change_production_callback(GtkComboBox *combo,
3143 struct city_dialog *pdialog)
3144{
3145 GtkTreeIter iter;
3146
3148 && gtk_combo_box_get_active_iter(combo, &iter)) {
3149 cid id;
3150 struct universal univ;
3151
3152 gtk_tree_model_get(gtk_combo_box_get_model(combo), &iter, 2, &id, -1);
3153 univ = cid_production(id);
3154 city_change_production(pdialog->pcity, &univ);
3155 }
3156}
3157
3158/**********************************************************************/
3161static void sell_callback(struct impr_type *pimprove, gpointer data)
3162{
3163 GtkWidget *shl;
3164 struct city_dialog *pdialog = (struct city_dialog *) data;
3165 pdialog->sell_id = improvement_number(pimprove);
3166 int price;
3167
3168 if (!can_client_issue_orders()) {
3169 return;
3170 }
3171
3173 pimprove) != TR_SUCCESS) {
3174 return;
3175 }
3176
3177 price = impr_sell_gold(pimprove);
3178 shl = gtk_message_dialog_new(NULL,
3179 GTK_DIALOG_DESTROY_WITH_PARENT,
3180 GTK_MESSAGE_QUESTION,
3181 GTK_BUTTONS_YES_NO,
3182 PL_("Sell %s for %d gold?",
3183 "Sell %s for %d gold?", price),
3184 city_improvement_name_translation(pdialog->pcity, pimprove), price);
3185 setup_dialog(shl, pdialog->shell);
3186 pdialog->sell_shell = shl;
3187
3188 gtk_window_set_title(GTK_WINDOW(shl), _("Sell It!"));
3189 gtk_window_set_position(GTK_WINDOW(shl), GTK_WIN_POS_CENTER_ON_PARENT);
3190
3191 g_signal_connect(shl, "response",
3192 G_CALLBACK(sell_callback_response), pdialog);
3193
3194 gtk_window_present(GTK_WINDOW(shl));
3195}
3196
3197/**********************************************************************/
3200static void sell_callback_response(GtkWidget *w, gint response, gpointer data)
3201{
3202 struct city_dialog *pdialog = data;
3203
3204 if (response == GTK_RESPONSE_YES) {
3205 city_sell_improvement(pdialog->pcity, pdialog->sell_id);
3206 }
3207 gtk_widget_destroy(w);
3208
3209 pdialog->sell_shell = NULL;
3210}
3211
3212/**********************************************************************/
3215static void impr_callback(GtkTreeView *view, GtkTreePath *path,
3216 GtkTreeViewColumn *col, gpointer data)
3217{
3218 GtkTreeModel *model;
3219 GtkTreeIter it;
3220 GdkWindow *win;
3221 GdkSeat *seat;
3222 GdkModifierType mask;
3223 struct impr_type *pimprove;
3224
3225 model = gtk_tree_view_get_model(view);
3226
3227 if (!gtk_tree_model_get_iter(model, &it, path)) {
3228 return;
3229 }
3230
3231 gtk_tree_model_get(model, &it, 0, &pimprove, -1);
3232
3233 win = gtk_widget_get_parent_window(GTK_WIDGET(view));
3234 seat = gdk_display_get_default_seat(gdk_window_get_display(win));
3235
3236 gdk_window_get_device_position(win, gdk_seat_get_pointer(seat),
3237 NULL, NULL, &mask);
3238
3239 if (!(mask & GDK_CONTROL_MASK)) {
3240 sell_callback(pimprove, data);
3241 } else {
3242 if (is_great_wonder(pimprove)) {
3244 } else {
3246 }
3247 }
3248}
3249
3250/************ Callbacks for stuff on the Misc. Settings page *************/
3251/**********************************************************************/
3254static void rename_callback(GtkWidget *w, gpointer data)
3255{
3256 struct city_dialog *pdialog;
3257
3258 pdialog = (struct city_dialog *) data;
3259
3260 pdialog->rename_shell = input_dialog_create(GTK_WINDOW(pdialog->shell),
3261 /* "shellrenamecity" */
3262 _("Rename City"),
3263 _("What should we rename the city to?"),
3264 city_name_get(pdialog->pcity),
3265 rename_popup_callback, pdialog);
3266}
3267
3268/**********************************************************************/
3271static void rename_popup_callback(gpointer data, gint response,
3272 const char *input)
3273{
3274 struct city_dialog *pdialog = data;
3275
3276 if (pdialog) {
3277 if (response == GTK_RESPONSE_OK) {
3278 city_rename(pdialog->pcity, input);
3279 } /* else CANCEL or DELETE_EVENT */
3280
3281 pdialog->rename_shell = NULL;
3282 }
3283}
3284
3285/**********************************************************************/
3288static void misc_whichtab_callback(GtkWidget * w, gpointer data)
3289{
3290 new_dialog_def_page = GPOINTER_TO_INT(data);
3291}
3292
3293/**********************************************************************/
3296static void cityopt_callback(GtkWidget * w, gpointer data)
3297{
3298 struct city_dialog *pdialog = (struct city_dialog *) data;
3299
3300 if (!can_client_issue_orders()) {
3301 return;
3302 }
3303
3304 if (!pdialog->misc.block_signal) {
3305 struct city *pcity = pdialog->pcity;
3306 bv_city_options new_options;
3307
3308 fc_assert(CITYO_LAST == 3);
3309
3310 BV_CLR_ALL(new_options);
3311 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pdialog->misc.disband_on_settler))) {
3312 BV_SET(new_options, CITYO_DISBAND);
3313 }
3314 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pdialog->misc.new_citizens_radio[1]))) {
3315 BV_SET(new_options, CITYO_SCIENCE_SPECIALISTS);
3316 }
3317 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pdialog->misc.new_citizens_radio[2]))) {
3318 BV_SET(new_options, CITYO_GOLD_SPECIALISTS);
3319 }
3320
3321 dsend_packet_city_options_req(&client.conn, pcity->id, pcity->id, new_options);
3322 }
3323}
3324
3325/**********************************************************************/
3329static void set_cityopt_values(struct city_dialog *pdialog)
3330{
3331 struct city *pcity = pdialog->pcity;
3332
3333 pdialog->misc.block_signal = 1;
3334
3335 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pdialog->misc.disband_on_settler),
3336 is_city_option_set(pcity, CITYO_DISBAND));
3337
3338 if (is_city_option_set(pcity, CITYO_SCIENCE_SPECIALISTS)) {
3339 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
3340 (pdialog->misc.new_citizens_radio[1]), TRUE);
3341 } else if (is_city_option_set(pcity, CITYO_GOLD_SPECIALISTS)) {
3342 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
3343 (pdialog->misc.new_citizens_radio[2]), TRUE);
3344 } else {
3345 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
3346 (pdialog->misc.new_citizens_radio[0]), TRUE);
3347 }
3348 pdialog->misc.block_signal = 0;
3349}
3350
3351/******************** Callbacks for: Close, Prev, Next. ******************/
3352/**********************************************************************/
3355static void close_callback(GtkWidget *w, gpointer data)
3356{
3357 close_city_dialog((struct city_dialog *) data);
3358}
3359
3360/**********************************************************************/
3363static void city_destroy_callback(GtkWidget *w, gpointer data)
3364{
3365 struct city_dialog *pdialog;
3366
3367 pdialog = (struct city_dialog *) data;
3368
3369 gtk_widget_hide(pdialog->shell);
3370
3372 citizens_dialog_close(pdialog->pcity);
3373 }
3374 close_happiness_dialog(pdialog->pcity);
3375 close_cma_dialog(pdialog->pcity);
3376
3377 /* Save size of the city dialog. */
3378 GUI_GTK_OPTION(citydlg_xsize)
3380 gtk_widget_get_allocated_width(pdialog->shell),
3382 GUI_GTK_OPTION(citydlg_ysize)
3384 gtk_widget_get_allocated_height(pdialog->shell),
3386
3387 last_page
3388 = gtk_notebook_get_current_page(GTK_NOTEBOOK(pdialog->notebook));
3389
3390 if (pdialog->popup_menu) {
3391 gtk_widget_destroy(pdialog->popup_menu);
3392 }
3393
3394 dialog_list_remove(dialog_list, pdialog);
3395
3396 unit_node_vector_free(&pdialog->overview.supported_units);
3397 unit_node_vector_free(&pdialog->overview.present_units);
3398
3399 if (pdialog->sell_shell) {
3400 gtk_widget_destroy(pdialog->sell_shell);
3401 }
3402 if (pdialog->rename_shell) {
3403 gtk_widget_destroy(pdialog->rename_shell);
3404 }
3405
3406 cairo_surface_destroy(pdialog->map_canvas_store_unscaled);
3407 cairo_surface_destroy(pdialog->citizen_surface);
3408
3409 free(pdialog);
3410
3411 /* need to do this every time a new dialog is closed. */
3413}
3414
3415/**********************************************************************/
3418static void close_city_dialog(struct city_dialog *pdialog)
3419{
3420 gtk_widget_destroy(pdialog->shell);
3421}
3422
3423/**********************************************************************/
3427static void switch_city_callback(GtkWidget *w, gpointer data)
3428{
3429 struct city_dialog *pdialog = (struct city_dialog *) data;
3430 int i, j, dir, size;
3431 struct city *new_pcity = NULL;
3432
3434 return;
3435 }
3436
3437 size = city_list_size(client.conn.playing->cities);
3438
3440 fc_assert_ret(size >= 1);
3442
3443 if (size == 1) {
3444 return;
3445 }
3446
3447 /* dir = 1 will advance to the city, dir = -1 will get previous */
3448 if (w == GTK_WIDGET(pdialog->next_command)) {
3449 dir = 1;
3450 } else if (w == GTK_WIDGET(pdialog->prev_command)) {
3451 dir = -1;
3452 } else {
3453 /* Always fails. */
3454 fc_assert_ret(w == GTK_WIDGET(pdialog->next_command)
3455 || w == GTK_WIDGET(pdialog->prev_command));
3456 dir = 1;
3457 }
3458
3459 for (i = 0; i < size; i++) {
3460 if (pdialog->pcity == city_list_get(client.conn.playing->cities, i)) {
3461 break;
3462 }
3463 }
3464
3465 fc_assert_ret(i < size);
3466
3467 for (j = 1; j < size; j++) {
3468 struct city *other_pcity = city_list_get(client.conn.playing->cities,
3469 (i + dir * j + size) % size);
3470 struct city_dialog *other_pdialog = get_city_dialog(other_pcity);
3471
3472 fc_assert_ret(other_pdialog != pdialog);
3473 if (!other_pdialog) {
3474 new_pcity = other_pcity;
3475 break;
3476 }
3477 }
3478
3479 if (!new_pcity) {
3480 /* Every other city has an open city dialog. */
3481 return;
3482 }
3483
3484 /* cleanup happiness dialog */
3486 citizens_dialog_close(pdialog->pcity);
3487 }
3488 close_happiness_dialog(pdialog->pcity);
3489
3490 pdialog->pcity = new_pcity;
3491
3492 /* reinitialize happiness, and cma dialogs */
3494 gtk_container_add(GTK_CONTAINER(pdialog->happiness.citizens),
3495 citizens_dialog_display(pdialog->pcity));
3496 }
3497 gtk_container_add(GTK_CONTAINER(pdialog->happiness.widget),
3498 get_top_happiness_display(pdialog->pcity, low_citydlg, pdialog->shell));
3499 if (!client_is_observer()) {
3500 fc_assert(pdialog->cma_editor != NULL);
3501 pdialog->cma_editor->pcity = new_pcity;
3502 }
3503
3504 reset_city_worklist(pdialog->production.worklist, pdialog->pcity);
3505
3506 can_slide = FALSE;
3507 center_tile_mapcanvas(pdialog->pcity->tile);
3508 can_slide = TRUE;
3509 if (!client_is_observer()) {
3510 set_cityopt_values(pdialog); /* need not be in real_city_dialog_refresh */
3511 }
3512
3514
3515 /* recenter the city map(s) */
3517 if (pdialog->happiness.map_canvas.sw) {
3519 }
3520}
const char * action_id_name_translation(action_id act_id)
Definition actions.c:1910
bool action_ever_possible(action_id action)
Definition actions.c:9305
#define action_id_univs_not_blocking(act_id, act_uni, tgt_uni)
Definition actions.h:962
#define n
Definition astring.c:77
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int canvas_y
Definition canvas_g.h:43
struct canvas int canvas_x
Definition canvas_g.h:43
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
void output_window_append(const struct ft_color color, const char *featured_text)
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:658
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:722
int city_granary_size(int city_size)
Definition city.c:2104
int city_build_slots(const struct city *pcity)
Definition city.c:2834
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:300
const char * city_name_get(const struct city *pcity)
Definition city.c:1115
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1231
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3301
int city_population(const struct city *pcity)
Definition city.c:1169
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:2943
bool city_unhappy(const struct city *pcity)
Definition city.c:1599
bool city_celebrating(const struct city *pcity)
Definition city.c:1618
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2772
bool city_happy(const struct city *pcity)
Definition city.c:1587
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:132
citizens city_specialists(const struct city *pcity)
Definition city.c:3230
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:991
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1969
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:695
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
citizen_category
Definition city.h:259
#define city_owner(_pcity_)
Definition city.h:543
#define MAX_CITY_SIZE
Definition city.h:98
@ FEELING_FINAL
Definition city.h:276
void get_city_dialog_output_text(const struct city *pcity, Output_type_id otype, char *buf, size_t bufsz)
void get_city_dialog_production(struct city *pcity, char *buffer, size_t buffer_len)
int city_rename(struct city *pcity, const char *name)
int get_city_citizen_types(struct city *pcity, enum citizen_feeling idx, enum citizen_category *categories)
int city_buy_production(struct city *pcity)
int city_toggle_worker(struct city *pcity, int city_x, int city_y)
void get_city_dialog_airlift_text(const struct city *pcity, char *buf, size_t bufsz)
int city_change_production(struct city *pcity, struct universal *target)
void city_rotate_specialist(struct city *pcity, int citizen_index)
int get_citydlg_canvas_width(void)
bool canvas_to_city_pos(int *city_x, int *city_y, int city_radius_sq, int canvas_x, int canvas_y)
void get_city_dialog_airlift_value(const struct city *pcity, char *buf, size_t bufsz)
void city_dialog_redraw_map(struct city *pcity, struct canvas *pcanvas)
int city_sell_improvement(struct city *pcity, Impr_type_id sell_id)
void get_city_dialog_pollution_text(const struct city *pcity, char *buf, size_t bufsz)
void get_city_dialog_culture_text(const struct city *pcity, char *buf, size_t bufsz)
bool city_can_buy(const struct city *pcity)
int get_citydlg_canvas_height(void)
void get_city_dialog_illness_text(const struct city *pcity, char *buf, size_t bufsz)
void city_report_dialog_update_city(struct city *pcity)
bool client_is_global_observer(void)
bool client_is_observer(void)
struct civclient client
bool can_client_issue_orders(void)
bool client_has_player(void)
#define client_player()
int collect_eventually_buildable_targets(struct universal *targets, struct city *pcity, bool advanced_tech)
Definition climisc.c:812
void name_and_sort_items(struct universal *targets, int num_targets, struct item *items, bool show_cost, struct city *pcity)
Definition climisc.c:643
cid cid_encode(struct universal target)
Definition climisc.c:476
int collect_already_built_targets(struct universal *targets, struct city *pcity)
Definition climisc.c:906
#define MAX_NUM_PRODUCTION_TARGETS
Definition climisc.h:89
#define cid_production
Definition climisc.h:71
int cid
Definition climisc.h:31
bool cma_is_city_under_agent(const struct city *pcity, struct cm_parameter *parameter)
Definition cma_core.c:551
void request_unit_fortify(struct unit *punit)
Definition control.c:2240
void unit_focus_set(struct unit *punit)
Definition control.c:507
void request_unit_change_homecity(struct unit *punit)
Definition control.c:2021
void request_unit_unload(struct unit *pcargo)
Definition control.c:2119
void request_unit_sentry(struct unit *punit)
Definition control.c:2229
#define can_unit_do_activity_client(_punit_, _act_)
Definition control.h:40
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:73
int int id
Definition editgui_g.h:28
static struct editor_state * editor
Definition editor.c:100
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:789
enum event_type event
Definition events.c:81
struct extra_type * next_extra_for_tile(const struct tile *ptile, enum extra_cause cause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:740
struct extra_type * prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:765
enum extra_cause activity_to_extra_cause(enum unit_activity act)
Definition extras.c:1028
enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act)
Definition extras.c:1049
#define extra_index(_e_)
Definition extras.h:177
int Impr_type_id
Definition fc_types.h:346
#define EC_NONE
Definition fc_types.h:967
@ TR_SUCCESS
Definition fc_types.h:1098
#define ERM_NONE
Definition fc_types.h:992
@ O_SHIELD
Definition fc_types.h:91
@ O_FOOD
Definition fc_types.h:91
@ O_TRADE
Definition fc_types.h:91
@ O_SCIENCE
Definition fc_types.h:91
@ O_LUXURY
Definition fc_types.h:91
@ O_GOLD
Definition fc_types.h:91
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
#define N_(String)
Definition fcintl.h:69
const struct ft_color ftc_client
const char * population_to_text(int thousand_citizen)
Definition game.c:714
struct civ_game game
Definition game.c:57
struct world wld
Definition game.c:58
struct city * game_city_by_number(int id)
Definition game.c:102
#define FC_STATIC_CANVAS_INIT
Definition canvas.h:27
GtkWidget * choice_dialog_start(GtkWindow *parent, const gchar *name, const gchar *text)
void choice_dialog_end(GtkWidget *dshell)
void choice_dialog_add(GtkWidget *dshell, const gchar *label, GCallback handler, gpointer data, bool meta, const gchar *tool_tip)
GtkWidget * citizens_dialog_display(const struct city *pcity)
void citizens_dialog_refresh(const struct city *pcity)
void citizens_dialog_close(const struct city *pcity)
static void unit_sentry_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:2758
citydlg_response
Definition citydlg.c:81
@ CDLGR_UNITS
Definition citydlg.c:81
@ CDLGR_PREV
Definition citydlg.c:81
@ CDLGR_NEXT
Definition citydlg.c:81
static int new_dialog_def_page
Definition citydlg.c:212
static void create_and_append_buildings_page(struct city_dialog *pdialog)
Definition citydlg.c:1193
static void unit_upgrade_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:2817
static void popup_workertask_dlg(struct city *pcity, struct tile *ptile)
Definition citydlg.c:2929
static void city_dialog_update_citizens(struct city_dialog *pdialog)
Definition citydlg.c:1735
static void city_destroy_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:3348
static void city_dialog_update_title(struct city_dialog *pdialog)
Definition citydlg.c:1696
static int last_page
Definition citydlg.c:213
static void init_citydlg_dimensions(void)
Definition citydlg.c:324
static void create_and_append_worklist_page(struct city_dialog *pdialog)
Definition citydlg.c:1227
struct tile * loc
Definition citydlg.c:220
static gboolean canvas_exposed_cb(GtkWidget *w, cairo_t *cr, gpointer data)
Definition citydlg.c:396
#define CITY_MAP_MIN_SIZE_X
Definition citydlg.c:127
void real_city_dialog_popup(struct city *pcity)
Definition citydlg.c:558
static void misc_whichtab_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:3273
static bool low_citydlg
Definition citydlg.c:223
bool city_dialog_is_open(struct city *pcity)
Definition citydlg.c:579
static void city_dialog_update_building(struct city_dialog *pdialog)
Definition citydlg.c:1926
static void citydlg_response_callback(GtkDialog *dlg, gint response, void *data)
Definition citydlg.c:2355
static void buy_callback_response(GtkWidget *w, gint response, gpointer data)
Definition citydlg.c:3063
static gboolean present_unit_middle_callback(GtkWidget *w, GdkEventButton *ev, gpointer data)
Definition citydlg.c:2601
void real_city_dialog_refresh(struct city *pcity)
Definition citydlg.c:481
static void unit_center_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:2657
static struct city_dialog * get_city_dialog(struct city *pcity)
Definition citydlg.c:379
#define CITY_MAP_MIN_SIZE_Y
Definition citydlg.c:128
static void city_dialog_update_information(GtkWidget **info_ebox, GtkWidget **info_label, struct city_dialog *pdialog)
Definition citydlg.c:1798
static GtkWidget * create_citydlg_improvement_list(struct city_dialog *pdialog, GtkWidget *vbox)
Definition citydlg.c:852
static void create_production_header(struct city_dialog *pdialog, GtkContainer *contain)
Definition citydlg.c:1160
static void workertask_dlg_destroy(GtkWidget *w, gpointer data)
Definition citydlg.c:2921
static void city_dialog_update_present_units(struct city_dialog *pdialog)
Definition citydlg.c:2212
#define CITYMAP_SCALE
Definition citydlg.c:75
static gboolean keyboard_handler(GtkWidget *widget, GdkEventKey *event, struct city_dialog *pdialog)
Definition citydlg.c:616
static gboolean citizens_callback(GtkWidget *w, GdkEventButton *ev, gpointer data)
Definition citydlg.c:2838
static void change_production_callback(GtkComboBox *combo, struct city_dialog *pdialog)
Definition citydlg.c:3126
static void unit_load_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:2732
static void set_cityopt_values(struct city_dialog *pdialog)
Definition citydlg.c:3314
static void close_city_dialog(struct city_dialog *pdialog)
Definition citydlg.c:3403
static gboolean show_info_popup(GtkWidget *w, GdkEventButton *ev, gpointer data)
Definition citydlg.c:653
static void create_and_append_overview_page(struct city_dialog *pdialog)
Definition citydlg.c:911
static void create_and_append_happiness_page(struct city_dialog *pdialog)
Definition citydlg.c:1271
void popdown_all_city_dialogs(void)
Definition citydlg.c:599
static void buy_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:3076
#define dialog_list_iterate_end
Definition citydlg.c:92
static void impr_callback(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
Definition citydlg.c:3199
static void create_and_append_map_page(struct city_dialog *pdialog)
Definition citydlg.c:1099
static void city_dialog_map_create(struct city_dialog *pdialog, struct city_map_canvas *cmap_canvas)
Definition citydlg.c:415
void refresh_unit_city_dialogs(struct unit *punit)
Definition citydlg.c:538
void reset_city_dialogs(void)
Definition citydlg.c:357
static gboolean show_info_button_release(GtkWidget *w, GdkEventButton *ev, gpointer data)
Definition citydlg.c:640
static void cityopt_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:3281
static void city_dialog_map_recenter(GtkWidget *map_canvas_sw)
Definition citydlg.c:454
static void draw_map_canvas(struct city_dialog *pdialog)
Definition citydlg.c:3051
static bool is_showing_workertask_dialog
Definition citydlg.c:215
#define unit_node_vector_iterate_end
Definition citydlg.c:107
static void sell_callback(struct impr_type *pimprove, gpointer data)
Definition citydlg.c:3145
#define dialog_list_iterate(dialoglist, pdialog)
Definition citydlg.c:90
static void supported_unit_activate_close_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:2684
static void city_dialog_update_prev_next(void)
Definition citydlg.c:2319
static void create_and_append_settings_page(struct city_dialog *pdialog)
Definition citydlg.c:1364
static bool city_dialogs_have_been_initialised
Definition citydlg.c:210
static void close_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:3340
static struct dialog_list * dialog_list
Definition citydlg.c:209
static void sell_callback_response(GtkWidget *w, gint response, gpointer data)
Definition citydlg.c:3184
static void create_citydlg_main_map(struct city_dialog *pdialog, GtkWidget *container)
Definition citydlg.c:835
#define NUM_CITIZENS_SHOWN
Definition citydlg.c:109
#define CITYMAP_HEIGHT
Definition citydlg.c:74
static void destroy_func(GtkWidget *w, gpointer data)
Definition citydlg.c:2408
static void unit_homecity_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:2804
static void unit_fortify_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:2771
static gboolean supported_unit_middle_callback(GtkWidget *w, GdkEventButton *ev, gpointer data)
Definition citydlg.c:2629
static gboolean present_unit_callback(GtkWidget *w, GdkEventButton *ev, gpointer data)
Definition citydlg.c:2480
struct city * owner
Definition citydlg.c:219
static GtkWidget * create_city_info_table(struct city_dialog *pdialog, GtkWidget **info_ebox, GtkWidget **info_label)
Definition citydlg.c:737
static struct city_dialog * create_city_dialog(struct city *pcity)
Definition citydlg.c:1508
static void target_drag_data_received(GtkWidget *w, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data)
Definition citydlg.c:1122
static void unit_disband_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:2784
#define unit_node_vector_iterate(list, elt)
Definition citydlg.c:105
@ INFO_LUXURY
Definition citydlg.c:119
@ INFO_STEAL
Definition citydlg.c:121
@ INFO_CORRUPTION
Definition citydlg.c:120
@ NUM_INFO_FIELDS
Definition citydlg.c:122
@ INFO_ILLNESS
Definition citydlg.c:121
@ INFO_WASTE
Definition citydlg.c:120
@ INFO_SIZE
Definition citydlg.c:118
@ INFO_GROWTH
Definition citydlg.c:119
@ INFO_SHIELD
Definition citydlg.c:118
@ INFO_CULTURE
Definition citydlg.c:120
@ INFO_GOLD
Definition citydlg.c:118
@ INFO_SCIENCE
Definition citydlg.c:119
@ INFO_POLLUTION
Definition citydlg.c:120
@ INFO_TRADE
Definition citydlg.c:118
@ INFO_AIRLIFT
Definition citydlg.c:121
@ INFO_GRANARY
Definition citydlg.c:119
@ INFO_FOOD
Definition citydlg.c:118
static void rename_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:3239
static void switch_city_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:3412
static gboolean button_down_citymap(GtkWidget *w, GdkEventButton *ev, gpointer data)
Definition citydlg.c:3013
#define CITYMAP_WIDTH
Definition citydlg.c:73
static void city_dialog_update_map(struct city_dialog *pdialog)
Definition citydlg.c:1904
static void unit_unload_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:2745
static void show_units_response(void *data)
Definition citydlg.c:2368
static void initialize_city_dialogs(void)
Definition citydlg.c:333
static int canvas_height
Definition citydlg.c:211
static int canvas_width
Definition citydlg.c:211
#define TINYSCREEN_MAX_HEIGHT
Definition citydlg.c:77
static void city_dialog_update_supported_units(struct city_dialog *pdialog)
Definition citydlg.c:2105
static void unit_activate_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:2670
static void present_unit_activate_close_callback(GtkWidget *w, gpointer data)
Definition citydlg.c:2709
static void set_city_workertask(GtkWidget *w, gpointer data)
Definition citydlg.c:2865
static void rename_popup_callback(gpointer data, gint response, const char *input)
Definition citydlg.c:3256
@ WORKLIST_PAGE
Definition citydlg.c:111
@ CMA_PAGE
Definition citydlg.c:111
@ HAPPINESS_PAGE
Definition citydlg.c:111
@ SETTINGS_PAGE
Definition citydlg.c:112
@ STICKY_PAGE
Definition citydlg.c:112
@ NUM_PAGES
Definition citydlg.c:113
@ OVERVIEW_PAGE
Definition citydlg.c:111
static void city_dialog_update_improvement_list(struct city_dialog *pdialog)
Definition citydlg.c:2048
static void create_and_append_cma_page(struct city_dialog *pdialog)
Definition citydlg.c:1344
void popdown_city_dialog(struct city *pcity)
Definition citydlg.c:587
static struct @139 workertask_req
static gboolean supported_unit_callback(GtkWidget *w, GdkEventButton *ev, gpointer data)
Definition citydlg.c:2416
void close_cma_dialog(struct city *pcity)
Definition cma_fe.c:104
struct cma_dialog * create_cma_dialog(struct city *pcity, bool tiny)
Definition cma_fe.c:214
void refresh_cma_dialog(struct city *pcity, enum cma_refresh refresh)
Definition cma_fe.c:472
@ REFRESH_ALL
Definition cma_fe.h:26
void unit_select_dialog_popup(struct tile *ptile)
Definition dialogs.c:382
void popup_upgrade_dialog(struct unit_list *punits)
Definition dialogs.c:1444
void popup_disband_dialog(struct unit_list *punits)
Definition dialogs.c:1482
GtkWidget * toplevel
Definition gui_main.c:124
GtkWidget * map_canvas
Definition gui_main.c:106
int screen_height(void)
Definition gui_main.c:2376
#define GUI_GTK_OPTION(optname)
Definition gui_main.h:25
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:281
void intl_slist(int n, const char **s, bool *done)
Definition gui_stuff.c:105
void close_happiness_dialog(struct city *pcity)
Definition happiness.c:330
void refresh_happiness_dialog(struct city *pcity)
Definition happiness.c:317
GtkWidget * get_top_happiness_display(struct city *pcity, bool low_dlg, GtkWidget *win)
Definition happiness.c:356
void popup_help_dialog_typed(const char *item, enum help_page_type htype)
Definition helpdlg.c:195
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
void put_unit_image_city_overlays(struct unit *punit, GtkImage *p, int height, int *upkeep_cost, int happy_cost)
Definition mapview.c:503
void put_unit_image(struct unit *punit, GtkImage *p, int height)
Definition mapview.c:478
static struct gui_dialog * shell
Definition messagedlg.c:39
GdkPixbuf * sprite_get_pixbuf(struct sprite *sprite)
Definition sprite.c:402
bool request_transport(struct unit *cargo, struct tile *ptile)
void refresh_worklist(GtkWidget *editor)
Definition wldlg.c:1329
void add_worklist_dnd_target(GtkWidget *w)
Definition wldlg.c:337
void reset_city_worklist(GtkWidget *editor, struct city *pcity)
Definition wldlg.c:1281
GtkWidget * create_worklist(void)
Definition wldlg.c:1054
GtkWidget * icon_label_button_new(const gchar *icon_name, const gchar *label_text)
Definition gui_stuff.c:76
@ HELP_IMPROVEMENT
Definition helpdlg_g.h:20
@ HELP_WONDER
Definition helpdlg_g.h:21
int impr_sell_gold(const struct impr_type *pimprove)
enum test_result test_player_sell_building_now(struct player *pplayer, struct city *pcity, const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
Impr_type_id improvement_number(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
bool is_small_wonder(const struct impr_type *pimprove)
const char * name
Definition inputfile.c:127
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_debug(message,...)
Definition log.h:115
void center_tile_mapcanvas(const struct tile *ptile)
bool can_slide
#define fc_malloc(sz)
Definition mem.h:34
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:304
bool unit_can_load(const struct unit *punit)
Definition movement.c:841
#define GUI_GTK3_22_CITYDLG_MAX_XSIZE
Definition options.h:597
#define GUI_GTK3_22_CITYDLG_MIN_XSIZE
Definition options.h:596
int send_packet_worker_task(struct connection *pc, const struct packet_worker_task *packet)
int dsend_packet_city_options_req(struct connection *pc, int city_id16, int city_id32, bv_city_options options)
int len
Definition packhand.c:125
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1205
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1179
void economy_report_dialog_update(void)
#define CLIP(lower, current, upper)
Definition shared.h:57
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MIN(x, y)
Definition shared.h:55
#define FC_INFINITY
Definition shared.h:36
size_t size
Definition specvec.h:72
cairo_surface_t * surface
Definition canvas.h:22
GtkWidget * prev_command
Definition citydlg.c:202
GtkWidget * name_label
Definition citydlg.c:140
GtkWidget * rename_shell
Definition citydlg.c:199
GtkWidget * info_ebox[NUM_INFO_FIELDS]
Definition citydlg.c:165
GtkWidget * rename_command
Definition citydlg.c:190
GtkWidget * production_bar
Definition citydlg.c:151
GtkWidget * supported_units_frame
Definition citydlg.c:156
GtkWidget * popup_menu
Definition citydlg.c:144
GtkWidget * sell_shell
Definition citydlg.c:197
GtkWidget * production_label
Definition citydlg.c:172
struct city_dialog::@143 misc
GtkWidget * widget
Definition citydlg.c:181
GtkWidget * supported_unit_table
Definition citydlg.c:157
GtkWidget * disband_on_settler
Definition citydlg.c:192
enum city_dialog::@211 page
struct city_map_canvas map_canvas
Definition citydlg.c:149
GtkWidget * improvement_list
Definition citydlg.c:154
GtkWidget * buy_command
Definition citydlg.c:153
short block_signal
Definition citydlg.c:194
GtkWidget * whichtab_radio[NUM_PAGES]
Definition citydlg.c:193
struct unit_node_vector supported_units
Definition citydlg.c:162
cairo_surface_t * map_canvas_store_unscaled
Definition citydlg.c:141
struct city * pcity
Definition citydlg.c:137
struct unit_node_vector present_units
Definition citydlg.c:163
struct city_dialog::@142 happiness
city_map * view
Definition citydlg.h:450
struct city_dialog::@141 production
GtkWidget * citizens
Definition citydlg.c:184
GtkWidget * show_units_command
Definition citydlg.c:201
Impr_type_id sell_id
Definition citydlg.c:204
GtkWidget * production_combo
Definition citydlg.c:152
struct city_dialog::@140 overview
struct cma_dialog * cma_editor
Definition citydlg.c:187
cairo_surface_t * citizen_surface
Definition citydlg.c:146
GtkWidget * shell
Definition citydlg.c:139
GtkWidget * citizen_images
Definition citydlg.c:145
GtkWidget * worklist
Definition citydlg.c:175
GtkWidget * present_units_frame
Definition citydlg.c:159
GtkWidget * info_label[NUM_INFO_FIELDS]
Definition citydlg.c:166
GtkWidget * new_citizens_radio[3]
Definition citydlg.c:191
GtkListStore * change_production_store
Definition citydlg.c:168
GtkWidget * present_unit_table
Definition citydlg.c:160
GtkWidget * notebook
Definition citydlg.c:142
GtkWidget * next_command
Definition citydlg.c:202
GtkTreeSelection * change_selection
Definition citydlg.c:198
GtkWidget * darea
Definition citydlg.c:133
GtkWidget * sw
Definition citydlg.c:131
GtkWidget * ebox
Definition citydlg.c:132
Definition city.h:309
struct worker_task_list * task_reqs
Definition city.h:395
int surplus[O_LAST]
Definition city.h:343
int food_stock
Definition city.h:354
int pollution
Definition city.h:356
int id
Definition city.h:315
int waste[O_LAST]
Definition city.h:344
struct unit_list * info_units_present
Definition city.h:457
struct player * owner
Definition city.h:312
struct unit_list * info_units_supported
Definition city.h:456
struct worklist worklist
Definition city.h:387
int steal
Definition city.h:397
citizens size
Definition city.h:320
int illness
Definition city.h:417
int culture
Definition city.h:448
int buy_cost
Definition city.h:449
struct tile * tile
Definition city.h:311
int shield_stock
Definition city.h:355
int prod[O_LAST]
Definition city.h:346
struct unit_list * units_supported
Definition city.h:391
struct city::@17::@20 client
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
GtkWidget * shell
Definition cma_fe.h:33
struct city * pcity
Definition cma_fe.h:32
struct player * playing
Definition connection.h:156
Definition climisc.h:82
struct universal item
Definition climisc.h:83
char descr[MAX_LEN_NAME+40]
Definition climisc.h:84
enum unit_activity activity
struct city_list * cities
Definition player.h:281
struct terrain * cultivate_result
Definition terrain.h:203
struct terrain * plant_result
Definition terrain.h:206
struct terrain * transform_result
Definition terrain.h:217
Definition tile.h:49
int index
Definition tile.h:50
struct unit_list * units
Definition tile.h:57
int height
Definition citydlg.c:97
GtkWidget * cmd
Definition citydlg.c:95
GtkWidget * pix
Definition citydlg.c:96
Definition unit.h:138
int upkeep[O_LAST]
Definition unit.h:148
enum unit_activity activity
Definition unit.h:157
int id
Definition unit.h:145
int homecity
Definition unit.h:146
enum universals_n kind
Definition fc_types.h:758
universals_u value
Definition fc_types.h:757
struct tile * ptile
Definition workertask.h:22
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * unit_description(struct unit *punit)
Definition text.c:508
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_terrain(_tile)
Definition tile.h:109
struct sprite * get_building_sprite(const struct tileset *t, const struct impr_type *pimprove)
Definition tilespec.c:6494
int tileset_small_sprite_width(const struct tileset *t)
Definition tilespec.c:864
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum direction8 facing)
Definition tilespec.c:6516
int tileset_full_tile_height(const struct tileset *t)
Definition tilespec.c:752
int tileset_small_sprite_height(const struct tileset *t)
Definition tilespec.c:900
struct sprite * get_icon_sprite(const struct tileset *t, enum icon_type icon)
Definition tilespec.c:6674
int tileset_unit_with_upkeep_height(const struct tileset *t)
Definition tilespec.c:822
struct sprite * get_citizen_sprite(const struct tileset *t, enum citizen_category type, int citizen_index, const struct city *pcity)
Definition tilespec.c:6437
@ ICON_CITYDLG
Definition tilespec.h:311
const struct unit_type * utype
Definition fc_types.h:604
const struct impr_type * building
Definition fc_types.h:598
bool can_unit_change_homecity_to(const struct civ_map *nmap, const struct unit *punit, const struct city *pcity)
Definition unit.c:444
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2425
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:328
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:771
#define unit_tile(_pu)
Definition unit.h:395
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1755
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1612
static SDL_Surface * info_label
Definition widget.c:57
bool worklist_is_empty(const struct worklist *pwl)
Definition worklist.c:66