mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 05:07:46 +02:00
add setting for quickplay singleplayer
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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>
|
||||
|
@ -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"
|
||||
|
@ -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);
|
||||
@ -120,6 +120,8 @@ void WorldListPage::openedImpl()
|
||||
m_wide_bar_setting = APPLICATION->settings()->getSetting(setting_name);
|
||||
|
||||
ui->toolBar->setVisibilityState(m_wide_bar_setting->get().toByteArray());
|
||||
auto mInst = std::dynamic_pointer_cast<MinecraftInstance>(m_inst);
|
||||
ui->toolBar->setActionVisible(ui->actionJoin, mInst && mInst->traits().contains("feature:is_quick_play_singleplayer"));
|
||||
}
|
||||
|
||||
void WorldListPage::closedImpl()
|
||||
@ -339,6 +341,9 @@ 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);
|
||||
ui->actionJoin->setEnabled(enable);
|
||||
ui->toolBar->setActionVisible(ui->actionJoin, mInst && mInst->traits().contains("feature:is_quick_play_singleplayer"));
|
||||
}
|
||||
|
||||
void WorldListPage::on_actionAdd_triggered()
|
||||
@ -418,4 +423,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"
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user