Added FTBAPP Import
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -33,38 +33,37 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "Application.h"
|
||||
#include "NewInstanceDialog.h"
|
||||
#include "Application.h"
|
||||
#include "ui/pages/modplatform/import_ftb/ImportFTBPage.h"
|
||||
#include "ui_NewInstanceDialog.h"
|
||||
|
||||
#include <BaseVersion.h>
|
||||
#include <InstanceList.h>
|
||||
#include <icons/IconList.h>
|
||||
#include <tasks/Task.h>
|
||||
#include <InstanceList.h>
|
||||
|
||||
#include "VersionSelectDialog.h"
|
||||
#include "ProgressDialog.h"
|
||||
#include "IconPickerDialog.h"
|
||||
#include "ProgressDialog.h"
|
||||
#include "VersionSelectDialog.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFileDialog>
|
||||
#include <QLayout>
|
||||
#include <QPushButton>
|
||||
#include <QFileDialog>
|
||||
#include <QValidator>
|
||||
#include <QDialogButtonBox>
|
||||
#include <utility>
|
||||
|
||||
#include "ui/widgets/PageContainer.h"
|
||||
#include "ui/pages/modplatform/CustomPage.h"
|
||||
#include "ui/pages/modplatform/atlauncher/AtlPage.h"
|
||||
#include "ui/pages/modplatform/legacy_ftb/Page.h"
|
||||
#include "ui/pages/modplatform/flame/FlamePage.h"
|
||||
#include "ui/pages/modplatform/ImportPage.h"
|
||||
#include "ui/pages/modplatform/atlauncher/AtlPage.h"
|
||||
#include "ui/pages/modplatform/flame/FlamePage.h"
|
||||
#include "ui/pages/modplatform/legacy_ftb/Page.h"
|
||||
#include "ui/pages/modplatform/modrinth/ModrinthPage.h"
|
||||
#include "ui/pages/modplatform/technic/TechnicPage.h"
|
||||
#include "ui/widgets/PageContainer.h"
|
||||
|
||||
|
||||
|
||||
NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString & url, QWidget *parent)
|
||||
NewInstanceDialog::NewInstanceDialog(const QString& initialGroup, const QString& url, QWidget* parent)
|
||||
: QDialog(parent), ui(new Ui::NewInstanceDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@ -168,6 +167,7 @@ QList<BasePage *> NewInstanceDialog::getPages()
|
||||
if (APPLICATION->capabilities() & Application::SupportsFlame)
|
||||
pages.append(new FlamePage(this));
|
||||
pages.append(new LegacyFTB::Page(this));
|
||||
pages.append(new FTBImportAPP::ImportFTBPage(this));
|
||||
pages.append(new ModrinthPage(this));
|
||||
pages.append(new TechnicPage(this));
|
||||
|
||||
|
104
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp
Normal file
104
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ImportFTBPage.h"
|
||||
#include "ui_ImportFTBPage.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include "FileSystem.h"
|
||||
#include "ListModel.h"
|
||||
#include "modplatform/import_ftb/PackInstallTask.h"
|
||||
#include "ui/dialogs/NewInstanceDialog.h"
|
||||
|
||||
namespace FTBImportAPP {
|
||||
|
||||
ImportFTBPage::ImportFTBPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), dialog(dialog), ui(new Ui::ImportFTBPage)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
{
|
||||
listModel = new ListModel(this);
|
||||
|
||||
ui->modpackList->setModel(listModel);
|
||||
ui->modpackList->setSortingEnabled(true);
|
||||
ui->modpackList->header()->hide();
|
||||
ui->modpackList->setIndentation(0);
|
||||
ui->modpackList->setIconSize(QSize(42, 42));
|
||||
}
|
||||
|
||||
connect(ui->modpackList->selectionModel(), &QItemSelectionModel::currentChanged, this, &ImportFTBPage::onPublicPackSelectionChanged);
|
||||
|
||||
ui->modpackList->selectionModel()->reset();
|
||||
}
|
||||
|
||||
ImportFTBPage::~ImportFTBPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ImportFTBPage::openedImpl()
|
||||
{
|
||||
if (!initialized) {
|
||||
listModel->update();
|
||||
initialized = true;
|
||||
}
|
||||
suggestCurrent();
|
||||
}
|
||||
|
||||
void ImportFTBPage::retranslate()
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
|
||||
void ImportFTBPage::suggestCurrent()
|
||||
{
|
||||
if (!isOpened)
|
||||
return;
|
||||
|
||||
if (selected.path.isEmpty()) {
|
||||
dialog->setSuggestedPack();
|
||||
return;
|
||||
}
|
||||
|
||||
dialog->setSuggestedPack(selected.name, new PackInstallTask(selected));
|
||||
QString editedLogoName = QString("ftb_%1").arg(selected.id);
|
||||
dialog->setSuggestedIconFromFile(FS::PathCombine(selected.path, "folder.jpg"), editedLogoName);
|
||||
}
|
||||
|
||||
void ImportFTBPage::onPublicPackSelectionChanged(QModelIndex now, QModelIndex prev)
|
||||
{
|
||||
if (!now.isValid()) {
|
||||
onPackSelectionChanged();
|
||||
return;
|
||||
}
|
||||
Modpack selectedPack = listModel->data(now, Qt::UserRole).value<Modpack>();
|
||||
onPackSelectionChanged(&selectedPack);
|
||||
}
|
||||
|
||||
void ImportFTBPage::onPackSelectionChanged(Modpack* pack)
|
||||
{
|
||||
if (pack) {
|
||||
selected = *pack;
|
||||
suggestCurrent();
|
||||
return;
|
||||
}
|
||||
if (isOpened)
|
||||
dialog->setSuggestedPack();
|
||||
}
|
||||
|
||||
} // namespace FTBImportAPP
|
67
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h
Normal file
67
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.h
Normal file
@ -0,0 +1,67 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTextBrowser>
|
||||
#include <QTreeView>
|
||||
#include <QWidget>
|
||||
|
||||
#include <Application.h>
|
||||
#include "modplatform/import_ftb/PackHelpers.h"
|
||||
#include "ui/pages/BasePage.h"
|
||||
#include "ui/pages/modplatform/import_ftb/ListModel.h"
|
||||
|
||||
class NewInstanceDialog;
|
||||
|
||||
namespace FTBImportAPP {
|
||||
namespace Ui {
|
||||
class ImportFTBPage;
|
||||
}
|
||||
|
||||
class ImportFTBPage : public QWidget, public BasePage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ImportFTBPage(NewInstanceDialog* dialog, QWidget* parent = 0);
|
||||
virtual ~ImportFTBPage();
|
||||
QString displayName() const override { return "FTB App Import"; }
|
||||
QIcon icon() const override { return APPLICATION->getThemedIcon("ftb_logo"); }
|
||||
QString id() const override { return "import_ftb"; }
|
||||
QString helpPage() const override { return "FTB-platform"; }
|
||||
bool shouldDisplay() const override { return true; }
|
||||
void openedImpl() override;
|
||||
void retranslate() override;
|
||||
|
||||
private:
|
||||
void suggestCurrent();
|
||||
void onPackSelectionChanged(Modpack* pack = nullptr);
|
||||
private slots:
|
||||
void onPublicPackSelectionChanged(QModelIndex first, QModelIndex second);
|
||||
|
||||
private:
|
||||
bool initialized = false;
|
||||
Modpack selected;
|
||||
ListModel* listModel = nullptr;
|
||||
|
||||
NewInstanceDialog* dialog = nullptr;
|
||||
Ui::ImportFTBPage* ui = nullptr;
|
||||
};
|
||||
|
||||
} // namespace FTBImportAPP
|
28
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui
Normal file
28
launcher/ui/pages/modplatform/import_ftb/ImportFTBPage.ui
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FTBImportAPP::ImportFTBPage</class>
|
||||
<widget class="QWidget" name="FTBImportAPP::ImportFTBPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1461</width>
|
||||
<height>1011</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QTreeView" name="modpackList">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
89
launcher/ui/pages/modplatform/import_ftb/ListModel.cpp
Normal file
89
launcher/ui/pages/modplatform/import_ftb/ListModel.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ListModel.h"
|
||||
#include <qnamespace.h>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
#include <QIcon>
|
||||
#include <QProcessEnvironment>
|
||||
#include "FileSystem.h"
|
||||
#include "modplatform/import_ftb/PackHelpers.h"
|
||||
|
||||
namespace FTBImportAPP {
|
||||
|
||||
QString getPath()
|
||||
{
|
||||
QString partialPath;
|
||||
#if defined(Q_OS_OSX)
|
||||
partialPath = FS::PathCombine(QDir::homePath(), "Library/Application Support");
|
||||
#elif defined(Q_OS_WIN32)
|
||||
partialPath = QProcessEnvironment::systemEnvironment().value("LOCALAPPDATA", "");
|
||||
#else
|
||||
partialPath = QDir::homePath();
|
||||
#endif
|
||||
return FS::PathCombine(partialPath, ".ftba");
|
||||
}
|
||||
|
||||
const QString ListModel::FTB_APP_PATH = getPath();
|
||||
|
||||
void ListModel::update()
|
||||
{
|
||||
beginResetModel();
|
||||
modpacks.clear();
|
||||
|
||||
QString instancesPath = FS::PathCombine(FTB_APP_PATH, "instances");
|
||||
if (auto instancesInfo = QFileInfo(instancesPath); instancesInfo.exists() && instancesInfo.isDir()) {
|
||||
QDirIterator directoryIterator(instancesPath, QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable | QDir::Hidden,
|
||||
QDirIterator::FollowSymlinks);
|
||||
while (directoryIterator.hasNext()) {
|
||||
auto modpack = parseDirectory(directoryIterator.next());
|
||||
if (!modpack.path.isEmpty())
|
||||
modpacks.append(modpack);
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Couldn't find ftb instances folder: " << instancesPath;
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QVariant ListModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
int pos = index.row();
|
||||
if (pos >= modpacks.size() || pos < 0 || !index.isValid()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
auto pack = modpacks.at(pos);
|
||||
if (role == Qt::DisplayRole) {
|
||||
return pack.name;
|
||||
} else if (role == Qt::DecorationRole) {
|
||||
return pack.icon;
|
||||
} else if (role == Qt::UserRole) {
|
||||
QVariant v;
|
||||
v.setValue(pack);
|
||||
return v;
|
||||
} else if (role == Qt::ToolTipRole) {
|
||||
return tr("Minecraft %1").arg(pack.mcVersion);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
} // namespace FTBImportAPP
|
46
launcher/ui/pages/modplatform/import_ftb/ListModel.h
Normal file
46
launcher/ui/pages/modplatform/import_ftb/ListModel.h
Normal file
@ -0,0 +1,46 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QIcon>
|
||||
#include <QVariant>
|
||||
#include "modplatform/import_ftb/PackHelpers.h"
|
||||
|
||||
namespace FTBImportAPP {
|
||||
|
||||
class ListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ListModel(QObject* parent) : QAbstractListModel(parent) {}
|
||||
virtual ~ListModel() = default;
|
||||
|
||||
int rowCount(const QModelIndex& parent) const { return modpacks.size(); }
|
||||
int columnCount(const QModelIndex& parent) const { return 1; }
|
||||
QVariant data(const QModelIndex& index, int role) const;
|
||||
|
||||
void update();
|
||||
|
||||
static const QString FTB_APP_PATH;
|
||||
|
||||
private:
|
||||
ModpackList modpacks;
|
||||
};
|
||||
} // namespace FTBImportAPP
|
Reference in New Issue
Block a user