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

Freeciv-3.1

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