Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-gtk-5.0/diplodlg.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
diplodlg.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
21#include <gtk/gtk.h>
22
23/* utility */
24#include "log.h"
25#include "mem.h"
26#include "shared.h"
27#include "support.h"
28
29/* common */
30#include "diptreaty.h"
31#include "fcintl.h"
32#include "game.h"
33#include "government.h"
34#include "map.h"
35#include "nation.h"
36#include "packets.h"
37#include "player.h"
38#include "research.h"
39
40/* client */
41#include "chatline.h"
42#include "client_main.h"
43#include "climisc.h"
44#include "options.h"
45
46/* client/gui-gtk-5.0 */
47#include "diplodlg.h"
48#include "gui_main.h"
49#include "gui_stuff.h"
50#include "mapview.h"
51#include "plrdlg.h"
52
53struct Diplomacy_dialog {
54 struct Treaty *treaty;
55 struct gui_dialog *dialog;
56
57 GtkWidget *pic0;
58 GtkWidget *pic1;
59
60 GtkListStore *store;
61};
62
63struct Diplomacy_notebook {
64 struct gui_dialog *dialog;
65 GtkWidget *notebook;
66};
67
68struct city_deal {
69 int giver;
70 int receiver;
71 int id;
72};
73
74#define SPECLIST_TAG dialog
75#define SPECLIST_TYPE struct Diplomacy_dialog
76#include "speclist.h"
77
78#define dialog_list_iterate(dialoglist, pdialog) \
79 TYPED_LIST_ITERATE(struct Diplomacy_dialog, dialoglist, pdialog)
80#define dialog_list_iterate_end LIST_ITERATE_END
81
82 static struct dialog_list *dialog_list;
83 static struct Diplomacy_notebook *dipl_main;
84
85static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty,
86 struct player *plr0,
87 struct player *plr1);
88
89static struct Diplomacy_dialog *find_diplomacy_dialog(struct player *they);
90static void popup_diplomacy_dialog(struct Treaty *ptreaty, struct player *they,
91 struct player *initiator);
92static void diplomacy_dialog_map_callback(GSimpleAction *action,
93 GVariant *parameter,
94 gpointer data);
95static void diplomacy_dialog_seamap_callback(GSimpleAction *action,
96 GVariant *parameter,
97 gpointer data);
98
99static void diplomacy_dialog_tech_callback(GSimpleAction *action,
100 GVariant *parameter,
101 gpointer data);
102static void diplomacy_dialog_city_callback(GSimpleAction *action,
103 GVariant *parameter,
104 gpointer data);
105static void diplomacy_dialog_vision_callback(GSimpleAction *action,
106 GVariant *parameter,
107 gpointer data);
108static void diplomacy_dialog_embassy_callback(GSimpleAction *action,
109 GVariant *parameter,
110 gpointer data);
111static void diplomacy_dialog_shared_tiles_callback(GSimpleAction *action,
112 GVariant *parameter,
113 gpointer data);
114static void diplomacy_dialog_ceasefire_callback(GSimpleAction *action,
115 GVariant *parameter,
116 gpointer data);
117static void diplomacy_dialog_peace_callback(GSimpleAction *action,
118 GVariant *parameter,
119 gpointer data);
120static void diplomacy_dialog_alliance_callback(GSimpleAction *action,
121 GVariant *parameter,
122 gpointer data);
123
124static void close_diplomacy_dialog(struct Diplomacy_dialog *pdialog);
125static void update_diplomacy_dialog(struct Diplomacy_dialog *pdialog);
126static void diplo_dialog_returnkey(GtkWidget *w, gpointer data);
127
128static struct Diplomacy_notebook *diplomacy_main_create(void);
129static void diplomacy_main_destroy(void);
130static void diplomacy_main_response(struct gui_dialog *dlg, int response,
131 gpointer data);
132
133#define RESPONSE_CANCEL_MEETING 100
134#define RESPONSE_CANCEL_MEETING_ALL 101
135
136/************************************************************************/
139 void gui_recv_accept_treaty(struct Treaty *ptreaty, struct player *they)
140{
141 struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
142
143 if (!pdialog) {
144 return;
145 }
146
147 fc_assert(pdialog->treaty == ptreaty);
148
149 update_diplomacy_dialog(pdialog);
150 gui_dialog_alert(pdialog->dialog);
151}
152
153/************************************************************************/
156 void gui_init_meeting(struct Treaty *ptreaty, struct player *they,
157 struct player *initiator)
158{
159 popup_diplomacy_dialog(ptreaty, they, initiator);
160}
161
162/************************************************************************/
165 void gui_recv_cancel_meeting(struct Treaty *ptreaty, struct player *they,
166 struct player *initiator)
167{
168 struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
169
170 if (!pdialog) {
171 return;
172 }
173
174 fc_assert(pdialog->treaty == ptreaty);
175
176 close_diplomacy_dialog(pdialog);
177}
178
179/**********************************************************************/
182 void gui_prepare_clause_updt(struct Treaty *ptreaty, struct player *they)
183{
184 /* Not needed */
185}
186
187/************************************************************************/
190 void gui_recv_create_clause(struct Treaty *ptreaty, struct player *they)
191{
192 struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
193
194 if (!pdialog) {
195 return;
196 }
197
198 fc_assert(pdialog->treaty == ptreaty);
199
200 update_diplomacy_dialog(pdialog);
201 gui_dialog_alert(pdialog->dialog);
202}
203
204/************************************************************************/
207 void gui_recv_remove_clause(struct Treaty *ptreaty, struct player *they)
208{
209 struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
210
211 if (!pdialog) {
212 return;
213 }
214
215 fc_assert(pdialog->treaty == ptreaty);
216
217 update_diplomacy_dialog(pdialog);
218 gui_dialog_alert(pdialog->dialog);
219}
220
221/************************************************************************/
224 static void popup_diplomacy_dialog(struct Treaty *ptreaty, struct player *they,
225 struct player *initiator)
226{
227 struct Diplomacy_dialog *pdialog = find_diplomacy_dialog(they);
228
229 if (!is_human(client_player())) {
230 return; /* Don't show if we are not human controlled. */
231 }
232
233 if (!pdialog) {
234 pdialog = create_diplomacy_dialog(ptreaty, client_player(), they);
235 }
236
237 gui_dialog_present(pdialog->dialog);
238 /* We initated the meeting - Make the tab active */
239 if (initiator == client_player()) {
240 /* We have to raise the diplomacy meeting tab as well as the selected
241 * meeting. */
242 fc_assert_ret(dipl_main != NULL);
243 gui_dialog_raise(dipl_main->dialog);
244 gui_dialog_raise(pdialog->dialog);
245
246 if (players_dialog_shell != NULL) {
247 gui_dialog_set_return_dialog(pdialog->dialog, players_dialog_shell);
248 }
249 }
250}
251
252/************************************************************************/
255 static gint sort_advance_names(gconstpointer a, gconstpointer b)
256{
257 const struct advance *padvance1 = (const struct advance *) a;
258 const struct advance *padvance2 = (const struct advance *) b;
259
260 return fc_strcoll(advance_name_translation(padvance1),
261 advance_name_translation(padvance2));
262}
263
264/************************************************************************/
267 static GMenu *create_clause_menu(GActionGroup *group,
268 struct Diplomacy_dialog *pdialog,
269 struct player *partner, bool them)
270{
271 GMenu *topmenu, *submenu;
272 GSimpleAction *act;
273 bool any_map = FALSE;
274 char act_plr_part[20];
275 char act_name[60];
276 struct player *pgiver, *pother;
277
278 if (them) {
279 fc_strlcpy(act_plr_part, "_them", sizeof(act_plr_part));
280 pgiver = partner;
281 pother = client_player();
282 } else {
283 fc_strlcpy(act_plr_part, "_us", sizeof(act_plr_part));
284 pgiver = client_player();
285 pother = partner;
286 }
287
288 topmenu = g_menu_new();
289
290 /* Maps. */
291 if (clause_enabled(CLAUSE_MAP)) {
292 submenu = g_menu_new();
293
294 fc_snprintf(act_name, sizeof(act_name), "worldmap%s", act_plr_part);
295 act = g_simple_action_new(act_name, NULL);
296 g_object_set_data(G_OBJECT(act), "plr", pgiver);
297 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
298 g_signal_connect(act, "activate", G_CALLBACK(diplomacy_dialog_map_callback),
299 pdialog);
300
301 fc_snprintf(act_name, sizeof(act_name), "win.worldmap%s", act_plr_part);
302 menu_item_append_unref(submenu, g_menu_item_new(_("World-map"), act_name));
303
304 any_map = TRUE;
305 }
306
307 if (clause_enabled(CLAUSE_SEAMAP)) {
308 if (!any_map) {
309 submenu = g_menu_new();
310 }
311
312 fc_snprintf(act_name, sizeof(act_name), "seamap%s", act_plr_part);
313 act = g_simple_action_new(act_name, NULL);
314 g_object_set_data(G_OBJECT(act), "plr", pgiver);
315 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
316 g_signal_connect(act, "activate", G_CALLBACK(diplomacy_dialog_seamap_callback),
317 pdialog);
318
319 fc_snprintf(act_name, sizeof(act_name), "win.seamap%s", act_plr_part);
320 menu_item_append_unref(submenu, g_menu_item_new(_("Sea-map"), act_name));
321
322 any_map = TRUE;
323 }
324
325 if (any_map) {
326 submenu_append_unref(topmenu, _("_Maps"), G_MENU_MODEL(submenu));
327 }
328
329 /* Trading: advances */
330 if (clause_enabled(CLAUSE_ADVANCE)) {
331 const struct research *gresearch = research_get(pgiver);
332 const struct research *oresearch = research_get(pother);
333 GList *sorting_list = NULL;
334 bool team_embassy = team_has_embassy(pgiver->team, pother);
335 int i;
336
337 submenu = g_menu_new();
338
339 advance_iterate(padvance) {
340 Tech_type_id tech = advance_number(padvance);
341
342 if (research_invention_state(gresearch, tech) == TECH_KNOWN
343 && (!team_embassy /* We don't know what the other could actually receive */
344 || research_invention_gettable(oresearch, tech,
345 game.info.tech_trade_allow_holes))
346 && (research_invention_state(oresearch, tech) == TECH_UNKNOWN
347 || research_invention_state(oresearch, tech)
348 == TECH_PREREQS_KNOWN)) {
349 sorting_list = g_list_prepend(sorting_list, padvance);
350 }
351 } advance_iterate_end;
352
353 if (NULL != sorting_list) {
354 GList *list_item;
355 const struct advance *padvance;
356
357 sorting_list = g_list_sort(sorting_list, sort_advance_names);
358
359 /* TRANS: All technologies menu item in the diplomatic dialog. */
360 fc_snprintf(act_name, sizeof(act_name), "advance%sall", act_plr_part);
361 act = g_simple_action_new(act_name, NULL);
362
363 g_object_set_data(G_OBJECT(act), "player_from",
364 GINT_TO_POINTER(player_number(pgiver)));
365 g_object_set_data(G_OBJECT(act), "player_to",
366 GINT_TO_POINTER(player_number(pother)));
367 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
368 g_signal_connect(act, "activate",
369 G_CALLBACK(diplomacy_dialog_tech_callback),
370 GINT_TO_POINTER(A_LAST));
371
372 fc_snprintf(act_name, sizeof(act_name), "win.advance%sall", act_plr_part);
373 menu_item_append_unref(submenu, g_menu_item_new(_("All advances"), act_name));
374
375 for (list_item = sorting_list, i = 0; NULL != list_item;
376 list_item = g_list_next(list_item), i++) {
377
378 fc_snprintf(act_name, sizeof(act_name), "advance%s%d",
379 act_plr_part, i);
380 act = g_simple_action_new(act_name, NULL);
381
382 padvance = (const struct advance *) list_item->data;
383 g_object_set_data(G_OBJECT(act), "player_from",
384 GINT_TO_POINTER(player_number(pgiver)));
385 g_object_set_data(G_OBJECT(act), "player_to",
386 GINT_TO_POINTER(player_number(pother)));
387 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
388 g_signal_connect(act, "activate",
389 G_CALLBACK(diplomacy_dialog_tech_callback),
390 GINT_TO_POINTER(advance_number(padvance)));
391
392 fc_snprintf(act_name, sizeof(act_name), "win.advance%s%d",
393 act_plr_part, i);
394 menu_item_append_unref(submenu,
395 g_menu_item_new(advance_name_translation(padvance),
396 act_name));
397 }
398
399 g_list_free(sorting_list);
400 }
401
402 submenu_append_unref(topmenu, _("_Advances"), G_MENU_MODEL(submenu));
403 }
404
405 /* Trading: cities. */
406
407 /****************************************************************
408 Creates a sorted list of plr0's cities, excluding the capital and
409 any cities not visible to plr1. This means that you can only trade
410 cities visible to requesting player.
411
412 - Kris Bubendorfer
413 *****************************************************************/
414 if (clause_enabled(CLAUSE_CITY)) {
415 int i = 0;
416 int n = city_list_size(pgiver->cities);
417
418 submenu = g_menu_new();
419
420 if (n > 0) {
421 struct city **city_list_ptrs;
422
423 city_list_ptrs = fc_malloc(sizeof(struct city *) * n);
424
425 city_list_iterate(pgiver->cities, pcity) {
426 if (!is_capital(pcity)) {
427 city_list_ptrs[i] = pcity;
428 i++;
429 }
430 } city_list_iterate_end;
431
432 if (i > 0) { /* Cities other than capitals */
433 int j;
434
435 qsort(city_list_ptrs, i, sizeof(struct city *), city_name_compare);
436
437 for (j = 0; j < i; j++) {
438 struct city_deal *deal = fc_malloc(sizeof(struct city_deal));
439
440 fc_snprintf(act_name, sizeof(act_name), "city%s%d", act_plr_part, i);
441 act = g_simple_action_new(act_name, NULL);
442
443 deal->giver = player_number(pgiver);
444 deal->receiver = player_number(pother);
445 deal->id = city_list_ptrs[j]->id;
446
447 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
448 g_signal_connect(act, "activate",
449 G_CALLBACK(diplomacy_dialog_city_callback),
450 (gpointer)deal);
451
452 fc_snprintf(act_name, sizeof(act_name), "win.city%s%d",
453 act_plr_part, i);
454 menu_item_append_unref(submenu,
455 g_menu_item_new(city_name_get(city_list_ptrs[j]),
456 act_name));
457 }
458 }
459
460 free(city_list_ptrs);
461 }
462
463 submenu_append_unref(topmenu, _("_Cities"), G_MENU_MODEL(submenu));
464 }
465
466 /* Give shared vision. */
467 if (clause_enabled(CLAUSE_VISION)) {
468 fc_snprintf(act_name, sizeof(act_name), "vision%s", act_plr_part);
469 act = g_simple_action_new(act_name, NULL);
470 g_object_set_data(G_OBJECT(act), "plr", pgiver);
471 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
472 g_signal_connect(act, "activate", G_CALLBACK(diplomacy_dialog_vision_callback),
473 pdialog);
474
475 fc_snprintf(act_name, sizeof(act_name), "win.vision%s", act_plr_part);
476 menu_item_append_unref(topmenu, g_menu_item_new(_("_Give shared vision"), act_name));
477
478 g_simple_action_set_enabled(G_SIMPLE_ACTION(act),
479 !gives_shared_vision(pgiver, pother));
480 }
481
482 /* Give embassy. */
483 if (clause_enabled(CLAUSE_EMBASSY)) {
484 fc_snprintf(act_name, sizeof(act_name), "embassy%s", act_plr_part);
485 act = g_simple_action_new(act_name, NULL);
486 g_object_set_data(G_OBJECT(act), "plr", pgiver);
487 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
488 g_signal_connect(act, "activate", G_CALLBACK(diplomacy_dialog_embassy_callback),
489 pdialog);
490
491 fc_snprintf(act_name, sizeof(act_name), "win.embassy%s", act_plr_part);
492 menu_item_append_unref(topmenu, g_menu_item_new(_("Give _embassy"), act_name));
493
494 /* Don't take in account the embassy effects. */
495 g_simple_action_set_enabled(G_SIMPLE_ACTION(act),
496 !player_has_real_embassy(pother, pgiver));
497 }
498
499 /* Shared tiles */
500 if (clause_enabled(CLAUSE_SHARED_TILES)) {
501 fc_snprintf(act_name, sizeof(act_name), "tiles%s", act_plr_part);
502 act = g_simple_action_new(act_name, NULL);
503 g_object_set_data(G_OBJECT(act), "plr", pgiver);
504 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
505 g_signal_connect(act, "activate", G_CALLBACK(diplomacy_dialog_shared_tiles_callback),
506 pdialog);
507
508 fc_snprintf(act_name, sizeof(act_name), "win.tiles%s", act_plr_part);
509 menu_item_append_unref(topmenu, g_menu_item_new(_("_Share tiles"), act_name));
510 }
511
512 /* Pacts. */
513 if (pgiver == pdialog->treaty->plr0) {
514 enum diplstate_type ds;
515 int pact_clauses = 0;
516
517 ds = player_diplstate_get(pgiver, pother)->type;
518
519 submenu = g_menu_new();
520
521 if (clause_enabled(CLAUSE_CEASEFIRE)) {
522 fc_snprintf(act_name, sizeof(act_name), "ceasefire%s", act_plr_part);
523 act = g_simple_action_new(act_name, NULL);
524 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
525 g_signal_connect(act, "activate",
526 G_CALLBACK(diplomacy_dialog_ceasefire_callback), pdialog);
527
528 fc_snprintf(act_name, sizeof(act_name), "win.ceasefire%s", act_plr_part);
529 menu_item_append_unref(submenu,
530 g_menu_item_new(Q_("?diplomatic_state:Cease-fire"),
531 act_name));
532
533 g_simple_action_set_enabled(G_SIMPLE_ACTION(act),
534 ds != DS_CEASEFIRE && ds != DS_TEAM);
535 pact_clauses++;
536 }
537
538 if (clause_enabled(CLAUSE_PEACE)) {
539 fc_snprintf(act_name, sizeof(act_name), "peace%s", act_plr_part);
540 act = g_simple_action_new(act_name, NULL);
541 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
542 g_signal_connect(act, "activate",
543 G_CALLBACK(diplomacy_dialog_peace_callback), pdialog);
544
545 fc_snprintf(act_name, sizeof(act_name), "win.peace%s", act_plr_part);
546 menu_item_append_unref(submenu, g_menu_item_new(Q_("?diplomatic_state:Peace"),
547 act_name));
548
549 g_simple_action_set_enabled(G_SIMPLE_ACTION(act),
550 ds != DS_PEACE && ds != DS_TEAM);
551 pact_clauses++;
552 }
553
554 if (clause_enabled(CLAUSE_ALLIANCE)) {
555 fc_snprintf(act_name, sizeof(act_name), "alliance%s", act_plr_part);
556 act = g_simple_action_new(act_name, NULL);
557 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(act));
558 g_signal_connect(act, "activate",
559 G_CALLBACK(diplomacy_dialog_alliance_callback), pdialog);
560
561 fc_snprintf(act_name, sizeof(act_name), "win.alliance%s", act_plr_part);
562 menu_item_append_unref(submenu,
563 g_menu_item_new(Q_("?diplomatic_state:Alliance"),
564 act_name));
565
566 g_simple_action_set_enabled(G_SIMPLE_ACTION(act),
567 ds != DS_ALLIANCE && ds != DS_TEAM);
568 pact_clauses++;
569 }
570
571 if (pact_clauses > 0) {
572 submenu_append_unref(topmenu, _("_Pacts"), G_MENU_MODEL(submenu));
573 } else {
574 g_object_unref(submenu);
575 }
576 }
577
578 return topmenu;
579}
580
581/************************************************************************/
584 static void row_callback(GtkTreeView *view, GtkTreePath *path,
585 GtkTreeViewColumn *col, gpointer data)
586{
587 struct Diplomacy_dialog *pdialog = (struct Diplomacy_dialog *)data;
588 gint i;
589 gint *index;
590
591 index = gtk_tree_path_get_indices(path);
592
593 i = 0;
594 clause_list_iterate(pdialog->treaty->clauses, pclause) {
595 if (i == index[0]) {
596 dsend_packet_diplomacy_remove_clause_req(&client.conn,
597 player_number(pdialog->treaty->plr1),
598 player_number(pclause->from),
599 pclause->type,
600 pclause->value);
601 return;
602 }
603 i++;
604 } clause_list_iterate_end;
605}
606
607/************************************************************************/
610 static struct Diplomacy_notebook *diplomacy_main_create(void)
611{
612 /* Collect all meetings in one main tab. */
613 if (!dipl_main) {
614 GtkWidget *dipl_sw;
615
616 dipl_main = fc_malloc(sizeof(*dipl_main));
617 gui_dialog_new(&(dipl_main->dialog), GTK_NOTEBOOK(top_notebook),
618 dipl_main->dialog, TRUE);
619 dipl_main->notebook = gtk_notebook_new();
620 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(dipl_main->notebook),
621 GTK_POS_RIGHT);
622 gtk_notebook_set_scrollable(GTK_NOTEBOOK(dipl_main->notebook), TRUE);
623
624 dipl_sw = gtk_scrolled_window_new();
625 gtk_widget_set_margin_bottom(dipl_sw, 2);
626 gtk_widget_set_margin_end(dipl_sw, 2);
627 gtk_widget_set_margin_start(dipl_sw, 2);
628 gtk_widget_set_margin_top(dipl_sw, 2);
629 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dipl_sw),
630 GTK_POLICY_AUTOMATIC,
631 GTK_POLICY_AUTOMATIC);
632 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(dipl_sw),
633 dipl_main->notebook);
634
635 /* Buttons */
636 gui_dialog_add_button(dipl_main->dialog, NULL,
637 _("Cancel _all meetings"),
638 RESPONSE_CANCEL_MEETING_ALL);
639
640 /* Responses for _all_ meetings. */
641 gui_dialog_response_set_callback(dipl_main->dialog,
642 diplomacy_main_response);
643
644 gui_dialog_add_content_widget(dipl_main->dialog, dipl_sw);
645
646 gui_dialog_show_all(dipl_main->dialog);
647 gui_dialog_present(dipl_main->dialog);
648 }
649
650 return dipl_main;
651}
652
653/************************************************************************/
656 static void diplomacy_main_destroy(void)
657{
658 if (dipl_main->dialog) {
659 gui_dialog_destroy(dipl_main->dialog);
660 }
661 free(dipl_main);
662 dipl_main = NULL;
663}
664
665/************************************************************************/
668 static void diplomacy_main_response(struct gui_dialog *dlg, int response,
669 gpointer data)
670{
671 if (!dipl_main) {
672 return;
673 }
674
675 switch (response) {
676 default:
677 log_error("unhandled response in %s: %d", __FUNCTION__, response);
678 fc__fallthrough; /* No break. */
679 case GTK_RESPONSE_DELETE_EVENT: /* GTK: delete the widget. */
680 case RESPONSE_CANCEL_MEETING_ALL: /* Cancel all meetings. */
681 dialog_list_iterate(dialog_list, adialog) {
682 /* This will do a round trip to the server ans close the diolag in the
683 * client. Closing the last dialog will also close the main tab.*/
684 dsend_packet_diplomacy_cancel_meeting_req(&client.conn,
685 player_number(
686 adialog->treaty->plr1));
687 } dialog_list_iterate_end;
688 break;
689 }
690}
691
692/************************************************************************/
695 static void diplomacy_destroy(struct Diplomacy_dialog *pdialog)
696{
697 if (NULL != pdialog->dialog) {
698 /* pdialog->dialog may be NULL if the tab has been destroyed
699 * by an other way. */
700 gui_dialog_destroy(pdialog->dialog);
701 pdialog->dialog = NULL;
702 }
703 dialog_list_remove(dialog_list, pdialog);
704 free(pdialog);
705
706 if (dialog_list) {
707 /* Diplomatic meetings in one main tab. */
708 if (dialog_list_size(dialog_list) > 0) {
709 if (dipl_main && dipl_main->dialog) {
710 gchar *buf;
711
712 buf = g_strdup_printf(_("Diplomacy [%d]"), dialog_list_size(dialog_list));
713 gui_dialog_set_title(dipl_main->dialog, buf);
714 g_free(buf);
715 }
716 } else if (dipl_main) {
717 /* No meeting left - destroy main tab. */
718 diplomacy_main_destroy();
719 }
720 }
721}
722
723/************************************************************************/
726 static void diplomacy_response(struct gui_dialog *dlg, int response,
727 gpointer data)
728{
729 struct Diplomacy_dialog *pdialog = NULL;
730
731 fc_assert_ret(data);
732 pdialog = (struct Diplomacy_dialog *)data;
733
734 switch (response) {
735 case GTK_RESPONSE_ACCEPT: /* Accept treaty. */
736 dsend_packet_diplomacy_accept_treaty_req(&client.conn,
737 player_number(
738 pdialog->treaty->plr1));
739 break;
740
741 default:
742 log_error("unhandled response in %s: %d", __FUNCTION__, response);
743 fc__fallthrough; /* No break. */
744 case GTK_RESPONSE_DELETE_EVENT: /* GTK: delete the widget. */
745 case GTK_RESPONSE_CANCEL: /* GTK: cancel button. */
746 case RESPONSE_CANCEL_MEETING: /* Cancel meetings. */
747 dsend_packet_diplomacy_cancel_meeting_req(&client.conn,
748 player_number(
749 pdialog->treaty->plr1));
750 break;
751 }
752}
753
754/************************************************************************/
757 static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty,
758 struct player *plr0,
759 struct player *plr1)
760{
761 struct Diplomacy_notebook *dipl_dialog;
762 GtkWidget *vbox, *hgrid, *table, *mainbox;
763 GtkWidget *label, *sw, *view, *pic, *spin;
764 GtkWidget *aux_menu, *notebook;
765 struct sprite *flag_spr;
766 GtkListStore *store;
767 GtkCellRenderer *rend;
768 int i;
769 struct Diplomacy_dialog *pdialog;
770 char plr_buf[4 * MAX_LEN_NAME];
771 gchar *buf;
772 int grid_col = 0;
773 int main_row = 0;
774 GActionGroup *group;
775 GMenu *menu;
776
777 pdialog = fc_malloc(sizeof(*pdialog));
778
779 dialog_list_prepend(dialog_list, pdialog);
780 pdialog->treaty = ptreaty;
781
782 /* Get main diplomacy tab. */
783 dipl_dialog = diplomacy_main_create();
784
785 buf = g_strdup_printf(_("Diplomacy [%d]"), dialog_list_size(dialog_list));
786 gui_dialog_set_title(dipl_dialog->dialog, buf);
787 g_free(buf);
788
789 notebook = dipl_dialog->notebook;
790
791 gui_dialog_new(&(pdialog->dialog), GTK_NOTEBOOK(notebook), pdialog, FALSE);
792
793 /* Buttons */
794 gui_dialog_add_button(pdialog->dialog, NULL,
795 _("Accept treaty"), GTK_RESPONSE_ACCEPT);
796 gui_dialog_add_button(pdialog->dialog, NULL,
797 _("Cancel meeting"), RESPONSE_CANCEL_MEETING);
798
799 /* Responses for one meeting. */
800 gui_dialog_response_set_callback(pdialog->dialog, diplomacy_response);
801
802 /* Label for the new meeting. */
803 buf = g_strdup_printf("%s", nation_plural_for_player(plr1));
804 gui_dialog_set_title(pdialog->dialog, buf);
805
806 /* Sort meeting tabs alphabetically by the tab label. */
807 for (i = 0; i < gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook)); i++) {
808 GtkWidget *prev_page
809 = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), i);
810 struct gui_dialog *prev_dialog
811 = g_object_get_data(G_OBJECT(prev_page), "gui-dialog-data");
812 const char *prev_label
813 = gtk_label_get_text(GTK_LABEL(prev_dialog->v.tab.label));
814
815 if (fc_strcasecmp(buf, prev_label) < 0) {
816 gtk_notebook_reorder_child(GTK_NOTEBOOK(notebook),
817 pdialog->dialog->grid, i);
818 break;
819 }
820 }
821 g_free(buf);
822
823 /* Us. */
824 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
825 gtk_widget_set_margin_start(vbox, 2);
826 gtk_widget_set_margin_end(vbox, 2);
827 gtk_widget_set_margin_top(vbox, 2);
828 gtk_widget_set_margin_bottom(vbox, 2);
829 gui_dialog_add_content_widget(pdialog->dialog, vbox);
830
831 /* Our nation. */
832 label = gtk_label_new(NULL);
833 gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
834 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
835 buf = g_strdup_printf("<span size=\"large\"><u>%s</u></span>",
836 nation_plural_for_player(plr0));
837 gtk_label_set_markup(GTK_LABEL(label), buf);
838 g_free(buf);
839 gtk_box_append(GTK_BOX(vbox), label);
840
841 hgrid = gtk_grid_new();
842 gtk_grid_set_column_spacing(GTK_GRID(hgrid), 5);
843 gtk_box_append(GTK_BOX(vbox), hgrid);
844
845 /* Our flag */
846 flag_spr = get_nation_flag_sprite(tileset, nation_of_player(plr0));
847
848 pic = gtk_picture_new();
849 picture_set_from_surface(GTK_PICTURE(pic), flag_spr->surface);
850 gtk_grid_attach(GTK_GRID(hgrid), pic, grid_col++, 0, 1, 1);
851
852 /* Our name. */
853 label = gtk_label_new(NULL);
854 gtk_widget_set_hexpand(label, TRUE);
855 gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
856 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
857 buf = g_strdup_printf("<span size=\"large\" weight=\"bold\">%s</span>",
858 ruler_title_for_player(plr0, plr_buf, sizeof(plr_buf)));
859 gtk_label_set_markup(GTK_LABEL(label), buf);
860 g_free(buf);
861 gtk_grid_attach(GTK_GRID(hgrid), label, grid_col++, 0, 1, 1);
862
863 pdialog->pic0 = gtk_picture_new();
864 gtk_grid_attach(GTK_GRID(hgrid), pdialog->pic0, grid_col++, 0, 1, 1);
865
866 /* Menu for clauses: we. */
867 aux_menu = aux_menu_new();
868 group = G_ACTION_GROUP(g_simple_action_group_new());
869
870 menu = create_clause_menu(group, pdialog, plr1, FALSE);
871 gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(aux_menu), G_MENU_MODEL(menu));
872
873 /* Main table for clauses and (if activated) gold trading: we. */
874 table = gtk_grid_new();
875 gtk_widget_set_halign(table, GTK_ALIGN_CENTER);
876 gtk_widget_set_valign(table, GTK_ALIGN_CENTER);
877 gtk_grid_set_column_spacing(GTK_GRID(table), 16);
878 gtk_box_append(GTK_BOX(vbox), table);
879
880 if (clause_enabled(CLAUSE_GOLD)) {
881 spin = gtk_spin_button_new_with_range(0.0, plr0->economic.gold + 0.1,
882 1.0);
883 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), 0);
884 gtk_editable_set_width_chars(GTK_EDITABLE(spin), 16);
885 gtk_grid_attach(GTK_GRID(table), spin, 1, 0, 1, 1);
886 g_object_set_data(G_OBJECT(spin), "plr", plr0);
887 g_signal_connect_after(spin, "value-changed",
888 G_CALLBACK(diplo_dialog_returnkey), pdialog);
889
890 label = g_object_new(GTK_TYPE_LABEL, "use-underline", TRUE,
891 "mnemonic-widget", spin, "label", _("Gold:"),
892 "xalign", 0.0, "yalign", 0.5, NULL);
893 gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
894
895 gtk_grid_attach(GTK_GRID(table), aux_menu, 2, 0, 1, 1);
896 } else {
897 gtk_grid_attach(GTK_GRID(table), aux_menu, 0, 0, 1, 1);
898 }
899 gtk_widget_insert_action_group(aux_menu, "win", group);
900
901 /* Them. */
902 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
903 gtk_widget_set_margin_start(vbox, 2);
904 gtk_widget_set_margin_end(vbox, 2);
905 gtk_widget_set_margin_top(vbox, 2);
906 gtk_widget_set_margin_bottom(vbox, 2);
907 gui_dialog_add_content_widget(pdialog->dialog, vbox);
908
909 /* Their nation. */
910 label = gtk_label_new(NULL);
911 gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
912 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
913 buf = g_strdup_printf("<span size=\"large\"><u>%s</u></span>",
914 nation_plural_for_player(plr1));
915 gtk_label_set_markup(GTK_LABEL(label), buf);
916 g_free(buf);
917 gtk_box_append(GTK_BOX(vbox), label);
918
919 hgrid = gtk_grid_new();
920 grid_col = 0;
921 gtk_grid_set_column_spacing(GTK_GRID(hgrid), 5);
922 gtk_box_append(GTK_BOX(vbox), hgrid);
923
924 /* Their flag */
925 flag_spr = get_nation_flag_sprite(tileset, nation_of_player(plr1));
926
927 pic = gtk_picture_new();
928 picture_set_from_surface(GTK_PICTURE(pic), flag_spr->surface);
929 gtk_grid_attach(GTK_GRID(hgrid), pic, grid_col++, 0, 1, 1);
930
931 /* Their name. */
932 label = gtk_label_new(NULL);
933 gtk_widget_set_hexpand(label, TRUE);
934 gtk_widget_set_halign(label, GTK_ALIGN_CENTER);
935 gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
936 buf = g_strdup_printf("<span size=\"large\" weight=\"bold\">%s</span>",
937 ruler_title_for_player(plr1, plr_buf, sizeof(plr_buf)));
938 gtk_label_set_markup(GTK_LABEL(label), buf);
939 g_free(buf);
940 gtk_grid_attach(GTK_GRID(hgrid), label, grid_col++, 0, 1, 1);
941
942 pdialog->pic1 = gtk_picture_new();
943 gtk_grid_attach(GTK_GRID(hgrid), pdialog->pic1, grid_col++, 0, 1, 1);
944
945 /* Menu for clauses: they. */
946 aux_menu = aux_menu_new();
947 group = G_ACTION_GROUP(g_simple_action_group_new());
948
949 menu = create_clause_menu(group, pdialog, plr1, TRUE);
950 gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(aux_menu), G_MENU_MODEL(menu));
951
952 /* Main table for clauses and (if activated) gold trading: they. */
953 table = gtk_grid_new();
954 gtk_widget_set_halign(table, GTK_ALIGN_CENTER);
955 gtk_widget_set_valign(table, GTK_ALIGN_CENTER);
956 gtk_grid_set_column_spacing(GTK_GRID(table), 16);
957 gtk_box_append(GTK_BOX(vbox), table);
958
959 if (clause_enabled(CLAUSE_GOLD)) {
960 spin = gtk_spin_button_new_with_range(0.0, plr1->economic.gold + 0.1,
961 1.0);
962 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), 0);
963 gtk_editable_set_width_chars(GTK_EDITABLE(spin), 16);
964 gtk_grid_attach(GTK_GRID(table), spin, 1, 0, 1, 1);
965 g_object_set_data(G_OBJECT(spin), "plr", plr1);
966 g_signal_connect_after(spin, "value-changed",
967 G_CALLBACK(diplo_dialog_returnkey), pdialog);
968
969 label = g_object_new(GTK_TYPE_LABEL, "use-underline", TRUE,
970 "mnemonic-widget", spin, "label", _("Gold:"),
971 "xalign", 0.0, "yalign", 0.5, NULL);
972 gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
973
974 gtk_grid_attach(GTK_GRID(table), aux_menu, 2, 0, 1, 1);
975 } else {
976 gtk_grid_attach(GTK_GRID(table), aux_menu, 0, 0, 1, 1);
977 }
978 gtk_widget_insert_action_group(aux_menu, "win", group);
979
980 /* Clauses. */
981 mainbox = gtk_grid_new();
982 gtk_orientable_set_orientation(GTK_ORIENTABLE(mainbox),
983 GTK_ORIENTATION_VERTICAL);
984 gui_dialog_add_content_widget(pdialog->dialog, mainbox);
985
986 store = gtk_list_store_new(1, G_TYPE_STRING);
987 pdialog->store = store;
988
989 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
990 gtk_widget_set_hexpand(view, TRUE);
991 gtk_widget_set_vexpand(view, TRUE);
992 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
993 g_object_unref(store);
994 gtk_widget_set_size_request(view, 320, 100);
995
996 rend = gtk_cell_renderer_text_new();
997 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, NULL,
998 rend, "text", 0, NULL);
999
1000 sw = gtk_scrolled_window_new();
1001 gtk_widget_set_margin_bottom(sw, 2);
1002 gtk_widget_set_margin_end(sw, 2);
1003 gtk_widget_set_margin_start(sw, 2);
1004 gtk_widget_set_margin_top(sw, 2);
1005 gtk_scrolled_window_set_has_frame(GTK_SCROLLED_WINDOW(sw), TRUE);
1006 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
1007 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1008 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), view);
1009
1010 label = g_object_new(GTK_TYPE_LABEL,
1011 "use-underline", TRUE,
1012 "mnemonic-widget", view,
1013 "label", _("C_lauses:"),
1014 "xalign", 0.0,
1015 "yalign", 0.5,
1016 NULL);
1017
1018 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
1019
1020 gtk_grid_attach(GTK_GRID(mainbox), vbox, 0, main_row++, 1, 1);
1021 gtk_box_append(GTK_BOX(vbox), label);
1022 gtk_box_append(GTK_BOX(vbox), sw);
1023
1024 gtk_widget_set_visible(mainbox, TRUE);
1025
1026 g_signal_connect(view, "row_activated", G_CALLBACK(row_callback), pdialog);
1027
1028 update_diplomacy_dialog(pdialog);
1029 gui_dialog_show_all(pdialog->dialog);
1030
1031 return pdialog;
1032}
1033
1034/************************************************************************/
1037 static void update_diplomacy_dialog(struct Diplomacy_dialog *pdialog)
1038{
1039 GtkListStore *store;
1040 GtkTreeIter it;
1041 bool blank = TRUE;
1042 GdkPixbuf *pixbuf;
1043
1044 store = pdialog->store;
1045
1046 gtk_list_store_clear(store);
1047 clause_list_iterate(pdialog->treaty->clauses, pclause) {
1048 char buf[128];
1049
1050 client_diplomacy_clause_string(buf, sizeof(buf), pclause);
1051
1052 gtk_list_store_append(store, &it);
1053 gtk_list_store_set(store, &it, 0, buf, -1);
1054 blank = FALSE;
1055 } clause_list_iterate_end;
1056
1057 if (blank) {
1058 gtk_list_store_append(store, &it);
1059 gtk_list_store_set(store, &it, 0,
1060 _("--- This treaty is blank. "
1061 "Please add some clauses. ---"), -1);
1062 }
1063
1064 pixbuf = get_thumb_pixbuf(pdialog->treaty->accept0);
1065 gtk_picture_set_pixbuf(GTK_PICTURE(pdialog->pic0), pixbuf);
1066 g_object_unref(G_OBJECT(pixbuf));
1067 pixbuf = get_thumb_pixbuf(pdialog->treaty->accept1);
1068 gtk_picture_set_pixbuf(GTK_PICTURE(pdialog->pic1), pixbuf);
1069 g_object_unref(G_OBJECT(pixbuf));
1070}
1071
1072/************************************************************************/
1075 static void diplomacy_dialog_tech_callback(GSimpleAction *action,
1076 GVariant *parameter,
1077 gpointer data)
1078{
1079 int giver, dest, other, tech;
1080
1081 giver = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "player_from"));
1082 dest = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), "player_to"));
1083 tech = GPOINTER_TO_INT(data);
1084 if (player_by_number(giver) == client_player()) {
1085 other = dest;
1086 } else {
1087 other = giver;
1088 }
1089
1090 if (A_LAST == tech) {
1091 /* All techs. */
1092 struct player *pgiver = player_by_number(giver);
1093 struct player *pdest = player_by_number(dest);
1094 const struct research *dresearch, *gresearch;
1095
1096 fc_assert_ret(NULL != pgiver);
1097 fc_assert_ret(NULL != pdest);
1098
1099 dresearch = research_get(pdest);
1100 gresearch = research_get(pgiver);
1101 advance_iterate(padvance) {
1102 Tech_type_id i = advance_number(padvance);
1103
1104 if (research_invention_state(gresearch, i) == TECH_KNOWN
1105 && research_invention_gettable(dresearch, i,
1106 game.info.tech_trade_allow_holes)
1107 && (research_invention_state(dresearch, i) == TECH_UNKNOWN
1108 || research_invention_state(dresearch, i)
1109 == TECH_PREREQS_KNOWN)) {
1110 dsend_packet_diplomacy_create_clause_req(&client.conn, other, giver,
1111 CLAUSE_ADVANCE, i);
1112 }
1113 } advance_iterate_end;
1114 } else {
1115 /* Only one tech. */
1116 dsend_packet_diplomacy_create_clause_req(&client.conn, other, giver,
1117 CLAUSE_ADVANCE, tech);
1118 }
1119}
1120
1121/************************************************************************/
1125 static void diplomacy_dialog_city_callback(GSimpleAction *action,
1126 GVariant *parameter,
1127 gpointer data)
1128{
1129 struct city_deal *deal_data = (struct city_deal *)data;
1130 int other;
1131
1132 if (player_by_number(deal_data->giver) == client.conn.playing) {
1133 other = deal_data->receiver;
1134 } else {
1135 other = deal_data->giver;
1136 }
1137
1138 dsend_packet_diplomacy_create_clause_req(&client.conn, other, deal_data->giver,
1139 CLAUSE_CITY, deal_data->id);
1140
1141 free(deal_data);
1142}
1143
1144/************************************************************************/
1147 static void diplomacy_dialog_map_callback(GSimpleAction *action, GVariant *parameter,
1148 gpointer data)
1149{
1150 struct Diplomacy_dialog *pdialog = (struct Diplomacy_dialog *)data;
1151 struct player *pgiver;
1152
1153 pgiver = (struct player *)g_object_get_data(G_OBJECT(action), "plr");
1154
1155 dsend_packet_diplomacy_create_clause_req(&client.conn,
1156 player_number(pdialog->treaty->plr1),
1157 player_number(pgiver), CLAUSE_MAP, 0);
1158}
1159
1160/************************************************************************/
1163 static void diplomacy_dialog_seamap_callback(GSimpleAction *action, GVariant *parameter,
1164 gpointer data)
1165{
1166 struct Diplomacy_dialog *pdialog = (struct Diplomacy_dialog *)data;
1167 struct player *pgiver;
1168
1169 pgiver = (struct player *)g_object_get_data(G_OBJECT(action), "plr");
1170
1171 dsend_packet_diplomacy_create_clause_req(&client.conn,
1172 player_number(pdialog->treaty->plr1),
1173 player_number(pgiver), CLAUSE_SEAMAP,
1174 0);
1175}
1176
1177/************************************************************************/
1180 static void diplomacy_dialog_add_pact_clause(gpointer data, int type)
1181{
1182 struct Diplomacy_dialog *pdialog = (struct Diplomacy_dialog *)data;
1183
1184 dsend_packet_diplomacy_create_clause_req(&client.conn,
1185 player_number(pdialog->treaty->plr1),
1186 player_number(pdialog->treaty->plr0),
1187 type, 0);
1188}
1189
1190/************************************************************************/
1193 static void diplomacy_dialog_ceasefire_callback(GSimpleAction *action,
1194 GVariant *parameter,
1195 gpointer data)
1196{
1197 diplomacy_dialog_add_pact_clause(data, CLAUSE_CEASEFIRE);
1198}
1199
1200/************************************************************************/
1203 static void diplomacy_dialog_peace_callback(GSimpleAction *action,
1204 GVariant *parameter,
1205 gpointer data)
1206{
1207 diplomacy_dialog_add_pact_clause(data, CLAUSE_PEACE);
1208}
1209
1210/************************************************************************/
1213 static void diplomacy_dialog_alliance_callback(GSimpleAction *action,
1214 GVariant *parameter,
1215 gpointer data)
1216{
1217 diplomacy_dialog_add_pact_clause(data, CLAUSE_ALLIANCE);
1218}
1219
1220/************************************************************************/
1223 static void diplomacy_dialog_vision_callback(GSimpleAction *action,
1224 GVariant *parameter,
1225 gpointer data)
1226{
1227 struct Diplomacy_dialog *pdialog = (struct Diplomacy_dialog *) data;
1228 struct player *pgiver;
1229
1230 pgiver = (struct player *)g_object_get_data(G_OBJECT(action), "plr");
1231
1232 dsend_packet_diplomacy_create_clause_req(&client.conn,
1233 player_number(pdialog->treaty->plr1),
1234 player_number(pgiver), CLAUSE_VISION,
1235 0);
1236}
1237
1238/************************************************************************/
1241 static void diplomacy_dialog_embassy_callback(GSimpleAction *action,
1242 GVariant *parameter,
1243 gpointer data)
1244{
1245 struct Diplomacy_dialog *pdialog = (struct Diplomacy_dialog *) data;
1246 struct player *pgiver;
1247
1248 pgiver = (struct player *)g_object_get_data(G_OBJECT(action), "plr");
1249
1250 dsend_packet_diplomacy_create_clause_req(&client.conn,
1251 player_number(pdialog->treaty->plr1),
1252 player_number(pgiver), CLAUSE_EMBASSY,
1253 0);
1254}
1255
1256/************************************************************************/
1259 static void diplomacy_dialog_shared_tiles_callback(GSimpleAction *action,
1260 GVariant *parameter,
1261 gpointer data)
1262{
1263 struct Diplomacy_dialog *pdialog = (struct Diplomacy_dialog *) data;
1264 struct player *pgiver;
1265
1266 pgiver = (struct player *)g_object_get_data(G_OBJECT(action), "plr");
1267
1268 dsend_packet_diplomacy_create_clause_req(&client.conn,
1269 player_number(pdialog->treaty->plr1),
1270 player_number(pgiver),
1271 CLAUSE_SHARED_TILES,
1272 0);
1273}
1274
1275/************************************************************************/
1278 void close_diplomacy_dialog(struct Diplomacy_dialog *pdialog)
1279{
1280 diplomacy_destroy(pdialog);
1281}
1282
1283/************************************************************************/
1286 void diplomacy_dialog_init(void)
1287{
1288 dialog_list = dialog_list_new();
1289 dipl_main = NULL;
1290}
1291
1292/************************************************************************/
1295 void diplomacy_dialog_done(void)
1296{
1297 dialog_list_destroy(dialog_list);
1298}
1299
1300/************************************************************************/
1303 static struct Diplomacy_dialog *find_diplomacy_dialog(struct player *they)
1304{
1305 struct player *plr0 = client.conn.playing;
1306
1307 dialog_list_iterate(dialog_list, pdialog) {
1308 if ((pdialog->treaty->plr0 == plr0 && pdialog->treaty->plr1 == they)
1309 || (pdialog->treaty->plr0 == they && pdialog->treaty->plr1 == plr0)) {
1310 return pdialog;
1311 }
1312 } dialog_list_iterate_end;
1313
1314 return NULL;
1315}
1316
1317/************************************************************************/
1320 static void diplo_dialog_returnkey(GtkWidget *w, gpointer data)
1321{
1322 struct Diplomacy_dialog *pdialog = (struct Diplomacy_dialog *) data;
1323 struct player *pgiver =
1324 (struct player *) g_object_get_data(G_OBJECT(w), "plr");
1325 int amount = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(w));
1326
1327 if (amount >= 0 && amount <= pgiver-> economic.gold) {
1328 dsend_packet_diplomacy_create_clause_req(&client.conn,
1329 player_number(pdialog->treaty->plr1),
1330 player_number(pgiver),
1331 CLAUSE_GOLD, amount);
1332 } else {
1333 output_window_append(ftc_client, _("Invalid amount of gold specified."));
1334 }
1335}
1336
1337/************************************************************************/
1340 void close_all_diplomacy_dialogs(void)
1341{
1342 while (dialog_list_size(dialog_list) > 0) {
1343 close_diplomacy_dialog(dialog_list_get(dialog_list, 0));
1344 }
1345}
n
#define n
Definition astring.c:77
output_window_append
void output_window_append(const struct ft_color color, const char *featured_text)
Definition chatline_common.c:104
is_capital
bool is_capital(const struct city *pcity)
Definition city.c:1575
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1133
city_name_compare
int city_name_compare(const void *p1, const void *p2)
Definition city.c:1707
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:508
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:510
client
struct civclient client
Definition client_main.c:153
client_main.h
client_player
#define client_player()
Definition client_main.h:106
client_diplomacy_clause_string
void client_diplomacy_clause_string(char *buf, int bufsiz, struct Clause *pclause)
Definition climisc.c:241
climisc.h
incite_cost
char * incite_cost
Definition comments.c:74
gui_recv_create_clause
struct Treaty struct player struct player *initiator gui_recv_create_clause
Definition diplodlg_g.h:32
ptreaty
struct Treaty * ptreaty
Definition diplodlg_g.h:28
gui_recv_accept_treaty
struct Treaty struct player struct player *initiator struct Treaty struct player *they gui_recv_accept_treaty
Definition diplodlg_g.h:36
they
struct Treaty struct player * they
Definition diplodlg_g.h:28
gui_recv_cancel_meeting
gui_recv_cancel_meeting
Definition diplodlg_g.h:27
clause_enabled
bool clause_enabled(enum clause_type type)
Definition diptreaty.c:305
diptreaty.h
clause_list_iterate_end
#define clause_list_iterate_end
Definition diptreaty.h:71
clause_list_iterate
#define clause_list_iterate(clauselist, pclause)
Definition diptreaty.h:69
Tech_type_id
int Tech_type_id
Definition fc_types.h:381
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
fcintl.h
Q_
#define Q_(String)
Definition fcintl.h:70
_
#define _(String)
Definition fcintl.h:67
ftc_client
const struct ft_color ftc_client
Definition featured_text.c:78
game
struct civ_game game
Definition game.c:61
game.h
ruler_title_for_player
const char * ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
Definition government.c:391
government.h
diplomacy_dialog_add_pact_clause
static void diplomacy_dialog_add_pact_clause(GtkWidget *w, gpointer data, int type)
Definition diplodlg.c:1111
RESPONSE_CANCEL_MEETING
#define RESPONSE_CANCEL_MEETING
Definition diplodlg.c:114
sort_advance_names
static gint sort_advance_names(gconstpointer a, gconstpointer b)
Definition diplodlg.c:236
close_diplomacy_dialog
static void close_diplomacy_dialog(struct Diplomacy_dialog *pdialog)
Definition diplodlg.c:1196
diplomacy_dialog_tech_callback
static void diplomacy_dialog_tech_callback(GtkWidget *w, gpointer data)
Definition diplodlg.c:1012
row_callback
static void row_callback(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
Definition diplodlg.c:515
diplomacy_dialog_ceasefire_callback
static void diplomacy_dialog_ceasefire_callback(GtkWidget *w, gpointer data)
Definition diplodlg.c:1125
update_diplomacy_dialog
static void update_diplomacy_dialog(struct Diplomacy_dialog *pdialog)
Definition diplodlg.c:974
create_diplomacy_dialog
static struct Diplomacy_dialog * create_diplomacy_dialog(struct Treaty *ptreaty, struct player *plr0, struct player *plr1)
Definition diplodlg.c:687
gui_init_meeting
void gui_init_meeting(struct Treaty *ptreaty, struct player *they, struct player *initiator)
Definition diplodlg.c:137
diplomacy_dialog_seamap_callback
static void diplomacy_dialog_seamap_callback(GtkWidget *w, gpointer data)
Definition diplodlg.c:1095
diplomacy_dialog_city_callback
static void diplomacy_dialog_city_callback(GtkWidget *w, gpointer data)
Definition diplodlg.c:1060
diplomacy_dialog_map_callback
static void diplomacy_dialog_map_callback(GtkWidget *w, gpointer data)
Definition diplodlg.c:1080
diplomacy_dialog_init
void diplomacy_dialog_init(void)
Definition diplodlg.c:1204
diplomacy_destroy
static void diplomacy_destroy(struct Diplomacy_dialog *pdialog)
Definition diplodlg.c:625
dialog_list_iterate_end
#define dialog_list_iterate_end
Definition diplodlg.c:83
diplomacy_main_create
static struct Diplomacy_notebook * diplomacy_main_create(void)
Definition diplodlg.c:541
find_diplomacy_dialog
static struct Diplomacy_dialog * find_diplomacy_dialog(struct player *they)
Definition diplodlg.c:1221
diplomacy_dialog_vision_callback
static void diplomacy_dialog_vision_callback(GtkWidget *w, gpointer data)
Definition diplodlg.c:1149
close_all_diplomacy_dialogs
void close_all_diplomacy_dialogs(void)
Definition diplodlg.c:1258
RESPONSE_CANCEL_MEETING_ALL
#define RESPONSE_CANCEL_MEETING_ALL
Definition diplodlg.c:115
diplomacy_dialog_embassy_callback
static void diplomacy_dialog_embassy_callback(GtkWidget *w, gpointer data)
Definition diplodlg.c:1164
diplomacy_dialog_shared_tiles_callback
static void diplomacy_dialog_shared_tiles_callback(GtkWidget *w, gpointer data)
Definition diplodlg.c:1179
diplomacy_response
static void diplomacy_response(struct gui_dialog *dlg, int response, gpointer data)
Definition diplodlg.c:656
gui_recv_remove_clause
void gui_recv_remove_clause(struct Treaty *ptreaty, struct player *they)
Definition diplodlg.c:188
dialog_list_iterate
#define dialog_list_iterate(dialoglist, pdialog)
Definition diplodlg.c:81
dialog_list
static struct dialog_list * dialog_list
Definition diplodlg.c:85
diplomacy_main_response
static void diplomacy_main_response(struct gui_dialog *dlg, int response, gpointer data)
Definition diplodlg.c:598
diplomacy_dialog_peace_callback
static void diplomacy_dialog_peace_callback(GtkWidget *w, gpointer data)
Definition diplodlg.c:1133
diplomacy_dialog_done
void diplomacy_dialog_done(void)
Definition diplodlg.c:1213
diplo_dialog_returnkey
static void diplo_dialog_returnkey(GtkWidget *w, gpointer data)
Definition diplodlg.c:1238
popup_diplomacy_dialog
static void popup_diplomacy_dialog(struct Treaty *ptreaty, struct player *they, struct player *initiator)
Definition diplodlg.c:205
diplomacy_main_destroy
static void diplomacy_main_destroy(void)
Definition diplodlg.c:586
gui_prepare_clause_updt
void gui_prepare_clause_updt(struct Treaty *ptreaty, struct player *they)
Definition diplodlg.c:163
diplomacy_dialog_alliance_callback
static void diplomacy_dialog_alliance_callback(GtkWidget *w, gpointer data)
Definition diplodlg.c:1141
dipl_main
static struct Diplomacy_notebook * dipl_main
Definition diplodlg.c:86
top_notebook
GtkWidget * top_notebook
Definition gui_main.c:129
gui_dialog_destroy
void gui_dialog_destroy(struct gui_dialog *dlg)
Definition gui_stuff.c:954
gui_dialog_present
void gui_dialog_present(struct gui_dialog *dlg)
Definition gui_stuff.c:835
gui_dialog_raise
void gui_dialog_raise(struct gui_dialog *dlg)
Definition gui_stuff.c:865
gui_dialog_new
void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook, gpointer user_data, bool check_top)
Definition gui_stuff.c:517
gui_dialog_set_return_dialog
void gui_dialog_set_return_dialog(struct gui_dialog *dlg, struct gui_dialog *return_dialog)
Definition gui_stuff.c:997
gui_dialog_response_set_callback
void gui_dialog_response_set_callback(struct gui_dialog *dlg, GUI_DIALOG_RESPONSE_FUN fun)
Definition gui_stuff.c:988
gui_dialog_show_all
void gui_dialog_show_all(struct gui_dialog *dlg)
Definition gui_stuff.c:795
gui_dialog_set_title
void gui_dialog_set_title(struct gui_dialog *dlg, const char *title)
Definition gui_stuff.c:935
gui_dialog_alert
void gui_dialog_alert(struct gui_dialog *dlg)
Definition gui_stuff.c:888
gui_dialog_add_button
GtkWidget * gui_dialog_add_button(struct gui_dialog *dlg, const char *icon_name, const char *text, int response)
Definition gui_stuff.c:706
get_thumb_pixbuf
GdkPixbuf * get_thumb_pixbuf(int onoff)
Definition mapview.c:292
players_dialog_shell
struct gui_dialog * players_dialog_shell
Definition plrdlg.c:58
type
GType type
Definition repodlgs.c:1313
create_clause_menu
static GMenu * create_clause_menu(GActionGroup *group, struct Diplomacy_dialog *pdialog, struct player *partner, bool them)
Definition diplodlg.c:267
aux_menu_new
GtkWidget * aux_menu_new(void)
Definition gui_stuff.c:244
gui_dialog_add_content_widget
void gui_dialog_add_content_widget(struct gui_dialog *dlg, GtkWidget *wdg)
Definition gui_stuff.c:1105
submenu_append_unref
#define submenu_append_unref(menu, name, submenu)
Definition gui_stuff.h:165
menu_item_append_unref
#define menu_item_append_unref(menu, item)
Definition gui_stuff.h:149
picture_set_from_surface
void picture_set_from_surface(GtkPicture *pic, cairo_surface_t *surf)
Definition sprite.c:544
gui_stuff.h
chatline.h
diplodlg.h
gui_main.h
mapview.h
plrdlg.h
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
fc_assert
#define fc_assert(condition)
Definition log.h:176
log_error
#define log_error(message,...)
Definition log.h:103
map.h
mem.h
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
nation_of_player
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
nation_plural_for_player
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
nation.h
options.h
packets.h
dsend_packet_diplomacy_create_clause_req
int dsend_packet_diplomacy_create_clause_req(struct connection *pc, int counterpart, int giver, enum clause_type type, int value)
Definition packets_gen.c:40720
dsend_packet_diplomacy_cancel_meeting_req
int dsend_packet_diplomacy_cancel_meeting_req(struct connection *pc, int counterpart)
Definition packets_gen.c:40100
dsend_packet_diplomacy_remove_clause_req
int dsend_packet_diplomacy_remove_clause_req(struct connection *pc, int counterpart, int giver, enum clause_type type, int value)
Definition packets_gen.c:41459
dsend_packet_diplomacy_accept_treaty_req
int dsend_packet_diplomacy_accept_treaty_req(struct connection *pc, int counterpart)
Definition packets_gen.c:42035
player_by_number
struct player * player_by_number(const int player_id)
Definition player.c:849
player_number
int player_number(const struct player *pplayer)
Definition player.c:837
player_has_real_embassy
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:240
team_has_embassy
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:220
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
gives_shared_vision
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1489
player.h
is_human
#define is_human(plr)
Definition player.h:231
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
research_invention_gettable
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:693
research.h
shared.h
speclist.h
Diplomacy_dialog
Definition diplodlg.c:53
Diplomacy_dialog::pic1
GtkWidget * pic1
Definition diplodlg.c:58
Diplomacy_dialog::pic0
GtkWidget * pic0
Definition diplodlg.c:57
Diplomacy_dialog::treaty
struct Treaty * treaty
Definition diplodlg.c:54
Diplomacy_dialog::dialog
struct gui_dialog * dialog
Definition diplodlg.c:55
Diplomacy_dialog::store
GtkListStore * store
Definition diplodlg.c:63
Diplomacy_notebook
Definition diplodlg.c:66
Diplomacy_notebook::dialog
struct gui_dialog * dialog
Definition diplodlg.c:67
Diplomacy_notebook::notebook
GtkWidget * notebook
Definition diplodlg.c:68
Treaty
Definition diptreaty.h:79
Treaty::plr0
struct player * plr0
Definition diptreaty.h:80
Treaty::accept0
bool accept0
Definition diptreaty.h:81
Treaty::accept1
bool accept1
Definition diptreaty.h:81
Treaty::clauses
struct clause_list * clauses
Definition diptreaty.h:82
Treaty::plr1
struct player * plr1
Definition diptreaty.h:80
action
Definition actions.h:106
advance
Definition tech.h:124
city_deal
Definition diplodlg.c:71
city_deal::giver
int giver
Definition diplodlg.c:72
city_deal::receiver
int receiver
Definition diplodlg.c:73
city_deal::id
int id
Definition diplodlg.c:74
city
Definition city.h:320
civ_game::info
struct packet_game_info info
Definition game.h:89
civclient::conn
struct connection conn
Definition client_main.h:96
connection::playing
struct player * playing
Definition connection.h:151
connection::id
int id
Definition connection.h:137
gui_dialog
Definition gui_stuff.h:70
gui_dialog::vbox
GtkWidget * vbox
Definition gui_stuff.h:72
gui_dialog::grid
GtkWidget * grid
Definition gui_stuff.h:71
gui_dialog::label
GtkWidget * label
Definition gui_stuff.h:87
gui_dialog::notebook
GtkWidget * notebook
Definition gui_stuff.h:88
packet_game_info::tech_trade_allow_holes
bool tech_trade_allow_holes
Definition packets_gen.h:216
player_diplstate::type
enum diplstate_type type
Definition player.h:199
player_economic::gold
int gold
Definition player.h:63
player
Definition player.h:249
player::economic
struct player_economic economic
Definition player.h:284
research
Definition research.h:39
sprite
Definition sprite.h:22
tileset
Definition tilespec.c:482
view
Definition mapview_common.h:36
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
fc_strlcpy
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
fc_strcoll
int fc_strcoll(const char *str0, const char *str1)
Definition support.c:471
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
fc__fallthrough
#define fc__fallthrough
Definition support.h:119
advance_name_translation
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:300
advance_number
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
advance_iterate
#define advance_iterate(_p)
Definition tech.h:276
advance_iterate_end
#define advance_iterate_end
Definition tech.h:277
A_LAST
#define A_LAST
Definition tech.h:45
get_nation_flag_sprite
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6795