diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 6eb5e78e..f3b1e5c9 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022 arthomnix + * Copyright 2022-2023 arthomnix * * This source is subject to the Microsoft Public License (MS-PL). * Please see the COPYING.md file for more information. @@ -13,6 +13,8 @@ #include "Application.h" #include "minecraft/auth/AccountList.h" #include "minecraft/MinecraftInstance.h" +#include "minecraft/WorldList.h" +#include "minecraft/VersionFilterData.h" #include "minecraft/PackProfile.h" #include "icons/IconList.h" @@ -43,6 +45,23 @@ CreateShortcutDialog::CreateShortcutDialog(QWidget *parent, InstancePtr instance // TODO: check if version is affected by crashing when joining servers on launch, ideally in meta + auto mcInstance = std::dynamic_pointer_cast(instance); + mcInstance->getPackProfile()->reload(Net::Mode::Offline); + if (mcInstance && mcInstance->getPackProfile()->getComponent("net.minecraft")->getReleaseDateTime() >= g_VersionFilterData.quickPlayBeginsDate) + { + mcInstance->worldList()->update(); + for (const auto &world : mcInstance->worldList()->allWorlds()) + { + ui->joinSingleplayer->addItem(world.folderName()); + } + } + else + { + ui->joinServerRadioButton->setChecked(true); + ui->joinSingleplayerRadioButton->setVisible(false); + ui->joinSingleplayer->setVisible(false); + } + // Macs don't have any concept of a desktop shortcut, so force-enable the option to generate a shell script instead #if defined(Q_OS_UNIX) && !defined(Q_OS_LINUX) ui->createScriptCheckBox->setEnabled(false); @@ -90,16 +109,16 @@ void CreateShortcutDialog::accept() void CreateShortcutDialog::updateDialogState() { - ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok)->setEnabled( !ui->shortcutPath->text().isEmpty() - && (!ui->joinServerCheckBox->isChecked() || !ui->joinServer->text().isEmpty()) + && (!ui->joinWorldCheckBox->isChecked() || ui->joinServerRadioButton->isChecked() || ui->joinSingleplayerRadioButton->isChecked()) + && (!ui->joinServerRadioButton->isChecked() || !ui->joinServer->text().isEmpty()) + && (!ui->joinSingleplayerRadioButton->isChecked() || !ui->joinSingleplayer->currentText().isEmpty()) && (!ui->offlineUsernameCheckBox->isChecked() || !ui->offlineUsername->text().isEmpty()) && (!ui->useProfileCheckBox->isChecked() || !ui->profileComboBox->currentText().isEmpty()) ); - ui->joinServer->setEnabled(ui->joinServerCheckBox->isChecked()); - ui->profileComboBox->setEnabled(ui->useProfileCheckBox->isChecked()); - ui->offlineUsernameCheckBox->setEnabled(ui->launchOfflineCheckBox->isChecked()); + ui->joinServer->setEnabled(ui->joinWorldCheckBox->isChecked() && ui->joinServerRadioButton->isChecked()); + ui->joinSingleplayer->setEnabled(ui->joinWorldCheckBox->isChecked() && ui->joinSingleplayerRadioButton->isChecked()); ui->offlineUsername->setEnabled(ui->launchOfflineCheckBox->isChecked() && ui->offlineUsernameCheckBox->isChecked()); if (!ui->launchOfflineCheckBox->isChecked()) { @@ -117,7 +136,8 @@ QString CreateShortcutDialog::getLaunchArgs(bool escapeQuotesTwice) { return " -d \"" + QDir::toNativeSeparators(QDir::currentPath()).replace('"', escapeQuotesTwice ? "\\\\\"" : "\\\"") + "\"" + " -l \"" + m_instance->id() + "\"" - + (ui->joinServerCheckBox->isChecked() ? " -s \"" + ui->joinServer->text() + "\"" : "") + + (ui->joinServerRadioButton->isChecked() ? " -s \"" + ui->joinServer->text() + "\"" : "") + + (ui->joinSingleplayerRadioButton->isChecked() ? " -w \"" + ui->joinSingleplayer->currentText() + "\"" : "") + (ui->useProfileCheckBox->isChecked() ? " -a \"" + ui->profileComboBox->currentText() + "\"" : "") + (ui->launchOfflineCheckBox->isChecked() ? " -o" : "") + (ui->offlineUsernameCheckBox->isChecked() ? " -n \"" + ui->offlineUsername->text() + "\"" : ""); diff --git a/launcher/ui/dialogs/CreateShortcutDialog.ui b/launcher/ui/dialogs/CreateShortcutDialog.ui index 568bf0a6..59659656 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.ui +++ b/launcher/ui/dialogs/CreateShortcutDialog.ui @@ -1,6 +1,6 @@ @@ -12,7 +12,7 @@ 0 0 796 - 232 + 330 @@ -30,17 +30,82 @@ QLayout::SetDefaultConstraint - + + + + Shortcut path: + + + + + + + Use specific profile: + + + + + + + false + + + + Launch in offline mode - - + + + + false + + + + + - Shortcut path: + Join world on launch: + + + + + + + false + + + + + + + false + + + + + + + + + + false + + + Set offline mode username: + + + + + + + false + + + Singleplayer world: @@ -51,39 +116,16 @@ - - - - - - - - - - - - - Set offline mode username: - - - - - - - Join server on launch: - - - - + + + false + - Use specific profile: + Server address: - - - @@ -173,18 +215,18 @@ - joinServerCheckBox - stateChanged(int) - CreateShortcutDialog - updateDialogState() + joinWorldCheckBox + toggled(bool) + joinServerRadioButton + setEnabled(bool) 122 61 - 397 - 114 + 140 + 93 @@ -284,5 +326,136 @@ + + joinWorldCheckBox + toggled(bool) + joinSingleplayerRadioButton + setEnabled(bool) + + + 140 + 59 + + + 140 + 132 + + + + + joinServerRadioButton + toggled(bool) + joinServer + setEnabled(bool) + + + 140 + 93 + + + 489 + 93 + + + + + joinSingleplayerRadioButton + toggled(bool) + joinSingleplayer + setEnabled(bool) + + + 140 + 132 + + + 489 + 132 + + + + + useProfileCheckBox + toggled(bool) + profileComboBox + setEnabled(bool) + + + 140 + 171 + + + 489 + 171 + + + + + launchOfflineCheckBox + toggled(bool) + offlineUsernameCheckBox + setEnabled(bool) + + + 140 + 205 + + + 140 + 239 + + + + + joinSingleplayer + currentTextChanged(QString) + CreateShortcutDialog + updateDialogState() + + + 489 + 132 + + + 397 + 164 + + + + + joinServerRadioButton + toggled(bool) + CreateShortcutDialog + updateDialogState() + + + 140 + 93 + + + 397 + 164 + + + + + joinSingleplayerRadioButton + toggled(bool) + CreateShortcutDialog + updateDialogState() + + + 140 + 132 + + + 397 + 164 + + + + + updateDialogState() +