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-2.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
, *alignment
;
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(shell
)->vbox
), notebook
);
201 table
= gtk_table_new(ARRAY_SIZE(table_text
), 2, FALSE
);
203 gtk_table_set_row_spacings(GTK_TABLE(table
), 2);
204 gtk_table_set_col_spacings(GTK_TABLE(table
), 12);
206 alignment
= gtk_alignment_new(0.0, 0.0, 0.0, 0.0);
207 gtk_container_set_border_width(GTK_CONTAINER(alignment
), 6);
208 gtk_container_add(GTK_CONTAINER(alignment
), table
);
210 /* TRANS: Overview tab of foreign intelligence report dialog */
211 label
= gtk_label_new_with_mnemonic(_("_Overview"));
212 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), alignment
, label
);
214 for (i
= 0; i
< ARRAY_SIZE(table_text
); i
++) {
216 label
= gtk_label_new(_(table_text
[i
]));
217 gtk_misc_set_alignment(GTK_MISC(label
), 0.0, 0.5);
218 gtk_table_attach(GTK_TABLE(table
), label
,
219 0, 1, i
, i
+1, GTK_FILL
, GTK_FILL
|GTK_EXPAND
, 0, 0);
221 label
= gtk_label_new(NULL
);
222 pdialog
->table_labels
[i
] = label
;
223 gtk_misc_set_alignment(GTK_MISC(label
), 0.0, 0.5);
224 gtk_table_attach(GTK_TABLE(table
), label
,
225 1, 2, i
, i
+1, GTK_FILL
, GTK_FILL
|GTK_EXPAND
, 0, 0);
227 pdialog
->table_labels
[i
] = NULL
;
228 gtk_table_set_row_spacing(GTK_TABLE(table
), i
, 12);
233 pdialog
->diplstates
= gtk_tree_store_new(1, G_TYPE_STRING
);
235 view
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(pdialog
->diplstates
));
236 g_object_unref(pdialog
->diplstates
);
237 gtk_container_set_border_width(GTK_CONTAINER(view
), 6);
238 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view
), FALSE
);
240 rend
= gtk_cell_renderer_text_new();
241 col
= gtk_tree_view_column_new_with_attributes(NULL
, rend
,
243 gtk_tree_view_append_column(GTK_TREE_VIEW(view
), col
);
245 gtk_tree_view_expand_all(GTK_TREE_VIEW(view
));
247 sw
= gtk_scrolled_window_new(NULL
,NULL
);
248 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw
),
249 GTK_SHADOW_ETCHED_IN
);
250 gtk_container_add(GTK_CONTAINER(sw
), view
);
252 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw
),
253 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
255 alignment
= gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
256 gtk_container_set_border_width(GTK_CONTAINER(alignment
), 6);
257 gtk_container_add(GTK_CONTAINER(alignment
), sw
);
259 label
= gtk_label_new_with_mnemonic(_("_Diplomacy"));
260 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), alignment
, label
);
263 pdialog
->techs
= gtk_list_store_new(2, G_TYPE_BOOLEAN
, G_TYPE_STRING
);
264 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(pdialog
->techs
),
265 1, GTK_SORT_ASCENDING
);
267 view
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(pdialog
->techs
));
268 g_object_unref(pdialog
->techs
);
269 gtk_container_set_border_width(GTK_CONTAINER(view
), 6);
270 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view
), FALSE
);
272 rend
= gtk_cell_renderer_toggle_new();
273 col
= gtk_tree_view_column_new_with_attributes(NULL
, rend
,
275 gtk_tree_view_append_column(GTK_TREE_VIEW(view
), col
);
277 rend
= gtk_cell_renderer_text_new();
278 col
= gtk_tree_view_column_new_with_attributes(NULL
, rend
,
280 gtk_tree_view_append_column(GTK_TREE_VIEW(view
), col
);
282 sw
= gtk_scrolled_window_new(NULL
,NULL
);
283 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw
),
284 GTK_SHADOW_ETCHED_IN
);
285 gtk_container_add(GTK_CONTAINER(sw
), view
);
287 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw
),
288 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
290 alignment
= gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
291 gtk_container_set_border_width(GTK_CONTAINER(alignment
), 6);
292 gtk_container_add(GTK_CONTAINER(alignment
), sw
);
294 label
= gtk_label_new_with_mnemonic(_("_Techs"));
295 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), alignment
, label
);
297 gtk_widget_show_all(GTK_DIALOG(shell
)->vbox
);
299 dialog_list_prepend(dialog_list
, pdialog
);
304 /****************************************************************************
305 Update the intelligence dialog for the given player. This is called by
306 the core client code when that player's information changes.
307 ****************************************************************************/
308 void update_intel_dialog(struct player
*p
)
310 struct intel_dialog
*pdialog
= get_intel_dialog(p
);
313 const struct research
*mresearch
, *presearch
;
314 GtkTreeIter diplstates
[DS_LAST
];
318 gchar
*title
= g_strdup_printf(_("Foreign Intelligence: %s Empire"),
319 nation_adjective_for_player(p
));
320 gtk_window_set_title(GTK_WINDOW(pdialog
->shell
), title
);
324 gtk_tree_store_clear(pdialog
->diplstates
);
326 for (i
= 0; i
< ARRAY_SIZE(diplstates
); i
++) {
330 gtk_tree_store_append(pdialog
->diplstates
, &it
, NULL
);
331 g_value_init(&v
, G_TYPE_STRING
);
332 g_value_set_static_string(&v
, diplstate_type_translated_name(i
));
333 gtk_tree_store_set_value(pdialog
->diplstates
, &it
, 0, &v
);
338 players_iterate_alive(other
) {
339 const struct player_diplstate
*state
;
346 state
= player_diplstate_get(p
, other
);
347 gtk_tree_store_append(pdialog
->diplstates
, &it
,
348 &diplstates
[state
->type
]);
349 g_value_init(&v
, G_TYPE_STRING
);
350 g_value_set_static_string(&v
, player_name(other
));
351 gtk_tree_store_set_value(pdialog
->diplstates
, &it
, 0, &v
);
353 } players_iterate_alive_end
;
356 gtk_list_store_clear(pdialog
->techs
);
358 mresearch
= research_get(client_player());
359 presearch
= research_get(p
);
360 advance_index_iterate(A_FIRST
, advi
) {
361 if (research_invention_state(presearch
, advi
) == TECH_KNOWN
) {
364 gtk_list_store_append(pdialog
->techs
, &it
);
366 gtk_list_store_set(pdialog
->techs
, &it
,
367 0, research_invention_state(mresearch
, advi
)
369 1, research_advance_name_translation(presearch
,
373 } advance_index_iterate_end
;
376 for (i
= 0; i
< ARRAY_SIZE(pdialog
->table_labels
); i
++) {
377 if (pdialog
->table_labels
[i
]) {
384 ruler_title_for_player(p
, tbuf
, sizeof(tbuf
));
385 buf
= g_strdup(tbuf
);
387 case LABEL_GOVERNMENT
:
388 buf
= g_strdup(government_name_for_player(p
));
391 pcity
= player_capital(p
);
392 /* TRANS: "unknown" location */
393 buf
= g_strdup((!pcity
) ? _("(unknown)") : city_name_get(pcity
));
396 buf
= g_strdup_printf("%d", p
->economic
.gold
);
399 buf
= g_strdup_printf("%d%%", p
->economic
.tax
);
402 buf
= g_strdup_printf("%d%%", p
->economic
.science
);
405 buf
= g_strdup_printf("%d%%", p
->economic
.luxury
);
407 case LABEL_RESEARCHING
:
409 struct research
*research
= research_get(p
);
411 switch (research
->researching
) {
413 /* TRANS: "Unknown" advance/technology */
414 buf
= g_strdup(_("(Unknown)"));
417 /* TRANS: missing value */
418 buf
= g_strdup(_("(none)"));
421 buf
= g_strdup_printf("%s(%d/%d)",
422 research_advance_name_translation
423 (research
, research
->researching
),
424 research
->bulbs_researched
,
425 research
->client
.researching_cost
);
435 gtk_label_set_text(GTK_LABEL(pdialog
->table_labels
[i
]), buf
);