Freeciv-3.1
Loading...
Searching...
No Matches
repodlgs.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 <QComboBox>
21#include <QElapsedTimer>
22#include <QGridLayout>
23#include <QGroupBox>
24#include <QHeaderView>
25#include <QMessageBox>
26#include <QMouseEvent>
27#include <QPainter>
28#include <QRadioButton>
29#include <QScrollArea>
30#include <QTableWidget>
31#include <QtMath>
32#include <QToolTip>
33
34// common
35#include "control.h"
36#include "government.h"
37#include "research.h"
38
39// client
40#include "client_main.h"
41#include "gui_main.h"
42#include "helpdata.h"
43#include "options.h"
44#include "repodlgs_common.h"
45#include "reqtree.h"
46#include "sprite.h"
47#include "text.h"
48#include "tilespec.h"
49
50// gui-qt
51#include "citydlg.h"
52#include "cityrep.h"
53#include "fc_client.h"
54#include "hudwidget.h"
55#include "sidebar.h"
56
57#include "repodlgs.h"
58
59extern QString split_text(QString text, bool cut);
60extern QString cut_helptext(QString text);
61extern QString get_tooltip_improvement(impr_type *building,
62 struct city *pcity, bool ext);
63extern QString get_tooltip_unit(struct unit_type *unit, bool ext);
64
66
67/****************************************************************************
68 From reqtree.c used to get tooltips
69****************************************************************************/
81
82/****************************************************************************
83 From reqtree.c used to get tooltips
84****************************************************************************/
93
94/************************************************************************/
98 struct unit_type *ut): QFrame(parent)
99{
100 int isize;
101 QFont f;
102 QFontMetrics *fm;
103 QHBoxLayout *hbox;
104 QHBoxLayout *hbox_top;
105 QHBoxLayout *hbox_upkeep;
106 QImage cropped_img;
107 QImage img;
108 QLabel *lab;
109 QPixmap pix;
110 QRect crop;
111 QSizePolicy size_fixed_policy(QSizePolicy::Maximum, QSizePolicy::Maximum,
112 QSizePolicy::Slider);
113 QSpacerItem *spacer;
114 QVBoxLayout *vbox;
115 QVBoxLayout *vbox_main;
116 struct sprite *spr;
117
118 setParent(parent);
119 utype = ut;
120 init_img();
121 unit_scroll = 0;
122 setSizePolicy(size_fixed_policy);
124 fm = new QFontMetrics(f);
125 isize = fm->height() * 2 / 3;
126 vbox_main = new QVBoxLayout();
127 hbox = new QHBoxLayout();
128 vbox = new QVBoxLayout();
129 hbox_top = new QHBoxLayout();
130 upgrade_button.setText("★");
131 upgrade_button.setVisible(false);
132 connect(&upgrade_button, &QAbstractButton::pressed, this, &unittype_item::upgrade_units);
133 hbox_top->addWidget(&upgrade_button, 0, Qt::AlignLeft);
134 label_info_unit.setTextFormat(Qt::PlainText);
135 hbox_top->addWidget(&label_info_unit);
136 vbox_main->addLayout(hbox_top);
137 vbox->addWidget(&label_info_active);
138 vbox->addWidget(&label_info_inbuild);
139 hbox->addWidget(&label_pix);
140 hbox->addLayout(vbox);
141 vbox_main->addLayout(hbox);
142 hbox_upkeep = new QHBoxLayout;
143 hbox_upkeep->addWidget(&shield_upkeep);
144 lab = new QLabel("");
145 spr = tiles_lookup_sprite_tag_alt(tileset, LOG_VERBOSE, "upkeep.shield",
146 "citybar.shields", "", "", false);
147 img = spr->pm->toImage();
148 crop = zealous_crop_rect(img);
149 cropped_img = img.copy(crop);
150 pix = QPixmap::fromImage(cropped_img);
151 lab->setPixmap(pix.scaledToHeight(isize));
152 hbox_upkeep->addWidget(lab);
153 spacer = new QSpacerItem(0, isize, QSizePolicy::Expanding,
154 QSizePolicy::Minimum);
155 hbox_upkeep->addSpacerItem(spacer);
156 hbox_upkeep->addWidget(&gold_upkeep);
158 lab = new QLabel("");
159 lab->setPixmap(spr->pm->scaledToHeight(isize));
160 hbox_upkeep->addWidget(lab);
161 spacer = new QSpacerItem(0, isize, QSizePolicy::Expanding,
162 QSizePolicy::Minimum);
163 hbox_upkeep->addSpacerItem(spacer);
164 hbox_upkeep->addWidget(&food_upkeep);
165 lab = new QLabel("");
166 spr = tiles_lookup_sprite_tag_alt(tileset, LOG_VERBOSE, "citybar.food",
167 "citybar.food", "", "", false);
168 img = spr->pm->toImage();
169 crop = zealous_crop_rect(img);
170 cropped_img = img.copy(crop);
171 pix = QPixmap::fromImage(cropped_img);
172 lab->setPixmap(pix.scaledToHeight(isize));
173 hbox_upkeep->addWidget(lab);
174 vbox_main->addLayout(hbox_upkeep);
175 setLayout(vbox_main);
176 entered = false;
177 delete fm;
178}
179
180/************************************************************************/
187
188/************************************************************************/
192{
193 struct sprite *sp;
194
195 sp = get_unittype_sprite(get_tileset(), utype, direction8_invalid());
196 label_pix.setPixmap(*sp->pm);
197}
198
199/************************************************************************/
203{
204 char buf[1024];
205 char buf2[2048];
206 hud_message_box *ask = new hud_message_box(gui()->central_wdg);
207 int price;
208 QString s2;
209 const struct unit_type *upgrade;
211
213 price = unit_upgrade_price(client_player(), utype, upgrade);
214 fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Treasury contains %d gold.",
215 "Treasury contains %d gold.",
216 client_player()->economic.gold),
217 client_player()->economic.gold);
218 fc_snprintf(buf2, ARRAY_SIZE(buf2),
219 PL_("Upgrade as many %s to %s as possible "
220 "for %d gold each?\n%s",
221 "Upgrade as many %s to %s as possible "
222 "for %d gold each?\n%s", price),
224 utype_name_translation(upgrade), price, buf);
225 s2 = QString(buf2);
226 ask->set_text_title(s2, _("Upgrade Obsolete Units"));
227 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
228 ask->setDefaultButton(QMessageBox::Cancel);
229 ask->setAttribute(Qt::WA_DeleteOnClose);
230 connect(ask, &hud_message_box::accepted, [=]() {
232 });
233 ask->show();
234}
235
236/************************************************************************/
239#ifndef FC_QT5_MODE
241#else // FC_QT5_MODE
243#endif // FC_QT5_MODE
244{
245 entered = true;
246 update();
247}
248
249/************************************************************************/
253{
254 QRect rfull;
255 QPainter p;
256
257 if (entered) {
258 rfull = QRect(1 , 1, width() - 2 , height() - 2);
259 p.begin(this);
260 p.setPen(QColor(palette().color(QPalette::Highlight)));
261 p.drawRect(rfull);
262 p.end();
263 }
264}
265
266/************************************************************************/
270{
271 entered = false;
272 update();
273}
274
275/************************************************************************/
279{
280 int unit_count = 0;
281
283 if (punit->utype != utype) {
284 continue;
285 }
286 if (ACTIVITY_IDLE == punit->activity
287 || ACTIVITY_SENTRY == punit->activity) {
288 if (can_unit_do_activity_client(punit, ACTIVITY_IDLE)) {
289 unit_count++;
290 }
291 }
293
294 if (event->angleDelta().y() < 0) {
295 unit_scroll--;
296 } else {
297 unit_scroll++;
298 }
299 if (unit_scroll < 0) {
300 unit_scroll = unit_count;
301 } else if (unit_scroll > unit_count) {
302 unit_scroll = 0;
303 }
304
305 unit_count = 0;
306
308 if (punit->utype != utype) {
309 continue;
310 }
311 if (ACTIVITY_IDLE == punit->activity
312 || ACTIVITY_SENTRY == punit->activity) {
313 if (can_unit_do_activity_client(punit, ACTIVITY_IDLE)) {
314 unit_count++;
315 if (unit_count == unit_scroll) {
317 }
318 }
319 }
321 event->accept();
322}
323
324/************************************************************************/
328{
329 layout = new QHBoxLayout;
330 scroll_layout = new QHBoxLayout(this);
331 init_layout();
332 setParent(gui()->mapview_wdg);
333 cw = new close_widget(this);
334 cw->setFixedSize(12, 12);
335 setVisible(false);
336}
337
338/************************************************************************/
342{
343 qDeleteAll(unittype_list);
344 unittype_list.clear();
345 delete cw;
346}
347
348/************************************************************************/
355
356/************************************************************************/
365
366/************************************************************************/
370{
371 if (m_instance) {
372 delete m_instance;
373 m_instance = 0;
374 }
375}
376
377/************************************************************************/
381{
382 was_destroyed = true;
383 drop();
384}
385
386/************************************************************************/
390{
391 QSizePolicy size_fixed_policy(QSizePolicy::Maximum,
392 QSizePolicy::Maximum,
393 QSizePolicy::Slider);
394
395 scroll = new QScrollArea(this);
396 setSizePolicy(size_fixed_policy);
397 scroll->setWidgetResizable(true);
398 scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
399 scroll_widget.setLayout(layout);
400 scroll->setWidget(&scroll_widget);
401 scroll->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
402 scroll->setProperty("city_scroll", true);
403 scroll_layout->addWidget(scroll);
404 setLayout(scroll_layout);
405}
406
407/************************************************************************/
411{
412 cw->put_to_corner();
413}
414
415/************************************************************************/
419{
420 struct urd_info {
421 int active_count;
422 int building_count;
423 int upkeep[O_LAST];
424 };
425 bool upgradable;
426 int i, j;
427 int output;
428 int total_len = 0;
429 struct urd_info *info;
430 struct urd_info *unit_array = (struct urd_info *)fc_calloc(sizeof(struct urd_info), utype_count());
431 struct urd_info unit_totals;
432 Unit_type_id utype_id;
433 unittype_item *ui = nullptr;
434
435 clear_layout();
436 memset(&unit_totals, '\0', sizeof(unit_totals));
437 /* Count units. */
438 players_iterate(pplayer) {
439 if (client_has_player() && pplayer != client_player()) {
440 continue;
441 }
442 unit_list_iterate(pplayer->units, punit) {
443 info = unit_array + utype_index(unit_type_get(punit));
444 if (0 != punit->homecity) {
445 for (output = 0; output < O_LAST; output++) {
446 info->upkeep[output] += punit->upkeep[output];
447 }
448 }
449 info->active_count++;
451 city_list_iterate(pplayer->cities, pcity) {
452 if (VUT_UTYPE == pcity->production.kind) {
453 int num_units;
454 info = unit_array + utype_index(pcity->production.value.utype);
455 /* Account for build slots in city */
456 (void) city_production_build_units(pcity, true, &num_units);
457 /* Unit is in progress even if it won't be done this turn */
458 num_units = MAX(num_units, 1);
459 info->building_count += num_units;
460 }
463
464 unit_type_iterate(utype) {
465 utype_id = utype_index(utype);
466 info = unit_array + utype_id;
467 upgradable = client_has_player()
468 && nullptr != can_upgrade_unittype(client_player(), utype);
469 if (0 == info->active_count && 0 == info->building_count) {
470 continue; /* We don't need a row for this type. */
471 }
472 ui = new unittype_item(this, utype);
473 ui->label_info_active.setText("⚔:" + QString::number(info->active_count));
474 ui->label_info_inbuild.setText("⚒:" + QString::number(info->building_count));
475 ui->label_info_unit.setText(utype_name_translation(utype));
476 if (upgradable) {
477 ui->upgrade_button.setVisible(true);
478 } else {
479 ui->upgrade_button.setVisible(false);
480 }
481 ui->shield_upkeep.setText(QString::number(info->upkeep[O_SHIELD]));
482 ui->food_upkeep.setText(QString::number(info->upkeep[O_FOOD]));
483 ui->gold_upkeep.setText(QString::number(info->upkeep[O_GOLD]));
484 add_item(ui);
486
487 free(unit_array);
488
489 setUpdatesEnabled(false);
490 hide();
491 i = unittype_list.count();
492 for (j = 0; j < i; j++) {
493 ui = unittype_list[j];
494 layout->addWidget(ui, 0, Qt::AlignVCenter);
495 total_len = total_len + ui->sizeHint().width() + 18;
496 }
497
498 total_len = total_len + contentsMargins().left()
499 + contentsMargins().right();
500 if (show) {
501 setVisible(true);
502 }
503 setUpdatesEnabled(true);
504 setFixedWidth(qMin(total_len, gui()->mapview_wdg->width()));
505 if (ui != nullptr) {
506 setFixedHeight(ui->height() + 60);
507 }
508 layout->update();
509 updateGeometry();
510}
511
512/************************************************************************/
516{
517 int i = unittype_list.count();
518 unittype_item *ui;
519 int j;
520
521 setUpdatesEnabled(false);
522 setMouseTracking(false);
523
524 for (j = 0; j < i; j++) {
525 ui = unittype_list[j];
526 layout->removeWidget(ui);
527 delete ui;
528 }
529
530 while (!unittype_list.empty()) {
531 unittype_list.removeFirst();
532 }
533
534 setMouseTracking(true);
535 setUpdatesEnabled(true);
536}
537
538/************************************************************************/
541bool comp_less_than(const qlist_item &q1, const qlist_item &q2)
542{
543 return (q1.tech_str < q2.tech_str);
544}
545
546/************************************************************************/
549research_diagram::research_diagram(QWidget *parent): QWidget(parent)
550{
551 pcanvas = NULL;
552 req = NULL;
553 reset();
554 setMouseTracking(true);
555}
556
557/************************************************************************/
561{
564 qDeleteAll(tt_help);
565 tt_help.clear();
566}
567
568/************************************************************************/
572{
573 tech_id = -1;
574 tunit = nullptr;
575 timpr = nullptr;
576}
577
578/************************************************************************/
582{
583 int i, j;
584 int swidth, sheight;
585 struct sprite *sprite;
586 reqtree *tree;
587 req_tooltip_help *rttp;
588
589 qDeleteAll(tt_help);
590 tt_help.clear();
591 if (req == nullptr) {
592 return;
593 } else {
594 tree = req;
595 }
596
597 for (i = 0; i < tree->num_layers; i++) {
598 for (j = 0; j < tree->layer_size[i]; j++) {
599 struct tree_node *node = tree->layers[i][j];
600 int startx, starty, nwidth, nheight;
601
602 startx = node->node_x;
603 starty = node->node_y;
604 nwidth = node->node_width;
605 nheight = node->node_height;
606
607 if (!node->is_dummy) {
608 const char *text = research_advance_name_translation(
610 int text_w, text_h;
611 int icon_startx;
612
613 get_text_size(&text_w, &text_h, FONT_REQTREE_TEXT, text);
614 rttp = new req_tooltip_help();
615 rttp->rect = QRect(startx + (nwidth - text_w) / 2, starty + 4,
616 text_w, text_h);
617 rttp->tech_id = node->tech;
618 tt_help.append(rttp);
619 icon_startx = startx + 5;
620
623 if (advance_number(unit->require_advance) != node->tech) {
624 continue;
625 }
626 sprite = get_unittype_sprite(tileset, unit, direction8_invalid());
627 get_sprite_dimensions(sprite, &swidth, &sheight);
628 rttp = new req_tooltip_help();
629 rttp->rect = QRect(icon_startx, starty + text_h + 4
630 + (nheight - text_h - 4 - sheight) / 2,
631 swidth, sheight);
632 rttp->tunit = unit;
633 tt_help.append(rttp);
634 icon_startx += swidth + 2;
636
637 improvement_iterate(pimprove) {
638 if (valid_improvement(pimprove)) {
639 requirement_vector_iterate(&(pimprove->reqs), preq) {
640 if (VUT_ADVANCE == preq->source.kind
641 && advance_number(preq->source.value.advance) == node->tech) {
643 if (sprite) {
644 get_sprite_dimensions(sprite, &swidth, &sheight);
645 rttp = new req_tooltip_help();
646 rttp->rect = QRect(icon_startx, starty + text_h + 4
647 + (nheight - text_h - 4 - sheight) / 2,
648 swidth, sheight);
649 rttp->timpr = pimprove;
650 tt_help.append(rttp);
651 icon_startx += swidth + 2;
652 }
653 }
655 }
657
659 requirement_vector_iterate(&(gov->reqs), preq) {
660 if (VUT_ADVANCE == preq->source.kind
661 && advance_number(preq->source.value.advance) == node->tech) {
663 get_sprite_dimensions(sprite, &swidth, &sheight);
664 rttp = new req_tooltip_help();
665 rttp->rect = QRect(icon_startx, starty + text_h + 4
666 + (nheight - text_h - 4 - sheight) / 2,
667 swidth, sheight);
668 rttp->tgov = gov;
669 tt_help.append(rttp);
670 icon_startx += swidth + 2;
671 }
674 }
675 }
676 }
677 }
678}
679
680/************************************************************************/
684{
685 reset();
686 draw_reqtree(req, pcanvas, 0, 0, 0, 0, width, height);
688 update();
689}
690
691/************************************************************************/
695{
696 timer_active = false;
697 if (req != NULL) {
699 }
700 if (pcanvas != NULL) {
702 }
706 pcanvas->map_pixmap.fill(Qt::transparent);
707 resize(width, height);
708}
709
710
711/************************************************************************/
715{
716 QPoint pos = event->pos();
717 Tech_type_id tech = get_tech_on_reqtree(req, pos.x(), pos.y());
718 req_tooltip_help *rttp;
719 int i;
720
721 if (event->button() == Qt::LeftButton && can_client_issue_orders()) {
723 case TECH_PREREQS_KNOWN:
725 break;
726 case TECH_UNKNOWN:
728 break;
729 case TECH_KNOWN:
730 break;
731 }
732 } else if (event->button() == Qt::RightButton) {
733 for (i = 0; i < tt_help.count(); i++) {
734 rttp = tt_help.at(i);
735 if (rttp->rect.contains(event->pos())) {
736 if (rttp->tech_id != -1) {
739 rttp->tech_id), HELP_TECH);
740 } else if (rttp->timpr != nullptr) {
744 } else if (rttp->tunit != nullptr) {
746 HELP_UNIT);
747 } else if (rttp->tgov != nullptr) {
750 } else {
751 return;
752 }
753 }
754 }
755 }
756}
757
758/************************************************************************/
762{
763 req_tooltip_help *rttp;
764 int i;
765 QString tt_text;
766 QString def_str;
767 char buffer[8192];
768 char buf2[1];
769
770 buf2[0] = '\0';
771 for (i = 0; i < tt_help.count(); i++) {
772 rttp = tt_help.at(i);
773 if (rttp->rect.contains(event->pos())) {
774 if (rttp->tech_id != -1) {
775 helptext_advance(buffer, sizeof(buffer), client.conn.playing,
776 buf2, rttp->tech_id);
777 tt_text = QString(buffer);
778 def_str = "<p style='white-space:pre'><b>"
779 + QString(advance_name_translation(
780 advance_by_number(rttp->tech_id))).toHtmlEscaped()
781 + "</b>\n";
782 } else if (rttp->timpr != nullptr) {
783 def_str = get_tooltip_improvement(rttp->timpr, nullptr);
784 tt_text = helptext_building(buffer, sizeof(buffer),
785 client.conn.playing, NULL, rttp->timpr);
786 tt_text = cut_helptext(tt_text);
787 } else if (rttp->tunit != nullptr) {
788 def_str = get_tooltip_unit(rttp->tunit);
789 tt_text += helptext_unit(buffer, sizeof(buffer), client.conn.playing,
790 buf2, rttp->tunit);
791 tt_text = cut_helptext(tt_text);
792 } else if (rttp->tgov != nullptr) {
793 helptext_government(buffer, sizeof(buffer), client.conn.playing,
794 buf2, rttp->tgov);
795 tt_text = QString(buffer);
796 tt_text = cut_helptext(tt_text);
797 def_str = "<p style='white-space:pre'><b>"
798 + QString(government_name_translation(rttp->tgov)).toHtmlEscaped()
799 + "</b>\n";
800 } else {
801 return;
802 }
803 tt_text = split_text(tt_text, true);
804 tt_text = def_str + tt_text.toHtmlEscaped();
805 tooltip_text = tt_text.trimmed();
806 tooltip_rect = rttp->rect;
808 if (!QToolTip::isVisible() && !timer_active) {
809 timer_active = true;
810 QTimer::singleShot(500, this, SLOT(show_tooltip()));
811 }
812 }
813 }
814}
815
816/************************************************************************/
820{
821 QPoint cp;
822
823 timer_active = false;
824 cp = QCursor::pos();
825 if (qAbs(cp.x() - tooltip_pos.x()) < 4
826 && qAbs(cp.y() - tooltip_pos.y()) < 4) {
827 QToolTip::showText(cp, tooltip_text, this, tooltip_rect);
828 }
829}
830
831/************************************************************************/
835{
836 QPainter painter;
837
838 painter.begin(this);
839 painter.drawPixmap(0, 0, width, height, pcanvas->map_pixmap);
840 painter.end();
841}
842
843/************************************************************************/
847{
848 QSize s;
849
850 s.setWidth(width);;
851 s.setHeight(height);
852 return s;
853}
854
855/************************************************************************/
859{
860 QSize size;
861 QSizePolicy size_expanding_policy(QSizePolicy::Expanding,
862 QSizePolicy::Expanding);
863 QSizePolicy size_fixed_policy(QSizePolicy::Minimum, QSizePolicy::Minimum);
864
865 goal_combo = new QComboBox();
866 info_label = new QLabel();
867 progress = new progress_bar(this);
868 progress_label = new QLabel();
869 researching_combo = new QComboBox();
870 sci_layout = new QGridLayout();
872 scroll = new QScrollArea();
873
874 curr_list = NULL;
875 goal_list = NULL;
876 progress->setTextVisible(true);
877 progress_label->setSizePolicy(size_fixed_policy);
878 sci_layout->addWidget(progress_label, 0, 0, 1, 8);
879 sci_layout->addWidget(researching_combo, 1, 0, 1, 4);
880 researching_combo->setSizePolicy(size_fixed_policy);
881 sci_layout->addWidget(progress, 1, 5, 1, 4);
882 progress->setSizePolicy(size_fixed_policy);
883 sci_layout->addWidget(goal_combo, 2, 0, 1, 4);
884 goal_combo->setSizePolicy(size_fixed_policy);
885 sci_layout->addWidget(info_label, 2, 5, 1, 4);
886 info_label->setSizePolicy(size_fixed_policy);
887
888 size = res_diag->size();
889 res_diag->setMinimumSize(size);
890 scroll->setAutoFillBackground(true);
891 scroll->setPalette(QPalette(QColor(215,215,215)));
892 scroll->setWidget(res_diag);
893 scroll->setSizePolicy(size_expanding_policy);
894 sci_layout->addWidget(scroll, 4, 0, 1, 10);
895
896 QObject::connect(researching_combo, SIGNAL(currentIndexChanged(int)),
897 SLOT(current_tech_changed(int)));
898
899 QObject::connect(goal_combo, SIGNAL(currentIndexChanged(int)),
900 SLOT(goal_tech_changed(int)));
901
902 setLayout(sci_layout);
903
904}
905
906/************************************************************************/
912{
913 if (curr_list) {
914 delete curr_list;
915 }
916
917 if (goal_list) {
918 delete goal_list;
919 }
920 gui()->remove_repo_dlg("SCI");
921}
922
923/************************************************************************/
929{
930 gui()->gimme_place(this, "SCI");
931 index = gui()->add_game_tab(this);
932 gui()->game_tab_widget->setCurrentIndex(index);
934}
935
936/************************************************************************/
940{
941 update();
942}
943
944/************************************************************************/
948{
949 QSize size;
950 res_diag->reset();
951 size = res_diag->size();
952 res_diag->setMinimumSize(size);
953 update();
954}
955
956/************************************************************************/
960{
961
963 const char *text;
964 int total;
965 int done = research->bulbs_researched;
966 QVariant qvar, qres;
967 double not_used;
968 QString str;
970 struct sprite *sp;
971
972 fc_assert_ret(NULL != research);
973
974 if (curr_list) {
975 delete curr_list;
976 }
977
978 if (goal_list) {
979 delete goal_list;
980 }
981
982 if (research->researching != A_UNSET) {
984 } else {
985 total = -1;
986 }
987
988 curr_list = new QList<qlist_item>;
989 goal_list = new QList<qlist_item>;
991 progress_label->setAlignment(Qt::AlignHCenter);
992 info_label->setAlignment(Qt::AlignHCenter);
994 text = get_science_target_text(&not_used);
995 str = QString::fromUtf8(text);
996 progress->setFormat(str);
997 progress->setMinimum(0);
998 progress->setMaximum(total);
999 progress->set_pixmap(static_cast<int>(research->researching));
1000
1001 if (done <= total) {
1002 progress->setValue(done);
1003 } else {
1004 done = total;
1005 progress->setValue(done);
1006 }
1007
1010 if (TECH_PREREQS_KNOWN == research->inventions[i].state) {
1011 item.tech_str
1012 =
1013 QString::fromUtf8(advance_name_translation(advance_by_number(i)));
1014 item.id = i;
1015 curr_list->append(item);
1016 }
1018
1019
1023 && TECH_KNOWN != research->inventions[i].state
1024 && (i == research->tech_goal
1025 || 10 >= research->inventions[i].num_required_techs)) {
1026 item.tech_str
1027 = QString::fromUtf8(advance_name_translation(advance_by_number(i)));
1028 item.id = i;
1029 goal_list->append(item);
1030 }
1032
1034 std::sort(goal_list->begin(), goal_list->end(), comp_less_than);
1035 std::sort(curr_list->begin(), curr_list->end(), comp_less_than);
1036
1038 researching_combo->blockSignals(true);
1039 goal_combo->blockSignals(true);
1040
1041 researching_combo->clear();
1042 goal_combo->clear();
1043 for (int i = 0; i < curr_list->count(); i++) {
1044 QIcon ic;
1045
1046 sp = get_tech_sprite(tileset, curr_list->at(i).id);
1047 if (sp) {
1048 ic = QIcon(*sp->pm);
1049 }
1050 qvar = curr_list->at(i).id;
1051 researching_combo->insertItem(i, ic, curr_list->at(i).tech_str, qvar);
1052 }
1053
1054 for (int i = 0; i < goal_list->count(); i++) {
1055 QIcon ic;
1056
1057 sp = get_tech_sprite(tileset, goal_list->at(i).id);
1058 if (sp) {
1059 ic = QIcon(*sp->pm);
1060 }
1061 qvar = goal_list->at(i).id;
1062 goal_combo->insertItem(i, ic, goal_list->at(i).tech_str, qvar);
1063 }
1064
1066 qres = research->researching;
1067 if (qres == A_UNSET || is_future_tech(research->researching)) {
1070 A_UNSET);
1071 researching_combo->setCurrentIndex(0);
1072 } else {
1073 for (int i = 0; i < researching_combo->count(); i++) {
1074 qvar = researching_combo->itemData(i);
1075
1076 if (qvar == qres) {
1077 researching_combo->setCurrentIndex(i);
1078 }
1079 }
1080 }
1081
1082 qres = research->tech_goal;
1083
1084 if (qres == A_UNSET) {
1085 goal_combo->insertItem(0, Q_("?tech:None"), A_UNSET);
1086 goal_combo->setCurrentIndex(0);
1087 } else {
1088 for (int i = 0; i < goal_combo->count(); i++) {
1089 qvar = goal_combo->itemData(i);
1090
1091 if (qvar == qres) {
1092 goal_combo->setCurrentIndex(i);
1093 }
1094 }
1095 }
1096
1097 researching_combo->blockSignals(false);
1098 goal_combo->blockSignals(false);
1099
1100 if (client_is_observer()) {
1101 researching_combo->setDisabled(true);
1102 goal_combo->setDisabled(true);
1103 } else {
1104 researching_combo->setDisabled(false);
1105 goal_combo->setDisabled(false);
1106 }
1108}
1109
1110/************************************************************************/
1117
1118/************************************************************************/
1122{
1123 QVariant qvar;
1124
1125 qvar = researching_combo->itemData(changed_index);
1126
1127 if (researching_combo->hasFocus()) {
1130 }
1131 }
1132}
1133
1134/************************************************************************/
1138{
1139 QVariant qvar;
1140
1141 qvar = goal_combo->itemData(changed_index);
1142
1143 if (goal_combo->hasFocus()) {
1146 }
1147 }
1148}
1149
1150/************************************************************************/
1154{
1155 int i;
1156 int percent;
1157 science_report *sci_rep;
1158 bool blk = false;
1159 QWidget *w;
1160 QString str;
1161 struct player *plr = client_player();
1162
1163 if (NULL != plr) {
1164 struct research *research = research_get(plr);
1165
1166 if (research->researching == A_UNSET) {
1167 str = QString(Q_("?tech:None"));
1168 } else if (research->client.researching_cost != 0) {
1171 str = str + "\n (" + QString::number(percent) + "%)";
1172 }
1175 blk = true;
1176 }
1177 } else {
1178 str = " ";
1179 }
1180
1181 if (blk) {
1182 gui()->sw_science->keep_blinking = true;
1183 gui()->sw_science->set_custom_labels(str);
1184 gui()->sw_science->sblink();
1185 } else {
1186 gui()->sw_science->keep_blinking = false;
1187 gui()->sw_science->set_custom_labels(str);
1188 gui()->sw_science->update_final_pixmap();
1189 }
1190 gui()->update_sidebar_tooltips();
1191
1192 if (gui()->is_repo_dlg_open("SCI")) {
1193 i = gui()->gimme_index_of("SCI");
1194 fc_assert(i != -1);
1195 w = gui()->game_tab_widget->widget(i);
1196 sci_rep = reinterpret_cast<science_report*>(w);
1197 sci_rep->update_report();
1198 }
1199}
1200
1201/************************************************************************/
1205{
1206 QHeaderView *header;
1207 QGridLayout *eco_layout = new QGridLayout;
1208 eco_widget = new QTableWidget;
1209 disband_button = new QPushButton;
1210 sell_button = new QPushButton;
1211 sell_redun_button = new QPushButton;
1212 eco_label = new QLabel;
1213
1214 QStringList slist;
1215 slist << _("Type") << Q_("?Building or Unit type:Name") << _("Redundant")
1216 << _("Count") << _("Cost") << _("U Total");
1217 eco_widget->setColumnCount(slist.count());
1218 eco_widget->setHorizontalHeaderLabels(slist);
1219 eco_widget->setProperty("showGrid", "false");
1220 eco_widget->setProperty("selectionBehavior", "SelectRows");
1221 eco_widget->setEditTriggers(QAbstractItemView::NoEditTriggers);
1222 eco_widget->horizontalHeader()->resizeSections(QHeaderView::Stretch);
1223 eco_widget->verticalHeader()->setVisible(false);
1224 eco_widget->setSelectionMode(QAbstractItemView::SingleSelection);
1225 eco_widget->setSortingEnabled(true);
1226 header = eco_widget->horizontalHeader();
1227 header->setSectionResizeMode(1, QHeaderView::Stretch);
1228 header->setStretchLastSection(true);
1229 disband_button->setText(_("Disband"));
1230 disband_button->setEnabled(false);
1231 sell_button->setText(_("Sell All"));
1232 sell_button->setEnabled(false);
1233 sell_redun_button->setText(_("Sell Redundant"));
1234 sell_redun_button->setEnabled(false);
1235 eco_layout->addWidget(eco_widget, 1, 0, 5, 5);
1236 eco_layout->addWidget(disband_button, 0, 0, 1, 1);
1237 eco_layout->addWidget(sell_button, 0, 1, 1, 1);
1238 eco_layout->addWidget(sell_redun_button, 0, 2, 1, 1);
1239 eco_layout->addWidget(eco_label, 6, 0, 1, 5);
1240
1241 connect(disband_button, &QAbstractButton::pressed, this, &eco_report::disband_units);
1242 connect(sell_button, &QAbstractButton::pressed, this, &eco_report::sell_buildings);
1243 connect(sell_redun_button, &QAbstractButton::pressed, this, &eco_report::sell_redundant);
1244 connect(eco_widget->selectionModel(),
1245 SIGNAL(selectionChanged(const QItemSelection &,
1246 const QItemSelection &)),
1247 SLOT(selection_changed(const QItemSelection &,
1248 const QItemSelection &)));
1249 setLayout(eco_layout);
1250}
1251
1252/************************************************************************/
1256{
1257 gui()->remove_repo_dlg("ECO");
1258}
1259
1260/************************************************************************/
1264{
1265 curr_row = -1;
1266 gui()->gimme_place(this, "ECO");
1267 index = gui()->add_game_tab(this);
1268 gui()->game_tab_widget->setCurrentIndex(index);
1269}
1270
1271/************************************************************************/
1275{
1276 struct improvement_entry building_entries[B_LAST];
1277 struct unit_entry unit_entries[U_LAST];
1278 int entries_used, building_total, unit_total, tax, i, j;
1279 char buf[256];
1280 QTableWidgetItem *item;
1281 QFont f = QApplication::font();
1282 int h;
1283 QFontMetrics fm(f);
1284 h = fm.height() + 6;
1285 QPixmap *pix;
1286 QPixmap pix_scaled;
1287 struct sprite *sprite;
1288
1289 eco_widget->setRowCount(0);
1290 eco_widget->clearContents();
1291 get_economy_report_data(building_entries, &entries_used,
1292 &building_total, &tax);
1293 for (i = 0; i < entries_used; i++) {
1294 struct improvement_entry *pentry = building_entries + i;
1295 struct impr_type *pimprove = pentry->type;
1296
1297 pix = NULL;
1298 sprite = get_building_sprite(tileset, pimprove);
1299 if (sprite != NULL) {
1300 pix = sprite->pm;
1301 }
1302 if (pix != NULL) {
1303 pix_scaled = pix->scaledToHeight(h);
1304 } else {
1305 pix_scaled.fill();
1306 }
1307 cid id = cid_encode_building(pimprove);
1308
1309 eco_widget->insertRow(i);
1310 for (j = 0; j < 6; j++) {
1311 item = new QTableWidgetItem;
1312 switch (j) {
1313 case 0:
1314 item->setData(Qt::DecorationRole, pix_scaled);
1315 item->setData(Qt::UserRole, id);
1316 break;
1317 case 1:
1318 item->setTextAlignment(Qt::AlignLeft);
1319 item->setText(improvement_name_translation(pimprove));
1320 break;
1321 case 2:
1322 item->setData(Qt::DisplayRole, pentry->redundant);
1323 break;
1324 case 3:
1325 item->setData(Qt::DisplayRole, pentry->count);
1326 break;
1327 case 4:
1328 item->setData(Qt::DisplayRole, pentry->cost);
1329 break;
1330 case 5:
1331 item->setData(Qt::DisplayRole, pentry->total_cost);
1332 break;
1333 }
1334 item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
1335 eco_widget->setItem(i, j, item);
1336 }
1337 }
1338 max_row = i;
1339 get_economy_report_units_data(unit_entries, &entries_used, &unit_total);
1340 for (i = 0; i < entries_used; i++) {
1341 struct unit_entry *pentry = unit_entries + i;
1342 struct unit_type *putype = pentry->type;
1343 cid id;
1344
1345 pix = NULL;
1346 sprite = get_unittype_sprite(tileset, putype, direction8_invalid());
1347 if (sprite != NULL) {
1348 pix = sprite->pm;
1349 }
1350 id = cid_encode_unit(putype);
1351
1352 eco_widget->insertRow(i + max_row);
1353 for (j = 0; j < 6; j++) {
1354 item = new QTableWidgetItem;
1355 item->setTextAlignment(Qt::AlignHCenter);
1356 switch (j) {
1357 case 0:
1358 if (pix != NULL) {
1359 pix_scaled = pix->scaledToHeight(h);
1360 item->setData(Qt::DecorationRole, pix_scaled);
1361 }
1362 item->setData(Qt::UserRole, id);
1363 break;
1364 case 1:
1365 item->setTextAlignment(Qt::AlignLeft);
1366 item->setText(utype_name_translation(putype));
1367 break;
1368 case 2:
1369 item->setData(Qt::DisplayRole, 0);
1370 break;
1371 case 3:
1372 item->setData(Qt::DisplayRole, pentry->count);
1373 break;
1374 case 4:
1375 item->setData(Qt::DisplayRole, pentry->cost);
1376 break;
1377 case 5:
1378 item->setData(Qt::DisplayRole, pentry->total_cost);
1379 break;
1380 }
1381 item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
1382 eco_widget->setItem(max_row + i, j, item);
1383 }
1384 }
1385 max_row = max_row + i;
1386 fc_snprintf(buf, sizeof(buf), _("Income: %d Total Costs: %d"),
1387 tax, building_total + unit_total);
1388 eco_label->setText(buf);
1389}
1390
1391/************************************************************************/
1394void eco_report::selection_changed(const QItemSelection & sl,
1395 const QItemSelection & ds)
1396{
1397 QTableWidgetItem *itm;
1398 int i;
1399 QVariant qvar;
1400 struct universal selected;
1401 const struct impr_type *pimprove;
1402 disband_button->setEnabled(false);
1403 sell_button->setEnabled(false);
1404 sell_redun_button->setEnabled(false);
1405
1406 if (sl.isEmpty()) {
1407 return;
1408 }
1409
1410 curr_row = sl.indexes().at(0).row();
1411 if (curr_row >= 0 && curr_row <= max_row) {
1412 itm = eco_widget->item(curr_row, 0);
1413 qvar = itm->data(Qt::UserRole);
1414 uid = qvar.toInt();
1415 selected = cid_decode(uid);
1416 switch (selected.kind) {
1417 case VUT_IMPROVEMENT:
1418 pimprove = selected.value.building;
1419 counter = eco_widget->item(curr_row, 3)->text().toInt();
1420 if (can_sell_building(pimprove)) {
1421 sell_button->setEnabled(true);
1422 }
1423 itm = eco_widget->item(curr_row, 2);
1424 i = itm->text().toInt();
1425 if (i > 0) {
1426 sell_redun_button->setEnabled(true);
1427 }
1428 break;
1429 case VUT_UTYPE:
1430 counter = eco_widget->item(curr_row, 3)->text().toInt();
1431 disband_button->setEnabled(true);
1432 break;
1433 default:
1434 log_error("Not supported type: %d.", selected.kind);
1435 }
1436 }
1437}
1438
1439/************************************************************************/
1443{
1444 struct universal selected;
1445 char title[1024];
1446 hud_message_box *ask = new hud_message_box(gui()->central_wdg);
1447 Unit_type_id utype;
1448
1449 selected = cid_decode(uid);
1450 utype = utype_number(selected.value.utype);
1452 _("Do you really wish to disband every %s (%d total)?"),
1454
1455 ask->set_text_title(title, _("Disband Units"));
1456 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
1457 ask->setDefaultButton(QMessageBox::Cancel);
1458 ask->setAttribute(Qt::WA_DeleteOnClose);
1459 connect(ask, &hud_message_box::accepted, [=]() {
1460 struct unit_type *putype = utype_by_number(utype);
1461 char buf[1024];
1462 hud_message_box *result;
1463
1464 if (putype) {
1465 disband_all_units(putype, false, buf, sizeof(buf));
1466 }
1467
1468 result = new hud_message_box(gui()->central_wdg);
1469 result->set_text_title(buf, _("Disband Results"));
1470 result->setStandardButtons(QMessageBox::Ok);
1471 result->setAttribute(Qt::WA_DeleteOnClose);
1472 result->show();
1473 });
1474}
1475
1476/************************************************************************/
1480{
1481 struct universal selected;
1482 char title[1024];
1483 hud_message_box *ask = new hud_message_box(gui()->central_wdg);
1484 const struct impr_type *pimpr;
1485 Impr_type_id impr_id;
1486
1487 selected = cid_decode(uid);
1488 pimpr = selected.value.building;
1489 impr_id = improvement_number(pimpr);
1490
1492 _("Do you really wish to sell "
1493 "every %s (%d total)?"),
1495
1496 ask->set_text_title(title, _("Sell Improvements"));
1497 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
1498 ask->setDefaultButton(QMessageBox::Cancel);
1499 ask->setAttribute(Qt::WA_DeleteOnClose);
1500 connect(ask, &hud_message_box::accepted, [=]() {
1501 char buf[1024];
1502 hud_message_box *result;
1503 struct impr_type *pimprove = improvement_by_number(impr_id);
1504
1505 if (!pimprove) {
1506 return;
1507 }
1508
1509 sell_all_improvements(pimprove, false, buf, sizeof(buf));
1510
1511 result = new hud_message_box(gui()->central_wdg);
1512 result->set_text_title(buf, _("Sell-Off: Results"));
1513 result->setStandardButtons(QMessageBox::Ok);
1514 result->setAttribute(Qt::WA_DeleteOnClose);
1515 result->show();
1516 });
1517}
1518
1519
1520/************************************************************************/
1524{
1525 struct universal selected;
1526 char title[1024];
1527 hud_message_box *ask = new hud_message_box(gui()->central_wdg);
1528 const struct impr_type *pimpr;
1529 Impr_type_id impr_id;
1530
1531 selected = cid_decode(uid);
1532 pimpr = selected.value.building;
1533 impr_id = improvement_number(pimpr);
1534
1536 _("Do you really wish to sell "
1537 "every redundant %s (%d total)?"),
1539
1540 ask->set_text_title(title, _("Sell Improvements"));
1541 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
1542 ask->setDefaultButton(QMessageBox::Cancel);
1543 ask->setAttribute(Qt::WA_DeleteOnClose);
1544 connect(ask, &hud_message_box::accepted, [=]() {
1545 char buf[1024];
1546 hud_message_box *result;
1547 struct impr_type *pimprove = improvement_by_number(impr_id);
1548
1549 if (!pimprove) {
1550 return;
1551 }
1552
1553 sell_all_improvements(pimprove, true, buf, sizeof(buf));
1554
1555 result = new hud_message_box(gui()->central_wdg);
1556 result->set_text_title(buf, _("Sell-Off: Results"));
1557 result->setStandardButtons(QMessageBox::Ok);
1558 result->setAttribute(Qt::WA_DeleteOnClose);
1559 result->show();
1560 });
1561}
1562
1563/************************************************************************/
1567{
1568 QGridLayout *end_layout = new QGridLayout;
1569 end_widget = new QTableWidget;
1570 unsigned int i;
1571
1572 players = 0;
1573 const size_t col_num = packet->category_num + 3;
1574 QStringList slist;
1575 slist << _("Player") << _("Nation") << _("Score");
1576 for (i = 0 ; i < col_num - 3; i++) {
1577 slist << Q_(packet->category_name[i]);
1578 }
1579 end_widget->setColumnCount(slist.count());
1580 end_widget->setHorizontalHeaderLabels(slist);
1581 end_widget->setProperty("showGrid", "false");
1582 end_widget->setProperty("selectionBehavior", "SelectRows");
1583 end_widget->setEditTriggers(QAbstractItemView::NoEditTriggers);
1584 end_widget->verticalHeader()->setVisible(false);
1585 end_widget->setSelectionMode(QAbstractItemView::SingleSelection);
1586 end_widget->horizontalHeader()->setSectionResizeMode(
1587 QHeaderView::ResizeToContents);
1588 end_layout->addWidget(end_widget, 1, 0, 5, 5);
1589 setLayout(end_layout);
1590
1591}
1592
1593/************************************************************************/
1597{
1598 gui()->remove_repo_dlg("END");
1599}
1600
1601/************************************************************************/
1605{
1606 gui()->gimme_place(this, "END");
1607 index = gui()->add_game_tab(this);
1608 gui()->game_tab_widget->setCurrentIndex(index);
1609}
1610
1611/************************************************************************/
1615{
1616 QTableWidgetItem *item;
1617 QPixmap *pix;
1618 unsigned int i;
1619 const struct player *pplayer = player_by_number(packet->player_id);
1620 const size_t col_num = packet->category_num + 3;
1621 end_widget->insertRow(players);
1622 for (i = 0; i < col_num; i++) {
1623 item = new QTableWidgetItem;
1624 switch (i) {
1625 case 0:
1626 item->setText(player_name(pplayer));
1627 break;
1628 case 1:
1630 if (pix != NULL) {
1631 item->setData(Qt::DecorationRole, *pix);
1632 }
1633 break;
1634 case 2:
1635 item->setText(QString::number(packet->score));
1636 item->setTextAlignment(Qt::AlignHCenter);
1637 break;
1638 default:
1639 item->setText(QString::number(packet->category_score[i-3]));
1640 item->setTextAlignment(Qt::AlignHCenter);
1641 break;
1642 }
1643 end_widget->setItem(players, i, item);
1644 }
1645 players++;
1646 end_widget->resizeRowsToContents();
1647}
1648
1649/************************************************************************/
1654{
1655 science_report *sci_rep;
1656 int i;
1657 QWidget *w;
1658
1660 return;
1661 }
1662 if (!gui()->is_repo_dlg_open("SCI")) {
1663 sci_rep = new science_report;
1664 sci_rep->init();
1665 } else {
1666 i = gui()->gimme_index_of("SCI");
1667 w = gui()->game_tab_widget->widget(i);
1668 sci_rep = reinterpret_cast<science_report*>(w);
1669 if (gui()->game_tab_widget->currentIndex() == i) {
1670 sci_rep->redraw();
1671 } else if (raise) {
1672 gui()->game_tab_widget->setCurrentWidget(sci_rep);
1673 }
1674 }
1675}
1676
1677/************************************************************************/
1681{
1682 int i;
1683 eco_report *eco_rep;
1684 QWidget *w;
1685
1686 if (gui()->is_repo_dlg_open("ECO")) {
1687 i = gui()->gimme_index_of("ECO");
1688 if (gui()->game_tab_widget->currentIndex() == i) {
1689 w = gui()->game_tab_widget->widget(i);
1690 eco_rep = reinterpret_cast<eco_report*>(w);
1691 eco_rep->update_report();
1692 }
1693 }
1694 gui()->update_sidebar_tooltips();
1695}
1696
1697/************************************************************************/
1701{
1702 int i;
1703 eco_report *eco_rep;
1704 QWidget *w;
1705
1706 if (!gui()->is_repo_dlg_open("ECO")) {
1707 eco_rep = new eco_report;
1708 eco_rep->init();
1709 eco_rep->update_report();
1710 } else {
1711 i = gui()->gimme_index_of("ECO");
1712 fc_assert(i != -1);
1713 w = gui()->game_tab_widget->widget(i);
1714 if (w->isVisible()) {
1715 gui()->game_tab_widget->setCurrentIndex(0);
1716 return;
1717 }
1718 eco_rep = reinterpret_cast<eco_report *>(w);
1719 eco_rep->update_report();
1720 gui()->game_tab_widget->setCurrentWidget(eco_rep);
1721 }
1722}
1723
1724/************************************************************************/
1728{
1729 if (units_reports::instance()->isVisible()) {
1731 }
1732}
1733
1734/************************************************************************/
1738{
1739 gui()->game_tab_widget->setCurrentIndex(0);
1741}
1742
1743/************************************************************************/
1747{
1748 endgame_report *end_rep;
1749 end_rep = new endgame_report(packet);
1750 end_rep->init();
1751}
1752
1753/************************************************************************/
1757{
1758 int i;
1759 if (gui()->is_repo_dlg_open("END")) {
1760 i = gui()->gimme_index_of("END");
1761 fc_assert(i != -1);
1762 delete gui()->game_tab_widget->widget(i);
1763 }
1764}
1765
1766/************************************************************************/
1770{
1771 int i;
1772 if (gui()->is_repo_dlg_open("END")) {
1773 i = gui()->gimme_index_of("END");
1774 gui()->game_tab_widget->setCurrentIndex(i);
1775 }
1776}
1777
1778/************************************************************************/
1782{
1783 int i;
1784 endgame_report *end_rep;
1785 QWidget *w;
1786
1787 if (gui()->is_repo_dlg_open("END")) {
1788 i = gui()->gimme_index_of("END");
1789 fc_assert(i != -1);
1790 w = gui()->game_tab_widget->widget(i);
1791 end_rep = reinterpret_cast<endgame_report*>(w);
1792 end_rep->update_report(packet);
1793 }
1794}
1795
1796/************************************************************************/
1800{
1801 int i;
1802 science_report *sci_rep;
1803 QWidget *w;
1804
1805 if (gui()->is_repo_dlg_open("SCI")) {
1806 i = gui()->gimme_index_of("SCI");
1807 if (gui()->game_tab_widget->currentIndex() == i) {
1808 w = gui()->game_tab_widget->widget(i);
1809 sci_rep = reinterpret_cast<science_report*>(w);
1810 sci_rep->redraw();
1811 }
1812 }
1813}
1814
1815/************************************************************************/
1819{
1820 int i;
1821 eco_report *eco_rep;
1822 QWidget *w;
1823
1824 if (gui()->is_repo_dlg_open("ECO")) {
1825 i = gui()->gimme_index_of("ECO");
1826 fc_assert(i != -1);
1827 w = gui()->game_tab_widget->widget(i);
1828 eco_rep = reinterpret_cast<eco_report*>(w);
1829 eco_rep->deleteLater();
1830 }
1831}
1832
1833/************************************************************************/
1837{
1838 int i;
1839 science_report *sci_rep;
1840 QWidget *w;
1841
1842 if (gui()->is_repo_dlg_open("SCI")) {
1843 i = gui()->gimme_index_of("SCI");
1844 fc_assert(i != -1);
1845 w = gui()->game_tab_widget->widget(i);
1846 sci_rep = reinterpret_cast<science_report*>(w);
1847 sci_rep->deleteLater();
1848 }
1849}
1850
1851/************************************************************************/
1858
1859/************************************************************************/
1863 {
1864 Q_UNUSED(x);
1865 if (units_reports::instance()->isVisible()
1866 && gui()->game_tab_widget->currentIndex() == 0) {
1868 } else {
1870 }
1871}
int entries_used
Definition agents.c:74
#define str
Definition astring.c:76
QRect zealous_crop_rect(QImage &p)
Definition canvas.cpp:399
struct canvas * qtg_canvas_create(int width, int height)
Definition canvas.cpp:35
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
FONT_REQTREE_TEXT
Definition canvas_g.h:72
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
bool city_production_build_units(const struct city *pcity, bool add_production, int *num_units)
Definition city.c:732
#define city_list_iterate(citylist, pcity)
Definition city.h:488
#define city_list_iterate_end
Definition city.h:490
QString split_text(QString text, bool cut)
Definition optiondlg.cpp:62
QString get_tooltip_improvement(const impr_type *building, struct city *pcity, bool ext)
Definition citydlg.cpp:3894
QString cut_helptext(QString text)
QString get_tooltip_unit(const struct unit_type *utype, bool ext)
Definition citydlg.cpp:3951
void put_to_corner()
Definition mapview.cpp:504
QPushButton * sell_button
Definition repodlgs.h:212
void selection_changed(const QItemSelection &sl, const QItemSelection &ds)
QPushButton * sell_redun_button
Definition repodlgs.h:213
QPushButton * disband_button
Definition repodlgs.h:211
void disband_units()
QTableWidget * eco_widget
Definition repodlgs.h:214
int max_row
Definition repodlgs.h:226
void sell_buildings()
void init()
void sell_redundant()
int curr_row
Definition repodlgs.h:225
void update_report()
QLabel * eco_label
Definition repodlgs.h:215
int counter
Definition repodlgs.h:228
static fc_font * instance()
Definition fonts.cpp:41
QFont * get_font(QString name)
Definition fonts.cpp:63
bool was_destroyed
Definition mapview.h:176
int set_text_title(QString s1, QString s2, bool return_exec=false)
void set_pixmap(struct universal *target)
Definition citydlg.cpp:113
struct government * tgov
Definition repodlgs.h:133
Tech_type_id tech_id
Definition repodlgs.h:130
struct unit_type * tunit
Definition repodlgs.h:131
struct impr_type * timpr
Definition repodlgs.h:132
struct canvas * pcanvas
Definition repodlgs.h:155
void mousePressEvent(QMouseEvent *event)
Definition repodlgs.cpp:714
void create_tooltip_help()
Definition repodlgs.cpp:581
struct reqtree * req
Definition repodlgs.h:156
QString tooltip_text
Definition repodlgs.h:162
QList< req_tooltip_help * > tt_help
Definition repodlgs.h:160
research_diagram(QWidget *parent=0)
Definition repodlgs.cpp:549
void mouseMoveEvent(QMouseEvent *event)
Definition repodlgs.cpp:761
void update_reqtree()
Definition repodlgs.cpp:683
void paintEvent(QPaintEvent *event)
Definition repodlgs.cpp:834
QPoint tooltip_pos
Definition repodlgs.h:161
static units_reports * m_instance
Definition repodlgs.h:95
void clear_layout()
Definition repodlgs.cpp:515
void paintEvent(QPaintEvent *event)
Definition repodlgs.cpp:410
static void drop()
Definition repodlgs.cpp:369
close_widget * cw
Definition repodlgs.h:90
void add_item(unittype_item *item)
Definition repodlgs.cpp:351
static units_reports * instance()
Definition repodlgs.cpp:359
virtual void update_menu()
Definition repodlgs.cpp:380
void update_units(bool show=false)
Definition repodlgs.cpp:418
QHBoxLayout * layout
Definition repodlgs.h:106
QList< unittype_item * > unittype_list
Definition repodlgs.h:107
QHBoxLayout * scroll_layout
Definition repodlgs.h:92
QWidget scroll_widget
Definition repodlgs.h:94
QScrollArea * scroll
Definition repodlgs.h:93
void init_layout()
Definition repodlgs.cpp:389
QLabel label_pix
Definition repodlgs.h:54
int unit_scroll
Definition repodlgs.h:53
QLabel label_info_active
Definition repodlgs.h:62
void leaveEvent(QEvent *event)
Definition repodlgs.cpp:269
unittype_item(QWidget *parent, unit_type *ut)
Definition repodlgs.cpp:97
QLabel gold_upkeep
Definition repodlgs.h:61
QLabel label_info_inbuild
Definition repodlgs.h:63
QLabel shield_upkeep
Definition repodlgs.h:65
void init_img()
Definition repodlgs.cpp:191
void upgrade_units()
Definition repodlgs.cpp:202
void enterEvent(QEnterEvent *event)
Definition repodlgs.cpp:240
QLabel food_upkeep
Definition repodlgs.h:60
QLabel label_info_unit
Definition repodlgs.h:64
unit_type * utype
Definition repodlgs.h:69
QPushButton upgrade_button
Definition repodlgs.h:66
void paintEvent(QPaintEvent *event)
Definition repodlgs.cpp:252
void wheelEvent(QWheelEvent *event)
Definition repodlgs.cpp:278
bool client_is_global_observer(void)
bool client_is_observer(void)
struct civclient client
bool can_client_issue_orders(void)
bool client_has_player(void)
#define client_player()
cid cid_encode_building(const struct impr_type *pimprove)
Definition climisc.c:498
struct universal cid_decode(cid id)
Definition climisc.c:519
cid cid_encode_unit(const struct unit_type *punittype)
Definition climisc.c:486
int cid
Definition climisc.h:31
void unit_focus_set_and_select(struct unit *punit)
Definition control.c:637
#define can_unit_do_activity_client(_punit_, _act_)
Definition control.h:40
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:73
int int id
Definition editgui_g.h:28
enum event_type event
Definition events.c:81
int Tech_type_id
Definition fc_types.h:347
int Impr_type_id
Definition fc_types.h:346
int Unit_type_id
Definition fc_types.h:352
@ O_SHIELD
Definition fc_types.h:91
@ O_FOOD
Definition fc_types.h:91
@ O_GOLD
Definition fc_types.h:91
@ O_LAST
Definition fc_types.h:91
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:57
const char * government_name_translation(const struct government *pgovern)
Definition government.c:142
#define governments_iterate(NAME_pgov)
Definition government.h:121
#define governments_iterate_end
Definition government.h:124
void get_text_size(int *width, int *height, enum client_font font, const char *text)
Definition canvas.c:347
void canvas_free(struct canvas *store)
Definition canvas.c:44
static struct tile * pos
Definition finddlg.c:53
void popup_help_dialog_typed(const char *item, enum help_page_type htype)
Definition helpdlg.c:195
const char * title
Definition repodlgs.c:1313
GType type
Definition repodlgs.c:1312
void get_sprite_dimensions(struct sprite *sprite, int *width, int *height)
Definition sprite.c:107
#define mevent_gpos(__ev__)
Definition gui_main.h:29
bool comp_less_than(const qlist_item &q1, const qlist_item &q2)
Definition repodlgs.cpp:541
void helptext_government(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct government *gov)
Definition helpdata.c:4175
void helptext_advance(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, int i)
Definition helpdata.c:3115
char * helptext_building(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct impr_type *pimprove)
Definition helpdata.c:1316
char * helptext_unit(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct unit_type *utype)
Definition helpdata.c:1763
@ HELP_IMPROVEMENT
Definition helpdlg_g.h:20
@ HELP_UNIT
Definition helpdlg_g.h:20
@ HELP_GOVERNMENT
Definition helpdlg_g.h:22
@ HELP_WONDER
Definition helpdlg_g.h:21
@ HELP_TECH
Definition helpdlg_g.h:21
const struct impr_type * valid_improvement(const struct impr_type *pimprove)
struct impr_type * improvement_by_number(const Impr_type_id id)
bool can_sell_building(const struct impr_type *pimprove)
Impr_type_id improvement_number(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define B_LAST
Definition improvement.h:42
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert(condition)
Definition log.h:176
@ LOG_VERBOSE
Definition log.h:33
#define log_error(message,...)
Definition log.h:103
#define fc_calloc(n, esz)
Definition mem.h:38
static mpgui * gui
Definition mpgui_qt.cpp:52
const char *const default_font
Definition fonts.h:27
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
struct client_options gui_options
Definition options.c:71
int dsend_packet_player_tech_goal(struct connection *pc, int tech)
int dsend_packet_player_research(struct connection *pc, int tech)
int dsend_packet_unit_type_upgrade(struct connection *pc, Unit_type_id type)
const char * science_dialog_text(void)
Definition text.c:774
struct player * player_by_number(const int player_id)
Definition player.c:840
const char * player_name(const struct player *pplayer)
Definition player.c:886
#define players_iterate_end
Definition player.h:535
#define players_iterate(_pplayer)
Definition player.h:530
void science_report_dialog_popup(bool raise)
QString get_tooltip_improvement(impr_type *building, struct city *pcity, bool ext)
void endgame_report_dialog_start(const struct packet_endgame_report *packet)
QString split_text(QString text, bool cut)
Definition optiondlg.cpp:62
void real_units_report_dialog_update(void *unused)
void real_economy_report_dialog_update(void *unused)
bool comp_less_than(const qlist_item &q1, const qlist_item &q2)
Definition repodlgs.cpp:541
void popdown_economy_report()
void economy_report_dialog_popup(bool raise)
void popdown_science_report()
void units_report_dialog_popup(bool raise)
void popdown_endgame_report()
void science_report_dialog_redraw(void)
void popdown_units_report()
void toggle_units_report(bool x)
void popup_endgame_report()
QString cut_helptext(QString text)
QString get_tooltip_unit(struct unit_type *unit, bool ext)
void real_science_report_dialog_update(void *unused)
void get_economy_report_units_data(struct unit_entry *entries, int *num_entries_used, int *total_cost)
void get_economy_report_data(struct improvement_entry *entries, int *num_entries_used, int *total_cost, int *total_income)
void sell_all_improvements(const struct impr_type *pimprove, bool redundant_only, char *message, size_t message_sz)
void disband_all_units(const struct unit_type *punittype, bool in_cities_only, char *message, size_t message_sz)
endgame_report_dialog_player
Definition repodlgs_g.h:33
void draw_reqtree(struct reqtree *tree, struct canvas *pcanvas, int canvas_x, int canvas_y, int tt_x, int tt_y, int w, int h)
Definition reqtree.c:1033
void get_reqtree_dimensions(struct reqtree *reqtree, int *width, int *height)
Definition reqtree.c:867
Tech_type_id get_tech_on_reqtree(struct reqtree *tree, int x, int y)
Definition reqtree.c:1170
void destroy_reqtree(struct reqtree *tree)
Definition reqtree.c:470
struct reqtree * create_reqtree(struct player *pplayer, bool show_all)
Definition reqtree.c:836
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
bool research_invention_reachable(const struct research *presearch, const Tech_type_id tech)
Definition research.c:665
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:271
struct research * research_get(const struct player *pplayer)
Definition research.c:126
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:616
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MAX(x, y)
Definition shared.h:54
size_t size
Definition specvec.h:72
QPixmap map_pixmap
Definition canvas.h:25
Definition city.h:309
struct packet_ruleset_control control
Definition game.h:83
struct connection conn
Definition client_main.h:96
bool reqtree_show_icons
Definition options.h:213
Definition colors.h:20
struct player * playing
Definition connection.h:156
QTableWidget * end_widget
Definition repodlgs.h:244
endgame_report(const struct packet_endgame_report *packet)
void update_report(const struct packet_endgame_player *packet)
Definition mapimg.c:367
int cost
struct impr_type * type
int total_cost
int count
int redundant
Definition climisc.h:82
char category_name[32][MAX_LEN_NAME]
Definition packets_gen.h:90
QString tech_str
Definition repodlgs.h:117
int num_nodes
Definition repodlgs.cpp:86
struct tree_node ** nodes
Definition repodlgs.cpp:87
int * layer_size
Definition repodlgs.cpp:89
int diagram_height
Definition repodlgs.cpp:91
int diagram_width
Definition repodlgs.cpp:91
struct tree_node *** layers
Definition repodlgs.cpp:90
int num_layers
Definition repodlgs.cpp:88
enum tech_state state
Definition research.h:73
Tech_type_id researching
Definition research.h:52
Tech_type_id tech_goal
Definition research.h:85
struct research::@75::@77 client
struct research::research_invention inventions[A_ARRAY_SIZE]
int techs_researched
Definition research.h:42
int researching_cost
Definition research.h:98
int bulbs_researched
Definition research.h:53
QGridLayout * sci_layout
Definition repodlgs.h:178
QLabel * progress_label
Definition repodlgs.h:181
GtkProgressBar * progress_bar
Definition repodlgs.c:75
progress_bar * progress
Definition repodlgs.h:179
QScrollArea * scroll
Definition repodlgs.h:185
QComboBox * goal_combo
Definition repodlgs.h:176
QList< qlist_item > * curr_list
Definition repodlgs.h:182
QLabel * info_label
Definition repodlgs.h:180
research_diagram * res_diag
Definition repodlgs.h:184
QList< qlist_item > * goal_list
Definition repodlgs.h:183
void update_report()
Definition repodlgs.cpp:959
void update_reqtree()
void reset_tree()
Definition repodlgs.cpp:947
void current_tech_changed(int index)
void goal_tech_changed(int index)
QComboBox * researching_combo
Definition repodlgs.h:177
QPixmap * pm
Definition sprite.h:25
Tech_type_id tech
Definition repodlgs.cpp:72
int nprovide
Definition repodlgs.cpp:75
struct tree_node ** provide
Definition repodlgs.cpp:76
int node_width
Definition repodlgs.cpp:78
bool is_dummy
Definition repodlgs.cpp:71
int node_height
Definition repodlgs.cpp:78
int nrequire
Definition repodlgs.cpp:73
struct tree_node ** require
Definition repodlgs.cpp:74
int total_cost
struct unit_type * type
int count
int cost
Definition unit.h:138
int upkeep[O_LAST]
Definition unit.h:148
enum unit_activity activity
Definition unit.h:157
int homecity
Definition unit.h:146
const struct unit_type * utype
Definition unit.h:139
enum universals_n kind
Definition fc_types.h:758
universals_u value
Definition fc_types.h:757
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
bool is_future_tech(Tech_type_id tech)
Definition tech.c:281
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:290
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
#define advance_index_iterate_end
Definition tech.h:248
#define A_FIRST
Definition tech.h:44
#define A_UNSET
Definition tech.h:48
#define advance_index_iterate(_start, _index)
Definition tech.h:244
const char * get_science_target_text(double *percent)
Definition text.c:853
const char * get_science_goal_text(Tech_type_id goal)
Definition text.c:899
struct sprite * get_government_sprite(const struct tileset *t, const struct government *gov)
Definition tilespec.c:6504
struct sprite * get_building_sprite(const struct tileset *t, const struct impr_type *pimprove)
Definition tilespec.c:6494
struct tileset * get_tileset(void)
Definition tilespec.c:655
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum direction8 facing)
Definition tilespec.c:6516
struct sprite * tiles_lookup_sprite_tag_alt(struct tileset *t, enum log_level level, const char *tag, const char *alt, const char *what, const char *name, bool scale)
Definition tilespec.c:3458
struct sprite * get_tax_sprite(const struct tileset *t, Output_type_id otype)
Definition tilespec.c:6575
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6467
struct sprite * get_tech_sprite(const struct tileset *t, Tech_type_id tech)
Definition tilespec.c:6485
const struct unit_type * utype
Definition fc_types.h:604
const struct impr_type * building
Definition fc_types.h:598
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
const struct unit_type * can_upgrade_unittype(const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1755
Unit_type_id utype_count(void)
Definition unittype.c:80
struct unit_type * utype_by_number(const Unit_type_id id)
Definition unittype.c:112
Unit_type_id utype_number(const struct unit_type *punittype)
Definition unittype.c:100
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1612
int unit_upgrade_price(const struct player *pplayer, const struct unit_type *from, const struct unit_type *to)
Definition unittype.c:1783
#define unit_type_iterate(_p)
Definition unittype.h:841
#define U_LAST
Definition unittype.h:40
#define unit_type_iterate_end
Definition unittype.h:848
#define show(id)
Definition widget.h:235
#define hide(id)
Definition widget.h:238