Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into validate_metadata

This commit is contained in:
Trial97
2024-08-18 22:39:46 +03:00
83 changed files with 650 additions and 651 deletions

View File

@@ -36,6 +36,8 @@
*/
#include "InstanceSettingsPage.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/WorldList.h"
#include "ui_InstanceSettingsPage.h"
#include <QDialog>
@@ -71,6 +73,22 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance* inst, QWidget* parent)
connect(ui->useNativeGLFWCheck, &QAbstractButton::toggled, this, &InstanceSettingsPage::onUseNativeGLFWChanged);
connect(ui->useNativeOpenALCheck, &QAbstractButton::toggled, this, &InstanceSettingsPage::onUseNativeOpenALChanged);
auto mInst = dynamic_cast<MinecraftInstance*>(inst);
m_world_quickplay_supported = mInst && mInst->traits().contains("feature:is_quick_play_singleplayer");
if (m_world_quickplay_supported) {
auto worlds = mInst->worldList();
worlds->update();
for (const auto& world : worlds->allWorlds()) {
ui->worldsCb->addItem(world.folderName());
}
} else {
ui->worldsCb->hide();
ui->worldJoinButton->hide();
ui->serverJoinAddressButton->setChecked(true);
ui->serverJoinAddress->setEnabled(true);
ui->serverJoinAddressButton->setStyleSheet("QRadioButton::indicator { width: 0px; height: 0px; }");
}
loadSettings();
updateThresholds();
@@ -256,9 +274,16 @@ void InstanceSettingsPage::applySettings()
bool joinServerOnLaunch = ui->serverJoinGroupBox->isChecked();
m_settings->set("JoinServerOnLaunch", joinServerOnLaunch);
if (joinServerOnLaunch) {
m_settings->set("JoinServerOnLaunchAddress", ui->serverJoinAddress->text());
if (ui->serverJoinAddressButton->isChecked() || !m_world_quickplay_supported) {
m_settings->set("JoinServerOnLaunchAddress", ui->serverJoinAddress->text());
m_settings->reset("JoinWorldOnLaunch");
} else {
m_settings->set("JoinWorldOnLaunch", ui->worldsCb->currentText());
m_settings->reset("JoinServerOnLaunchAddress");
}
} else {
m_settings->reset("JoinServerOnLaunchAddress");
m_settings->reset("JoinWorldOnLaunch");
}
// Use an account for this instance
@@ -379,7 +404,25 @@ void InstanceSettingsPage::loadSettings()
ui->recordGameTime->setChecked(m_settings->get("RecordGameTime").toBool());
ui->serverJoinGroupBox->setChecked(m_settings->get("JoinServerOnLaunch").toBool());
ui->serverJoinAddress->setText(m_settings->get("JoinServerOnLaunchAddress").toString());
if (auto server = m_settings->get("JoinServerOnLaunchAddress").toString(); !server.isEmpty()) {
ui->serverJoinAddress->setText(server);
ui->serverJoinAddressButton->setChecked(true);
ui->worldJoinButton->setChecked(false);
ui->serverJoinAddress->setEnabled(true);
ui->worldsCb->setEnabled(false);
} else if (auto world = m_settings->get("JoinWorldOnLaunch").toString(); !world.isEmpty() && m_world_quickplay_supported) {
ui->worldsCb->setCurrentText(world);
ui->serverJoinAddressButton->setChecked(false);
ui->worldJoinButton->setChecked(true);
ui->serverJoinAddress->setEnabled(false);
ui->worldsCb->setEnabled(true);
} else {
ui->serverJoinAddressButton->setChecked(true);
ui->worldJoinButton->setChecked(false);
ui->serverJoinAddress->setEnabled(true);
ui->worldsCb->setEnabled(false);
}
ui->instanceAccountGroupBox->setChecked(m_settings->get("UseAccountForInstance").toBool());
updateAccountsMenu();
@@ -534,3 +577,13 @@ void InstanceSettingsPage::updateThresholds()
ui->labelMaxMemIcon->setPixmap(pix);
}
}
void InstanceSettingsPage::on_serverJoinAddressButton_toggled(bool checked)
{
ui->serverJoinAddress->setEnabled(checked);
}
void InstanceSettingsPage::on_worldJoinButton_toggled(bool checked)
{
ui->worldsCb->setEnabled(checked);
}

View File

