Global data packs

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2025-03-25 16:28:16 +00:00
parent 6ab4fef0c5
commit 18ee1f897a
No known key found for this signature in database
GPG Key ID: 5E39D70B4C93C38E
26 changed files with 254 additions and 24 deletions

View File

@ -1,5 +1,6 @@
#pragma once
#include <FileSystem.h>
#include <ui/pages/instance/DataPackPage.h>
#include "minecraft/MinecraftInstance.h"
#include "ui/pages/BasePage.h"
#include "ui/pages/BasePageProvider.h"
@ -36,6 +37,7 @@ class InstancePageProvider : protected QObject, public BasePageProvider {
values.append(new CoreModFolderPage(onesix.get(), onesix->coreModList()));
values.append(new NilModFolderPage(onesix.get(), onesix->nilModList()));
values.append(new ResourcePackPage(onesix.get(), onesix->resourcePackList()));
values.append(new GlobalDataPackPage(onesix.get()));
values.append(new TexturePackPage(onesix.get(), onesix->texturePackList()));
values.append(new ShaderPackPage(onesix.get(), onesix->shaderPackList()));
values.append(new NotesPage(onesix.get()));

View File

@ -250,6 +250,12 @@ void MinecraftInstance::loadSpecificSettings()
m_settings->registerSetting("ExportAuthor", "");
m_settings->registerSetting("ExportOptionalFiles", true);
auto dataPacksEnabled = m_settings->registerSetting("GlobalDataPacksEnabled", false);
auto dataPacksPath = m_settings->registerSetting("GlobalDataPacksPath", "");
connect(dataPacksEnabled.get(), &Setting::SettingChanged, this, [this] { m_data_pack_list.reset(); });
connect(dataPacksPath.get(), &Setting::SettingChanged, this, [this] { m_data_pack_list.reset(); });
qDebug() << "Instance-type specific settings were loaded!";
setSpecificSettingsLoaded(true);
@ -392,6 +398,16 @@ QString MinecraftInstance::nilModsDir() const
return FS::PathCombine(gameRoot(), "nilmods");
}
QString MinecraftInstance::dataPacksDir()
{
QString relativePath = settings()->get("GlobalDataPacksPath").toString();
if (relativePath.isEmpty())
relativePath = "datapacks";
return FS::PathCombine(gameRoot(), relativePath);
}
QString MinecraftInstance::resourcePacksDir() const
{
return FS::PathCombine(gameRoot(), "resourcepacks");
@ -1303,9 +1319,18 @@ std::shared_ptr<ShaderPackFolderModel> MinecraftInstance::shaderPackList()
return m_shader_pack_list;
}
std::shared_ptr<DataPackFolderModel> MinecraftInstance::dataPackList()
{
if (!m_data_pack_list && settings()->get("GlobalDataPacksEnabled").toBool()) {
bool isIndexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_data_pack_list.reset(new DataPackFolderModel(dataPacksDir(), this, isIndexed, true));
}
return m_data_pack_list;
}
QList<std::shared_ptr<ResourceFolderModel>> MinecraftInstance::resourceLists()
{
return { loaderModList(), coreModList(), nilModList(), resourcePackList(), texturePackList(), shaderPackList() };
return { loaderModList(), coreModList(), nilModList(), resourcePackList(), texturePackList(), shaderPackList(), dataPackList() };
}
std::shared_ptr<WorldList> MinecraftInstance::worldList()

View File

