Freeciv-3.2
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" {
62}
63extern void write_shortcuts();
64
66
67/************************************************************************/
70fc_client::fc_client() : QMainWindow()
71{
73
74#ifdef FC_QT5_MODE
75 QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
76#endif // FC_QT5_MODE
84 main_wdg = NULL;
95 button = NULL;
108 menu_bar = NULL;
110 sidebar_wdg = nullptr;
111 msgwdg = NULL;
112 infotab = NULL;
116 unit_sel = NULL;
117 info_tile_wdg = nullptr;
119 current_file = "";
120 status_bar_queue.clear();
121 quitting = false;
122 pre_vote = NULL;
123 x_vote = NULL;
124 gtd = NULL;
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++) {
133 pages[i] = NULL;
134 }
135
136 wtitle = _("Freeciv (%1)");
137 wtitle = wtitle.arg(
138#if FC_QT5_MODE
139 "Qt5"
140#else // FC_QT5_MODE
141 "Qt6"
142#endif // FC_QT5_MODE
143 );
144
146
147 init();
148}
149
150/************************************************************************/
154{
157 QApplication::setFont(*fc_font::instance()->get_font(fonts::default_font));
158 QString path;
159 central_wdg = new QWidget;
161
162 // General part not related to any single page
163 menu_bar = new mr_menu();
165 corner_wid = new fc_corner(this);
166 menu_bar->setCornerWidget(corner_wid);
167 }
170 status_bar_label = new QLabel;
171 status_bar_label->setAlignment(Qt::AlignCenter);
172 status_bar->addWidget(status_bar_label, 1);
173 set_status_bar(_("Welcome to Freeciv"));
175
176 // PAGE_MAIN
177 pages[PAGE_MAIN] = new QWidget(central_wdg);
178 page = PAGE_MAIN;
180
181 // PAGE_START
182 pages[PAGE_START] = new QWidget(central_wdg);
184
185 // PAGE_SCENARIO
186 pages[PAGE_SCENARIO] = new QWidget(central_wdg);
188
189 // PAGE_LOAD
190 pages[PAGE_LOAD] = new QWidget(central_wdg);
192
193 // PAGE_NETWORK
194 pages[PAGE_NETWORK] = new QWidget(central_wdg);
196 pages[PAGE_NETWORK]->setVisible(false);
197
198 // PAGE_GAME
200 path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
201 if (!path.isEmpty()) {
202 QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, path);
203 }
204 pages[PAGE_GAME] = new QWidget(central_wdg);
207
208 pages[PAGE_GAME + 1] = new QWidget(central_wdg);
210
211 pages_layout[PAGE_GAME]->setContentsMargins(0, 0, 0, 0);
212
219 pages[PAGE_GAME + 1]->setLayout(pages_layout[PAGE_GAME + 1]);
220
221 central_layout->addWidget(pages[PAGE_MAIN]);
222 central_layout->addWidget(pages[PAGE_NETWORK]);
223 central_layout->addWidget(pages[PAGE_LOAD]);
225 central_layout->addWidget(pages[PAGE_START]);
226 central_layout->addWidget(pages[PAGE_GAME]);
227 central_layout->addWidget(pages[PAGE_GAME + 1]);
228
229 central_wdg->setLayout(central_layout);
231
232 resize(pages[PAGE_MAIN]->minimumSizeHint());
233 setVisible(true);
234
237
238 QPixmapCache::setCacheLimit(80000);
239}
240
241/************************************************************************/
245{
246 status_bar_queue.clear();
247 if (fc_shortcuts::sc()) {
248 delete fc_shortcuts::sc();
249 }
251}
252
253
254/************************************************************************/
261{
262 qRegisterMetaType<QTextCursor>("QTextCursor");
263 qRegisterMetaType<QTextBlock>("QTextBlock");
265 real_output_window_append(_("This is Qt-client for Freeciv."), NULL, -1);
268
270
272 connect(qapp, &QCoreApplication::aboutToQuit, this, &fc_client::closing);
273 qapp->exec();
274
277}
278
279/************************************************************************/
283{
284 return quitting;
285}
286
287/************************************************************************/
291{
292 quitting = true;
293}
294
295/************************************************************************/
302
303/************************************************************************/
307 const struct text_tag_list *tags)
308{
309 QTextCursor cursor;
310 QColor col = output_window->palette().color(QPalette::Text);
311 QString str = apply_tags(message, tags, col);
312
313 if (output_window != NULL) {
314 output_window->append(str);
315 output_window->verticalScrollBar()->setSliderPosition(
316 output_window->verticalScrollBar()->maximum());
317 }
318}
319
320/************************************************************************/
324{
325 if (check == PAGE_START || check == PAGE_GAME) {
326 return true;
327 }
328
329 return false;
330}
331
332/************************************************************************/
339{
340 char buf[256];
342 int i_page;
343
344 new_page = static_cast<client_pages>(new_pg);
345
347 && !is_server_running()) {
348 current_file = "";
350 return;
351 }
352
353 if (page == PAGE_NETWORK) {
355 }
356 menuBar()->setVisible(false);
357 if (status_bar != nullptr) {
358 status_bar->setVisible(true);
359 }
360 QApplication::alert(gui()->central_wdg);
361 central_layout->setCurrentWidget(pages[new_pg]);
362 page = new_page;
364 switch (i_page) {
365 case PAGE_MAIN:
366 break;
367 case PAGE_START:
368 pre_vote->hide();
370 break;
371 case PAGE_LOAD:
373 break;
374 case PAGE_GAME:
376 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
377 }
379 // For MS Windows, it might ignore first
382 status_bar->setVisible(false);
383
386 }
387
388 menuBar()->setVisible(true);
389 mapview_wdg->setFocus();
398 break;
399 case PAGE_SCENARIO:
401 break;
402 case PAGE_NETWORK:
406 fc_snprintf(buf, sizeof(buf), "%d", server_port);
407 connect_port_edit->setText(buf);
409 connect_password_edit->setDisabled(true);
410 connect_confirm_password_edit->setDisabled(true);
411 break;
412 case (PAGE_GAME + 1):
413 break;
414 default:
415 if (client.conn.used) {
417 }
419 break;
420 }
421}
422
423/************************************************************************/
427{
429 gui()->showFullScreen();
430 gui()->game_tab_widget->showFullScreen();
431 } else {
432 // FIXME: Doesn't return properly, probably something with sidebar
433 gui()->showNormal();
434 gui()->game_tab_widget->showNormal();
435 }
436}
437
438/************************************************************************/
442{
443 return page;
444}
445
446/************************************************************************/
450{
451 server_notifier = new QSocketNotifier(sock, QSocketNotifier::Read);
452
453 connect(server_notifier, &QSocketNotifier::activated, this,
455}
456
457/************************************************************************/
464
465/************************************************************************/
469{
470 if (event->type() == QEvent::User) {
472 dynamic_cast<version_message_event&>(*event);
473 set_status_bar(vmevt.get_message());
474 return true;
475 } else {
476 return QMainWindow::event(event);
477 }
478}
479
480/************************************************************************/
484{
485 if (!is_client_quitting()) {
487 event->ignore();
488 }
489}
490
491/************************************************************************/
495{
496 server_notifier->deleteLater();
497}
498
499/************************************************************************/
503{
504 server_notifier->setEnabled(false);
505 input_from_server(sock);
506 server_notifier->setEnabled(true);
507}
508
509/************************************************************************/
513{
514 // Prevent current timer from repeating with possibly wrong interval
515 killTimer(event->timerId());
516
517 // Call timer callback in client common code and
518 // start new timer with correct interval
520}
521
522/************************************************************************/
526{
528
529 if (qapp != nullptr) {
530 qapp->quit();
531 }
532}
533
534/************************************************************************/
545
546/************************************************************************/
550{
552 if (game.info.is_new_game) {
553 send_chat("/take -");
554 } else {
555 send_chat("/detach");
556 }
557 obs_button->setText(_("Don't Observe"));
558 } else {
559 send_chat("/observe");
560 obs_button->setText(_("Observe"));
561 }
562}
563
564/************************************************************************/
577
578/****************************************************************************
579 Deletes cursors
580****************************************************************************/
582{
583 int frame;
584 int cursor;
585
586 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
587 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
588 delete fc_cursors[cursor][frame];
589 }
590 }
591}
592
593
594/************************************************************************/
598{
599 QString x;
600
602
603 if (x.isEmpty()) {
604 opened_repo_dlgs.insert(str, widget);
605 return;
606 }
607 log_error("Failed to find place for new tab widget");
608 return;
609}
610
611/************************************************************************/
617{
618 QWidget *w;
619
620 w = opened_repo_dlgs.value(str);
621
622 if (w == NULL) {
623 return false;
624 }
625
626 return true;
627}
628
629/************************************************************************/
633{
634 int i;
635 QWidget *w;
636
637 if (str == "MAP") {
638 return 0;
639 }
640
641 w = opened_repo_dlgs.value(str);
642 i = game_tab_widget->indexOf(w);
643 return i;
644}
645
646/************************************************************************/
650{
651 // This can't be shared between freeciv versions as the content
652 // might be incompatible.
653 QString sname = "freeciv-qt-client-set-"
654 + QString::number(MAJOR_NEW_OPTION_FILE_NAME) + "."
655 + QString::number(MINOR_NEW_OPTION_FILE_NAME);
656 QSettings s(QSettings::IniFormat, QSettings::UserScope,
657 sname);
658
659 if (s.contains("Chat-fx-size")) {
660 qt_settings.chat_fwidth = s.value("Chat-fx-size").toFloat();
661 } else {
663 }
664 if (s.contains("Chat-fy-size")) {
665 qt_settings.chat_fheight = s.value("Chat-fy-size").toFloat();
666 } else {
668 }
669 if (s.contains("Chat-fx-pos")) {
670 qt_settings.chat_fx_pos = s.value("Chat-fx-pos").toFloat();
671 } else {
673 }
674 if (s.contains("Chat-fy-pos")) {
675 qt_settings.chat_fy_pos = s.value("Chat-fy-pos").toFloat();
676 } else {
678 }
679 if (s.contains("unit_fx")) {
680 qt_settings.unit_info_pos_fx = s.value("unit_fx").toFloat();
681 } else {
683 }
684 if (s.contains("unit_fy")) {
685 qt_settings.unit_info_pos_fy = s.value("unit_fy").toFloat();
686 } else {
688 }
689 if (s.contains("minimap_x")) {
690 qt_settings.minimap_x = s.value("minimap_x").toFloat();
691 } else {
692 qt_settings.minimap_x = 0.84;
693 }
694 if (s.contains("minimap_y")) {
695 qt_settings.minimap_y = s.value("minimap_y").toFloat();
696 } else {
697 qt_settings.minimap_y = 0.79;
698 }
699 if (s.contains("minimap_width")) {
700 qt_settings.minimap_width = s.value("minimap_width").toFloat();
701 } else {
703 }
704 if (s.contains("minimap_height")) {
705 qt_settings.minimap_height = s.value("minimap_height").toFloat();
706 } else {
708 }
709 if (s.contains("battlelog_scale")) {
710 qt_settings.battlelog_scale = s.value("battlelog_scale").toFloat();
711 } else {
713 }
714
715 if (s.contains("City-dialog")) {
716 qt_settings.city_geometry = s.value("City-dialog").toByteArray();
717 }
718 if (s.contains("splitter1")) {
719 qt_settings.city_splitter1 = s.value("splitter1").toByteArray();
720 }
721 if (s.contains("splitter2")) {
722 qt_settings.city_splitter2 = s.value("splitter2").toByteArray();
723 }
724 if (s.contains("splitter3")) {
725 qt_settings.city_splitter3 = s.value("splitter3").toByteArray();
726 }
727 if (s.contains("help-dialog")) {
728 qt_settings.help_geometry = s.value("help-dialog").toByteArray();
729 }
730 if (s.contains("help_splitter1")) {
731 qt_settings.help_splitter1 = s.value("help_splitter1").toByteArray();
732 }
733 if (s.contains("opt-client-dialog")) {
734 qt_settings.options_client_geometry = s.value("opt-client-dialog").toByteArray();
735 }
736 if (s.contains("opt-server-dialog")) {
737 qt_settings.options_server_geometry = s.value("opt-server-dialog").toByteArray();
738 }
739 if (s.contains("new_turn_text")) {
740 qt_settings.show_new_turn_text = s.value("new_turn_text").toBool();
741 } else {
743 }
744 if (s.contains("show_battle_log")) {
745 qt_settings.show_battle_log = s.value("show_battle_log").toBool();
746 } else {
748 }
749 if (s.contains("battlelog_x")) {
750 qt_settings.battlelog_x = s.value("battlelog_x").toFloat();
751 } else {
753 }
754 if (s.contains("minimap_y")) {
755 qt_settings.battlelog_y = s.value("battlelog_y").toFloat();
756 } else {
758 }
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);
826}
827
828/************************************************************************/
832{
833 if (unit_sel != NULL) {
834 unit_sel->close();
835 delete unit_sel;
836 unit_sel = new units_select(ptile, gui()->mapview_wdg);
837 unit_sel->show();
838 } else {
839 unit_sel = new units_select(ptile, gui()->mapview_wdg);
840 unit_sel->show();
841 }
842}
843
844/************************************************************************/
848{
849 if (unit_sel != NULL) {
852 unit_sel->update();
853 }
854}
855
856/************************************************************************/
860{
861 if (unit_sel != nullptr) {
862 unit_sel->close();
863 delete unit_sel;
864 unit_sel = nullptr;
865 }
866}
867
868/************************************************************************/
872{
873 // If app is closing, opened_repo_dlg is already deleted */
874 if (!is_closing()) {
875 opened_repo_dlgs.remove(str);
876 }
877}
878
879/************************************************************************/
883{
884 option_dialog_popup(_("Set local options"), client_optset, true);
885}
886
887/************************************************************************/
891{
892 enum cursor_type curs;
893 int cursor;
894 QPixmap *pix;
895 int hot_x, hot_y;
896 struct sprite *sprite;
897 int frame;
898 QCursor *c;
899 for (cursor = 0; cursor < CURSOR_LAST; cursor++) {
900 for (frame = 0; frame < NUM_CURSOR_FRAMES; frame++) {
901 curs = static_cast<cursor_type>(cursor);
902 sprite = get_cursor_sprite(tileset, curs, &hot_x, &hot_y, frame);
903 pix = sprite->pm;
904 c = new QCursor(*pix, hot_x, hot_y);
905 fc_cursors[cursor][frame] = c;
906 }
907 }
908}
909
910/************************************************************************/
913fc_corner::fc_corner(QMainWindow *qmw): QWidget()
914{
916 QPushButton *qpb;
917 int h;
919
920 if (f->pointSize() > 0) {
921 h = f->pointSize();
922 } else {
923 h = f->pixelSize();
924 }
925 mw = qmw;
926 hb = new QHBoxLayout();
927 qpb = new QPushButton(fc_icons::instance()->get_icon("cmin"), "");
928 qpb->setFixedSize(h, h);
929 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::minimize);
930 hb->addWidget(qpb);
931 qpb = new QPushButton(fc_icons::instance()->get_icon("cmax"), "");
932 qpb->setFixedSize(h, h);
933 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::maximize);
934 hb->addWidget(qpb);
935 qpb = new QPushButton(fc_icons::instance()->get_icon("cclose"), "");
936 qpb->setFixedSize(h, h);
937 connect(qpb, &QAbstractButton::clicked, this, &fc_corner::close_fc);
938 hb->addWidget(qpb);
939 setLayout(hb);
940}
941
942/************************************************************************/
946{
947 mw->close();
948}
949
950/************************************************************************/
954{
955 if (!mw->isMaximized()) {
956 mw->showMaximized();
957 } else {
958 mw->showNormal();
959 }
960}
961
962/************************************************************************/
966{
967 mw->showMinimized();
968}
969
970/************************************************************************/
974{
975}
976
977/************************************************************************/
981{
982 connect(this, &QStackedWidget::currentChanged, this, &fc_game_tab_widget::current_changed);
983}
984
985/************************************************************************/
991
992/************************************************************************/
996{
997 if (!m_instance) {
998 m_instance = new fc_icons;
999 }
1000 return m_instance;
1001}
1002
1003/************************************************************************/
1007{
1008 if (m_instance) {
1009 delete m_instance;
1010 m_instance = 0;
1011 }
1012}
1013
1014/************************************************************************/
1018{
1019 QIcon icon;
1020 QString str;
1023
1024 str = QString("themes") + DIR_SEPARATOR + "gui-qt" + DIR_SEPARATOR;
1025 // Try custom icon from theme
1026 pn_bytes = str.toUtf8();
1028 + id + ".png").toUtf8();
1029 icon.addFile(fileinfoname(get_data_dirs(),
1030 png_bytes.data()));
1031 str = str + "icons" + DIR_SEPARATOR;
1032 // Try icon from icons dir
1033 if (icon.isNull()) {
1034 pn_bytes = str.toUtf8();
1035 png_bytes = QString(pn_bytes.data() + id + ".png").toUtf8();
1036 icon.addFile(fileinfoname(get_data_dirs(),
1037 png_bytes.data()));
1038 }
1039
1040 return QIcon(icon);
1041}
1042
1043/************************************************************************/
1047{
1048 QPixmap *pm;
1049 bool status;
1050 QString str;
1052
1053 pm = new QPixmap;
1054 if (QPixmapCache::find(id, pm)) {
1055 return pm;
1056 }
1057 str = QString("themes") + DIR_SEPARATOR + "gui-qt" + DIR_SEPARATOR;
1059 + id + ".png").toUtf8();
1060 status = pm->load(fileinfoname(get_data_dirs(),
1061 png_bytes.data()));
1062
1063 if (!status) {
1064 str = str + "icons" + DIR_SEPARATOR;
1065 png_bytes = QString(str + id + ".png").toUtf8();
1066 pm->load(fileinfoname(get_data_dirs(), png_bytes.data()));
1067 }
1068 QPixmapCache::insert(id, *pm);
1069
1070 return pm;
1071}
1072
1073/************************************************************************/
1077{
1078 QString str;
1080
1081 str = QString("themes") + DIR_SEPARATOR + "gui-qt"
1082 + DIR_SEPARATOR + "icons" + DIR_SEPARATOR;
1083 png_bytes = QString(str + id + ".png").toUtf8();
1084
1085 return fileinfoname(get_data_dirs(),
1086 png_bytes.data());
1087}
1088
1089/************************************************************************/
1093{
1094 QSize size;
1095
1096 size = event->size();
1097 if (C_S_RUNNING <= client_state()) {
1098 gui()->sidebar_wdg->resize_me(size.height());
1099 map_canvas_resized(size.width(), size.height());
1100 gui()->infotab->resize(qRound((size.width()
1101 * gui()->qt_settings.chat_fwidth)),
1102 qRound((size.height()
1103 * gui()->qt_settings.chat_fheight)));
1104 gui()->infotab->move(qRound((size.width()
1105 * gui()->qt_settings.chat_fx_pos)),
1106 qRound((size.height()
1107 * gui()->qt_settings.chat_fy_pos)));
1108 gui()->infotab->restore_chat();
1109 gui()->minimapview_wdg->move(qRound(gui()->qt_settings.minimap_x
1110 * mapview.width),
1111 qRound(gui()->qt_settings.minimap_y
1112 * mapview.height));
1113 gui()->minimapview_wdg->resize(qRound(gui()->qt_settings.minimap_width
1114 * mapview.width),
1115 qRound(gui()->qt_settings.minimap_height
1116 * mapview.height));
1117 gui()->battlelog_wdg->set_scale(gui()->qt_settings.battlelog_scale);
1118 gui()->battlelog_wdg->move(qRound(gui()->qt_settings.battlelog_x
1119 * mapview.width),
1120 qRound(gui()->qt_settings.battlelog_y
1121 * mapview.height));
1122 gui()->x_vote->move(width() / 2 - gui()->x_vote->width() / 2, 0);
1125 gui()->mapview_wdg->resize(event->size().width(),size.height());
1126 gui()->unitinfo_wdg->update_actions(nullptr);
1127 }
1128 event->setAccepted(true);
1129}
1130
1131/************************************************************************/
1135{
1137 fc_sidewidget *sw;
1138
1139 if (gui()->is_closing()) {
1140 return;
1141 }
1143
1144 foreach(sw, objs) {
1145 sw->update_final_pixmap();
1146 }
1147 currentWidget()->hide();
1148 widget(index)->show();
1149
1150 // Set focus to map instead sidebar
1151 if (gui()->mapview_wdg && gui()->current_page() == PAGE_GAME
1152 && index == 0) {
1153 gui()->mapview_wdg->setFocus();
1154 }
1155
1156}
1157
1158/************************************************************************/
1162{
1163}
1164
1165/************************************************************************/
1169{
1171 QPushButton *qclient_options;
1172 QHBoxLayout *hbox = nullptr;
1173 QPushButton *but;
1174 int level;
1175
1176 layout = new QFormLayout(this);
1177 nation = new QPushButton(this);
1178 qclient_options = new QPushButton(_("Client Options"));
1179 max_players = new QSpinBox(this);
1180 ailevel = new QComboBox(this);
1181 cruleset = new QComboBox(this);
1182 max_players->setRange(1, MAX_NUM_PLAYERS);
1183
1184 // Text and icon set by update_buttons()
1185 connect(nation, &QPushButton::clicked,
1187 connect(qclient_options, SIGNAL(clicked()), parentWidget(),
1188 SLOT(popup_client_options()));
1189 for (level = 0; level < AI_LEVEL_COUNT; level++) {
1190 if (is_settable_ai_level(static_cast<ai_level>(level))) {
1192 static_cast<ai_level>(level));
1193 ailevel->addItem(level_name, level);
1194 }
1195 }
1196 ailevel->setCurrentIndex(-1);
1197
1198 connect(max_players, SIGNAL(valueChanged(int)),
1199 SLOT(max_players_change(int)));
1200 connect(ailevel, SIGNAL(currentIndexChanged(int)),
1201 SLOT(ailevel_change(int)));
1202 connect(cruleset, SIGNAL(currentIndexChanged(int)),
1203 SLOT(ruleset_change(int)));
1204
1205 but = new QPushButton;
1206 but->setText(_("More Game Options"));
1207 but->setIcon(fc_icons::instance()->get_icon("preferences-other"));
1208 QObject::connect(but, &QAbstractButton::clicked, this,
1210
1211 layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
1212 layout->addRow(_("Nation:"), nation);
1213 layout->addRow(_("Rules:"), cruleset);
1214
1215 hbox = new QHBoxLayout();
1216 hbox->addWidget(max_players);
1217 hbox->addWidget(ailevel);
1218 layout->addRow(_("Players:"), hbox);
1219 layout->addWidget(but);
1220 layout->addWidget(qclient_options);
1222
1224}
1225
1226/************************************************************************/
1230{
1231 int i;
1232 int def_idx = -1;
1233
1234 cruleset->clear();
1235 cruleset->blockSignals(true);
1236 for (i = 0; i < num_rulesets; i++) {
1237 cruleset->addItem(rulesets[i], i);
1238 if (!strcmp("default", rulesets[i])) {
1239 def_idx = i;
1240 }
1241 }
1242
1243 // HACK: server should tell us the current ruleset.
1244 cruleset->setCurrentIndex(def_idx);
1245 cruleset->blockSignals(false);
1246}
1247
1248/************************************************************************/
1253{
1254 max_players->blockSignals(true);
1255 max_players->setValue(aifill);
1256 max_players->blockSignals(false);
1257}
1258
1259/************************************************************************/
1263{
1264 struct sprite *psprite = nullptr;
1265 QPixmap *pixmap = nullptr;
1266 const struct player *pplayer = client_player();
1267
1268 // Update the "Select Nation" button
1269 if (pplayer != nullptr) {
1270 if (pplayer->nation != nullptr) {
1271 // Defeat keyboard shortcut mnemonics
1272 nation->setText(QString(nation_adjective_for_player(pplayer))
1273 .replace("&", "&&"));
1275 pixmap = psprite->pm;
1276 nation->setIconSize(pixmap->size());
1277 nation->setIcon(QIcon(*pixmap));
1278 } else {
1279 nation->setText(_("Random"));
1280 nation->setIcon(fc_icons::instance()->get_icon("flush-random"));
1281 }
1282 }
1283}
1284
1285/************************************************************************/
1289{
1290 enum ai_level level = server_ai_level();
1291
1292 if (ai_level_is_valid(level)) {
1293 int i = ailevel->findData(level);
1294
1295 ailevel->setCurrentIndex(i);
1296 } else {
1297 ailevel->setCurrentIndex(-1);
1298 }
1299}
1300
1301/************************************************************************/
1308
1309/************************************************************************/
1313{
1314 QVariant v = ailevel->currentData();
1315
1316 if (v.isValid()) {
1317 enum ai_level k = static_cast<ai_level>(v.toInt());
1318
1319 // Suppress changes provoked by server rather than local user
1320 if (server_ai_level() != k) {
1321 const char *name = ai_level_cmd(k);
1322
1323 send_chat_printf("/%s", name);
1324 }
1325 }
1326}
1327
1328/************************************************************************/
1332{
1333 if (!cruleset->currentText().isEmpty()) {
1335
1336 rn_bytes = cruleset->currentText().toUtf8();
1337 set_ruleset(rn_bytes.data());
1338 }
1339}
1340
1341/************************************************************************/
1348
1349/************************************************************************/
1353{
1354 option_dialog_popup(_("Set server options"), server_optset, false);
1355}
#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:555
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:486
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:351
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:2134
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:354
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:349
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:641
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:999
QLabel * status_bar_label
Definition fc_client.h:217
QGridLayout * pages_layout[PAGE_GAME+2]
Definition fc_client.h:178
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:996
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:1026
QWidget * central_wdg
Definition fc_client.h:256
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: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:1414
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:574
void remove_server_source()
void update_scenarios_page(void)
Definition pages.cpp:1445
void create_game_page()
Definition pages.cpp:725
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: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:4761
void create_pixmap()
Definition dialogs.cpp:4460
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:1518
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:75
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:65
void real_science_report_dialog_update(void *)
Definition repodlgs.c:751
void write_shortcuts()
@ LOGIN_TYPE
Definition fc_client.h:56
class fc_client * gui()
Definition gui_main.cpp:84
#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:874
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:972
static enum client_pages current_page
Definition pages.c:78
void real_science_report_dialog_update(void *unused)
Definition repodlgs.c:751
void voteinfo_gui_update(void)
static QApplication * qapp
Definition gui_main.cpp:71
QApplication * current_app()
Definition gui_main.cpp:229
void show_new_turn_info()
const char * name
Definition inputfile.c:127
#define log_error(message,...)
Definition log.h:103
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:4016
const struct option_set * client_optset
Definition options.c:1280
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:431
bool option_int_set(struct option *poption, int val)
Definition options.c:878
#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)
void client_start_server_and_set_page(enum client_pages page)
void set_client_page(enum client_pages page)
bool is_settable_ai_level(enum ai_level level)
Definition player.c:1919
int player_number(const struct player *pplayer)
Definition player.c:837
#define ai_level_cmd(_level_)
Definition player.h:567
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1101
const struct strvec * get_data_dirs(void)
Definition shared.c:893
#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:2465
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
bool gui_qt_fullscreen
Definition options.h:405
bool gui_qt_allied_chat_only
Definition options.h:407
bool gui_qt_show_titlebar
Definition options.h:418
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:258
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:974
#define TRUE
Definition support.h:46
void tileset_free_tiles(struct tileset *t)
Definition tilespec.c:6604
struct sprite * get_nation_shield_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6765
struct sprite * get_cursor_sprite(const struct tileset *t, enum cursor_type cursor, int *hot_x, int *hot_y, int frame)
Definition tilespec.c:6960
#define NUM_CURSOR_FRAMES
Definition tilespec.h:303
cursor_type
Definition tilespec.h:287
@ CURSOR_LAST
Definition tilespec.h:299