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)
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 ***********************************************************************/
15 #include <fc_config.h>
30 #include "government.h"
36 #include "client_main.h"
39 /* client/gui-gtk-3.0 */
41 #include "gui_stuff.h"
46 /******************************************************************/
47 static const char *table_text
[] = {
74 /******************************************************************/
76 struct player
*pplayer
;
79 GtkTreeStore
*diplstates
;
81 GtkWidget
*table_labels
[LABEL_LAST
];
84 #define SPECLIST_TAG dialog
85 #define SPECLIST_TYPE struct intel_dialog
88 #define dialog_list_iterate(dialoglist, pdialog) \
89 TYPED_LIST_ITERATE(struct intel_dialog, dialoglist, pdialog)
90 #define dialog_list_iterate_end LIST_ITERATE_END
92 static struct dialog_list
*dialog_list
;
93 static struct intel_dialog
*create_intel_dialog(struct player
*p
);
95 /****************************************************************
96 Initialize intelligenze dialogs
97 *****************************************************************/
98 void intel_dialog_init()
100 dialog_list
= dialog_list_new();
103 /****************************************************************
104 Free resources allocated for intelligenze dialogs
105 *****************************************************************/
106 void intel_dialog_done()
108 dialog_list_destroy(dialog_list
);
111 /****************************************************************
112 Get intelligenze dialog between client user and other player
114 *****************************************************************/
115 static struct intel_dialog
*get_intel_dialog(struct player
*pplayer
)
117 dialog_list_iterate(dialog_list
, pdialog
) {
118 if (pdialog
->pplayer
== pplayer
) {
121 } dialog_list_iterate_end
;
126 /****************************************************************
127 Open intelligenze dialog
128 *****************************************************************/
129 void popup_intel_dialog(struct player
*p
)
131 struct intel_dialog
*pdialog
;
133 if (!(pdialog
= get_intel_dialog(p
))) {
134 pdialog
= create_intel_dialog(p
);
137 update_intel_dialog(p
);
139 gtk_window_present(GTK_WINDOW(pdialog
->shell
));
142 /****************************************************************
143 Intelligenze dialog destruction requested
144 *****************************************************************/
145 static void intel_destroy_callback(GtkWidget
*w
, gpointer data
)
147 struct intel_dialog
*pdialog
= (struct intel_dialog
*)data
;
149 dialog_list_remove(dialog_list
, pdialog
);
154 /**************************************************************************
155 Close an intelligence dialog for the given player.
156 **************************************************************************/
157 void close_intel_dialog(struct player
*p
)
159 struct intel_dialog
*pdialog
= get_intel_dialog(p
);
160 intel_destroy_callback(NULL
, pdialog
);
163 /****************************************************************
164 Create new intelligenze dialog between client user and player
166 *****************************************************************/
167 static struct intel_dialog
*create_intel_dialog(struct player
*p
)
169 struct intel_dialog
*pdialog
;
171 GtkWidget
*shell
, *notebook
, *label
, *sw
, *view
, *table
;
172 GtkCellRenderer
*rend
;
173 GtkTreeViewColumn
*col
;
177 pdialog
= fc_malloc(sizeof(*pdialog
));
178 pdialog
->pplayer
= p
;
180 shell
= gtk_dialog_new_with_buttons(NULL
,
186 pdialog
->shell
= shell
;
187 gtk_window_set_default_size(GTK_WINDOW(shell
), 350, 350);
188 setup_dialog(shell
, toplevel
);
189 gtk_dialog_set_default_response(GTK_DIALOG(shell
), GTK_RESPONSE_CLOSE
);
191 g_signal_connect(shell
, "destroy",
192 G_CALLBACK(intel_destroy_callback
), pdialog
);
193 g_signal_connect(shell
, "response",
194 G_CALLBACK(gtk_widget_destroy
), NULL
);
196 notebook
= gtk_notebook_new();
197 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook
), GTK_POS_BOTTOM
);
198 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(shell
))), notebook
);
201 table
= gtk_grid_new();
202 g_object_set(table
, "margin", 6, NULL
);
204 gtk_grid_set_row_spacing(GTK_GRID(table
), 2);
205 gtk_grid_set_column_spacing(GTK_GRID(table
), 12);
207 /* TRANS: Overview tab of foreign intelligence report dialog */
208 label
= gtk_label_new_with_mnemonic(_("_Overview"));
209 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), table
, label
);
211 for (i
= 0; i
< ARRAY_SIZE(table_text
); i
++) {
213 label
= gtk_label_new(_(table_text
[i
]));
214 gtk_widget_set_halign(label
, GTK_ALIGN_START
);
215 gtk_widget_set_valign(label
, GTK_ALIGN_CENTER
);
216 gtk_grid_attach(GTK_GRID(table
), label
, 0, i
, 1, 1);
218 label
= gtk_label_new(NULL
);
219 pdialog
->table_labels
[i
] = label
;
220 gtk_widget_set_halign(label
, GTK_ALIGN_START
);
221 gtk_widget_set_valign(label
, GTK_ALIGN_CENTER
);
222 gtk_grid_attach(GTK_GRID(table
), label
, 1, i
, 1, 1);
224 pdialog
->table_labels
[i
] = NULL
;
229 pdialog
->diplstates
= gtk_tree_store_new(1, G_TYPE_STRING
);
231 view
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(pdialog
->diplstates
));
232 g_object_set(view
, "margin", 6, NULL
);
233 gtk_widget_set_hexpand(view
, TRUE
);
234 gtk_widget_set_vexpand(view
, TRUE
);
235 g_object_unref(pdialog
->diplstates
);
236 gtk_container_set_border_width(GTK_CONTAINER(view
), 6);
237 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view
), FALSE
);
239 rend
= gtk_cell_renderer_text_new();
240 col
= gtk_tree_view_column_new_with_attributes(NULL
, rend
,
242 gtk_tree_view_append_column(GTK_TREE_VIEW(view
), col
);
244 gtk_tree_view_expand_all(GTK_TREE_VIEW(view
));
246 sw
= gtk_scrolled_window_new(NULL
,NULL
);
247 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw
),
248 GTK_SHADOW_ETCHED_IN
);
249 gtk_container_add(GTK_CONTAINER(sw
), view
);
251 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw
),
252 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
254 label
= gtk_label_new_with_mnemonic(_("_Diplomacy"));
255 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), sw
, label
);
258 pdialog
->techs
= gtk_list_store_new(2, G_TYPE_BOOLEAN
, G_TYPE_STRING
);
259 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(pdialog
->techs
),
260 1, GTK_SORT_ASCENDING
);
262 view
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(pdialog
->techs
));
263 g_object_set(view
, "margin", 6, NULL
);
264 gtk_widget_set_hexpand(view
, TRUE
);
265 gtk_widget_set_vexpand(view
, TRUE
);
266 g_object_unref(pdialog
->techs
);
267 gtk_container_set_border_width(GTK_CONTAINER(view
), 6);
268 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view
), FALSE
);
270 rend
= gtk_cell_renderer_toggle_new();
271 col
= gtk_tree_view_column_new_with_attributes(NULL
, rend
,
273 gtk_tree_view_append_column(GTK_TREE_VIEW(view
), col
);
275 rend
= gtk_cell_renderer_text_new();
276 col
= gtk_tree_view_column_new_with_attributes(NULL
, rend
,
278 gtk_tree_view_append_column(GTK_TREE_VIEW(view
), col
);
280 sw
= gtk_scrolled_window_new(NULL
,NULL
);
281 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw
),
282 GTK_SHADOW_ETCHED_IN
);
283 gtk_container_add(GTK_CONTAINER(sw
), view
);
285 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw
),
286 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
288 label
= gtk_label_new_with_mnemonic(_("_Techs"));
289 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), sw
, label
);
291 gtk_widget_show_all(gtk_dialog_get_content_area(GTK_DIALOG(shell
)));
293 dialog_list_prepend(dialog_list
, pdialog
);
298 /****************************************************************************
299 Update the intelligence dialog for the given player. This is called by
300 the core client code when that player's information changes.
301 ****************************************************************************/
302 void update_intel_dialog(struct player
*p
)
304 struct intel_dialog
*pdialog
= get_intel_dialog(p
);
307 const struct research
*mresearch
, *presearch
;
308 GtkTreeIter diplstates
[DS_LAST
];
312 gchar
*title
= g_strdup_printf(_("Foreign Intelligence: %s Empire"),
313 nation_adjective_for_player(p
));
314 gtk_window_set_title(GTK_WINDOW(pdialog
->shell
), title
);
318 gtk_tree_store_clear(pdialog
->diplstates
);
320 for (i
= 0; i
< ARRAY_SIZE(diplstates
); i
++) {
324 gtk_tree_store_append(pdialog
->diplstates
, &it
, NULL
);
325 g_value_init(&v
, G_TYPE_STRING
);
326 g_value_set_static_string(&v
, diplstate_type_translated_name(i
));
327 gtk_tree_store_set_value(pdialog
->diplstates
, &it
, 0, &v
);
332 players_iterate(other
) {
333 const struct player_diplstate
*state
;
337 if (other
== p
|| !other
->is_alive
) {
340 state
= player_diplstate_get(p
, other
);
341 gtk_tree_store_append(pdialog
->diplstates
, &it
,
342 &diplstates
[state
->type
]);
343 g_value_init(&v
, G_TYPE_STRING
);
344 g_value_set_static_string(&v
, player_name(other
));
345 gtk_tree_store_set_value(pdialog
->diplstates
, &it
, 0, &v
);
347 } players_iterate_end
;
350 gtk_list_store_clear(pdialog
->techs
);
352 mresearch
= research_get(client_player());
353 presearch
= research_get(p
);
354 advance_index_iterate(A_FIRST
, advi
) {
355 if (research_invention_state(presearch
, advi
) == TECH_KNOWN
) {
358 gtk_list_store_append(pdialog
->techs
, &it
);
360 gtk_list_store_set(pdialog
->techs
, &it
,
361 0, research_invention_state(mresearch
, advi
)
363 1, research_advance_name_translation(presearch
,
367 } advance_index_iterate_end
;
370 for (i
= 0; i
< ARRAY_SIZE(pdialog
->table_labels
); i
++) {
371 if (pdialog
->table_labels
[i
]) {
378 ruler_title_for_player(p
, tbuf
, sizeof(tbuf
));
379 buf
= g_strdup(tbuf
);
381 case LABEL_GOVERNMENT
:
382 buf
= g_strdup(government_name_for_player(p
));
385 pcity
= player_capital(p
);
386 /* TRANS: "unknown" location */
387 buf
= g_strdup((!pcity
) ? _("(unknown)") : city_name_get(pcity
));
390 buf
= g_strdup_printf("%d", p
->economic
.gold
);
393 buf
= g_strdup_printf("%d%%", p
->economic
.tax
);
396 buf
= g_strdup_printf("%d%%", p
->economic
.science
);
399 buf
= g_strdup_printf("%d%%", p
->economic
.luxury
);
401 case LABEL_RESEARCHING
:
403 struct research
*research
= research_get(p
);
405 switch (research
->researching
) {
407 /* TRANS: "Unknown" advance/technology */
408 buf
= g_strdup(_("(Unknown)"));
411 /* TRANS: missing value */
412 buf
= g_strdup(_("(none)"));
415 buf
= g_strdup_printf("%s(%d/%d)",
416 research_advance_name_translation
417 (research
, research
->researching
),
418 research
->bulbs_researched
,
419 research
->client
.researching_cost
);
429 gtk_label_set_text(GTK_LABEL(pdialog
->table_labels
[i
]), buf
);