@ -36,6 +36,7 @@
#pragma once
#include <java/JavaVersion.h>
#include <minecraft/mod/DataPackFolderModel.h>
#include <QDir>
#include <QProcess>
#include "BaseInstance.h"
@ -80,6 +81,7 @@ class MinecraftInstance : public BaseInstance {
QString modsRoot() const override;
QString coreModsDir() const;
QString nilModsDir() const;
QString dataPacksDir();
QString modsCacheLocation() const;
QString libDir() const;
QString worldDir() const;
@ -116,6 +118,7 @@ class MinecraftInstance : public BaseInstance {
std::shared_ptr<ResourcePackFolderModel> resourcePackList();
std::shared_ptr<TexturePackFolderModel> texturePackList();
std::shared_ptr<ShaderPackFolderModel> shaderPackList();
std::shared_ptr<DataPackFolderModel> dataPackList();
QList<std::shared_ptr<ResourceFolderModel>> resourceLists();
std::shared_ptr<WorldList> worldList();
std::shared_ptr<GameOptions> gameOptionsModel();
@ -171,6 +174,7 @@ class MinecraftInstance : public BaseInstance {
mutable std::shared_ptr<ResourcePackFolderModel> m_resource_pack_list;
mutable std::shared_ptr<ShaderPackFolderModel> m_shader_pack_list;
mutable std::shared_ptr<TexturePackFolderModel> m_texture_pack_list;
mutable std::shared_ptr<DataPackFolderModel> m_data_pack_list;
mutable std::shared_ptr<WorldList> m_world_list;
mutable std::shared_ptr<GameOptions> m_game_options;
};

View File

@ -9,7 +9,7 @@
<file>scalable/copy.svg</file>
<file>scalable/coremods.svg</file>
<file>scalable/custom-commands.svg</file>
<file>scalable/environment-variables.svg</file>
<file>scalable/datapacks.svg</file>
<file>scalable/discord.svg</file>
<file>scalable/externaltools.svg</file>
<file>scalable/help.svg</file>

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -9,7 +9,7 @@
<file>scalable/copy.svg</file>
<file>scalable/coremods.svg</file>
<file>scalable/custom-commands.svg</file>
<file>scalable/environment-variables.svg</file>
<file>scalable/datapacks.svg</file>
<file>scalable/discord.svg</file>
<file>scalable/externaltools.svg</file>
<file>scalable/help.svg</file>

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -11,7 +11,7 @@
<file>scalable/copy.svg</file>
<file>scalable/coremods.svg</file>
<file>scalable/custom-commands.svg</file>
<file>scalable/environment-variables.svg</file>
<file>scalable/datapacks.svg</file>
<file>scalable/discord.svg</file>
<file>scalable/externaltools.svg</file>
<file>scalable/help.svg</file>

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -11,7 +11,7 @@
<file>scalable/copy.svg</file>
<file>scalable/coremods.svg</file>
<file>scalable/custom-commands.svg</file>
<file>scalable/environment-variables.svg</file>
<file>scalable/datapacks.svg</file>
<file>scalable/discord.svg</file>
<file>scalable/externaltools.svg</file>
<file>scalable/help.svg</file>

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -74,7 +74,7 @@
<file>scalable/screenshots.svg</file>
<file>scalable/custom-commands.svg</file>
<file>scalable/environment-variables.svg</file>
<file>scalable/datapacks.svg</file>
<!-- The cat button. Freeware, http://findicons.com/icon/73096/black_cat -->
<file>16x16/cat.png</file>

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -10,7 +10,7 @@
<file>scalable/copy.svg</file>
<file>scalable/coremods.svg</file>
<file>scalable/custom-commands.svg</file>
<file>scalable/environment-variables.svg</file>
<file>scalable/datapacks.svg</file>
<file>scalable/externaltools.svg</file>
<file>scalable/help.svg</file>
<file>scalable/instance-settings.svg</file>

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -10,7 +10,7 @@
<file>scalable/copy.svg</file>
<file>scalable/coremods.svg</file>
<file>scalable/custom-commands.svg</file>
<file>scalable/environment-variables.svg</file>
<file>scalable/datapacks.svg</file>
<file>scalable/externaltools.svg</file>
<file>scalable/help.svg</file>
<file>scalable/instance-settings.svg</file>

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -10,7 +10,7 @@
<file>scalable/copy.svg</file>
<file>scalable/coremods.svg</file>
<file>scalable/custom-commands.svg</file>
<file>scalable/environment-variables.svg</file>
<file>scalable/datapacks.svg</file>
<file>scalable/externaltools.svg</file>
<file>scalable/help.svg</file>
<file>scalable/instance-settings.svg</file>

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -10,7 +10,7 @@
<file>scalable/copy.svg</file>
<file>scalable/coremods.svg</file>
<file>scalable/custom-commands.svg</file>
<file>scalable/environment-variables.svg</file>
<file>scalable/datapacks.svg</file>
<file>scalable/externaltools.svg</file>
<file>scalable/help.svg</file>
<file>scalable/instance-settings.svg</file>

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -22,7 +22,7 @@
#include "ui/dialogs/ProgressDialog.h"
#include "ui/dialogs/ResourceDownloadDialog.h"
DataPackPage::DataPackPage(MinecraftInstance* instance, std::shared_ptr<DataPackFolderModel> model, QWidget* parent)
DataPackPage::DataPackPage(BaseInstance* instance, std::shared_ptr<DataPackFolderModel> model, QWidget* parent)
: ExternalResourcesPage(instance, model, parent)
{
ui->actionDownloadItem->setText(tr("Download packs"));
@ -30,7 +30,7 @@ DataPackPage::DataPackPage(MinecraftInstance* instance, std::shared_ptr<DataPack
ui->actionDownloadItem->setEnabled(true);
connect(ui->actionDownloadItem, &QAction::triggered, this, &DataPackPage::downloadDataPacks);
ui->actionsToolbar->insertActionBefore(ui->actionAddItem, ui->actionDownloadItem);
ui->actionViewConfigs->setVisible(false);
}
@ -49,8 +49,7 @@ void DataPackPage::downloadDataPacks()
ResourceDownload::DataPackDownloadDialog mdownload(this, std::static_pointer_cast<DataPackFolderModel>(m_model), m_instance);
if (mdownload.exec()) {
auto tasks =
new ConcurrentTask("Download Data Pack", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
auto tasks = new ConcurrentTask("Download Data Pack", APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt());
connect(tasks, &Task::failed, [this, tasks](QString reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
tasks->deleteLater();
@ -78,3 +77,95 @@ void DataPackPage::downloadDataPacks()
m_model->update();
}
}
GlobalDataPackPage::GlobalDataPackPage(MinecraftInstance* instance, QWidget* parent) : QWidget(parent), m_instance(instance)
{
auto layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout);
connect(instance->settings()->getSetting("GlobalDataPacksEnabled").get(), &Setting::SettingChanged, this, [this] {
updateContent();
if (m_container != nullptr)
m_container->refreshContainer();
});
connect(instance->settings()->getSetting("GlobalDataPacksPath").get(), &Setting::SettingChanged, this,
&GlobalDataPackPage::updateContent);
}
QString GlobalDataPackPage::displayName() const
{
if (m_underlyingPage == nullptr)
return {};
return m_underlyingPage->displayName();
}
QIcon GlobalDataPackPage::icon() const
{
if (m_underlyingPage == nullptr)
return {};
return m_underlyingPage->icon();
}
QString GlobalDataPackPage::helpPage() const
{
if (m_underlyingPage == nullptr)
return {};
return m_underlyingPage->helpPage();
}
bool GlobalDataPackPage::shouldDisplay() const
{
return m_instance->settings()->get("GlobalDataPacksEnabled").toBool();
}
bool GlobalDataPackPage::apply()
{
return m_underlyingPage != nullptr && m_underlyingPage->apply();
}
void GlobalDataPackPage::openedImpl()
{
if (m_underlyingPage != nullptr)
m_underlyingPage->openedImpl();
}
void GlobalDataPackPage::closedImpl()
{
if (m_underlyingPage != nullptr)
m_underlyingPage->closedImpl();
}
void GlobalDataPackPage::updateContent()
{
if (m_underlyingPage != nullptr) {
if (m_container->selectedPage() == this)
m_underlyingPage->closedImpl();
m_underlyingPage->apply();
layout()->removeWidget(m_underlyingPage);
delete m_underlyingPage;
m_underlyingPage = nullptr;
}
if (shouldDisplay()) {
m_underlyingPage = new DataPackPage(m_instance, m_instance->dataPackList());
if (m_container->selectedPage() == this)
m_underlyingPage->openedImpl();
layout()->addWidget(m_underlyingPage);
}
}
void GlobalDataPackPage::setParentContainer(BasePageContainer* container)
{
BasePage::setParentContainer(container);
updateContent();
}

View File

@ -25,9 +25,9 @@
class DataPackPage : public ExternalResourcesPage {
Q_OBJECT
public:
explicit DataPackPage(MinecraftInstance* instance, std::shared_ptr<DataPackFolderModel> model, QWidget* parent = 0);
explicit DataPackPage(BaseInstance* instance, std::shared_ptr<DataPackFolderModel> model, QWidget* parent = nullptr);
QString displayName() const override { return tr("Data packs"); }
QString displayName() const override { return QObject::tr("Data packs"); }
QIcon icon() const override { return APPLICATION->getThemedIcon("datapacks"); }
QString id() const override { return "datapacks"; }
QString helpPage() const override { return "Data-packs"; }
@ -37,3 +37,31 @@ class DataPackPage : public ExternalResourcesPage {
void updateFrame(const QModelIndex& current, const QModelIndex& previous) override;
void downloadDataPacks();
};
/**
* Syncs DataPackPage with GlobalDataPacksPath and shows/hides based on GlobalDataPacksEnabled.
*/
class GlobalDataPackPage : public QWidget, public BasePage {
public:
explicit GlobalDataPackPage(MinecraftInstance* instance, QWidget* parent = nullptr);
QString displayName() const override;
QIcon icon() const override;
QString id() const override { return "datapacks"; }
QString helpPage() const override;
bool shouldDisplay() const override;
bool apply() override;
void openedImpl() override;
void closedImpl() override;
void setParentContainer(BasePageContainer *container) override;
private:
void updateContent();
QVBoxLayout* layout() { return static_cast<QVBoxLayout*>(QWidget::layout()); }
MinecraftInstance* m_instance;
DataPackPage* m_underlyingPage = nullptr;
};

View File

@ -238,8 +238,11 @@ void WorldListPage::on_actionData_Packs_triggered()
static_cast<int>(std::max(0.75 * window()->height(), 400.0)));
dialog->restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get("DataPackDownloadGeometry").toByteArray()));
bool isIndexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
auto model = std::make_shared<DataPackFolderModel>(folder, m_inst.get(), isIndexed, true);
auto layout = new QHBoxLayout(dialog);
auto page = new DataPackPage(m_inst.get(), std::make_shared<DataPackFolderModel>(folder, m_inst.get(), true, true));
auto page = new DataPackPage(m_inst.get(), std::move(model));
page->setParent(dialog); // HACK: many pages extend QMainWindow; setting the parent manually prevents them from creating a window.
layout->addWidget(page);
dialog->setLayout(layout);

View File

@ -58,6 +58,8 @@ MinecraftSettingsWidget::MinecraftSettingsWidget(MinecraftInstancePtr instance,
}
m_ui->openGlobalSettingsButton->setVisible(false);
m_ui->globalDataPacksGroupBox->hide();
} else {
m_javaSettings = new JavaSettingsWidget(m_instance, this);
m_ui->javaScrollArea->setWidget(m_javaSettings);
@ -97,6 +99,11 @@ MinecraftSettingsWidget::MinecraftSettingsWidget(MinecraftInstancePtr instance,
connect(m_ui->openGlobalSettingsButton, &QCommandLinkButton::clicked, this, &MinecraftSettingsWidget::openGlobalSettings);
connect(m_ui->serverJoinAddressButton, &QAbstractButton::toggled, m_ui->serverJoinAddress, &QWidget::setEnabled);
connect(m_ui->worldJoinButton, &QAbstractButton::toggled, m_ui->worldsCb, &QWidget::setEnabled);
connect(m_ui->globalDataPacksGroupBox, &QGroupBox::toggled, this,
[this](bool value) { m_instance->settings()->set("GlobalDataPacksEnabled", value); });
connect(m_ui->dataPacksPathEdit, &QLineEdit::editingFinished, this,
[this]() { m_instance->settings()->set("GlobalDataPacksPath", m_ui->dataPacksPathEdit->text()); });
}
m_ui->maximizedWarning->hide();
@ -231,6 +238,13 @@ void MinecraftSettingsWidget::loadSettings()
m_ui->legacySettingsGroupBox->setChecked(settings->get("OverrideLegacySettings").toBool());
m_ui->onlineFixes->setChecked(settings->get("OnlineFixes").toBool());
m_ui->globalDataPacksGroupBox->blockSignals(true);
m_ui->dataPacksPathEdit->blockSignals(true);
m_ui->globalDataPacksGroupBox->setChecked(settings->get("GlobalDataPacksEnabled").toBool());
m_ui->dataPacksPathEdit->setText(settings->get("GlobalDataPacksPath").toString());
m_ui->globalDataPacksGroupBox->blockSignals(false);
m_ui->dataPacksPathEdit->blockSignals(false);
}
void MinecraftSettingsWidget::saveSettings()

View File

@ -61,9 +61,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-253</y>
<y>-166</y>
<width>610</width>
<height>550</height>
<height>768</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
@ -149,6 +149,70 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="globalDataPacksGroupBox">
<property name="title">
<string>&amp;Global Data Packs</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Allows installing data packs across all worlds if an applicable mod is installed.
It is most likely you will need to change the path - please refer to the mod's website.</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>6</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Folder Path</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="dataPacksPathEdit">
<property name="placeholderText">
<string>datapacks</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="dataPacksPathBrowse">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gameTimeGroupBox">
<property name="enabled">
@ -298,7 +362,7 @@
<x>0</x>
<y>0</y>
<width>624</width>
<height>297</height>
<height>291</height>
</rect>
</property>
</widget>
@ -323,9 +387,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-101</y>
<y>0</y>
<width>610</width>
<height>398</height>
<height>439</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
@ -513,7 +577,7 @@
<x>0</x>
<y>0</y>
<width>624</width>
<height>297</height>
<height>291</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_14">
@ -647,7 +711,6 @@
<tabstops>
<tabstop>openGlobalSettingsButton</tabstop>
<tabstop>settingsTabs</tabstop>
<tabstop>scrollArea</tabstop>
<tabstop>maximizedCheckBox</tabstop>
<tabstop>windowWidthSpinBox</tabstop>
<tabstop>windowHeightSpinBox</tabstop>