From 9427ca82d42db165720f76a2cd40bd83e483952d Mon Sep 17 00:00:00 2001 From: Peter Repukat Date: Sun, 22 Jan 2023 01:23:32 +0100 Subject: [PATCH] GlosSIConfig: Add some UI for experimental standalone mode setup --- GlosSIConfig/UIModel.cpp | 49 ++++++++++++++++++++ GlosSIConfig/UIModel.h | 6 +++ GlosSIConfig/qml/GlobalConf.qml | 79 +++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) diff --git a/GlosSIConfig/UIModel.cpp b/GlosSIConfig/UIModel.cpp index a382f49..61edb12 100644 --- a/GlosSIConfig/UIModel.cpp +++ b/GlosSIConfig/UIModel.cpp @@ -206,6 +206,21 @@ uint32_t UIModel::getAppId(QVariant shortcut) return 0; } +Q_INVOKABLE QString UIModel::getGameId(QVariant shortcut) { + + /* + * enum SteamLaunchableType + { + App = 0, + GameMod = 1, + Shortcut = 2, + P2P = 3 + } + */ + uint64_t gameId = (((uint64_t)getAppId(shortcut) << 32) | ((uint32_t)2 << 24) | 0); + return QVariant(gameId).toString(); +} + bool UIModel::addToSteam(QVariant shortcut, const QString& shortcutspath, bool from_cmd) { QDir appDir = QGuiApplication::applicationDirPath(); @@ -404,6 +419,8 @@ QVariantMap UIModel::getDefaultConf() const QJsonValue::fromVariant(QString::fromStdWString(getSteamPath(false).wstring()))}, {"steamUserId", QJsonValue::fromVariant(QString::fromStdWString(getSteamUserId(false)))}, + {"standaloneModeGameId", ""}, + {"standaloneUseGamepadUI", false}, {"controller", QJsonObject{{"maxControllers", 1}, {"emulateDS4", false}, {"allowDesktopConfig", false}}}, {"devices", QJsonObject{ @@ -486,6 +503,38 @@ void UIModel::saveDefaultConf(QVariantMap conf) const file.close(); } +Q_INVOKABLE QVariant UIModel::standaloneShortcutConf() { + for (auto& target : targets_) { + const auto map = target.toMap(); + if (map["name"] == "GlosSI Standalone/Desktop") { + return target; + } + } + return QVariant(); +} + +Q_INVOKABLE bool UIModel::standaloneModeShortcutExists() { + const auto map = standaloneShortcutConf().toMap(); + if (map["name"] == "GlosSI Standalone/Desktop") { + return true; + } + return false; +} + +Q_INVOKABLE uint32_t UIModel::standaloneModeShortcutAppId() { + if (!standaloneModeShortcutExists()) { + return 0; + } + return getAppId(standaloneShortcutConf()); +} + +Q_INVOKABLE QString UIModel::standaloneModeShortcutGameId() { + if (!standaloneModeShortcutExists()) { + return ""; + } + return getGameId(standaloneShortcutConf()); +} + #ifdef _WIN32 QVariantList UIModel::uwpApps() { return UWPFetch::UWPAppList(); } #endif diff --git a/GlosSIConfig/UIModel.h b/GlosSIConfig/UIModel.h index 4edcb56..10cdb3a 100644 --- a/GlosSIConfig/UIModel.h +++ b/GlosSIConfig/UIModel.h @@ -50,6 +50,7 @@ class UIModel : public QObject { Q_INVOKABLE void deleteTarget(int index); Q_INVOKABLE bool isInSteam(QVariant shortcut) const; Q_INVOKABLE uint32_t getAppId(QVariant shortcut); + Q_INVOKABLE QString getGameId(QVariant shortcut); Q_INVOKABLE bool addToSteam(QVariant shortcut, const QString& shortcutspath, bool from_cmd = false); bool addToSteam(const QString& name, const QString& shortcutspath, bool from_cmd = false); Q_INVOKABLE bool removeFromSteam(const QString& name, const QString& shortcutspath, bool from_cmd = false); @@ -62,6 +63,11 @@ class UIModel : public QObject { Q_INVOKABLE QVariantMap getDefaultConf() const; Q_INVOKABLE void saveDefaultConf(QVariantMap conf) const; + + Q_INVOKABLE QVariant standaloneShortcutConf(); + Q_INVOKABLE bool standaloneModeShortcutExists(); + Q_INVOKABLE uint32_t standaloneModeShortcutAppId(); + Q_INVOKABLE QString standaloneModeShortcutGameId(); #ifdef _WIN32 Q_INVOKABLE QVariantList uwpApps(); diff --git a/GlosSIConfig/qml/GlobalConf.qml b/GlosSIConfig/qml/GlobalConf.qml index 29ec398..4cda0e7 100644 --- a/GlosSIConfig/qml/GlobalConf.qml +++ b/GlosSIConfig/qml/GlobalConf.qml @@ -118,6 +118,85 @@ Item { + "as well as settings applied when launching GlosSITarget without config") } + Item { + width: 1 + height: 4 + } + + RPane { + width: parent.width + radius: 4 + Material.elevation: 32 + bgOpacity: 0.97 + Column { + width: parent.width + height: parent.height + spacing: 4 + Label { + font.bold: true + font.pixelSize: 24 + text: qsTr("Experimental 🧪") + } + Row { + Row { + CheckBox { + id: standaloneUseGamepadUI + text: qsTr("Use BPM for standalone-/desktop-mode") + checked: config.standaloneUseGamepadUI + onCheckedChanged: config.standaloneUseGamepadUI = checked + } + } + } + Row { + leftPadding: 12 + Row { + spacing: 16 + Label { + topPadding: 8 + id: standAloneGameIdLabel + text: qsTr("StandaloneGameId") + } + FluentTextInput { + width: 128 + id: standAloneGameId + enabled: false + text: config.standaloneModeGameId + onTextChanged: config.standaloneModeGameId = text + } + Button { + id: standAloneGameIdButton + text: qsTr("Create standalone-/desktop-mode shortcut") + onClicked: { + const standaloneConf = uiModel.getDefaultConf(); + standaloneConf.name = "GlosSI Standalone/Desktop"; + standaloneConf.launch.launch = false; + uiModel.addTarget(standaloneConf); + if (uiModel.addToSteam(standaloneConf, "")) { + steamChangedDialog.open(); + } + const standaloneGID = uiModel.standaloneModeShortcutGameId(); + standAloneGameId.text = standaloneGID; + setTimeout(() => { + uiModel.saveDefaultConf(config); + done(); + }, 10); + } + highlighted: true + visible: !uiModel.standaloneModeShortcutExists() + } + Button { + id: standAloneGameIdConfigButton + text: qsTr("Open standalone-/desktop-mode controller config") + onClicked: { + Qt.openUrlExternally("steam://currentcontrollerconfig/" + uiModel.standaloneModeShortcutAppId() + "/"); + } + visible: uiModel.standaloneModeShortcutExists() + } + } + } + } + } + Item { width: 1 height: 32