From 64dfd6de31c6dfcaff1c7c6dcb955a3752c60565 Mon Sep 17 00:00:00 2001 From: Morgan Gardner Date: Mon, 8 Aug 2022 13:58:30 +0100 Subject: [PATCH] Added toggle binds - Toggle binds can be used to display a specific page/display when a button is pressed, but returns to the previous page. A use case for this could be the Brake Magic feature on Mercedes F1 cars, where a screen displaying brake temperatures is displayed temporarily until it is de-activated. --- Properties/AssemblyInfo.cs | 4 +-- Property.xaml | 4 +++ Property.xaml.cs | 5 ++++ SwitchableProperties.csproj | 7 +++++ SwitchablePropertiesPlugin.cs | 51 +++++++++++++++++++++++++++-------- ToggleBind.xaml | 34 +++++++++++++++++++++++ ToggleBind.xaml.cs | 27 +++++++++++++++++++ 7 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 ToggleBind.xaml create mode 100644 ToggleBind.xaml.cs diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index b120f73..0b35110 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut // en utilisant '*', comme indiqué ci-dessous : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.0.0")] -[assembly: AssemblyFileVersion("1.3.0.0")] +[assembly: AssemblyVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.4.0.0")] diff --git a/Property.xaml b/Property.xaml index 36083da..a576f15 100644 --- a/Property.xaml +++ b/Property.xaml @@ -26,6 +26,7 @@ New bind New cycler bind + New toggle bind @@ -35,6 +36,9 @@ + + + diff --git a/Property.xaml.cs b/Property.xaml.cs index 592af31..c6e761a 100644 --- a/Property.xaml.cs +++ b/Property.xaml.cs @@ -37,6 +37,11 @@ private void btnAddCyclerBind_Click(object sender, RoutedEventArgs e) ((IList)pnlBinds.ItemsSource).Add(new SwitchableCyclerBind()); } + private void btnAddToggleBind_Click(object sender, RoutedEventArgs e) + { + ((IList)pnlBinds.ItemsSource).Add(new SwitchableToggleBind()); + } + private void DeleteBind_OnExecuted(object sender, ExecutedRoutedEventArgs e) { ((SwitchableProperty)this.DataContext).Binds.Remove(e.Parameter as SwitchableBind); diff --git a/SwitchableProperties.csproj b/SwitchableProperties.csproj index cb3dc86..6263385 100644 --- a/SwitchableProperties.csproj +++ b/SwitchableProperties.csproj @@ -63,6 +63,9 @@ + + ToggleBind.xaml + CyclerBind.xaml @@ -85,6 +88,10 @@ + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/SwitchablePropertiesPlugin.cs b/SwitchablePropertiesPlugin.cs index 928fd28..6b0ea9f 100644 --- a/SwitchablePropertiesPlugin.cs +++ b/SwitchablePropertiesPlugin.cs @@ -137,6 +137,14 @@ public void Init(PluginManager pluginManager) this.TriggerEvent($"{property.Property.PropertyName}Update"); }); } + else if (bind.GetType() == typeof(SwitchableToggleBind)) + { + this.AddAction($"{property.Property.PropertyName}_{bind.ActionName}", (a, b) => + { + property.PropertyValue = property.GetToggleValue(((SwitchableToggleBind)bind).PropertyValue); + this.TriggerEvent($"{property.Property.PropertyName}Update"); + }); + } } } } @@ -145,37 +153,38 @@ public void Init(PluginManager pluginManager) internal class SwitchablePropertyContainer { internal string PropertyValue; - internal int PropertyIndex; + private string _lastPropertyValue; + private int _propertyIndex; internal SwitchableProperty Property; internal string GetNextBindValue() { - PropertyIndex = GetIndexOfBind(); + _propertyIndex = GetIndexOfBind(); - PropertyIndex++; - if ((PropertyIndex) > Property.Binds + _propertyIndex++; + if ((_propertyIndex) > Property.Binds .OfType() .Count() - 1) { - PropertyIndex = 0; + _propertyIndex = 0; } - return GetBindValueAt(PropertyIndex); + return GetBindValueAt(_propertyIndex); } internal string GetPreviousBindValue() { - PropertyIndex = GetIndexOfBind(); + _propertyIndex = GetIndexOfBind(); - PropertyIndex--; - if ((PropertyIndex) < 0) + _propertyIndex--; + if ((_propertyIndex) < 0) { - PropertyIndex = Property.Binds + _propertyIndex = Property.Binds .OfType() .Count() - 1; } - return GetBindValueAt(PropertyIndex); + return GetBindValueAt(_propertyIndex); } private string GetBindValueAt(int index) @@ -195,6 +204,20 @@ private int GetIndexOfBind() return Property.Binds .IndexOf(activeBind); } + + internal string GetToggleValue(string bindValue) + { + if (bindValue == PropertyValue) + { + PropertyValue = _lastPropertyValue; + } + else + { + _lastPropertyValue = PropertyValue; + PropertyValue = bindValue; + } + return PropertyValue; + } } public class SwitchableProperty @@ -220,6 +243,12 @@ public class SwitchableCyclerBind : SwitchableBind public string Direction { get; set; } } + public class SwitchableToggleBind : SwitchableBind + { + public override string ActionName { get; set; } + public string PropertyValue { get; set; } + } + //USED FOR CONVERTING V1 SETTINGS into V1.1+ internal class OldSwitchablePropertiesSettings { diff --git a/ToggleBind.xaml b/ToggleBind.xaml new file mode 100644 index 0000000..eea27ae --- /dev/null +++ b/ToggleBind.xaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + diff --git a/ToggleBind.xaml.cs b/ToggleBind.xaml.cs new file mode 100644 index 0000000..74cb796 --- /dev/null +++ b/ToggleBind.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace SwitchableProperties +{ + /// + /// Interaction logic for ToggleBind.xaml + /// + public partial class ToggleBind : UserControl + { + public ToggleBind() + { + InitializeComponent(); + } + } +}