Skip to content

Commit

Permalink
no longer rely on checkboxes for UMC activator(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Nov 20, 2022
1 parent ae1dfda commit 524ce80
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 303 deletions.
38 changes: 0 additions & 38 deletions ControllerCommon/Utils/InputUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
98 changes: 62 additions & 36 deletions HandheldCompanion/Managers/Hotkeys/Hotkey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
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
{
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
Expand Down Expand Up @@ -49,18 +50,16 @@ public Hotkey(ushort id, InputsHotkey _inputsHotkey)
hotkeyId = id;

inputsHotkey = _inputsHotkey;
inputsChord = new();
}

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;
Expand All @@ -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()
{
Expand All @@ -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()
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -236,7 +255,7 @@ public void DrawControl()
quickPanel.Children.Add(quickName);

// update buttons name and states
UpdateHotkey();
Refresh();
}

private void ClearButton_Click()
Expand All @@ -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()
Expand All @@ -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;
Expand Down
63 changes: 34 additions & 29 deletions HandheldCompanion/Managers/Hotkeys/InputsHotkey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,44 @@ public enum InputsHotkeyType : ushort
Windows = 2,
Handheld = 3,
Custom = 4,
UI = 5,
}

public static SortedDictionary<ushort, InputsHotkey> 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; }
Expand Down
Loading

0 comments on commit 524ce80

Please sign in to comment.