13 #include <QApplication>
14 #include <QDirIterator>
17 #include <QStackedLayout>
18 #include <QStandardPaths>
61 setWindowFlags(Qt::FramelessWindowHint);
62 setWindowState(Qt::WindowFullScreen);
64 QTextCodec::setCodecForLocale(QTextCodec::codecForName(
"UTF-8"));
66 for (
int i = 0; i <= PAGE_GAME; i++) {
75 setWindowTitle(
_(
"Freeciv21"));
98 pages[PAGE_NETWORK]->setVisible(
false);
100 path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
101 if (!path.isEmpty()) {
102 QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, path);
107 page_game->chat->installEventFilter(
this);
108 pages[PAGE_GAME] = page_game;
122 resize(
pages[PAGE_MAIN]->minimumSizeHint());
124 QPixmapCache::setCacheLimit(80000);
146 qRegisterMetaType<QTextCursor>(
"QTextCursor");
147 qRegisterMetaType<QTextBlock>(
"QTextBlock");
157 qapp->setAttribute(Qt::AA_UseHighDpiPixmaps);
182 const auto new_page =
static_cast<client_pages
>(new_pg);
184 if ((new_page == PAGE_SCENARIO || new_page == PAGE_LOAD)
191 if (
page == PAGE_NETWORK) {
192 qobject_cast<page_network *>(
pages[PAGE_NETWORK])
193 ->destroy_server_scans();
195 menuBar()->setVisible(
false);
216 qobject_cast<page_load *>(
pages[PAGE_LOAD])->update_load_page();
221 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
232 king()->showFullScreen();
235 menuBar()->setVisible(
true);
251 qobject_cast<page_scenario *>(
pages[PAGE_SCENARIO])
252 ->update_scenarios_page();
255 qobject_cast<page_network *>(
pages[PAGE_NETWORK])
257 qobject_cast<page_network *>(
pages[PAGE_NETWORK])
258 ->update_network_lists();
266 if (
page != PAGE_GAME) {
302 if (
auto *socket =
dynamic_cast<QIODevice *
>(sender())) {
313 killTimer(
event->timerId());
351 const auto page_game = qobject_cast<pageGame *>(
pages[PAGE_GAME]);
352 if (page_game && obj == page_game->chat
353 && page_game->chat->is_chat_visible()) {
354 const auto chat = page_game->chat;
355 const auto mapview = page_game->mapview_wdg;
356 if (
event->type() == QEvent::Move) {
357 const auto xy = QPointF(chat->pos());
360 }
else if (
event->type() == QEvent::Resize) {
361 const auto size = QSizeF(chat->size());
374 QSettings s(QSettings::IniFormat, QSettings::UserScope,
375 QStringLiteral(
"freeciv21-client"));
376 if (s.contains(QStringLiteral(
"Chat-fx-size"))) {
378 s.value(QStringLiteral(
"Chat-fx-size")).toFloat();
382 if (s.contains(QStringLiteral(
"Chat-fy-size"))) {
384 s.value(QStringLiteral(
"Chat-fy-size")).toFloat();
388 if (s.contains(QStringLiteral(
"Chat-fx-pos"))) {
390 s.value(QStringLiteral(
"Chat-fx-pos")).toFloat();
394 if (s.contains(QStringLiteral(
"Chat-fy-pos"))) {
396 s.value(QStringLiteral(
"Chat-fy-pos")).toFloat();
400 if (s.contains(QStringLiteral(
"unit_fx"))) {
402 s.value(QStringLiteral(
"unit_fx")).toFloat();
406 if (s.contains(QStringLiteral(
"unit_fy"))) {
408 s.value(QStringLiteral(
"unit_fy")).toFloat();
412 if (s.contains(QStringLiteral(
"minimap_x"))) {
417 if (s.contains(QStringLiteral(
"minimap_y"))) {
422 if (s.contains(QStringLiteral(
"minimap_width"))) {
424 s.value(QStringLiteral(
"minimap_width")).toFloat();
428 if (s.contains(QStringLiteral(
"minimap_height"))) {
430 s.value(QStringLiteral(
"minimap_height")).toFloat();
434 if (s.contains(QStringLiteral(
"battlelog_scale"))) {
436 s.value(QStringLiteral(
"battlelog_scale")).toFloat();
441 if (s.contains(QStringLiteral(
"help-dialog"))) {
443 s.value(QStringLiteral(
"help-dialog")).toByteArray();
445 if (s.contains(QStringLiteral(
"help_splitter1"))) {
447 s.value(QStringLiteral(
"help_splitter1")).toByteArray();
449 if (s.contains(QStringLiteral(
"new_turn_text"))) {
451 s.value(QStringLiteral(
"new_turn_text")).toBool();
455 if (s.contains(QStringLiteral(
"show_battle_log"))) {
457 s.value(QStringLiteral(
"show_battle_log")).toBool();
463 s.value(QStringLiteral(
"show_chat"),
true).toBool();
465 s.value(QStringLiteral(
"show_messages"),
false).toBool();
467 if (s.contains(QStringLiteral(
"battlelog_x"))) {
469 s.value(QStringLiteral(
"battlelog_x")).toFloat();
473 if (s.contains(QStringLiteral(
"battlelog_y"))) {
475 s.value(QStringLiteral(
"battlelog_y")).toFloat();
516 QSettings s(QSettings::IniFormat, QSettings::UserScope,
517 QStringLiteral(
"freeciv21-client"));
518 s.setValue(QStringLiteral(
"Fonts-set"),
true);
534 s.setValue(QStringLiteral(
"new_turn_text"),
537 s.setValue(QStringLiteral(
"show_chat"),
queen()->chat->is_chat_visible());
538 s.setValue(QStringLiteral(
"show_messages"),
539 queen()->sw_message->isChecked());
556 for (
int cursor = 0; cursor <
CURSOR_LAST; cursor++) {
561 auto c =
new QCursor(*sprite, hot_x, hot_y);
582 qobject_cast<page_pregame *>(
king()->pages[PAGE_START])
583 ->set_rulesets(num_rulesets, rulesets);
599 qobject_cast<page_pregame *>(
king()->pages[PAGE_START])
600 ->update_start_page();
640 QLabel *label =
new QLabel(
_(
"Loading..."));
643 pages_layout[PAGE_LOADING]->addWidget(label, 0, 0, 1, 1, Qt::AlignHCenter);
652 QStringLiteral(
"tutorial.sav*"),
false);
654 qCritical(
_(
"Could not find the tutorial savegame."));
662 [](
void *) { king()->start_from_file(king()->current_file); },
this);
700 if (storage ==
nullptr) {
702 _(
"Cannot find Freeciv21 storage directory"));
705 _(
"You'll have to start the modpack installer manually. Sorry..."));
710 const QString modpack_name = QStringLiteral(
"freeciv21-modpack-qt");
714 QString location = QStandardPaths::findExecutable(
715 modpack_name, {QCoreApplication::applicationDirPath()});
716 if (location.isEmpty()) {
718 location = QStandardPaths::findExecutable(modpack_name);
722 qInfo(
_(
"Starting freeciv21-modpack-qt at %s"), qUtf8Printable(location));
724 QProcess *modProcess =
new QProcess(
this);
725 QStringList arguments;
726 modProcess->start(location, arguments);
739 if (f.pointSize() > 0) {
745 hb =
new QHBoxLayout();
748 qpb->setFixedSize(h, h);
753 qpb->setFixedSize(h, h);
759 qpb->setFixedSize(h, h);
775 if (!
mw->isMaximized()) {
void real_output_window_append(const QString &astring, const text_tag_list *tags)
Appends the string to the chat output window.
int send_chat_printf(const char *format,...)
Send the message as a chat to the server.
void fc_release_ow_mutex()
Release output window mutex.
int send_chat(const char *message)
Send the message as a chat to the server.
void output_window_append(const struct ft_color color, const char *featured_text)
Add a line of text to the output ("chatline") window, like puts() would do it in the console.
void fc_allocate_ow_mutex()
Allocate output window mutex.
void chat_welcome_message(bool gui_has_copying_mitem)
Standard welcome message.
void initFonts()
Initiazlizes fonts from client options.
QFont getFont(const QString &name, double zoom=1.0) const
Returns desired font.
static fcFont * m_instance
static fcFont * instance()
Returns instance of fc_font.
static fcIcons * instance()
Returns instance of fc_icons.
void load_modpack()
Load the modpack-installer from the start menu.
QStringList status_bar_queue
void closing()
Called when fc_client is going to quit.
void closeEvent(QCloseEvent *event) override
Closes main window.
~fc_client() override
Destructor.
QGridLayout * pages_layout[PAGE_COUNT]
void timerEvent(QTimerEvent *) override
Timer event handling.
void create_cursors()
Setup cursors.
void read_settings()
Loads qt-specific options.
enum client_pages current_page()
Returns currently open page.
QCursor * fc_cursors[CURSOR_LAST][NUM_CURSOR_FRAMES]
bool eventFilter(QObject *obj, QEvent *event) override
Used to keep track of the size and location of the chat widget.
QStackedLayout * central_layout
void write_settings()
Save qt-specific options.
void slot_disconnect()
Disconnect from server and return to MAIN PAGE.
void clear_status_bar()
Clears status bar or shows next message in queue if exists.
QLabel * status_bar_label
void add_server_source(QIODevice *socket)
Add notifier for server input.
void switch_page(int i)
Switch from one client page to another.
QWidget * pages[static_cast< int >(PAGE_GAME)+2]
void create_loading_page()
Creates page LOADING, showing label with Loading text.
void fc_main(QApplication *)
This is not called simply 'fc_client::main()', since SDL includes ould sometimes cause 'main' to be c...
void set_status_bar(const QString &str, int timeout=20000)
Sets application status bar for given time in miliseconds.
void server_input()
There is input from server.
void start_tutorial()
start tutorial
void start_from_file(const QString &file)
start from save file
void delete_cursors()
Deletes cursors.
bool is_closing()
Returns status if fc_client is being closed.
void start_new_game()
spawn a server, if there isn't one, using the default settings.
void minimize()
Slot for minimizing freeciv window via corner widget.
void maximize()
Slot for maximizing freeciv window via corner widget.
void close_fc()
Slot for closing freeciv via corner widget.
fc_corner(QMainWindow *qmw)
Contructor for corner widget (used for menubar)
static fc_shortcuts * sc()
Returns given instance.
void write() const
Writes shortcuts to file.
void hide_debugger()
Closes the tileset debugger if it is open.
void updateSidebarTooltips()
Updates top bar tooltips.
fc_game_tab_widget * game_tab_widget
top_bar_widget * sw_message
static update_queue * uq()
void connect_processing_finished(int request_id, uq_callback_t cb, void *data)
QUrl & client_url()
Returns the URL that this client connects to.
double real_timer_callback()
This function should be called at least once per second.
void set_client_state(enum client_states newstate)
Change client state.
void center_on_something()
Find something sensible to display.
void input_from_server(QIODevice *sock)
This function is called when the client received a new input from the server.
void disconnect_from_server()
Get rid of server connection.
bool is_server_running()
The general chain of events:
bool client_start_server(const QString &user_name)
Forks a server if it can.
void set_rulesets(int num_rulesets, QStringList rulesets)
Set the list of available rulesets.
enum client_pages get_current_client_page()
Returns current client page.
void popup_client_options()
Popups client options.
void real_set_client_page(enum client_pages page)
Sets the "page" that the client should show.
void real_science_report_dialog_update(void *)
Update the science report.
void update_start_page(void)
Update the start page.
class fc_client * king()
Return fc_client instance.
const struct ft_color ftc_client
void popup_quit_dialog()
Open dialog to confirm that user wants to quit client.
void update_info_label(void)
Typically an info box is provided to tell the player about the state of their civilization.
void tileset_changed(void)
This function is called when the tileset is changed.
void update_minimap(void)
Return a canvas that is the overview window.
const char *const default_font
void option_dialog_popup(const char *name, const struct option_set *poptset)
Popup the option dialog for the option set.
client_options * gui_options
const struct option_set * client_optset
pageGame * queen()
Return game instandce.
void client_start_server_and_set_page(enum client_pages page)
QFileInfoList find_files_in_path(const QStringList &path, const QString &pattern, bool nodups)
Search for file names matching the pattern in the provided list of directories.
QString freeciv_storage_dir()
Returns string which gives freeciv storage dir.
const QStringList & get_scenario_dirs()
Returns a list of scenario directory paths, in the order in which they should be searched.
bool gui_qt_allied_chat_only
bool gui_qt_show_titlebar
struct connection::@55::@60 client
QByteArray help_splitter1
void tileset_free_tiles(struct tileset *t)
Free all sprites from tileset.
const QPixmap * get_cursor_sprite(const struct tileset *t, enum cursor_type cursor, int *hot_x, int *hot_y, int frame)
Returns a sprite for the given cursor.
#define NUM_CURSOR_FRAMES
void init_mapcanvas_and_overview()
Sets up data for the mapview and overview.
void free_mapcanvas_and_overview()
Frees resources allocated for mapview and overview.
void voteinfo_gui_update(void)
Refresh all vote related GUI widgets.