Skip to content

Commit

Permalink
Add an Add Ons button to start screen that loads mp installer
Browse files Browse the repository at this point in the history
  • Loading branch information
jwrober authored and lmoureaux committed Mar 17, 2024
1 parent 83cb7e1 commit 8fde678
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 20 deletions.
40 changes: 40 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,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)
*/
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

0 comments on commit 8fde678

Please sign in to comment.