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 <QShortcut>
29#include <QSocketNotifier>
30#include <QSpinBox>
31#include <QStackedLayout>
32#include <QStandardPaths>
33#include <QStatusBar>
34#include <QStyleFactory>
35#include <QTabBar>
36#include <QTextBlock>
37#include <QTextEdit>
38
39// common
40#include "game.h"
41
42// client
43#include "connectdlg_common.h"
44
45// gui-qt
46#include "fc_client.h"
47#include "fonts.h"
48#include "gui_main.h"
49#include "optiondlg.h"
50#include "sidebar.h"
51#include "sprite.h"
52
55extern "C" {
57}
58extern void write_shortcuts();
59
61
62/************************************************************************/
65fc_client::fc_client() : QMainWindow()
66{
68
76 main_wdg = nullptr;
77 connect_lan = nullptr;
78 connect_metaserver = nullptr;
79 central_layout = nullptr;
80 output_window = nullptr;
81 scenarios_view = nullptr;
82 connect_host_edit = nullptr;
83 connect_port_edit = nullptr;
84 connect_login_edit = nullptr;
85 connect_password_edit = nullptr;
87 button = nullptr;
88 button_box = nullptr;
89 server_notifier = nullptr;
90 chat_line = nullptr;
91 lan_widget = nullptr;
92 wan_widget = nullptr;
93 info_widget = nullptr;
94 saves_load = nullptr;
95 scenarios_load = nullptr;
96 meta_scan_timer = nullptr;
97 lan_scan_timer = nullptr;
98 status_bar = nullptr;
99 status_bar_label = nullptr;
100 menu_bar = nullptr;
101 mapview_wdg = nullptr;
102 sidebar_wdg = nullptr;
103 msgwdg = nullptr;
104 infotab = nullptr;
105 central_wdg = nullptr;
106 game_tab_widget = nullptr;
107 start_players_tree = nullptr;
108 unit_sel = nullptr;
109 info_tile_wdg = nullptr;
110 opened_dialog = nullptr;
111 current_file = "";
112 status_bar_queue.clear();
113 quitting = false;
114 pre_vote = nullptr;
115 x_vote = nullptr;
116 gtd = nullptr;
117 update_info_timer = nullptr;
118 unitinfo_wdg = nullptr;
119 battlelog_wdg = nullptr;
120 interface_locked = false;
121 map_scale = 1.0f;
122 map_font_scale = true;
123 for (int i = 0; i <= PAGE_GAME; i++) {
124 pages_layout[i] = nullptr;
125 pages[i] = nullptr;
126 }
127
128 wtitle = _("Freeciv (%1)");
129 wtitle = wtitle.arg(
131 "Qt6x"
132#else // FC_QT6X_MODE
133 "Qt6"
134#endif // FC_QT6X_MODE
135 );
136
138
139 init();
140}
141
142/************************************************************************/
146{
149 QApplication::setFont(*fc_font::instance()->get_font(fonts::default_font));
150 QString path;
151 central_wdg = new QWidget;
153
154 // General part not related to any single page
155 menu_bar = new mr_menu();
157 corner_wid = new fc_corner(this);
158 menu_bar->setCornerWidget(corner_wid);
159 }
162 status_bar_label = new QLabel;
163 status_bar_label->setAlignment(Qt::AlignCenter);
164 status_bar->addWidget(status_bar_label, 1);
165 set_status_bar(_("Welcome to Freeciv"));
167
168 // PAGE_MAIN
169 pages[PAGE_MAIN] = new QWidget(central_wdg);
170 page = PAGE_MAIN;
172
173 // PAGE_START
174 pages[PAGE_START] = new QWidget(central_wdg);
176
177 // PAGE_SCENARIO
178 pages[PAGE_SCENARIO] = new QWidget(central_wdg);
180
181 // PAGE_LOAD
182 pages[PAGE_LOAD] = new QWidget(central_wdg);
184
185 // PAGE_NETWORK
186 pages[PAGE_NETWORK] = new QWidget(central_wdg);
188 pages[PAGE_NETWORK]->setVisible(false);
189
190 // PAGE_GAME
192 path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
193 if (!path.isEmpty()) {
194 QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, path);
195 }
196 pages[PAGE_GAME] = new QWidget(central_wdg);
199
200 pages[PAGE_GAME + 1] = new QWidget(central_wdg);
202
203 pages_layout[PAGE_GAME]->setContentsMargins(0, 0, 0, 0);
204
211 pages[PAGE_GAME + 1]->setLayout(pages_layout[PAGE_GAME + 1]);
212
213 central_layout->addWidget(pages[PAGE_MAIN]);
214 central_layout->addWidget(pages[PAGE_NETWORK]);
215 central_layout->addWidget(pages[PAGE_LOAD]);
217 central_layout->addWidget(pages[PAGE_START]);
218 central_layout->addWidget(pages[PAGE_GAME]);
219 central_layout->addWidget(pages[PAGE_GAME + 1]);
220
221 central_wdg->setLayout(central_layout);
223
224 resize(pages[PAGE_MAIN]->minimumSizeHint());
225 setVisible(true);
226
229
230 QPixmapCache::setCacheLimit(80000);
231}
232
233/************************************************************************/
237{
238 status_bar_queue.clear();
239 if (fc_shortcuts::sc()) {
240 delete fc_shortcuts::sc();
241 }
243}
244
245
246/************************************************************************/
253{
254 QShortcut *quit_shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this);
255
256 qRegisterMetaType<QTextCursor>("QTextCursor");
257 qRegisterMetaType<QTextBlock>("QTextBlock");
259 real_output_window_append(_("This is Qt-client for Freeciv."), nullptr, -1);
262
264
266 connect(quit_shortcut, &QShortcut::activated, this, &fc_client::quit);
267 connect(qapp, &QCoreApplication::aboutToQuit, this, &fc_client::closing);
268 qapp->exec();
269
272}
273
274/************************************************************************/
278{
279 return quitting;
280}
281
282/************************************************************************/
286{
287 quitting = true;
288}
289
290/************************************************************************/
297
298/************************************************************************/
302 const struct text_tag_list *tags)
303{
304 QTextCursor cursor;
305 QColor col = output_window->palette().color(QPalette::Text);
306 QString str = apply_tags(message, tags, col);
307
308 if (output_window != nullptr) {
309 output_window->append(str);
310 output_window->verticalScrollBar()->setSliderPosition(
311 output_window->verticalScrollBar()->maximum());
312 }
313}
314
315/************************************************************************/
319{
320 if (check == PAGE_START || check == PAGE_GAME) {
321 return true;
322 }
323
324 return false;
325}
326
327/************************************************************************/
334{
335 char buf[256];
337 int i_page;
338
339 new_page = static_cast<client_pages>(new_pg);
340
342 && !is_server_running()) {
343 current_file = "";
345 return;
346 }
347
348 if (page == PAGE_NETWORK) {
350 }
351 menuBar()->setVisible(false);
352 if (status_bar != nullptr) {
353 status_bar->setVisible(true);
354 }
355 QApplication::alert(gui()->central_wdg);
356 central_layout->setCurrentWidget(pages[new_pg]);
357 page = new_page;
359 switch (i_page) {
360 case PAGE_MAIN:
361 break;
362 case PAGE_START:
363 pre_vote->hide();
365 break;
366 case PAGE_LOAD:
368 break;
369 case PAGE_GAME:
371 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
372 }
374 // For MS Windows, it might ignore first
377 status_bar->setVisible(false);
378
381 }
382
383 menuBar()->setVisible(true);
384 mapview_wdg->setFocus();
393 break;
394 case PAGE_SCENARIO:
396 break;
397 case PAGE_NETWORK:
401 fc_snprintf(buf, sizeof(buf), "%d", server_port);
402 connect_port_edit->setText(buf);
404 connect_password_edit->setDisabled(true);
405 connect_confirm_password_edit->setDisabled(true);
406 break;
407 case (PAGE_GAME + 1):
408 break;
409 default:
410 if (client.conn.used) {
412 }
414 break;
415 }
416}
417
418/************************************************************************/
422{
424 gui()->showFullScreen();
425 gui()->game_tab_widget->showFullScreen();
426 } else {
427 // FIXME: Doesn't return properly, probably something with sidebar
428 gui()->showNormal();
429 gui()->game_tab_widget->showNormal();
430 }
431}
432
433/************************************************************************/
437{
438 return page;
439}
440
441/************************************************************************/
445{
446 server_notifier = new QSocketNotifier(sock, QSocketNotifier::Read);
447
448 connect(server_notifier, &QSocketNotifier::activated, this,
450}
451
452/************************************************************************/
459
460/************************************************************************/
464{
465 if (event->type() == QEvent::User) {
467 dynamic_cast<version_message_event&>(*event);
468 set_status_bar(vmevt.get_message());
469 return true;
470 } else {
471 return QMainWindow::event(event);
472 }
473}
474
475/************************************************************************/
479{
480 if (!is_client_quitting()) {
482 event->ignore();
483 }
484}
485
486/************************************************************************/
490{
491 server_notifier->deleteLater();
492}
493
494/************************************************************************/
498{
499 server_notifier->setEnabled(false);
500 input_from_server(sock);
501 server_notifier->setEnabled(true);
502}
503
504/************************************************************************/
508{
509 // Prevent current timer from repeating with possibly wrong interval
510 killTimer(event->timerId());
511
512 // Call timer callback in client common code and
513 // start new timer with correct interval
515}
516
517/************************************************************************/
521{
523
524 if (qapp != nullptr) {
525 qapp->quit();
526 }
527}
528
529/************************************************************************/
540
541/************************************************************************/
545{
547 if (game.info.is_new_game) {
548 send_chat("/take -");
549 } else {
550 send_chat("/detach");
551 }
552 obs_button->setText(_("Don't Observe"));
553 } else {
554 send_chat("/observe");
555 obs_button->setText(_("Observe"));
556 }
557}
558
559/************************************************************************/
572
573/****************************************************************************
574 Deletes cursors
575****************************************************************************/
577{
578 int frame;
579 int cursor;
580
581 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
582 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
583 delete fc_cursors[cursor][frame];
584 }
585 }
586}
587
588
589/************************************************************************/
593{
594 QString x;
595
597
598 if (x.isEmpty()) {
599 opened_repo_dlgs.insert(str, widget);
600 return;
601 }
602 log_error("Failed to find place for new tab widget");
603 return;
604}
605
606/************************************************************************/
612{
613 QWidget *w;
614
615 w = opened_repo_dlgs.value(str);
616
617 if (w == nullptr) {
618 return false;
619 }
620
621 return true;
622}
623
624/************************************************************************/
628{
629 int i;
630 QWidget *w;
631
632 if (str == "MAP") {
633 return 0;
634 }
635
636 w = opened_repo_dlgs.value(str);
637 i = game_tab_widget->indexOf(w);
638 return i;
639}
640
641/************************************************************************/
645{
646 // This can't be shared between freeciv versions as the content
647 // might be incompatible.
648 QString sname = "freeciv-qt-client-set-"
649 + QString::number(MAJOR_NEW_OPTION_FILE_NAME) + "."
650 + QString::number(MINOR_NEW_OPTION_FILE_NAME);
651 QSettings s(QSettings::IniFormat, QSettings::UserScope,
652 sname);
653
654 if (s.contains("Chat-fx-size")) {
655 qt_settings.chat_fwidth = s.value("Chat-fx-size").toFloat();
656 } else {
658 }
659 if (s.contains("Chat-fy-size")) {
660 qt_settings.chat_fheight = s.value("Chat-fy-size").toFloat();
661 } else {
663 }
664 if (s.contains("Chat-fx-pos")) {
665 qt_settings.chat_fx_pos = s.value("Chat-fx-pos").toFloat();
666 } else {
668 }
669 if (s.contains("Chat-fy-pos")) {
670 qt_settings.chat_fy_pos = s.value("Chat-fy-pos").toFloat();
671 } else {
673 }
674 if (s.contains("unit_fx")) {
675 qt_settings.unit_info_pos_fx = s.value("unit_fx").toFloat();
676 } else {
678 }
679 if (s.contains("unit_fy")) {
680 qt_settings.unit_info_pos_fy = s.value("unit_fy").toFloat();
681 } else {
683 }
684 if (s.contains("minimap_x")) {
685 qt_settings.minimap_x = s.value("minimap_x").toFloat();
686 } else {
687 qt_settings.minimap_x = 0.84;
688 }
689 if (s.contains("minimap_y")) {
690 qt_settings.minimap_y = s.value("minimap_y").toFloat();
691 } else {
692 qt_settings.minimap_y = 0.79;
693 }
694 if (s.contains("minimap_width")) {
695 qt_settings.minimap_width = s.value("minimap_width").toFloat();
696 } else {
698 }
699 if (s.contains("minimap_height")) {
700 qt_settings.minimap_height = s.value("minimap_height").toFloat();
701 } else {
703 }
704 if (s.contains("battlelog_scale")) {
705 qt_settings.battlelog_scale = s.value("battlelog_scale").toFloat();
706 } else {
708 }
709
710 if (s.contains("City-dialog")) {
711 qt_settings.city_geometry = s.value("City-dialog").toByteArray();
712 }
713 if (s.contains("splitter1")) {
714 qt_settings.city_splitter1 = s.value("splitter1").toByteArray();
715 }
716 if (s.contains("splitter2")) {
717 qt_settings.city_splitter2 = s.value("splitter2").toByteArray();
718 }
719 if (s.contains("splitter3")) {
720 qt_settings.city_splitter3 = s.value("splitter3").toByteArray();
721 }
722 if (s.contains("help-dialog")) {
723 qt_settings.help_geometry = s.value("help-dialog").toByteArray();
724 }
725 if (s.contains("help_splitter1")) {
726 qt_settings.help_splitter1 = s.value("help_splitter1").toByteArray();
727 }
728 if (s.contains("opt-client-dialog")) {
729 qt_settings.options_client_geometry = s.value("opt-client-dialog").toByteArray();
730 }
731 if (s.contains("opt-server-dialog")) {
732 qt_settings.options_server_geometry = s.value("opt-server-dialog").toByteArray();
733 }
734 if (s.contains("new_turn_text")) {
735 qt_settings.show_new_turn_text = s.value("new_turn_text").toBool();
736 } else {
738 }
739 if (s.contains("show_battle_log")) {
740 qt_settings.show_battle_log = s.value("show_battle_log").toBool();
741 } else {
743 }
744 if (s.contains("battlelog_x")) {
745 qt_settings.battlelog_x = s.value("battlelog_x").toFloat();
746 } else {
748 }
749 if (s.contains("minimap_y")) {
750 qt_settings.battlelog_y = s.value("battlelog_y").toFloat();
751 } else {
753 }
755
756 if (s.contains("city_repo_columns")) {
757 qt_settings.city_repo_columns = s.value("city_repo_columns").toByteArray();
758 } else {
760 }
761
764 }
767 }
768 if (qt_settings.chat_fwidth < 0.05 || qt_settings.chat_fwidth > 0.9) {
770 }
771 if (qt_settings.chat_fheight < 0.05 || qt_settings.chat_fheight > 0.9) {
773 }
774 if (qt_settings.battlelog_x < 0.0) {
776 }
777 if (qt_settings.battlelog_y < 0.0) {
779 }
780 if (qt_settings.battlelog_scale > 5.0) {
782 }
785 }
788 }
789}
790
791/************************************************************************/
795{
796 QString sname = "freeciv-qt-client-set-"
797 + QString::number(MAJOR_NEW_OPTION_FILE_NAME) + "."
798 + QString::number(MINOR_NEW_OPTION_FILE_NAME);
799 QSettings s(QSettings::IniFormat, QSettings::UserScope,
800 sname);
801
802 s.setValue("Chat-fx-size", qt_settings.chat_fwidth);
803 s.setValue("Chat-fy-size", qt_settings.chat_fheight);
804 s.setValue("Chat-fx-pos", qt_settings.chat_fx_pos);
805 s.setValue("Chat-fy-pos", qt_settings.chat_fy_pos);
806 s.setValue("City-dialog", qt_settings.city_geometry);
807 s.setValue("splitter1", qt_settings.city_splitter1);
808 s.setValue("splitter2", qt_settings.city_splitter2);
809 s.setValue("splitter3", qt_settings.city_splitter3);
810 s.setValue("help-dialog", qt_settings.help_geometry);
811 s.setValue("help_splitter1", qt_settings.help_splitter1);
812 s.setValue("opt-client-dialog", qt_settings.options_client_geometry);
813 s.setValue("opt-server-dialog", qt_settings.options_server_geometry);
814 s.setValue("unit_fx", qt_settings.unit_info_pos_fx);
815 s.setValue("unit_fy", qt_settings.unit_info_pos_fy);
816 s.setValue("minimap_x", qt_settings.minimap_x);
817 s.setValue("minimap_y", qt_settings.minimap_y);
818 s.setValue("minimap_width", qt_settings.minimap_width);
819 s.setValue("minimap_height", qt_settings.minimap_height);
820 s.setValue("battlelog_scale", qt_settings.battlelog_scale);
821 s.setValue("battlelog_x", qt_settings.battlelog_x);
822 s.setValue("battlelog_y", qt_settings.battlelog_y);
823 s.setValue("new_turn_text", qt_settings.show_new_turn_text);
824 s.setValue("show_battle_log", qt_settings.show_battle_log);
825 s.setValue("city_repo_columns", qt_settings.city_repo_columns);
827}
828
829/************************************************************************/
833{
834 if (unit_sel != nullptr) {
835 unit_sel->close();
836 delete unit_sel;
837 unit_sel = new units_select(ptile, gui()->mapview_wdg);
838 unit_sel->show();
839 } else {
840 unit_sel = new units_select(ptile, gui()->mapview_wdg);
841 unit_sel->show();
842 }
843}
844
845/************************************************************************/
849{
850 if (unit_sel != nullptr) {
853 unit_sel->update();
854 }
855}
856
857/************************************************************************/
861{
862 if (unit_sel != nullptr) {
863 unit_sel->close();
864 delete unit_sel;
865 unit_sel = nullptr;
866 }
867}
868
869/************************************************************************/
873{
874 // If app is closing, opened_repo_dlg is already deleted */
875 if (!is_closing()) {
876 opened_repo_dlgs.remove(str);
877 }
878}
879
880/************************************************************************/
884{
885 option_dialog_popup(_("Set local options"), client_optset, true);
886}
887
888/************************************************************************/
892{
893 enum cursor_type curs;
894 int cursor;
895 QPixmap *pix;
896 int hot_x, hot_y;
897 struct sprite *sprite;
898 int frame;
899 QCursor *c;
900 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
901 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
902 curs = static_cast<cursor_type>(cursor);
903 sprite = get_cursor_sprite(tileset, curs, &hot_x, &hot_y, frame);
904 pix = sprite->pm;
905 c = new QCursor(*pix, hot_x, hot_y);
906 fc_cursors[cursor][frame] = c;
907 }
908 }
909}
910
911/************************************************************************/
914fc_corner::fc_corner(QMainWindow *qmw): QWidget()
915{
917 QPushButton *qpb;
918 int h;
920
921 if (f->pointSize() > 0) {
922 h = f->pointSize();
923 } else {
924 h = f->pixelSize();
925 }
926 mw = qmw;
927 hb = new QHBoxLayout();
928 qpb = new QPushButton(fc_icons::instance()->get_icon("cmin"), "");
929 qpb->setFixedSize(h, h);
930 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::minimize);
931 hb->addWidget(qpb);
932 qpb = new QPushButton(fc_icons::instance()->get_icon("cmax"), "");
933 qpb->setFixedSize(h, h);
934 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::maximize);
935 hb->addWidget(qpb);
936 qpb = new QPushButton(fc_icons::instance()->get_icon("cclose"), "");
937 qpb->setFixedSize(h, h);
938 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::close_fc);
939 hb->addWidget(qpb);
940 setLayout(hb);
941}
942
943/************************************************************************/
947{
948 mw->close();
949}
950
951/************************************************************************/
955{
956 if (!mw->isMaximized()) {
957 mw->showMaximized();
958 } else {
959 mw->showNormal();
960 }
961}
962
963/************************************************************************/
967{
968 mw->showMinimized();
969}
970
971/************************************************************************/
975{
976}
977
978/************************************************************************/
982{
983 connect(this, &QStackedWidget::currentChanged, this, &fc_game_tab_widget::current_changed);
984}
985
986/************************************************************************/
992
993/************************************************************************/
997{
998 if (!m_instance) {
999 m_instance = new fc_icons;
1000 }
1001 return m_instance;
1002}
1003
1004/************************************************************************/
1008{
1009 if (m_instance) {
1010 delete m_instance;
1011 m_instance = 0;
1012 }
1013}
1014
1015/************************************************************************/
1019{
1020 QIcon icon;
1021 QString str;
1024
1025 str = QString("themes") + DIR_SEPARATOR + "gui-qt" + DIR_SEPARATOR;
1026 // Try custom icon from theme
1027 pn_bytes = str.toUtf8();
1029 + id + ".png").toUtf8();
1030 icon.addFile(fileinfoname(get_data_dirs(),
1031 png_bytes.data()));
1032 str = str + "icons" + DIR_SEPARATOR;
1033 // Try icon from icons dir
1034 if (icon.isNull()) {
1035 pn_bytes = str.toUtf8();
1036 png_bytes = QString(pn_bytes.data() + id + ".png").toUtf8();
1037 icon.addFile(fileinfoname(get_data_dirs(),
1038 png_bytes.data()));
1039 }
1040
1041 return QIcon(icon);
1042}
1043
1044/************************************************************************/
1048{
1049 QPixmap *pm;
1050 bool status;
1051 QString str;
1053
1054 pm = new QPixmap;
1055 if (QPixmapCache::find(id, pm)) {
1056 return pm;
1057 }
1058 str = QString("themes") + DIR_SEPARATOR + "gui-qt" + DIR_SEPARATOR;
1060 + id + ".png").toUtf8();
1061 status = pm->load(fileinfoname(get_data_dirs(),
1062 png_bytes.data()));
1063
1064 if (!status) {
1065 str = str + "icons" + DIR_SEPARATOR;
1066 png_bytes = QString(str + id + ".png").toUtf8();
1067 pm->load(fileinfoname(get_data_dirs(), png_bytes.data()));
1068 }
1069 QPixmapCache::insert(id, *pm);
1070
1071 return pm;
1072}
1073
1074/************************************************************************/
1078{
1079 QString str;
1081
1082 str = QString("themes") + DIR_SEPARATOR + "gui-qt"
1083 + DIR_SEPARATOR + "icons" + DIR_SEPARATOR;
1084 png_bytes = QString(str + id + ".png").toUtf8();
1085
1086 return fileinfoname(get_data_dirs(),
1087 png_bytes.data());
1088}
1089
1090/************************************************************************/
1094{
1095 QSize size;
1096
1097 size = event->size();
1098 if (C_S_RUNNING <= client_state()) {
1099 gui()->sidebar_wdg->resize_me(size.height());
1100 map_canvas_resized(size.width(), size.height());
1101 gui()->infotab->resize(qRound((size.width()
1102 * gui()->qt_settings.chat_fwidth)),
1103 qRound((size.height()
1104 * gui()->qt_settings.chat_fheight)));
1105 gui()->infotab->move(qRound((size.width()
1106 * gui()->qt_settings.chat_fx_pos)),
1107 qRound((size.height()
1108 * gui()->qt_settings.chat_fy_pos)));
1109 gui()->infotab->restore_chat();
1110 gui()->minimapview_wdg->move(qRound(gui()->qt_settings.minimap_x
1111 * mapview.width),
1112 qRound(gui()->qt_settings.minimap_y
1113 * mapview.height));
1114 gui()->minimapview_wdg->resize(qRound(gui()->qt_settings.minimap_width
1115 * mapview.width),
1116 qRound(gui()->qt_settings.minimap_height
1117 * mapview.height));
1118 gui()->battlelog_wdg->set_scale(gui()->qt_settings.battlelog_scale);
1119 gui()->battlelog_wdg->move(qRound(gui()->qt_settings.battlelog_x
1120 * mapview.width),
1121 qRound(gui()->qt_settings.battlelog_y
1122 * mapview.height));
1123 gui()->x_vote->move(width() / 2 - gui()->x_vote->width() / 2, 0);
1126 gui()->mapview_wdg->resize(event->size().width(),size.height());
1127 gui()->unitinfo_wdg->update_actions(nullptr);
1128 }
1129 event->setAccepted(true);
1130}
1131
1132/************************************************************************/
1136{
1138 fc_sidewidget *sw;
1139
1140 if (gui()->is_closing()) {
1141 return;
1142 }
1144
1145 foreach(sw, objs) {
1146 sw->update_final_pixmap();
1147 }
1148 currentWidget()->hide();
1149 widget(index)->show();
1150
1151 // Set focus to map instead sidebar
1152 if (gui()->mapview_wdg && gui()->current_page() == PAGE_GAME
1153 && index == 0) {
1154 gui()->mapview_wdg->setFocus();
1155 }
1156
1157}
1158
1159/************************************************************************/
1163{
1164}
1165
1166/************************************************************************/
1170{
1172 QPushButton *qclient_options;
1173 QHBoxLayout *hbox = nullptr;
1174 QPushButton *but;
1175 int level;
1176
1177 layout = new QFormLayout(this);
1178 nation = new QPushButton(this);
1179 qclient_options = new QPushButton(_("Client Options"));
1180 max_players = new QSpinBox(this);
1181 ailevel = new QComboBox(this);
1182 cruleset = new QComboBox(this);
1183 max_players->setRange(1, MAX_NUM_PLAYERS);
1184
1185 // Text and icon set by update_buttons()
1186 connect(nation, &QPushButton::clicked,
1188 connect(qclient_options, SIGNAL(clicked()), parentWidget(),
1189 SLOT(popup_client_options()));
1190 for (level = 0; level < AI_LEVEL_COUNT; level++) {
1191 if (is_settable_ai_level(static_cast<ai_level>(level))) {
1193 static_cast<ai_level>(level));
1194 ailevel->addItem(level_name, level);
1195 }
1196 }
1197 ailevel->setCurrentIndex(-1);
1198
1199 connect(max_players, SIGNAL(valueChanged(int)),
1200 SLOT(max_players_change(int)));
1201 connect(ailevel, SIGNAL(currentIndexChanged(int)),
1202 SLOT(ailevel_change(int)));
1203 connect(cruleset, SIGNAL(currentIndexChanged(int)),
1204 SLOT(ruleset_change(int)));
1205
1206 but = new QPushButton;
1207 but->setText(_("More Game Options"));
1208 but->setIcon(fc_icons::instance()->get_icon("preferences-other"));
1209 QObject::connect(but, &QAbstractButton::clicked, this,
1211
1212 layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
1213 layout->addRow(_("Nation:"), nation);
1214 layout->addRow(_("Rules:"), cruleset);
1215
1216 hbox = new QHBoxLayout();
1217 hbox->addWidget(max_players);
1218 hbox->addWidget(ailevel);
1219 layout->addRow(_("Players:"), hbox);
1220 layout->addWidget(but);
1221 layout->addWidget(qclient_options);
1223
1225}
1226
1227/************************************************************************/
1231{
1232 int i;
1233 int def_idx = -1;
1234
1235 cruleset->clear();
1236 cruleset->blockSignals(true);
1237 for (i = 0; i < num_rulesets; i++) {
1238 cruleset->addItem(rulesets[i], i);
1239 if (!strcmp("default", rulesets[i])) {
1240 def_idx = i;
1241 }
1242 }
1243
1244 // HACK: server should tell us the current ruleset.
1245 cruleset->setCurrentIndex(def_idx);
1246 cruleset->blockSignals(false);
1247}
1248
1249/************************************************************************/
1254{
1255 max_players->blockSignals(true);
1256 max_players->setValue(aifill);
1257 max_players->blockSignals(false);
1258}
1259
1260/************************************************************************/
1264{
1265 struct sprite *psprite = nullptr;
1266 QPixmap *pixmap = nullptr;
1267 const struct player *pplayer = client_player();
1268
1269 // Update the "Select Nation" button
1270 if (pplayer != nullptr) {
1271 if (pplayer->nation != nullptr) {
1272 // Defeat keyboard shortcut mnemonics
1273 nation->setText(QString(nation_adjective_for_player(pplayer))
1274 .replace("&", "&&"));
1276 pixmap = psprite->pm;
1277 nation->setIconSize(pixmap->size());
1278 nation->setIcon(QIcon(*pixmap));
1279 } else {
1280 nation->setText(_("Random"));
1281 nation->setIcon(fc_icons::instance()->get_icon("flush-random"));
1282 }
1283 }
1284}
1285
1286/************************************************************************/
1290{
1291 enum ai_level level = server_ai_level();
1292
1293 if (ai_level_is_valid(level)) {
1294 int i = ailevel->findData(level);
1295
1296 ailevel->setCurrentIndex(i);
1297 } else {
1298 ailevel->setCurrentIndex(-1);
1299 }
1300}
1301
1302/************************************************************************/
1309
1310/************************************************************************/
1314{
1315 QVariant v = ailevel->currentData();
1316
1317 if (v.isValid()) {
1318 enum ai_level k = static_cast<ai_level>(v.toInt());
1319
1320 // Suppress changes provoked by server rather than local user
1321 if (server_ai_level() != k) {
1322 const char *name = ai_level_cmd(k);
1323
1324 send_chat_printf("/%s", name);
1325 }
1326 }
1327}
1328
1329/************************************************************************/
1333{
1334 if (!cruleset->currentText().isEmpty()) {
1336
1337 rn_bytes = cruleset->currentText().toUtf8();
1338 set_ruleset(rn_bytes.data());
1339 }
1340}
1341
1342/************************************************************************/
1349
1350/************************************************************************/
1354{
1355 option_dialog_popup(_("Set server options"), server_optset, false);
1356}
#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:258
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:217
QStringList status_bar_queue
Definition fc_client.h:351
QSocketNotifier * server_notifier
Definition fc_client.h:200
QLineEdit * connect_host_edit
Definition fc_client.h:187
void popdown_unit_sel()
QTextEdit * output_window
Definition fc_client.h:180
bool interface_locked
Definition fc_client.h:272
void init()
void update_sidebar_tooltips()
Definition pages.cpp:2153
fc_settings qt_settings
Definition fc_client.h:267
goto_dialog * gtd
Definition fc_client.h:264
mr_menu * menu_bar
Definition fc_client.h:256
bool quitting
Definition fc_client.h:354
QTimer * meta_scan_timer
Definition fc_client.h:211
hud_battle_log * battlelog_wdg
Definition fc_client.h:271
void closing()
QWidget * connect_lan
Definition fc_client.h:173
QTableWidget * lan_widget
Definition fc_client.h:204
QWidget * connect_metaserver
Definition fc_client.h:174
QLineEdit * connect_confirm_password_edit
Definition fc_client.h:191
chat_input * chat_line
Definition fc_client.h:202
hud_units * unitinfo_wdg
Definition fc_client.h:270
bool map_font_scale
Definition fc_client.h:279
choice_dialog * opened_dialog
Definition fc_client.h:218
pregamevote * pre_vote
Definition fc_client.h:261
QTableWidget * saves_load
Definition fc_client.h:207
void read_settings()
messagewdg * msgwdg
Definition fc_client.h:259
void set_status_bar(QString str, int timeout=2000)
Definition pages.cpp:451
QPushButton * button
Definition fc_client.h:193
bool is_repo_dlg_open(QString str)
void server_input(int sock)
enum client_pages page
Definition fc_client.h:349
enum client_pages current_page()
units_select * unit_sel
Definition fc_client.h:262
QLineEdit * connect_password_edit
Definition fc_client.h:190
void quit()
minimap_view * minimapview_wdg
Definition fc_client.h:231
QStatusBar * status_bar
Definition fc_client.h:215
QTableWidget * wan_widget
Definition fc_client.h:205
void gimme_place(QWidget *widget, QString str)
QCursor * fc_cursors[CURSOR_LAST][NUM_CURSOR_FRAMES]
Definition fc_client.h:265
map_view * mapview_wdg
Definition fc_client.h:229
void delete_cursors(void)
QStackedLayout * central_layout
Definition fc_client.h:178
void write_settings()
info_tab * infotab
Definition fc_client.h:260
void create_start_page()
Definition pages.cpp:647
void slot_disconnect()
QWidget * pages[(int) PAGE_GAME+2]
Definition fc_client.h:172
void slot_pregame_observe()
QTableWidget * info_widget
Definition fc_client.h:206
void set_connection_state(enum connection_state state)
Definition pages.cpp:266
QPushButton * obs_button
Definition fc_client.h:194
void update_info_label()
Definition mapview.cpp:1000
QLabel * status_bar_label
Definition fc_client.h:216
QGridLayout * pages_layout[PAGE_GAME+2]
Definition fc_client.h:177
QWidget * main_wdg
Definition fc_client.h:171
QLineEdit * connect_login_edit
Definition fc_client.h:189
void add_server_source(int)
QTextEdit * scenarios_view
Definition fc_client.h:181
QDialogButtonBox * button_box
Definition fc_client.h:198
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:209
bool chat_active_on_page(enum client_pages)
void create_load_page()
Definition pages.cpp:495
QTimer * lan_scan_timer
Definition fc_client.h:212
QLineEdit * connect_port_edit
Definition fc_client.h:188
fc_sidebar * sidebar_wdg
Definition fc_client.h:230
void create_main_page()
Definition pages.cpp:138
bool event(QEvent *event)
float map_scale
Definition fc_client.h:278
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:255
void fc_main(QApplication *qapp)
QMap< QString, QWidget * > opened_repo_dlgs
Definition fc_client.h:350
QString current_file
Definition fc_client.h:352
void closeEvent(QCloseEvent *event)
xvote * x_vote
Definition fc_client.h:263
void remove_repo_dlg(QString str)
void slot_pregame_start()
QTimer * update_info_timer
Definition fc_client.h:213
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:208
int gimme_index_of(QString str)
fc_corner * corner_wid
Definition fc_client.h:257
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:157
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:374
QComboBox * ailevel
Definition fc_client.h:372
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:373
pregame_options(QWidget *parent)
void ruleset_change(int i)
QSpinBox * max_players
Definition fc_client.h:375
void update_units()
Definition dialogs.cpp:4855
void create_pixmap()
Definition dialogs.cpp:4554
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:1524
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:60
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:2347
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:2552
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:134
QByteArray city_geometry
Definition fc_client.h:132
QByteArray help_geometry
Definition fc_client.h:136
float unit_info_pos_fx
Definition fc_client.h:140
QByteArray options_client_geometry
Definition fc_client.h:138
float unit_info_pos_fy
Definition fc_client.h:141
float chat_fwidth
Definition fc_client.h:123
float chat_fheight
Definition fc_client.h:124
QByteArray help_splitter1
Definition fc_client.h:137
float chat_fx_pos
Definition fc_client.h:125
float battlelog_scale
Definition fc_client.h:146
float battlelog_x
Definition fc_client.h:147
QByteArray city_splitter3
Definition fc_client.h:135
float minimap_x
Definition fc_client.h:142
float minimap_height
Definition fc_client.h:145
bool show_battle_log
Definition fc_client.h:129
float minimap_width
Definition fc_client.h:144
float battlelog_y
Definition fc_client.h:148
QByteArray options_server_geometry
Definition fc_client.h:139
QByteArray city_repo_columns
Definition fc_client.h:131
float chat_fy_pos
Definition fc_client.h:126
QByteArray city_splitter1
Definition fc_client.h:133
bool show_new_turn_text
Definition fc_client.h:128
float minimap_y
Definition fc_client.h:143
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:6845
struct sprite * get_nation_shield_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:7015
struct sprite * get_cursor_sprite(const struct tileset *t, enum cursor_type cursor, int *hot_x, int *hot_y, int frame)
Definition tilespec.c:7218
#define NUM_CURSOR_FRAMES
Definition tilespec.h:306
cursor_type
Definition tilespec.h:290
@ CURSOR_LAST
Definition tilespec.h:302
void client_start_server_and_set_page(enum client_pages page)
void set_client_page(enum client_pages page)