From d1d3e03136c290651a8451617427eb6e7166a9f3 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 7 Jan 2024 10:31:04 -0600 Subject: [PATCH 1/3] Add an Add Ons button to start screen that loads mp installer Closes #1366 --- client/fc_client.cpp | 40 +++++++++++++++++++++++++++++++++++ client/fc_client.h | 1 + client/page_main.cpp | 3 +++ client/page_main.ui | 50 ++++++++++++++++++++++++++------------------ 4 files changed, 74 insertions(+), 20 deletions(-) diff --git a/client/fc_client.cpp b/client/fc_client.cpp index 6ab6481e59..bc287a3466 100644 --- a/client/fc_client.cpp +++ b/client/fc_client.cpp @@ -12,6 +12,7 @@ // Qt #include #include +#include #include #include #include @@ -19,6 +20,7 @@ #include #include #include + // utility #include "fcintl.h" // common @@ -687,6 +689,44 @@ void fc_client::start_new_game() } } +/** + * Load the modpack-installer from the start menu + */ +void fc_client::load_modpack() +{ + output_window_append(ftc_client, _("Starting the modpack installer...")); + + const QString storage = freeciv_storage_dir(); + if (storage == nullptr) { + output_window_append(ftc_client, + _("Cannot find Freeciv21 storage directory")); + output_window_append( + ftc_client, + _("You'll have to start the modpack installer manually. Sorry...")); + return; + } + + // Look for a modpack installer binary + const QString modpack_name = QStringLiteral("freeciv21-modpack-qt"); + + // First next to the client binary + // NOTE On Windows findExecutable adds the .exe automatically + QString location = QStandardPaths::findExecutable( + modpack_name, {QCoreApplication::applicationDirPath()}); + if (location.isEmpty()) { + // Then in PATH + location = QStandardPaths::findExecutable(modpack_name); + } + + // Start it + qInfo(_("Starting freeciv21-modpack-qt at %s"), qUtf8Printable(location)); + + QProcess *modProcess = new QProcess(this); + QStringList arguments; + modProcess->start(location, arguments); + modProcess->waitForFinished(); +} + /** Contructor for corner widget (used for menubar) */ diff --git a/client/fc_client.h b/client/fc_client.h index aacf4f102e..99042e11b1 100644 --- a/client/fc_client.h +++ b/client/fc_client.h @@ -140,6 +140,7 @@ public slots: void start_from_file(const QString &file); void start_new_game(); void switch_page(int i); + void load_modpack(); private: void create_loading_page(); diff --git a/client/page_main.cpp b/client/page_main.cpp index 75f4295f35..84427dee0e 100644 --- a/client/page_main.cpp +++ b/client/page_main.cpp @@ -28,11 +28,14 @@ page_main::page_main(QWidget *parent, fc_client *gui) : QWidget(parent) ui.bload->setText(_("Load saved game")); ui.bconnect->setText(_("Connect to network game")); ui.bquit->setText(_("Quit")); + ui.baddon->setText(_("Add Ons")); connect(ui.btut, &QAbstractButton::clicked, gui, &fc_client::start_tutorial); connect(ui.bstart, &QAbstractButton::clicked, gui, &fc_client::start_new_game); + connect(ui.baddon, &QAbstractButton::clicked, gui, + &fc_client::load_modpack); connect(ui.bscenario, &QPushButton::clicked, [gui]() { gui->switch_page(PAGE_SCENARIO); }); connect(ui.boptions, &QAbstractButton::clicked, diff --git a/client/page_main.ui b/client/page_main.ui index e8e59b7c94..d53e171bf5 100644 --- a/client/page_main.ui +++ b/client/page_main.ui @@ -7,7 +7,7 @@ 0 0 821 - 397 + 477 @@ -25,7 +25,7 @@ 50 40 651 - 321 + 381 @@ -95,29 +95,16 @@ - + - Options + Add Ons true - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + Qt::Vertical @@ -130,7 +117,7 @@ - + Quit @@ -140,7 +127,20 @@ - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + lversion @@ -150,6 +150,16 @@ + + + + Options + + + true + + + From 4075168c5cffb1af88f05ae088afce266aed9da6 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 7 Jan 2024 10:44:42 -0600 Subject: [PATCH 2/3] Resize mp installer at launch --- tools/fcmp/mpgui_qt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/fcmp/mpgui_qt.cpp b/tools/fcmp/mpgui_qt.cpp index 28f0d6f180..18b2c3d2cf 100644 --- a/tools/fcmp/mpgui_qt.cpp +++ b/tools/fcmp/mpgui_qt.cpp @@ -104,7 +104,7 @@ int main(int argc, char **argv) central = new QWidget; main_window = new mpgui_main(&app, central); - main_window->setGeometry(0, 30, 640, 60); + main_window->resize(820, 140); main_window->setWindowTitle( QString::fromUtf8(_("Freeciv21 modpack installer (Qt)"))); From 1b093b119869fa0859308d8da8140f2332dafbb7 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 8 Jan 2024 15:53:49 -0600 Subject: [PATCH 3/3] Remove waitForFinished() per review --- client/fc_client.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/client/fc_client.cpp b/client/fc_client.cpp index bc287a3466..59d49cad1a 100644 --- a/client/fc_client.cpp +++ b/client/fc_client.cpp @@ -724,7 +724,6 @@ void fc_client::load_modpack() QProcess *modProcess = new QProcess(this); QStringList arguments; modProcess->start(location, arguments); - modProcess->waitForFinished(); } /**