aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--launcher/minecraft/MinecraftInstance.cpp8
-rw-r--r--launcher/minecraft/MinecraftInstance.h2
-rw-r--r--launcher/ui/InstanceWindow.cpp8
-rw-r--r--launcher/ui/MainWindow.cpp14
4 files changed, 31 insertions, 1 deletions
diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp
index 9478b1b8..ab904fa2 100644
--- a/launcher/minecraft/MinecraftInstance.cpp
+++ b/launcher/minecraft/MinecraftInstance.cpp
@@ -245,6 +245,14 @@ QString MinecraftInstance::getLocalLibraryPath() const
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
{
QDir jarmods_dir(FS::PathCombine(instanceRoot(), "jarmods/"));
diff --git a/launcher/minecraft/MinecraftInstance.h b/launcher/minecraft/MinecraftInstance.h
index d62ac655..fe39674a 100644
--- a/launcher/minecraft/MinecraftInstance.h
+++ b/launcher/minecraft/MinecraftInstance.h
@@ -69,6 +69,8 @@ public:
// where the instance-local libraries should be
QString getLocalLibraryPath() const;
+ /** Returns whether the instance, with its version, has support for demo mode. */
+ [[nodiscard]] bool supportsDemo() const;
////// Profile management //////
std::shared_ptr<PackProfile> getPackProfile() const;
diff --git a/launcher/ui/InstanceWindow.cpp b/launcher/ui/InstanceWindow.cpp
index 5bf42bb5..09ce0d67 100644
--- a/launcher/ui/InstanceWindow.cpp
+++ b/launcher/ui/InstanceWindow.cpp
@@ -166,7 +166,13 @@ void InstanceWindow::updateLaunchButtons()
else
{
m_launchOfflineButton->setEnabled(true);
- m_launchDemoButton->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->setObjectName("launchButton");
m_killButton->setToolTip(tr("Launch the instance"));
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp
index 9b195d26..58b1ae80 100644
--- a/launcher/ui/MainWindow.cpp
+++ b/launcher/ui/MainWindow.cpp
@@ -1253,6 +1253,13 @@ void MainWindow::updateToolsMenu()
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");
launchMenu->addSeparator()->setText(profilersTitle);
launchOfflineMenu->addSeparator()->setText(profilersTitle);
@@ -2164,6 +2171,13 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
ui->actionLaunchInstance->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->actionExportInstance->setEnabled(m_selectedInstance->canExport());
ui->renameButton->setText(m_selectedInstance->name());