@@ -70,6 +70,8 @@ class InstanceSettingsPage : public QWidget, public BasePage {
void on_javaTestBtn_clicked();
void on_javaBrowseBtn_clicked();
void on_maxMemSpinBox_valueChanged(int i);
void on_serverJoinAddressButton_toggled(bool checked);
void on_worldJoinButton_toggled(bool checked);
void onUseNativeGLFWChanged(bool checked);
void onUseNativeOpenALChanged(bool checked);
@@ -90,4 +92,5 @@ class InstanceSettingsPage : public QWidget, public BasePage {
BaseInstance* m_instance;
SettingsObjectPtr m_settings;
unique_qobject_ptr<JavaCommon::TestCheck> checker;
bool m_world_quickplay_supported;
};

View File

@@ -660,7 +660,7 @@
<item>
<widget class="QGroupBox" name="serverJoinGroupBox">
<property name="title">
<string>Set a server to join on launch</string>
<string>Set a target to join on launch</string>
</property>
<property name="checkable">
<bool>true</bool>
@@ -668,26 +668,26 @@
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<layout class="QGridLayout" name="serverJoinLayout">
<item row="0" column="0">
<widget class="QLabel" name="serverJoinAddressLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Server address:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="serverJoinAddress"/>
</item>
</layout>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QRadioButton" name="serverJoinAddressButton">
<property name="text">
<string>Server address:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="serverJoinAddress"/>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="worldJoinButton">
<property name="text">
<string>Singleplayer world</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="worldsCb"/>
</item>
</layout>
</widget>

View File

@@ -168,7 +168,7 @@ class ServersModel : public QAbstractListModel {
m_saveTimer.setInterval(5000);
connect(&m_saveTimer, &QTimer::timeout, this, &ServersModel::save_internal);
}
virtual ~ServersModel() {};
virtual ~ServersModel() = default;
void observe()
{
@@ -731,7 +731,7 @@ void ServersPage::on_actionMove_Down_triggered()
void ServersPage::on_actionJoin_triggered()
{
const auto& address = m_model->at(currentServer)->m_address;
APPLICATION->launch(m_inst, true, false, std::make_shared<MinecraftServerTarget>(MinecraftServerTarget::parse(address)));
APPLICATION->launch(m_inst, true, false, std::make_shared<MinecraftTarget>(MinecraftTarget::parse(address, false)));
}
#include "ServersPage.moc"

View File

@@ -82,7 +82,7 @@ class WorldListProxyModel : public QSortFilterProxyModel {
}
};
WorldListPage::WorldListPage(BaseInstance* inst, std::shared_ptr<WorldList> worlds, QWidget* parent)
WorldListPage::WorldListPage(InstancePtr inst, std::shared_ptr<WorldList> worlds, QWidget* parent)
: QMainWindow(parent), m_inst(inst), ui(new Ui::WorldListPage), m_worlds(worlds)
{
ui->setupUi(this);
@@ -113,6 +113,11 @@ void WorldListPage::openedImpl()
{
m_worlds->startWatching();
auto mInst = std::dynamic_pointer_cast<MinecraftInstance>(m_inst);
if (!mInst || !mInst->traits().contains("feature:is_quick_play_singleplayer")) {
ui->toolBar->removeAction(ui->actionJoin);
}
auto const setting_name = QString("WideBarVisibility_%1").arg(id());
if (!APPLICATION->settings()->contains(setting_name))
m_wide_bar_setting = APPLICATION->settings()->registerSetting(setting_name);
@@ -339,6 +344,14 @@ void WorldListPage::worldChanged([[maybe_unused]] const QModelIndex& current, [[
ui->actionDatapacks->setEnabled(enable);
bool hasIcon = !index.data(WorldList::IconFileRole).isNull();
ui->actionReset_Icon->setEnabled(enable && hasIcon);
auto mInst = std::dynamic_pointer_cast<MinecraftInstance>(m_inst);
auto supportsJoin = mInst && mInst->traits().contains("feature:is_quick_play_singleplayer");
ui->actionJoin->setEnabled(enable && supportsJoin);
if (!supportsJoin) {
ui->toolBar->removeAction(ui->actionJoin);
}
}
void WorldListPage::on_actionAdd_triggered()
@@ -418,4 +431,15 @@ void WorldListPage::on_actionRefresh_triggered()
m_worlds->update();
}
void WorldListPage::on_actionJoin_triggered()
{
QModelIndex index = getSelectedWorld();
if (!index.isValid()) {
return;
}
auto worldVariant = m_worlds->data(index, WorldList::ObjectRole);
auto world = (World*)worldVariant.value<void*>();
APPLICATION->launch(m_inst, true, false, std::make_shared<MinecraftTarget>(MinecraftTarget::parse(world->folderName(), true)));
}
#include "WorldListPage.moc"

View File

@@ -53,7 +53,7 @@ class WorldListPage : public QMainWindow, public BasePage {
Q_OBJECT
public:
explicit WorldListPage(BaseInstance* inst, std::shared_ptr<WorldList> worlds, QWidget* parent = 0);
explicit WorldListPage(InstancePtr inst, std::shared_ptr<WorldList> worlds, QWidget* parent = 0);
virtual ~WorldListPage();
virtual QString displayName() const override { return tr("Worlds"); }
@@ -72,7 +72,7 @@ class WorldListPage : public QMainWindow, public BasePage {
QMenu* createPopupMenu() override;
protected:
BaseInstance* m_inst;
InstancePtr m_inst;
private:
QModelIndex getSelectedWorld();
@@ -101,6 +101,7 @@ class WorldListPage : public QMainWindow, public BasePage {
void on_actionReset_Icon_triggered();
void worldChanged(const QModelIndex& current, const QModelIndex& previous);
void mceditState(LoggedProcess::State state);
void on_actionJoin_triggered();
void ShowContextMenu(const QPoint& pos);
};

View File

@@ -81,6 +81,7 @@
</attribute>
<addaction name="actionAdd"/>
<addaction name="separator"/>
<addaction name="actionJoin"/>
<addaction name="actionRename"/>
<addaction name="actionCopy"/>
<addaction name="actionRemove"/>
@@ -97,6 +98,11 @@
<string>Add</string>
</property>
</action>
<action name="actionJoin">
<property name="text">
<string>Join</string>
</property>
</action>
<action name="actionRename">
<property name="text">
<string>Rename</string>

View File

@@ -321,14 +321,9 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
updateUi();
}
void ResourcePage::onVersionSelectionChanged(QString versionData)
void ResourcePage::onVersionSelectionChanged(int index)
{
if (versionData.isNull() || versionData.isEmpty()) {
m_selected_version_index = -1;
return;
}
m_selected_version_index = m_ui->versionSelectionBox->currentData().toInt();
m_selected_version_index = index;
updateSelectionButton();
}

View File

@@ -89,7 +89,7 @@ class ResourcePage : public QWidget, public BasePage {
virtual void triggerSearch() = 0;
void onSelectionChanged(QModelIndex first, QModelIndex second);
void onVersionSelectionChanged(QString data);
void onVersionSelectionChanged(int index);
void onResourceSelected();
// NOTE: Can't use [[nodiscard]] here because of https://bugreports.qt.io/browse/QTBUG-58628 on Qt 5.12

View File

@@ -84,7 +84,7 @@ FlamePage::FlamePage(NewInstanceDialog* dialog, QWidget* parent)
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlamePage::onSelectionChanged);
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlamePage::onVersionSelectionChanged);
connect(ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FlamePage::onVersionSelectionChanged);
ui->packView->setItemDelegate(new ProjectItemDelegate(this));
ui->packDescription->setMetaEntry("FlamePacks");
@@ -240,17 +240,17 @@ void FlamePage::suggestCurrent()
[this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); });
}
void FlamePage::onVersionSelectionChanged(QString version)
void FlamePage::onVersionSelectionChanged(int index)
{
bool is_blocked = false;
ui->versionSelectionBox->currentData().toInt(&is_blocked);
if (version.isNull() || version.isEmpty() || is_blocked) {
if (index == -1 || is_blocked) {
m_selected_version_index = -1;
return;
}
m_selected_version_index = ui->versionSelectionBox->currentIndex();
m_selected_version_index = index;
Q_ASSERT(current.versions.at(m_selected_version_index).downloadUrl == ui->versionSelectionBox->currentData().toString());

View File

@@ -78,7 +78,7 @@ class FlamePage : public QWidget, public BasePage {
private slots:
void triggerSearch();
void onSelectionChanged(QModelIndex first, QModelIndex second);
void onVersionSelectionChanged(QString data);
void onVersionSelectionChanged(int index);
private:
Ui::FlamePage* ui = nullptr;

View File

@@ -60,7 +60,7 @@ FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance& instance) :
// so it's best not to connect them in the parent's contructor...
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameModPage::onSelectionChanged);
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameModPage::onVersionSelectionChanged);
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FlameModPage::onVersionSelectionChanged);
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &FlameModPage::onResourceSelected);
m_ui->packDescription->setMetaEntry(metaEntryBase());
@@ -94,7 +94,8 @@ FlameResourcePackPage::FlameResourcePackPage(ResourcePackDownloadDialog* dialog,
// so it's best not to connect them in the parent's contructor...
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameResourcePackPage::onSelectionChanged);
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameResourcePackPage::onVersionSelectionChanged);
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&FlameResourcePackPage::onVersionSelectionChanged);
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &FlameResourcePackPage::onResourceSelected);
m_ui->packDescription->setMetaEntry(metaEntryBase());
@@ -128,7 +129,8 @@ FlameTexturePackPage::FlameTexturePackPage(TexturePackDownloadDialog* dialog, Ba
// so it's best not to connect them in the parent's contructor...
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameTexturePackPage::onSelectionChanged);
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameTexturePackPage::onVersionSelectionChanged);
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&FlameTexturePackPage::onVersionSelectionChanged);
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &FlameTexturePackPage::onResourceSelected);
m_ui->packDescription->setMetaEntry(metaEntryBase());
@@ -162,7 +164,8 @@ FlameShaderPackPage::FlameShaderPackPage(ShaderPackDownloadDialog* dialog, BaseI
// so it's best not to connect them in the parent's constructor...
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FlameShaderPackPage::onSelectionChanged);
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FlameShaderPackPage::onVersionSelectionChanged);
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&FlameShaderPackPage::onVersionSelectionChanged);
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &FlameShaderPackPage::onResourceSelected);
m_ui->packDescription->setMetaEntry(metaEntryBase());

