diff --git a/ControllerCommon/Utils/InputUtils.cs b/ControllerCommon/Utils/InputUtils.cs index ab1ad6b8a..d401fb68b 100644 --- a/ControllerCommon/Utils/InputUtils.cs +++ b/ControllerCommon/Utils/InputUtils.cs @@ -51,44 +51,6 @@ public enum OverlayModelMode public static class InputUtils { - public static string GamepadButtonToGlyph(ControllerButtonFlags button) - { - switch (button) - { - case ControllerButtonFlags.B1: - return "\uF093"; // A - case ControllerButtonFlags.B2: - return "\uF094"; // B - case ControllerButtonFlags.B3: - return "\uF095"; // X - case ControllerButtonFlags.B4: - return "\uF096"; // Y - case ControllerButtonFlags.DPadRight: - case ControllerButtonFlags.DPadDown: - case ControllerButtonFlags.DPadUp: - case ControllerButtonFlags.DPadLeft: - return "\uF10E"; - case ControllerButtonFlags.LeftTrigger: - return "\uF10A"; - case ControllerButtonFlags.RightTrigger: - return "\uF10B"; - case ControllerButtonFlags.LeftShoulder: - return "\uF10C"; - case ControllerButtonFlags.RightShoulder: - return "\uF10D"; - case ControllerButtonFlags.LeftThumb: - return "\uF108"; - case ControllerButtonFlags.RightThumb: - return "\uF109"; - case ControllerButtonFlags.Start: - return "\uEDE3"; - case ControllerButtonFlags.Back: - return "\uEECA"; - default: - return "\uE783"; - } - } - public static float Clamp(float value, float min, float max) { return Math.Min(max, Math.Max(min, value)); diff --git a/HandheldCompanion/Managers/Hotkeys/Hotkey.cs b/HandheldCompanion/Managers/Hotkeys/Hotkey.cs index 25c0cca5b..7afaa837d 100644 --- a/HandheldCompanion/Managers/Hotkeys/Hotkey.cs +++ b/HandheldCompanion/Managers/Hotkeys/Hotkey.cs @@ -6,6 +6,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media.Animation; +using static HandheldCompanion.Managers.InputsManager; using Application = System.Windows.Application; namespace HandheldCompanion.Managers @@ -13,11 +14,11 @@ namespace HandheldCompanion.Managers public class Hotkey { // not serialized - public InputsHotkey inputsHotkey; + public InputsHotkey inputsHotkey = new(); // serialized public ushort hotkeyId { get; set; } - public InputsChord inputsChord { get; set; } + public InputsChord inputsChord { get; set; } = new(); public bool IsPinned { get; set; } // HotkeysPage UI @@ -49,7 +50,6 @@ public Hotkey(ushort id, InputsHotkey _inputsHotkey) hotkeyId = id; inputsHotkey = _inputsHotkey; - inputsChord = new(); } public Hotkey(ushort id) @@ -57,10 +57,9 @@ public Hotkey(ushort id) hotkeyId = id; inputsHotkey = InputsHotkey.InputsHotkeys[id]; - inputsChord = new(); } - public void DrawControl() + public void DrawControl(bool embedded = false) { if (mainBorder != null) return; @@ -72,16 +71,21 @@ public void DrawControl() Visibility = Visibility.Visible, Tag = hotkeyId }; - mainBorder.SetResourceReference(Control.BackgroundProperty, "SystemControlBackgroundChromeMediumLowBrush"); + + if (!embedded) + mainBorder.SetResourceReference(Control.BackgroundProperty, "SystemControlBackgroundChromeMediumLowBrush"); // main grid content // Define the Columns - ColumnDefinition colDef0 = new ColumnDefinition() + if (!embedded) { - Width = new GridLength(5, GridUnitType.Star), - MinWidth = 200 - }; - mainGrid.ColumnDefinitions.Add(colDef0); + ColumnDefinition colDef0 = new ColumnDefinition() + { + Width = new GridLength(5, GridUnitType.Star), + MinWidth = 200 + }; + mainGrid.ColumnDefinitions.Add(colDef0); + } ColumnDefinition colDef1 = new ColumnDefinition() { @@ -96,11 +100,14 @@ public void DrawControl() }; mainGrid.ColumnDefinitions.Add(colDef2); - ColumnDefinition colDef3 = new ColumnDefinition() + if (!embedded) { - Width = new GridLength(50, GridUnitType.Pixel) - }; - mainGrid.ColumnDefinitions.Add(colDef3); + ColumnDefinition colDef3 = new ColumnDefinition() + { + Width = new GridLength(50, GridUnitType.Pixel) + }; + mainGrid.ColumnDefinitions.Add(colDef3); + } // main panel content currentIcon = new FontIcon() @@ -143,7 +150,11 @@ public void DrawControl() HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center, }; - Grid.SetColumn(buttonPanel, 1); + + if (!embedded) + Grid.SetColumn(buttonPanel, 1); + else + Grid.SetColumn(buttonPanel, 0); inputButton = new Button() { @@ -173,7 +184,9 @@ public void DrawControl() HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Center, }; - Grid.SetColumn(pinButton, 3); + + if (!embedded) + Grid.SetColumn(pinButton, 3); // add elements to main panel buttonPanel.Children.Add(inputButton); @@ -194,15 +207,21 @@ public void DrawControl() break; } - // add elements to main panel - mainPanel.Children.Add(currentIcon); - mainPanel.Children.Add(contentPanel); + if (!embedded) + { + // add elements to main panel + mainPanel.Children.Add(currentIcon); + mainPanel.Children.Add(contentPanel); + + // add elements to grid + mainGrid.Children.Add(mainPanel); + } - // add elements to grid - mainGrid.Children.Add(mainPanel); mainGrid.Children.Add(buttonPanel); mainGrid.Children.Add(eraseButton); - mainGrid.Children.Add(pinButton); + + if (!embedded) + mainGrid.Children.Add(pinButton); // add elements to border mainBorder.Child = mainGrid; @@ -236,7 +255,7 @@ public void DrawControl() quickPanel.Children.Add(quickName); // update buttons name and states - UpdateHotkey(); + Refresh(); } private void ClearButton_Click() @@ -245,52 +264,59 @@ private void ClearButton_Click() HotkeysManager.ClearHotkey(this); } - public void StartListening(bool IsCombo) + public void StartListening(ListenerType type) { // update button - switch (IsCombo) + switch (type) { - case true: + case ListenerType.Output: outputButton.Content = Properties.Resources.OverlayPage_Listening; outputButton.Style = Application.Current.FindResource("AccentButtonStyle") as Style; break; - case false: + case ListenerType.UI: + case ListenerType.Default: inputButton.Content = Properties.Resources.OverlayPage_Listening; inputButton.Style = Application.Current.FindResource("AccentButtonStyle") as Style; break; } } - public void StopListening(InputsChord inputsChord, bool IsCombo) + public void StopListening(InputsChord inputsChord, ListenerType type) { this.inputsChord = inputsChord; // update button - switch (IsCombo) + switch (type) { - case true: + case ListenerType.Output: outputButton.Style = Application.Current.FindResource("DefaultButtonStyle") as Style; break; - case false: + case ListenerType.UI: + case ListenerType.Default: inputButton.Style = Application.Current.FindResource("DefaultButtonStyle") as Style; break; } - UpdateHotkey(); + Refresh(); } public void StartPinning() { IsPinned = true; - UpdateHotkey(); + Refresh(); } public void StopPinning() { IsPinned = false; - UpdateHotkey(); + Refresh(); + } + + public SimpleStackPanel GetButtonPanel() + { + return buttonPanel; } public Border GetHotkey() @@ -303,7 +329,7 @@ public SimpleStackPanel GetPin() return quickPanel; } - private void UpdateHotkey() + public void Refresh() { bool hasbuttons = (inputsChord.GamepadButtons != ControllerButtonFlags.None); bool hascombo = inputsChord.OutputKeys.Count != 0; diff --git a/HandheldCompanion/Managers/Hotkeys/InputsHotkey.cs b/HandheldCompanion/Managers/Hotkeys/InputsHotkey.cs index ffa5e7b41..04ced2acb 100644 --- a/HandheldCompanion/Managers/Hotkeys/InputsHotkey.cs +++ b/HandheldCompanion/Managers/Hotkeys/InputsHotkey.cs @@ -14,39 +14,44 @@ public enum InputsHotkeyType : ushort Windows = 2, Handheld = 3, Custom = 4, + UI = 5, } public static SortedDictionary InputsHotkeys = new() { - { 01, new InputsHotkey(InputsHotkeyType.Overlay, "\uEDE3", "overlayGamepad", "Segoe Fluent Icons", 20, false, true) }, - { 02, new InputsHotkey(InputsHotkeyType.Overlay, "\uEDA4", "overlayTrackpads", "Segoe Fluent Icons", 20, false, true) }, - - { 10, new InputsHotkey(InputsHotkeyType.Quicktools, "\uEC7A", "quickTools", "Segoe Fluent Icons", 20, false, true) }, - { 11, new InputsHotkey(InputsHotkeyType.Quicktools, "\u2795", "increaseTDP", "Segoe UI Symbol", 20, false, true) }, - { 12, new InputsHotkey(InputsHotkeyType.Quicktools, "\u2796", "decreaseTDP", "Segoe UI Symbol", 20, false, true) }, - { 13, new InputsHotkey(InputsHotkeyType.Quicktools, "\uE769", "suspendResumeTask", "Segoe Fluent Icons", 20, false, true) }, - - { 20, new InputsHotkey(InputsHotkeyType.Windows, "\uE765", "shortcutKeyboard", "Segoe Fluent Icons", 20, false, true) }, - { 21, new InputsHotkey(InputsHotkeyType.Windows, "\uE138", "shortcutDesktop", "Segoe UI Symbol", 20, false, true) }, - { 22, new InputsHotkey(InputsHotkeyType.Windows, "ESC", "shortcutESC", "Segoe UI", 12, false, true) }, - { 23, new InputsHotkey(InputsHotkeyType.Windows, "\uEE49", "shortcutExpand", "Segoe Fluent Icons", 20, false, true) }, - { 24, new InputsHotkey(InputsHotkeyType.Windows, "\uE7C4", "shortcutTaskview", "Segoe MDL2 Assets", 20, false, true) }, - { 25, new InputsHotkey(InputsHotkeyType.Windows, "\uE71D", "shortcutTaskManager", "Segoe Fluent Icons", 20, false, true) }, - { 26, new InputsHotkey(InputsHotkeyType.Windows, "\uE8BB", "shortcutKillApp", "Segoe Fluent Icons", 20, false, true) }, - - { 30, new InputsHotkey(InputsHotkeyType.Handheld, "\uE7C4", "shortcutMainwindow", "Segoe Fluent Icons", 20, false, true) }, - { 31, new InputsHotkey(InputsHotkeyType.Handheld, "\uE2E8", "shortcutGuide", "Segoe UI Symbol", 20, false, true) }, - - { 40, new InputsHotkey(InputsHotkeyType.Custom, "\u2780", "shortcutCustom0", "Segoe UI Symbol", 20, false, true) }, - { 41, new InputsHotkey(InputsHotkeyType.Custom, "\u2781", "shortcutCustom1", "Segoe UI Symbol", 20, false, true) }, - { 42, new InputsHotkey(InputsHotkeyType.Custom, "\u2782", "shortcutCustom2", "Segoe UI Symbol", 20, false, true) }, - { 43, new InputsHotkey(InputsHotkeyType.Custom, "\u2783", "shortcutCustom3", "Segoe UI Symbol", 20, false, true) }, - { 44, new InputsHotkey(InputsHotkeyType.Custom, "\u2784", "shortcutCustom4", "Segoe UI Symbol", 20, false, true) }, - { 45, new InputsHotkey(InputsHotkeyType.Custom, "\u2785", "shortcutCustom5", "Segoe UI Symbol", 20, false, true) }, - { 46, new InputsHotkey(InputsHotkeyType.Custom, "\u2786", "shortcutCustom6", "Segoe UI Symbol", 20, false, true) }, - { 47, new InputsHotkey(InputsHotkeyType.Custom, "\u2787", "shortcutCustom7", "Segoe UI Symbol", 20, false, true) }, - { 48, new InputsHotkey(InputsHotkeyType.Custom, "\u2788", "shortcutCustom8", "Segoe UI Symbol", 20, false, true) }, - { 49, new InputsHotkey(InputsHotkeyType.Custom, "\u2789", "shortcutCustom9", "Segoe UI Symbol", 20, false, true) }, + { 01, new InputsHotkey(InputsHotkeyType.Overlay, "\uEDE3", "overlayGamepad", "Segoe Fluent Icons", 20, false, true) }, + { 02, new InputsHotkey(InputsHotkeyType.Overlay, "\uEDA4", "overlayTrackpads", "Segoe Fluent Icons", 20, false, true) }, + + { 10, new InputsHotkey(InputsHotkeyType.Quicktools, "\uEC7A", "quickTools", "Segoe Fluent Icons", 20, false, true) }, + { 11, new InputsHotkey(InputsHotkeyType.Quicktools, "\u2795", "increaseTDP", "Segoe UI Symbol", 20, false, true) }, + { 12, new InputsHotkey(InputsHotkeyType.Quicktools, "\u2796", "decreaseTDP", "Segoe UI Symbol", 20, false, true) }, + { 13, new InputsHotkey(InputsHotkeyType.Quicktools, "\uE769", "suspendResumeTask", "Segoe Fluent Icons", 20, false, true) }, + + { 20, new InputsHotkey(InputsHotkeyType.Windows, "\uE765", "shortcutKeyboard", "Segoe Fluent Icons", 20, false, true) }, + { 21, new InputsHotkey(InputsHotkeyType.Windows, "\uE138", "shortcutDesktop", "Segoe UI Symbol", 20, false, true) }, + { 22, new InputsHotkey(InputsHotkeyType.Windows, "ESC", "shortcutESC", "Segoe UI", 12, false, true) }, + { 23, new InputsHotkey(InputsHotkeyType.Windows, "\uEE49", "shortcutExpand", "Segoe Fluent Icons", 20, false, true) }, + { 24, new InputsHotkey(InputsHotkeyType.Windows, "\uE7C4", "shortcutTaskview", "Segoe MDL2 Assets", 20, false, true) }, + { 25, new InputsHotkey(InputsHotkeyType.Windows, "\uE71D", "shortcutTaskManager", "Segoe Fluent Icons", 20, false, true) }, + { 26, new InputsHotkey(InputsHotkeyType.Windows, "\uE8BB", "shortcutKillApp", "Segoe Fluent Icons", 20, false, true) }, + + { 30, new InputsHotkey(InputsHotkeyType.Handheld, "\uE7C4", "shortcutMainwindow", "Segoe Fluent Icons", 20, false, true) }, + { 31, new InputsHotkey(InputsHotkeyType.Handheld, "\uE2E8", "shortcutGuide", "Segoe UI Symbol", 20, false, true) }, + + { 40, new InputsHotkey(InputsHotkeyType.Custom, "\u2780", "shortcutCustom0", "Segoe UI Symbol", 20, false, true) }, + { 41, new InputsHotkey(InputsHotkeyType.Custom, "\u2781", "shortcutCustom1", "Segoe UI Symbol", 20, false, true) }, + { 42, new InputsHotkey(InputsHotkeyType.Custom, "\u2782", "shortcutCustom2", "Segoe UI Symbol", 20, false, true) }, + { 43, new InputsHotkey(InputsHotkeyType.Custom, "\u2783", "shortcutCustom3", "Segoe UI Symbol", 20, false, true) }, + { 44, new InputsHotkey(InputsHotkeyType.Custom, "\u2784", "shortcutCustom4", "Segoe UI Symbol", 20, false, true) }, + { 45, new InputsHotkey(InputsHotkeyType.Custom, "\u2785", "shortcutCustom5", "Segoe UI Symbol", 20, false, true) }, + { 46, new InputsHotkey(InputsHotkeyType.Custom, "\u2786", "shortcutCustom6", "Segoe UI Symbol", 20, false, true) }, + { 47, new InputsHotkey(InputsHotkeyType.Custom, "\u2787", "shortcutCustom7", "Segoe UI Symbol", 20, false, true) }, + { 48, new InputsHotkey(InputsHotkeyType.Custom, "\u2788", "shortcutCustom8", "Segoe UI Symbol", 20, false, true) }, + { 49, new InputsHotkey(InputsHotkeyType.Custom, "\u2789", "shortcutCustom9", "Segoe UI Symbol", 20, false, true) }, + + // UI hotkeys shouldn't be listed on the hotkeys page + { 50, new InputsHotkey(InputsHotkeyType.UI, "\uEDE3", "shortcutProfilesPage", "Segoe Fluent Icons", 20, false, true) }, + { 51, new InputsHotkey(InputsHotkeyType.UI, "\uEDE3", "shortcutProfilesSettingsMode0", "Segoe Fluent Icons", 20, false, true) }, }; public string Glyph { get; set; } diff --git a/HandheldCompanion/Managers/HotkeysManager.cs b/HandheldCompanion/Managers/HotkeysManager.cs index da72a6fec..36ab9e7f9 100644 --- a/HandheldCompanion/Managers/HotkeysManager.cs +++ b/HandheldCompanion/Managers/HotkeysManager.cs @@ -12,15 +12,8 @@ using System.Threading; using System.Windows; using static HandheldCompanion.Managers.InputsHotkey; -using Shell -/* Unmerged change from project 'HandheldCompanion (net6.0-windows10.0.19041.0)' -Before: -using Shell32; +using static HandheldCompanion.Managers.InputsManager; using Shell = Shell32.Shell; -After: -using Shell = Shell32.Shell; -*/ - = Shell32.Shell; namespace HandheldCompanion.Managers { @@ -79,7 +72,16 @@ public static void Start() hotkey = new Hotkey(Id, inputsHotkey); hotkey.inputsHotkey = InputsHotkey.InputsHotkeys[hotkey.hotkeyId]; - hotkey.DrawControl(); + + switch (hotkey.inputsHotkey.hotkeyType) + { + case InputsHotkeyType.UI: + hotkey.DrawControl(true); + break; + default: + hotkey.DrawControl(); + break; + } Hotkeys.Add(hotkey.hotkeyId, hotkey); } @@ -92,9 +94,19 @@ public static void Start() { HotkeyCreated?.Invoke(hotkey); - hotkey.inputButton.Click += (sender, e) => StartListening(hotkey, false); - hotkey.outputButton.Click += (sender, e) => StartListening(hotkey, true); + switch(hotkey.inputsHotkey.hotkeyType) + { + case InputsHotkeyType.UI: + hotkey.inputButton.Click += (sender, e) => StartListening(hotkey, ListenerType.UI); + break; + default: + hotkey.inputButton.Click += (sender, e) => StartListening(hotkey, ListenerType.Default); + break; + } + + hotkey.outputButton.Click += (sender, e) => StartListening(hotkey, ListenerType.Output); hotkey.pinButton.Click += (sender, e) => PinOrUnpinHotkey(hotkey); + hotkey.quickButton.PreviewTouchDown += (sender, e) => { InputsManager.InvokeTrigger(hotkey, true, false); }; hotkey.quickButton.PreviewMouseDown += (sender, e) => { InputsManager.InvokeTrigger(hotkey, true, false); }; hotkey.quickButton.PreviewMouseUp += (sender, e) => { InputsManager.InvokeTrigger(hotkey, false, true); }; @@ -112,10 +124,10 @@ public static void Stop() IsInitialized = false; } - private static void StartListening(Hotkey hotkey, bool IsCombo) + private static void StartListening(Hotkey hotkey, ListenerType type) { - InputsManager.StartListening(hotkey, IsCombo); - hotkey.StartListening(IsCombo); + InputsManager.StartListening(hotkey, type); + hotkey.StartListening(type); } private static void PinOrUnpinHotkey(Hotkey hotkey) @@ -155,7 +167,7 @@ private static int CountPinned() return Hotkeys.Values.Where(item => item.IsPinned).Count(); } - private static void TriggerUpdated(string listener, InputsChord inputs, bool IsCombo) + private static void TriggerUpdated(string listener, InputsChord inputs, ListenerType type) { Application.Current.Dispatcher.Invoke(new Action(() => { @@ -164,7 +176,7 @@ private static void TriggerUpdated(string listener, InputsChord inputs, bool IsC if (hotkey is null) return; - hotkey.StopListening(inputs, IsCombo); + hotkey.StopListening(inputs, type); // overwrite current file SerializeHotkey(hotkey, true); diff --git a/HandheldCompanion/Managers/InputsManager.cs b/HandheldCompanion/Managers/InputsManager.cs index 56a0b6117..ad7f560f8 100644 --- a/HandheldCompanion/Managers/InputsManager.cs +++ b/HandheldCompanion/Managers/InputsManager.cs @@ -8,6 +8,7 @@ using PrecisionTiming; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading; using System.Windows.Forms; @@ -17,6 +18,13 @@ namespace HandheldCompanion.Managers { public static class InputsManager { + public enum ListenerType + { + Default, + Output, + UI, + } + // Gamepad variables private static PrecisionTimer KeyboardResetTimer; private static PrecisionTimer GamepadResetTimer; @@ -47,7 +55,7 @@ public static class InputsManager private const short TIME_EXPIRED = 3000; // default interval before considering a chord as expired if no input is detected - private static bool IsCombo; + private static ListenerType currentType; private static InputsHotkey currentHotkey = new(); private static List BufferKeys = new(); @@ -63,7 +71,7 @@ public static class InputsManager public delegate void TriggerRaisedEventHandler(string listener, InputsChord inputs, bool IsKeyDown, bool IsKeyUp); public static event TriggerUpdatedEventHandler TriggerUpdated; - public delegate void TriggerUpdatedEventHandler(string listener, InputsChord inputs, bool IsCombo); + public delegate void TriggerUpdatedEventHandler(string listener, InputsChord inputs, ListenerType type); public static event InitializedEventHandler Initialized; public delegate void InitializedEventHandler(); @@ -203,12 +211,14 @@ private static void CheckForSequence(bool IsKeyDown, bool IsKeyUp) } InputsHotkey hotkey = InputsHotkey.InputsHotkeys.Values.Where(item => item.Listener == currentHotkey.Listener).FirstOrDefault(); - - switch (hotkey.OnKeyDown) + if (hotkey != null) { - case true: - currentChord.InputsType = InputsChordType.Hold; - break; + switch (hotkey.OnKeyDown) + { + case true: + currentChord.InputsType = InputsChordType.Hold; + break; + } } StopListening(currentChord); @@ -263,7 +273,7 @@ private static void M_GlobalHook_KeyEvent(object? sender, KeyEventArgs e) KeyUsed = false; // are we listening for keyboards inputs as part of a custom hotkey ? - if (IsCombo) + if (currentType == ListenerType.Output) { args.SuppressKeyPress = true; if (args.IsKeyUp && args.IsExtendedKey) @@ -549,29 +559,31 @@ public static void UpdateReport(ControllerButtonFlags Buttons) GamepadResetTimer.Start(); } - public static void StartListening(Hotkey hotkey, bool IsCombo) + public static void StartListening(Hotkey hotkey, ListenerType type) { // force expiration on previous listener, if any if (!string.IsNullOrEmpty(currentHotkey.Listener)) ListenerExpired(); + // store current hotkey values + prevChord = new InputsChord(hotkey.inputsChord.GamepadButtons, hotkey.inputsChord.OutputKeys, hotkey.inputsChord.InputsType); + currentHotkey = hotkey.inputsHotkey; currentChord = hotkey.inputsChord; - prevChord = new InputsChord(currentChord.GamepadButtons, currentChord.OutputKeys, currentChord.InputsType); + currentType = type; - switch (IsCombo) + switch (type) { - case true: + case ListenerType.Output: currentChord.OutputKeys.Clear(); break; default: - case false: + case ListenerType.UI: + case ListenerType.Default: currentChord.GamepadButtons = ControllerButtonFlags.None; break; } - InputsManager.IsCombo = IsCombo; - BufferKeys.Clear(); ListenerTimer.Start(); @@ -582,14 +594,21 @@ private static void StopListening(InputsChord inputsChord = null) if (inputsChord == null) inputsChord = new InputsChord(); - Triggers[currentHotkey.Listener] = new InputsChord(inputsChord.GamepadButtons, inputsChord.OutputKeys, inputsChord.InputsType); - TriggerUpdated?.Invoke(currentHotkey.Listener, inputsChord, IsCombo); + switch(currentType) + { + case ListenerType.Default: + case ListenerType.Output: + Triggers[currentHotkey.Listener] = new InputsChord(inputsChord.GamepadButtons, inputsChord.OutputKeys, inputsChord.InputsType); + break; + } + + TriggerUpdated?.Invoke(currentHotkey.Listener, inputsChord, currentType); LogManager.LogDebug("Trigger: {0} updated. buttons: {1}, type: {2}", currentHotkey.Listener, inputsChord.GamepadButtons, inputsChord.InputsType); currentHotkey = new(); currentChord = new(); - IsCombo = false; + currentType = ListenerType.Default; ListenerTimer.Stop(); InputsChordHoldTimer.Stop(); diff --git a/HandheldCompanion/Views/Pages/HotkeysPage.xaml.cs b/HandheldCompanion/Views/Pages/HotkeysPage.xaml.cs index c79f8c81c..399863457 100644 --- a/HandheldCompanion/Views/Pages/HotkeysPage.xaml.cs +++ b/HandheldCompanion/Views/Pages/HotkeysPage.xaml.cs @@ -51,9 +51,15 @@ private void HotkeysManager_HotkeyTypeCreated(InputsHotkey.InputsHotkeyType type private void HotkeysManager_HotkeyCreated(Hotkey hotkey) { + // UI types shouldn't be added + if (hotkey.inputsHotkey.hotkeyType == InputsHotkey.InputsHotkeyType.UI) + return; + this.Dispatcher.Invoke(() => { Border hotkeyBorder = hotkey.GetHotkey(); + if (hotkeyBorder is null || hotkeyBorder.Parent != null) + return; ushort idx = (ushort)hotkey.inputsHotkey.hotkeyType; SimpleStackPanel stackPanel = (SimpleStackPanel)HotkeysPanel.Children[idx]; diff --git a/HandheldCompanion/Views/Pages/ProfileSettingsMode0.xaml b/HandheldCompanion/Views/Pages/ProfileSettingsMode0.xaml index eea23cf56..60bf929c4 100644 --- a/HandheldCompanion/Views/Pages/ProfileSettingsMode0.xaml +++ b/HandheldCompanion/Views/Pages/ProfileSettingsMode0.xaml @@ -89,16 +89,9 @@ - - - - - - - - - - + + + diff --git a/HandheldCompanion/Views/Pages/ProfileSettingsMode0.xaml.cs b/HandheldCompanion/Views/Pages/ProfileSettingsMode0.xaml.cs index 22dec47dc..d81e1edea 100644 --- a/HandheldCompanion/Views/Pages/ProfileSettingsMode0.xaml.cs +++ b/HandheldCompanion/Views/Pages/ProfileSettingsMode0.xaml.cs @@ -1,4 +1,5 @@ -using ControllerCommon; +using ControllerCommon; +using ControllerCommon.Managers; using ControllerCommon.Controllers; using ControllerCommon.Utils; using ControllerService.Sensors; @@ -11,7 +12,9 @@ using System.Windows.Input; using System.Windows.Media; using Page = System.Windows.Controls.Page; - +using HandheldCompanion.Managers; +using System.Linq; + namespace HandheldCompanion.Views.Pages { /// @@ -19,27 +22,37 @@ namespace HandheldCompanion.Views.Pages /// public partial class ProfileSettingsMode0 : Page { - private Profile profileCurrent; - - private Dictionary AimingDownSightsActivators = new(); + private Profile currentProfile; + private Hotkey ProfilesPageHotkey; public ProfileSettingsMode0() { InitializeComponent(); } - public ProfileSettingsMode0(string Tag, Profile profileCurrent) : this() - { + public ProfileSettingsMode0(string Tag) : this() + { this.Tag = Tag; - this.profileCurrent = profileCurrent; - PipeClient.ServerMessage += OnServerMessage; + PipeClient.ServerMessage += OnServerMessage; + + HotkeysManager.HotkeyCreated += TriggerCreated; + InputsManager.TriggerUpdated += TriggerUpdated; + } + + public void Update(Profile currentProfile) + { + this.currentProfile = currentProfile; - SliderSensivity.Value = profileCurrent.aiming_sensivity; - tb_ProfileAimingDownSightsMultiplier.Value = profileCurrent.aiming_down_sights_multiplier; - Toggle_FlickStick.IsOn = profileCurrent.flickstick_enabled; - tb_ProfileFlickDuration.Value = profileCurrent.flick_duration * 1000; - tb_ProfileStickSensitivity.Value = profileCurrent.stick_sensivity; + SliderSensivity.Value = currentProfile.aiming_sensivity; + tb_ProfileAimingDownSightsMultiplier.Value = currentProfile.aiming_down_sights_multiplier; + Toggle_FlickStick.IsOn = currentProfile.flickstick_enabled; + tb_ProfileFlickDuration.Value = currentProfile.flick_duration * 1000; + tb_ProfileStickSensitivity.Value = currentProfile.stick_sensivity; + + // todo: improve me ? + ProfilesPageHotkey.inputsChord.GamepadButtons = currentProfile.aiming_down_sights_activation; + ProfilesPageHotkey.Refresh(); // temp StackCurve.Children.Clear(); @@ -49,7 +62,7 @@ public ProfileSettingsMode0(string Tag, Profile profileCurrent) : this() if (i == 1) continue; - double height = profileCurrent.aiming_array[i - 1].y * StackCurve.Height; + double height = currentProfile.aiming_array[i - 1].y * StackCurve.Height; Thumb thumb = new Thumb() { Tag = i - 1, @@ -64,41 +77,7 @@ public ProfileSettingsMode0(string Tag, Profile profileCurrent) : this() }; StackCurve.Children.Add(thumb); - } - - // draw aiming down sight activators - foreach (ControllerButtonFlags button in (ControllerButtonFlags[])Enum.GetValues(typeof(ControllerButtonFlags))) - { - // create panel - SimpleStackPanel panel = new SimpleStackPanel() { Spacing = 6, Orientation = Orientation.Horizontal, VerticalAlignment = VerticalAlignment.Center }; - - // create icon - FontIcon icon = new FontIcon() { Glyph = "" }; - icon.Glyph = InputUtils.GamepadButtonToGlyph(button); - - if (icon.Glyph != "") - panel.Children.Add(icon); - - // create textblock - string description = EnumUtils.GetDescriptionFromEnumValue(button); - TextBlock text = new TextBlock() { Text = description }; - panel.Children.Add(text); - - // create checkbox - CheckBox checkbox = new CheckBox() { Tag = button, Content = panel, Width = 170 }; - checkbox.Checked += AimingDownSightsActivatorsTickedEvent; - checkbox.Unchecked += AimingDownSightsActivatorsUntickedEvent; - - cB_AimingDownSightsActivationButtons.Children.Add(checkbox); - AimingDownSightsActivators.Add(button, checkbox); - } - - // Fill activators based on profile - foreach (ControllerButtonFlags button in (ControllerButtonFlags[])Enum.GetValues(typeof(ControllerButtonFlags))) - if (profileCurrent.aiming_down_sights_activation.HasFlag(button)) - AimingDownSightsActivators[button].IsChecked = true; - else - AimingDownSightsActivators[button].IsChecked = false; + } } private void Page_Loaded(object sender, RoutedEventArgs e) @@ -129,10 +108,10 @@ private void OnServerMessage(PipeMessage message) private void SliderSensivity_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { - if (profileCurrent is null) + if (currentProfile is null) return; - profileCurrent.aiming_sensivity = (float)SliderSensivity.Value; + currentProfile.aiming_sensivity = (float)SliderSensivity.Value; } private void Highlight_Thumb(float value) @@ -144,7 +123,7 @@ private void Highlight_Thumb(float value) foreach (Control control in StackCurve.Children) { int idx = (int)control.Tag; - ProfileVector vector = profileCurrent.aiming_array[idx]; + ProfileVector vector = currentProfile.aiming_array[idx]; if (dist_x > vector.x) control.BorderThickness = new Thickness(0, 0, 0, 20); @@ -161,7 +140,7 @@ private void StackCurve_MouseDown(object sender, MouseButtonEventArgs e) private void StackCurve_MouseMove(object sender, MouseEventArgs e) { - if (profileCurrent is null) + if (currentProfile is null) return; Control Thumb = null; @@ -187,7 +166,7 @@ private void StackCurve_MouseMove(object sender, MouseEventArgs e) int idx = (int)Thumb.Tag; Thumb.Height = StackCurve.ActualHeight - e.GetPosition(StackCurve).Y; - profileCurrent.aiming_array[idx].y = Thumb.Height / StackCurve.Height; + currentProfile.aiming_array[idx].y = Thumb.Height / StackCurve.Height; } } @@ -199,7 +178,7 @@ private void Button_Click(object sender, RoutedEventArgs e) int idx = (int)Thumb.Tag; Thumb.Height = StackCurve.Height / 2.0f; - profileCurrent.aiming_array[idx].y = Thumb.Height / StackCurve.Height; + currentProfile.aiming_array[idx].y = Thumb.Height / StackCurve.Height; } } @@ -213,7 +192,7 @@ private void Button_Click_1(object sender, RoutedEventArgs e) float value = (float)(-Math.Sqrt(idx * tempx) + 0.85f); Thumb.Height = StackCurve.Height * value; - profileCurrent.aiming_array[idx].y = Thumb.Height / StackCurve.Height; + currentProfile.aiming_array[idx].y = Thumb.Height / StackCurve.Height; } } @@ -227,7 +206,7 @@ private void Button_Click_2(object sender, RoutedEventArgs e) float value = (float)(Math.Sqrt(idx * tempx) + 0.25f - (tempx * idx)); Thumb.Height = StackCurve.Height * value; - profileCurrent.aiming_array[idx].y = Thumb.Height / StackCurve.Height; + currentProfile.aiming_array[idx].y = Thumb.Height / StackCurve.Height; } } @@ -238,58 +217,72 @@ private void Expander_Expanded(object sender, RoutedEventArgs e) private void SliderAimingDownSightsMultiplier_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { - if (profileCurrent is null) + if (currentProfile is null) return; - profileCurrent.aiming_down_sights_multiplier = (float)tb_ProfileAimingDownSightsMultiplier.Value; - } - - private void AimingDownSightsActivatorsTickedEvent(object sender, RoutedEventArgs e) - { - foreach (ControllerButtonFlags button in (ControllerButtonFlags[])Enum.GetValues(typeof(ControllerButtonFlags))) - { - if ((bool)AimingDownSightsActivators[button].IsChecked) - { - profileCurrent.aiming_down_sights_activation |= button; - } - } - } - - private void AimingDownSightsActivatorsUntickedEvent(object sender, RoutedEventArgs e) - { - foreach (ControllerButtonFlags button in (ControllerButtonFlags[])Enum.GetValues(typeof(ControllerButtonFlags))) - { - if (!(bool)AimingDownSightsActivators[button].IsChecked) - { - // Perform a bitwise "AND" mask with every bit set - // except the ones already ticked, use complement. - profileCurrent.aiming_down_sights_activation &= ~button; - } - } + currentProfile.aiming_down_sights_multiplier = (float)tb_ProfileAimingDownSightsMultiplier.Value; } private void Toggle_FlickStick_Toggled(object sender, RoutedEventArgs e) { - if (profileCurrent == null) + if (currentProfile == null) return; - profileCurrent.flickstick_enabled = (bool)Toggle_FlickStick.IsOn; + currentProfile.flickstick_enabled = (bool)Toggle_FlickStick.IsOn; } private void SliderFlickDuration_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { - if (profileCurrent is null) + if (currentProfile is null) return; - profileCurrent.flick_duration = (float)tb_ProfileFlickDuration.Value / 1000; + currentProfile.flick_duration = (float)tb_ProfileFlickDuration.Value / 1000; } private void SliderStickSensivity_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { - if (profileCurrent is null) + if (currentProfile is null) return; - profileCurrent.stick_sensivity = (float)tb_ProfileStickSensitivity.Value; + currentProfile.stick_sensivity = (float)tb_ProfileStickSensitivity.Value; + } + + private void TriggerCreated(Hotkey hotkey) + { + switch (hotkey.hotkeyId) + { + case 51: + { + // pull hotkey + ProfilesPageHotkey = hotkey; + + // add to UI + Border hotkeyBorder = ProfilesPageHotkey.GetHotkey(); + if (hotkeyBorder is null || hotkeyBorder.Parent != null) + return; + + UMC_Activator.Children.Add(hotkeyBorder); + } + break; + } + } + + private void TriggerUpdated(string listener, InputsChord inputs, InputsManager.ListenerType type) + { + Hotkey hotkey = HotkeysManager.Hotkeys.Values.Where(item => item.inputsHotkey.Listener.Equals(listener)).FirstOrDefault(); + + if (hotkey is null) + return; + + switch (hotkey.hotkeyId) + { + case 51: + { + // update profile + currentProfile.aiming_down_sights_activation = inputs.GamepadButtons; + } + break; + } } } } diff --git a/HandheldCompanion/Views/Pages/ProfilesPage.xaml b/HandheldCompanion/Views/Pages/ProfilesPage.xaml index b5fad75ae..1d50da1a5 100644 --- a/HandheldCompanion/Views/Pages/ProfilesPage.xaml +++ b/HandheldCompanion/Views/Pages/ProfilesPage.xaml @@ -129,7 +129,7 @@ - + @@ -458,47 +458,28 @@ - - + + - + - + - - - - - - + + - - - - - - - - - - + - - - - - - -