16 #include <QApplication>
17 #include <QCloseEvent>
18 #include <QGridLayout>
19 #include <QHeaderView>
22 #include <QPushButton>
24 #include <QTableWidget>
49 : QWidget(), active_menu(0), curr_player(0), index(0)
62 QPushButton *add_clause1;
63 QPushButton *add_clause2;
64 const QPixmap *sprite, *sprite2;
70 if (counterpart == initiated_from) {
83 text_tooltip = QString(diplstate_type_translated_name(state->
type));
85 text_tooltip = text_tooltip +
" (";
88 + QString(
PL_(
"%1 turn left",
"%1 turns left", state->
turns_left))
90 text_tooltip = text_tooltip +
")";
97 +
"</center></h3></b>";
100 "<style>h3{background-color: " + color.name() +
";" +
"color: "
102 +
"}</style>" + text;
103 label3->setText(text);
104 label3->setMinimumWidth(300);
106 text =
"<b><h3><center>"
109 +
"</center></h3></b></body>";
112 "<style>h3{background-color: " + color.name() +
";" +
"color: "
114 +
"}</style>" + text;
115 label4->setMinimumWidth(300);
116 label4->setText(text);
117 layout->addWidget(label3, 0, 5);
118 layout->addWidget(label4, 5, 5);
119 plr1_label =
new QLabel;
123 if (sprite !=
nullptr) {
124 plr1_label->setPixmap(*sprite);
126 plr1_label->setText(QStringLiteral(
"FLAG MISSING"));
130 text =
"<b><center>" + text.toHtmlEscaped() +
"</center></b>";
131 label->setText(text);
133 layout->addWidget(plr1_label, 1, 0);
134 layout->addWidget(label, 1, 5);
139 plr2_label =
new QLabel;
140 if (sprite2 !=
nullptr) {
141 plr2_label->setPixmap(*sprite2);
143 plr2_label->setText(QStringLiteral(
"FLAG MISSING"));
147 text2 =
"<b><center>" + text2.toHtmlEscaped() +
"</center></b>";
148 label2->setText(text2);
150 layout->addWidget(plr2_label, 6, 0);
151 layout->addWidget(label2, 6, 5);
153 goldlab1 =
new QLabel(
_(
"Gold:"));
154 goldlab1->setAlignment(Qt::AlignRight);
155 goldlab2 =
new QLabel(
_(
"Gold:"));
156 goldlab2->setAlignment(Qt::AlignRight);
161 gold_edit1->setMaximum(std::numeric_limits<std::int32_t>::max());
162 gold_edit2->setMaximum(std::numeric_limits<std::int32_t>::max());
167 connect(
gold_edit1, qOverload<int>(&QSpinBox::valueChanged),
this,
169 connect(
gold_edit2, qOverload<int>(&QSpinBox::valueChanged),
this,
171 add_clause1 =
new QPushButton(style()->standardIcon(QStyle::SP_ArrowRight),
173 add_clause2 =
new QPushButton(style()->standardIcon(QStyle::SP_ArrowRight),
175 add_clause1->setFocusPolicy(Qt::ClickFocus);
176 add_clause2->setFocusPolicy(Qt::ClickFocus);
177 connect(add_clause1, &QAbstractButton::clicked,
this,
179 connect(add_clause2, &QAbstractButton::clicked,
this,
181 layout->addWidget(goldlab1, 7, 4);
182 layout->addWidget(goldlab2, 3, 4);
185 layout->addWidget(add_clause1, 7, 6);
186 layout->addWidget(add_clause2, 3, 6);
190 text_edit->setProperty(
"showGrid",
"false");
191 text_edit->setProperty(
"selectionBehavior",
"SelectRows");
192 text_edit->setEditTriggers(QAbstractItemView::NoEditTriggers);
193 text_edit->verticalHeader()->setVisible(
false);
194 text_edit->horizontalHeader()->setVisible(
false);
195 text_edit->setSelectionMode(QAbstractItemView::SingleSelection);
198 header->setStretchLastSection(
true);
199 connect(
text_edit, &QTableWidget::itemDoubleClicked,
this,
205 style()->standardIcon(QStyle::SP_DialogYesButton),
_(
"Accept treaty"));
207 style()->standardIcon(QStyle::SP_DialogNoButton),
_(
"Cancel meeting"));
216 label4->setToolTip(text_tooltip);
217 plr2_label->setToolTip(text_tooltip);
220 label3->setToolTip(text_tooltip);
221 plr1_label->setToolTip(text_tooltip);
248 dsend_packet_diplomacy_remove_clause_req(
250 player_number(pclause->from), pclause->type, pclause->value);
293 struct player *pgiver, *pother;
294 enum diplstate_type ds;
295 QAction *all_advancs;
296 QAction *some_action;
297 QAction *world_map, *sea_map;
302 QMenu *map_menu, *adv_menu, *city_menu, *pacts_menu;
303 QMenu *menu =
new QMenu(
this);
316 map_menu = menu->addMenu(
_(
"Maps"));
317 world_map =
new QAction(
_(
"World-map"),
this);
318 connect(world_map, &QAction::triggered,
this,
320 map_menu->addAction(world_map);
321 sea_map =
new QAction(
_(
"Sea-map"),
this);
323 map_menu->addAction(sea_map);
329 adv_menu = menu->addMenu(
_(
"Advances"));
339 == TECH_PREREQS_KNOWN)) {
346 all_advancs =
new QAction(
_(
"All advances"),
this);
347 connect(all_advancs, &QAction::triggered,
this,
349 adv_menu->addAction(all_advancs);
350 adv_menu->addSeparator();
353 adv_iter = adv_list.constBegin();
354 if (adv_list.count() > 0) {
355 while (adv_iter != adv_list.constEnd()) {
356 id = adv_iter.value();
357 some_action = adv_menu->addAction(adv_iter.key());
358 connect(some_action, &QAction::triggered,
this,
363 adv_menu->setDisabled(
true);
369 city_menu = menu->addMenu(
_(
"Cities"));
374 city_list.insert(pcity->name, pcity->id);
378 city_iter = city_list.constBegin();
379 if (city_list.count() > 0) {
380 while (city_iter != city_list.constEnd()) {
381 id = city_iter.value();
382 some_action = city_menu->addAction(city_iter.key());
383 connect(some_action, &QAction::triggered,
this,
388 city_menu->setDisabled(
true);
391 some_action =
new QAction(
_(
"Give shared vision"),
this);
392 connect(some_action, &QAction::triggered,
this,
394 menu->addAction(some_action);
396 some_action->setDisabled(
true);
398 some_action =
new QAction(
_(
"Give embassy"),
this);
400 menu->addAction(some_action);
402 some_action->setDisabled(
true);
407 pacts_menu = menu->addMenu(
_(
"Pacts"));
409 some_action =
new QAction(
Q_(
"?diplomatic_state:Cease-fire"),
this);
410 connect(some_action, &QAction::triggered,
this,
412 pacts_menu->addAction(some_action);
413 if (ds == DS_CEASEFIRE || ds == DS_TEAM) {
414 some_action->setDisabled(
true);
416 some_action =
new QAction(
Q_(
"?diplomatic_state:Peace"),
this);
418 pacts_menu->addAction(some_action);
419 if (ds == DS_PEACE || ds == DS_TEAM) {
420 some_action->setDisabled(
true);
422 some_action =
new QAction(
Q_(
"?diplomatic_state:Alliance"),
this);
423 connect(some_action, &QAction::triggered,
this,
425 pacts_menu->addAction(some_action);
426 if (ds == DS_ALLIANCE || ds == DS_TEAM) {
427 some_action->setDisabled(
true);
432 menu->setAttribute(Qt::WA_DeleteOnClose);
433 menu->popup(QCursor::pos());
441 dsend_packet_diplomacy_create_clause_req(&
client.
conn,
451 dsend_packet_diplomacy_create_clause_req(&
client.
conn,
461 dsend_packet_diplomacy_create_clause_req(&
client.
conn,
471 dsend_packet_diplomacy_create_clause_req(&
client.
conn,
481 dsend_packet_diplomacy_create_clause_req(&
client.
conn,
491 dsend_packet_diplomacy_create_clause_req(&
client.
conn,
501 dsend_packet_diplomacy_create_clause_req(
510 int giver, dest, other;
525 dsend_packet_diplomacy_create_clause_req(&
client.
conn, other, giver,
526 CLAUSE_CITY, city_num);
534 int giver, dest, other;
549 dsend_packet_diplomacy_create_clause_req(&
client.
conn, other, giver,
550 CLAUSE_ADVANCE, tech);
558 int giver, dest, other;
559 const struct research *dresearch, *gresearch;
593 == TECH_PREREQS_KNOWN)) {
594 dsend_packet_diplomacy_create_clause_req(&
client.
conn, other, giver,
628 QTableWidgetItem *qitem;
639 qitem =
new QTableWidgetItem();
641 qitem->setTextAlignment(Qt::AlignLeft);
650 qitem =
new QTableWidgetItem();
651 qitem->setText(
_(
"--- This treaty is blank. "
652 "Please add some clauses. ---"));
653 qitem->setTextAlignment(Qt::AlignLeft);
658 if (sprite !=
nullptr) {
661 plr1_accept->setText(QStringLiteral(
"PIXMAP MISSING"));
665 if (sprite !=
nullptr) {
668 plr2_accept->setText(QStringLiteral(
"PIXMAP MISSING"));
688 dsend_packet_diplomacy_accept_treaty_req(&
client.
conn,
698 dsend_packet_diplomacy_cancel_meeting_req(&
client.
conn,
708 setFocusPolicy(Qt::ClickFocus);
719 dw =
new diplo_wdg(counterpart, initiated_from);
725 if (sprite !=
nullptr) {
726 setTabIcon(i, QIcon(*sprite));
756 setAttribute(Qt::WA_DeleteOnClose);
772 while (i.hasNext()) {
814 while (i.hasNext()) {
833 if (!
queen()->isRepoDlgOpen(QStringLiteral(
"DDI"))) {
840 dd = qobject_cast<diplo_dlg *>(w);
863 if (
king()->current_page() != PAGE_GAME) {
867 if (!
queen()->isRepoDlgOpen(QStringLiteral(
"DDI"))) {
868 dd =
new diplo_dlg(counterpart, initiated_from);
870 if (!dd->
init(
false)) {
880 dd = qobject_cast<diplo_dlg *>(w);
899 enum clause_type type,
int value)
906 if (!
queen()->isRepoDlgOpen(QStringLiteral(
"DDI"))) {
913 dd = qobject_cast<diplo_dlg *>(w);
929 if (!
queen()->isRepoDlgOpen(QStringLiteral(
"DDI"))) {
936 dd = qobject_cast<diplo_dlg *>(w);
945 enum clause_type type,
int value)
952 if (!
queen()->isRepoDlgOpen(QStringLiteral(
"DDI"))) {
959 dd = qobject_cast<diplo_dlg *>(w);
976 qApp->alert(
king()->central_wdg);
977 if (!
queen()->isRepoDlgOpen(QStringLiteral(
"DDI"))) {
984 dd = qobject_cast<diplo_dlg *>(w);
bool is_capital(const struct city *pcity)
Return TRUE iff this city is its nation's capital.
#define city_list_iterate(citylist, pcity)
#define city_list_iterate_end
QMap< int, diplo_wdg * > treaty_list
void make_active(int party)
Sets given widget as active in current dialog.
~diplo_dlg() override
Destructor for diplomacy dialog.
diplo_dlg(int counterpart, int initiated_from)
Constructor for diplomacy dialog.
void close_widget(int counterpart)
Closes given diplomacy widget.
void update_dlg()
Updates all diplomacy widgets in current dialog.
void add_widget(int counterpart, int initiated_from)
Creates new diplomacy widget and adds to diplomacy dialog.
diplo_wdg * find_widget(int counterpart)
Finds diplomacy widget in current dialog.
bool init(bool raise)
Initializes some data for diplomacy dialog.
void response_accept()
Button 'Accept treaty' has been clicked.
void pact_ceasfire()
Ceasefire pact menu activated.
void show_menu_p1()
Show menu for first player.
void give_embassy()
Give embassy menu activated.
~diplo_wdg() override
Destructor for diplomacy widget.
void show_menu(int player)
Shows popup menu with available clauses to create.
void gold_changed1(int val)
Gold changed on first spinner.
void world_map_clause()
World map menu activated.
void gold_changed2(int val)
Gold changed on second spinner.
int get_index()
Sets index in QTabWidget.
void pact_allianze()
Create alliance menu activated.
void all_advances()
Give all advances menu activated.
QPushButton * cancel_treaty
void closeEvent(QCloseEvent *event) override
Received event about diplomacy widget being closed.
void sea_map_clause()
Sea map menu activated.
void give_shared_vision()
Give shared vision menu activated.
void give_city(int city_num)
Give city menu activated.
void response_cancel()
Button 'Cancel treaty' has been clicked.
void dbl_click(QTableWidgetItem *item)
Double click on treaty list - it removes clicked clause from list.
void show_menu_p2()
Show menu for second player.
void update_wdg()
Updates diplomacy widget - updates clauses and redraws pixmaps.
void restore_pixmap()
Restores original nations pixmap.
diplo_wdg(int id, int id2)
Constructor for diplomacy widget.
QPushButton * accept_treaty
void give_advance(int tech)
Give advance menu activated.
void pact_peace()
Peace pact menu activated.
void set_index(int ind)
Sets index in QTabWidget.
static fcIcons * instance()
Returns instance of fc_icons.
void switch_page(int i)
Switch from one client page to another.
int gimmeIndexOf(const QString &str)
Returns index on game tab page of given report dialog.
int addGameTab(QWidget *widget)
Inserts tab widget to game view page.
void removeRepoDlg(const QString &str)
Removes report dialog string from the list marking it as closed.
void gimmePlace(QWidget *widget, const QString &str)
Finds not used index on game_view_tab and returns it.
fc_game_tab_widget * game_tab_widget
top_bar_widget * sw_diplo
enum client_states client_state()
Return current client state.
int client_player_number()
Returns number of player attached to client.
struct player * client_player()
Either controlling or observing.
bool can_client_issue_orders()
Returns TRUE iff the client can issue orders (such as giving unit commands).
bool client_is_observer()
Returns whether client is observer.
void client_diplomacy_clause_string(char *buf, int bufsiz, struct Clause *pclause)
Copy a string that describes the given clause into the return buffer.
QColor color_best_contrast(const QColor &subject, const QColor *candidates, int ncandidates)
Find the colour from 'candidates' with the best perceptual contrast from 'subject'.
QColor get_color(const struct tileset *t, enum color_std stdcolor)
Return a pointer to the given "standard" color.
QColor get_player_color(const struct tileset *t, const struct player *pplayer)
Return the color of the player.
void handle_diplomacy_init_meeting(int counterpart, int initiated_from)
Handle the start of a diplomacy meeting - usually by poping up a diplomacy dialog.
void handle_diplomacy_cancel_meeting(int counterpart, int initiated_from)
Update the diplomacy dialog when the meeting is canceled (the dialog should be closed).
void handle_diplomacy_create_clause(int counterpart, int giver, enum clause_type type, int value)
Update the diplomacy dialog by adding a clause.
void handle_diplomacy_remove_clause(int counterpart, int giver, enum clause_type type, int value)
Update the diplomacy dialog by removing a clause.
void close_all_diplomacy_dialogs()
Close all open diplomacy dialogs.
void handle_diplomacy_accept_treaty(int counterpart, bool I_accepted, bool other_accepted)
Update a player's acceptance status of a treaty (traditionally shown with the thumbs-up/thumbs-down s...
bool add_clause(struct Treaty *ptreaty, struct player *pfrom, enum clause_type type, int val)
Add clause to treaty.
void init_treaty(struct Treaty *ptreaty, struct player *plr0, struct player *plr1)
Initialize treaty structure between two players.
bool remove_clause(struct Treaty *ptreaty, struct player *pfrom, enum clause_type type, int val)
Remove clause from treaty.
#define clause_list_iterate_end
#define clause_list_iterate(clauselist, pclause)
class fc_client * king()
Return fc_client instance.
#define PL_(String1, String2, n)
const char * ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
Return the ruler title of the player (translated).
#define fc_assert_ret(condition)
#define fc_assert(condition)
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
pageGame * queen()
Return game instandce.
struct player * player_by_number(const int player_id)
Return struct player pointer for the given player index.
int player_number(const struct player *pplayer)
Return the player index/number/id.
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Returns whether pplayer has a real embassy with pplayer2, established from a diplomat,...
bool gives_shared_vision(const struct player *me, const struct player *them)
Return TRUE iff the player me gives shared vision to player them.
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Returns state of the tech for current research.
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Returns TRUE iff the given tech can be given to the players sharing the research immediately.
struct clause_list * clauses
struct packet_game_info info
struct city_list * cities
Tech_type_id advance_number(const struct advance *padvance)
Return the advance index.
const char * advance_name_translation(const struct advance *padvance)
Return the (translated) name of the given advance/technology.
#define advance_iterate(_start, _p)
#define advance_iterate_end
const QPixmap * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Return the sprite for the nation.
const QPixmap * get_treaty_thumb_sprite(const struct tileset *t, bool on_off)
Return a thumbs-up/thumbs-down sprite to show treaty approval or disapproval.
void top_bar_show_map()
Callback to show map.
void update_top_bar_diplomacy_status(bool notify)
Function to update the top bar button.