Merge pull request #903 from jopejoe1/demo-launch

This commit is contained in:
Sefa Eyeoglu 2022-09-18 14:41:25 +02:00 committed by GitHub
commit 098327f128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 105 additions and 13 deletions

View File

@ -1041,7 +1041,7 @@ void Application::performMainStartupAction()
qDebug() << " Launching with account" << m_profileToUse; qDebug() << " Launching with account" << m_profileToUse;
} }
launch(inst, true, nullptr, serverToJoin, accountToUse); launch(inst, true, false, nullptr, serverToJoin, accountToUse);
return; return;
} }
} }
@ -1145,6 +1145,7 @@ void Application::messageReceived(const QByteArray& message)
launch( launch(
instance, instance,
true, true,
false,
nullptr, nullptr,
serverObject, serverObject,
accountObject accountObject
@ -1245,6 +1246,7 @@ bool Application::openJsonEditor(const QString &filename)
bool Application::launch( bool Application::launch(
InstancePtr instance, InstancePtr instance,
bool online, bool online,
bool demo,
BaseProfilerFactory *profiler, BaseProfilerFactory *profiler,
MinecraftServerTargetPtr serverToJoin, MinecraftServerTargetPtr serverToJoin,
MinecraftAccountPtr accountToUse MinecraftAccountPtr accountToUse
@ -1268,6 +1270,7 @@ bool Application::launch(
controller.reset(new LaunchController()); controller.reset(new LaunchController());
controller->setInstance(instance); controller->setInstance(instance);
controller->setOnline(online); controller->setOnline(online);
controller->setDemo(demo);
controller->setProfiler(profiler); controller->setProfiler(profiler);
controller->setServerToJoin(serverToJoin); controller->setServerToJoin(serverToJoin);
controller->setAccountToUse(accountToUse); controller->setAccountToUse(accountToUse);

View File

@ -213,6 +213,7 @@ public slots:
bool launch( bool launch(
InstancePtr instance, InstancePtr instance,
bool online = true, bool online = true,
bool demo = false,
BaseProfilerFactory *profiler = nullptr, BaseProfilerFactory *profiler = nullptr,
MinecraftServerTargetPtr serverToJoin = nullptr, MinecraftServerTargetPtr serverToJoin = nullptr,
MinecraftAccountPtr accountToUse = nullptr MinecraftAccountPtr accountToUse = nullptr

View File

@ -167,6 +167,7 @@ void LaunchController::login() {
tries++; tries++;
m_session = std::make_shared<AuthSession>(); m_session = std::make_shared<AuthSession>();
m_session->wants_online = m_online; m_session->wants_online = m_online;
m_session->demo = m_demo;
m_accountToUse->fillSession(m_session); m_accountToUse->fillSession(m_session);
// Launch immediately in true offline mode // Launch immediately in true offline mode
@ -184,12 +185,18 @@ void LaunchController::login() {
if(!m_session->wants_online) { if(!m_session->wants_online) {
// we ask the user for a player name // we ask the user for a player name
bool ok = false; bool ok = false;
QString message = tr("Choose your offline mode player name.");
if(m_session->demo) {
message = tr("Choose your demo mode player name.");
}
QString lastOfflinePlayerName = APPLICATION->settings()->get("LastOfflinePlayerName").toString(); QString lastOfflinePlayerName = APPLICATION->settings()->get("LastOfflinePlayerName").toString();
QString usedname = lastOfflinePlayerName.isEmpty() ? m_session->player_name : lastOfflinePlayerName; QString usedname = lastOfflinePlayerName.isEmpty() ? m_session->player_name : lastOfflinePlayerName;
QString name = QInputDialog::getText( QString name = QInputDialog::getText(
m_parentWidget, m_parentWidget,
tr("Player name"), tr("Player name"),
tr("Choose your offline mode player name."), message,
QLineEdit::Normal, QLineEdit::Normal,
usedname, usedname,
&ok &ok
@ -369,7 +376,7 @@ void LaunchController::launchInstance()
} }
m_launcher->prependStep(new TextPrint(m_launcher.get(), resolved_servers, MessageLevel::Launcher)); m_launcher->prependStep(new TextPrint(m_launcher.get(), resolved_servers, MessageLevel::Launcher));
} else { } else {
online_mode = "offline"; online_mode = m_demo ? "demo" : "offline";
} }
m_launcher->prependStep(new TextPrint(m_launcher.get(), "Launched instance in " + online_mode + " mode\n", MessageLevel::Launcher)); m_launcher->prependStep(new TextPrint(m_launcher.get(), "Launched instance in " + online_mode + " mode\n", MessageLevel::Launcher));

View File

@ -63,6 +63,10 @@ public:
m_online = online; m_online = online;
} }
void setDemo(bool demo) {
m_demo = demo;
}
void setProfiler(BaseProfilerFactory *profiler) { void setProfiler(BaseProfilerFactory *profiler) {
m_profiler = profiler; m_profiler = profiler;
} }
@ -101,6 +105,7 @@ private slots:
private: private:
BaseProfilerFactory *m_profiler = nullptr; BaseProfilerFactory *m_profiler = nullptr;
bool m_online = true; bool m_online = true;
bool m_demo = false;
InstancePtr m_instance; InstancePtr m_instance;
QWidget * m_parentWidget = nullptr; QWidget * m_parentWidget = nullptr;
InstanceWindow *m_console = nullptr; InstanceWindow *m_console = nullptr;

View File

@ -245,6 +245,14 @@ QString MinecraftInstance::getLocalLibraryPath() const
return libraries_dir.absolutePath(); return libraries_dir.absolutePath();
} }
bool MinecraftInstance::supportsDemo() const
{
Version instance_ver { getPackProfile()->getComponentVersion("net.minecraft") };
// Demo mode was introduced in 1.3.1: https://minecraft.fandom.com/wiki/Demo_mode#History
// FIXME: Due to Version constraints atm, this can't handle well non-release versions
return instance_ver >= Version("1.3.1");
}
QString MinecraftInstance::jarModsDir() const QString MinecraftInstance::jarModsDir() const
{ {
QDir jarmods_dir(FS::PathCombine(instanceRoot(), "jarmods/")); QDir jarmods_dir(FS::PathCombine(instanceRoot(), "jarmods/"));

View File

@ -69,6 +69,8 @@ public:
// where the instance-local libraries should be // where the instance-local libraries should be
QString getLocalLibraryPath() const; QString getLocalLibraryPath() const;
/** Returns whether the instance, with its version, has support for demo mode. */
[[nodiscard]] bool supportsDemo() const;
////// Profile management ////// ////// Profile management //////
std::shared_ptr<PackProfile> getPackProfile() const; std::shared_ptr<PackProfile> getPackProfile() const;

View File

@ -95,8 +95,14 @@ InstanceWindow::InstanceWindow(InstancePtr instance, QWidget *parent)
m_launchOfflineButton = new QPushButton(); m_launchOfflineButton = new QPushButton();
horizontalLayout->addWidget(m_launchOfflineButton); horizontalLayout->addWidget(m_launchOfflineButton);
m_launchOfflineButton->setText(tr("Launch Offline")); m_launchOfflineButton->setText(tr("Launch Offline"));
m_launchDemoButton = new QPushButton();
horizontalLayout->addWidget(m_launchDemoButton);
m_launchDemoButton->setText(tr("Launch Demo"));
updateLaunchButtons(); updateLaunchButtons();
connect(m_launchOfflineButton, SIGNAL(clicked(bool)), SLOT(on_btnLaunchMinecraftOffline_clicked())); connect(m_launchOfflineButton, SIGNAL(clicked(bool)), SLOT(on_btnLaunchMinecraftOffline_clicked()));
connect(m_launchDemoButton, SIGNAL(clicked(bool)), SLOT(on_btnLaunchMinecraftDemo_clicked()));
m_closeButton = new QPushButton(); m_closeButton = new QPushButton();
m_closeButton->setText(tr("Close")); m_closeButton->setText(tr("Close"));
@ -143,6 +149,7 @@ void InstanceWindow::updateLaunchButtons()
if(m_instance->isRunning()) if(m_instance->isRunning())
{ {
m_launchOfflineButton->setEnabled(false); m_launchOfflineButton->setEnabled(false);
m_launchDemoButton->setEnabled(false);
m_killButton->setText(tr("Kill")); m_killButton->setText(tr("Kill"));
m_killButton->setObjectName("killButton"); m_killButton->setObjectName("killButton");
m_killButton->setToolTip(tr("Kill the running instance")); m_killButton->setToolTip(tr("Kill the running instance"));
@ -150,6 +157,7 @@ void InstanceWindow::updateLaunchButtons()
else if(!m_instance->canLaunch()) else if(!m_instance->canLaunch())
{ {
m_launchOfflineButton->setEnabled(false); m_launchOfflineButton->setEnabled(false);
m_launchDemoButton->setEnabled(false);
m_killButton->setText(tr("Launch")); m_killButton->setText(tr("Launch"));
m_killButton->setObjectName("launchButton"); m_killButton->setObjectName("launchButton");
m_killButton->setToolTip(tr("Launch the instance")); m_killButton->setToolTip(tr("Launch the instance"));
@ -158,6 +166,13 @@ void InstanceWindow::updateLaunchButtons()
else else
{ {
m_launchOfflineButton->setEnabled(true); m_launchOfflineButton->setEnabled(true);
// Disable demo-mode if not available.
auto instance = dynamic_cast<MinecraftInstance*>(m_instance.get());
if (instance) {
m_launchDemoButton->setEnabled(instance->supportsDemo());
}
m_killButton->setText(tr("Launch")); m_killButton->setText(tr("Launch"));
m_killButton->setObjectName("launchButton"); m_killButton->setObjectName("launchButton");
m_killButton->setToolTip(tr("Launch the instance")); m_killButton->setToolTip(tr("Launch the instance"));
@ -169,7 +184,12 @@ void InstanceWindow::updateLaunchButtons()
void InstanceWindow::on_btnLaunchMinecraftOffline_clicked() void InstanceWindow::on_btnLaunchMinecraftOffline_clicked()
{ {
APPLICATION->launch(m_instance, false, nullptr); APPLICATION->launch(m_instance, false, false, nullptr);
}
void InstanceWindow::on_btnLaunchMinecraftDemo_clicked()
{
APPLICATION->launch(m_instance, false, true, nullptr);
} }
void InstanceWindow::instanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> proc) void InstanceWindow::instanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> proc)
@ -223,7 +243,7 @@ void InstanceWindow::on_btnKillMinecraft_clicked()
} }
else else
{ {
APPLICATION->launch(m_instance, true, nullptr); APPLICATION->launch(m_instance, true, false, nullptr);
} }
} }

View File

@ -74,6 +74,7 @@ slots:
void on_closeButton_clicked(); void on_closeButton_clicked();
void on_btnKillMinecraft_clicked(); void on_btnKillMinecraft_clicked();
void on_btnLaunchMinecraftOffline_clicked(); void on_btnLaunchMinecraftOffline_clicked();
void on_btnLaunchMinecraftDemo_clicked();
void instanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> proc); void instanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> proc);
void runningStateChanged(bool running); void runningStateChanged(bool running);
@ -93,4 +94,5 @@ private:
QPushButton *m_closeButton = nullptr; QPushButton *m_closeButton = nullptr;
QPushButton *m_killButton = nullptr; QPushButton *m_killButton = nullptr;
QPushButton *m_launchOfflineButton = nullptr; QPushButton *m_launchOfflineButton = nullptr;
QPushButton *m_launchDemoButton = nullptr;
}; };

View File

@ -240,6 +240,7 @@ public:
TranslatedAction actionCAT; TranslatedAction actionCAT;
TranslatedAction actionCopyInstance; TranslatedAction actionCopyInstance;
TranslatedAction actionLaunchInstanceOffline; TranslatedAction actionLaunchInstanceOffline;
TranslatedAction actionLaunchInstanceDemo;
TranslatedAction actionScreenshots; TranslatedAction actionScreenshots;
TranslatedAction actionExportInstance; TranslatedAction actionExportInstance;
QVector<TranslatedAction *> all_actions; QVector<TranslatedAction *> all_actions;
@ -499,6 +500,7 @@ public:
fileMenu->addAction(actionAddInstance); fileMenu->addAction(actionAddInstance);
fileMenu->addAction(actionLaunchInstance); fileMenu->addAction(actionLaunchInstance);
fileMenu->addAction(actionLaunchInstanceOffline); fileMenu->addAction(actionLaunchInstanceOffline);
fileMenu->addAction(actionLaunchInstanceDemo);
fileMenu->addAction(actionKillInstance); fileMenu->addAction(actionKillInstance);
fileMenu->addAction(actionCloseWindow); fileMenu->addAction(actionCloseWindow);
fileMenu->addSeparator(); fileMenu->addSeparator();
@ -669,6 +671,12 @@ public:
actionLaunchInstanceOffline.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance in offline mode.")); actionLaunchInstanceOffline.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance in offline mode."));
all_actions.append(&actionLaunchInstanceOffline); all_actions.append(&actionLaunchInstanceOffline);
actionLaunchInstanceDemo = TranslatedAction(MainWindow);
actionLaunchInstanceDemo->setObjectName(QStringLiteral("actionLaunchInstanceDemo"));
actionLaunchInstanceDemo.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Launch &Demo"));
actionLaunchInstanceDemo.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance in demo mode."));
all_actions.append(&actionLaunchInstanceDemo);
actionKillInstance = TranslatedAction(MainWindow); actionKillInstance = TranslatedAction(MainWindow);
actionKillInstance->setObjectName(QStringLiteral("actionKillInstance")); actionKillInstance->setObjectName(QStringLiteral("actionKillInstance"));
actionKillInstance->setDisabled(true); actionKillInstance->setDisabled(true);
@ -1195,6 +1203,7 @@ void MainWindow::updateToolsMenu()
ui->actionLaunchInstance->setDisabled(!m_selectedInstance || currentInstanceRunning); ui->actionLaunchInstance->setDisabled(!m_selectedInstance || currentInstanceRunning);
ui->actionLaunchInstanceOffline->setDisabled(!m_selectedInstance || currentInstanceRunning); ui->actionLaunchInstanceOffline->setDisabled(!m_selectedInstance || currentInstanceRunning);
ui->actionLaunchInstanceDemo->setDisabled(!m_selectedInstance || currentInstanceRunning);
QMenu *launchMenu = ui->actionLaunchInstance->menu(); QMenu *launchMenu = ui->actionLaunchInstance->menu();
QMenu *launchOfflineMenu = ui->actionLaunchInstanceOffline->menu(); QMenu *launchOfflineMenu = ui->actionLaunchInstanceOffline->menu();
@ -1220,23 +1229,37 @@ void MainWindow::updateToolsMenu()
normalLaunch->setShortcut(QKeySequence::Open); normalLaunch->setShortcut(QKeySequence::Open);
QAction *normalLaunchOffline = launchOfflineMenu->addAction(tr("Launch Offline")); QAction *normalLaunchOffline = launchOfflineMenu->addAction(tr("Launch Offline"));
normalLaunchOffline->setShortcut(QKeySequence(tr("Ctrl+Shift+O"))); normalLaunchOffline->setShortcut(QKeySequence(tr("Ctrl+Shift+O")));
QAction *normalLaunchDemo = launchOfflineMenu->addAction(tr("Launch Demo"));
normalLaunchDemo->setShortcut(QKeySequence(tr("Ctrl+Alt+O")));
if (m_selectedInstance) if (m_selectedInstance)
{ {
normalLaunch->setEnabled(m_selectedInstance->canLaunch()); normalLaunch->setEnabled(m_selectedInstance->canLaunch());
normalLaunchOffline->setEnabled(m_selectedInstance->canLaunch()); normalLaunchOffline->setEnabled(m_selectedInstance->canLaunch());
normalLaunchDemo->setEnabled(m_selectedInstance->canLaunch());
connect(normalLaunch, &QAction::triggered, [this]() { connect(normalLaunch, &QAction::triggered, [this]() {
APPLICATION->launch(m_selectedInstance, true); APPLICATION->launch(m_selectedInstance, true, false);
}); });
connect(normalLaunchOffline, &QAction::triggered, [this]() { connect(normalLaunchOffline, &QAction::triggered, [this]() {
APPLICATION->launch(m_selectedInstance, false); APPLICATION->launch(m_selectedInstance, false, false);
});
connect(normalLaunchDemo, &QAction::triggered, [this]() {
APPLICATION->launch(m_selectedInstance, false, true);
}); });
} }
else else
{ {
normalLaunch->setDisabled(true); normalLaunch->setDisabled(true);
normalLaunchOffline->setDisabled(true); normalLaunchOffline->setDisabled(true);
normalLaunchDemo->setDisabled(true);
} }
// Disable demo-mode if not available.
auto instance = dynamic_cast<MinecraftInstance*>(m_selectedInstance.get());
if (instance) {
normalLaunchDemo->setEnabled(instance->supportsDemo());
}
QString profilersTitle = tr("Profilers"); QString profilersTitle = tr("Profilers");
launchMenu->addSeparator()->setText(profilersTitle); launchMenu->addSeparator()->setText(profilersTitle);
launchOfflineMenu->addSeparator()->setText(profilersTitle); launchOfflineMenu->addSeparator()->setText(profilersTitle);
@ -1260,11 +1283,11 @@ void MainWindow::updateToolsMenu()
connect(profilerAction, &QAction::triggered, [this, profiler]() connect(profilerAction, &QAction::triggered, [this, profiler]()
{ {
APPLICATION->launch(m_selectedInstance, true, profiler.get()); APPLICATION->launch(m_selectedInstance, true, false, profiler.get());
}); });
connect(profilerOfflineAction, &QAction::triggered, [this, profiler]() connect(profilerOfflineAction, &QAction::triggered, [this, profiler]()
{ {
APPLICATION->launch(m_selectedInstance, false, profiler.get()); APPLICATION->launch(m_selectedInstance, false, false, profiler.get());
}); });
} }
else else
@ -2096,6 +2119,14 @@ void MainWindow::on_actionLaunchInstanceOffline_triggered()
} }
} }
void MainWindow::on_actionLaunchInstanceDemo_triggered()
{
if (m_selectedInstance)
{
APPLICATION->launch(m_selectedInstance, false, true);
}
}
void MainWindow::on_actionKillInstance_triggered() void MainWindow::on_actionKillInstance_triggered()
{ {
if(m_selectedInstance && m_selectedInstance->isRunning()) if(m_selectedInstance && m_selectedInstance->isRunning())
@ -2139,6 +2170,14 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
ui->setInstanceActionsEnabled(true); ui->setInstanceActionsEnabled(true);
ui->actionLaunchInstance->setEnabled(m_selectedInstance->canLaunch()); ui->actionLaunchInstance->setEnabled(m_selectedInstance->canLaunch());
ui->actionLaunchInstanceOffline->setEnabled(m_selectedInstance->canLaunch()); ui->actionLaunchInstanceOffline->setEnabled(m_selectedInstance->canLaunch());
ui->actionLaunchInstanceDemo->setEnabled(m_selectedInstance->canLaunch());
// Disable demo-mode if not available.
auto instance = dynamic_cast<MinecraftInstance*>(m_selectedInstance.get());
if (instance) {
ui->actionLaunchInstanceDemo->setEnabled(instance->supportsDemo());
}
ui->actionKillInstance->setEnabled(m_selectedInstance->isRunning()); ui->actionKillInstance->setEnabled(m_selectedInstance->isRunning());
ui->actionExportInstance->setEnabled(m_selectedInstance->canExport()); ui->actionExportInstance->setEnabled(m_selectedInstance->canExport());
ui->renameButton->setText(m_selectedInstance->name()); ui->renameButton->setText(m_selectedInstance->name());
@ -2158,6 +2197,7 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
ui->setInstanceActionsEnabled(false); ui->setInstanceActionsEnabled(false);
ui->actionLaunchInstance->setEnabled(false); ui->actionLaunchInstance->setEnabled(false);
ui->actionLaunchInstanceOffline->setEnabled(false); ui->actionLaunchInstanceOffline->setEnabled(false);
ui->actionLaunchInstanceDemo->setEnabled(false);
ui->actionKillInstance->setEnabled(false); ui->actionKillInstance->setEnabled(false);
APPLICATION->settings()->set("SelectedInstance", QString()); APPLICATION->settings()->set("SelectedInstance", QString());
selectionBad(); selectionBad();

View File

@ -140,6 +140,8 @@ private slots:
void on_actionLaunchInstanceOffline_triggered(); void on_actionLaunchInstanceOffline_triggered();
void on_actionLaunchInstanceDemo_triggered();
void on_actionKillInstance_triggered(); void on_actionKillInstance_triggered();
void on_actionDeleteInstance_triggered(); void on_actionDeleteInstance_triggered();

View File

@ -811,7 +811,7 @@ void ServersPage::on_actionMove_Down_triggered()
void ServersPage::on_actionJoin_triggered() void ServersPage::on_actionJoin_triggered()
{ {
const auto &address = m_model->at(currentServer)->m_address; 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, false, nullptr, std::make_shared<MinecraftServerTarget>(MinecraftServerTarget::parse(address)));
} }
#include "ServersPage.moc" #include "ServersPage.moc"

View File

@ -63,7 +63,8 @@ public final class LegacyFrame extends Frame {
int winSizeH, int winSizeH,
boolean maximize, boolean maximize,
String serverAddress, String serverAddress,
String serverPort String serverPort,
boolean isDemo
) { ) {
// Implements support for launching in to multiplayer on classic servers using a mpticket // Implements support for launching in to multiplayer on classic servers using a mpticket
// file generated by an external program and stored in the instance's root folder. // file generated by an external program and stored in the instance's root folder.
@ -106,7 +107,7 @@ public final class LegacyFrame extends Frame {
appletWrap.setParameter("sessionid", session); appletWrap.setParameter("sessionid", session);
appletWrap.setParameter("stand-alone", "true"); // Show the quit button. appletWrap.setParameter("stand-alone", "true"); // Show the quit button.
appletWrap.setParameter("haspaid", "true"); // Some old versions need this for world saves to work. appletWrap.setParameter("haspaid", "true"); // Some old versions need this for world saves to work.
appletWrap.setParameter("demo", "false"); appletWrap.setParameter("demo", isDemo ? "true" : "false");
appletWrap.setParameter("fullscreen", "false"); appletWrap.setParameter("fullscreen", "false");
add(appletWrap); add(appletWrap);

View File

@ -137,7 +137,8 @@ public final class OneSixLauncher implements Launcher {
winSizeH, winSizeH,
maximize, maximize,
serverAddress, serverAddress,
serverPort serverPort,
mcParams.contains("--demo")
); );
return; return;