mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-10-03 16:51:30 +00:00
NOISSUE Add support for launching worlds directly via Quick Play
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
#include "java/JavaInstallList.h"
|
||||
#include "FileSystem.h"
|
||||
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "minecraft/VersionFilterData.h"
|
||||
#include "minecraft/WorldList.h"
|
||||
|
||||
InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
|
||||
: QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)
|
||||
@@ -27,6 +31,23 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
|
||||
connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked);
|
||||
connect(APPLICATION, &Application::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings);
|
||||
connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
|
||||
|
||||
auto *mcInst = dynamic_cast<MinecraftInstance *>(inst);
|
||||
if (mcInst && mcInst->getPackProfile()->getComponent("net.minecraft")->getReleaseDateTime() >= g_VersionFilterData.quickPlayBeginsDate)
|
||||
{
|
||||
mcInst->worldList()->update();
|
||||
for (const auto &world : mcInst->worldList()->allWorlds())
|
||||
{
|
||||
ui->worldsComboBox->addItem(world.folderName());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->worldRadioButton->setVisible(false);
|
||||
ui->worldsComboBox->setVisible(false);
|
||||
ui->serverAddressRadioButton->setChecked(true);
|
||||
}
|
||||
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
@@ -195,8 +216,12 @@ void InstanceSettingsPage::applySettings()
|
||||
}
|
||||
|
||||
// Join server on launch
|
||||
bool joinServerOnLaunch = ui->serverJoinGroupBox->isChecked();
|
||||
bool joinWorldOnLaunch = ui->quickPlayGroupBox->isChecked();
|
||||
m_settings->set("JoinWorldOnLaunch", joinWorldOnLaunch);
|
||||
|
||||
bool joinServerOnLaunch = ui->serverAddressRadioButton->isChecked();
|
||||
m_settings->set("JoinServerOnLaunch", joinServerOnLaunch);
|
||||
|
||||
if (joinServerOnLaunch)
|
||||
{
|
||||
m_settings->set("JoinServerOnLaunchAddress", ui->serverJoinAddress->text());
|
||||
@@ -205,6 +230,18 @@ void InstanceSettingsPage::applySettings()
|
||||
{
|
||||
m_settings->reset("JoinServerOnLaunchAddress");
|
||||
}
|
||||
|
||||
bool joinSingleplayerWorldOnLaunch = ui->worldRadioButton->isChecked();
|
||||
m_settings->set("JoinSingleplayerWorldOnLaunch", joinSingleplayerWorldOnLaunch);
|
||||
|
||||
if (joinSingleplayerWorldOnLaunch)
|
||||
{
|
||||
m_settings->set("JoinSingleplayerWorldOnLaunchName", ui->worldsComboBox->currentText());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_settings->reset("JoinSingleplayerWorldOnLaunchName");
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceSettingsPage::loadSettings()
|
||||
@@ -272,8 +309,23 @@ void InstanceSettingsPage::loadSettings()
|
||||
ui->showGameTime->setChecked(m_settings->get("ShowGameTime").toBool());
|
||||
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 (!m_settings->contains("JoinWorldOnLaunch"))
|
||||
{
|
||||
ui->quickPlayGroupBox->setChecked(m_settings->get("JoinServerOnLaunch").toBool());
|
||||
ui->serverAddressRadioButton->setChecked(m_settings->get("JoinServerOnLaunch").toBool());
|
||||
ui->worldRadioButton->setChecked(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->quickPlayGroupBox->setChecked(m_settings->get("JoinWorldOnLaunch").toBool());
|
||||
ui->serverAddressRadioButton->setChecked(m_settings->get("JoinServerOnLaunch").toBool());
|
||||
ui->serverJoinAddress->setEnabled(m_settings->get("JoinServerOnLaunch").toBool());
|
||||
ui->serverJoinAddress->setText(m_settings->get("JoinServerOnLaunchAddress").toString());
|
||||
ui->worldRadioButton->setChecked(m_settings->get("JoinSingleplayerWorldOnLaunch").toBool());
|
||||
ui->worldsComboBox->setEnabled(m_settings->get("JoinSingleplayerWorldOnLaunch").toBool());
|
||||
ui->worldsComboBox->setCurrentText(m_settings->get("JoinSingleplayerWorldOnLaunchName").toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void InstanceSettingsPage::on_javaDetectBtn_clicked()
|
||||
@@ -334,6 +386,16 @@ void InstanceSettingsPage::on_javaTestBtn_clicked()
|
||||
checker->run();
|
||||
}
|
||||
|
||||
void InstanceSettingsPage::on_serverAddressRadioButton_toggled(bool checked)
|
||||
{
|
||||
ui->serverJoinAddress->setEnabled(checked);
|
||||
}
|
||||
|
||||
void InstanceSettingsPage::on_worldRadioButton_toggled(bool checked)
|
||||
{
|
||||
ui->worldsComboBox->setEnabled(checked);
|
||||
}
|
||||
|
||||
void InstanceSettingsPage::checkerFinished()
|
||||
{
|
||||
checker.reset();
|
||||
|
@@ -22,6 +22,7 @@
|
||||
#include <QObjectPtr.h>
|
||||
#include "ui/pages/BasePage.h"
|
||||
#include "JavaCommon.h"
|
||||
#include "minecraft/WorldList.h"
|
||||
#include "Application.h"
|
||||
|
||||
class JavaChecker;
|
||||
@@ -60,6 +61,8 @@ private slots:
|
||||
void on_javaDetectBtn_clicked();
|
||||
void on_javaTestBtn_clicked();
|
||||
void on_javaBrowseBtn_clicked();
|
||||
void on_serverAddressRadioButton_toggled(bool checked);
|
||||
void on_worldRadioButton_toggled(bool checked);
|
||||
|
||||
void applySettings();
|
||||
void loadSettings();
|
||||
|
@@ -39,7 +39,7 @@
|
||||
<enum>QTabWidget::Rounded</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>4</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="minecraftTab">
|
||||
<attribute name="title">
|
||||
@@ -454,9 +454,9 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="serverJoinGroupBox">
|
||||
<widget class="QGroupBox" name="quickPlayGroupBox">
|
||||
<property name="title">
|
||||
<string>Set a server to join on launch</string>
|
||||
<string>Set a world to join on launch</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
@@ -466,15 +466,9 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_11">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="serverJoinLayout">
|
||||
<layout class="QGridLayout" name="quickPlayLayout">
|
||||
<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>
|
||||
<widget class="QRadioButton" name="serverAddressRadioButton">
|
||||
<property name="text">
|
||||
<string>Server address:</string>
|
||||
</property>
|
||||
@@ -483,6 +477,16 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="serverJoinAddress"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QRadioButton" name="worldRadioButton">
|
||||
<property name="text">
|
||||
<string>Singleplayer world:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="worldsComboBox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
@@ -762,7 +762,8 @@ 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, nullptr, std::make_shared<MinecraftServerTarget>(MinecraftServerTarget::parse(address)));
|
||||
APPLICATION->launch(m_inst, true, nullptr, std::make_shared<QuickPlayTarget>(
|
||||
QuickPlayTarget::parseMultiplayer(address)));
|
||||
}
|
||||
|
||||
#include "ServersPage.moc"
|
||||
|
@@ -24,7 +24,6 @@
|
||||
#include <QMessageBox>
|
||||
#include <QTreeView>
|
||||
#include <QInputDialog>
|
||||
#include <QProcess>
|
||||
|
||||
#include "tools/MCEditTool.h"
|
||||
#include "FileSystem.h"
|
||||
@@ -32,6 +31,9 @@
|
||||
#include "ui/GuiUtil.h"
|
||||
#include "DesktopServices.h"
|
||||
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "minecraft/VersionFilterData.h"
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
|
||||
@@ -62,7 +64,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
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);
|
||||
@@ -311,8 +313,15 @@ void WorldListPage::mceditState(LoggedProcess::State state)
|
||||
|
||||
void WorldListPage::worldChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
auto mcInst = std::dynamic_pointer_cast<MinecraftInstance>(m_inst);
|
||||
bool enableJoinActions = mcInst && mcInst->getPackProfile()->getComponent("net.minecraft")->getReleaseDateTime() >= g_VersionFilterData.quickPlayBeginsDate;
|
||||
|
||||
QModelIndex index = getSelectedWorld();
|
||||
bool enable = index.isValid();
|
||||
// FIXME: Hide the join buttons if the Minecraft version is too old instead of just disabling them.
|
||||
// ui->actionJoin->setVisible(false) had no effect for some reason, at least on my machine -arthomnix
|
||||
ui->actionJoin->setEnabled(enable && enableJoinActions);
|
||||
ui->actionJoinOffline->setEnabled(enable && enableJoinActions);
|
||||
ui->actionCopy_Seed->setEnabled(enable);
|
||||
ui->actionMCEdit->setEnabled(enable);
|
||||
ui->actionRemove->setEnabled(enable);
|
||||
@@ -409,4 +418,29 @@ void WorldListPage::on_actionRefresh_triggered()
|
||||
m_worlds->update();
|
||||
}
|
||||
|
||||
void WorldListPage::joinSelectedWorld(bool online)
|
||||
{
|
||||
auto index = getSelectedWorld();
|
||||
if (!index.isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto worldVariant = m_worlds->data(index, WorldList::ObjectRole);
|
||||
auto world = (World *) worldVariant.value<void *>();
|
||||
auto name = world->folderName();
|
||||
|
||||
APPLICATION->launch(m_inst, online, nullptr, std::make_shared<QuickPlayTarget>(QuickPlayTarget::parseSingleplayer(name)));
|
||||
}
|
||||
|
||||
void WorldListPage::on_actionJoin_triggered()
|
||||
{
|
||||
joinSelectedWorld(true);
|
||||
}
|
||||
|
||||
void WorldListPage::on_actionJoinOffline_triggered()
|
||||
{
|
||||
joinSelectedWorld(false);
|
||||
}
|
||||
|
||||
#include "WorldListPage.moc"
|
||||
|
@@ -34,7 +34,7 @@ class WorldListPage : public QMainWindow, public BasePage
|
||||
|
||||
public:
|
||||
explicit WorldListPage(
|
||||
BaseInstance *inst,
|
||||
InstancePtr inst,
|
||||
std::shared_ptr<WorldList> worlds,
|
||||
QWidget *parent = 0
|
||||
);
|
||||
@@ -67,13 +67,14 @@ protected:
|
||||
QMenu * createPopupMenu() override;
|
||||
|
||||
protected:
|
||||
BaseInstance *m_inst;
|
||||
InstancePtr m_inst;
|
||||
|
||||
private:
|
||||
QModelIndex getSelectedWorld();
|
||||
bool isWorldSafe(QModelIndex index);
|
||||
bool worldSafetyNagQuestion();
|
||||
void mceditError();
|
||||
void joinSelectedWorld(bool online);
|
||||
|
||||
private:
|
||||
Ui::WorldListPage *ui;
|
||||
@@ -92,6 +93,8 @@ private slots:
|
||||
void on_actionView_Folder_triggered();
|
||||
void on_actionDatapacks_triggered();
|
||||
void on_actionReset_Icon_triggered();
|
||||
void on_actionJoin_triggered();
|
||||
void on_actionJoinOffline_triggered();
|
||||
void worldChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void mceditState(LoggedProcess::State state);
|
||||
|
||||
|
@@ -81,6 +81,9 @@
|
||||
</attribute>
|
||||
<addaction name="actionAdd"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionJoin" />
|
||||
<addaction name="actionJoinOffline" />
|
||||
<addaction name="separator" />
|
||||
<addaction name="actionRename"/>
|
||||
<addaction name="actionCopy"/>
|
||||
<addaction name="actionRemove"/>
|
||||
@@ -97,6 +100,22 @@
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionJoin">
|
||||
<property name="text">
|
||||
<string>Join</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Launch the instance directly into the selected world</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionJoinOffline">
|
||||
<property name="text">
|
||||
<string>Join offline</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Launch the instance in offline mode directly into the selected world</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRename">
|
||||
<property name="text">
|
||||
<string>Rename</string>
|
||||
|
Reference in New Issue
Block a user