Freeciv-3.1
Loading...
Searching...
No Matches
diplodlg.cpp
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// Qt
19#include <QApplication>
20#include <QCloseEvent>
21#include <QGridLayout>
22#include <QHeaderView>
23#include <QLabel>
24#include <QMenu>
25#include <QSpinBox>
26#include <QPainter>
27#include <QPushButton>
28
29// common
30#include "government.h"
31#include "player.h"
32
33// client
34#include "client_main.h"
35
36// gui-qt
37#include "colors.h"
38#include "diplodlg.h"
39#include "fc_client.h"
40#include "gui_main.h"
41#include "sidebar.h"
42
43extern "C" {
44 int client_player_number(void);
45 struct player *player_by_number(const int player_id);
46}
47
49typedef city *p_city;
50
51/************************************************************************/
54diplo_wdg::diplo_wdg(int counterpart, int initiated_from): QWidget()
55{
56 color *colr;
57 QString text;
58 QString text2;
59 QString text_tooltip;
60 QLabel *plr1_label;
61 QLabel *plr2_label;
62 QLabel *label;
63 QLabel *label2;
64 QLabel *label3;
65 QLabel *label4;
66 QPushButton *add_clause1;
67 QPushButton *add_clause2;
68 QPixmap *pix = NULL;
69 QPalette palette;
70 struct sprite *sprite, *sprite2;
71 char plr_buf[4 * MAX_LEN_NAME];
72 const struct player_diplstate *state;
73 QHeaderView *header;
74 struct color *textcolors[2] = {
75 get_color(tileset, COLOR_MAPVIEW_CITYTEXT),
76 get_color(tileset, COLOR_MAPVIEW_CITYTEXT_DARK)
77 };
78 int clause_column;
79
80 if (counterpart == initiated_from) {
81 initiated_from = client_player_number();
82 }
83 p1_accept = false;
84 p2_accept = false;
85 player1 = initiated_from;
87 layout = new QGridLayout;
88
90 player_by_number(initiated_from));
93 text_tooltip = QString(diplstate_type_translated_name(state->type));
94 if (state->turns_left > 0) {
95 text_tooltip = text_tooltip + " (";
96 text_tooltip = text_tooltip + QString(PL_("%1 turn left",
97 "%1 turns left",
98 state->turns_left))
99 .arg(state->turns_left);
100 text_tooltip = text_tooltip + ")";
101 }
102 label3 = new QLabel;
103 text = "<b><h3><center>"
104 + QString(nation_plural_for_player(player_by_number(initiated_from)))
105 .toHtmlEscaped()
106 + "</center></h3></b>";
107 colr = get_player_color(tileset, player_by_number(initiated_from));
108 text = "<style>h3{background-color: "
109 + colr->qcolor.name() + ";" + "color: " + color_best_contrast(colr,
110 textcolors, ARRAY_SIZE(textcolors))->qcolor.name()
111 + "}</style>" + text;
112 label3->setText(text);
113 label3->setMinimumWidth(300);
114 label4 = new QLabel;
115 text = "<b><h3><center>"
117 .toHtmlEscaped()
118 + "</center></h3></b></body>";
120 text = "<style>h3{background-color: "
121 + colr->qcolor.name() + ";" + "color: " + color_best_contrast(colr,
122 textcolors, ARRAY_SIZE(textcolors))->qcolor.name()
123 + "}</style>" + text;
124 label4->setMinimumWidth(300);
125 label4->setText(text);
126 layout->addWidget(label3, 0, 5);
127 layout->addWidget(label4, 5, 5);
128 plr1_label = new QLabel;
129 label = new QLabel;
132 (initiated_from)));
133 if (sprite != NULL) {
134 pix = sprite->pm;
135 plr1_label->setPixmap(*pix);
136 } else {
137 plr1_label->setText("FLAG MISSING");
138 }
139 text = ruler_title_for_player(player_by_number(initiated_from),
140 plr_buf, sizeof(plr_buf));
141 text = "<b><center>" + text.toHtmlEscaped() + "</center></b>";
142 label->setText(text);
143 plr1_accept = new QLabel;
144 layout->addWidget(plr1_label, 1, 0);
145 layout->addWidget(label, 1, 5);
146 layout->addWidget(plr1_accept, 1, 10);
147 label2 = new QLabel;
150 (counterpart)));
151 plr2_label = new QLabel;
152 if (sprite2 != NULL) {
153 pix = sprite2->pm;
154 plr2_label->setPixmap(*pix);
155 } else {
156 plr2_label->setText("FLAG MISSING");
157 }
159 plr_buf, sizeof(plr_buf));
160 text2 = "<b><center>" + text2.toHtmlEscaped() + "</center></b>";
161 label2->setText(text2);
162 plr2_accept = new QLabel;
163 layout->addWidget(plr2_label, 6, 0);
164 layout->addWidget(label2, 6, 5);
165 layout->addWidget(plr2_accept, 6, 10);
166
167 if (clause_enabled(CLAUSE_GOLD)) {
168 QLabel *goldlab1;
169 QLabel *goldlab2;
170 QSpinBox *gold_edit1;
171 QSpinBox *gold_edit2;
172
173 goldlab1 = new QLabel(_("Gold:"));
174 goldlab1->setAlignment(Qt::AlignRight);
175 goldlab2 = new QLabel(_("Gold:"));
176 goldlab2->setAlignment(Qt::AlignRight);
177 gold_edit1 = new QSpinBox;
178 gold_edit2 = new QSpinBox;
179 gold_edit1->setMinimum(0);
180 gold_edit2->setMinimum(0);
181 gold_edit1->setFocusPolicy(Qt::ClickFocus);
182 gold_edit2->setFocusPolicy(Qt::ClickFocus);
183 gold_edit2->setMaximum(player_by_number(player1)->economic.gold);
184 gold_edit1->setMaximum(player_by_number(player2)->economic.gold);
185 connect(gold_edit1, SIGNAL(valueChanged(int)), SLOT(gold_changed1(int)));
186 connect(gold_edit2, SIGNAL(valueChanged(int)), SLOT(gold_changed2(int)));
187 layout->addWidget(goldlab1, 7, 4);
188 layout->addWidget(goldlab2, 3, 4);
189 layout->addWidget(gold_edit1, 7, 5);
190 layout->addWidget(gold_edit2, 3, 5);
191 clause_column = 6;
192 } else {
193 clause_column = 5;
194 }
195
196 add_clause1 = new QPushButton(style()->standardIcon(QStyle::SP_ArrowRight),
197 _("Add Clause..."));
198 add_clause2 = new QPushButton(style()->standardIcon(QStyle::SP_ArrowRight),
199 _("Add Clause..."));
200 add_clause1->setFocusPolicy(Qt::ClickFocus);
201 add_clause2->setFocusPolicy(Qt::ClickFocus);
202 connect(add_clause1, &QAbstractButton::clicked, this, &diplo_wdg::show_menu_p2);
203 connect(add_clause2, &QAbstractButton::clicked, this, &diplo_wdg::show_menu_p1);
204 layout->addWidget(add_clause1, 7, clause_column);
205 layout->addWidget(add_clause2, 3, clause_column);
206
207 text_edit = new QTableWidget();
208 text_edit->setColumnCount(1);
209 text_edit->setProperty("showGrid", "false");
210 text_edit->setProperty("selectionBehavior", "SelectRows");
211 text_edit->setEditTriggers(QAbstractItemView::NoEditTriggers);
212 text_edit->verticalHeader()->setVisible(false);
213 text_edit->horizontalHeader()->setVisible(false);
214 text_edit->setSelectionMode(QAbstractItemView::SingleSelection);
215 text_edit->setFocusPolicy(Qt::NoFocus);
216 header = text_edit->horizontalHeader();
217 header->setStretchLastSection(true);
218 connect(text_edit, &QTableWidget::itemDoubleClicked,
219 this, &diplo_wdg::dbl_click);
220 text_edit->clearContents();
221 text_edit->setRowCount(0);
222 layout->addWidget(text_edit, 9, 0, 8, 11);
224 new QPushButton(style()->standardIcon(QStyle::SP_DialogYesButton),
225 _("Accept treaty"));
227 new QPushButton(style()->standardIcon(QStyle::SP_DialogNoButton),
228 _("Cancel meeting"));
229 connect(accept_treaty, &QAbstractButton::clicked, this, &diplo_wdg::response_accept);
230 connect(cancel_treaty, &QAbstractButton::clicked, this, &diplo_wdg::response_cancel);
231 layout->addWidget(accept_treaty, 17, 5);
232 layout->addWidget(cancel_treaty, 17, 6);
233
235 label4->setToolTip(text_tooltip);
236 plr2_label->setToolTip(text_tooltip);
237 }
238 if (client_player_number() != initiated_from) {
239 label3->setToolTip(text_tooltip);
240 plr1_label->setToolTip(text_tooltip);
241 }
242
243 accept_treaty->setAutoDefault(true);
244 accept_treaty->setDefault(true);
245 cancel_treaty->setAutoDefault(true);
246 setLayout(layout);
247 update_wdg();
248
249}
250
251/************************************************************************/
257
258/************************************************************************/
261void diplo_wdg::dbl_click(QTableWidgetItem *item)
262{
263 int i, r;
264
265 r = item->row();
266 i = 0;
268 if (i == r) {
271 player_number(pclause->from),
272 pclause->type,
273 pclause->value);
274 return;
275 }
276 i++;
278}
279
280/************************************************************************/
283void diplo_wdg::closeEvent(QCloseEvent *event)
284{
285 if (C_S_RUNNING == client_state()) {
287 }
288 event->accept();
289}
290
291/************************************************************************/
295{
298 CLAUSE_GOLD, val);
299}
300
301/************************************************************************/
305{
308 CLAUSE_GOLD, val);
309}
310
311/************************************************************************/
315{
316 int other_player;
317 struct player *pgiver, *pother;
318 enum diplstate_type ds;
319 QAction *all_advancs;
320 QAction *some_action;
321 QMap <QString, int>city_list;
322 QMap <QString, int>::const_iterator city_iter;
323 QMap <QString, Tech_type_id> adv_list;
324 QMap <QString, Tech_type_id>::const_iterator adv_iter;
325 QMenu *map_menu = nullptr;
326 QMenu *adv_menu, *city_menu, *pacts_menu;
327 QMenu *menu = new QMenu(this);
328 int id;
329
331 if (curr_player == player1) {
332 other_player = player2;
333 } else {
334 other_player = player1;
335 }
336 pgiver = player_by_number(player);
337 pother = player_by_number(other_player);
338
339 // Maps
340 if (clause_enabled(CLAUSE_MAP)) {
341 QAction *world_map;
342
343 map_menu = menu->addMenu(_("Maps"));
344 world_map = new QAction(_("World-map"), this);
345 connect(world_map, &QAction::triggered, this, &diplo_wdg::world_map_clause);
346 map_menu->addAction(world_map);
347 }
348
349 if (clause_enabled(CLAUSE_SEAMAP)) {
350 QAction *sea_map;
351
352 if (map_menu == nullptr) {
353 map_menu = menu->addMenu(_("Maps"));
354 }
355
356 sea_map = new QAction(_("Sea-map"), this);
357 connect(sea_map, &QAction::triggered, this, &diplo_wdg::sea_map_clause);
358 map_menu->addAction(sea_map);
359 }
360
361 // Trading: advances
362 if (clause_enabled(CLAUSE_ADVANCE)) {
363 const struct research *gresearch = research_get(pgiver);
364 const struct research *oresearch = research_get(pother);
365 adv_menu = menu->addMenu(_("Advances"));
366 advance_iterate(A_FIRST, padvance) {
367 Tech_type_id i = advance_number(padvance);
368
369 if (research_invention_state(gresearch, i) == TECH_KNOWN
370 && research_invention_gettable(oresearch, i,
372 && (research_invention_state(oresearch, i) == TECH_UNKNOWN
373 || research_invention_state(oresearch, i)
374 == TECH_PREREQS_KNOWN)) {
375 adv_list.insert(advance_name_translation(padvance), i);
376 }
378
379 // All advances
380 all_advancs = new QAction(_("All advances"), this);
381 connect(all_advancs, &QAction::triggered, this, &diplo_wdg::all_advances);
382 adv_menu->addAction(all_advancs);
383 adv_menu->addSeparator();
384
385 // QMap is sorted by default when iterating
386 adv_iter = adv_list.constBegin();
387 if (adv_list.count() > 0) {
388 while (adv_iter != adv_list.constEnd()) {
389 id = adv_iter.value();
390 some_action = adv_menu->addAction(adv_iter.key());
391 connect(some_action, &QAction::triggered, this,
393 give_advance(id);
394 });
395 adv_iter++;
396 }
397 } else {
398 adv_menu->setDisabled(true);
399 }
400
401 }
402
403 // Trading: cities.
404 if (clause_enabled(CLAUSE_CITY)) {
405 city_menu = menu->addMenu(_("Cities"));
406
407 city_list_iterate(pgiver->cities, pcity) {
408 if (!is_capital(pcity)) {
409 city_list.insert(pcity->name, pcity->id);
410 }
412 city_iter = city_list.constBegin();
413 if (city_list.count() > 0) {
414 while (city_iter != city_list.constEnd()) {
415 id = city_iter.value();
416 some_action = city_menu->addAction(city_iter.key());
417 connect(some_action, &QAction::triggered, this,
419 give_city(id);
420 });
421 city_iter++;
422 }
423 } else {
424 city_menu->setDisabled(true);
425 }
426 }
427
428 if (clause_enabled(CLAUSE_VISION)) {
429 some_action = new QAction(_("Give shared vision"), this);
430 connect(some_action, &QAction::triggered, this,
432 menu->addAction(some_action);
433 if (gives_shared_vision(pgiver, pother)) {
434 some_action->setDisabled(true);
435 }
436 }
437
438 if (clause_enabled(CLAUSE_EMBASSY)) {
439 some_action = new QAction(_("Give embassy"), this);
440 connect(some_action, &QAction::triggered, this, &diplo_wdg::give_embassy);
441 menu->addAction(some_action);
442 if (player_has_real_embassy(pother, pgiver)) {
443 some_action->setDisabled(true);
444 }
445 }
446
447 // Pacts
449 pacts_menu = menu->addMenu(_("Pacts"));
450 ds = player_diplstate_get(pgiver, pother)->type;
451
452 if (clause_enabled(CLAUSE_CEASEFIRE)) {
453 some_action = new QAction(Q_("?diplomatic_state:Cease-fire"), this);
454 connect(some_action, &QAction::triggered, this, &diplo_wdg::pact_ceasfire);
455 pacts_menu->addAction(some_action);
456 if (ds == DS_CEASEFIRE || ds == DS_TEAM) {
457 some_action->setDisabled(true);
458 }
459 }
460
461 if (clause_enabled(CLAUSE_PEACE)) {
462 some_action = new QAction(Q_("?diplomatic_state:Peace"), this);
463 connect(some_action, &QAction::triggered, this, &diplo_wdg::pact_peace);
464 pacts_menu->addAction(some_action);
465 if (ds == DS_PEACE || ds == DS_TEAM) {
466 some_action->setDisabled(true);
467 }
468 }
469
470 if (clause_enabled(CLAUSE_ALLIANCE)) {
471 some_action = new QAction(Q_("?diplomatic_state:Alliance"), this);
472 connect(some_action, &QAction::triggered, this, &diplo_wdg::pact_allianze);
473 pacts_menu->addAction(some_action);
474 if (ds == DS_ALLIANCE || ds == DS_TEAM) {
475 some_action->setDisabled(true);
476 }
477 }
478 }
479
480 /* Check user response for not defined responses in slots */
481 menu->setAttribute(Qt::WA_DeleteOnClose);
482 menu->popup(QCursor::pos());
483}
484
485/************************************************************************/
494
495/************************************************************************/
504
505/************************************************************************/
514
515/************************************************************************/
524
525/************************************************************************/
534
535/************************************************************************/
544
545/************************************************************************/
554
555/************************************************************************/
558void diplo_wdg::give_city(int city_num)
559{
560 int giver, dest, other;
561
563 if (curr_player == player1) {
564 dest = player2;
565 } else {
566 dest = player1;
567 }
568
570 other = dest;
571 } else {
572 other = giver;
573 }
574
576 CLAUSE_CITY, city_num);
577}
578
579/************************************************************************/
583{
584 int giver, dest, other;
585
587 if (curr_player == player1) {
588 dest = player2;
589 } else {
590 dest = player1;
591 }
592
594 other = dest;
595 } else {
596 other = giver;
597 }
598
600 CLAUSE_ADVANCE, tech);
601}
602
603/************************************************************************/
607{
608 int giver, dest, other;
609 const struct research *dresearch, *gresearch;
610
612 if (curr_player == player1) {
613 dest = player2;
614 } else {
615 dest = player1;
616 }
617
619 other = dest;
620 } else {
621 other = giver;
622 }
623
624 /* All techs. */
625 struct player *pgiver = player_by_number(giver);
626 struct player *pdest = player_by_number(dest);
627
628 fc_assert_ret(NULL != pgiver);
629 fc_assert_ret(NULL != pdest);
630
631 dresearch = research_get(pdest);
632 gresearch = research_get(pgiver);
633
634 advance_iterate(A_FIRST, padvance) {
635 Tech_type_id i = advance_number(padvance);
636
637 if (research_invention_state(gresearch, i) == TECH_KNOWN
638 && research_invention_gettable(dresearch, i,
640 && (research_invention_state(dresearch, i) == TECH_UNKNOWN
641 || research_invention_state(dresearch, i)
642 == TECH_PREREQS_KNOWN)) {
644 CLAUSE_ADVANCE, i);
645 }
647}
648
649/************************************************************************/
656
657/************************************************************************/
664
665/************************************************************************/
669{
670 index = ind;
671}
672
673/************************************************************************/
677{
678 return index;
679}
680
681/************************************************************************/
685{
686 bool blank;
687 int i;
688 struct sprite *sprite;
689 QPixmap *pix = NULL;
690 QTableWidgetItem *qitem;
691
692 blank = true;
693 text_edit->clearContents();
694 text_edit->setRowCount(0);
695 i = 0;
697 char buf[128];
698 client_diplomacy_clause_string(buf, sizeof(buf), pclause);
699 text_edit->insertRow(i);
700 qitem = new QTableWidgetItem();
701 qitem->setText(buf);
702 qitem->setTextAlignment(Qt::AlignLeft);
703 text_edit->setItem(i, 0, qitem);
704 blank = false;
705 i++;
707
708 if (blank) {
709 text_edit->insertRow(0);
710 qitem = new QTableWidgetItem();
711 qitem->setText(_("--- This treaty is blank. "
712 "Please add some clauses. ---"));
713 qitem->setTextAlignment(Qt::AlignLeft);
714 text_edit->setItem(0, 0, qitem);
715 }
716
718 if (sprite != NULL) {
719 pix = sprite->pm;
720 plr1_accept->setPixmap(*pix);
721 } else {
722 plr1_accept->setText("PIXMAP MISSING");
723 }
724
726 if (sprite != NULL) {
727 pix = sprite->pm;
728 plr2_accept->setPixmap(*pix);
729 } else {
730 plr2_accept->setText("PIXMAP MISSING");
731 }
732}
733
734/************************************************************************/
738{
739 gui()->sw_diplo->set_pixmap(fc_icons::instance()->get_pixmap("nations"));
740 gui()->sw_diplo->resize_pixmap(gui()->sw_diplo->width(),
741 gui()->sw_diplo->height());
742 gui()->sw_diplo->set_custom_labels(QString());
743 gui()->sw_diplo->update_final_pixmap();
744}
745
746/************************************************************************/
755
756/************************************************************************/
765
766/************************************************************************/
769diplo_dlg::diplo_dlg(int counterpart, int initiated_from): QTabWidget()
770{
771 add_widget(counterpart, initiated_from);
772 setFocusPolicy(Qt::ClickFocus);
773}
774
775/************************************************************************/
778void diplo_dlg::add_widget(int counterpart, int initiated_from)
779{
780 diplo_wdg *dw;
781 struct sprite *sprite;
782 QPixmap *pix;
783 int i;
784
785 pix = NULL;
786 dw = new diplo_wdg(counterpart, initiated_from);
787 treaty_list.insert(counterpart, dw);
789 dw->set_index(i);
792 (counterpart)));
793 if (sprite != NULL) {
794 pix = sprite->pm;
795 }
796 if (pix != NULL) {
797 setTabIcon(i, QIcon(*pix));
798 }
799}
800
801/************************************************************************/
805{
806 QWidget *w;
807
808 w = find_widget(party);
809 if (w == NULL) {
810 return;
811 }
812 setCurrentWidget(w);
813}
814
815/************************************************************************/
818bool diplo_dlg::init(bool raise)
819{
821 return false;
822 }
823 if (!is_human(client.conn.playing)) {
824 return false;
825 }
826 setAttribute(Qt::WA_DeleteOnClose);
827 gui()->gimme_place(this, "DDI");
828 index = gui()->add_game_tab(this);
829 gui()->game_tab_widget->setCurrentIndex(index);
830
831 return true;
832}
833
834/************************************************************************/
838{
839 QMapIterator<int, diplo_wdg *>i(treaty_list);
840 diplo_wdg *dw;
841
842 while (i.hasNext()) {
843 i.next();
844 dw = i.value();
845 dw->close();
846 removeTab(dw->get_index());
847 dw->deleteLater();
848 }
849 gui()->remove_repo_dlg("DDI");
850 gui()->game_tab_widget->setCurrentIndex(0);
851}
852
853/************************************************************************/
860
861/************************************************************************/
865{
866 diplo_wdg *dw;
867
868 dw = treaty_list.take(counterpart);
869 removeTab(dw->get_index());
870 dw->deleteLater();
871 if (treaty_list.isEmpty()) {
872 close();
873 }
874}
875
876/************************************************************************/
880{
881 QMapIterator <int, diplo_wdg *>i(treaty_list);
882 diplo_wdg *dw;
883
884 while (i.hasNext()) {
885 i.next();
886 dw = i.value();
887 dw->update_wdg();
888 }
889}
890
891/************************************************************************/
895{
896 raise();
897}
898
899/************************************************************************/
904 bool other_accepted)
905{
906 int i;
907 diplo_dlg *dd;
908 diplo_wdg *dw;
909 QWidget *w;
910
911 if (!gui()->is_repo_dlg_open("DDI")) {
912 return;
913 }
914 i = gui()->gimme_index_of("DDI");
915 fc_assert(i != -1);
916 w = gui()->game_tab_widget->widget(i);
917 dd = qobject_cast<diplo_dlg *>(w);
918 dw = dd->find_widget(counterpart);
919 dw->treaty.accept0 = I_accepted;
920 dw->treaty.accept1 = other_accepted;
921 dw->update_wdg();
922
923}
924
925/************************************************************************/
929void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
930{
931
932 int i;
933 diplo_dlg *dd;
934 QPainter p;
935 QPixmap *pix, *def_pix, *pix2, *pix3, *def_pix_del;
936 QWidget *w;
937 QWidget *fw;
938 bool was_open;
939
940 if (client_is_observer()) {
941 return;
942 }
943
944 if (gui()->current_page() != PAGE_GAME) {
945 gui()->switch_page(PAGE_GAME);
946 }
947
948 pix2 = new QPixmap();
949 def_pix_del = new QPixmap();
952 (counterpart)))->pm;
953 *pix2 = pix->scaledToWidth(gui()->sw_diplo->width() - 2,
954 Qt::SmoothTransformation);
955 if (pix2->height() > gui()->sw_diplo->height()) {
956 *pix2 = pix->scaledToHeight(gui()->sw_diplo->height(),
957 Qt::SmoothTransformation);
958 }
959 pix3 = new QPixmap(gui()->sw_diplo->width(), gui()->sw_diplo->height());
960 pix3->fill(Qt::transparent);
961 def_pix = fc_icons::instance()->get_pixmap("nations");
962 *def_pix_del = def_pix->scaled(gui()->sw_diplo->width(),
963 gui()->sw_diplo->height(),
964 Qt::IgnoreAspectRatio,
965 Qt::SmoothTransformation);
966 p.begin(pix3);
967 p.drawPixmap(1, 1, *pix2);
968 p.drawPixmap(0, 0, *def_pix_del);
969 p.end();
970 gui()->sw_diplo->set_pixmap(pix3);
971 gui()->sw_diplo->resize_pixmap(gui()->sw_diplo->width(),
972 gui()->sw_diplo->height());
973 gui()->sw_diplo->set_custom_labels(QString(nation_plural_for_player(
975 gui()->sw_diplo->update_final_pixmap();
976 delete pix2;
977 delete def_pix;
978 delete def_pix_del;
979
980 was_open = gui()->is_repo_dlg_open("DDI");
981 if (!was_open) {
982 dd = new diplo_dlg(counterpart, initiated_from);
983
984 if (!dd->init(false)) {
985 delete dd;
986 return;
987 }
988 dd->update_dlg();
990 }
991 i = gui()->gimme_index_of("DDI");
992 fc_assert(i != -1);
993 w = gui()->game_tab_widget->widget(i);
994 dd = qobject_cast<diplo_dlg *>(w);
995
996 if (was_open) {
997 dd->reactivate();
998 }
999
1000 fw = dd->find_widget(counterpart);
1001 if (fw == NULL) {
1002 dd->add_widget(counterpart, initiated_from);
1003 gui()->game_tab_widget->setCurrentIndex(i);
1004 }
1006
1007 /* Bring it to front if user requested meeting */
1008 if (player_by_number(initiated_from) == client.conn.playing) {
1009 gui()->game_tab_widget->setCurrentIndex(i);
1010 }
1011}
1012
1013/************************************************************************/
1017 enum clause_type type, int value)
1018{
1019 int i;
1020 diplo_dlg *dd;
1021 diplo_wdg *dw;
1022 QWidget *w;
1023
1024 if (!gui()->is_repo_dlg_open("DDI")) {
1025 return;
1026 }
1027 i = gui()->gimme_index_of("DDI");
1028 fc_assert(i != -1);
1029 w = gui()->game_tab_widget->widget(i);
1030 dd = qobject_cast<diplo_dlg *>(w);
1031 dw = dd->find_widget(counterpart);
1033 client_player());
1034 dw->update_wdg();
1035}
1036
1037/************************************************************************/
1042{
1043 int i;
1044 diplo_dlg *dd;
1045 QWidget *w;
1046
1047 if (!gui()->is_repo_dlg_open("DDI")) {
1048 return;
1049 }
1050 i = gui()->gimme_index_of("DDI");
1051 fc_assert(i != -1);
1052 w = gui()->game_tab_widget->widget(i);
1053 dd = qobject_cast<diplo_dlg *>(w);
1055
1056}
1057
1058/************************************************************************/
1062 enum clause_type type, int value)
1063{
1064
1065 int i;
1066 diplo_dlg *dd;
1067 diplo_wdg *dw;
1068 QWidget *w;
1069
1070 if (!gui()->is_repo_dlg_open("DDI")) {
1071 return;
1072 }
1073 i = gui()->gimme_index_of("DDI");
1074 fc_assert(i != -1);
1075 w = gui()->game_tab_widget->widget(i);
1076 dd = qobject_cast<diplo_dlg *>(w);
1077 dw = dd->find_widget(counterpart);
1079 dw->update_wdg();
1080
1081}
1082
1083/************************************************************************/
1089{
1090 int i;
1091 diplo_dlg *dd;
1092 QWidget *w;
1093
1094 current_app()->alert(gui()->central_wdg);
1095 if (!gui()->is_repo_dlg_open("DDI")) {
1096 return;
1097 }
1098 i = gui()->gimme_index_of("DDI");
1099 fc_assert(i != -1);
1100 w = gui()->game_tab_widget->widget(i);
1101 dd = qobject_cast<diplo_dlg *>(w);
1102 dd->close();
1103 delete dd;
1104}
bool is_capital(const struct city *pcity)
Definition city.c:1552
#define city_list_iterate(citylist, pcity)
Definition city.h:488
#define city_list_iterate_end
Definition city.h:490
QMap< int, diplo_wdg * > treaty_list
Definition diplodlg.h:106
void make_active(int party)
Definition diplodlg.cpp:804
diplo_dlg(int counterpart, int initiated_from)
Definition diplodlg.cpp:769
void close_widget(int counterpart)
Definition diplodlg.cpp:864
void update_dlg()
Definition diplodlg.cpp:879
void add_widget(int counterpart, int initiated_from)
Definition diplodlg.cpp:778
diplo_wdg * find_widget(int counterpart)
Definition diplodlg.cpp:856
bool init(bool raise)
Definition diplodlg.cpp:818
int index
Definition diplodlg.h:120
void reactivate()
Definition diplodlg.cpp:894
void response_accept()
Definition diplodlg.cpp:749
void pact_ceasfire()
Definition diplodlg.cpp:518
bool p2_accept
Definition diplodlg.h:96
void show_menu_p1()
Definition diplodlg.cpp:660
void give_embassy()
Definition diplodlg.cpp:488
QLabel * plr2_accept
Definition diplodlg.h:54
void show_menu(int player)
Definition diplodlg.cpp:314
void gold_changed1(int val)
Definition diplodlg.cpp:294
void world_map_clause()
Definition diplodlg.cpp:548
void gold_changed2(int val)
Definition diplodlg.cpp:304
int get_index()
Definition diplodlg.cpp:676
void pact_allianze()
Definition diplodlg.cpp:508
void closeEvent(QCloseEvent *event)
Definition diplodlg.cpp:283
int player1
Definition diplodlg.h:91
void all_advances()
Definition diplodlg.cpp:606
QPushButton * cancel_treaty
Definition diplodlg.h:56
void sea_map_clause()
Definition diplodlg.cpp:538
void give_shared_vision()
Definition diplodlg.cpp:498
void give_city(int city_num)
Definition diplodlg.cpp:558
void response_cancel()
Definition diplodlg.cpp:759
void dbl_click(QTableWidgetItem *item)
Definition diplodlg.cpp:261
void show_menu_p2()
Definition diplodlg.cpp:652
void update_wdg()
Definition diplodlg.cpp:684
int curr_player
Definition diplodlg.h:94
int index
Definition diplodlg.h:97
void restore_pixmap()
Definition diplodlg.cpp:737
bool p1_accept
Definition diplodlg.h:95
diplo_wdg(int id, int id2)
Definition diplodlg.cpp:54
QPushButton * accept_treaty
Definition diplodlg.h:55
int player2
Definition diplodlg.h:92
void give_advance(int tech)
Definition diplodlg.cpp:582
QGridLayout * layout
Definition diplodlg.h:52
void pact_peace()
Definition diplodlg.cpp:528
void set_index(int ind)
Definition diplodlg.cpp:668
struct Treaty treaty
Definition diplodlg.h:65
QLabel * plr1_accept
Definition diplodlg.h:53
QPixmap * get_pixmap(const QString &id)
static fc_icons * instance()
bool client_is_observer(void)
int client_player_number(void)
struct civclient client
enum client_states client_state(void)
bool can_client_issue_orders(void)
const char * title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
#define client_player()
@ C_S_RUNNING
Definition client_main.h:47
void client_diplomacy_clause_string(char *buf, int bufsiz, struct Clause *pclause)
Definition climisc.c:241
struct color * color_best_contrast(struct color *subject, struct color **candidates, int ncandidates)
struct color * get_player_color(const struct tileset *t, const struct player *pplayer)
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
city * p_city
Definition diplodlg.cpp:49
struct player * player_by_number(const int player_id)
Definition player.c:840
void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
Definition diplodlg.cpp:929
int client_player_number(void)
void handle_diplomacy_create_clause(int counterpart, int giver, enum clause_type type, int value)
void close_all_diplomacy_dialogs(void)
advance * p_advance
Definition diplodlg.cpp:48
void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted, bool other_accepted)
Definition diplodlg.cpp:903
int int initiated_from int int giver
Definition diplodlg_g.h:28
int int initiated_from handle_diplomacy_remove_clause
Definition diplodlg_g.h:28
handle_diplomacy_cancel_meeting
Definition diplodlg_g.h:24
int counterpart
Definition diplodlg_g.h:25
void init_treaty(struct Treaty *ptreaty, struct player *plr0, struct player *plr1)
Definition diptreaty.c:96
bool add_clause(struct Treaty *ptreaty, struct player *pfrom, enum clause_type type, int val, struct player *client_player)
Definition diptreaty.c:142
bool clause_enabled(enum clause_type type)
Definition diptreaty.c:286
bool remove_clause(struct Treaty *ptreaty, struct player *pfrom, enum clause_type type, int val)
Definition diptreaty.c:120
#define clause_list_iterate_end
Definition diptreaty.h:68
#define clause_list_iterate(clauselist, pclause)
Definition diptreaty.h:66
int int id
Definition editgui_g.h:28
enum event_type event
Definition events.c:81
int Tech_type_id
Definition fc_types.h:347
#define MAX_LEN_NAME
Definition fc_types.h:66
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:57
const char * ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
Definition government.c:390
static enum client_pages current_page
Definition pages.c:78
GType type
Definition repodlgs.c:1312
#define CAPTURE_DEFAULT_THIS
Definition gui_main.h:23
QApplication * current_app()
Definition gui_main.cpp:220
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert(condition)
Definition log.h:176
static mpgui * gui
Definition mpgui_qt.cpp:52
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
int dsend_packet_diplomacy_create_clause_req(struct connection *pc, int counterpart, int giver, enum clause_type type, int value)
int dsend_packet_diplomacy_cancel_meeting_req(struct connection *pc, int counterpart)
int dsend_packet_diplomacy_remove_clause_req(struct connection *pc, int counterpart, int giver, enum clause_type type, int value)
int dsend_packet_diplomacy_accept_treaty_req(struct connection *pc, int counterpart)
struct player * player_by_number(const int player_id)
Definition player.c:840
int player_number(const struct player *pplayer)
Definition player.c:828
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:234
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1461
#define is_human(plr)
Definition player.h:233
struct research * research_get(const struct player *pplayer)
Definition research.c:126
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:690
#define ARRAY_SIZE(x)
Definition shared.h:85
struct player * plr0
Definition diptreaty.h:77
bool accept0
Definition diptreaty.h:78
bool accept1
Definition diptreaty.h:78
struct clause_list * clauses
Definition diptreaty.h:79
Definition city.h:309
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
Definition colors.h:20
QColor qcolor
Definition colors.h:25
struct player * playing
Definition connection.h:156
Definition climisc.h:82
bool tech_trade_allow_holes
enum diplstate_type type
Definition player.h:201
struct city_list * cities
Definition player.h:281
QPixmap * pm
Definition sprite.h:25
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:290
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
#define advance_iterate(_start, _p)
Definition tech.h:264
#define A_FIRST
Definition tech.h:44
#define advance_iterate_end
Definition tech.h:270
struct sprite * get_treaty_thumb_sprite(const struct tileset *t, bool on_off)
Definition tilespec.c:6605
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6467