Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an Add Ons button to start screen that loads mp installer #2143

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions client/fc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
// Qt
#include <QApplication>
#include <QDirIterator>
#include <QProcess>
#include <QSettings>
#include <QStackedLayout>
#include <QStandardPaths>
#include <QStatusBar>
#include <QTcpSocket>
#include <QTextBlock>
#include <QTextCodec>

// utility
#include "fcintl.h"
// common
Expand Down Expand Up @@ -687,6 +689,43 @@ 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);
}

/**
Contructor for corner widget (used for menubar)
*/
Expand Down
1 change: 1 addition & 0 deletions client/fc_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions client/page_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
50 changes: 30 additions & 20 deletions client/page_main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>821</width>
<height>397</height>
<height>477</height>
</rect>
</property>
<property name="minimumSize">
Expand All @@ -25,7 +25,7 @@
<x>50</x>
<y>40</y>
<width>651</width>
<height>321</height>
<height>381</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -95,29 +95,16 @@
</widget>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="boptions">
<widget class="QPushButton" name="baddon">
<property name="text">
<string>Options</string>
<string>Add Ons</string>
</property>
<property name="main_pagebt" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="0">
<item row="7" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -130,7 +117,7 @@
</property>
</spacer>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QPushButton" name="bquit">
<property name="text">
<string>Quit</string>
Expand All @@ -140,7 +127,20 @@
</property>
</widget>
</item>
<item row="7" column="2">
<item row="8" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="8" column="2">
<widget class="QLabel" name="lversion">
<property name="text">
<string>lversion</string>
Expand All @@ -150,6 +150,16 @@
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QPushButton" name="boptions">
<property name="text">
<string>Options</string>
</property>
<property name="main_pagebt" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down
2 changes: 1 addition & 1 deletion tools/fcmp/mpgui_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)")));

Expand Down
Loading