Freeciv-3.3
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
37#ifdef FC_QT5_MODE
38#include <QTextCodec>
39#endif // FC_QT5_MODE
40
41#include <QTextEdit>
42
43// common
44#include "game.h"
45
46// client
47#include "connectdlg_common.h"
48
49// gui-qt
50#include "fc_client.h"
51#include "fonts.h"
52#include "gui_main.h"
53#include "optiondlg.h"
54#include "sidebar.h"
55#include "sprite.h"
56
59extern "C" {
61}
62extern void write_shortcuts();
63
65
66/************************************************************************/
69fc_client::fc_client() : QMainWindow()
70{
72
73#ifdef FC_QT5_MODE
74 QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
75#endif // FC_QT5_MODE
76
84 main_wdg = nullptr;
85 connect_lan = nullptr;
86 connect_metaserver = nullptr;
87 central_layout = nullptr;
88 output_window = nullptr;
89 scenarios_view = nullptr;
90 connect_host_edit = nullptr;
91 connect_port_edit = nullptr;
92 connect_login_edit = nullptr;
93 connect_password_edit = nullptr;
95 button = nullptr;
96 button_box = nullptr;
97 server_notifier = nullptr;
98 chat_line = nullptr;
99 lan_widget = nullptr;
100 wan_widget = nullptr;
101 info_widget = nullptr;
102 saves_load = nullptr;
103 scenarios_load = nullptr;
104 meta_scan_timer = nullptr;
105 lan_scan_timer = nullptr;
106 status_bar = nullptr;
107 status_bar_label = nullptr;
108 menu_bar = nullptr;
109 mapview_wdg = nullptr;
110 sidebar_wdg = nullptr;
111 msgwdg = nullptr;
112 infotab = nullptr;
113 central_wdg = nullptr;
114 game_tab_widget = nullptr;
115 start_players_tree = nullptr;
116 unit_sel = nullptr;
117 info_tile_wdg = nullptr;
118 opened_dialog = nullptr;
119 current_file = "";
120 status_bar_queue.clear();
121 quitting = false;
122 pre_vote = nullptr;
123 x_vote = nullptr;
124 gtd = nullptr;
125 update_info_timer = nullptr;
126 unitinfo_wdg = nullptr;
127 battlelog_wdg = nullptr;
128 interface_locked = false;
129 map_scale = 1.0f;
130 map_font_scale = true;
131 for (int i = 0; i <= PAGE_GAME; i++) {
132 pages_layout[i] = nullptr;
133 pages[i] = nullptr;
134 }
135
136 wtitle = _("Freeciv (%1)");
137 wtitle = wtitle.arg(
139 "Qt6x"
141 "Qt5"
142#else // FC_QT6X_MODE
143 "Qt6"
144#endif // FC_QT6X_MODE
145 );
146
148
149 init();
150}
151
152/************************************************************************/
156{
159 QApplication::setFont(*fc_font::instance()->get_font(fonts::default_font));
160 QString path;
161 central_wdg = new QWidget;
163
164 // General part not related to any single page
165 menu_bar = new mr_menu();
167 corner_wid = new fc_corner(this);
168 menu_bar->setCornerWidget(corner_wid);
169 }
172 status_bar_label = new QLabel;
173 status_bar_label->setAlignment(Qt::AlignCenter);
174 status_bar->addWidget(status_bar_label, 1);
175 set_status_bar(_("Welcome to Freeciv"));
177
178 // PAGE_MAIN
179 pages[PAGE_MAIN] = new QWidget(central_wdg);
180 page = PAGE_MAIN;
182
183 // PAGE_START
184 pages[PAGE_START] = new QWidget(central_wdg);
186
187 // PAGE_SCENARIO
188 pages[PAGE_SCENARIO] = new QWidget(central_wdg);
190
191 // PAGE_LOAD
192 pages[PAGE_LOAD] = new QWidget(central_wdg);
194
195 // PAGE_NETWORK
196 pages[PAGE_NETWORK] = new QWidget(central_wdg);
198 pages[PAGE_NETWORK]->setVisible(false);
199
200 // PAGE_GAME
202 path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
203 if (!path.isEmpty()) {
204 QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, path);
205 }
206 pages[PAGE_GAME] = new QWidget(central_wdg);
209
210 pages[PAGE_GAME + 1] = new QWidget(central_wdg);
212
213 pages_layout[PAGE_GAME]->setContentsMargins(0, 0, 0, 0);
214
221 pages[PAGE_GAME + 1]->setLayout(pages_layout[PAGE_GAME + 1]);
222
223 central_layout->addWidget(pages[PAGE_MAIN]);
224 central_layout->addWidget(pages[PAGE_NETWORK]);
225 central_layout->addWidget(pages[PAGE_LOAD]);
227 central_layout->addWidget(pages[PAGE_START]);
228 central_layout->addWidget(pages[PAGE_GAME]);
229 central_layout->addWidget(pages[PAGE_GAME + 1]);
230
231 central_wdg->setLayout(central_layout);
233
234 resize(pages[PAGE_MAIN]->minimumSizeHint());
235 setVisible(true);
236
239
240 QPixmapCache::setCacheLimit(80000);
241}
242
243/************************************************************************/
247{
248 status_bar_queue.clear();
249 if (fc_shortcuts::sc()) {
250 delete fc_shortcuts::sc();
251 }
253}
254
255
256/************************************************************************/
263{
264 qRegisterMetaType<QTextCursor>("QTextCursor");
265 qRegisterMetaType<QTextBlock>("QTextBlock");
267 real_output_window_append(_("This is Qt-client for Freeciv."), nullptr, -1);
270
272
274 connect(qapp, &QCoreApplication::aboutToQuit, this, &fc_client::closing);
275 qapp->exec();
276
279}
280
281/************************************************************************/
285{
286 return quitting;
287}
288
289/************************************************************************/
293{
294 quitting = true;
295}
296
297/************************************************************************/
304
305/************************************************************************/
309 const struct text_tag_list *tags)
310{
311 QTextCursor cursor;
312 QColor col = output_window->palette().color(QPalette::Text);
313 QString str = apply_tags(message, tags, col);
314
315 if (output_window != nullptr) {
316 output_window->append(str);
317 output_window->verticalScrollBar()->setSliderPosition(
318 output_window->verticalScrollBar()->maximum());
319 }
320}
321
322/************************************************************************/
326{
327 if (check == PAGE_START || check == PAGE_GAME) {
328 return true;
329 }
330
331 return false;
332}
333
334/************************************************************************/
341{
342 char buf[256];
344 int i_page;
345
346 new_page = static_cast<client_pages>(new_pg);
347
349 && !is_server_running()) {
350 current_file = "";
352 return;
353 }
354
355 if (page == PAGE_NETWORK) {
357 }
358 menuBar()->setVisible(false);
359 if (status_bar != nullptr) {
360 status_bar->setVisible(true);
361 }
362 QApplication::alert(gui()->central_wdg);
363 central_layout->setCurrentWidget(pages[new_pg]);
364 page = new_page;
366 switch (i_page) {
367 case PAGE_MAIN:
368 break;
369 case PAGE_START:
370 pre_vote->hide();
372 break;
373 case PAGE_LOAD:
375 break;
376 case PAGE_GAME:
378 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
379 }
381 // For MS Windows, it might ignore first
384 status_bar->setVisible(false);
385
388 }
389
390 menuBar()->setVisible(true);
391 mapview_wdg->setFocus();
400 break;
401 case PAGE_SCENARIO:
403 break;
404 case PAGE_NETWORK:
408 fc_snprintf(buf, sizeof(buf), "%d", server_port);
409 connect_port_edit->setText(buf);
411 connect_password_edit->setDisabled(true);
412 connect_confirm_password_edit->setDisabled(true);
413 break;
414 case (PAGE_GAME + 1):
415 break;
416 default:
417 if (client.conn.used) {
419 }
421 break;
422 }
423}
424
425/************************************************************************/
429{
431 gui()->showFullScreen();
432 gui()->game_tab_widget->showFullScreen();
433 } else {
434 // FIXME: Doesn't return properly, probably something with sidebar
435 gui()->showNormal();
436 gui()->game_tab_widget->showNormal();
437 }
438}
439
440/************************************************************************/
444{
445 return page;
446}
447
448/************************************************************************/
452{
453 server_notifier = new QSocketNotifier(sock, QSocketNotifier::Read);
454
455 connect(server_notifier, &QSocketNotifier::activated, this,
457}
458
459/************************************************************************/
466
467/************************************************************************/
471{
472 if (event->type() == QEvent::User) {
474 dynamic_cast<version_message_event&>(*event);
475 set_status_bar(vmevt.get_message());
476 return true;
477 } else {
478 return QMainWindow::event(event);
479 }
480}
481
482/************************************************************************/
486{
487 if (!is_client_quitting()) {
489 event->ignore();
490 }
491}
492
493/************************************************************************/
497{
498 server_notifier->deleteLater();
499}
500
501/************************************************************************/
505{
506 server_notifier->setEnabled(false);
507 input_from_server(sock);
508 server_notifier->setEnabled(true);
509}
510
511/************************************************************************/
515{
516 // Prevent current timer from repeating with possibly wrong interval
517 killTimer(event->timerId());
518
519 // Call timer callback in client common code and
520 // start new timer with correct interval
522}
523
524/************************************************************************/
528{
530
531 if (qapp != nullptr) {
532 qapp->quit();
533 }
534}
535
536/************************************************************************/
547
548/************************************************************************/
552{
554 if (game.info.is_new_game) {
555 send_chat("/take -");
556 } else {
557 send_chat("/detach");
558 }
559 obs_button->setText(_("Don't Observe"));
560 } else {
561 send_chat("/observe");
562 obs_button->setText(_("Observe"));
563 }
564}
565
566/************************************************************************/
579
580/****************************************************************************
581 Deletes cursors
582****************************************************************************/
584{
585 int frame;
586 int cursor;
587
588 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
589 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
590 delete fc_cursors[cursor][frame];
591 }
592 }
593}
594
595
596/************************************************************************/
600{
601 QString x;
602
604
605 if (x.isEmpty()) {
606 opened_repo_dlgs.insert(str, widget);
607 return;
608 }
609 log_error("Failed to find place for new tab widget");
610 return;
611}
612
613/************************************************************************/
619{
620 QWidget *w;
621
622 w = opened_repo_dlgs.value(str);
623
624 if (w == nullptr) {
625 return false;
626 }
627
628 return true;
629}
630
631/************************************************************************/
635{
636 int i;
637 QWidget *w;
638
639 if (str == "MAP") {
640 return 0;
641 }
642
643 w = opened_repo_dlgs.value(str);
644 i = game_tab_widget->indexOf(w);
645 return i;
646}
647
648/************************************************************************/
652{
653 // This can't be shared between freeciv versions as the content
654 // might be incompatible.
655 QString sname = "freeciv-qt-client-set-"
656 + QString::number(MAJOR_NEW_OPTION_FILE_NAME) + "."
657 + QString::number(MINOR_NEW_OPTION_FILE_NAME);
658 QSettings s(QSettings::IniFormat, QSettings::UserScope,
659 sname);
660
661 if (s.contains("Chat-fx-size")) {
662 qt_settings.chat_fwidth = s.value("Chat-fx-size").toFloat();
663 } else {
665 }
666 if (s.contains("Chat-fy-size")) {
667 qt_settings.chat_fheight = s.value("Chat-fy-size").toFloat();
668 } else {
670 }
671 if (s.contains("Chat-fx-pos")) {
672 qt_settings.chat_fx_pos = s.value("Chat-fx-pos").toFloat();
673 } else {
675 }
676 if (s.contains("Chat-fy-pos")) {
677 qt_settings.chat_fy_pos = s.value("Chat-fy-pos").toFloat();
678 } else {
680 }
681 if (s.contains("unit_fx")) {
682 qt_settings.unit_info_pos_fx = s.value("unit_fx").toFloat();
683 } else {
685 }
686 if (s.contains("unit_fy")) {
687 qt_settings.unit_info_pos_fy = s.value("unit_fy").toFloat();
688 } else {
690 }
691 if (s.contains("minimap_x")) {
692 qt_settings.minimap_x = s.value("minimap_x").toFloat();
693 } else {
694 qt_settings.minimap_x = 0.84;
695 }
696 if (s.contains("minimap_y")) {
697 qt_settings.minimap_y = s.value("minimap_y").toFloat();
698 } else {
699 qt_settings.minimap_y = 0.79;
700 }
701 if (s.contains("minimap_width")) {
702 qt_settings.minimap_width = s.value("minimap_width").toFloat();
703 } else {
705 }
706 if (s.contains("minimap_height")) {
707 qt_settings.minimap_height = s.value("minimap_height").toFloat();
708 } else {
710 }
711 if (s.contains("battlelog_scale")) {
712 qt_settings.battlelog_scale = s.value("battlelog_scale").toFloat();
713 } else {
715 }
716
717 if (s.contains("City-dialog")) {
718 qt_settings.city_geometry = s.value("City-dialog").toByteArray();
719 }
720 if (s.contains("splitter1")) {
721 qt_settings.city_splitter1 = s.value("splitter1").toByteArray();
722 }
723 if (s.contains("splitter2")) {
724 qt_settings.city_splitter2 = s.value("splitter2").toByteArray();
725 }
726 if (s.contains("splitter3")) {
727 qt_settings.city_splitter3 = s.value("splitter3").toByteArray();
728 }
729 if (s.contains("help-dialog")) {
730 qt_settings.help_geometry = s.value("help-dialog").toByteArray();
731 }
732 if (s.contains("help_splitter1")) {
733 qt_settings.help_splitter1 = s.value("help_splitter1").toByteArray();
734 }
735 if (s.contains("opt-client-dialog")) {
736 qt_settings.options_client_geometry = s.value("opt-client-dialog").toByteArray();
737 }
738 if (s.contains("opt-server-dialog")) {
739 qt_settings.options_server_geometry = s.value("opt-server-dialog").toByteArray();
740 }
741 if (s.contains("new_turn_text")) {
742 qt_settings.show_new_turn_text = s.value("new_turn_text").toBool();
743 } else {
745 }
746 if (s.contains("show_battle_log")) {
747 qt_settings.show_battle_log = s.value("show_battle_log").toBool();
748 } else {
750 }
751 if (s.contains("battlelog_x")) {
752 qt_settings.battlelog_x = s.value("battlelog_x").toFloat();
753 } else {
755 }
756 if (s.contains("minimap_y")) {
757 qt_settings.battlelog_y = s.value("battlelog_y").toFloat();
758 } else {
760 }
763
766 }
769 }
770 if (qt_settings.chat_fwidth < 0.05 || qt_settings.chat_fwidth > 0.9) {
772 }
773 if (qt_settings.chat_fheight < 0.05 || qt_settings.chat_fheight > 0.9) {
775 }
776 if (qt_settings.battlelog_x < 0.0) {
778 }
779 if (qt_settings.battlelog_y < 0.0) {
781 }
782 if (qt_settings.battlelog_scale > 5.0) {
784 }
787 }
790 }
791}
792
793/************************************************************************/
797{
798 QString sname = "freeciv-qt-client-set-"
799 + QString::number(MAJOR_NEW_OPTION_FILE_NAME) + "."
800 + QString::number(MINOR_NEW_OPTION_FILE_NAME);
801 QSettings s(QSettings::IniFormat, QSettings::UserScope,
802 sname);
803
804 s.setValue("Chat-fx-size", qt_settings.chat_fwidth);
805 s.setValue("Chat-fy-size", qt_settings.chat_fheight);
806 s.setValue("Chat-fx-pos", qt_settings.chat_fx_pos);
807 s.setValue("Chat-fy-pos", qt_settings.chat_fy_pos);
808 s.setValue("City-dialog", qt_settings.city_geometry);
809 s.setValue("splitter1", qt_settings.city_splitter1);
810 s.setValue("splitter2", qt_settings.city_splitter2);
811 s.setValue("splitter3", qt_settings.city_splitter3);
812 s.setValue("help-dialog", qt_settings.help_geometry);
813 s.setValue("help_splitter1", qt_settings.help_splitter1);
814 s.setValue("opt-client-dialog", qt_settings.options_client_geometry);
815 s.setValue("opt-server-dialog", qt_settings.options_server_geometry);
816 s.setValue("unit_fx", qt_settings.unit_info_pos_fx);
817 s.setValue("unit_fy", qt_settings.unit_info_pos_fy);
818 s.setValue("minimap_x", qt_settings.minimap_x);
819 s.setValue("minimap_y", qt_settings.minimap_y);
820 s.setValue("minimap_width", qt_settings.minimap_width);
821 s.setValue("minimap_height", qt_settings.minimap_height);
822 s.setValue("battlelog_scale", qt_settings.battlelog_scale);
823 s.setValue("battlelog_x", qt_settings.battlelog_x);
824 s.setValue("battlelog_y", qt_settings.battlelog_y);
825 s.setValue("new_turn_text", qt_settings.show_new_turn_text);
826 s.setValue("show_battle_log", qt_settings.show_battle_log);
828}
829
830/************************************************************************/
834{
835 if (unit_sel != nullptr) {
836 unit_sel->close();
837 delete unit_sel;
838 unit_sel = new units_select(ptile, gui()->mapview_wdg);
839 unit_sel->show();
840 } else {
841 unit_sel = new units_select(ptile, gui()->mapview_wdg);
842 unit_sel->show();
843 }
844}
845
846/************************************************************************/
850{
851 if (unit_sel != nullptr) {
854 unit_sel->update();
855 }
856}
857
858/************************************************************************/
862{
863 if (unit_sel != nullptr) {
864 unit_sel->close();
865 delete unit_sel;
866 unit_sel = nullptr;
867 }
868}
869
870/************************************************************************/
874{
875 // If app is closing, opened_repo_dlg is already deleted */
876 if (!is_closing()) {
877 opened_repo_dlgs.remove(str);
878 }
879}
880
881/************************************************************************/
885{
886 option_dialog_popup(_("Set local options"), client_optset, true);
887}
888
889/************************************************************************/
893{
894 enum cursor_type curs;
895 int cursor;
896 QPixmap *pix;
897 int hot_x, hot_y;
898 struct sprite *sprite;
899 int frame;
900 QCursor *c;
901 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
902 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
903 curs = static_cast<cursor_type>(cursor);
904 sprite = get_cursor_sprite(tileset, curs, &hot_x, &hot_y, frame);
905 pix = sprite->pm;
906 c = new QCursor(*pix, hot_x, hot_y);
907 fc_cursors[cursor][frame] = c;
908 }
909 }
910}
911
912/************************************************************************/
915fc_corner::fc_corner(QMainWindow *qmw): QWidget()
916{
918 QPushButton *qpb;
919 int h;
921
922 if (f->pointSize() > 0) {
923 h = f->pointSize();
924 } else {
925 h = f->pixelSize();
926 }
927 mw = qmw;
928 hb = new QHBoxLayout();
929 qpb = new QPushButton(fc_icons::instance()->get_icon("cmin"), "");
930 qpb->setFixedSize(h, h);
931 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::minimize);
932 hb->addWidget(qpb);
933 qpb = new QPushButton(fc_icons::instance()->get_icon("cmax"), "");
934 qpb->setFixedSize(h, h);
935 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::maximize);
936 hb->addWidget(qpb);
937 qpb = new QPushButton(fc_icons::instance()->get_icon("cclose"), "");
938 qpb->setFixedSize(h, h);
939 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::close_fc);
940 hb->addWidget(qpb);
941 setLayout(hb);
942}
943
944/************************************************************************/
948{
949 mw->close();
950}
951
952/************************************************************************/
956{
957 if (!mw->isMaximized()) {
958 mw->showMaximized();
959 } else {
960 mw->showNormal();
961 }
962}
963
964/************************************************************************/
968{
969 mw->showMinimized();
970}
971
972/************************************************************************/
976{
977}
978
979/************************************************************************/
983{
984 connect(this, &QStackedWidget::currentChanged, this, &fc_game_tab_widget::current_changed);
985}
986
987/************************************************************************/
993
994/************************************************************************/
998{
999 if (!m_instance) {
1000 m_instance = new fc_icons;
1001 }
1002 return m_instance;
1003}
1004
1005/************************************************************************/
1009{
1010 if (m_instance) {
1011 delete m_instance;
1012 m_instance = 0;
1013 }
1014}
1015
1016/************************************************************************/
1020{
1021 QIcon icon;
1022 QString str;
1025
1026 str = QString("themes") + DIR_SEPARATOR + "gui-qt" + DIR_SEPARATOR;
1027 // Try custom icon from theme
1028 pn_bytes = str.toUtf8();
1030 + id + ".png").toUtf8();
1031 icon.addFile(fileinfoname(get_data_dirs(),
1032 png_bytes.data()));
1033 str = str + "icons" + DIR_SEPARATOR;
1034 // Try icon from icons dir
1035 if (icon.isNull()) {
1036 pn_bytes = str.toUtf8();
1037 png_bytes = QString(pn_bytes.data() + id + ".png").toUtf8();
1038 icon.addFile(fileinfoname(get_data_dirs(),
1039 png_bytes.data()));
1040 }
1041
1042 return QIcon(icon);
1043}
1044
1045/************************************************************************/
1049{
1050 QPixmap *pm;
1051 bool status;
1052 QString str;
1054
1055 pm = new QPixmap;
1056 if (QPixmapCache::find(id, pm)) {
1057 return pm;
1058 }
1059 str = QString("themes") + DIR_SEPARATOR + "gui-qt" + DIR_SEPARATOR;
1061 + id + ".png").toUtf8();
1062 status = pm->load(fileinfoname(get_data_dirs(),
1063 png_bytes.data()));
1064
1065 if (!status) {
1066 str = str + "icons" + DIR_SEPARATOR;
1067 png_bytes = QString(str + id + ".png").toUtf8();
1068 pm->load(fileinfoname(get_data_dirs(), png_bytes.data()));
1069 }
1070 QPixmapCache::insert(id, *pm);
1071
1072 return pm;
1073}
1074
1075/************************************************************************/
1079{
1080 QString str;
1082
1083 str = QString("themes") + DIR_SEPARATOR + "gui-qt"
1084 + DIR_SEPARATOR + "icons" + DIR_SEPARATOR;
1085 png_bytes = QString(str + id + ".png").toUtf8();
1086
1087 return fileinfoname(get_data_dirs(),
1088 png_bytes.data());
1089}
1090
1091/************************************************************************/
1095{
1096 QSize size;
1097
1098 size = event->size();
1099 if (C_S_RUNNING <= client_state()) {
1100 gui()->sidebar_wdg->resize_me(size.height());
1101 map_canvas_resized(size.width(), size.height());
1102 gui()->infotab->resize(qRound((size.width()
1103 * gui()->qt_settings.chat_fwidth)),
1104 qRound((size.height()
1105 * gui()->qt_settings.chat_fheight)));
1106 gui()->infotab->move(qRound((size.width()
1107 * gui()->qt_settings.chat_fx_pos)),
1108 qRound((size.height()
1109 * gui()->qt_settings.chat_fy_pos)));
1110 gui()->infotab->restore_chat();
1111 gui()->minimapview_wdg->move(qRound(gui()->qt_settings.minimap_x
1112 * mapview.width),
1113 qRound(gui()->qt_settings.minimap_y
1114 * mapview.height));
1115 gui()->minimapview_wdg->resize(qRound(gui()->qt_settings.minimap_width
1116 * mapview.width),
1117 qRound(gui()->qt_settings.minimap_height
1118 * mapview.height));
1119 gui()->battlelog_wdg->set_scale(gui()->qt_settings.battlelog_scale);
1120 gui()->battlelog_wdg->move(qRound(gui()->qt_settings.battlelog_x
1121 * mapview.width),
1122 qRound(gui()->qt_settings.battlelog_y
1123 * mapview.height));
1124 gui()->x_vote->move(width() / 2 - gui()->x_vote->width() / 2, 0);
1127 gui()->mapview_wdg->resize(event->size().width(),size.height());
1128 gui()->unitinfo_wdg->update_actions(nullptr);
1129 }
1130 event->setAccepted(true);
1131}
1132
1133/************************************************************************/
1137{
1139 fc_sidewidget *sw;
1140
1141 if (gui()->is_closing()) {
1142 return;
1143 }
1145
1146 foreach(sw, objs) {
1147 sw->update_final_pixmap();
1148 }
1149 currentWidget()->hide();
1150 widget(index)->show();
1151
1152 // Set focus to map instead sidebar
1153 if (gui()->mapview_wdg && gui()->current_page() == PAGE_GAME
1154 && index == 0) {
1155 gui()->mapview_wdg->setFocus();
1156 }
1157
1158}
1159
1160/************************************************************************/
1164{
1165}
1166
1167/************************************************************************/
1171{
1173 QPushButton *qclient_options;
1174 QHBoxLayout *hbox = nullptr;
1175 QPushButton *but;
1176 int level;
1177
1178 layout = new QFormLayout(this);
1179 nation = new QPushButton(this);
1180 qclient_options = new QPushButton(_("Client Options"));
1181 max_players = new QSpinBox(this);
1182 ailevel = new QComboBox(this);
1183 cruleset = new QComboBox(this);
1184 max_players->setRange(1, MAX_NUM_PLAYERS);
1185
1186 // Text and icon set by update_buttons()
1187 connect(nation, &QPushButton::clicked,
1189 connect(qclient_options, SIGNAL(clicked()), parentWidget(),
1190 SLOT(popup_client_options()));
1191 for (level = 0; level < AI_LEVEL_COUNT; level++) {
1192 if (is_settable_ai_level(static_cast<ai_level>(level))) {
1194 static_cast<ai_level>(level));
1195 ailevel->addItem(level_name, level);
1196 }
1197 }
1198 ailevel->setCurrentIndex(-1);
1199
1200 connect(max_players, SIGNAL(valueChanged(int)),
1201 SLOT(max_players_change(int)));
1202 connect(ailevel, SIGNAL(currentIndexChanged(int)),
1203 SLOT(ailevel_change(int)));
1204 connect(cruleset, SIGNAL(currentIndexChanged(int)),
1205 SLOT(ruleset_change(int)));
1206
1207 but = new QPushButton;
1208 but->setText(_("More Game Options"));
1209 but->setIcon(fc_icons::instance()->get_icon("preferences-other"));
1210 QObject::connect(but, &QAbstractButton::clicked, this,
1212
1213 layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
1214 layout->addRow(_("Nation:"), nation);
1215 layout->addRow(_("Rules:"), cruleset);
1216
1217 hbox = new QHBoxLayout();
1218 hbox->addWidget(max_players);
1219 hbox->addWidget(ailevel);
1220 layout->addRow(_("Players:"), hbox);
1221 layout->addWidget(but);
1222 layout->addWidget(qclient_options);
1224
1226}
1227
1228/************************************************************************/
1232{
1233 int i;
1234 int def_idx = -1;
1235
1236 cruleset->clear();
1237 cruleset->blockSignals(true);
1238 for (i = 0; i < num_rulesets; i++) {
1239 cruleset->addItem(rulesets[i], i);
1240 if (!strcmp("default", rulesets[i])) {
1241 def_idx = i;
1242 }
1243 }
1244
1245 // HACK: server should tell us the current ruleset.
1246 cruleset->setCurrentIndex(def_idx);
1247 cruleset->blockSignals(false);
1248}
1249
1250/************************************************************************/
1255{
1256 max_players->blockSignals(true);
1257 max_players->setValue(aifill);
1258 max_players->blockSignals(false);
1259}
1260
1261/************************************************************************/
1265{
1266 struct sprite *psprite = nullptr;
1267 QPixmap *pixmap = nullptr;
1268 const struct player *pplayer = client_player();
1269
1270 // Update the "Select Nation" button
1271 if (pplayer != nullptr) {
1272 if (pplayer->nation != nullptr) {
1273 // Defeat keyboard shortcut mnemonics
1274 nation->setText(QString(nation_adjective_for_player(pplayer))
1275 .replace("&", "&&"));
1277 pixmap = psprite->pm;
1278 nation->setIconSize(pixmap->size());
1279 nation->setIcon(QIcon(*pixmap));
1280 } else {
1281 nation->setText(_("Random"));
1282 nation->setIcon(fc_icons::instance()->get_icon("flush-random"));
1283 }
1284 }
1285}
1286
1287/************************************************************************/
1291{
1292 enum ai_level level = server_ai_level();
1293
1294 if (ai_level_is_valid(level)) {
1295 int i = ailevel->findData(level);
1296
1297 ailevel->setCurrentIndex(i);
1298 } else {
1299 ailevel->setCurrentIndex(-1);
1300 }
1301}
1302
1303/************************************************************************/
1310
1311/************************************************************************/
1315{
1316 QVariant v = ailevel->currentData();
1317
1318 if (v.isValid()) {
1319 enum ai_level k = static_cast<ai_level>(v.toInt());
1320
1321 // Suppress changes provoked by server rather than local user
1322 if (server_ai_level() != k) {
1323 const char *name = ai_level_cmd(k);
1324
1325 send_chat_printf("/%s", name);
1326 }
1327 }
1328}
1329
1330/************************************************************************/
1334{
1335 if (!cruleset->currentText().isEmpty()) {
1337
1338 rn_bytes = cruleset->currentText().toUtf8();
1339 set_ruleset(rn_bytes.data());
1340 }
1341}
1342
1343/************************************************************************/
1350
1351/************************************************************************/
1355{
1356 option_dialog_popup(_("Set server options"), server_optset, false);
1357}
#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:572
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:503
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:2160
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:456
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:651
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:271
QPushButton * obs_button
Definition fc_client.h:195
void update_info_label()
Definition mapview.cpp:999
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:1025
void create_cursors(void)
void switch_page(int i)
void create_network_page()
Definition pages.cpp:308
QTreeWidget * start_players_tree
Definition fc_client.h:210
bool chat_active_on_page(enum client_pages)
void create_load_page()
Definition pages.cpp:500
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:488
void update_fonts()
void update_network_lists()
Definition pages.cpp:1055
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:1440
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:584
void remove_server_source()
void update_scenarios_page(void)
Definition pages.cpp:1471
void create_game_page()
Definition pages.cpp:735
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:570
QList< fc_sidewidget * > objects
Definition sidebar.h:121
void update_fonts()
Definition sidebar.cpp:612
void update_final_pixmap()
Definition sidebar.cpp:393
void set_scale(float s)
void update_actions(unit_list *punits)
void restore_chat()
chatwdg * chtwdg
Definition messagewin.h:79
void reset()
Definition mapview.cpp:731
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:4834
void create_pixmap()
Definition dialogs.cpp:4533
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:76
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:64
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:61
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:2350
void overview_size_changed(void)
Definition mapview.c:326
void option_dialog_popup(const char *name, const struct option_set *poptset)
Definition optiondlg.c:972
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
void side_disable_endturn(bool do_restore)
Definition sidebar.cpp:676
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:4278
const struct option_set * client_optset
Definition options.c:1316
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:467
bool option_int_set(struct option *poption, int val)
Definition options.c:914
#define MAJOR_NEW_OPTION_FILE_NAME
Definition options.h:38
#define MINOR_NEW_OPTION_FILE_NAME
Definition options.h:42
int dsend_packet_player_ready(struct connection *pc, int player_no, bool is_ready)
bool is_settable_ai_level(enum ai_level level)
Definition player.c:1925
int player_number(const struct player *pplayer)
Definition player.c:837
#define ai_level_cmd(_level_)
Definition player.h:572
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:2506
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
bool gui_qt_fullscreen
Definition options.h:442
bool gui_qt_allied_chat_only
Definition options.h:444
bool gui_qt_show_titlebar
Definition options.h:455
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:6819
struct sprite * get_nation_shield_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6989
struct sprite * get_cursor_sprite(const struct tileset *t, enum cursor_type cursor, int *hot_x, int *hot_y, int frame)
Definition tilespec.c:7184
#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)