aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/ui')
-rw-r--r--launcher/ui/InstanceWindow.cpp24
-rw-r--r--launcher/ui/InstanceWindow.h2
-rw-r--r--launcher/ui/MainWindow.cpp48
-rw-r--r--launcher/ui/MainWindow.h2
-rw-r--r--launcher/ui/WinDarkmode.cpp32
-rw-r--r--launcher/ui/WinDarkmode.h60
-rw-r--r--launcher/ui/pages/instance/ServersPage.cpp2
7 files changed, 163 insertions, 7 deletions
diff --git a/launcher/ui/InstanceWindow.cpp b/launcher/ui/InstanceWindow.cpp
index 0ad8c594..09ce0d67 100644
--- a/launcher/ui/InstanceWindow.cpp
+++ b/launcher/ui/InstanceWindow.cpp
@@ -95,8 +95,14 @@ InstanceWindow::InstanceWindow(InstancePtr instance, QWidget *parent)
m_launchOfflineButton = new QPushButton();
horizontalLayout->addWidget(m_launchOfflineButton);
m_launchOfflineButton->setText(tr("Launch Offline"));
+
+ m_launchDemoButton = new QPushButton();
+ horizontalLayout->addWidget(m_launchDemoButton);
+ m_launchDemoButton->setText(tr("Launch Demo"));
+
updateLaunchButtons();
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->setText(tr("Close"));
@@ -143,6 +149,7 @@ void InstanceWindow::updateLaunchButtons()
if(m_instance->isRunning())
{
m_launchOfflineButton->setEnabled(false);
+ m_launchDemoButton->setEnabled(false);
m_killButton->setText(tr("Kill"));
m_killButton->setObjectName("killButton");
m_killButton->setToolTip(tr("Kill the running instance"));
@@ -150,6 +157,7 @@ void InstanceWindow::updateLaunchButtons()
else if(!m_instance->canLaunch())
{
m_launchOfflineButton->setEnabled(false);
+ m_launchDemoButton->setEnabled(false);
m_killButton->setText(tr("Launch"));
m_killButton->setObjectName("launchButton");
m_killButton->setToolTip(tr("Launch the instance"));
@@ -158,6 +166,13 @@ void InstanceWindow::updateLaunchButtons()
else
{
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->setObjectName("launchButton");
m_killButton->setToolTip(tr("Launch the instance"));
@@ -169,7 +184,12 @@ void InstanceWindow::updateLaunchButtons()
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)
@@ -223,7 +243,7 @@ void InstanceWindow::on_btnKillMinecraft_clicked()
}
else
{
- APPLICATION->launch(m_instance, true, nullptr);
+ APPLICATION->launch(m_instance, true, false, nullptr);
}
}
diff --git a/launcher/ui/InstanceWindow.h b/launcher/ui/InstanceWindow.h
index aec07868..554c4c74 100644
--- a/launcher/ui/InstanceWindow.h
+++ b/launcher/ui/InstanceWindow.h
@@ -74,6 +74,7 @@ slots:
void on_closeButton_clicked();
void on_btnKillMinecraft_clicked();
void on_btnLaunchMinecraftOffline_clicked();
+ void on_btnLaunchMinecraftDemo_clicked();
void instanceLaunchTaskChanged(shared_qobject_ptr<LaunchTask> proc);
void runningStateChanged(bool running);
@@ -93,4 +94,5 @@ private:
QPushButton *m_closeButton = nullptr;
QPushButton *m_killButton = nullptr;
QPushButton *m_launchOfflineButton = nullptr;
+ QPushButton *m_launchDemoButton = nullptr;
};
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp
index 299401f5..58b1ae80 100644
--- a/launcher/ui/MainWindow.cpp
+++ b/launcher/ui/MainWindow.cpp
@@ -240,6 +240,7 @@ public:
TranslatedAction actionCAT;
TranslatedAction actionCopyInstance;
TranslatedAction actionLaunchInstanceOffline;
+ TranslatedAction actionLaunchInstanceDemo;
TranslatedAction actionScreenshots;
TranslatedAction actionExportInstance;
QVector<TranslatedAction *> all_actions;
@@ -499,6 +500,7 @@ public:
fileMenu->addAction(actionAddInstance);
fileMenu->addAction(actionLaunchInstance);
fileMenu->addAction(actionLaunchInstanceOffline);
+ fileMenu->addAction(actionLaunchInstanceDemo);
fileMenu->addAction(actionKillInstance);
fileMenu->addAction(actionCloseWindow);
fileMenu->addSeparator();
@@ -669,6 +671,12 @@ public:
actionLaunchInstanceOffline.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Launch the selected instance in offline mode."));
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->setObjectName(QStringLiteral("actionKillInstance"));
actionKillInstance->setDisabled(true);
@@ -1195,6 +1203,7 @@ void MainWindow::updateToolsMenu()
ui->actionLaunchInstance->setDisabled(!m_selectedInstance || currentInstanceRunning);
ui->actionLaunchInstanceOffline->setDisabled(!m_selectedInstance || currentInstanceRunning);
+ ui->actionLaunchInstanceDemo->setDisabled(!m_selectedInstance || currentInstanceRunning);
QMenu *launchMenu = ui->actionLaunchInstance->menu();
QMenu *launchOfflineMenu = ui->actionLaunchInstanceOffline->menu();
@@ -1220,23 +1229,37 @@ void MainWindow::updateToolsMenu()
normalLaunch->setShortcut(QKeySequence::Open);
QAction *normalLaunchOffline = launchOfflineMenu->addAction(tr("Launch Offline"));
normalLaunchOffline->setShortcut(QKeySequence(tr("Ctrl+Shift+O")));
+ QAction *normalLaunchDemo = launchOfflineMenu->addAction(tr("Launch Demo"));
+ normalLaunchDemo->setShortcut(QKeySequence(tr("Ctrl+Alt+O")));
if (m_selectedInstance)
{
normalLaunch->setEnabled(m_selectedInstance->canLaunch());
normalLaunchOffline->setEnabled(m_selectedInstance->canLaunch());
+ normalLaunchDemo->setEnabled(m_selectedInstance->canLaunch());
connect(normalLaunch, &QAction::triggered, [this]() {
- APPLICATION->launch(m_selectedInstance, true);
+ APPLICATION->launch(m_selectedInstance, true, false);
});
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
{
normalLaunch->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");
launchMenu->addSeparator()->setText(profilersTitle);
launchOfflineMenu->addSeparator()->setText(profilersTitle);
@@ -1260,11 +1283,11 @@ void MainWindow::updateToolsMenu()
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]()
{
- APPLICATION->launch(m_selectedInstance, false, profiler.get());
+ APPLICATION->launch(m_selectedInstance, false, false, profiler.get());
});
}
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()
{
if(m_selectedInstance && m_selectedInstance->isRunning())
@@ -2139,6 +2170,14 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
ui->setInstanceActionsEnabled(true);
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());
@@ -2158,6 +2197,7 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
ui->setInstanceActionsEnabled(false);
ui->actionLaunchInstance->setEnabled(false);
ui->actionLaunchInstanceOffline->setEnabled(false);
+ ui->actionLaunchInstanceDemo->setEnabled(false);
ui->actionKillInstance->setEnabled(false);
APPLICATION->settings()->set("SelectedInstance", QString());
selectionBad();
diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h
index dde3d02c..8b41bf94 100644
--- a/launcher/ui/MainWindow.h
+++ b/launcher/ui/MainWindow.h
@@ -140,6 +140,8 @@ private slots:
void on_actionLaunchInstanceOffline_triggered();
+ void on_actionLaunchInstanceDemo_triggered();
+
void on_actionKillInstance_triggered();
void on_actionDeleteInstance_triggered();
diff --git a/launcher/ui/WinDarkmode.cpp b/launcher/ui/WinDarkmode.cpp
new file mode 100644
index 00000000..eac68e4f
--- /dev/null
+++ b/launcher/ui/WinDarkmode.cpp
@@ -0,0 +1,32 @@
+#include <QWidget>
+
+#include "WinDarkmode.h"
+
+namespace WinDarkmode {
+
+/* See https://github.com/statiolake/neovim-qt/commit/da8eaba7f0e38b6b51f3bacd02a8cc2d1f7a34d8 */
+void setDarkWinTitlebar(WId winid, bool darkmode)
+{
+ HWND hwnd = reinterpret_cast<HWND>(winid);
+ BOOL dark = (BOOL) darkmode;
+
+ HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
+ HMODULE hUser32 = GetModuleHandleW(L"user32.dll");
+ fnAllowDarkModeForWindow AllowDarkModeForWindow
+ = reinterpret_cast<fnAllowDarkModeForWindow>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133)));
+ fnSetPreferredAppMode SetPreferredAppMode
+ = reinterpret_cast<fnSetPreferredAppMode>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135)));
+ fnSetWindowCompositionAttribute SetWindowCompositionAttribute
+ = reinterpret_cast<fnSetWindowCompositionAttribute>(GetProcAddress(hUser32, "SetWindowCompositionAttribute"));
+
+ SetPreferredAppMode(AllowDark);
+ AllowDarkModeForWindow(hwnd, dark);
+ WINDOWCOMPOSITIONATTRIBDATA data = {
+ WCA_USEDARKMODECOLORS,
+ &dark,
+ sizeof(dark)
+ };
+ SetWindowCompositionAttribute(hwnd, &data);
+}
+
+}
diff --git a/launcher/ui/WinDarkmode.h b/launcher/ui/WinDarkmode.h
new file mode 100644
index 00000000..5b567c6b
--- /dev/null
+++ b/launcher/ui/WinDarkmode.h
@@ -0,0 +1,60 @@
+#pragma once
+
+#include <windows.h>
+#include <dwmapi.h>
+
+
+namespace WinDarkmode {
+
+void setDarkWinTitlebar(WId winid, bool darkmode);
+
+enum PreferredAppMode {
+ Default,
+ AllowDark,
+ ForceDark,
+ ForceLight,
+ Max
+};
+
+enum WINDOWCOMPOSITIONATTRIB {
+ WCA_UNDEFINED = 0,
+ WCA_NCRENDERING_ENABLED = 1,
+ WCA_NCRENDERING_POLICY = 2,
+ WCA_TRANSITIONS_FORCEDISABLED = 3,
+ WCA_ALLOW_NCPAINT = 4,
+ WCA_CAPTION_BUTTON_BOUNDS = 5,
+ WCA_NONCLIENT_RTL_LAYOUT = 6,
+ WCA_FORCE_ICONIC_REPRESENTATION = 7,
+ WCA_EXTENDED_FRAME_BOUNDS = 8,
+ WCA_HAS_ICONIC_BITMAP = 9,
+ WCA_THEME_ATTRIBUTES = 10,
+ WCA_NCRENDERING_EXILED = 11,
+ WCA_NCADORNMENTINFO = 12,
+ WCA_EXCLUDED_FROM_LIVEPREVIEW = 13,
+ WCA_VIDEO_OVERLAY_ACTIVE = 14,
+ WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15,
+ WCA_DISALLOW_PEEK = 16,
+ WCA_CLOAK = 17,
+ WCA_CLOAKED = 18,
+ WCA_ACCENT_POLICY = 19,
+ WCA_FREEZE_REPRESENTATION = 20,
+ WCA_EVER_UNCLOAKED = 21,
+ WCA_VISUAL_OWNER = 22,
+ WCA_HOLOGRAPHIC = 23,
+ WCA_EXCLUDED_FROM_DDA = 24,
+ WCA_PASSIVEUPDATEMODE = 25,
+ WCA_USEDARKMODECOLORS = 26,
+ WCA_LAST = 27
+};
+
+struct WINDOWCOMPOSITIONATTRIBDATA {
+ WINDOWCOMPOSITIONATTRIB Attrib;
+ PVOID pvData;
+ SIZE_T cbData;
+};
+
+using fnAllowDarkModeForWindow = BOOL (WINAPI *)(HWND hWnd, BOOL allow);
+using fnSetPreferredAppMode = PreferredAppMode (WINAPI *)(PreferredAppMode appMode);
+using fnSetWindowCompositionAttribute = BOOL (WINAPI *)(HWND hwnd, WINDOWCOMPOSITIONATTRIBDATA *);
+
+}
diff --git a/launcher/ui/pages/instance/ServersPage.cpp b/launcher/ui/pages/instance/ServersPage.cpp
index e5cce96c..5e8bd7cc 100644
--- a/launcher/ui/pages/instance/ServersPage.cpp
+++ b/launcher/ui/pages/instance/ServersPage.cpp
@@ -811,7 +811,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, 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"