Freeciv-3.4
Loading...
Searching...
No Matches
citydlg.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 <QCheckBox>
21#include <QGroupBox>
22#include <QHeaderView>
23#include <QImage>
24#include <QMenu>
25#include <QMessageBox>
26#include <QPainter>
27#include <QRadioButton>
28#include <QRect>
29#include <QScreen>
30#include <QScrollArea>
31#include <QScrollBar>
32#include <QSplitter>
33#include <QToolTip>
34#include <QVBoxLayout>
35#include <QWheelEvent>
36#include <QWidgetAction>
37
38// utility
39#include "support.h"
40
41// common
42#include "citizens.h"
43#include "city.h"
44#include "counters.h"
45#include "game.h"
46
47//agents
48#include "cma_core.h"
49#include "cma_fec.h"
50
51// client
52#include "citydlg_common.h"
53#include "client_main.h"
54#include "climisc.h"
55#include "control.h"
56#include "global_worklist.h"
57#include "helpdata.h"
58#include "mapview_common.h"
59#include "movement.h"
60#include "sprite.h"
61#include "text.h"
62#include "tilespec.h"
63
64// gui-qt
65#include "citydlg.h"
66#include "colors.h"
67#include "fc_client.h"
68#include "gui_main.h"
69#include "hudwidget.h"
70
71static bool city_dlg_created = false;
76extern QString split_text(QString text, bool cut);
77extern QString cut_helptext(QString text);
78
79/************************************************************************/
83{
84 m_timer.start();
85 startTimer(50);
87 sfont = new QFont;
89 pix = nullptr;
90}
91
92/************************************************************************/
96{
97 if (pix != nullptr) {
98 delete pix;
99 }
100 delete sfont;
101}
102
103/************************************************************************/
110
111/************************************************************************/
115{
116 struct sprite *sprite;
118 QImage img;
120 QRect crop;
121
122 if (VUT_UTYPE == target->kind) {
125 } else {
127 }
128 if (pix != nullptr) {
129 delete pix;
130 }
131 if (sprite == nullptr) {
132 pix = nullptr;
133 return;
134 }
135 img = sprite->pm->toImage();
137 cropped_img = img.copy(crop);
138 tpix = QPixmap::fromImage(cropped_img);
139 pix = new QPixmap(tpix.width(), tpix.height());
140 pix->fill(Qt::transparent);
141 pixmap_copy(pix, &tpix, 0 , 0, 0, 0, tpix.width(), tpix.height());
142}
143
144/************************************************************************/
148{
149 struct sprite *sprite;
150
153 } else {
154 sprite = nullptr;
155 }
156 if (pix != nullptr) {
157 delete pix;
158 }
159 if (sprite == nullptr) {
160 pix = nullptr;
161 return;
162 }
163 pix = new QPixmap(sprite->pm->width(),
164 sprite->pm->height());
165 pix->fill(Qt::transparent);
166 pixmap_copy(pix, sprite->pm, 0 , 0, 0, 0,
167 sprite->pm->width(), sprite->pm->height());
168 if (isVisible()) {
169 update();
170 }
171}
172
173/************************************************************************/
177{
178 if ((value() != minimum() && value() < maximum())
179 || (0 == minimum() && 0 == maximum())) {
180 m_animate_step = m_timer.elapsed() / 50;
181 update();
182 }
183}
184
185/************************************************************************/
189{
190 QPainter p;
192 QColor c;
193 QRect r, rx, r2;
194 int max;
195 int f_pixel_size;
196 int pix_width = 0;
197 int pixel_size = sfont->pixelSize();
198 int pbw, pbh;
199
200 if (pix != nullptr) {
201 pix_width = height() - 4;
202 }
203
204 if (pixel_size > 0) {
206 } else {
208
209 f_pixel_size = fm.height();
210 }
211
212 pbw = width();
213 pbh = height();
214
215 rx.setX(0);
216 rx.setY(0);
217 rx.setWidth(pbw);
218 rx.setHeight(pbh);
219 p.begin(this);
220 p.drawLine(rx.topLeft(), rx.topRight());
221 p.drawLine(rx.bottomLeft(), rx.bottomRight());
222
223 max = maximum();
224
225 if (max == 0) {
226 max = 1;
227 }
228
229 r = QRect(0, 0, pbw * value() / max, pbh);
230
231 gx = QLinearGradient(0 , 0, 0, pbh);
232 c = QColor(palette().color(QPalette::Highlight));
233 gx.setColorAt(0, c);
234 gx.setColorAt(0.5, QColor(40, 40, 40));
235 gx.setColorAt(1, c);
236 p.fillRect(r, QBrush(gx));
237 p.setClipRegion(reg.translated(m_animate_step % 32, 0));
238
239 g = QLinearGradient(0 , 0, pbw, pbh);
240 c.setAlphaF(0.1);
241 g.setColorAt(0, c);
242 c.setAlphaF(0.9);
243 g.setColorAt(1, c);
244 p.fillRect(r, QBrush(g));
245
246 p.setClipping(false);
247 r2 = QRect(pbw * value() / max, 0, pbw, pbh);
248 c = palette().color(QPalette::Window);
249 p.fillRect(r2, c);
250
251 // Draw icon
252 if (pix != nullptr) {
253 p.setCompositionMode(QPainter::CompositionMode_SourceOver);
254 p.drawPixmap(2 , 2, pix_width
255 * static_cast<float>(pix->width()) / pix->height(),
256 pix_width, *pix, 0, 0, pix->width(), pix->height());
257 }
258
259 // Draw text
260 c = palette().color(QPalette::Text);
261 p.setPen(c);
262 sfont->setCapitalization(QFont::AllUppercase);
263 sfont->setBold(true);
264
265 if (text().contains('\n')) {
266 QString s1, s2;
267 int i, j;
268 QFont tmp_font = *sfont; // Don't make changes to font to be kept
269
270 i = text().indexOf('\n');
271 s1 = text().left(i);
272 s2 = text().right(text().length() - i);
273
274 if (2 * f_pixel_size >= 3 * pbh / 2) {
275 tmp_font.setPixelSize(pbh / 3);
276 }
277
278 p.setFont(tmp_font);
279
280 j = pbh - 2 * f_pixel_size;
281 p.setCompositionMode(QPainter::CompositionMode_ColorDodge);
283
284 if (fm.horizontalAdvance(s1) > rx.width()) {
285 s1 = fm.elidedText(s1, Qt::ElideRight, rx.width());
286 }
287
288 i = rx.width() - fm.horizontalAdvance(s1) + pix_width;
289 i = qMax(0, i);
290 p.drawText(i / 2, j / 3 + f_pixel_size, s1);
291
292 if (fm.horizontalAdvance(s2) > rx.width()) {
293 s2 = fm.elidedText(s2, Qt::ElideRight, rx.width());
294 }
295
296 i = rx.width() - fm.horizontalAdvance(s2) + pix_width;
297 i = qMax(0, i);
298
299 p.drawText(i / 2, pbh - j / 3, s2);
300 } else {
301 QString s;
302 int i, j;
303
304 p.setFont(*sfont);
305
306 s = text();
307 j = pbh - f_pixel_size;
308 p.setCompositionMode(QPainter::CompositionMode_ColorDodge);
310
311 if (fm.horizontalAdvance(s) > rx.width()) {
312 s = fm.elidedText(s, Qt::ElideRight, rx.width());
313 }
314
315 i = rx.width() - fm.horizontalAdvance(s) + pix_width;
316 i = qMax(0, i);
317 p.drawText(i / 2, j / 2 + f_pixel_size, s);
318 }
319
320 p.end();
321}
322
323/************************************************************************/
327{
328 int offset;
329 QRect r(-50, 0, width() + 50, height());
330 int chunk_width = 16;
331 int size = width() + 50;
332 reg = QRegion();
333
334 for (offset = 0; offset < (size * 2); offset += (chunk_width * 2)) {
335 QPolygon a;
336
337 a.setPoints(4, r.x(), r.y() + offset,
338 r.x() + r.width(), (r.y() + offset) - size,
339 r.x() + r.width(),
340 (r.y() + offset + chunk_width) - size,
341 r.x(), r.y() + offset + chunk_width);
342 reg += QRegion(a);
343 }
344
345}
346
347/************************************************************************/
350static void pixmap_put_x(QPixmap *pix)
351{
352 QPen pen(QColor(0, 0, 0));
353 QPainter p;
354
355 pen.setWidth(2);
356 p.begin(pix);
357 p.setRenderHint(QPainter::Antialiasing);
358 p.setPen(pen);
359 p.drawLine(0, 0, pix->width(), pix->height());
360 p.drawLine(pix->width(), 0, 0, pix->height());
361 p.end();
362}
363
364/************************************************************************/
367impr_item::impr_item(QWidget *parent, const impr_type *building,
368 struct city *pcity): QLabel(parent)
369{
371 dlgcity = pcity;
372 impr = building;
373 impr_pixmap = nullptr;
374 struct sprite *sprite;
375 sprite = get_building_sprite(tileset , building);
376
377 if (sprite != nullptr) {
379 sprite->pm->height());
380 impr_pixmap->map_pixmap.fill(Qt::transparent);
381 pixmap_copy(&impr_pixmap->map_pixmap, sprite->pm, 0 , 0, 0, 0,
382 sprite->pm->width(), sprite->pm->height());
383 } else {
385 impr_pixmap->map_pixmap.fill(Qt::red);
386 }
387
391}
392
393/************************************************************************/
397{
398 if (impr_pixmap) {
400 }
401}
402
403/************************************************************************/
407{
409 update();
410}
411
412/************************************************************************/
416{
417 struct sprite *sprite;
418 QPainter p;
419
420 if (impr_pixmap) {
422 }
423
425 if (impr && sprite) {
427 sprite->pm->height());
428 impr_pixmap->map_pixmap.fill(QColor(palette().color(QPalette::Highlight)));
429 pixmap_copy(&impr_pixmap->map_pixmap, sprite->pm, 0 , 0, 0, 0,
430 sprite->pm->width(), sprite->pm->height());
431 } else {
433 impr_pixmap->map_pixmap.fill(QColor(palette().color(QPalette::Highlight)));
434 }
435
436 init_pix();
437}
438
439/************************************************************************/
443{
444 struct sprite *sprite;
445
446 if (impr_pixmap) {
448 }
449
451 if (impr && sprite) {
453 sprite->pm->height());
454 impr_pixmap->map_pixmap.fill(Qt::transparent);
455 pixmap_copy(&impr_pixmap->map_pixmap, sprite->pm, 0 , 0, 0, 0,
456 sprite->pm->width(), sprite->pm->height());
457 } else {
459 impr_pixmap->map_pixmap.fill(Qt::red);
460 }
461
462 init_pix();
463}
464
465/************************************************************************/
469{
471 layout = new QHBoxLayout(this);
472 init_layout();
473}
474
475/************************************************************************/
479{
480 QSizePolicy size_fixed_policy(QSizePolicy::Fixed,
481 QSizePolicy::MinimumExpanding,
482 QSizePolicy::Slider);
483
486}
487
488/************************************************************************/
492{
493
494}
495
496/************************************************************************/
500{
501 impr_list.append(item);
502}
503
504/************************************************************************/
508{
509 int i = impr_list.count();
510 impr_item *ui;
511 int j;
512 setUpdatesEnabled(false);
513 setMouseTracking(false);
514
515 for (j = 0; j < i; j++) {
516 ui = impr_list[j];
517 layout->removeWidget(ui);
518 delete ui;
519 }
520
521 while (!impr_list.empty()) {
522 impr_list.removeFirst();
523 }
524
525 setMouseTracking(true);
526 setUpdatesEnabled(true);
527}
528
529/************************************************************************/
533{
534 QPoint p;
535
536 p = parentWidget()->parentWidget()->pos();
537 p = mapToGlobal(p);
538
539 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
540 event->angleDelta(),
541 event->buttons(),
542 event->modifiers(),
543 event->phase(), false, event->source());
544
545 QApplication::sendEvent(parentWidget(), &new_event);
546}
547
548/************************************************************************/
552{
553 int i = impr_list.count();
554 int j;
555 int h = 0;
556 impr_item *ui;
557
558 setUpdatesEnabled(false);
559 hide();
560
561 for (j = 0; j < i; j++) {
562 ui = impr_list[j];
563 h = ui->height();
564 layout->addWidget(ui, 0, Qt::AlignVCenter);
565 }
566
567 if (impr_list.count() > 0) {
568 parentWidget()->parentWidget()->setFixedHeight(city_dlg->scroll_height
569 + h + 6);
570 } else {
571 parentWidget()->parentWidget()->setFixedHeight(0);
572 }
573
574 show();
575 setUpdatesEnabled(true);
576 layout->update();
578}
579
580/************************************************************************/
584{
585 QPoint p;
586
587 p = parentWidget()->parentWidget()->pos();
588 p = mapToGlobal(p);
589
590 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
591 event->angleDelta(),
592 event->buttons(),
593 event->modifiers(),
594 event->phase(), false, event->source());
595
596 QApplication::sendEvent(parentWidget()->parentWidget(),
597 &new_event);
598}
599
600/************************************************************************/
604{
606 return;
607 }
608
609 if (event->button() == Qt::LeftButton) {
610 char buf[256];
611 int price;
612 const int impr_id = improvement_number(impr);
613 const int city_id = dlgcity->id;
615
617 impr) != TR_SUCCESS) {
618 return;
619 }
620
622
625 PL_("Sell %s for %d gold?",
626 "Sell %s for %d gold?", price),
628
629 ask->set_text_title(buf, (_("Sell improvement?")));
630 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
631 ask->setAttribute(Qt::WA_DeleteOnClose);
632 connect(ask, &hud_message_box::accepted, [=]() {
633 struct city *pcity = game_city_by_number(city_id);
634
635 if (pcity == nullptr) {
636 return;
637 }
639 });
640 ask->show();
641 }
642}
643
644/************************************************************************/
648 bool supp, int hppy_cost) : QLabel()
649{
652 QImage img;
653 QRect crop;
654 qunit = punit;
655 struct canvas *unit_pixmap;
656 struct tileset *tmp;
657 float isosize;
658
660 supported = supp;
661
662 tmp = nullptr;
663 if (unscaled_tileset) {
664 tmp = tileset;
666 }
667 isosize = 0.6;
669 isosize = 0.45;
670 }
671
672 if (punit) {
673 if (supported) {
676 } else {
679 }
680
681 unit_pixmap->map_pixmap.fill(Qt::transparent);
682 put_unit(punit, unit_pixmap, 1.0, 0, 0);
683
684 if (supported) {
688 }
689 } else {
691 unit_pixmap->map_pixmap.fill(Qt::transparent);
692 }
693
694 img = unit_pixmap->map_pixmap.toImage();
696 cropped_img = img.copy(crop);
699 * isosize, Qt::SmoothTransformation);
700 } else {
702 Qt::SmoothTransformation);
703 }
705 if (tmp != nullptr) {
706 tileset = tmp;
707 }
708
710 setFixedWidth(unit_img.width() + 4);
711 setFixedHeight(unit_img.height());
713}
714
715/************************************************************************/
719{
720 setPixmap(QPixmap::fromImage(unit_img));
721 update();
722}
723
724/************************************************************************/
730
731/************************************************************************/
735{
736 QMenu *menu;
737
739 return;
740 }
741
742 if (unit_owner(qunit) != client_player()) {
743 return;
744 }
745
746 menu = new QMenu(gui()->central_wdg);
747 menu->addAction(activate);
748 menu->addAction(activate_and_close);
749
750 if (sentry) {
751 menu->addAction(sentry);
752 }
753
754 if (fortify) {
755 menu->addAction(fortify);
756 }
757
758 if (change_home) {
759 menu->addAction(change_home);
760 }
761
762 if (load) {
763 menu->addAction(load);
764 }
765
766 if (unload) {
767 menu->addAction(unload);
768 }
769
770 if (unload_trans) {
771 menu->addAction(unload_trans);
772 }
773
774 if (disband_action) {
775 menu->addAction(disband_action);
776 }
777
778 if (upgrade) {
779 menu->addAction(upgrade);
780 }
781
782 menu->popup(event->globalPos());
783}
784
785/************************************************************************/
789{
790 struct unit_list *qunits;
791
793 return;
794 }
795
798 activate = new QAction(_("Activate unit"), this);
799 connect(activate, &QAction::triggered, this, &unit_item::activate_unit);
800 activate_and_close = new QAction(_("Activate and close dialog"), this);
801 connect(activate_and_close, &QAction::triggered, this,
803
805 sentry = new QAction(_("Sentry unit"), this);
806 connect(sentry, &QAction::triggered, this, &unit_item::sentry_unit);
807 } else {
808 sentry = nullptr;
809 }
810
812 fortify = new QAction(_("Fortify unit"), this);
813 connect(fortify, &QAction::triggered, this, &unit_item::fortify_unit);
814 } else {
815 fortify = nullptr;
816 }
818 disband_action = new QAction(_("Disband unit"), this);
819 connect(disband_action, &QAction::triggered, this, &unit_item::disband);
820 } else {
821 disband_action = nullptr;
822 }
823
826 this);
827 connect(change_home, &QAction::triggered, this, &unit_item::change_homecity);
828 } else {
829 change_home = nullptr;
830 }
831
832 if (units_can_load(qunits)) {
833 load = new QAction(_("Load"), this);
834 connect(load, &QAction::triggered, this, &unit_item::load_unit);
835 } else {
836 load = nullptr;
837 }
838
839 if (units_can_unload(&(wld.map), qunits)) {
840 unload = new QAction(_("Unload"), this);
841 connect(unload, &QAction::triggered, this, &unit_item::unload_unit);
842 } else {
843 unload = nullptr;
844 }
845
847 unload_trans = new QAction(_("Unload All From Transporter"), this);
848 connect(unload_trans, &QAction::triggered, this, &unit_item::unload_all);
849 } else {
850 unload_trans = nullptr;
851 }
852
853 if (units_can_upgrade(&(wld.map), qunits)) {
854 upgrade = new QAction(_("Upgrade Unit"), this);
855 connect(upgrade, &QAction::triggered, this, &unit_item::upgrade_unit);
856 } else {
857 upgrade = nullptr;
858 }
859
861}
862
863/************************************************************************/
867{
868 struct unit_list *punits;
870
871 if (punit == nullptr) {
872 return;
873 }
874
879}
880
881/************************************************************************/
888
889/************************************************************************/
896
897/************************************************************************/
904
905/************************************************************************/
916
917/************************************************************************/
926
927/************************************************************************/
937
938/************************************************************************/
942{
943 if (qunit) {
945 }
946}
947
948/************************************************************************/
952{
953 if (qunit) {
955 }
956}
957
958/************************************************************************/
962{
963 QImage temp_img(unit_img.size(), QImage::Format_ARGB32_Premultiplied);
964 QPainter p;
965
966 p.begin(&temp_img);
967 p.fillRect(0, 0, unit_img.width(), unit_img.height(),
968 QColor(palette().color(QPalette::Highlight)));
969 p.drawImage(0, 0, unit_img);
970 p.end();
971
972 setPixmap(QPixmap::fromImage(temp_img));
973 update();
974}
975
976/************************************************************************/
980{
981 init_pix();
982}
983
984/************************************************************************/
988{
989 QPoint p;
990
991 p = parentWidget()->parentWidget()->pos();
992 p = mapToGlobal(p);
993
994 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
995 event->angleDelta(),
996 event->buttons(),
997 event->modifiers(),
998 event->phase(), false, event->source());
999
1000 QApplication::sendEvent(parentWidget()->parentWidget(),
1001 &new_event);
1002}
1003
1004/************************************************************************/
1008{
1009 if (event->button() == Qt::LeftButton) {
1010 if (qunit) {
1013 }
1014 }
1015}
1016
1017/************************************************************************/
1021{
1022 if (qunit) {
1024 }
1025}
1026
1027/************************************************************************/
1031{
1032 layout = new QHBoxLayout(this);
1033 init_layout();
1034 supports = supp;
1035}
1036
1037/************************************************************************/
1041{
1043 unit_list.clear();
1044}
1045
1046/************************************************************************/
1050{
1051 unit_list.append(item);
1052}
1053
1054/************************************************************************/
1058{
1059 QSizePolicy size_fixed_policy(QSizePolicy::Fixed,
1060 QSizePolicy::MinimumExpanding,
1061 QSizePolicy::Slider);
1064}
1065
1066/************************************************************************/
1070{
1071 QPoint p;
1072
1073 p = parentWidget()->parentWidget()->pos();
1074 p = mapToGlobal(p);
1075
1076 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
1077 event->angleDelta(),
1078 event->buttons(),
1079 event->modifiers(),
1080 event->phase(), false, event->source());
1081
1082 QApplication::sendEvent(parentWidget(), &new_event);
1083}
1084
1085/************************************************************************/
1089{
1090 int i = unit_list.count();
1091 int j;
1092 int h;
1093 float hexfix;
1094 unit_item *ui;
1095
1096 setUpdatesEnabled(false);
1097 hide();
1098
1099 for (j = 0; j < i; j++) {
1100 ui = unit_list[j];
1101 layout->addWidget(ui, 0, Qt::AlignVCenter);
1102 }
1103
1104 hexfix = 1.0;
1106 hexfix = 0.75;
1107 }
1108
1110 h = tileset_unit_width(get_tileset()) * 0.7 * hexfix + 6;
1111 } else {
1113 }
1114 if (unit_list.count() > 0) {
1115 parentWidget()->parentWidget()->setFixedHeight(city_dlg->scroll_height
1116 + h);
1117 } else {
1118 parentWidget()->parentWidget()->setFixedHeight(0);
1119 }
1120 show();
1121 setUpdatesEnabled(true);
1122 layout->update();
1124}
1125
1126/************************************************************************/
1130{
1131 int i = unit_list.count();
1132 unit_item *ui;
1133 int j;
1134 setUpdatesEnabled(false);
1135 setMouseTracking(false);
1136
1137 for (j = 0; j < i; j++) {
1138 ui = unit_list[j];
1139 layout->removeWidget(ui);
1140 delete ui;
1141 }
1142
1143 while (!unit_list.empty()) {
1144 unit_list.removeFirst();
1145 }
1146
1147 setMouseTracking(true);
1148 setUpdatesEnabled(true);
1149}
1150
1151/************************************************************************/
1155city_label::city_label(int t, QWidget *parent) : QLabel(parent)
1156{
1157 type = t;
1158}
1159
1160/************************************************************************/
1164{
1165 int citnum, i;
1166 int w = tileset_small_sprite_width(tileset) / gui()->map_scale;
1167 int num_citizens = pcity->size;
1168
1169 if (cma_is_city_under_agent(pcity, nullptr)) {
1170 return;
1171 }
1172
1173 i = 1 + (num_citizens * 5 / 200);
1174 w = w / i;
1175 citnum = event->pos().x() / w;
1176
1177 if (!can_client_issue_orders()) {
1178 return;
1179 }
1180
1182}
1183
1184/************************************************************************/
1188{
1189 pcity = pciti;
1190}
1191
1192/************************************************************************/
1196{
1198 radius = 0;
1204 view->map_pixmap.fill(Qt::black);
1206 miniview->map_pixmap.fill(Qt::black);
1207 delta_x = 0;
1208 delta_y = 0;
1209 setContextMenuPolicy(Qt::CustomContextMenu);
1210 connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
1211 this, SLOT(context_menu(const QPoint &)));
1212}
1213
1214/************************************************************************/
1222
1223/************************************************************************/
1227{
1229 QString str;
1230
1231 painter.begin(this);
1232 painter.drawPixmap(0, 0, zoomed_pixmap);
1233
1234 if (cma_is_city_under_agent(mcity, nullptr)) {
1235 painter.fillRect(0, 0, zoomed_pixmap.width(), zoomed_pixmap.height(),
1236 QBrush(QColor(60, 60 , 60 , 110)));
1237 painter.setPen(QColor(255, 255, 255));
1238 // TRANS: %1 is a custom string chosen by player.
1239 str = QString(_("Governor %1"))
1241 painter.drawText(5, zoomed_pixmap.height() - 10, str);
1242 }
1243
1244 painter.end();
1245}
1246
1247/************************************************************************/
1250void city_map::set_pixmap(struct city *pcity, float z)
1251{
1252 int r, max_r;
1253 QSize size;
1254
1255 zoom = z;
1257
1258 if (radius != r) {
1260 radius = r;
1262 cutted_width = wdth * (r + 1) / max_r;
1263 cutted_height = height * (r + 1) / max_r;
1266 delta_x = (wdth - cutted_width) / 2;
1267 delta_y = (height - cutted_height) / 2;
1269 miniview->map_pixmap.fill(Qt::black);
1270 }
1271
1275 size = miniview->map_pixmap.size();
1277 Qt::KeepAspectRatio,
1278 Qt::SmoothTransformation);
1280 mcity = pcity;
1281}
1282
1283/************************************************************************/
1287{
1288 return zoomed_pixmap.size();
1289}
1290
1291/************************************************************************/
1295{
1296 return zoomed_pixmap.size();
1297}
1298
1299/************************************************************************/
1303{
1305 QPoint pos;
1306
1307 if (!can_client_issue_orders() || event->button() != Qt::LeftButton) {
1308 return;
1309 }
1310
1311 pos = event->pos();
1312 canvas_x = pos.x() / zoom + delta_x;
1313 canvas_y = pos.y() / zoom + delta_y;
1314
1316 canvas_x, canvas_y)) {
1318 }
1319}
1320
1321/************************************************************************/
1325{
1327 QAction *con_cultivate = nullptr;
1328 QAction *con_irrig = nullptr;
1329 QAction *con_plant = nullptr;
1330 QAction *con_mine = nullptr;
1331 QAction *con_road = nullptr;
1332 QAction *con_trfrm = nullptr;
1333 QAction *con_clean = nullptr;
1334 QAction *con_clear = nullptr;
1335 QMenu *con_menu;
1337 struct terrain *pterr;
1338 struct tile *ptile;
1339 struct universal for_terr;
1340 struct worker_task *ptask;
1341 int city_id = mcity->id;
1342
1343 if (!can_client_issue_orders()) {
1344 return;
1345 }
1346
1347 canvas_x = point.x() / zoom + delta_x;
1348 canvas_y = point.y() / zoom + delta_y;
1349
1351 canvas_x, canvas_y)) {
1352 return;
1353 }
1354
1356 city_x, city_y);
1357 pterr = tile_terrain(ptile);
1358 for_terr.kind = VUT_TERRAIN;
1359 for_terr.value.terrain = pterr;
1361
1362 wid_act = new QWidgetAction(this);
1363 wid_act->setDefaultWidget(new QLabel(_("Autoworker activity:")));
1364
1365 con_menu = new QMenu(this);
1366 con_menu->addAction(wid_act);
1367
1368 if (pterr->plant_result != nullptr
1370 con_plant = con_menu->addAction(_("Plant"));
1371 }
1373 con_mine = con_menu->addAction(Q_("?act:Mine"));
1374 }
1375
1376 if (pterr->cultivate_result != nullptr
1378 con_cultivate = con_menu->addAction(_("Cultivate"));
1379 }
1381 con_irrig = con_menu->addAction(_("Irrigate"));
1382 }
1383
1384 if (pterr->transform_result != pterr && pterr->transform_result != nullptr
1386 nullptr, &for_terr)) {
1387 con_trfrm = con_menu->addAction(_("Transform"));
1388 }
1389
1390 if (next_extra_for_tile(ptile, EC_ROAD, city_owner(mcity), nullptr) != nullptr) {
1391 con_road = con_menu->addAction(_("Road"));
1392 }
1393
1394 if (prev_extra_in_tile(ptile, ERM_CLEAN,
1395 city_owner(mcity), nullptr) != nullptr) {
1396 con_clean = con_menu->addAction(_("Clean"));
1397 }
1398
1399 if (ptask != nullptr) {
1400 con_clear = con_menu->addAction(_("Clear"));
1401 }
1402
1403 con_menu->setAttribute(Qt::WA_DeleteOnClose);
1404 connect(con_menu, &QMenu::triggered,
1406 bool target = false;
1407 struct packet_worker_task task;
1408
1409 if (!act) {
1410 return;
1411 }
1412
1413 task.city_id = city_id;
1414
1415 if (act == con_road) {
1417 target = TRUE;
1418 } else if (act == con_mine) {
1419 task.activity = ACTIVITY_MINE;
1420 target = TRUE;
1421 } else if (act == con_plant) {
1422 task.activity = ACTIVITY_PLANT;
1423 } else if (act == con_irrig) {
1425 target = TRUE;
1426 } else if (act == con_cultivate) {
1428 } else if (act == con_trfrm) {
1430 } else if (act == con_clean) {
1431 task.activity = ACTIVITY_CLEAN;
1432 target = TRUE;
1433 } else if (act == con_clear) {
1434 task.activity = ACTIVITY_LAST;
1435 } else {
1436 // Closed dialog without selecting any activity entry.
1437 return;
1438 }
1439
1440 task.want = 100;
1441
1442 if (target) {
1443 enum extra_cause cause = activity_to_extra_cause(task.activity);
1445 struct extra_type *tgt;
1446
1447 if (cause != EC_NONE) {
1448 tgt = next_extra_for_tile(ptile, cause, city_owner(mcity), nullptr);
1449 } else if (rmcause != ERM_NONE) {
1450 tgt = prev_extra_in_tile(ptile, rmcause, city_owner(mcity), nullptr);
1451 } else {
1452 tgt = nullptr;
1453 }
1454
1455 if (tgt != nullptr) {
1456 task.tgt = extra_index(tgt);
1457 } else {
1458 task.tgt = -1;
1459 }
1460 } else {
1461 task.tgt = -1;
1462 }
1463
1464 task.tile_id = ptile->index;
1466 });
1467
1468 con_menu->popup(mapToGlobal(point));
1469}
1470
1471/************************************************************************/
1475{
1476 QFont f = QApplication::font();
1477 QFont *small_font;
1478 QFontMetrics fm(f);
1484 QHeaderView *header;
1485 QLabel *lab2, *label, *ql, *some_label;
1486 QPushButton *qpush2;
1488 QSizePolicy size_expanding_policy(QSizePolicy::Expanding,
1489 QSizePolicy::Expanding);
1490 QSlider *slider;
1491 QStringList info_list, str_list;
1496 int list_size;
1497 int h = 2 * fm.height() + 2;
1498
1501 zoom = 1.0;
1502
1504 central_splitter->setOpaqueResize(false);
1506 central_left_splitter->setOpaqueResize(false);
1508 prod_unit_splitter->setOpaqueResize(false);
1509
1510 setMouseTracking(true);
1511 selected_row_p = -1;
1512 dlgcity = nullptr;
1513 lcity_name = new QPushButton(this);
1514 lcity_name->setToolTip(_("Click to change city name"));
1515
1517 single_page_layout->setContentsMargins(0, 0 ,0 ,0);
1518 size_expanding_policy.setHorizontalStretch(0);
1519 size_expanding_policy.setVerticalStretch(0);
1521 current_building = 0;
1522
1523 // Map view
1524 map_box = new QGroupBox(this);
1525
1526 // City information widget texts about surpluses and so on
1527 info_wdg = new QWidget(this);
1528
1529 // Fill info_wdg with labels
1531
1532 info_wdg->setFont(*small_font);
1533 info_grid_layout->setSpacing(0);
1534 info_grid_layout->setContentsMargins(0, 0, 0, 0);
1535
1536
1537 for (enum city_info info_field = city_info_begin();
1540
1541 ql = new QLabel(_(city_info_name(info_field)), info_wdg);
1542 ql->setFont(*small_font);
1543 ql->setProperty(fonts::notify_label, "true");
1544 info_grid_layout->addWidget(ql, info_field, 0);
1545 qlt[info_field] = new QLabel(info_wdg);
1546 qlt[info_field]->setFont(*small_font);
1547 qlt[info_field]->setProperty(fonts::notify_label, "true");
1548 info_grid_layout->addWidget(qlt[info_field], info_field, 1);
1549 info_grid_layout->setRowStretch(info_field, 0);
1550 }
1551
1552 info_wdg->setLayout(info_grid_layout);
1553
1554 // Buy button
1555 buy_button = new QPushButton();
1556 buy_button->setIcon(fc_icons::instance()->get_icon("help-donate"));
1557 connect(buy_button, &QAbstractButton::clicked, this, &city_dialog::buy);
1558
1559 connect(lcity_name, &QAbstractButton::clicked, this, &city_dialog::city_rename);
1561 citizen_pixmap = nullptr;
1562 view = new city_map(this);
1563
1564 zoom_vbox = new QVBoxLayout();
1565 zoom_in_button = new QPushButton();
1566 zoom_in_button->setIcon(fc_icons::instance()->get_icon("plus"));
1567 zoom_in_button->setIconSize(QSize(16, 16));
1568 zoom_in_button->setFixedSize(QSize(20, 20));
1569 zoom_in_button->setToolTip(_("Zoom in"));
1570 connect(zoom_in_button, &QAbstractButton::clicked, this, &city_dialog::zoom_in);
1571 zoom_out_button = new QPushButton();
1572 zoom_out_button->setIcon(fc_icons::instance()->get_icon("minus"));
1573 zoom_out_button->setIconSize(QSize(16, 16));
1574 zoom_out_button->setFixedSize(QSize(20, 20));
1575 zoom_out_button->setToolTip(_("Zoom out"));
1576 connect(zoom_out_button, &QAbstractButton::clicked, this, &city_dialog::zoom_out);
1577 zoom_vbox->addWidget(zoom_in_button);
1578 zoom_vbox->addWidget(zoom_out_button);
1579
1580 // City map group box
1583 hbox_layout->addStretch(100);
1584 hbox_layout->addWidget(view);
1585 hbox_layout->addStretch(100);
1586 hbox_layout->addLayout(zoom_vbox);
1587 vbox_layout->addLayout(hbox_layout);
1588 vbox_layout->addWidget(lcity_name);
1589 map_box->setLayout(vbox_layout);
1590 map_box->setTitle(_("City map"));
1591
1592 // Current/supported units/improvements widgets
1593 supp_units = new QLabel();
1594 curr_units = new QLabel();
1595 curr_impr = new QLabel();
1596 curr_units->setAlignment(Qt::AlignLeft);
1597 curr_impr->setAlignment(Qt::AlignLeft);
1598 supp_units->setAlignment(Qt::AlignLeft);
1599 supported_units = new unit_info(true);
1600 scroll = new QScrollArea;
1601 scroll->setWidgetResizable(true);
1602 scroll->setMaximumHeight(tileset_unit_with_upkeep_height(get_tileset()) + 6
1603 + scroll->horizontalScrollBar()->height());
1604 scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1605 scroll->setWidget(supported_units);
1606 current_units = new unit_info(false);
1607 scroll2 = new QScrollArea;
1608 scroll2->setWidgetResizable(true);
1609 scroll2->setMaximumHeight(tileset_unit_height(get_tileset()) + 6
1610 + scroll2->horizontalScrollBar()->height());
1611 scroll2->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1612 scroll2->setWidget(current_units);
1613 scroll_height = scroll2->horizontalScrollBar()->height();
1614 city_buildings = new impr_info(this);
1615 scroll3 = new QScrollArea;
1616 scroll3->setWidgetResizable(true);
1617 scroll3->setMaximumHeight(tileset_unit_height(tileset) + 6
1618 + scroll3->horizontalScrollBar()->height());
1619 scroll3->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1620 scroll3->setWidget(city_buildings);
1621 scroll->setProperty("city_scroll", true);
1622 scroll2->setProperty("city_scroll", true);
1623 scroll3->setProperty("city_scroll", true);
1624
1627 right_layout = new QVBoxLayout();
1629 units_layout = new QVBoxLayout();
1630 left_layout = new QVBoxLayout();
1631
1632 /* Checkboxes to show units/wonders/imrovements
1633 * on production list */
1636 show_buildings->setToolTip(_("Show buildings"));
1637 show_buildings->setChecked(true);
1638 label = new QLabel();
1639 label->setPixmap(*fc_icons::instance()->get_pixmap("building"));
1640 label->setToolTip(_("Show buildings"));
1641 prod_option_layout->addWidget(show_buildings, Qt::AlignLeft);
1642 prod_option_layout->addWidget(label, Qt::AlignLeft);
1643 prod_option_layout->addStretch(100);
1644 label = new QLabel();
1645 label->setPixmap(*fc_icons::instance()->get_pixmap("cunits"));
1646 label->setToolTip(_("Show units"));
1647 show_units = new QCheckBox;
1648 show_units->setToolTip(_("Show units"));
1649 show_units->setChecked(true);
1650 prod_option_layout->addWidget(show_units, Qt::AlignHCenter);
1651 prod_option_layout->addWidget(label, Qt::AlignHCenter);
1652 prod_option_layout->addStretch(100);
1653 label = new QLabel();
1654 label->setPixmap(*fc_icons::instance()->get_pixmap("wonder"));
1655 label->setToolTip(_("Show wonders"));
1656 show_wonders = new QCheckBox;
1657 show_wonders->setToolTip(_("Show wonders"));
1658 show_wonders->setChecked(true);
1659 prod_option_layout->addWidget(show_wonders);
1660 prod_option_layout->addWidget(label);
1661 prod_option_layout->addStretch(100);
1662 label = new QLabel();
1663 label->setPixmap(*fc_icons::instance()->get_pixmap("future"));
1664 label->setToolTip(_("Show future targets"));
1666 future_targets->setToolTip(_("Show future targets"));
1667 future_targets->setChecked(false);
1669 prod_option_layout->addWidget(label, Qt::AlignRight);
1670 prod_options = new QGroupBox(this);
1671 prod_options->setLayout(prod_option_layout);
1672 prod_options->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
1673
1674 // Prev/next and close buttons
1675 button = new QPushButton;
1676 button->setIcon(fc_icons::instance()->get_icon("city-close"));
1677 button->setIconSize(QSize(56, 56));
1678 button->setToolTip(_("Close city dialog"));
1679 connect(button, &QAbstractButton::clicked, this, &QWidget::hide);
1680
1681 next_city_but = new QPushButton();
1682 next_city_but->setIcon(fc_icons::instance()->get_icon("city-right"));
1683 next_city_but->setIconSize(QSize(56, 56));
1684 next_city_but->setToolTip(_("Show next city"));
1685 connect(next_city_but, &QAbstractButton::clicked, this, &city_dialog::next_city);
1686
1687 prev_city_but = new QPushButton();
1688 connect(prev_city_but, &QAbstractButton::clicked, this, &city_dialog::prev_city);
1689 prev_city_but->setIcon(fc_icons::instance()->get_icon("city-left"));
1690 prev_city_but->setIconSize(QSize(56, 56));
1691 prev_city_but->setToolTip(_("Show previous city"));
1692
1693 happiness_button = new QPushButton();
1694 happiness_button->setIcon(fc_icons::instance()->get_icon("city-switch"));
1695 happiness_button->setIconSize(QSize(56, 28));
1696 connect(happiness_button, &QAbstractButton::clicked, this, &city_dialog::show_happiness);
1697
1698 button->setFixedSize(64, 64);
1699 prev_city_but->setFixedSize(64, 64);
1700 next_city_but->setFixedSize(64, 64);
1701 happiness_button->setFixedSize(64, 32);
1703 vbox_layout->addWidget(prev_city_but);
1704 vbox_layout->addWidget(next_city_but);
1705 vbox_layout->addWidget(button);
1706 vbox_layout->addWidget(happiness_button, Qt::AlignHCenter);
1707
1708 counterss_button = new QPushButton();
1709 connect(counterss_button, &QAbstractButton::clicked, this, &city_dialog::show_counters);
1710 vbox_layout->addWidget(counterss_button, Qt::AlignHCenter);
1711
1712 update_tabs();
1714
1715 hbox_layout->addLayout(vbox_layout, Qt::AlignLeft);
1716 hbox_layout->addWidget(info_wdg, Qt::AlignLeft);
1717 hbox_layout->addWidget(map_box, Qt::AlignCenter);
1718
1719 // Layout with city view and buttons
1720 lefttop_layout->addWidget(citizens_label, Qt::AlignHCenter);
1721 lefttop_layout->addStretch(0);
1722 lefttop_layout->addLayout(hbox_layout);
1723 lefttop_layout->addStretch(50);
1724
1725 // Layout for units/buildings
1726 curr_unit_wdg = new QWidget();
1727 supp_unit_wdg = new QWidget();
1728 curr_impr_wdg = new QWidget();
1729 v_layout = new QVBoxLayout;
1730 v_layout->addWidget(curr_impr);
1731 v_layout->addWidget(scroll3);
1732 v_layout->setContentsMargins(0 , 0 , 0, 0);
1733 v_layout->setSpacing(0);
1734 curr_impr_wdg->setLayout(v_layout);
1735 v_layout = new QVBoxLayout;
1736 v_layout->addWidget(curr_units);
1737 v_layout->addWidget(scroll2);
1738 v_layout->setContentsMargins(0 , 0 , 0, 0);
1739 v_layout->setSpacing(0);
1740 curr_unit_wdg->setLayout(v_layout);
1741 v_layout = new QVBoxLayout;
1742 v_layout->addWidget(supp_units);
1743 v_layout->addWidget(scroll);
1744 v_layout->setContentsMargins(0 , 0 , 0, 0);
1745 v_layout->setSpacing(0);
1746 supp_unit_wdg->setLayout(v_layout);
1747
1748 units_layout->addWidget(curr_unit_wdg);
1749 units_layout->addWidget(supp_unit_wdg);
1750 units_layout->addWidget(curr_impr_wdg);
1751 units_layout->setSpacing(0);
1752 units_layout->setContentsMargins(0 , 0 , 0, 0);
1753
1754 vbox = new QVBoxLayout;
1756 qgbprod = new QGroupBox;
1757 group_box = new QGroupBox(_("Worklist Option"));
1759 work_next_but = new QPushButton(fc_icons::instance()->get_icon(
1760 "go-down"), "");
1761 work_prev_but = new QPushButton(fc_icons::instance()->get_icon(
1762 "go-up"), "");
1763 work_add_but = new QPushButton(fc_icons::instance()->get_icon(
1764 "list-add"), "");
1765 work_rem_but = new QPushButton(style()->standardIcon(
1766 QStyle::SP_DialogDiscardButton), "");
1767 work_but_layout->addWidget(work_add_but);
1768 work_but_layout->addWidget(work_next_but);
1769 work_but_layout->addWidget(work_prev_but);
1770 work_but_layout->addWidget(work_rem_but);
1772 production_combo_p->setToolTip(_("Click to change current production"));
1773 p_table_p = new QTableWidget;
1774
1775 r1 = new QRadioButton(_("Change"));
1776 r2 = new QRadioButton(_("Insert Before"));
1777 r3 = new QRadioButton(_("Insert After"));
1778 r4 = new QRadioButton(_("Add Last"));
1779 r4->setChecked(true);
1780 group_box->setLayout(vbox);
1781
1782
1783 p_table_p->setColumnCount(3);
1784 p_table_p->setProperty("showGrid", "false");
1785 p_table_p->setProperty("selectionBehavior", "SelectRows");
1786 p_table_p->setEditTriggers(QAbstractItemView::NoEditTriggers);
1787 p_table_p->verticalHeader()->setVisible(false);
1788 p_table_p->horizontalHeader()->setVisible(false);
1789 p_table_p->setSelectionMode(QAbstractItemView::SingleSelection);
1790 production_combo_p->setFixedHeight(h);
1791 p_table_p->setMinimumWidth(200);
1792 p_table_p->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
1793 p_table_p->setContextMenuPolicy(Qt::CustomContextMenu);
1794 p_table_p->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
1795 header = p_table_p->horizontalHeader();
1796 header->setStretchLastSection(true);
1797
1798 qgbprod->setTitle(_("Worklist"));
1799 vbox_layout->setSpacing(0);
1800 vbox_layout->addWidget(prod_options);
1801 vbox_layout->addWidget(buy_button);
1802 vbox_layout->addWidget(production_combo_p);
1803 vbox_layout->addLayout(work_but_layout);
1804 vbox_layout->addWidget(p_table_p);
1805 qgbprod->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1806 qgbprod->setLayout(vbox_layout);
1807
1808 worklist_layout->setSpacing(0);
1809 worklist_layout->addWidget(qgbprod);
1810 connect(p_table_p,
1811 &QWidget::customContextMenuRequested, this,
1814 connect(work_add_but, &QAbstractButton::clicked, this, &city_dialog::show_targets_worklist);
1815 connect(work_prev_but, &QAbstractButton::clicked, this, &city_dialog::worklist_up);
1816 connect(work_next_but, &QAbstractButton::clicked, this, &city_dialog::worklist_down);
1817 connect(work_rem_but, &QAbstractButton::clicked, this, &city_dialog::worklist_del);
1818 connect(p_table_p,
1819 &QTableWidget::itemDoubleClicked,
1821 connect(p_table_p->selectionModel(),
1823 const QItemSelection &)),
1825 const QItemSelection &)));
1826 happiness_group = new QGroupBox(_("Happiness"));
1827 gridl = new QGridLayout;
1828
1829 nationality_table = new QTableWidget;
1830 nationality_table->setColumnCount(3);
1831 nationality_table->setProperty("showGrid", "false");
1832 nationality_table->setProperty("selectionBehavior", "SelectRows");
1833 nationality_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
1834 nationality_table->verticalHeader()->setVisible(false);
1835 nationality_table->horizontalHeader()->setStretchLastSection(true);
1836
1837 info_list.clear();
1838 info_list << _("Cities:") << _("Luxuries:") << _("Buildings:")
1839 << _("Nationality:") << _("Units:") << _("Wonders:");
1840
1841 for (int i = 0; i < info_list.count(); i++) {
1842 lab_table[i] = new city_label(1 + i, this);
1843 gridl->addWidget(lab_table[i], i, 1, 1, 1);
1844 lab2 = new QLabel(this);
1845 lab2->setFont(*small_font);
1846 lab2->setProperty(fonts::notify_label, "true");
1847 lab2->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
1848 lab2->setText(info_list.at(i));
1849 gridl->addWidget(lab2, i, 0, 1, 1);
1850 }
1851
1852 gridl->setSpacing(0);
1853 happiness_group->setLayout(gridl);
1854
1855
1859 happiness_layout->setStretch(0, 10);
1860 happiness_widget = new QWidget();
1862 qgbox = new QGroupBox(_("Presets:"));
1863 qsliderbox = new QGroupBox(_("Governor settings"));
1864 result_box = new QGroupBox(_("Results:"));
1865 hbox = new QHBoxLayout;
1866 gridl = new QGridLayout;
1868
1870 counterss_frame = new QFrame();
1872
1873 qpush2
1874 = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton),
1875 _("Save"));
1876 connect(qpush2, &QAbstractButton::pressed, this, &city_dialog::save_cma);
1877
1878 cma_info_text = new QLabel;
1879 cma_info_text->setFont(*small_font);
1880 cma_info_text->setAlignment(Qt::AlignCenter);
1881 cma_table = new QTableWidget;
1882 cma_table->setColumnCount(1);
1883 cma_table->setProperty("showGrid", "false");
1884 cma_table->setProperty("selectionBehavior", "SelectRows");
1885 cma_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
1886 cma_table->setSelectionMode(QAbstractItemView::SingleSelection);
1887 cma_table->setContextMenuPolicy(Qt::CustomContextMenu);
1888 cma_table->verticalHeader()->setVisible(false);
1889 cma_table->horizontalHeader()->setVisible(false);
1890 cma_table->horizontalHeader()->setSectionResizeMode(
1891 QHeaderView::Stretch);
1892
1893 connect(cma_table->selectionModel(),
1895 const QItemSelection &)),
1897 const QItemSelection &)));
1898 connect(cma_table,
1899 &QWidget::customContextMenuRequested, this,
1901 connect(cma_table, &QTableWidget::cellDoubleClicked, this,
1903 gridl->addWidget(cma_table, 0, 0, 1, 2);
1904 qgbox->setLayout(gridl);
1905 hbox->addWidget(cma_info_text);
1906 result_box->setLayout(hbox);
1907 str_list << _("Food") << _("Shield") << _("Trade") << _("Gold")
1908 << _("Luxury") << _("Science") << _("Celebrate")
1909 << _("Maximize growth");
1910 some_label = new QLabel(_("Minimal Surplus"));
1912 some_label->setAlignment(Qt::AlignRight);
1913 slider_grid->addWidget(some_label, 0, 0, 1, 3);
1914 some_label = new QLabel(_("Priority"));
1916 some_label->setAlignment(Qt::AlignCenter);
1917 slider_grid->addWidget(some_label, 0, 3, 1, 2);
1918
1919 list_size = str_list.count();
1920 for (int i = 0; i < list_size; i++) {
1921 some_label = new QLabel(str_list.at(i));
1922 slider_grid->addWidget(some_label, i + 1, 0, 1, 1);
1923 some_label = new QLabel("0");
1924 some_label->setMinimumWidth(25);
1925
1926 if (i < list_size - 2) {
1927 slider = new QSlider(Qt::Horizontal);
1928 slider->setPageStep(1);
1929 slider->setFocusPolicy(Qt::TabFocus);
1930 slider_tab[2 * i] = slider;
1931 slider->setRange(-20, 20);
1932 slider->setSingleStep(1);
1933 slider_grid->addWidget(some_label, i + 1, 1, 1, 1);
1934 slider_grid->addWidget(slider, i + 1, 2, 1, 1);
1935 slider->setProperty("FC", QVariant::fromValue((void *)some_label));
1936
1937 connect(slider, &QAbstractSlider::valueChanged, this, &city_dialog::cma_slider);
1938 } else if (i == list_size - 2) {
1940 slider_grid->addWidget(cma_celeb_checkbox, i + 1, 2 , 1 , 1);
1941#ifdef FC_QT6X_MODE
1942 // Qt-6.7
1943 connect(cma_celeb_checkbox,
1944 &QCheckBox::checkStateChanged, this, &city_dialog::cma_toggle_changed);
1945#else // FC_QT6X_MODE
1946 connect(cma_celeb_checkbox,
1947 &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
1948#endif // FC_QT6X_MODE
1949 } else {
1950 fc_assert(i == list_size - 1);
1951
1953 slider_grid->addWidget(cma_max_growth, i + 1, 2 , 1 , 1);
1954#ifdef FC_QT6X_MODE
1955 // Qt-6.7
1956 connect(cma_max_growth,
1957 &QCheckBox::checkStateChanged, this, &city_dialog::cma_toggle_changed);
1958#else // FC_QT6X_MODE
1959 connect(cma_max_growth,
1960 &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
1961#endif // FC_QT6X_MODE
1962 }
1963
1964 if (i <= list_size - 2) {
1965 some_label = new QLabel("0");
1966 some_label->setMinimumWidth(25);
1967 slider = new QSlider(Qt::Horizontal);
1968 slider->setFocusPolicy(Qt::TabFocus);
1969 slider->setRange(0, 25);
1970 slider_tab[2 * i + 1] = slider;
1971 slider->setProperty("FC", QVariant::fromValue((void *)some_label));
1972 slider_grid->addWidget(some_label, i + 1, 3, 1, 1);
1973 slider_grid->addWidget(slider, i + 1, 4, 1, 1);
1974 connect(slider, &QAbstractSlider::valueChanged, this, &city_dialog::cma_slider);
1975 }
1976 }
1977
1978 cma_enable_but = new QPushButton();
1979 cma_enable_but->setFocusPolicy(Qt::TabFocus);
1980 connect(cma_enable_but, &QAbstractButton::pressed, this, &city_dialog::cma_enable);
1981 slider_grid->addWidget(cma_enable_but, O_LAST + 4, 0, 1, 3);
1982 slider_grid->addWidget(qpush2, O_LAST + 4, 3, 1, 2);
1983
1984 qsliderbox->setLayout(slider_grid);
1985 cma_result = new QLabel;
1986 cma_result_pix = new QLabel;
1987
1988 hbox = new QHBoxLayout;
1989 QScrollArea *govA = new QScrollArea();
1990 hbox->addWidget(cma_result_pix);
1991 hbox->addWidget(cma_result);
1992 hbox->addStretch(10);
1993 govA->setWidget(qsliderbox);
1994 govA->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
1995 right_layout->addWidget(qgbox);
1996 right_layout->addLayout(hbox);
1997 right_layout->addWidget(govA);
1998
1999 split_widget1 = new QWidget;
2000 split_widget1->setLayout(worklist_layout);
2001 split_widget2 = new QWidget;
2002 split_widget2->setLayout(units_layout);
2005 prod_unit_splitter->setStretchFactor(0, 3);
2006 prod_unit_splitter->setStretchFactor(1, 97);
2007 prod_unit_splitter->setOrientation(Qt::Horizontal);
2009 top_widget = new QWidget;
2010 top_widget->setLayout(lefttop_layout);
2011 top_widget->setSizePolicy(QSizePolicy::Minimum,
2012 QSizePolicy::Minimum);
2013 scroll_info = new QScrollArea();
2014 scroll_info->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
2015 scroll_unit = new QScrollArea();
2016 scroll_info->setWidget(top_widget);
2017 scroll_info->setWidgetResizable(true);
2018 prod_happ_widget = new QWidget;
2019 prod_happ_widget->setLayout(leftbot_layout);
2020 prod_happ_widget->setSizePolicy(QSizePolicy::MinimumExpanding,
2021 QSizePolicy::MinimumExpanding);
2022 scroll_unit->setWidget(prod_happ_widget);
2023 scroll_unit->setWidgetResizable(true);
2026 central_left_splitter->setStretchFactor(0, 40);
2027 central_left_splitter->setStretchFactor(1, 60);
2028 central_left_splitter->setOrientation(Qt::Vertical);
2030
2031 split_widget1 = new QWidget(this);
2032 split_widget2 = new QWidget(this);
2033 split_widget1->setLayout(left_layout);
2034 split_widget2->setLayout(right_layout);
2035 central_splitter->addWidget(split_widget1);
2036 central_splitter->addWidget(split_widget2);
2037 central_splitter->setStretchFactor(0, 99);
2038 central_splitter->setStretchFactor(1, 1);
2039 central_splitter->setOrientation(Qt::Horizontal);
2041 setSizeGripEnabled(true);
2043
2044 installEventFilter(this);
2045
2046 ::city_dlg_created = true;
2047
2049}
2050
2051/************************************************************************/
2055{
2056
2057 cid cprod;
2058 int i, pos;
2059 int item, targets_used;
2061 QString str;
2062 struct item items[MAX_NUM_PRODUCTION_TARGETS];
2063 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
2064 struct universal univ;
2065
2066 pos = 0;
2069 name_and_sort_items(targets, targets_used, items, false, dlgcity);
2070
2071 for (item = 0; item < targets_used; item++) {
2072 if (can_city_build_now(&(wld.map), dlgcity, &items[item].item,
2073 RPT_CERTAIN)) {
2074 prod_list << cid_encode(items[item].item);
2075 }
2076 }
2077
2078 for (i = 0; i < prod_list.size(); i++) {
2079 if (prod_list.at(i) == cprod) {
2080 if (next) {
2081 pos = i + 1;
2082 } else {
2083 pos = i - 1;
2084 }
2085 }
2086 }
2087 if (pos == prod_list.size()) {
2088 pos = 0;
2089 }
2090 if (pos == - 1) {
2091 pos = prod_list.size() - 1;
2092 }
2093 univ = cid_decode(static_cast<cid>(prod_list.at(pos)));
2095}
2096
2097/************************************************************************/
2101{
2102 if (current_tab == happiness) {
2103 happiness_button->setToolTip(_("Show city production"));
2104 counterss_button->setToolTip(_("Show counters information"));
2105
2106 } else {
2107 happiness_button->setToolTip(_("Show happiness information"));
2108
2109 if (current_tab == counters) {
2110 counterss_button->setToolTip(_("Show city production"));
2111 }
2112 else {
2113 counterss_button->setToolTip(_("Show counters information"));
2114 }
2115 }
2116}
2117
2118/************************************************************************/
2122{
2124 setUpdatesEnabled(false);
2125
2126
2127 if (current_tab != happiness) {
2128 leftbot_layout->replaceWidget(active_tab,
2130 Qt::FindDirectChildrenOnly);
2131 active_tab->hide();
2132 happiness_widget->show();
2133 happiness_widget->updateGeometry();
2135 } else {
2136 /* We do not change prod_unit_splitter to current_tab,
2137 * because happiness is active tab and clicked -
2138 * switching to default */
2139 leftbot_layout->replaceWidget(happiness_widget,
2141 Qt::FindDirectChildrenOnly);
2142 prod_unit_splitter->show();
2143 prod_unit_splitter->updateGeometry();
2144 happiness_widget->hide();
2146 }
2147
2148 setUpdatesEnabled(true);
2149 update();
2150 update_tabs();
2151}
2152
2153/************************************************************************/
2157{
2159 setUpdatesEnabled(false);
2160
2161
2162 if (current_tab != counters) {
2163 leftbot_layout->replaceWidget(active_tab,
2165 Qt::FindDirectChildrenOnly);
2166 active_tab->hide();
2167 counterss_frame->show();
2168 counterss_frame->updateGeometry();
2170 } else {
2171 /* We do not change prod_unit_splitter to current_tab,
2172 * because counters is active tab and clicked -
2173 * switching to default */
2174 leftbot_layout->replaceWidget(counterss_frame,
2176 Qt::FindDirectChildrenOnly);
2177 prod_unit_splitter->show();
2178 prod_unit_splitter->updateGeometry();
2179 counterss_frame->hide();
2181 }
2182
2183 setUpdatesEnabled(true);
2184 update();
2185 update_tabs();
2186}
2187
2188/************************************************************************/
2192{
2193 struct player *pplayer = client_player();
2194
2195 if (pplayer == nullptr
2196 || city_owner(dlgcity) != pplayer) {
2197 prev_city_but->setDisabled(true);
2198 next_city_but->setDisabled(true);
2199 buy_button->setDisabled(true);
2200 cma_enable_but->setDisabled(true);
2201 production_combo_p->setDisabled(true);
2202 current_units->setDisabled(true);
2203 supported_units->setDisabled(true);
2204 view->setDisabled(true);
2205 } else {
2206 prev_city_but->setEnabled(true);
2207 next_city_but->setEnabled(true);
2208 buy_button->setEnabled(true);
2209 cma_enable_but->setEnabled(true);
2210 production_combo_p->setEnabled(true);
2211 current_units->setEnabled(true);
2212 supported_units->setEnabled(true);
2213 view->setEnabled(true);
2214 }
2215
2217 cma_enable_but->setEnabled(true);
2218 } else {
2219 cma_enable_but->setDisabled(true);
2220 }
2221
2223}
2224
2225/************************************************************************/
2229{
2230 struct player *pplayer = client_player();
2231
2232 work_next_but->setDisabled(true);
2233 work_prev_but->setDisabled(true);
2234 work_add_but->setDisabled(true);
2235 work_rem_but->setDisabled(true);
2236
2237 if (pplayer != nullptr
2238 && city_owner(dlgcity) == pplayer) {
2239 work_add_but->setEnabled(true);
2240
2241 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount()) {
2242 work_rem_but->setEnabled(true);
2243 }
2244
2245 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount() - 1) {
2246 work_next_but->setEnabled(true);
2247 }
2248
2249 if (selected_row_p > 0 && selected_row_p < p_table_p->rowCount()) {
2250 work_prev_but->setEnabled(true);
2251 }
2252 }
2253}
2254
2255/************************************************************************/
2259{
2260 if (citizen_pixmap) {
2261 citizen_pixmap->detach();
2262 delete citizen_pixmap;
2263 }
2264
2265 cma_table->clear();
2266 p_table_p->clear();
2267 nationality_table->clear();
2269 supported_units->clear_layout();
2270 removeEventFilter(this);
2271 ::city_dlg_created = false;
2272
2273 // Delete the one widget that currently does NOT have a parent
2274 if (current_tab == common) {
2275 delete happiness_widget;
2276 delete counterss_frame;
2277 }
2278 else if (current_tab == counters) {
2279 delete happiness_widget;
2280 delete prod_unit_splitter;
2281 }else {
2282 delete counterss_frame;
2283 delete prod_unit_splitter;
2284 }
2285}
2286
2287/************************************************************************/
2291{
2292 gui()->qt_settings.city_geometry = saveGeometry();
2293 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2294 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2295 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2296}
2297
2298/************************************************************************/
2302{
2303 if (!gui()->qt_settings.city_geometry.isNull()) {
2304 restoreGeometry(gui()->qt_settings.city_geometry);
2305 prod_unit_splitter->restoreState(gui()->qt_settings.city_splitter1);
2306 central_left_splitter->restoreState(gui()->qt_settings.city_splitter2);
2307 central_splitter->restoreState(gui()->qt_settings.city_splitter3);
2308 } else {
2309 QRect rect = QApplication::primaryScreen()->availableGeometry();
2310
2311 resize((rect.width() * 4) / 5, (rect.height() * 5) / 6);
2312 }
2313}
2314
2315/************************************************************************/
2319{
2320 gui()->qt_settings.city_geometry = saveGeometry();
2321 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2322 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2323 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2324}
2325
2326/************************************************************************/
2329bool city_dialog::eventFilter(QObject *obj, QEvent *event)
2330{
2331
2332 if (obj == this) {
2333 if (event->type() == QEvent::KeyPress) {
2334 }
2335
2336 if (event->type() == QEvent::ShortcutOverride) {
2337 QKeyEvent *key_event = static_cast<QKeyEvent *>(event);
2338 if (key_event->key() == Qt::Key_Right) {
2339 next_city();
2340 event->setAccepted(true);
2341 return true;
2342 }
2343 if (key_event->key() == Qt::Key_Left) {
2344 prev_city();
2345 event->setAccepted(true);
2346 return true;
2347 }
2348 if (key_event->key() == Qt::Key_Up) {
2349 change_production(true);
2350 event->setAccepted(true);
2351 return true;
2352 }
2353 if (key_event->key() == Qt::Key_Down) {
2354 change_production(false);
2355 event->setAccepted(true);
2356 return true;
2357 }
2358 }
2359 }
2360 return QObject::eventFilter(obj, event);
2361}
2362
2363/************************************************************************/
2367{
2369 const int city_id = dlgcity->id;
2370
2371 if (!can_client_issue_orders()) {
2372 return;
2373 }
2374
2375 ask = new hud_input_box(gui()->central_wdg);
2376 ask->set_text_title_definput(_("What should we rename the city to?"),
2377 _("Rename City"), city_name_get(dlgcity));
2378 ask->setAttribute(Qt::WA_DeleteOnClose);
2379 connect(ask, &hud_message_box::accepted, this, [=]() {
2380 struct city *pcity = game_city_by_number(city_id);
2382
2383 if (!pcity) {
2384 return;
2385 }
2386
2387 ask_bytes = ask->input_edit.text().toUtf8();
2388 ::city_rename(pcity, ask_bytes.data());
2389 });
2390 ask->show();
2391}
2392
2393/************************************************************************/
2397{
2398 zoom = zoom * 1.2;
2399 if (dlgcity) {
2400 view->set_pixmap(dlgcity, zoom);
2401 }
2403 left_layout->update();
2404}
2405
2406/************************************************************************/
2410{
2411 zoom = zoom / 1.2;
2412 if (dlgcity) {
2413 view->set_pixmap(dlgcity, zoom);
2414 }
2416 left_layout->update();
2417}
2418
2419/************************************************************************/
2423{
2424 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
2425
2426 ask->set_text_title_definput(_("What should we name the preset?"),
2427 _("Name new preset"),
2428 _("new preset"));
2429 ask->setAttribute(Qt::WA_DeleteOnClose);
2430 connect(ask, &hud_message_box::accepted, this,
2432 struct cm_parameter param;
2433 QByteArray ask_bytes = ask->input_edit.text().toUtf8();
2434 QString text = ask_bytes.data();
2435 if (!text.isEmpty()) {
2436 param.allow_disorder = false;
2437 param.allow_specialists = true;
2438 param.require_happy = cma_celeb_checkbox->isChecked();
2439 param.max_growth = cma_max_growth->isChecked();
2440 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2441
2442 for (int i = O_FOOD; i < O_LAST; i++) {
2443 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2444 param.factor[i] = slider_tab[2 * i + 1]->value();
2445 }
2446
2447 ask_bytes = text.toUtf8();
2448 cmafec_preset_add(ask_bytes.data(), &param);
2450 }
2451 });
2452 ask->show();
2453}
2454
2455/************************************************************************/
2459{
2460 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2462
2463 return;
2464 }
2465
2466 cma_changed();
2468}
2469
2470/************************************************************************/
2474{
2475 struct cm_parameter param;
2476
2477 param.allow_disorder = false;
2478 param.allow_specialists = true;
2479 param.require_happy = cma_celeb_checkbox->isChecked();
2480 param.max_growth = cma_max_growth->isChecked();
2481 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2482
2483 for (int i = O_FOOD; i < O_LAST; i++) {
2484 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2485 param.factor[i] = slider_tab[2 * i + 1]->value();
2486 }
2487
2489}
2490
2491/************************************************************************/
2495{
2496 const struct cm_parameter *param;
2497
2498 if (!can_client_issue_orders()) {
2499 return;
2500 }
2502 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2504 }
2505
2508}
2509
2510/************************************************************************/
2514 const QItemSelection &ds)
2515{
2516 const struct cm_parameter *param;
2517 QModelIndex index;
2518 QModelIndexList indexes = sl.indexes();
2519
2520 if (indexes.isEmpty() || cma_table->signalsBlocked()) {
2521 return;
2522 }
2523
2524 index = indexes.at(0);
2525 int ind = index.row();
2526
2527 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2528 return;
2529 }
2530
2533
2534 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2537 }
2538}
2539
2540/************************************************************************/
2544{
2545 struct cm_parameter param;
2546 const struct cm_parameter *cparam;
2547 int output;
2548 QVariant qvar;
2549 QLabel *label;
2550
2551 if (!cma_is_city_under_agent(dlgcity, &param)) {
2552 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2553 return;
2554 }
2556 cm_copy_parameter(&param, cparam);
2557 }
2558
2559 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2560 slider_tab[output]->blockSignals(true);
2561 }
2562
2563 for (output = O_FOOD; output < O_LAST; output++) {
2564 qvar = slider_tab[2 * output + 1]->property("FC");
2565 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2566 label->setText(QString::number(param.factor[output]));
2567 slider_tab[2 * output + 1]->setValue(param.factor[output]);
2568 qvar = slider_tab[2 * output]->property("FC");
2569 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2570 label->setText(QString::number(param.minimal_surplus[output]));
2571 slider_tab[2 * output]->setValue(param.minimal_surplus[output]);
2572 }
2573
2574 slider_tab[2 * O_LAST + 1]->blockSignals(true);
2575 qvar = slider_tab[2 * O_LAST + 1]->property("FC");
2576 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2577 label->setText(QString::number(param.happy_factor));
2578 slider_tab[2 * O_LAST + 1]->setValue(param.happy_factor);
2579 slider_tab[2 * O_LAST + 1]->blockSignals(false);
2580 cma_celeb_checkbox->blockSignals(true);
2581 cma_celeb_checkbox->setChecked(param.require_happy);
2582 cma_celeb_checkbox->blockSignals(false);
2583 cma_max_growth->blockSignals(true);
2584 cma_max_growth->setChecked(param.max_growth);
2585 cma_max_growth->blockSignals(false);
2586
2587 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2588 slider_tab[output]->blockSignals(false);
2589 }
2590}
2591
2592/************************************************************************/
2596{
2597 QString s;
2599 struct cm_parameter param;
2600 QPixmap pix;
2601 int i;
2602
2603 cma_table->clear();
2604 cma_table->setRowCount(0);
2605
2606 for (i = 0; i < cmafec_preset_num(); i++) {
2607 item = new QTableWidgetItem;
2608 item->setText(cmafec_preset_get_descr(i));
2609 cma_table->insertRow(i);
2610 cma_table->setItem(i, 0, item);
2611 }
2612
2613 if (cmafec_preset_num() == 0) {
2614 cma_table->insertRow(0);
2615 item = new QTableWidgetItem;
2616 item->setText(_("No governor defined"));
2617 cma_table->setItem(0, 0, item);
2618 }
2619
2620 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2621 view->update();
2623 pix = style()->standardPixmap(QStyle::SP_DialogApplyButton);
2624 pix = pix.scaled(2 * pix.width(), 2 * pix.height(),
2625 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2626 cma_result_pix->setPixmap(pix);
2627 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2628 // TRANS: %1 is custom string chosen by player
2629 cma_result->setText(QString(_("<h3>Governor Enabled<br>(%1)</h3>"))
2630 .arg(s.toHtmlEscaped()));
2631 cma_result->setAlignment(Qt::AlignCenter);
2632 } else {
2633 pix = style()->standardPixmap(QStyle::SP_DialogCancelButton);
2634 pix = pix.scaled(1.6 * pix.width(), 1.6 * pix.height(),
2635 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2636 cma_result_pix->setPixmap(pix);
2637 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2638 cma_result->setText(QString(_("<h3>Governor Disabled</h3>")));
2639 cma_result->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
2640 }
2641
2642 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2645 cm_parameter *const >(&param));
2646 if (i >= 0 && i < cma_table->rowCount()) {
2647 cma_table->blockSignals(true);
2648 cma_table->setCurrentCell(i, 0);
2649 cma_table->blockSignals(false);
2650 }
2651
2652 cma_enable_but->setText(_("Disable"));
2653 } else {
2654 cma_enable_but->setText(_("Enable"));
2655 }
2657}
2658
2659/************************************************************************/
2663{
2664 int i;
2666
2667 i = cma_table->currentRow();
2668
2669 if (i == -1 || cmafec_preset_num() == 0) {
2670 return;
2671 }
2672
2674 ask->set_text_title(_("Remove this preset?"), cmafec_preset_get_descr(i));
2675 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
2676 ask->setDefaultButton(QMessageBox::Cancel);
2677 ask->setAttribute(Qt::WA_DeleteOnClose);
2678 connect(ask, &hud_message_box::accepted, this,
2682 });
2683 ask->show();
2684}
2685
2686/************************************************************************/
2689void city_dialog::cma_toggle_changed(Qt::CheckState state)
2690{
2691 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2692 cma_changed();
2694 }
2695}
2696
2697/************************************************************************/
2702{
2703 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2704 cma_changed();
2706 }
2707}
2708
2709/************************************************************************/
2713{
2714 QVariant qvar;
2715 QSlider *slider;
2716 QLabel *label;
2717
2719 qvar = slider->property("FC");
2720
2721 if (qvar.isNull() || !qvar.isValid()) {
2722 return;
2723 }
2724
2725 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2726 label->setText(QString::number(value));
2727
2728 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2729 cma_changed();
2731 }
2732}
2733
2734/************************************************************************/
2754
2755/************************************************************************/
2759{
2760 QMenu *cma_menu = new QMenu(this);
2762
2763 cma_menu->setAttribute(Qt::WA_DeleteOnClose);
2764 cma_del_item = cma_menu->addAction(_("Remove Governor"));
2765 connect(cma_menu, &QMenu::triggered, this,
2767 if (act == cma_del_item) {
2768 cma_remove();
2769 }
2770 });
2771
2772 cma_menu->popup(QCursor::pos());
2773}
2774
2775/************************************************************************/
2779{
2780 QAction *action;
2781 QAction *disband;
2786 QMap<QString, cid>::const_iterator map_iter;
2787 QMenu *change_menu;
2788 QMenu *insert_menu;
2789 QMenu *list_menu;
2790 QMenu *options_menu;
2791 int city_id = dlgcity->id;
2792
2793 if (!can_client_issue_orders()) {
2794 return;
2795 }
2796 list_menu = new QMenu(this);
2797 change_menu = list_menu->addMenu(_("Change worklist"));
2798 insert_menu = list_menu->addMenu(_("Insert worklist"));
2799 wl_clear = list_menu->addAction(_("Clear"));
2800 connect(wl_clear, &QAction::triggered, this, &city_dialog::clear_worklist);
2801 list.clear();
2802
2806
2807 if (list.count() == 0) {
2808 wl_empty = change_menu->addAction(_("(no worklists defined)"));
2809 insert_menu->addAction(wl_empty);
2810 }
2811
2812 map_iter = list.constBegin();
2813
2814 while (map_iter != list.constEnd()) {
2815 action = change_menu->addAction(map_iter.key());
2816 action->setData(map_iter.value());
2817
2818 action = insert_menu->addAction(map_iter.key());
2819 action->setData(map_iter.value());
2820
2821 map_iter++;
2822 }
2823
2824 wl_save = list_menu->addAction(_("Save worklist"));
2825 connect(wl_save, &QAction::triggered, this, &city_dialog::save_worklist);
2826 options_menu = list_menu->addMenu(_("Options"));
2827 disband = options_menu->addAction(_("Allow disbanding city"));
2828 disband->setCheckable(true);
2829 disband->setChecked(is_city_option_set(dlgcity, CITYO_DISBAND));
2830 connect(disband, &QAction::triggered, this,
2832
2833 connect(change_menu, &QMenu::triggered, this, [=](QAction *act) {
2834 QVariant id = act->data();
2835 struct city *pcity = game_city_by_number(city_id);
2836 const struct worklist *worklist;
2837
2838 if (!pcity) {
2839 return;
2840 }
2841
2842 fc_assert_ret(id.typeId() == QMetaType::Int);
2843
2846 });
2847
2848 connect(insert_menu, &QMenu::triggered, this,
2850 QVariant id = act->data();
2851 struct city *pcity = game_city_by_number(city_id);
2852 const struct worklist *worklist;
2853
2854 if (!pcity) {
2855 return;
2856 }
2857
2858 fc_assert_ret(id.typeId() == QMetaType::Int);
2859
2862 });
2863
2864 list_menu->popup(QCursor::pos());
2865}
2866
2867/************************************************************************/
2871{
2872 QString str;
2873 int value;
2874 struct player *pplayer = client_player();
2875
2876 buy_button->setDisabled(true);
2877
2878 if (!client_is_observer() && pplayer != nullptr) {
2879 value = dlgcity->client.buy_cost;
2880 str = QString(PL_("Buy (%1 gold)", "Buy (%1 gold)",
2881 value)).arg(QString::number(value));
2882
2883 if (pplayer->economic.gold >= value && value != 0) {
2884 buy_button->setEnabled(true);
2885 }
2886 } else {
2887 str = QString(_("Buy"));
2888 }
2889
2890 buy_button->setText(str);
2891}
2892
2893/************************************************************************/
2897{
2898 enum citizen_category categories[MAX_CITY_SIZE];
2899 int i, j, width, height;
2900 QPainter p;
2901 QPixmap *pix;
2903 int num_supers
2905 ARRAY_SIZE(categories) - num_citizens,
2906 &categories[num_citizens]);
2907
2908 int w = tileset_small_sprite_width(tileset) / gui()->map_scale;
2909 int h = tileset_small_sprite_height(tileset) / gui()->map_scale;
2910
2911 if (num_supers >= 0) {
2912 /* Just draw superspecialists in the common roster */
2914 } else {
2915 /* FIXME: show them in some compact way */
2916 num_citizens = ARRAY_SIZE(categories);
2917 }
2918 i = 1 + (num_citizens * 5 / 200);
2919 w = w / i;
2920 QRect source_rect(0, 0, w, h);
2921 QRect dest_rect(0, 0, w, h);
2922 width = w * num_citizens;
2923 height = h;
2924
2925 if (citizen_pixmap) {
2926 citizen_pixmap->detach();
2927 delete citizen_pixmap;
2928 }
2929
2931
2932 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2933 dest_rect.moveTo(i * w, 0);
2934 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2935 p.begin(citizen_pixmap);
2936 p.drawPixmap(dest_rect, *pix, source_rect);
2937 p.end();
2938 }
2939
2941 citizens_label->setPixmap(*citizen_pixmap);
2942
2945
2946 for (int k = 0; k < FEELING_LAST - 1; k++) {
2949 static_cast<citizen_feeling>(k),
2950 categories);
2951
2952 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2953 dest_rect.moveTo(i * w, 0);
2954 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2955 p.begin(citizen_pixmap);
2956 p.drawPixmap(dest_rect, *pix, source_rect);
2957 p.end();
2958 }
2959
2960 lab_table[k]->setPixmap(*citizen_pixmap);
2961
2962 switch (k) {
2963 case FEELING_BASE:
2964 lab_table[k]->setToolTip(text_happiness_cities(dlgcity));
2965 break;
2966
2967 case FEELING_LUXURY:
2968 lab_table[k]->setToolTip(text_happiness_luxuries(dlgcity));
2969 break;
2970
2971 case FEELING_EFFECT :
2973 break;
2974
2977 break;
2978
2979 case FEELING_MARTIAL:
2980 lab_table[k]->setToolTip(text_happiness_units(dlgcity));
2981 break;
2982
2983 default:
2984 break;
2985 }
2986 }
2987}
2988
2989/************************************************************************/
2993{
2994 setUpdatesEnabled(false);
2995 production_combo_p->blockSignals(true);
2996
2997 if (dlgcity) {
2998 view->set_pixmap(dlgcity, zoom);
2999 view->update();
3000 update_title();
3007 update_units();
3011 } else {
3013 }
3014
3015 production_combo_p->blockSignals(false);
3016 setUpdatesEnabled(true);
3018 update();
3019}
3020
3021/************************************************************************/
3025{
3026 QFont *small_font;
3027
3029
3030 qDeleteAll(counterss_frame->findChildren<QWidget*>("", Qt::FindDirectChildrenOnly));
3032 QString helptext;
3033 char buf[1024];
3034 QLabel *name, *value, *activated, *help;
3035
3036 name = new QLabel(name_translation_get(&pcount->name));
3037 fc_snprintf(buf, sizeof(buf), _("Current value is: %d"),
3039 value = new QLabel(buf);
3040 fc_snprintf(buf, sizeof(buf), _("Activated once value equal "
3041 "or higher than: %d"),
3042 pcount->checkpoint);
3043 activated = new QLabel(buf);
3044 if (pcount->helptext != nullptr) {
3045 strvec_iterate(pcount->helptext, text_) {
3046 helptext += text_;
3048 }
3049 help = new QLabel(helptext);
3050
3051 name->setFont(*small_font);
3052 value->setFont(*small_font);
3053 activated->setFont(*small_font);
3054 help->setFont(*small_font);
3055
3056 counterss_layout->addWidget(name);
3057 counterss_layout->addWidget(value);
3058 counterss_layout->addWidget(activated);
3059 counterss_layout->addWidget(help);
3061}
3062
3063/************************************************************************/
3067{
3068 QFont f = QApplication::font();
3069 QFontMetrics fm(f);
3070 QPixmap *pix = nullptr;
3072 QString str;
3075 char buf[8];
3077 int h;
3078 int i = 0;
3079 struct sprite *sprite;
3080
3081 h = fm.height() + 6;
3082 nationality_table->clear();
3083 nationality_table->setRowCount(0);
3084 info_list.clear();
3085 info_list << _("#") << _("Flag") << _("Nation");
3086 nationality_table->setHorizontalHeaderLabels(info_list);
3087
3088 citizens_iterate(dlgcity, pslot, nationality) {
3089 nationality_table->insertRow(i);
3090
3091 for (int j = 0; j < nationality_table->columnCount(); j++) {
3092 item = new QTableWidgetItem;
3093
3094 switch (j) {
3095 case 0:
3097
3098 if (nationality_i == 0) {
3099 str = "-";
3100 } else {
3101 fc_snprintf(buf, sizeof(buf), "%d", nationality_i);
3102 str = QString(buf);
3103 }
3104
3105 item->setText(str);
3106 break;
3107
3108 case 1:
3111 (player_slot_get_player(pslot)));
3112
3113 if (sprite != nullptr) {
3114 pix = sprite->pm;
3115 pix_scaled = pix->scaledToHeight(h);
3116 item->setData(Qt::DecorationRole, pix_scaled);
3117 } else {
3118 item->setText("FLAG MISSING");
3119 }
3120 break;
3121
3122 case 2:
3124 (player_slot_get_player(pslot)));
3125 break;
3126
3127 default:
3128 break;
3129 }
3130 nationality_table->setItem(i, j, item);
3131 }
3132 i++;
3134 nationality_table->horizontalHeader()->setStretchLastSection(false);
3135 nationality_table->resizeColumnsToContents();
3136 nationality_table->resizeRowsToContents();
3137 nationality_table->horizontalHeader()->setStretchLastSection(true);
3138}
3139
3140/************************************************************************/
3144{
3145 int illness = 0;
3146 char buffer[512];
3147 char buf_info[NUM_INFO_FIELDS][512];
3148 char buf_tooltip[NUM_INFO_FIELDS][512];
3149 int granaryturns;
3150 int spec, supers;
3151
3152 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3153 buf_info[i][0] = '\0';
3154 buf_tooltip[i][0] = '\0';
3155 }
3156
3157 // Fill the buffers with the necessary info
3158 spec = city_specialists(dlgcity);
3160
3162 "%3d (%4d)", dlgcity->size, spec);
3163 if (supers) {
3165 _("Population: %d, Specialists: %d + %d"),
3166 dlgcity->size, spec, supers);
3167 } else {
3169 _("Population: %d, Specialists: %d"),
3170 dlgcity->size, spec);
3171 }
3172 fc_snprintf(buf_info[INFO_FOOD], sizeof(buf_info[INFO_FOOD]), "%3d (%+4d)",
3175 "%3d (%+4d)", dlgcity->prod[O_SHIELD] + dlgcity->waste[O_SHIELD],
3177 fc_snprintf(buf_info[INFO_TRADE], sizeof(buf_info[INFO_TRADE]), "%3d (%+4d)",
3180 fc_snprintf(buf_info[INFO_GOLD], sizeof(buf_info[INFO_GOLD]), "%3d (%+4d)",
3187 "%4d/%-4d", dlgcity->food_stock,
3189
3191 sizeof(buf_tooltip[INFO_FOOD]));
3193 sizeof(buf_tooltip[INFO_SHIELD]));
3195 sizeof(buf_tooltip[INFO_TRADE]));
3197 sizeof(buf_tooltip[INFO_GOLD]));
3199 sizeof(buf_tooltip[INFO_SCIENCE]));
3201 sizeof(buf_tooltip[INFO_LUXURY]));
3203 sizeof(buf_tooltip[INFO_CULTURE]));
3205 sizeof(buf_tooltip[INFO_POLLUTION]));
3207 sizeof(buf_tooltip[INFO_ILLNESS]));
3208
3210
3211 if (granaryturns == 0) {
3212 // TRANS: city growth is blocked. Keep short.
3213 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("blocked"));
3214 } else if (granaryturns == FC_INFINITY) {
3215 // TRANS: city is not growing. Keep short.
3216 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("never"));
3217 } else {
3218 /* A negative value means we'll have famine in that many turns.
3219 But that's handled down below. */
3220 // TRANS: city growth turns. Keep short.
3222 PL_("%d turn", "%d turns", abs(granaryturns)),
3223 abs(granaryturns));
3224 }
3225
3227 "%4d", dlgcity->waste[O_TRADE]);
3234
3235 if (!game.info.illness_on) {
3237 " -.-");
3238 } else {
3239 illness = city_illness_calc(dlgcity, nullptr, nullptr, nullptr, nullptr);
3240 // Illness is in tenth of percent
3242 "%5.1f%%", (float) illness / 10.0);
3243 }
3244 if (dlgcity->steal) {
3246 PL_("%d time", "%d times", dlgcity->steal), dlgcity->steal);
3247 } else {
3249 _("Not stolen"));
3250 }
3251
3253 sizeof(buf_info[INFO_AIRLIFT]));
3255 sizeof(buf_tooltip[INFO_AIRLIFT]));
3256
3257 get_city_dialog_output_text(dlgcity, O_FOOD, buffer, sizeof(buffer));
3258
3259 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3260 qlt[i]->setText(QString(buf_info[i]));
3261
3262 if (buf_tooltip[i][0]) {
3263 qlt[i]->setToolTip("<pre>" + QString(buf_tooltip[i]).toHtmlEscaped()
3264 + "</pre>");
3265 }
3266 }
3267}
3268
3269/************************************************************************/
3273{
3276
3277 setContentsMargins(0, 0 ,0 ,0);
3279 dlgcity = qcity;
3280 production_combo_p->blockSignals(true);
3281 refresh();
3282 production_combo_p->blockSignals(false);
3283}
3284
3285/************************************************************************/
3289{
3290 struct worklist queue;
3291
3292 city_get_queue(dlgcity, &queue);
3293
3295 return;
3296 }
3297
3299 city_set_queue(dlgcity, &queue);
3300}
3301
3302/************************************************************************/
3306{
3307 unit_item *ui;
3308 struct unit_list *units;
3309 char buf[256];
3310 int n;
3311 int happy_cost;
3313 struct player *pplayer = client_player();
3314 const struct civ_map *nmap = &(wld.map);
3315
3316 supported_units->setUpdatesEnabled(false);
3317 supported_units->clear_layout();
3318
3319 if (pplayer != nullptr
3320 && city_owner(dlgcity) != pplayer) {
3322 } else {
3323 units = dlgcity->units_supported;
3324 }
3325
3326 unit_list_iterate(units, punit) {
3328 ui = new unit_item(this, punit, true, happy_cost);
3329 ui->init_pix();
3330 supported_units->add_item(ui);
3332 n = unit_list_size(units);
3333 fc_snprintf(buf, sizeof(buf), _("Supported units %d"), n);
3334 supp_units->setText(QString(buf));
3335 supported_units->update_units();
3336 supported_units->setUpdatesEnabled(true);
3337 current_units->setUpdatesEnabled(true);
3339
3340 if (pplayer != nullptr
3341 && city_owner(dlgcity) != pplayer) {
3343 } else {
3344 units = dlgcity->tile->units;
3345 }
3346
3347 unit_list_iterate(units, punit) {
3348 ui = new unit_item(this , punit, false);
3349 ui->init_pix();
3352
3353 n = unit_list_size(units);
3354 fc_snprintf(buf, sizeof(buf), _("Present units %d"), n);
3355 curr_units->setText(QString(buf));
3356
3358 current_units->setUpdatesEnabled(true);
3359}
3360
3361/************************************************************************/
3365 const QItemSelection &ds)
3366{
3367 QModelIndex index;
3368 QModelIndexList indexes = sl.indexes();
3369
3370 if (indexes.isEmpty()) {
3371 return;
3372 }
3373
3374 index = indexes.at(0);
3375 selected_row_p = index.row();
3377}
3378
3379/************************************************************************/
3383{
3384 int size, i;
3385 struct city *other_pcity = nullptr;
3386 struct player *pplayer = client_player();
3387
3388 if (pplayer == nullptr) {
3389 return;
3390 }
3391
3392 size = city_list_size(pplayer->cities);
3393
3394 if (size <= 1) {
3395 return;
3396 }
3397
3398 for (i = 0; i < size; i++) {
3399 if (dlgcity == city_list_get(pplayer->cities, i)) {
3400 break;
3401 }
3402 }
3403
3404 if (i >= size - 1) {
3405 // Current city last in the list (size - 1) or disappeared (size)
3406 other_pcity = city_list_get(pplayer->cities, 0);
3407 } else {
3408 other_pcity = city_list_get(pplayer->cities, i + 1);
3409 }
3410
3413}
3414
3415/************************************************************************/
3419{
3420 int size, i;
3421 struct city *other_pcity = nullptr;
3422 struct player *pplayer = client_player();
3423
3424 if (pplayer == nullptr) {
3425 return;
3426 }
3427
3428 size = city_list_size(pplayer->cities);
3429
3430 if (size <= 1) {
3431 return;
3432 }
3433
3434 for (i = 0; i < size; i++) {
3435 if (dlgcity == city_list_get(pplayer->cities, i)) {
3436 break;
3437 }
3438 }
3439
3440 if (i == 0 || i == size) {
3441 // Current city in the beginning of the list or disappeared
3442 other_pcity = city_list_get(pplayer->cities, size - 1);
3443 } else {
3444 other_pcity = city_list_get(pplayer->cities, i - 1);
3445 }
3446
3449}
3450
3451/************************************************************************/
3455{
3456 char buf[32];
3457 QString str;
3459
3461 production_combo_p->setRange(0, cost);
3463 if (dlgcity->shield_stock >= cost) {
3464 production_combo_p->setValue(cost);
3465 } else {
3467 }
3468 production_combo_p->setAlignment(Qt::AlignCenter);
3469 str = QString(buf);
3470 str = str.simplified();
3471
3472 production_combo_p->setFormat(QString("(%p%) %2\n%1")
3474 str));
3475
3476 production_combo_p->updateGeometry();
3477
3478}
3479
3480/************************************************************************/
3484{
3485 char buf[1024], buf2[1024];
3487 int value = dlgcity->client.buy_cost;
3489 int city_id = dlgcity->id;
3490
3491 if (!can_client_issue_orders()) {
3492 return;
3493 }
3494
3496 fc_snprintf(buf2, ARRAY_SIZE(buf2), PL_("Treasury contains %d gold.",
3497 "Treasury contains %d gold.",
3498 client_player()->economic.gold),
3499 client_player()->economic.gold);
3500 fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Buy %s for %d gold?",
3501 "Buy %s for %d gold?", value),
3502 name, value);
3503 ask->set_text_title(buf, buf2);
3504 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
3505 ask->setDefaultButton(QMessageBox::Cancel);
3506 ask->setAttribute(Qt::WA_DeleteOnClose);
3507 connect(ask, &hud_message_box::accepted, this, [=]() {
3508 struct city *pcity = game_city_by_number(city_id);
3509
3510 if (!pcity) {
3511 return;
3512 }
3513
3515 });
3516 ask->show();
3517}
3518
3519/************************************************************************/
3523{
3524 QFont f = QApplication::font();
3525 QFontMetrics fm(f);
3526 QPixmap *pix = nullptr;
3530 struct sprite *sprite;
3531 int h, cost, item, targets_used, col, upkeep;
3532 struct item items[MAX_NUM_PRODUCTION_TARGETS];
3533 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
3534 struct worklist queue;
3535 impr_item *ui;
3536
3537 upkeep = 0;
3538 city_buildings->setUpdatesEnabled(false);
3540
3541 h = fm.height() + 6;
3543 name_and_sort_items(targets, targets_used, items, false, dlgcity);
3544
3545 for (item = 0; item < targets_used; item++) {
3546 struct universal target = items[item].item;
3547
3548 ui = new impr_item(this, target.value.building, dlgcity);
3549 ui->init_pix();
3551
3552 fc_assert_action(VUT_IMPROVEMENT == target.kind, continue);
3554 upkeep = upkeep + city_improvement_upkeep(dlgcity, target.value.building);
3555 if (sprite != nullptr) {
3556 pix = sprite->pm;
3557 pix_scaled = pix->scaledToHeight(h);
3558 }
3559 }
3560
3561 city_get_queue(dlgcity, &queue);
3562 p_table_p->setRowCount(worklist_length(&queue));
3563
3564 for (int i = 0; i < worklist_length(&queue); i++) {
3565 struct universal target = queue.entries[i];
3566
3567 tooltip = "";
3568
3569 if (VUT_UTYPE == target.kind) {
3571 cost = utype_build_shield_cost(dlgcity, nullptr, target.value.utype);
3572 tooltip = get_tooltip_unit(target.value.utype, true).trimmed();
3576 } else {
3580 dlgcity, true).trimmed();
3581
3583 cost = -1;
3584 } else {
3586 }
3587 }
3588
3589 for (col = 0; col < 3; col++) {
3590 qitem = new QTableWidgetItem();
3591 qitem->setToolTip(tooltip);
3592
3593 switch (col) {
3594 case 0:
3595 if (sprite) {
3596 pix = sprite->pm;
3597 pix_scaled = pix->scaledToHeight(h);
3598 qitem->setData(Qt::DecorationRole, pix_scaled);
3599 }
3600 break;
3601
3602 case 1:
3603 if (str.contains('[') && str.contains(']')) {
3604 int ii, ij;
3605
3606 ii = str.lastIndexOf('[');
3607 ij = str.lastIndexOf(']');
3608 if (ij > ii) {
3609 str = str.remove(ii, ij - ii + 1);
3610 }
3611 }
3612 qitem->setText(str);
3613 break;
3614
3615 case 2:
3616 qitem->setTextAlignment(Qt::AlignRight);
3617 qitem->setText(QString::number(cost));
3618 break;
3619 }
3620 p_table_p->setItem(i, col, qitem);
3621 }
3622 }
3623
3624 p_table_p->horizontalHeader()->setStretchLastSection(false);
3625 p_table_p->resizeColumnsToContents();
3626 p_table_p->resizeRowsToContents();
3627 p_table_p->horizontalHeader()->setStretchLastSection(true);
3628
3630 city_buildings->setUpdatesEnabled(true);
3631 city_buildings->setUpdatesEnabled(true);
3632
3633 curr_impr->setText(QString(_("Improvements - upkeep %1")).arg(upkeep));
3634}
3635
3636/************************************************************************/
3640{
3641 cid id;
3642 QVariant qvar;
3643
3645 struct universal univ;
3646
3647 id = qvar.toInt();
3648 univ = cid_production(id);
3650 }
3651}
3652
3653/************************************************************************/
3658{
3660 int when = 1;
3661
3662 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3663 when, selected_row_p, show_units->isChecked(),
3664 false, show_wonders->isChecked(),
3665 show_buildings->isChecked());
3666 pw->show();
3667}
3668
3669/************************************************************************/
3674{
3676 int when = 4;
3677
3678 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3679 when, selected_row_p, show_units->isChecked(),
3680 false, show_wonders->isChecked(),
3681 show_buildings->isChecked());
3682 pw->show();
3683}
3684
3685/************************************************************************/
3689{
3690 struct worklist empty;
3691
3692 if (!can_client_issue_orders()) {
3693 return;
3694 }
3695
3698}
3699
3700/************************************************************************/
3704{
3705 QModelIndex index;
3706 struct worklist queue;
3707 struct universal *target;
3708
3710 return;
3711 }
3712
3713 target = new universal;
3714 city_get_queue(dlgcity, &queue);
3715 worklist_peek_ith(&queue, target, selected_row_p);
3717 worklist_insert(&queue, target, selected_row_p - 1);
3718 city_set_queue(dlgcity, &queue);
3719 index = p_table_p->model()->index(selected_row_p - 1, 0);
3720 p_table_p->setCurrentIndex(index);
3721 delete target;
3722
3723}
3724
3725/************************************************************************/
3729{
3731
3732 if (selected_row_p < 0
3733 || selected_row_p >= p_table_p->rowCount()) {
3734 return;
3735 }
3736
3740}
3741
3742/************************************************************************/
3746{
3747 QModelIndex index;
3748 struct worklist queue;
3749 struct universal *target;
3750
3752 return;
3753 }
3754
3755 target = new universal;
3756 city_get_queue(dlgcity, &queue);
3757 worklist_peek_ith(&queue, target, selected_row_p);
3759 worklist_insert(&queue, target, selected_row_p + 1);
3760 city_set_queue(dlgcity, &queue);
3761 index = p_table_p->model()->index(selected_row_p + 1, 0);
3762 p_table_p->setCurrentIndex(index);
3763 delete target;
3764}
3765
3766/************************************************************************/
3770{
3771 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
3772 int city_id = dlgcity->id;
3773
3774 ask->set_text_title_definput(_("What should we name new worklist?"),
3775 _("Save current worklist"),
3776 _("New worklist"));
3777 ask->setAttribute(Qt::WA_DeleteOnClose);
3778 connect(ask, &hud_message_box::accepted, [=]() {
3779 struct global_worklist *gw;
3780 struct worklist queue;
3782 QString text;
3783 struct city *pcity = game_city_by_number(city_id);
3784
3785 ask_bytes = ask->input_edit.text().toUtf8();
3786 text = ask_bytes.data();
3787 if (!text.isEmpty()) {
3788 ask_bytes = text.toUtf8();
3790 city_get_queue(pcity, &queue);
3791 global_worklist_set(gw, &queue);
3792 }
3793 });
3794 ask->show();
3795}
3796
3797/************************************************************************/
3801{
3802 QString buf;
3803
3804 // Defeat keyboard shortcut mnemonics
3806 .replace("&", "&&"));
3807
3808 if (city_unhappy(dlgcity)) {
3809 // TRANS: city dialog title
3810 buf = QString(_("%1 - %2 citizens - DISORDER")).arg(city_name_getx(dlgcity),
3812 } else if (city_celebrating(dlgcity)) {
3813 // TRANS: city dialog title
3814 buf = QString(_("%1 - %2 citizens - celebrating")).arg(city_name_getx(dlgcity),
3816 } else if (city_happy(dlgcity)) {
3817 // TRANS: city dialog title
3818 buf = QString(_("%1 - %2 citizens - happy")).arg(city_name_getx(dlgcity),
3820 } else {
3821 // TRANS: city dialog title
3822 buf = QString(_("%1 - %2 citizens")).arg(city_name_getx(dlgcity),
3824 }
3825
3827}
3828
3829/************************************************************************/
3834{
3835 if (!::city_dlg_created) {
3836 ::city_dlg = new city_dialog(gui()->mapview_wdg);
3837 }
3838
3840 city_dlg->show();
3841 city_dlg->activateWindow();
3842 city_dlg->raise();
3843}
3844
3845/************************************************************************/
3849{
3850 if (!::city_dlg_created) {
3851 return;
3852 }
3853
3854 city_dlg->close();
3855 ::city_dlg_created = false;
3856}
3857
3858/************************************************************************/
3862{
3863 if (!::city_dlg_created) {
3864 return;
3865 }
3866
3868}
3869
3870/************************************************************************/
3877
3878/************************************************************************/
3882{
3883 if (!::city_dlg_created) {
3884 return;
3885 }
3886
3888 city_dlg->refresh();
3889 }
3890}
3891
3892/************************************************************************/
3896{
3898 QFont *f;
3899
3900 if (!::city_dlg_created) {
3901 return;
3902 }
3903
3904 l = city_dlg->findChildren<QLabel *>();
3905
3907
3908 for (int i = 0; i < l.size(); ++i) {
3909 if (l.at(i)->property(fonts::notify_label).isValid()) {
3910 l.at(i)->setFont(*f);
3911 }
3912 }
3913}
3914
3915/************************************************************************/
3932
3933/************************************************************************/
3937{
3938 if (!::city_dlg_created) {
3939 return false;
3940 }
3941
3942 if (city_dlg->dlgcity == pcity && city_dlg->isVisible()) {
3943 return true;
3944 }
3945
3946 return false;
3947}
3948
3949/************************************************************************/
3952bool fc_tooltip::eventFilter(QObject *obj, QEvent *ev)
3953{
3956 QRect rect;
3957
3958 if (ev->type() == QEvent::ToolTip) {
3960
3961 if (!view) {
3962 return false;
3963 }
3964
3965 help_event = static_cast<QHelpEvent *>(ev);
3966 QPoint pos = help_event->pos();
3967 QModelIndex index = view->indexAt(pos);
3968 QPoint hpos;
3969
3970 if (!index.isValid()) {
3971 return false;
3972 }
3973
3974 item_tooltip = view->model()->data(index, Qt::ToolTipRole).toString();
3975 rect = view->visualRect(index);
3976
3977 hpos = help_event->globalPos();
3978
3979 rect.setX(rect.x() + hpos.x());
3980 rect.setY(rect.y() + hpos.y());
3981
3982 if (!item_tooltip.isEmpty()) {
3983 QToolTip::showText(help_event->globalPos(), item_tooltip, view, rect);
3984 } else {
3985 QToolTip::hideText();
3986 }
3987
3988 return true;
3989 }
3990
3991 return false;
3992}
3993
3994/************************************************************************/
3998{
3999 return QString("<b>" + text + "</b>");
4000}
4001
4002/************************************************************************/
4007 bool ext)
4008{
4010 QString upkeep;
4011 QString s1, s2, str;
4012 const char *req = skip_intl_qualifier_prefix(_("?tech:None"));
4013 struct player *pplayer = client_player();
4014
4015 if (pcity != nullptr) {
4016 upkeep = QString::number(city_improvement_upkeep(pcity, building));
4017 } else {
4018 upkeep = QString::number(building->upkeep);
4019 }
4021 if (pobs->source.kind == VUT_ADVANCE) {
4022 req = advance_name_translation(pobs->source.value.advance);
4023 break;
4024 }
4026 s2 = QString(req);
4027 str = _("Obsolete by:");
4028 str = str + " " + s2;
4029 def_str = "<p style='white-space:pre'><b>"
4030 + QString(improvement_name_translation(building)).toHtmlEscaped()
4031 + "</b>\n";
4032 if (pcity != nullptr) {
4033 def_str += QString(_("Cost: %1, Upkeep: %2\n"))
4034 .arg(impr_build_shield_cost(pcity, building))
4035 .arg(upkeep).toHtmlEscaped();
4036 } else {
4038 nullptr, building);
4039
4040 def_str += QString(_("Cost Estimate: %1, Upkeep: %2\n"))
4041 .arg(cost_est)
4042 .arg(upkeep).toHtmlEscaped();
4043 }
4044 if (s1.compare(s2) != 0) {
4045 def_str = def_str + str.toHtmlEscaped() + "\n";
4046 }
4047 def_str = def_str + "\n";
4048 if (ext) {
4049 char buffer[8192];
4050
4051 str = helptext_building(buffer, sizeof(buffer), pplayer,
4052 nullptr, building);
4053 str = cut_helptext(str);
4054 str = split_text(str, true);
4055 str = str.trimmed();
4056 def_str = def_str + str.toHtmlEscaped();
4057 }
4058 return def_str;
4059}
4060
4061/************************************************************************/
4065QString get_tooltip_unit(const struct unit_type *utype, bool ext)
4066{
4069 QString str;
4070 const struct unit_type *obsolete;
4071 struct advance *tech;
4072
4073 def_str = "<b>"
4074 + QString(utype_name_translation(utype)).toHtmlEscaped()
4075 + "</b>\n";
4076 obsolete = utype->obsoleted_by;
4077 if (obsolete) {
4078 // FIXME: Don't give the impression that primary tech is (always) the only one.
4080 obsolete_str = QString("</td></tr><tr><td colspan=\"3\">");
4081 if (tech && tech != advance_by_number(A_NONE)) {
4082 /* TRANS: this and nearby literal strings are interpreted
4083 * as (Qt) HTML */
4084 obsolete_str = obsolete_str + QString(_("Obsoleted by %1 (%2)."))
4086 .arg(advance_name_translation(tech)).toHtmlEscaped();
4087 } else {
4088 obsolete_str = obsolete_str + QString(_("Obsoleted by %1."))
4089 .arg(utype_name_translation(obsolete)).toHtmlEscaped();
4090 }
4091 }
4092 def_str += "<table width=\"100\%\"><tr><td>"
4093 + bold(QString(_("Attack:"))) + " "
4094 + QString::number(utype->attack_strength).toHtmlEscaped()
4095 + QString("</td><td>") + bold(QString(_("Defense:"))) + " "
4096 + QString::number(utype->defense_strength).toHtmlEscaped()
4097 + QString("</td><td>") + bold(QString(_("Move:"))) + " "
4098 + QString(move_points_text(utype->move_rate, TRUE)).toHtmlEscaped()
4099 + QString("</td></tr><tr><td>")
4100 + bold(QString(_("Cost:"))) + " "
4101 + QString::number(utype_build_shield_cost_base(utype))
4102 .toHtmlEscaped()
4103 + QString("</td><td colspan=\"2\">")
4104 + bold(QString(_("Basic Upkeep:")))
4105 + " " + QString(helptext_unit_upkeep_str(utype)).toHtmlEscaped()
4106 + QString("</td></tr><tr><td>")
4107 + bold(QString(_("Hitpoints:"))) + " "
4108 + QString::number(utype->hp).toHtmlEscaped()
4109 + QString("</td><td>") + bold(QString(_("Firepower:"))) + " "
4110 + QString::number(utype->firepower).toHtmlEscaped()
4111 + QString("</td><td>") + bold(QString(_("Vision:"))) + " "
4112 + QString::number((int) sqrt((double) utype->vision_radius_sq))
4113 .toHtmlEscaped()
4114 + obsolete_str
4115 + QString("</td></tr></table><p style='white-space:pre'>");
4116 if (ext) {
4117 char buffer[8192];
4118 char buf2[1];
4119
4120 buf2[0] = '\0';
4121 str = helptext_unit(buffer, sizeof(buffer), client_player(),
4122 buf2, utype, TRUE);
4123 str = cut_helptext(str);
4124 str = split_text(str, true);
4125 str = str.trimmed().toHtmlEscaped();
4126 def_str = def_str + str;
4127 }
4128
4129 return def_str;
4130};
4131
4132/************************************************************************/
4136{
4139 char buffer[8192];
4140 char buf2[1];
4141 struct universal *target;
4142 struct player *pplayer = client_player();
4143
4144 buf2[0] = '\0';
4145 target = reinterpret_cast<universal *>(qvar.value<void *>());
4146
4147 if (target == nullptr) {
4148 } else if (VUT_UTYPE == target->kind) {
4150 str = helptext_unit(buffer, sizeof(buffer), pplayer,
4151 buf2, target->value.utype, TRUE);
4152 } else {
4153 if (!is_convert_improvement(target->value.building)) {
4155 }
4156
4157 str = helptext_building(buffer, sizeof(buffer), pplayer,
4158 nullptr, target->value.building);
4159 }
4160
4161 // Remove all lines from help which has '*' in first 3 chars
4163 ret_str = split_text(ret_str, true);
4164 ret_str = ret_str.trimmed();
4165 ret_str = def_str + ret_str.toHtmlEscaped();
4166
4167 return ret_str;
4168}
4169
4170/************************************************************************/
4174 QObject *parent,
4175 struct city *city)
4176 : QItemDelegate(parent)
4177{
4178 pd = sh;
4179 item_height = sh.y();
4180 pcity = city;
4181}
4182
4183/************************************************************************/
4188 const QModelIndex &index) const
4189{
4190 struct universal *target;
4191 QString name;
4192 QVariant qvar;
4193 QPixmap *pix;
4195 QRect rect1;
4196 QRect rect2;
4197 struct sprite *sprite;
4198 bool useless = false;
4199 bool is_convert = false;
4200 bool is_neutral = false;
4201 bool is_sea = false;
4202 bool is_flying = false;
4203 bool is_unit = true;
4204 QPixmap pix_dec(option.rect.width(), option.rect.height());
4206 color col;
4207 QIcon icon = current_app()->style()->standardIcon(QStyle::SP_DialogCancelButton);
4208 bool free_sprite = false;
4209 struct unit_class *pclass;
4210
4211 if (!option.rect.isValid()) {
4212 return;
4213 }
4214
4215 qvar = index.data();
4216
4217 if (!qvar.isValid()) {
4218 return;
4219 }
4220
4221 target = reinterpret_cast<universal *>(qvar.value<void *>());
4222
4223 if (target == nullptr) {
4224 col.qcolor = Qt::white;
4225 sprite = qtg_create_sprite(100, 100, &col);
4226 free_sprite = true;
4227 *sprite->pm = icon.pixmap(100, 100);
4228 name = _("Cancel");
4229 is_unit = false;
4230 } else if (VUT_UTYPE == target->kind) {
4233 pclass = utype_class(target->value.utype);
4237 is_sea = true;
4238 }
4239
4240 if ((utype_fuel(target->value.utype)
4245 /* FIXME: Assumed to be flying since only missiles can do suicide
4246 * attacks in classic-like rulesets. This isn't true for all
4247 * rulesets. Not a high priority to fix since all is_flying and
4248 * is_sea is used for is to set a color. */
4250 target->value.utype)) {
4251 if (is_sea) {
4252 is_sea = false;
4253 }
4254 is_flying = true;
4255 }
4256
4260 } else {
4261 is_unit = false;
4264 useless = is_improvement_redundant(pcity, target->value.building);
4265 is_convert = (target->value.building->genus == IG_CONVERT);
4266 }
4267
4268 if (sprite != nullptr) {
4269 pix = sprite->pm;
4270 pix_scaled = pix->scaledToHeight(item_height - 2, Qt::SmoothTransformation);
4271
4272 if (useless) {
4274 }
4275 }
4276
4277 opt = QItemDelegate::setOptions(index, option);
4278 painter->save();
4279 opt.displayAlignment = Qt::AlignLeft;
4280 opt.textElideMode = Qt::ElideMiddle;
4281 QItemDelegate::drawBackground(painter, opt, index);
4282 rect1 = option.rect;
4283 rect1.setWidth(pix_scaled.width() + 4);
4284 rect2 = option.rect;
4285 rect2.setLeft(option.rect.left() + rect1.width());
4286 rect2.setTop(rect2.top() + (rect2.height()
4287 - painter->fontMetrics().height()) / 2);
4288 QItemDelegate::drawDisplay(painter, opt, rect2, name);
4289
4290 if (is_unit) {
4291 if (is_sea) {
4292 pix_dec.fill(QColor(0, 0, 255, 80));
4293 } else if (is_flying) {
4294 pix_dec.fill(QColor(220, 0, 0, 80));
4295 } else if (is_neutral) {
4296 pix_dec.fill(QColor(0, 120, 0, 40));
4297 } else {
4298 pix_dec.fill(QColor(0, 0, 150, 40));
4299 }
4300
4301 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4302 }
4303
4304 if (is_convert) {
4305 pix_dec.fill(QColor(255, 255, 0, 70));
4306 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4307 }
4308
4309 if (!pix_scaled.isNull()) {
4310 QItemDelegate::drawDecoration(painter, opt, rect1, pix_scaled);
4311 }
4312
4313 drawFocus(painter, opt, option.rect);
4314
4315 painter->restore();
4316
4317 if (free_sprite) {
4319 }
4320}
4321
4322/************************************************************************/
4327 const QRect &rect) const
4328{
4329 QPixmap pix(option.rect.width(), option.rect.height());
4330
4331 if ((option.state & QStyle::State_MouseOver) == 0 || !rect.isValid()) {
4332 return;
4333 }
4334
4335 pix.fill(QColor(50, 50, 50, 50));
4336 QItemDelegate::drawDecoration(painter, option, option.rect, pix);
4337}
4338
4339/************************************************************************/
4343 const QModelIndex &index) const
4344{
4345 QSize s;
4346
4347 s.setWidth(pd.x());
4348 s.setHeight(pd.y());
4349 return s;
4350}
4351
4352/************************************************************************/
4356 QObject *parent): QObject()
4357{
4359 target = ptarget;
4360}
4361
4362/************************************************************************/
4366{
4367 // Allocated as renegade in model
4368 if (target != nullptr) {
4369 delete target;
4370 }
4371}
4372
4373/************************************************************************/
4377{
4378 return QVariant::fromValue((void *)target);
4379}
4380
4381/************************************************************************/
4385{
4386 return false;
4387}
4388
4389/************************************************************************/
4393 bool su, bool sw, bool sb,
4394 QObject *parent)
4395 : QAbstractListModel(parent)
4396{
4397 show_units = su;
4398 show_wonders = sw;
4400 mcity = pcity;
4401 future_t = f;
4402 populate();
4403}
4404
4405/************************************************************************/
4413
4414/************************************************************************/
4418{
4419 if (!index.isValid()) {
4420 return QVariant();
4421 }
4422
4423 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4424 && index.column() < columnCount()
4425 && (index.column() + index.row() * 3 < city_target_list.count())) {
4426 int r, c, t, new_index;
4427
4428 r = index.row();
4429 c = index.column();
4430 t = r * 3 + c;
4431 new_index = t / 3 + rowCount() * c;
4432 // Exception, shift whole column
4433 if ((c == 2) && city_target_list.count() % 3 == 1) {
4434 new_index = t / 3 + rowCount() * c - 1;
4435 }
4436 if (role == Qt::ToolTipRole) {
4438 }
4439
4440 return city_target_list[new_index]->data();
4441 }
4442
4443 return QVariant();
4444}
4445
4446/************************************************************************/
4450{
4452 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
4453 struct item items[MAX_NUM_PRODUCTION_TARGETS];
4454 struct universal *renegade;
4455 int item, targets_used;
4456 QString str;
4458 QFontMetrics fm(f);
4459
4460 sh.setY(fm.height() * 2);
4461 sh.setX(0);
4462
4464 city_target_list.clear();
4465
4467 future_t);
4468 name_and_sort_items(targets, targets_used, items, false, mcity);
4469
4470 for (item = 0; item < targets_used; item++) {
4471 if (future_t || can_city_build_now(&(wld.map), mcity, &items[item].item,
4472 RPT_CERTAIN)) {
4473 renegade = new universal(items[item].item);
4474
4475 // Renegade deleted in production_item destructor
4476 if (VUT_UTYPE == renegade->kind) {
4477 str = utype_name_translation(renegade->value.utype);
4478 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4479
4480 if (show_units) {
4481 pi = new production_item(renegade, this);
4483 } else {
4484 delete renegade;
4485 }
4486 } else {
4487 str = improvement_name_translation(renegade->value.building);
4488 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4489
4490 if ((is_wonder(renegade->value.building) && show_wonders)
4491 || (is_improvement(renegade->value.building) && show_buildings)
4492 || (is_convert_improvement(renegade->value.building))
4493 || (is_special_improvement(renegade->value.building)
4494 && show_buildings)) {
4495 pi = new production_item(renegade, this);
4497 } else {
4498 delete renegade;
4499 }
4500 }
4501 }
4502 }
4503
4504 pi = new production_item(nullptr, this);
4506 sh.setX(2 * sh.y() + sh.x());
4507 sh.setX(qMin(sh.x(), 250));
4508}
4509
4510/************************************************************************/
4514 const QVariant &value, int role)
4515{
4516 if (!index.isValid() || role != Qt::DisplayRole || role != Qt::ToolTipRole)
4517 return false;
4518
4519 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4520 && index.column() < columnCount()) {
4521 bool change = city_target_list[index.row()]->setData();
4522 return change;
4523 }
4524
4525 return false;
4526}
4527
4528/************************************************************************/
4537 bool future, int when, int curr,
4538 bool show_units, bool buy,
4539 bool show_wonders,
4540 bool show_buildings): QTableView()
4541{
4542 QPoint pos, sh;
4543 QRect rect = QApplication::primaryScreen()->availableGeometry();
4544 int desk_width = rect.width();
4545 int desk_height = rect.height();
4546 fc_tt = new fc_tooltip(this);
4547 setAttribute(Qt::WA_DeleteOnClose);
4548 setWindowFlags(Qt::Popup);
4549 verticalHeader()->setVisible(false);
4550 horizontalHeader()->setVisible(false);
4551 setProperty("showGrid", false);
4553 sh_units = show_units;
4554 pw_city = pcity;
4555 buy_it = buy;
4556 when_change = when;
4557 list_model = new city_production_model(pw_city, future, show_units,
4558 show_wonders, show_buildings, this);
4559 sh = list_model->sh;
4560 c_p_d = new city_production_delegate(sh, this, pw_city);
4563 viewport()->installEventFilter(fc_tt);
4564 installEventFilter(this);
4566 const QItemSelection &)),
4568 const QItemSelection &)));
4571 setFixedWidth(3 * sh.x() + 6);
4572 setFixedHeight(list_model->rowCount()*sh.y() + 6);
4573
4574 if (width() > desk_width) {
4576 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4577 } else {
4578 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4579 }
4580
4581 if (height() > desk_height) {
4583 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4584 } else {
4585 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4586 }
4587
4588 pos = QCursor::pos();
4589
4590 if (pos.x() + width() > desk_width) {
4591 pos.setX(desk_width - width());
4592 } else if (pos.x() - width() < 0) {
4593 pos.setX(0);
4594 }
4595
4596 if (pos.y() + height() > desk_height) {
4597 pos.setY(desk_height - height());
4598 } else if (pos.y() - height() < 0) {
4599 pos.setY(0);
4600 }
4601
4602 move(pos);
4603 setMouseTracking(true);
4604 setFocus();
4605}
4606
4607/************************************************************************/
4611{
4612 if (event->button() == Qt::RightButton) {
4613 close();
4614 return;
4615 }
4616
4617 QAbstractItemView::mousePressEvent(event);
4618}
4619
4620/************************************************************************/
4624{
4625 QRect pw_rect;
4626 QPoint br;
4627
4628 if (obj != this)
4629 return false;
4630
4631 if (ev->type() == QEvent::MouseButtonPress) {
4632 pw_rect.setTopLeft(pos());
4633 br.setX(pos().x() + width());
4634 br.setY(pos().y() + height());
4635 pw_rect.setBottomRight(br);
4636
4637 if (!pw_rect.contains(QCursor::pos())) {
4638 close();
4639 }
4640 }
4641
4642 return false;
4643}
4644
4645/************************************************************************/
4649 const QItemSelection &ds)
4650{
4651 QModelIndexList indexes = selectionModel()->selectedIndexes();
4652 QModelIndex index;
4653 QVariant qvar;
4654 struct worklist queue;
4655 struct universal *target;
4656
4657 if (indexes.isEmpty() || client_is_observer()) {
4658 return;
4659 }
4660 index = indexes.at(0);
4661 qvar = index.data(Qt::UserRole);
4662 if (!qvar.isValid()) {
4663 return;
4664 }
4665 target = reinterpret_cast<universal *>(qvar.value<void *>());
4666 if (target != nullptr) {
4667 city_get_queue(pw_city, &queue);
4668 switch (when_change) {
4669 case 0: // Change current target
4671 if (city_can_buy(pw_city) && buy_it) {
4673 }
4674 break;
4675
4676 case 1: // Change current (selected on list)
4679 } else {
4681 worklist_insert(&queue, target, curr_selection);
4682 city_set_queue(pw_city, &queue);
4683 }
4684 break;
4685
4686 case 2: // Insert before
4688 curr_selection = 0;
4689 }
4692 worklist_insert(&queue, target, curr_selection);
4693 city_set_queue(pw_city, &queue);
4694 break;
4695
4696 case 3: // Insert after
4698 city_queue_insert(pw_city, -1, target);
4699 break;
4700 }
4702 worklist_insert(&queue, target, curr_selection);
4703 city_set_queue(pw_city, &queue);
4704 break;
4705
4706 case 4: // Add last
4707 city_queue_insert(pw_city, -1, target);
4708 break;
4709
4710 default:
4711 break;
4712 }
4713 }
4714 close();
4715 destroy();
4716}
4717
4718/************************************************************************/
4722{
4723 delete c_p_d;
4724 delete list_model;
4725 viewport()->removeEventFilter(fc_tt);
4726 removeEventFilter(this);
4727}
const char * action_id_name_translation(action_id act_id)
Definition actions.c:1271
#define action_id_univs_not_blocking(act_id, act_uni, tgt_uni)
Definition actions.h:740
#define str
Definition astring.c:76
#define n
Definition astring.c:77
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_CLR(bv, bit)
Definition bitvector.h:94
QRect zealous_crop_rect(QImage &p)
Definition canvas.cpp:419
void qtg_canvas_free(struct canvas *store)
Definition canvas.cpp:48
struct canvas * qtg_canvas_create(int width, int height)
Definition canvas.cpp:36
void qtg_canvas_copy(struct canvas *dest, struct canvas *src, int src_x, int src_y, int dest_x, int dest_y, int width, int height)
Definition canvas.cpp:79
void pixmap_copy(QPixmap *dest, QPixmap *src, int src_x, int src_y, int dest_x, int dest_y, int width, int height)
Definition canvas.cpp:101
static QFont * get_font(enum client_font font)
Definition canvas.cpp:379
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int canvas_y
Definition canvas_g.h:43
struct canvas int canvas_x
Definition canvas_g.h:43
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
#define citizens_iterate_end
Definition citizens.h:54
#define citizens_iterate(_pcity, _pslot, _nationality)
Definition citizens.h:48
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:666
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:740
const char * city_name_getx(const struct city *pcity)
Definition city.c:1166
int city_granary_size(int city_size)
Definition city.c:2189
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:305
int city_superspecialists(const struct city *pcity)
Definition city.c:3416
const char * city_name_get(const struct city *pcity)
Definition city.c:1157
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1312
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3486
int city_population(const struct city *pcity)
Definition city.c:1247
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:3107
bool city_unhappy(const struct city *pcity)
Definition city.c:1683
bool city_celebrating(const struct city *pcity)
Definition city.c:1702
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2928
bool city_happy(const struct city *pcity)
Definition city.c:1671
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target, const enum req_problem_type prob_type)
Definition city.c:1028
int rs_max_city_radius_sq(void)
Definition city.c:159
citizens city_specialists(const struct city *pcity)
Definition city.c:3401
int city_turns_to_grow(const struct city *pcity)
Definition city.c:2053
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:703
static citizens city_size_get(const struct city *pcity)
Definition city.h:570
citizen_category
Definition city.h:265
#define city_owner(_pcity_)
Definition city.h:564
#define MAX_CITY_SIZE
Definition city.h:104
citizen_feeling
Definition city.h:276
@ FEELING_EFFECT
Definition city.h:279
@ FEELING_LUXURY
Definition city.h:278
@ FEELING_FINAL
Definition city.h:282
@ FEELING_LAST
Definition city.h:283
@ FEELING_BASE
Definition city.h:277
@ FEELING_NATIONALITY
Definition city.h:280
@ FEELING_MARTIAL
Definition city.h:281
void qtg_popdown_city_dialog(struct city *pcity)
Definition citydlg.cpp:3861
void qtg_real_city_dialog_refresh(struct city *pcity)
Definition citydlg.cpp:3881
QString split_text(QString text, bool cut)
Definition optiondlg.cpp:62
void city_font_update()
Definition citydlg.cpp:3895
bool qtg_city_dialog_is_open(struct city *pcity)
Definition citydlg.cpp:3936
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4135
void qtg_popdown_all_city_dialogs()
Definition citydlg.cpp:3873
static city_dialog * city_dlg
Definition citydlg.cpp:75
void qtg_refresh_unit_city_dialogs(struct unit *punit)
Definition citydlg.cpp:3920
static QString bold(QString text)
Definition citydlg.cpp:3997
void qtg_real_city_dialog_popup(struct city *pcity)
Definition citydlg.cpp:3833
QString get_tooltip_improvement(const impr_type *building, struct city *pcity, bool ext)
Definition citydlg.cpp:4006
static bool city_dlg_created
Definition citydlg.cpp:71
static void pixmap_put_x(QPixmap *pix)
Definition citydlg.cpp:350
QString cut_helptext(QString text)
QString get_tooltip_unit(const struct unit_type *utype, bool ext)
Definition citydlg.cpp:4065
void destroy_city_dialog()
Definition citydlg.cpp:3848
void get_city_dialog_output_text(const struct city *pcity, Output_type_id otype, char *buf, size_t bufsz)
void get_city_dialog_production(struct city *pcity, char *buffer, size_t buffer_len)
int city_set_worklist(struct city *pcity, const struct worklist *pworklist)
int get_city_citizen_types(struct city *pcity, enum citizen_feeling idx, enum citizen_category *categories)
int city_buy_production(struct city *pcity)
bool city_queue_insert(struct city *pcity, int position, struct universal *item)
bool city_queue_insert_worklist(struct city *pcity, int position, const struct worklist *worklist)
int city_toggle_worker(struct city *pcity, int city_x, int city_y)
void get_city_dialog_airlift_text(const struct city *pcity, char *buf, size_t bufsz)
bool city_set_queue(struct city *pcity, const struct worklist *pqueue)
int city_change_production(struct city *pcity, struct universal *target)
void city_rotate_specialist(struct city *pcity, int citizen_index)
int get_citydlg_canvas_width(void)
bool canvas_to_city_pos(int *city_x, int *city_y, int city_radius_sq, int canvas_x, int canvas_y)
int city_try_fill_superspecialists(struct city *pcity, int cat_len, enum citizen_category *categories)
void get_city_dialog_airlift_value(const struct city *pcity, char *buf, size_t bufsz)
void city_get_queue(struct city *pcity, struct worklist *pqueue)
void city_dialog_redraw_map(struct city *pcity, struct canvas *pcanvas)
int city_sell_improvement(struct city *pcity, Impr_type_id sell_id)
void get_city_dialog_pollution_text(const struct city *pcity, char *buf, size_t bufsz)
void get_city_dialog_culture_text(const struct city *pcity, char *buf, size_t bufsz)
bool city_can_buy(const struct city *pcity)
int get_citydlg_canvas_height(void)
void get_city_dialog_illness_text(const struct city *pcity, char *buf, size_t bufsz)
void set_city(struct city *pcity)
Definition citydlg.cpp:1187
struct city * pcity
Definition citydlg.h:418
city_label(int type, QWidget *parent=nullptr)
Definition citydlg.cpp:1155
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:1163
int wdth
Definition citydlg.h:279
int cutted_height
Definition citydlg.h:282
QSize sizeHint() const
Definition citydlg.cpp:1286
void paintEvent(QPaintEvent *event)
Definition citydlg.cpp:1226
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:1302
int height
Definition citydlg.h:280
void set_pixmap(struct city *pcity, float z)
Definition citydlg.cpp:1250
void context_menu(QPoint point)
Definition citydlg.cpp:1324
canvas * miniview
Definition citydlg.h:266
struct city * mcity
Definition citydlg.h:276
QSize minimumSizeHint() const
Definition citydlg.cpp:1294
float zoom
Definition citydlg.h:278
QPixmap zoomed_pixmap
Definition citydlg.h:267
city_map(QWidget *parent)
Definition citydlg.cpp:1195
int cutted_width
Definition citydlg.h:281
int radius
Definition citydlg.h:277
int delta_y
Definition citydlg.h:284
int delta_x
Definition citydlg.h:283
city_production_delegate(QPoint sh, QObject *parent, struct city *city)
Definition citydlg.cpp:4173
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4186
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4342
struct city * pcity
Definition citydlg.h:310
void drawFocus(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect) const
Definition citydlg.cpp:4325
int rowCount(const QModelIndex &index=QModelIndex()) const
Definition citydlg.h:348
QList< production_item * > city_target_list
Definition citydlg.h:364
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole)
Definition citydlg.cpp:4513
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition citydlg.h:352
city_production_model(struct city *pcity, bool f, bool su, bool sw, bool sb, QObject *parent=nullptr)
Definition citydlg.cpp:4392
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition citydlg.cpp:4417
struct city * mcity
Definition citydlg.h:365
static fc_font * instance()
Definition fonts.cpp:41
QFont * get_font(QString name)
Definition fonts.cpp:63
static fc_icons * instance()
bool eventFilter(QObject *obj, QEvent *event)
Definition citydlg.cpp:3952
void update_buildings()
Definition citydlg.cpp:551
QHBoxLayout * layout
Definition citydlg.h:252
void add_item(impr_item *item)
Definition citydlg.cpp:499
void wheelEvent(QWheelEvent *event)
Definition citydlg.cpp:532
impr_info(QWidget *parent)
Definition citydlg.cpp:468
void clear_layout()
Definition citydlg.cpp:507
void init_layout()
Definition citydlg.cpp:478
QList< impr_item * > impr_list
Definition citydlg.h:253
void mouseDoubleClickEvent(QMouseEvent *event)
Definition citydlg.cpp:603
impr_item(QWidget *parent, const struct impr_type *building, struct city *pcity)
Definition citydlg.cpp:367
void init_pix()
Definition citydlg.cpp:406
void enterEvent(QEnterEvent *event)
Definition citydlg.cpp:415
struct canvas * impr_pixmap
Definition citydlg.h:229
struct city * dlgcity
Definition citydlg.h:230
const struct impr_type * impr
Definition citydlg.h:228
void leaveEvent(QEvent *event)
Definition citydlg.cpp:442
void wheelEvent(QWheelEvent *event)
Definition citydlg.cpp:583
struct universal * target
Definition citydlg.h:334
QVariant data() const
Definition citydlg.cpp:4376
production_item(struct universal *ptarget, QObject *parent)
Definition citydlg.cpp:4355
bool eventFilter(QObject *obj, QEvent *ev)
Definition citydlg.cpp:4623
void prod_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:4648
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:4610
city_production_model * list_model
Definition citydlg.h:379
struct city * pw_city
Definition citydlg.h:396
fc_tooltip * fc_tt
Definition citydlg.h:401
city_production_delegate * c_p_d
Definition citydlg.h:380
production_widget(QWidget *parent, struct city *pcity, bool future, int when, int curr, bool show_units, bool buy=false, bool show_wonders=true, bool show_buildings=true)
Definition citydlg.cpp:4536
progress_bar(QWidget *parent)
Definition citydlg.cpp:82
void paintEvent(QPaintEvent *event)
Definition citydlg.cpp:188
int m_animate_step
Definition citydlg.h:133
void resizeEvent(QResizeEvent *event)
Definition citydlg.cpp:106
QRegion reg
Definition citydlg.h:135
void set_pixmap(struct universal *target)
Definition citydlg.cpp:114
void create_region()
Definition citydlg.cpp:326
QElapsedTimer m_timer
Definition citydlg.h:114
void timerEvent(QTimerEvent *event)
Definition citydlg.cpp:176
QPixmap * pix
Definition citydlg.h:134
QFont * sfont
Definition citydlg.h:136
void clicked()
void wheelEvent(QWheelEvent *event)
Definition citydlg.cpp:1069
void init_layout()
Definition citydlg.cpp:1057
unit_info(bool supp)
Definition citydlg.cpp:1030
void add_item(unit_item *item)
Definition citydlg.cpp:1049
QHBoxLayout * layout
Definition citydlg.h:205
void update_units()
Definition citydlg.cpp:1088
void clear_layout()
Definition citydlg.cpp:1129
QList< unit_item * > unit_list
Definition citydlg.h:206
bool supports
Definition citydlg.h:209
QAction * activate
Definition citydlg.h:147
QAction * disband_action
Definition citydlg.h:145
void enterEvent(QEnterEvent *event)
Definition citydlg.cpp:961
void contextMenuEvent(QContextMenuEvent *ev)
Definition citydlg.cpp:734
QAction * sentry
Definition citydlg.h:149
struct unit * qunit
Definition citydlg.h:164
QAction * activate_and_close
Definition citydlg.h:148
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:1007
int happy_cost
Definition citydlg.h:168
void change_homecity()
Definition citydlg.cpp:920
QAction * unload
Definition citydlg.h:152
QAction * upgrade
Definition citydlg.h:153
bool supported
Definition citydlg.h:169
void fortify_unit()
Definition citydlg.cpp:951
void sentry_unit()
Definition citydlg.cpp:1020
QAction * unload_trans
Definition citydlg.h:154
void load_unit()
Definition citydlg.cpp:884
void wheelEvent(QWheelEvent *event)
Definition citydlg.cpp:987
QAction * load
Definition citydlg.h:151
void activate_unit()
Definition citydlg.cpp:941
QAction * change_home
Definition citydlg.h:146
QAction * fortify
Definition citydlg.h:150
QImage unit_img
Definition citydlg.h:165
void create_actions()
Definition citydlg.cpp:788
void unload_all()
Definition citydlg.cpp:900
void disband()
Definition citydlg.cpp:866
void upgrade_unit()
Definition citydlg.cpp:908
void init_pix()
Definition citydlg.cpp:718
void leaveEvent(QEvent *event)
Definition citydlg.cpp:979
unit_item(QWidget *parent, struct unit *punit, bool supp=false, int happy_cost=0)
Definition citydlg.cpp:647
void unload_unit()
Definition citydlg.cpp:892
void activate_and_close_dialog()
Definition citydlg.cpp:930
bool client_is_observer(void)
struct civclient client
bool can_client_issue_orders(void)
#define client_player()
int collect_eventually_buildable_targets(struct universal *targets, struct city *pcity, bool advanced_tech)
Definition climisc.c:821
void name_and_sort_items(struct universal *targets, int num_targets, struct item *items, bool show_cost, struct city *pcity)
Definition climisc.c:650
cid cid_encode(struct universal target)
Definition climisc.c:483
int collect_already_built_targets(struct universal *targets, struct city *pcity)
Definition climisc.c:918
struct universal cid_decode(cid id)
Definition climisc.c:526
#define MAX_NUM_PRODUCTION_TARGETS
Definition climisc.h:89
#define cid_production
Definition climisc.h:71
int cid
Definition climisc.h:31
static struct fc_sockaddr_list * list
Definition clinet.c:102
void cm_copy_parameter(struct cm_parameter *dest, const struct cm_parameter *const src)
Definition cm.c:2176
bool cma_is_city_under_agent(const struct city *pcity, struct cm_parameter *parameter)
Definition cma_core.c:552
void cma_put_city_under_agent(struct city *pcity, const struct cm_parameter *const parameter)
Definition cma_core.c:524
void cma_release_city(struct city *pcity)
Definition cma_core.c:542
char * cmafec_preset_get_descr(int idx)
Definition cma_fec.c:169
const char * cmafec_get_short_descr_of_city(const struct city *pcity)
Definition cma_fec.c:221
const struct cm_parameter * cmafec_preset_get_parameter(int idx)
Definition cma_fec.c:182
void cmafec_preset_add(const char *descr_name, struct cm_parameter *pparam)
Definition cma_fec.c:136
int cmafec_preset_get_index_of_parameter(const struct cm_parameter *const parameter)
Definition cma_fec.c:196
void cmafec_preset_remove(int idx)
Definition cma_fec.c:153
int cmafec_preset_num(void)
Definition cma_fec.c:213
void cmafec_get_fe_parameter(struct city *pcity, struct cm_parameter *dest)
Definition cma_fec.c:115
char * incite_cost
Definition comments.c:77
void request_unit_fortify(struct unit *punit)
Definition control.c:2365
struct unit * request_unit_unload_all(struct unit *punit)
Definition control.c:1523
void unit_focus_set(struct unit *punit)
Definition control.c:518
void request_unit_change_homecity(struct unit *punit)
Definition control.c:2106
void request_unit_unload(struct unit *pcargo)
Definition control.c:2206
void request_unit_sentry(struct unit *punit)
Definition control.c:2354
#define can_unit_do_activity_client(_punit_, _act_)
Definition control.h:41
int counter_index(const struct counter *pcount)
Definition counters.c:176
#define city_counters_iterate_end
Definition counters.h:64
#define city_counters_iterate(pcount)
Definition counters.h:57
bool qtg_request_transport(struct unit *pcargo, struct tile *ptile)
Definition dialogs.cpp:4959
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
int int id
Definition editgui_g.h:28
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
enum event_type event
Definition events.c:82
struct extra_type * next_extra_for_tile(const struct tile *ptile, enum extra_cause cause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:779
struct extra_type * prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:804
enum extra_cause activity_to_extra_cause(enum unit_activity act)
Definition extras.c:1090
enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act)
Definition extras.c:1111
#define extra_index(_e_)
Definition extras.h:183
unsigned char citizens
Definition fc_types.h:249
@ RPT_CERTAIN
Definition fc_types.h:516
#define EC_NONE
Definition fc_types.h:808
@ TR_SUCCESS
Definition fc_types.h:941
#define ERM_NONE
Definition fc_types.h:831
@ O_SHIELD
Definition fc_types.h:103
@ O_FOOD
Definition fc_types.h:103
@ O_TRADE
Definition fc_types.h:103
@ O_SCIENCE
Definition fc_types.h:103
@ O_LUXURY
Definition fc_types.h:103
@ O_GOLD
Definition fc_types.h:103
@ O_LAST
Definition fc_types.h:103
const char * skip_intl_qualifier_prefix(const char *str)
Definition fcintl.c:48
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
const char * population_to_text(int thousand_citizen)
Definition game.c:743
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct city * game_city_by_number(int id)
Definition game.c:106
struct global_worklist * global_worklist_by_id(int id)
bool global_worklist_set(struct global_worklist *pgwl, const struct worklist *pwl)
const char * global_worklist_name(const struct global_worklist *pgwl)
int global_worklist_id(const struct global_worklist *pgwl)
const struct worklist * global_worklist_get(const struct global_worklist *pgwl)
struct global_worklist * global_worklist_new(const char *name)
#define global_worklists_iterate(pgwl)
#define global_worklists_iterate_end
void canvas_free(struct canvas *store)
Definition canvas.c:44
@ INFO_LUXURY
Definition citydlg.c:120
@ INFO_STEAL
Definition citydlg.c:122
@ INFO_CORRUPTION
Definition citydlg.c:121
@ NUM_INFO_FIELDS
Definition citydlg.c:123
@ INFO_ILLNESS
Definition citydlg.c:122
@ INFO_WASTE
Definition citydlg.c:121
@ INFO_GROWTH
Definition citydlg.c:120
@ INFO_SHIELD
Definition citydlg.c:119
@ INFO_CULTURE
Definition citydlg.c:121
@ INFO_GOLD
Definition citydlg.c:119
@ INFO_SCIENCE
Definition citydlg.c:120
@ INFO_POLLUTION
Definition citydlg.c:121
@ INFO_TRADE
Definition citydlg.c:119
@ INFO_AIRLIFT
Definition citydlg.c:122
@ INFO_GRANARY
Definition citydlg.c:120
@ INFO_FOOD
Definition citydlg.c:119
void popup_upgrade_dialog(struct unit_list *punits)
Definition dialogs.c:1435
void popup_disband_dialog(struct unit_list *punits)
Definition dialogs.c:1473
static struct tile * pos
Definition finddlg.c:53
const char * tooltip
Definition repodlgs.c:1315
void free_sprite(struct sprite *s)
Definition sprite.c:278
static GMenu * change_menu
Definition cityrep.c:119
static GMenu * options_menu
Definition menu.c:91
QString get_tooltip_improvement(const impr_type *building, struct city *pcity=nullptr, bool ext=false)
Definition citydlg.cpp:4006
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4135
void set_theme_style()
Definition themes.cpp:107
#define CAPTURE_DEFAULT_THIS
Definition gui_main.h:23
#define show(id)
Definition widget.h:235
#define hide(id)
Definition widget.h:238
QApplication * current_app()
Definition gui_main.cpp:227
char * helptext_unit(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct unit_type *utype, bool class_help)
Definition helpdata.c:1985
char * helptext_unit_upkeep_str(const struct unit_type *utype)
Definition helpdata.c:5095
char * helptext_building(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct impr_type *pimprove)
Definition helpdata.c:1439
int impr_sell_gold(const struct impr_type *pimprove)
enum test_result test_player_sell_building_now(struct player *pplayer, struct city *pcity, const struct impr_type *pimprove)
bool is_special_improvement(const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool is_improvement(const struct impr_type *pimprove)
Impr_type_id improvement_number(const struct impr_type *pimprove)
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_convert_improvement(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
int impr_estimate_build_shield_cost(const struct player *pplayer, const struct tile *ptile, const struct impr_type *pimprove)
const char * name
Definition inputfile.c:127
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_action(condition, action)
Definition log.h:188
int send_packet_worker_task(struct connection *pc, const struct packet_worker_task *packet)
int dsend_packet_city_options_req(struct connection *pc, int city_id, bv_city_options options, enum city_wl_cancel_behavior wl_cb)
void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void put_unit_city_overlays(struct unit *punit, struct canvas *pcanvas, int canvas_x, int canvas_y, int *upkeep_cost, int happy_cost)
void center_tile_mapcanvas(const struct tile *ptile)
const char * move_points_text(int mp, bool reduce)
Definition movement.c:1066
static mpgui * gui
Definition mpgui_qt.cpp:53
static const char * name_translation_get(const struct name_translation *ptrans)
const char *const default_font
Definition fonts.h:27
const char *const notify_label
Definition fonts.h:28
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
const char * text_happiness_cities(const struct city *pcity)
Definition text.c:1979
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1217
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:432
void qtg_free_sprite(struct sprite *s)
Definition sprite.cpp:172
struct sprite * qtg_create_sprite(int width, int height, struct color *pcolor)
Definition sprite.cpp:181
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
#define ARRAY_SIZE(x)
Definition shared.h:85
#define FC_INFINITY
Definition shared.h:36
size_t size
Definition specvec.h:72
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
#define strvec_iterate(psv, str)
#define strvec_iterate_end
QPixmap map_pixmap
Definition canvas.h:25
void setup_ui(struct city *qcity)
Definition citydlg.cpp:3272
int current_building
Definition citydlg.h:504
void worklist_up()
Definition citydlg.cpp:3703
city_label * citizens_label
Definition citydlg.h:447
QPushButton * lcity_name
Definition citydlg.h:490
void show_happiness()
Definition citydlg.cpp:2121
void closeEvent(QCloseEvent *event)
Definition citydlg.cpp:2318
void show_counters()
Definition citydlg.cpp:2156
void update_nation_table()
Definition citydlg.cpp:3066
void hideEvent(QHideEvent *event)
Definition citydlg.cpp:2290
void cma_toggle_changed_depr(int state)
Definition citydlg.cpp:2701
QPushButton * work_next_but
Definition citydlg.h:478
void next_city()
Definition citydlg.cpp:3382
progress_bar * production_combo_p
Definition citydlg.h:462
QTableWidget * nationality_table
Definition citydlg.h:464
QRadioButton * r3
Definition citydlg.h:472
QTableWidget * cma_table
Definition citydlg.h:465
void showEvent(QShowEvent *event)
Definition citydlg.cpp:2301
QPushButton * happiness_button
Definition citydlg.h:482
void cma_double_clicked(int row, int column)
Definition citydlg.cpp:2494
void display_worklist_menu(const QPoint &p)
Definition citydlg.cpp:2778
void update_disabled()
Definition citydlg.cpp:2191
QLabel * supp_units
Definition citydlg.h:459
QPushButton * next_city_but
Definition citydlg.h:476
QLabel * qlt[NUM_INFO_FIELDS]
Definition citydlg.h:455
QPushButton * work_prev_but
Definition citydlg.h:479
QHBoxLayout * single_page_layout
Definition citydlg.h:436
void update_buy_button()
Definition citydlg.cpp:2870
int selected_row_p
Definition citydlg.h:491
QHBoxLayout * leftbot_layout
Definition citydlg.h:442
void update_building()
Definition citydlg.cpp:3454
QPushButton * zoom_in_button
Definition citydlg.h:484
void save_worklist()
Definition citydlg.cpp:3769
void worklist_del()
Definition citydlg.cpp:3728
QGridLayout * info_grid_layout
Definition citydlg.h:449
void clear_worklist()
Definition citydlg.cpp:3688
QPushButton * counterss_button
Definition citydlg.h:483
impr_info * city_buildings
Definition citydlg.h:489
QLabel * curr_impr
Definition citydlg.h:461
city_label * lab_table[6]
Definition citydlg.h:448
int scroll_height
Definition citydlg.h:500
QLabel * curr_units
Definition citydlg.h:460
unit_info * current_units
Definition citydlg.h:487
void zoom_out()
Definition citydlg.cpp:2409
void zoom_in()
Definition citydlg.cpp:2396
struct unit_node_vector supported_units
Definition citydlg.c:163
QPushButton * zoom_out_button
Definition citydlg.h:485
struct city * pcity
Definition citydlg.c:138
struct city_dialog::@148 happiness
void update_info_label()
Definition citydlg.cpp:3143
QPushButton * work_add_but
Definition citydlg.h:480
QSplitter * central_left_splitter
Definition citydlg.h:440
void disband_state_changed(bool allow_disband)
Definition citydlg.cpp:2737
void update_citizens()
Definition citydlg.cpp:2896
QRadioButton * r1
Definition citydlg.h:472
void cma_slider(int val)
Definition citydlg.cpp:2712
QCheckBox * cma_celeb_checkbox
Definition citydlg.h:466
QCheckBox * show_units
Definition citydlg.h:469
enum city_dialog::city_dialog_tab current_tab
void worklist_down()
Definition citydlg.cpp:3745
void update_title()
Definition citydlg.cpp:3800
QLabel * cma_info_text
Definition citydlg.h:456
void dbl_click_p(QTableWidgetItem *item)
Definition citydlg.cpp:3288
QPushButton * cma_enable_but
Definition citydlg.h:475
QLabel * cma_result
Definition citydlg.h:457
void cma_remove()
Definition citydlg.cpp:2662
QSlider * slider_tab[2 *O_LAST+2]
Definition citydlg.h:492
QPushButton * button
Definition citydlg.h:473
bool eventFilter(QObject *obj, QEvent *event)
Definition citydlg.cpp:2329
QSplitter * prod_unit_splitter
Definition citydlg.h:439
QVBoxLayout * left_layout
Definition citydlg.h:445
void prev_city()
Definition citydlg.cpp:3418
void city_rename()
Definition citydlg.cpp:2366
void refresh()
Definition citydlg.cpp:2992
void update_cma_tab()
Definition citydlg.cpp:2595
QPushButton * work_rem_but
Definition citydlg.h:481
float zoom
Definition citydlg.h:501
QSplitter * central_splitter
Definition citydlg.h:441
QWidget * prod_happ_widget
Definition citydlg.h:443
void show_targets()
Definition citydlg.cpp:3657
city_dialog(QWidget *parent=nullptr)
Definition citydlg.cpp:1474
void cma_toggle_changed(Qt::CheckState state)
Definition citydlg.cpp:2689
QVBoxLayout * counterss_layout
Definition citydlg.h:438
QFrame * counterss_frame
Definition citydlg.h:453
QWidget * top_widget
Definition citydlg.h:444
void update_tabs()
Definition citydlg.cpp:2100
QPushButton * prev_city_but
Definition citydlg.h:477
void cma_enable()
Definition citydlg.cpp:2458
QLabel * cma_result_pix
Definition citydlg.h:458
struct city * dlgcity
Definition citydlg.h:499
void update_counters_table()
Definition citydlg.cpp:3024
void update_sliders()
Definition citydlg.cpp:2543
void update_improvements()
Definition citydlg.cpp:3522
GtkWidget * worklist
Definition citydlg.c:176
QHBoxLayout * happiness_layout
Definition citydlg.h:437
QCheckBox * future_targets
Definition citydlg.h:468
void change_production(bool next)
Definition citydlg.cpp:2054
void cma_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:2513
QCheckBox * cma_max_growth
Definition citydlg.h:467
void item_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:3364
void show_targets_worklist()
Definition citydlg.cpp:3673
QCheckBox * show_wonders
Definition citydlg.h:471
void cma_context_menu(const QPoint &p)
Definition citydlg.cpp:2758
void cma_changed()
Definition citydlg.cpp:2473
QPushButton * buy_button
Definition citydlg.h:474
QRadioButton * r4
Definition citydlg.h:472
struct city_dialog::@149 counters
void update_units()
Definition citydlg.cpp:3305
QRadioButton * r2
Definition citydlg.h:472
QTableWidget * p_table_p
Definition citydlg.h:463
void save_cma()
Definition citydlg.cpp:2422
QPixmap * citizen_pixmap
Definition citydlg.h:486
void production_changed(int index)
Definition citydlg.cpp:3639
void update_prod_buttons()
Definition citydlg.cpp:2228
QWidget * happiness_widget
Definition citydlg.h:452
QGroupBox * happiness_group
Definition citydlg.h:451
QCheckBox * show_buildings
Definition citydlg.h:470
Definition city.h:318
struct worker_task_list * task_reqs
Definition city.h:410
int surplus[O_LAST]
Definition city.h:353
enum city_wl_cancel_behavior wlcb
Definition city.h:402
int food_stock
Definition city.h:365
int * counter_values
Definition city.h:406
int pollution
Definition city.h:367
int id
Definition city.h:324
int waste[O_LAST]
Definition city.h:354
struct unit_list * info_units_present
Definition city.h:474
struct unit_list * info_units_supported
Definition city.h:473
struct universal production
Definition city.h:394
int steal
Definition city.h:412
citizens size
Definition city.h:330
int culture
Definition city.h:465
int buy_cost
Definition city.h:466
struct city::@18::@21 client
struct tile * tile
Definition city.h:320
int shield_stock
Definition city.h:366
int prod[O_LAST]
Definition city.h:356
struct unit_list * units_supported
Definition city.h:404
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
bool allow_disorder
Definition cm.h:44
int factor[O_LAST]
Definition cm.h:47
bool max_growth
Definition cm.h:42
bool allow_specialists
Definition cm.h:45
bool require_happy
Definition cm.h:43
int minimal_surplus[O_LAST]
Definition cm.h:41
int happy_factor
Definition cm.h:48
Definition colors.h:21
Definition mapimg.c:367
enum impr_genus_id genus
Definition improvement.h:63
struct requirement_vector obsolete_by
Definition improvement.h:59
Definition climisc.h:82
struct universal item
Definition climisc.h:83
enum unit_activity activity
struct city_list * cities
Definition player.h:281
struct player_economic economic
Definition player.h:284
QPixmap * pm
Definition sprite.h:25
Definition tile.h:50
int index
Definition tile.h:51
struct unit_list * units
Definition tile.h:58
int defense_strength
Definition unittype.h:523
int firepower
Definition unittype.h:532
const struct unit_type * obsoleted_by
Definition unittype.h:536
int vision_radius_sq
Definition unittype.h:529
int move_rate
Definition unittype.h:524
int attack_strength
Definition unittype.h:522
Definition unit.h:140
int upkeep[O_LAST]
Definition unit.h:150
int id
Definition unit.h:147
struct tile * tile
Definition unit.h:142
int homecity
Definition unit.h:148
enum universals_n kind
Definition fc_types.h:595
universals_u value
Definition fc_types.h:594
struct universal entries[MAX_LEN_WORKLIST]
Definition worklist.h:30
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define TRUE
Definition support.h:46
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:110
bool is_future_tech(Tech_type_id tech)
Definition tech.c:286
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:305
struct advance * valid_advance_by_number(const Tech_type_id id)
Definition tech.c:181
#define A_NONE
Definition tech.h:43
const char * text_happiness_nationality(const struct city *pcity)
Definition text.c:1907
const char * text_happiness_wonders(const struct city *pcity)
Definition text.c:1949
const char * text_happiness_units(const struct city *pcity)
Definition text.c:2113
const char * text_happiness_luxuries(const struct city *pcity)
Definition text.c:2152
const char * text_happiness_buildings(const struct city *pcity)
Definition text.c:1879
const char * unit_description(struct unit *punit)
Definition text.c:528
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_terrain(_tile)
Definition tile.h:115
int tileset_hex_width(const struct tileset *t)
Definition tilespec.c:747
struct sprite * get_building_sprite(const struct tileset *t, const struct impr_type *pimprove)
Definition tilespec.c:7033
int tileset_unit_width(const struct tileset *t)
Definition tilespec.c:823
int tileset_unit_height(const struct tileset *t)
Definition tilespec.c:831
int tileset_small_sprite_width(const struct tileset *t)
Definition tilespec.c:927
struct tileset * get_tileset(void)
Definition tilespec.c:718
struct tileset * unscaled_tileset
Definition tilespec.c:592
int tileset_unit_layout_offset_y(const struct tileset *t)
Definition tilespec.c:908
bool tileset_is_isometric(const struct tileset *t)
Definition tilespec.c:738
int tileset_small_sprite_height(const struct tileset *t)
Definition tilespec.c:963
struct sprite * get_icon_sprite(const struct tileset *t, enum icon_type icon)
Definition tilespec.c:7237
int tileset_unit_with_upkeep_height(const struct tileset *t)
Definition tilespec.c:885
int tileset_hex_height(const struct tileset *t)
Definition tilespec.c:756
struct sprite * get_citizen_sprite(const struct tileset *t, enum citizen_category type, int citizen_index, const struct city *pcity)
Definition tilespec.c:6972
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:7055
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:7006
struct sprite * get_tech_sprite(const struct tileset *t, Tech_type_id tech)
Definition tilespec.c:7024
@ ICON_CITYDLG
Definition tilespec.h:317
const struct unit_type * utype
Definition fc_types.h:536
const struct impr_type * building
Definition fc_types.h:529
bool can_unit_change_homecity(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:524
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:402
#define unit_tile(_pu)
Definition unit.h:408
#define unit_owner(_pu)
Definition unit.h:407
bool units_are_occupied(const struct unit_list *punits)
Definition unitlist.c:275
bool units_can_unload(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:303
bool units_can_upgrade(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:337
bool units_can_load(const struct unit_list *punits)
Definition unitlist.c:289
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1493
bool utype_is_consumed_by_action_result(enum action_result result, const struct unit_type *utype)
Definition unittype.c:1254
struct advance * utype_primary_tech_req(const struct unit_type *ptype)
Definition unittype.c:2747
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:412
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1463
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1586
const char * utype_values_translation(const struct unit_type *punittype)
Definition unittype.c:1643
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:773
#define utype_class(_t_)
Definition unittype.h:756
#define utype_fuel(ptype)
Definition unittype.h:849
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
void worklist_init(struct worklist *pwl)
Definition worklist.c:38
bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod, int idx)
Definition worklist.c:86
bool worklist_insert(struct worklist *pwl, const struct universal *prod, int idx)
Definition worklist.c:167
void worklist_remove(struct worklist *pwl, int idx)
Definition worklist.c:122
int worklist_length(const struct worklist *pwl)
Definition worklist.c:57