View File

@@ -85,7 +85,7 @@ ModrinthPage::ModrinthPage(NewInstanceDialog* dialog, QWidget* parent)
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthPage::onSelectionChanged);
connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthPage::onVersionSelectionChanged);
connect(ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ModrinthPage::onVersionSelectionChanged);
ui->packView->setItemDelegate(new ProjectItemDelegate(this));
ui->packDescription->setMetaEntry(metaEntryBase());
@@ -342,9 +342,9 @@ void ModrinthPage::triggerSearch()
m_fetch_progress.watch(m_model->activeSearchJob().get());
}
void ModrinthPage::onVersionSelectionChanged(QString version)
void ModrinthPage::onVersionSelectionChanged(int index)
{
if (version.isNull() || version.isEmpty()) {
if (index == -1) {
selectedVersion = "";
return;
}

View File

@@ -80,7 +80,7 @@ class ModrinthPage : public QWidget, public BasePage {
private slots:
void onSelectionChanged(QModelIndex first, QModelIndex second);
void onVersionSelectionChanged(QString data);
void onVersionSelectionChanged(int index);
void triggerSearch();
private:

View File

@@ -58,7 +58,8 @@ ModrinthModPage::ModrinthModPage(ModDownloadDialog* dialog, BaseInstance& instan
// so it's best not to connect them in the parent's constructor...
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthModPage::onSelectionChanged);
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthModPage::onVersionSelectionChanged);
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ModrinthModPage::onVersionSelectionChanged);
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &ModrinthModPage::onResourceSelected);
m_ui->packDescription->setMetaEntry(metaEntryBase());
@@ -76,7 +77,8 @@ ModrinthResourcePackPage::ModrinthResourcePackPage(ResourcePackDownloadDialog* d
// so it's best not to connect them in the parent's constructor...
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthResourcePackPage::onSelectionChanged);
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthResourcePackPage::onVersionSelectionChanged);
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ModrinthResourcePackPage::onVersionSelectionChanged);
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &ModrinthResourcePackPage::onResourceSelected);
m_ui->packDescription->setMetaEntry(metaEntryBase());
@@ -94,7 +96,8 @@ ModrinthTexturePackPage::ModrinthTexturePackPage(TexturePackDownloadDialog* dial
// so it's best not to connect them in the parent's constructor...
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthTexturePackPage::onSelectionChanged);
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthTexturePackPage::onVersionSelectionChanged);
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ModrinthTexturePackPage::onVersionSelectionChanged);
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &ModrinthTexturePackPage::onResourceSelected);
m_ui->packDescription->setMetaEntry(metaEntryBase());
@@ -112,7 +115,8 @@ ModrinthShaderPackPage::ModrinthShaderPackPage(ShaderPackDownloadDialog* dialog,
// so it's best not to connect them in the parent's constructor...
connect(m_ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthShaderPackPage::onSelectionChanged);
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &ModrinthShaderPackPage::onVersionSelectionChanged);
connect(m_ui->versionSelectionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&ModrinthShaderPackPage::onVersionSelectionChanged);
connect(m_ui->resourceSelectionButton, &QPushButton::clicked, this, &ModrinthShaderPackPage::onResourceSelected);
m_ui->packDescription->setMetaEntry(metaEntryBase());