From 16c212c472bbebf50e16caa3924d966054bfd849 Mon Sep 17 00:00:00 2001 From: emmaus Date: Sun, 14 Oct 2018 15:16:43 +0000 Subject: [PATCH] added events and bindings for gamepad settings --- Ryujinx.UI/Emulation/EmulationController.cs | 6 +- Ryujinx.UI/UI/MainWindow.qml | 14 +- Ryujinx.UI/UI/Models/ConfigurationModel.cs | 257 ++++++---- Ryujinx.UI/UI/Views/GamePadSettings.qml | 503 ++++++++++++++------ 4 files changed, 536 insertions(+), 244 deletions(-) diff --git a/Ryujinx.UI/Emulation/EmulationController.cs b/Ryujinx.UI/Emulation/EmulationController.cs index f2e443c149..1b6bd99806 100644 --- a/Ryujinx.UI/Emulation/EmulationController.cs +++ b/Ryujinx.UI/Emulation/EmulationController.cs @@ -10,7 +10,7 @@ using System.Threading; namespace Ryujinx.UI.Emulation { - [Signal("failed", NetVariantType.String)] + [Signal("failed", NetVariantType.String, NetVariantType.String)] [Signal("success")] [Signal("loaded")] [Signal("unloaded")] @@ -64,7 +64,7 @@ namespace Ryujinx.UI.Emulation if (!File.Exists(GameFile)) { - this.ActivateSignal("failed", $"File {GameFile} does not exist."); + this.ActivateSignal("failed", "File not found.", $"File {GameFile} does not exist."); return; } @@ -104,7 +104,7 @@ namespace Ryujinx.UI.Emulation { if (!Directory.Exists(ExeFsPath)) { - this.ActivateSignal("failed", $"Directory {ExeFsPath} does not exist."); + this.ActivateSignal("failed", "Path not found", $"Directory {ExeFsPath} does not exist."); return; } diff --git a/Ryujinx.UI/UI/MainWindow.qml b/Ryujinx.UI/UI/MainWindow.qml index 7bff366bce..812ab30d22 100644 --- a/Ryujinx.UI/UI/MainWindow.qml +++ b/Ryujinx.UI/UI/MainWindow.qml @@ -160,16 +160,20 @@ ApplicationWindow { } } - + MessageDialog { + id: alertBox + standardButtons: StandardButton.Close + icon: StandardIcon.Critical + } EmulationController { id: controller - onFailed: function(result) { - // alertBox.title = "Failed to load game" - // alertBox.text = result + onFailed: function(error, message) { + alertBox.title = error + alertBox.text = message - // alertBox.open() + alertBox.open() loadGameMenuItem.enabled = true loadGameFolderMenuItem.enabled = true diff --git a/Ryujinx.UI/UI/Models/ConfigurationModel.cs b/Ryujinx.UI/UI/Models/ConfigurationModel.cs index 46127f3cba..57b372f6a9 100644 --- a/Ryujinx.UI/UI/Models/ConfigurationModel.cs +++ b/Ryujinx.UI/UI/Models/ConfigurationModel.cs @@ -14,6 +14,7 @@ namespace Ryujinx.UI.UI.Models { [Signal("waitReleased")] [Signal("showWaitDialog")] + [Signal("showError", NetVariantType.String, NetVariantType.String)] public class ConfigurationModel { private static Settings CurrentSettings; @@ -110,7 +111,7 @@ namespace Ryujinx.UI.UI.Models while (IsWaiting) { - await Task.Delay(16); + await Task.Delay(17); KeyboardState Keyboard = GetState(); @@ -149,110 +150,166 @@ namespace Ryujinx.UI.UI.Models public async Task GetGamePadInput(string SettingKey, int GamePadIndex) { - float TriggerThreshold = CurrentSettings.GetValue("GamePad_Trigger_Threshold"); + double TriggerThreshold = CurrentSettings.GetValue("GamePad_Trigger_Threshold"); - while (true) + RefreshInputDevices(); + + if (GamePadIndex >= GamePadStates.Length) { - await Task.Delay(33); + this.ActivateSignal("showError", "Failed to find GamePad", $"GamePad at Index {GamePadIndex} is not available"); - RefreshInputDevices(); - - if (GamePadIndex >= GamePadStates.Length) - { - // TODO :throw error here - - return string.Empty; - } - - if(GamePadStates[GamePadIndex].Buttons.IsAnyButtonPressed) - { - if (GamePadStates[GamePadIndex].Buttons.A == ButtonState.Pressed) - { - CurrentSettings.SetValue(SettingKey, "A"); - - return "A"; - } - if (GamePadStates[GamePadIndex].Buttons.B == ButtonState.Pressed) - { - CurrentSettings.SetValue(SettingKey, "B"); - - return "B"; - } - if (GamePadStates[GamePadIndex].Buttons.X == ButtonState.Pressed) - { - CurrentSettings.SetValue(SettingKey, "X"); - - return "X"; - } - if (GamePadStates[GamePadIndex].Buttons.Y == ButtonState.Pressed) - { - CurrentSettings.SetValue(SettingKey, "Y"); - - return "Y"; - } - if (GamePadStates[GamePadIndex].Buttons.LeftShoulder == ButtonState.Pressed) - { - CurrentSettings.SetValue(SettingKey, "LShoulder"); - - return "LShoulder"; - } - if (GamePadStates[GamePadIndex].Buttons.RightShoulder == ButtonState.Pressed) - { - CurrentSettings.SetValue(SettingKey, "RShoulder"); - - return "RShoulder"; - } - if (GamePadStates[GamePadIndex].Buttons.LeftStick == ButtonState.Pressed) - { - CurrentSettings.SetValue(SettingKey, "LStick"); - - return "LStick"; - } - if (GamePadStates[GamePadIndex].Buttons.RightStick == ButtonState.Pressed) - { - CurrentSettings.SetValue(SettingKey, "RStick"); - - return "RStick"; - } - if (GamePadStates[GamePadIndex].Buttons.Start == ButtonState.Pressed) - { - CurrentSettings.SetValue(SettingKey, "Start"); - - return "Start"; - } - if (GamePadStates[GamePadIndex].Buttons.Back == ButtonState.Pressed) - { - CurrentSettings.SetValue(SettingKey, "Back"); - - return "Back"; - } - } - else if (GamePadStates[GamePadIndex].DPad.IsUp) - { - CurrentSettings.SetValue(SettingKey, "DPadUp"); - - return "A"; - } - else if (GamePadStates[GamePadIndex].DPad.IsDown) - { - CurrentSettings.SetValue(SettingKey, "DPadDown"); - - return "DPadDown"; - } - else if (GamePadStates[GamePadIndex].DPad.IsLeft) - { - CurrentSettings.SetValue(SettingKey, "DPadLeft"); - - return "DPadLeft"; - } - else if (GamePadStates[GamePadIndex].DPad.IsRight) - { - CurrentSettings.SetValue(SettingKey, "DPadRight"); - - return "DPadRight"; - } + return string.Empty; } + if (IsWaiting) + { + return string.Empty; + } + + this.ActivateSignal("showWaitDialog"); + + IsWaiting = true; + + try + { + while (IsWaiting) + { + await Task.Delay(17); + + RefreshInputDevices(); + + if (GamePadIndex >= GamePadStates.Length) + { + this.ActivateSignal("showError", "Failed to find GamePad", $"GamePad at Index {GamePadIndex} is not available"); + + return string.Empty; + } + + GamePadState SelectedGamePad = GamePadStates[GamePadIndex]; + + if (SettingKey == "Controls_Left_JoyConController_Stick" || SettingKey == "Controls_Right_JoyConController_Stick") + { + // Check if Sticks have been moved since last update + if (SelectedGamePad.ThumbSticks.Left.Length > 0.1) + { + CurrentSettings.SetValue(SettingKey, "LJoystick"); + + return "LJoystick"; + } + else if (SelectedGamePad.ThumbSticks.Right.Length > 0.1) + { + CurrentSettings.SetValue(SettingKey, "RJoystick"); + + return "RJoystick"; + } + } + else if (SelectedGamePad.Buttons.IsAnyButtonPressed) + { + if (SelectedGamePad.Buttons.A == ButtonState.Pressed) + { + CurrentSettings.SetValue(SettingKey, "A"); + + return "A"; + } + if (SelectedGamePad.Buttons.B == ButtonState.Pressed) + { + CurrentSettings.SetValue(SettingKey, "B"); + + return "B"; + } + if (SelectedGamePad.Buttons.X == ButtonState.Pressed) + { + CurrentSettings.SetValue(SettingKey, "X"); + + return "X"; + } + if (SelectedGamePad.Buttons.Y == ButtonState.Pressed) + { + CurrentSettings.SetValue(SettingKey, "Y"); + + return "Y"; + } + if (SelectedGamePad.Buttons.LeftShoulder == ButtonState.Pressed) + { + CurrentSettings.SetValue(SettingKey, "LShoulder"); + + return "LShoulder"; + } + if (SelectedGamePad.Buttons.RightShoulder == ButtonState.Pressed) + { + CurrentSettings.SetValue(SettingKey, "RShoulder"); + + return "RShoulder"; + } + if (SelectedGamePad.Buttons.LeftStick == ButtonState.Pressed) + { + CurrentSettings.SetValue(SettingKey, "LStick"); + + return "LStick"; + } + if (SelectedGamePad.Buttons.RightStick == ButtonState.Pressed) + { + CurrentSettings.SetValue(SettingKey, "RStick"); + + return "RStick"; + } + if (SelectedGamePad.Buttons.Start == ButtonState.Pressed) + { + CurrentSettings.SetValue(SettingKey, "Start"); + + return "Start"; + } + if (SelectedGamePad.Buttons.Back == ButtonState.Pressed) + { + CurrentSettings.SetValue(SettingKey, "Back"); + + return "Back"; + } + else if (SelectedGamePad.DPad.IsUp) + { + CurrentSettings.SetValue(SettingKey, "DPadUp"); + + return "A"; + } + else if (SelectedGamePad.DPad.IsDown) + { + CurrentSettings.SetValue(SettingKey, "DPadDown"); + + return "DPadDown"; + } + else if (SelectedGamePad.DPad.IsLeft) + { + CurrentSettings.SetValue(SettingKey, "DPadLeft"); + + return "DPadLeft"; + } + else if (SelectedGamePad.DPad.IsRight) + { + CurrentSettings.SetValue(SettingKey, "DPadRight"); + + return "DPadRight"; + } + else if (SelectedGamePad.Triggers.Left > TriggerThreshold) + { + CurrentSettings.SetValue(SettingKey, "LTrigger"); + + return "LTrigger"; + } + else if (SelectedGamePad.Triggers.Right > TriggerThreshold) + { + CurrentSettings.SetValue(SettingKey, "RTrigger"); + + return "RTrigger"; + } + } + } + } + finally + { + ReleaseWait(); + } + + return string.Empty; } } } diff --git a/Ryujinx.UI/UI/Views/GamePadSettings.qml b/Ryujinx.UI/UI/Views/GamePadSettings.qml index 6a1a7bb0d3..b0494a1d16 100644 --- a/Ryujinx.UI/UI/Views/GamePadSettings.qml +++ b/Ryujinx.UI/UI/Views/GamePadSettings.qml @@ -1,6 +1,8 @@ import QtQuick 2.0 import QtQuick.Controls 2.3 import QtQuick.Layouts 1.3 +import QtQuick.Dialogs 1.3 +import Ryujinx 1.0 Frame { id: gamePadSettingsFrame @@ -17,6 +19,12 @@ Frame { CheckBox { id: enableGamePadCheckBox text: "Enable GamePad" + + checked: configModel.getValue("GamePad_Enable") + + onCheckedChanged: { + configModel.setValue("GamePad_Enable", checked) + } } GridLayout { @@ -25,6 +33,8 @@ Frame { columns: 2 rows: 3 + enabled: enableGamePadCheckBox.checked + Label { text: "GamePad Index" Layout.fillHeight: false @@ -49,24 +59,48 @@ Frame { TextField { id: gamePadIndexBox - Layout.fillWidth: true + horizontalAlignment: Text.AlignRight + Layout.preferredWidth: 80 + Layout.fillWidth: false Layout.column: 1 Layout.row:0 inputMethodHints: Qt.ImhDigitsOnly + + text: configModel.getValue("GamePad_Index") + + onTextEdited: { + configModel.setValue("GamePad_Index", text) + } } TextField { id: deadzoneBox + horizontalAlignment: Text.AlignRight + Layout.preferredWidth: 80 Layout.column: 1 Layout.row:1 inputMethodHints: Qt.ImhFormattedNumbersOnly + + text: configModel.getValue("GamePad_Deadzone") + + onTextEdited: { + configModel.setValue("GamePad_Deadzone", text) + } } TextField { id: triggerThresholdBox + horizontalAlignment: Text.AlignRight + Layout.preferredWidth: 80 Layout.column: 1 Layout.row:2 inputMethodHints: Qt.ImhFormattedNumbersOnly + + text: configModel.getValue("GamePad_Trigger_Threshold") + + onTextEdited: { + configModel.setValue("GamePad_Trigger_Threshold", text) + } } } } @@ -98,81 +132,38 @@ Frame { columns: 3 ColumnLayout { - Layout.fillHeight: true - Layout.fillWidth: true Layout.row: 0 Layout.column: 1 Label { - text: "Up" + text: "Stick" } Button { - text: "Up" + Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.fillHeight: true Layout.fillWidth: true - id: leftStickUpButton + id: leftStick + + text: configModel.getValue("Controls_Left_JoyConController_Stick") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Left_JoyConController_Stick", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } ColumnLayout { - Layout.fillHeight: true - Layout.fillWidth: true - Layout.row: 2 - Layout.column: 1 - - Label { - text: "Down" - } - - Button { - text: "Down" - Layout.fillHeight: true - Layout.fillWidth: true - id: leftStickDownButton - } - } - - ColumnLayout { - Layout.fillHeight: true - Layout.fillWidth: true - Layout.row: 1 - Layout.column: 0 - - Label { - text: "Left" - } - - Button { - text: "Left" - Layout.fillHeight: true - Layout.fillWidth: true - id: leftStickLeftButton - } - - } - - ColumnLayout { - Layout.fillHeight: true - Layout.fillWidth: true - Layout.row: 1 - Layout.column: 2 - - Label { - text: "Right" - } - - Button { - text: "Right" - Layout.fillHeight: true - Layout.fillWidth: true - id: leftStickRightButton - } - } - - ColumnLayout { - Layout.fillHeight: true - Layout.fillWidth: true Layout.row: 1 Layout.column: 1 @@ -181,10 +172,26 @@ Frame { } Button { - text: "Button" + Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.fillHeight: true Layout.fillWidth: true id: leftStickButton + + text: configModel.getValue("Controls_Left_JoyConController_Stick_Button") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Left_JoyConController_Stick_Button", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } } @@ -211,10 +218,25 @@ Frame { } Button { - text: "Up" Layout.fillHeight: true Layout.fillWidth: true id: leftDPadUpButton + + text: configModel.getValue("Controls_Left_JoyConController_DPad_Up") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Left_JoyConController_DPad_Up", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } @@ -229,10 +251,25 @@ Frame { } Button { - text: "Down" Layout.fillHeight: true Layout.fillWidth: true id: leftDPadDownButton + + text: configModel.getValue("Controls_Left_JoyConController_DPad_Down") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Left_JoyConController_DPad_Down", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } @@ -247,10 +284,25 @@ Frame { } Button { - text: "Left" Layout.fillHeight: true Layout.fillWidth: true id: leftDPadLeftButton + + text: configModel.getValue("Controls_Left_JoyConController_DPad_Left") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Left_JoyConController_DPad_Left", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } @@ -266,10 +318,25 @@ Frame { } Button { - text: "Right" Layout.fillHeight: true Layout.fillWidth: true id: leftDPadRightButton + + text: configModel.getValue("Controls_Left_JoyConController_DPad_Right") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Left_JoyConController_DPad_Right", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } } @@ -298,10 +365,25 @@ Frame { } Button { - text: "L" Layout.fillHeight: true Layout.fillWidth: true id: lButton + + text: configModel.getValue("Controls_Left_JoyConController_Button_L") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Left_JoyConController_Button_L", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } @@ -316,10 +398,25 @@ Frame { } Button { - text: "ZL" Layout.fillHeight: true Layout.fillWidth: true id: zLButton + + text: configModel.getValue("Controls_Left_JoyConController_Button_ZL") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Left_JoyConController_Button_ZL", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } } @@ -335,10 +432,25 @@ Frame { } Button { - text: "-" Layout.fillHeight: true Layout.fillWidth: true id: minusButton + + text: configModel.getValue("Controls_Left_JoyConController_Button_Minus") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Left_JoyConController_Button_Minus", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } } @@ -367,75 +479,34 @@ Frame { columns: 3 ColumnLayout { - Layout.fillHeight: true - Layout.fillWidth: true Layout.row: 0 Layout.column: 1 Label { - text: "Up" + text: "Stick" } Button { - text: "Up" + Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.fillHeight: true Layout.fillWidth: true - id: rightStickUpButton - } - } + id: rightStick - ColumnLayout { - Layout.fillHeight: true - Layout.fillWidth: true - Layout.row: 2 - Layout.column: 1 + text: configModel.getValue("Controls_Right_JoyConController_Stick") - Label { - text: "Down" - } + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Right_JoyConController_Stick", + parseInt(gamePadIndexBox.text)) - Button { - text: "Down" - Layout.fillHeight: true - Layout.fillWidth: true - id: rightStickDownButton - } - } - - ColumnLayout { - Layout.fillHeight: true - Layout.fillWidth: true - Layout.row: 1 - Layout.column: 0 - - Label { - text: "Left" - } - - Button { - text: "Left" - Layout.fillHeight: true - Layout.fillWidth: true - id: rightStickLeftButton - } - - } - - ColumnLayout { - Layout.fillHeight: true - Layout.fillWidth: true - Layout.row: 1 - Layout.column: 2 - - Label { - text: "Right" - } - - Button { - text: "Right" - Layout.fillHeight: true - Layout.fillWidth: true - id: rightStickRightButton + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } @@ -450,10 +521,25 @@ Frame { } Button { - text: "Button" Layout.fillHeight: true Layout.fillWidth: true id: rightStickButton + + text: configModel.getValue("Controls_Right_JoyConController_Stick_Button") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Right_JoyConController_Stick_Button", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } } @@ -480,10 +566,25 @@ Frame { } Button { - text: "X" Layout.fillHeight: true Layout.fillWidth: true id: xButton + + text: configModel.getValue("Controls_Right_JoyConController_Button_X") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Right_JoyConController_Button_X", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } @@ -498,10 +599,25 @@ Frame { } Button { - text: "B" Layout.fillHeight: true Layout.fillWidth: true id: bButton + + text: configModel.getValue("Controls_Right_JoyConController_Button_B") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Right_JoyConController_Button_B", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } @@ -516,10 +632,25 @@ Frame { } Button { - text: "Y" Layout.fillHeight: true Layout.fillWidth: true id: yButton + + text: configModel.getValue("Controls_Right_JoyConController_Button_Y") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Right_JoyConController_Button_Y", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } @@ -535,10 +666,25 @@ Frame { } Button { - text: "A" Layout.fillHeight: true Layout.fillWidth: true id: aButton + + text: configModel.getValue("Controls_Right_JoyConController_Button_A") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Right_JoyConController_Button_A", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } } @@ -567,10 +713,25 @@ Frame { } Button { - text: "L" Layout.fillHeight: true Layout.fillWidth: true id: rButton + + text: configModel.getValue("Controls_Right_JoyConController_Button_R") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Right_JoyConController_Button_R", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } @@ -585,10 +746,25 @@ Frame { } Button { - text: "ZL" Layout.fillHeight: true Layout.fillWidth: true id: zRButton + + text: configModel.getValue("Controls_Right_JoyConController_Button_ZR") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Right_JoyConController_Button_ZR", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } } @@ -604,10 +780,25 @@ Frame { } Button { - text: "+" Layout.fillHeight: true Layout.fillWidth: true id: plusButton + + text: configModel.getValue("Controls_Right_JoyConController_Button_Plus") + + onClicked: { + var task = configModel.getGamePadInput + ("Controls_Right_JoyConController_Button_Plus", + parseInt(gamePadIndexBox.text)) + + Net.await(task, function(result) + { + if(result !== "") + { + text = result + } + }) + } } } } @@ -616,6 +807,46 @@ Frame { } } } + } + MessageDialog { + id: inputWaitMessageDialog + text: "Please press a key..." + standardButtons: StandardButton.Close + + onRejected: { + configModel.releaseWait() + } + } + + MessageDialog { + id: errorAlert + standardButtons: StandardButton.Close + icon: StandardIcon.Critical + + onRejected: { + configModel.releaseWait() + } + } + + ConfigurationModel { + id: configModel + + onWaitReleased: { + if(inputWaitMessageDialog.visible){ + inputWaitMessageDialog.close() + } + } + + onShowWaitDialog: { + inputWaitMessageDialog.open() + } + + onShowError: function(error,message) { + errorAlert.text = message + errorAlert.title = error + + errorAlert.open() + } } }