Freeciv-3.4
Loading...
Searching...
No Matches
fc_client.cpp
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996-2005 - Freeciv Development Team
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 <QFormLayout>
22#include <QLineEdit>
23#include <QMainWindow>
24#include <QPainter>
25#include <QResizeEvent>
26#include <QScrollBar>
27#include <QSettings>
28#include <QSocketNotifier>
29#include <QSpinBox>
30#include <QStackedLayout>
31#include <QStandardPaths>
32#include <QStatusBar>
33#include <QStyleFactory>
34#include <QTabBar>
35#include <QTextBlock>
36#include <QTextEdit>
37
38// common
39#include "game.h"
40
41// client
42#include "connectdlg_common.h"
43
44// gui-qt
45#include "fc_client.h"
46#include "fonts.h"
47#include "gui_main.h"
48#include "optiondlg.h"
49#include "sidebar.h"
50#include "sprite.h"
51
54extern "C" {
56}
57extern void write_shortcuts();
58
60
61/************************************************************************/
64fc_client::fc_client() : QMainWindow()
65{
67
75 main_wdg = nullptr;
76 connect_lan = nullptr;
77 connect_metaserver = nullptr;
78 central_layout = nullptr;
79 output_window = nullptr;
80 scenarios_view = nullptr;
81 connect_host_edit = nullptr;
82 connect_port_edit = nullptr;
83 connect_login_edit = nullptr;
84 connect_password_edit = nullptr;
86 button = nullptr;
87 button_box = nullptr;
88 server_notifier = nullptr;
89 chat_line = nullptr;
90 lan_widget = nullptr;
91 wan_widget = nullptr;
92 info_widget = nullptr;
93 saves_load = nullptr;
94 scenarios_load = nullptr;
95 meta_scan_timer = nullptr;
96 lan_scan_timer = nullptr;
97 status_bar = nullptr;
98 status_bar_label = nullptr;
99 menu_bar = nullptr;
100 mapview_wdg = nullptr;
101 sidebar_wdg = nullptr;
102 msgwdg = nullptr;
103 infotab = nullptr;
104 central_wdg = nullptr;
105 game_tab_widget = nullptr;
106 start_players_tree = nullptr;
107 unit_sel = nullptr;
108 info_tile_wdg = nullptr;
109 opened_dialog = nullptr;
110 current_file = "";
111 status_bar_queue.clear();
112 quitting = false;
113 pre_vote = nullptr;
114 x_vote = nullptr;
115 gtd = nullptr;
116 update_info_timer = nullptr;
117 unitinfo_wdg = nullptr;
118 battlelog_wdg = nullptr;
119 interface_locked = false;
120 map_scale = 1.0f;
121 map_font_scale = true;
122 for (int i = 0; i <= PAGE_GAME; i++) {
123 pages_layout[i] = nullptr;
124 pages[i] = nullptr;
125 }
126
127 wtitle = _("Freeciv (%1)");
128 wtitle = wtitle.arg(
130 "Qt6x"
131#else // FC_QT6X_MODE
132 "Qt6"
133#endif // FC_QT6X_MODE
134 );
135
137
138 init();
139}
140
141/************************************************************************/
145{
148 QApplication::setFont(*fc_font::instance()->get_font(fonts::default_font));
149 QString path;
150 central_wdg = new QWidget;
152
153 // General part not related to any single page
154 menu_bar = new mr_menu();
156 corner_wid = new fc_corner(this);
157 menu_bar->setCornerWidget(corner_wid);
158 }
161 status_bar_label = new QLabel;
162 status_bar_label->setAlignment(Qt::AlignCenter);
163 status_bar->addWidget(status_bar_label, 1);
164 set_status_bar(_("Welcome to Freeciv"));
166
167 // PAGE_MAIN
168 pages[PAGE_MAIN] = new QWidget(central_wdg);
169 page = PAGE_MAIN;
171
172 // PAGE_START
173 pages[PAGE_START] = new QWidget(central_wdg);
175
176 // PAGE_SCENARIO
177 pages[PAGE_SCENARIO] = new QWidget(central_wdg);
179
180 // PAGE_LOAD
181 pages[PAGE_LOAD] = new QWidget(central_wdg);
183
184 // PAGE_NETWORK
185 pages[PAGE_NETWORK] = new QWidget(central_wdg);
187 pages[PAGE_NETWORK]->setVisible(false);
188
189 // PAGE_GAME
191 path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
192 if (!path.isEmpty()) {
193 QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, path);
194 }
195 pages[PAGE_GAME] = new QWidget(central_wdg);
198
199 pages[PAGE_GAME + 1] = new QWidget(central_wdg);
201
202 pages_layout[PAGE_GAME]->setContentsMargins(0, 0, 0, 0);
203
210 pages[PAGE_GAME + 1]->setLayout(pages_layout[PAGE_GAME + 1]);
211
212 central_layout->addWidget(pages[PAGE_MAIN]);
213 central_layout->addWidget(pages[PAGE_NETWORK]);
214 central_layout->addWidget(pages[PAGE_LOAD]);
216 central_layout->addWidget(pages[PAGE_START]);
217 central_layout->addWidget(pages[PAGE_GAME]);
218 central_layout->addWidget(pages[PAGE_GAME + 1]);
219
220 central_wdg->setLayout(central_layout);
222
223 resize(pages[PAGE_MAIN]->minimumSizeHint());
224 setVisible(true);
225
228
229 QPixmapCache::setCacheLimit(80000);
230}
231
232/************************************************************************/
236{
237 status_bar_queue.clear();
238 if (fc_shortcuts::sc()) {
239 delete fc_shortcuts::sc();
240 }
242}
243
244
245/************************************************************************/
252{
253 qRegisterMetaType<QTextCursor>("QTextCursor");
254 qRegisterMetaType<QTextBlock>("QTextBlock");
256 real_output_window_append(_("This is Qt-client for Freeciv."), nullptr, -1);
259
261
263 connect(qapp, &QCoreApplication::aboutToQuit, this, &fc_client::closing);
264 qapp->exec();
265
268}
269
270/************************************************************************/
274{
275 return quitting;
276}
277
278/************************************************************************/
282{
283 quitting = true;
284}
285
286/************************************************************************/
293
294/************************************************************************/
298 const struct text_tag_list *tags)
299{
300 QTextCursor cursor;
301 QColor col = output_window->palette().color(QPalette::Text);
302 QString str = apply_tags(message, tags, col);
303
304 if (output_window != nullptr) {
305 output_window->append(str);
306 output_window->verticalScrollBar()->setSliderPosition(
307 output_window->verticalScrollBar()->maximum());
308 }
309}
310
311/************************************************************************/
315{
316 if (check == PAGE_START || check == PAGE_GAME) {
317 return true;
318 }
319
320 return false;
321}
322
323/************************************************************************/
330{
331 char buf[256];
333 int i_page;
334
335 new_page = static_cast<client_pages>(new_pg);
336
338 && !is_server_running()) {
339 current_file = "";
341 return;
342 }
343
344 if (page == PAGE_NETWORK) {
346 }
347 menuBar()->setVisible(false);
348 if (status_bar != nullptr) {
349 status_bar->setVisible(true);
350 }
351 QApplication::alert(gui()->central_wdg);
352 central_layout->setCurrentWidget(pages[new_pg]);
353 page = new_page;
355 switch (i_page) {
356 case PAGE_MAIN:
357 break;
358 case PAGE_START:
359 pre_vote->hide();
361 break;
362 case PAGE_LOAD:
364 break;
365 case PAGE_GAME:
367 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
368 }
370 // For MS Windows, it might ignore first
373 status_bar->setVisible(false);
374
377 }
378
379 menuBar()->setVisible(true);
380 mapview_wdg->setFocus();
389 break;
390 case PAGE_SCENARIO:
392 break;
393 case PAGE_NETWORK:
397 fc_snprintf(buf, sizeof(buf), "%d", server_port);
398 connect_port_edit->setText(buf);
400 connect_password_edit->setDisabled(true);
401 connect_confirm_password_edit->setDisabled(true);
402 break;
403 case (PAGE_GAME + 1):
404 break;
405 default:
406 if (client.conn.used) {
408 }
410 break;
411 }
412}
413
414/************************************************************************/
418{
420 gui()->showFullScreen();
421 gui()->game_tab_widget->showFullScreen();
422 } else {
423 // FIXME: Doesn't return properly, probably something with sidebar
424 gui()->showNormal();
425 gui()->game_tab_widget->showNormal();
426 }
427}
428
429/************************************************************************/
433{
434 return page;
435}
436
437/************************************************************************/
441{
442 server_notifier = new QSocketNotifier(sock, QSocketNotifier::Read);
443
444 connect(server_notifier, &QSocketNotifier::activated, this,
446}
447
448/************************************************************************/
455
456/************************************************************************/
460{
461 if (event->type() == QEvent::User) {
463 dynamic_cast<version_message_event&>(*event);
464 set_status_bar(vmevt.get_message());
465 return true;
466 } else {
467 return QMainWindow::event(event);
468 }
469}
470
471/************************************************************************/
475{
476 if (!is_client_quitting()) {
478 event->ignore();
479 }
480}
481
482/************************************************************************/
486{
487 server_notifier->deleteLater();
488}
489
490/************************************************************************/
494{
495 server_notifier->setEnabled(false);
496 input_from_server(sock);
497 server_notifier->setEnabled(true);
498}
499
500/************************************************************************/
504{
505 // Prevent current timer from repeating with possibly wrong interval
506 killTimer(event->timerId());
507
508 // Call timer callback in client common code and
509 // start new timer with correct interval
511}
512
513/************************************************************************/
517{
519
520 if (qapp != nullptr) {
521 qapp->quit();
522 }
523}
524
525/************************************************************************/
536
537/************************************************************************/
541{
543 if (game.info.is_new_game) {
544 send_chat("/take -");
545 } else {
546 send_chat("/detach");
547 }
548 obs_button->setText(_("Don't Observe"));
549 } else {
550 send_chat("/observe");
551 obs_button->setText(_("Observe"));
552 }
553}
554
555/************************************************************************/
568
569/****************************************************************************
570 Deletes cursors
571****************************************************************************/
573{
574 int frame;
575 int cursor;
576
577 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
578 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
579 delete fc_cursors[cursor][frame];
580 }
581 }
582}
583
584
585/************************************************************************/
589{
590 QString x;
591
593
594 if (x.isEmpty()) {
595 opened_repo_dlgs.insert(str, widget);
596 return;
597 }
598 log_error("Failed to find place for new tab widget");
599 return;
600}
601
602/************************************************************************/
608{
609 QWidget *w;
610
611 w = opened_repo_dlgs.value(str);
612
613 if (w == nullptr) {
614 return false;
615 }
616
617 return true;
618}
619
620/************************************************************************/
624{
625 int i;
626 QWidget *w;
627
628 if (str == "MAP") {
629 return 0;
630 }
631
632 w = opened_repo_dlgs.value(str);
633 i = game_tab_widget->indexOf(w);
634 return i;
635}
636
637/************************************************************************/
641{
642 // This can't be shared between freeciv versions as the content
643 // might be incompatible.
644 QString sname = "freeciv-qt-client-set-"
645 + QString::number(MAJOR_NEW_OPTION_FILE_NAME) + "."
646 + QString::number(MINOR_NEW_OPTION_FILE_NAME);
647 QSettings s(QSettings::IniFormat, QSettings::UserScope,
648 sname);
649
650 if (s.contains("Chat-fx-size")) {
651 qt_settings.chat_fwidth = s.value("Chat-fx-size").toFloat();
652 } else {
654 }
655 if (s.contains("Chat-fy-size")) {
656 qt_settings.chat_fheight = s.value("Chat-fy-size").toFloat();
657 } else {
659 }
660 if (s.contains("Chat-fx-pos")) {
661 qt_settings.chat_fx_pos = s.value("Chat-fx-pos").toFloat();
662 } else {
664 }
665 if (s.contains("Chat-fy-pos")) {
666 qt_settings.chat_fy_pos = s.value("Chat-fy-pos").toFloat();
667 } else {
669 }
670 if (s.contains("unit_fx")) {
671 qt_settings.unit_info_pos_fx = s.value("unit_fx").toFloat();
672 } else {
674 }
675 if (s.contains("unit_fy")) {
676 qt_settings.unit_info_pos_fy = s.value("unit_fy").toFloat();
677 } else {
679 }
680 if (s.contains("minimap_x")) {
681 qt_settings.minimap_x = s.value("minimap_x").toFloat();
682 } else {
683 qt_settings.minimap_x = 0.84;
684 }
685 if (s.contains("minimap_y")) {
686 qt_settings.minimap_y = s.value("minimap_y").toFloat();
687 } else {
688 qt_settings.minimap_y = 0.79;
689 }
690 if (s.contains("minimap_width")) {
691 qt_settings.minimap_width = s.value("minimap_width").toFloat();
692 } else {
694 }
695 if (s.contains("minimap_height")) {
696 qt_settings.minimap_height = s.value("minimap_height").toFloat();
697 } else {
699 }
700 if (s.contains("battlelog_scale")) {
701 qt_settings.battlelog_scale = s.value("battlelog_scale").toFloat();
702 } else {
704 }
705
706 if (s.contains("City-dialog")) {
707 qt_settings.city_geometry = s.value("City-dialog").toByteArray();
708 }
709 if (s.contains("splitter1")) {
710 qt_settings.city_splitter1 = s.value("splitter1").toByteArray();
711 }
712 if (s.contains("splitter2")) {
713 qt_settings.city_splitter2 = s.value("splitter2").toByteArray();
714 }
715 if (s.contains("splitter3")) {
716 qt_settings.city_splitter3 = s.value("splitter3").toByteArray();
717 }
718 if (s.contains("help-dialog")) {
719 qt_settings.help_geometry = s.value("help-dialog").toByteArray();
720 }
721 if (s.contains("help_splitter1")) {
722 qt_settings.help_splitter1 = s.value("help_splitter1").toByteArray();
723 }
724 if (s.contains("opt-client-dialog")) {
725 qt_settings.options_client_geometry = s.value("opt-client-dialog").toByteArray();
726 }
727 if (s.contains("opt-server-dialog")) {
728 qt_settings.options_server_geometry = s.value("opt-server-dialog").toByteArray();
729 }
730 if (s.contains("new_turn_text")) {
731 qt_settings.show_new_turn_text = s.value("new_turn_text").toBool();
732 } else {
734 }
735 if (s.contains("show_battle_log")) {
736 qt_settings.show_battle_log = s.value("show_battle_log").toBool();
737 } else {
739 }
740 if (s.contains("battlelog_x")) {
741 qt_settings.battlelog_x = s.value("battlelog_x").toFloat();
742 } else {
744 }
745 if (s.contains("minimap_y")) {
746 qt_settings.battlelog_y = s.value("battlelog_y").toFloat();
747 } else {
749 }
752
755 }
758 }
759 if (qt_settings.chat_fwidth < 0.05 || qt_settings.chat_fwidth > 0.9) {
761 }
762 if (qt_settings.chat_fheight < 0.05 || qt_settings.chat_fheight > 0.9) {
764 }
765 if (qt_settings.battlelog_x < 0.0) {
767 }
768 if (qt_settings.battlelog_y < 0.0) {
770 }
771 if (qt_settings.battlelog_scale > 5.0) {
773 }
776 }
779 }
780}
781
782/************************************************************************/
786{
787 QString sname = "freeciv-qt-client-set-"
788 + QString::number(MAJOR_NEW_OPTION_FILE_NAME) + "."
789 + QString::number(MINOR_NEW_OPTION_FILE_NAME);
790 QSettings s(QSettings::IniFormat, QSettings::UserScope,
791 sname);
792
793 s.setValue("Chat-fx-size", qt_settings.chat_fwidth);
794 s.setValue("Chat-fy-size", qt_settings.chat_fheight);
795 s.setValue("Chat-fx-pos", qt_settings.chat_fx_pos);
796 s.setValue("Chat-fy-pos", qt_settings.chat_fy_pos);
797 s.setValue("City-dialog", qt_settings.city_geometry);
798 s.setValue("splitter1", qt_settings.city_splitter1);
799 s.setValue("splitter2", qt_settings.city_splitter2);
800 s.setValue("splitter3", qt_settings.city_splitter3);
801 s.setValue("help-dialog", qt_settings.help_geometry);
802 s.setValue("help_splitter1", qt_settings.help_splitter1);
803 s.setValue("opt-client-dialog", qt_settings.options_client_geometry);
804 s.setValue("opt-server-dialog", qt_settings.options_server_geometry);
805 s.setValue("unit_fx", qt_settings.unit_info_pos_fx);
806 s.setValue("unit_fy", qt_settings.unit_info_pos_fy);
807 s.setValue("minimap_x", qt_settings.minimap_x);
808 s.setValue("minimap_y", qt_settings.minimap_y);
809 s.setValue("minimap_width", qt_settings.minimap_width);
810 s.setValue("minimap_height", qt_settings.minimap_height);
811 s.setValue("battlelog_scale", qt_settings.battlelog_scale);
812 s.setValue("battlelog_x", qt_settings.battlelog_x);
813 s.setValue("battlelog_y", qt_settings.battlelog_y);
814 s.setValue("new_turn_text", qt_settings.show_new_turn_text);
815 s.setValue("show_battle_log", qt_settings.show_battle_log);
817}
818
819/************************************************************************/
823{
824 if (unit_sel != nullptr) {
825 unit_sel->close();
826 delete unit_sel;
827 unit_sel = new units_select(ptile, gui()->mapview_wdg);
828 unit_sel->show();
829 } else {
830 unit_sel = new units_select(ptile, gui()->mapview_wdg);
831 unit_sel->show();
832 }
833}
834
835/************************************************************************/
839{
840 if (unit_sel != nullptr) {
843 unit_sel->update();
844 }
845}
846
847/************************************************************************/
851{
852 if (unit_sel != nullptr) {
853 unit_sel->close();
854 delete unit_sel;
855 unit_sel = nullptr;
856 }
857}
858
859/************************************************************************/
863{
864 // If app is closing, opened_repo_dlg is already deleted */
865 if (!is_closing()) {
866 opened_repo_dlgs.remove(str);
867 }
868}
869
870/************************************************************************/
874{
875 option_dialog_popup(_("Set local options"), client_optset, true);
876}
877
878/************************************************************************/
882{
883 enum cursor_type curs;
884 int cursor;
885 QPixmap *pix;
886 int hot_x, hot_y;
887 struct sprite *sprite;
888 int frame;
889 QCursor *c;
890 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
891 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
892 curs = static_cast<cursor_type>(cursor);
893 sprite = get_cursor_sprite(tileset, curs, &hot_x, &hot_y, frame);
894 pix = sprite->pm;
895 c = new QCursor(*pix, hot_x, hot_y);
896 fc_cursors[cursor][frame] = c;
897 }
898 }
899}
900
901/************************************************************************/
904fc_corner::fc_corner(QMainWindow *qmw): QWidget()
905{
907 QPushButton *qpb;
908 int h;
910
911 if (f->pointSize() > 0) {
912 h = f->pointSize();
913 } else {
914 h = f->pixelSize();
915 }
916 mw = qmw;
917 hb = new QHBoxLayout();
918 qpb = new QPushButton(fc_icons::instance()->get_icon("cmin"), "");
919 qpb->setFixedSize(h, h);
920 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::minimize);
921 hb->addWidget(qpb);
922 qpb = new QPushButton(fc_icons::instance()->get_icon("cmax"), "");
923 qpb->setFixedSize(h, h);
924 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::maximize);
925 hb->addWidget(qpb);
926 qpb = new QPushButton(fc_icons::instance()->get_icon("cclose"), "");
927 qpb->setFixedSize(h, h);
928 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::close_fc);
929 hb->addWidget(qpb);
930 setLayout(hb);
931}
932
933/************************************************************************/
937{
938 mw->close();
939}
940
941/************************************************************************/
945{
946 if (!mw->isMaximized()) {
947 mw->showMaximized();
948 } else {
949 mw->showNormal();
950 }
951}
952
953/************************************************************************/
957{
958 mw->showMinimized();
959}
960
961/************************************************************************/
965{
966}
967
968/************************************************************************/
972{
973 connect(this, &QStackedWidget::currentChanged, this, &fc_game_tab_widget::current_changed);
974}
975
976/************************************************************************/
982
983/************************************************************************/
987{
988 if (!m_instance) {
989 m_instance = new fc_icons;
990 }
991 return m_instance;
992}
993
994/************************************************************************/
998{
999 if (m_instance) {
1000 delete m_instance;
1001 m_instance = 0;
1002 }
1003}
1004
1005/************************************************************************/
1009{
1010 QIcon icon;
1011 QString str;
1014
1015 str = QString("themes") + DIR_SEPARATOR + "gui-qt" + DIR_SEPARATOR;
1016 // Try custom icon from theme
1017 pn_bytes = str.toUtf8();
1019 + id + ".png").toUtf8();
1020 icon.addFile(fileinfoname(get_data_dirs(),
1021 png_bytes.data()));
1022 str = str + "icons" + DIR_SEPARATOR;
1023 // Try icon from icons dir
1024 if (icon.isNull()) {
1025 pn_bytes = str.toUtf8();
1026 png_bytes = QString(pn_bytes.data() + id + ".png").toUtf8();
1027 icon.addFile(fileinfoname(get_data_dirs(),
1028 png_bytes.data()));
1029 }
1030
1031 return QIcon(icon);
1032}
1033
1034/************************************************************************/
1038{
1039 QPixmap *pm;
1040 bool status;
1041 QString str;
1043
1044 pm = new QPixmap;
1045 if (QPixmapCache::find(id, pm)) {
1046 return pm;
1047 }
1048 str = QString("themes") + DIR_SEPARATOR + "gui-qt" + DIR_SEPARATOR;
1050 + id + ".png").toUtf8();
1051 status = pm->load(fileinfoname(get_data_dirs(),
1052 png_bytes.data()));
1053
1054 if (!status) {
1055 str = str + "icons" + DIR_SEPARATOR;
1056 png_bytes = QString(str + id + ".png").toUtf8();
1057 pm->load(fileinfoname(get_data_dirs(), png_bytes.data()));
1058 }
1059 QPixmapCache::insert(id, *pm);
1060
1061 return pm;
1062}
1063
1064/************************************************************************/
1068{
1069 QString str;
1071
1072 str = QString("themes") + DIR_SEPARATOR + "gui-qt"
1073 + DIR_SEPARATOR + "icons" + DIR_SEPARATOR;
1074 png_bytes = QString(str + id + ".png").toUtf8();
1075
1076 return fileinfoname(get_data_dirs(),
1077 png_bytes.data());
1078}
1079
1080/************************************************************************/
1084{
1085 QSize size;
1086
1087 size = event->size();
1088 if (C_S_RUNNING <= client_state()) {
1089 gui()->sidebar_wdg->resize_me(size.height());
1090 map_canvas_resized(size.width(), size.height());
1091 gui()->infotab->resize(qRound((size.width()
1092 * gui()->qt_settings.chat_fwidth)),
1093 qRound((size.height()
1094 * gui()->qt_settings.chat_fheight)));
1095 gui()->infotab->move(qRound((size.width()
1096 * gui()->qt_settings.chat_fx_pos)),
1097 qRound((size.height()
1098 * gui()->qt_settings.chat_fy_pos)));
1099 gui()->infotab->restore_chat();
1100 gui()->minimapview_wdg->move(qRound(gui()->qt_settings.minimap_x
1101 * mapview.width),
1102 qRound(gui()->qt_settings.minimap_y
1103 * mapview.height));
1104 gui()->minimapview_wdg->resize(qRound(gui()->qt_settings.minimap_width
1105 * mapview.width),
1106 qRound(gui()->qt_settings.minimap_height
1107 * mapview.height));
1108 gui()->battlelog_wdg->set_scale(gui()->qt_settings.battlelog_scale);
1109 gui()->battlelog_wdg->move(qRound(gui()->qt_settings.battlelog_x
1110 * mapview.width),
1111 qRound(gui()->qt_settings.battlelog_y
1112 * mapview.height));
1113 gui()->x_vote->move(width() / 2 - gui()->x_vote->width() / 2, 0);
1116 gui()->mapview_wdg->resize(event->size().width(),size.height());
1117 gui()->unitinfo_wdg->update_actions(nullptr);
1118 }
1119 event->setAccepted(true);
1120}
1121
1122/************************************************************************/
1126{
1128 fc_sidewidget *sw;
1129
1130 if (gui()->is_closing()) {
1131 return;
1132 }
1134
1135 foreach(sw, objs) {
1136 sw->update_final_pixmap();
1137 }
1138 currentWidget()->hide();
1139 widget(index)->show();
1140
1141 // Set focus to map instead sidebar
1142 if (gui()->mapview_wdg && gui()->current_page() == PAGE_GAME
1143 && index == 0) {
1144 gui()->mapview_wdg->setFocus();
1145 }
1146
1147}
1148
1149/************************************************************************/
1153{
1154}
1155
1156/************************************************************************/
1160{
1162 QPushButton *qclient_options;
1163 QHBoxLayout *hbox = nullptr;
1164 QPushButton *but;
1165 int level;
1166
1167 layout = new QFormLayout(this);
1168 nation = new QPushButton(this);
1169 qclient_options = new QPushButton(_("Client Options"));
1170 max_players = new QSpinBox(this);
1171 ailevel = new QComboBox(this);
1172 cruleset = new QComboBox(this);
1173 max_players->setRange(1, MAX_NUM_PLAYERS);
1174
1175 // Text and icon set by update_buttons()
1176 connect(nation, &QPushButton::clicked,
1178 connect(qclient_options, SIGNAL(clicked()), parentWidget(),
1179 SLOT(popup_client_options()));
1180 for (level = 0; level < AI_LEVEL_COUNT; level++) {
1181 if (is_settable_ai_level(static_cast<ai_level>(level))) {
1183 static_cast<ai_level>(level));
1184 ailevel->addItem(level_name, level);
1185 }
1186 }
1187 ailevel->setCurrentIndex(-1);
1188
1189 connect(max_players, SIGNAL(valueChanged(int)),
1190 SLOT(max_players_change(int)));
1191 connect(ailevel, SIGNAL(currentIndexChanged(int)),
1192 SLOT(ailevel_change(int)));
1193 connect(cruleset, SIGNAL(currentIndexChanged(int)),
1194 SLOT(ruleset_change(int)));
1195
1196 but = new QPushButton;
1197 but->setText(_("More Game Options"));
1198 but->setIcon(fc_icons::instance()->get_icon("preferences-other"));
1199 QObject::connect(but, &QAbstractButton::clicked, this,
1201
1202 layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
1203 layout->addRow(_("Nation:"), nation);
1204 layout->addRow(_("Rules:"), cruleset);
1205
1206 hbox = new QHBoxLayout();
1207 hbox->addWidget(max_players);
1208 hbox->addWidget(ailevel);
1209 layout->addRow(_("Players:"), hbox);
1210 layout->addWidget(but);
1211 layout->addWidget(qclient_options);
1213
1215}
1216
1217/************************************************************************/
1221{
1222 int i;
1223 int def_idx = -1;
1224
1225 cruleset->clear();
1226 cruleset->blockSignals(true);
1227 for (i = 0; i < num_rulesets; i++) {
1228 cruleset->addItem(rulesets[i], i);
1229 if (!strcmp("default", rulesets[i])) {
1230 def_idx = i;
1231 }
1232 }
1233
1234 // HACK: server should tell us the current ruleset.
1235 cruleset->setCurrentIndex(def_idx);
1236 cruleset->blockSignals(false);
1237}
1238
1239/************************************************************************/
1244{
1245 max_players->blockSignals(true);
1246 max_players->setValue(aifill);
1247 max_players->blockSignals(false);
1248}
1249
1250/************************************************************************/
1254{
1255 struct sprite *psprite = nullptr;
1256 QPixmap *pixmap = nullptr;
1257 const struct player *pplayer = client_player();
1258
1259 // Update the "Select Nation" button
1260 if (pplayer != nullptr) {
1261 if (pplayer->nation != nullptr) {
1262 // Defeat keyboard shortcut mnemonics
1263 nation->setText(QString(nation_adjective_for_player(pplayer))
1264 .replace("&", "&&"));
1266 pixmap = psprite->pm;
1267 nation->setIconSize(pixmap->size());
1268 nation->setIcon(QIcon(*pixmap));
1269 } else {
1270 nation->setText(_("Random"));
1271 nation->setIcon(fc_icons::instance()->get_icon("flush-random"));
1272 }
1273 }
1274}
1275
1276/************************************************************************/
1280{
1281 enum ai_level level = server_ai_level();
1282
1283 if (ai_level_is_valid(level)) {
1284 int i = ailevel->findData(level);
1285
1286 ailevel->setCurrentIndex(i);
1287 } else {
1288 ailevel->setCurrentIndex(-1);
1289 }
1290}
1291
1292/************************************************************************/
1299
1300/************************************************************************/
1304{
1305 QVariant v = ailevel->currentData();
1306
1307 if (v.isValid()) {
1308 enum ai_level k = static_cast<ai_level>(v.toInt());
1309
1310 // Suppress changes provoked by server rather than local user
1311 if (server_ai_level() != k) {
1312 const char *name = ai_level_cmd(k);
1313
1314 send_chat_printf("/%s", name);
1315 }
1316 }
1317}
1318
1319/************************************************************************/
1323{
1324 if (!cruleset->currentText().isEmpty()) {
1326
1327 rn_bytes = cruleset->currentText().toUtf8();
1328 set_ruleset(rn_bytes.data());
1329 }
1330}
1331
1332/************************************************************************/
1339
1340/************************************************************************/
1344{
1345 option_dialog_popup(_("Set server options"), server_optset, false);
1346}
#define str
Definition astring.c:76
static QFont * get_font(enum client_font font)
Definition canvas.cpp:379
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
QString apply_tags(QString str, const struct text_tag_list *tags, QColor bg_color)
Definition chatline.cpp:573
int send_chat_printf(const char *format,...)
int send_chat(const char *message)
void fc_allocate_ow_mutex(void)
void fc_release_ow_mutex(void)
void chat_welcome_message(bool gui_has_copying_mitem)
void send_chat_message(const QString &message)
Definition chatline.cpp:109
void update_widgets()
Definition chatline.cpp:504
fc_game_tab_widget * game_tab_widget
Definition fc_client.h:259
void chat_message_received(const QString &message, const struct text_tag_list *tags)
void apply_fullscreen()
info_tile * info_tile_wdg
Definition fc_client.h:218
QStringList status_bar_queue
Definition fc_client.h:352
QSocketNotifier * server_notifier
Definition fc_client.h:201
QLineEdit * connect_host_edit
Definition fc_client.h:188
void popdown_unit_sel()
QTextEdit * output_window
Definition fc_client.h:181
bool interface_locked
Definition fc_client.h:273
void init()
void update_sidebar_tooltips()
Definition pages.cpp:2153
fc_settings qt_settings
Definition fc_client.h:268
goto_dialog * gtd
Definition fc_client.h:265
mr_menu * menu_bar
Definition fc_client.h:257
bool quitting
Definition fc_client.h:355
QTimer * meta_scan_timer
Definition fc_client.h:212
hud_battle_log * battlelog_wdg
Definition fc_client.h:272
void closing()
QWidget * connect_lan
Definition fc_client.h:174
QTableWidget * lan_widget
Definition fc_client.h:205
QWidget * connect_metaserver
Definition fc_client.h:175
QLineEdit * connect_confirm_password_edit
Definition fc_client.h:192
chat_input * chat_line
Definition fc_client.h:203
hud_units * unitinfo_wdg
Definition fc_client.h:271
bool map_font_scale
Definition fc_client.h:280
choice_dialog * opened_dialog
Definition fc_client.h:219
pregamevote * pre_vote
Definition fc_client.h:262
QTableWidget * saves_load
Definition fc_client.h:208
void read_settings()
messagewdg * msgwdg
Definition fc_client.h:260
void set_status_bar(QString str, int timeout=2000)
Definition pages.cpp:451
QPushButton * button
Definition fc_client.h:194
bool is_repo_dlg_open(QString str)
void server_input(int sock)
enum client_pages page
Definition fc_client.h:350
enum client_pages current_page()
units_select * unit_sel
Definition fc_client.h:263
QLineEdit * connect_password_edit
Definition fc_client.h:191
void quit()
minimap_view * minimapview_wdg
Definition fc_client.h:232
QStatusBar * status_bar
Definition fc_client.h:216
QTableWidget * wan_widget
Definition fc_client.h:206
void gimme_place(QWidget *widget, QString str)
QCursor * fc_cursors[CURSOR_LAST][NUM_CURSOR_FRAMES]
Definition fc_client.h:266
map_view * mapview_wdg
Definition fc_client.h:230
void delete_cursors(void)
QStackedLayout * central_layout
Definition fc_client.h:179
void write_settings()
info_tab * infotab
Definition fc_client.h:261
void create_start_page()
Definition pages.cpp:647
void slot_disconnect()
QWidget * pages[(int) PAGE_GAME+2]
Definition fc_client.h:173
void slot_pregame_observe()
QTableWidget * info_widget
Definition fc_client.h:207
void set_connection_state(enum connection_state state)
Definition pages.cpp:266
QPushButton * obs_button
Definition fc_client.h:195
void update_info_label()
Definition mapview.cpp:1000
QLabel * status_bar_label
Definition fc_client.h:217
QGridLayout * pages_layout[PAGE_GAME+2]
Definition fc_client.h:178
QWidget * main_wdg
Definition fc_client.h:172
QLineEdit * connect_login_edit
Definition fc_client.h:190
void add_server_source(int)
QTextEdit * scenarios_view
Definition fc_client.h:182
QDialogButtonBox * button_box
Definition fc_client.h:199
void destroy_server_scans(void)
Definition pages.cpp:1021
void create_cursors(void)
void switch_page(int i)
void create_network_page()
Definition pages.cpp:303
QTreeWidget * start_players_tree
Definition fc_client.h:210
bool chat_active_on_page(enum client_pages)
void create_load_page()
Definition pages.cpp:495
QTimer * lan_scan_timer
Definition fc_client.h:213
QLineEdit * connect_port_edit
Definition fc_client.h:189
fc_sidebar * sidebar_wdg
Definition fc_client.h:231
void create_main_page()
Definition pages.cpp:138
bool event(QEvent *event)
float map_scale
Definition fc_client.h:279
void create_loading_page()
Definition pages.cpp:483
void update_fonts()
void update_network_lists()
Definition pages.cpp:1051
QWidget * central_wdg
Definition fc_client.h:256
void fc_main(QApplication *qapp)
QMap< QString, QWidget * > opened_repo_dlgs
Definition fc_client.h:351
QString current_file
Definition fc_client.h:353
void closeEvent(QCloseEvent *event)
xvote * x_vote
Definition fc_client.h:264
void remove_repo_dlg(QString str)
void slot_pregame_start()
QTimer * update_info_timer
Definition fc_client.h:214
void toggle_unit_sel_widget(struct tile *ptile)
void popup_client_options()
void update_unit_sel()
void update_load_page(void)
Definition pages.cpp:1433
QTableWidget * scenarios_load
Definition fc_client.h:209
int gimme_index_of(QString str)
fc_corner * corner_wid
Definition fc_client.h:258
void send_fake_chat_message(const QString &message)
void timerEvent(QTimerEvent *)
bool is_closing()
void create_scenario_page()
Definition pages.cpp:580
void remove_server_source()
void update_scenarios_page(void)
Definition pages.cpp:1464
void create_game_page()
Definition pages.cpp:731
void minimize()
QMainWindow * mw
Definition fc_client.h:158
void maximize()
void close_fc()
fc_corner(QMainWindow *qmw)
static fc_font * m_instance
Definition fonts.h:43
void init_fonts()
Definition fonts.cpp:77
static fc_font * instance()
Definition fonts.cpp:41
QFont * get_font(QString name)
Definition fonts.cpp:63
void resizeEvent(QResizeEvent *event)
void current_changed(int index)
QIcon get_icon(const QString &id)
static void drop()
static fc_icons * m_instance
Definition fc_client.h:93
QPixmap * get_pixmap(const QString &id)
static fc_icons * instance()
QString get_path(const QString &id)
static fc_shortcuts * sc()
void resize_me(int height, bool force=false)
Definition sidebar.cpp:566
QList< fc_sidewidget * > objects
Definition sidebar.h:117
void update_fonts()
Definition sidebar.cpp:608
void update_final_pixmap()
Definition sidebar.cpp:389
void set_scale(float s)
void update_actions(unit_list *punits)
void restore_chat()
chatwdg * chtwdg
Definition messagewin.h:75
void reset()
Definition mapview.cpp:732
void popup_server_options()
QPushButton * nation
Definition fc_client.h:375
QComboBox * ailevel
Definition fc_client.h:373
void ailevel_change(int i)
void set_rulesets(int num_rulesets, char **rulesets)
void set_aifill(int aifill)
void max_players_change(int i)
QComboBox * cruleset
Definition fc_client.h:374
pregame_options(QWidget *parent)
void ruleset_change(int i)
QSpinBox * max_players
Definition fc_client.h:376
void update_units()
Definition dialogs.cpp:4844
void create_pixmap()
Definition dialogs.cpp:4543
bool is_client_quitting(void)
bool can_client_control(void)
bool client_is_global_observer(void)
bool client_is_observer(void)
char user_name[512]
double real_timer_callback(void)
char server_host[512]
struct civclient client
enum client_states client_state(void)
int server_port
void set_client_state(enum client_states newstate)
#define client_player()
#define TIMER_INTERVAL
Definition client_main.h:30
@ C_S_DISCONNECTED
Definition client_main.h:45
@ C_S_RUNNING
Definition client_main.h:47
enum ai_level server_ai_level(void)
Definition climisc.c:1519
void center_on_something(void)
Definition climisc.c:430
void disconnect_from_server(bool leaving_sound)
Definition clinet.c:306
void input_from_server(int fd)
Definition clinet.c:411
char * incite_cost
Definition comments.c:77
void set_ruleset(const char *ruleset)
bool is_server_running(void)
enum event_type event
Definition events.c:81
bool get_turn_done_button_state()
QString current_theme
Definition fc_client.cpp:59
void write_shortcuts()
@ LOGIN_TYPE
Definition fc_client.h:56
class fc_client * gui()
Definition gui_main.cpp:82
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:62
static PangoLayout * layout
Definition canvas.c:325
void real_output_window_append(const char *astring, const struct text_tag_list *tags, int conn_id)
Definition chatline.c:875
void popup_races_dialog(struct player *pplayer)
Definition dialogs.c:1215
void popup_quit_dialog(void)
Definition gui_main.c:2349
void overview_size_changed(void)
Definition mapview.c:326
void option_dialog_popup(const char *name, const struct option_set *poptset)
Definition optiondlg.c:984
static enum client_pages current_page
Definition pages.c:78
void voteinfo_gui_update(void)
static QApplication * qapp
Definition gui_main.cpp:69
QApplication * current_app()
Definition gui_main.cpp:227
void show_new_turn_info()
const char * name
Definition inputfile.c:127
#define log_error(message,...)
Definition log.h:104
int dsend_packet_player_ready(struct connection *pc, int player_no, bool is_ready)
void side_disable_endturn(bool do_restore)
Definition sidebar.cpp:672
void init_mapcanvas_and_overview(void)
struct view mapview
void free_mapcanvas_and_overview(void)
bool map_canvas_resized(int width, int height)
const char *const default_font
Definition fonts.h:27
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
const struct option_set * server_optset
Definition options.c:4369
const struct option_set * client_optset
Definition options.c:1331
struct client_options gui_options
Definition options.c:71
struct option * optset_option_by_name(const struct option_set *poptset, const char *name)
Definition options.c:482
bool option_int_set(struct option *poption, int val)
Definition options.c:929
#define MAJOR_NEW_OPTION_FILE_NAME
Definition options.h:38
#define MINOR_NEW_OPTION_FILE_NAME
Definition options.h:42
bool is_settable_ai_level(enum ai_level level)
Definition player.c:1908
int player_number(const struct player *pplayer)
Definition player.c:826
#define ai_level_cmd(_level_)
Definition player.h:582
void qtg_real_science_report_dialog_update(void *unused)
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1094
const struct strvec * get_data_dirs(void)
Definition shared.c:886
#define DIR_SEPARATOR
Definition shared.h:127
size_t size
Definition specvec.h:72
struct sprite int x
Definition sprite_g.h:31
const char * aifill(int amount)
Definition srv_main.c:2509
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
bool gui_qt_fullscreen
Definition options.h:454
bool gui_qt_allied_chat_only
Definition options.h:456
bool gui_qt_show_titlebar
Definition options.h:467
QByteArray city_splitter2
Definition fc_client.h:135
QByteArray city_geometry
Definition fc_client.h:133
QByteArray help_geometry
Definition fc_client.h:137
float unit_info_pos_fx
Definition fc_client.h:141
QByteArray options_client_geometry
Definition fc_client.h:139
float unit_info_pos_fy
Definition fc_client.h:142
float chat_fwidth
Definition fc_client.h:123
float chat_fheight
Definition fc_client.h:124
QByteArray help_splitter1
Definition fc_client.h:138
float chat_fx_pos
Definition fc_client.h:125
float battlelog_scale
Definition fc_client.h:147
float battlelog_x
Definition fc_client.h:148
QByteArray city_splitter3
Definition fc_client.h:136
float minimap_x
Definition fc_client.h:143
float minimap_height
Definition fc_client.h:146
bool show_battle_log
Definition fc_client.h:129
int city_repo_sort_col
Definition fc_client.h:131
float minimap_width
Definition fc_client.h:145
float battlelog_y
Definition fc_client.h:149
QByteArray options_server_geometry
Definition fc_client.h:140
float chat_fy_pos
Definition fc_client.h:126
QByteArray city_splitter1
Definition fc_client.h:134
bool show_new_turn_text
Definition fc_client.h:128
float minimap_y
Definition fc_client.h:144
int player_repo_sort_col
Definition fc_client.h:127
struct nation_type * nation
Definition player.h:260
QPixmap * pm
Definition sprite.h:25
Definition tile.h:50
int height
int width
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define TRUE
Definition support.h:46
void tileset_free_tiles(struct tileset *t)
Definition tilespec.c:6835
struct sprite * get_nation_shield_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:7005
struct sprite * get_cursor_sprite(const struct tileset *t, enum cursor_type cursor, int *hot_x, int *hot_y, int frame)
Definition tilespec.c:7208
#define NUM_CURSOR_FRAMES
Definition tilespec.h:305
cursor_type
Definition tilespec.h:289
@ CURSOR_LAST
Definition tilespec.h:301
void client_start_server_and_set_page(enum client_pages page)
void set_client_page(enum client_pages page)