diff --git a/src/App.xaml b/src/App.xaml index d7c24bb..228de02 100644 --- a/src/App.xaml +++ b/src/App.xaml @@ -274,13 +274,13 @@ - + - + diff --git a/src/Controls/LinearAxisMap.xaml.cs b/src/Controls/LinearAxisMap.xaml.cs index 83a5c78..2396365 100644 --- a/src/Controls/LinearAxisMap.xaml.cs +++ b/src/Controls/LinearAxisMap.xaml.cs @@ -20,7 +20,42 @@ public partial class LinearAxisMap : UserControl private double _gaugeWidth = 120; private double _gaugeHeight = 20; + public static DependencyProperty AxisHandProperty = DependencyProperty.Register(nameof(AxisHand), typeof(int), typeof(LinearAxisMap), new FrameworkPropertyMetadata(0, OnPropertyChangedChanged)); + public static DependencyProperty IsMultiActionProperty = DependencyProperty.Register(nameof(IsMultiAction), typeof(int), typeof(LinearAxisMap), new FrameworkPropertyMetadata(0, OnPropertyChangedChanged)); + public static DependencyProperty SegmentCountProperty = DependencyProperty.Register(nameof(SegmentCount), typeof(int), typeof(LinearAxisMap), new FrameworkPropertyMetadata(0, OnPropertyChangedChanged)); + public static DependencyProperty SegmentBoundaryProperty = DependencyProperty.Register(nameof(SegmentBoundary), typeof(int), typeof(LinearAxisMap), new FrameworkPropertyMetadata(0, OnPropertyChangedChanged)); + private static void OnPropertyChangedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) + { + if (!(sender is LinearAxisMap prop)) return; + if (e.Property.Name == nameof(AxisHand)) prop.DrawRectangle((int)e.NewValue); + if (e.Property.Name == nameof(IsMultiAction) || e.Property.Name == nameof(SegmentCount)) prop.OnSegmentsChanged(); + if (e.Property.Name == nameof(SegmentBoundary)) prop.ChangeSegmentBoundary(); + } + + public int AxisHand + { + get => (int)GetValue(AxisHandProperty); + set => SetValue(AxisHandProperty, value); + } + + public int IsMultiAction + { + get => (int)GetValue(IsMultiActionProperty); + set => SetValue(IsMultiActionProperty, value); + } + + public int SegmentCount + { + get => (int)GetValue(SegmentCountProperty); + set => SetValue(SegmentCountProperty, value); + } + + public int SegmentBoundary + { + get => (int)GetValue(SegmentBoundaryProperty); + set => SetValue(SegmentBoundaryProperty, value); + } public LinearAxisMap() { InitializeComponent(); @@ -38,33 +73,17 @@ private bool SegmentFilter(object segment) return _axisVm.SegmentFilter(segment); } - private void _axisVm_OnAxisValueChanged(object sender, AxisChangedViewModelEventArgs e) - { - DrawRectangle(e.Value); - } - private void AxisMap_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { - if (_axisVm != null) - { - _axisVm.OnAxisValueChanged -= _axisVm_OnAxisValueChanged; - _axisVm.PropertyChanged -= _axisVm_PropertyChanged; - _axisVm.SegmentBoundaryChanged -= _axisVm_SegmentBoundaryChanged; - } - _axisVm = DataContext as AxisMapViewModel; if (_axisVm == null) return; SetSegmentBoundaryFilter(); - _axisVm.OnAxisValueChanged += _axisVm_OnAxisValueChanged; - _axisVm.PropertyChanged += _axisVm_PropertyChanged; - _axisVm.SegmentBoundaryChanged += _axisVm_SegmentBoundaryChanged; - OnSegmentsChanged(); } - private void _axisVm_SegmentBoundaryChanged(object sender, EventArgs e) + private void ChangeSegmentBoundary() { Dispatcher?.Invoke(() => { @@ -83,14 +102,6 @@ private void SetSegmentBoundaryFilter() } } - private void _axisVm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) - { - if (e.PropertyName == nameof(_axisVm.SegmentCount) || e.PropertyName == nameof(_axisVm.IsMultiAction)) - { - OnSegmentsChanged(); - } - } - private void OnSegmentsChanged() { RemoveAllSegmentLines(); diff --git a/src/Controls/RadialAxisMap.xaml.cs b/src/Controls/RadialAxisMap.xaml.cs index 6ec5c57..d5318f1 100644 --- a/src/Controls/RadialAxisMap.xaml.cs +++ b/src/Controls/RadialAxisMap.xaml.cs @@ -1,7 +1,8 @@ -using System; +using SierraHOTAS.ViewModels; +using System; using System.Collections.Generic; +using System.Diagnostics; using System.Windows; -using SierraHOTAS.ViewModels; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; @@ -11,6 +12,8 @@ namespace SierraHOTAS.Controls { public partial class RadialAxisMap : UserControl { + private static int instances = 0; + private Guid id; private AxisMapViewModel _axisVm; private Line _arc; private Ellipse _circle; @@ -18,16 +21,57 @@ public partial class RadialAxisMap : UserControl private double _gaugeDiameter = 40; private readonly Color _directionalColor; + public static DependencyProperty AxisHandProperty = DependencyProperty.Register(nameof(AxisHand), typeof(int), typeof(RadialAxisMap), new FrameworkPropertyMetadata(0, OnPropertyChangedChanged)); + public static DependencyProperty IsMultiActionProperty = DependencyProperty.Register(nameof(IsMultiAction), typeof(int), typeof(RadialAxisMap), new FrameworkPropertyMetadata(0, OnPropertyChangedChanged)); + public static DependencyProperty SegmentCountProperty = DependencyProperty.Register(nameof(SegmentCount), typeof(int), typeof(RadialAxisMap), new FrameworkPropertyMetadata(0, OnPropertyChangedChanged)); + public static DependencyProperty SegmentBoundaryProperty = DependencyProperty.Register(nameof(SegmentBoundary), typeof(int), typeof(RadialAxisMap), new FrameworkPropertyMetadata(0, OnPropertyChangedChanged)); + + private static void OnPropertyChangedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) + { + if (!(sender is RadialAxisMap prop)) return; + if(e.Property.Name == nameof(AxisHand)) prop.DrawCircle((int)e.NewValue); + if(e.Property.Name == nameof(IsMultiAction) || e.Property.Name == nameof(SegmentCount)) prop.OnSegmentsChanged(); + if(e.Property.Name == nameof(SegmentBoundary)) prop.ChangeSegmentBoundary(); + } + + public int AxisHand + { + get => (int)GetValue(AxisHandProperty); + set => SetValue(AxisHandProperty, value); + } + + public int IsMultiAction + { + get => (int)GetValue(IsMultiActionProperty); + set => SetValue(IsMultiActionProperty, value); + } + + public int SegmentCount + { + get => (int)GetValue(SegmentCountProperty); + set => SetValue(SegmentCountProperty, value); + } + + public int SegmentBoundary + { + get => (int)GetValue(SegmentBoundaryProperty); + set => SetValue(SegmentBoundaryProperty, value); + } public RadialAxisMap() { InitializeComponent(); + instances++; _segmentLines = new List(); _directionalColor = (Color)ColorConverter.ConvertFromString("#80e5ff"); DataContextChanged += AxisMap_DataContextChanged; + CreateDial(); + + id = Guid.NewGuid(); + Debug.WriteLine($"RadialAxisMap Constructor - instances:{instances} - {id}"); } private bool SegmentFilter(object segment) @@ -35,33 +79,17 @@ private bool SegmentFilter(object segment) return _axisVm.SegmentFilter(segment); } - private void _axisVm_OnAxisValueChanged(object sender, AxisChangedViewModelEventArgs e) - { - DrawCircle(e.Value); - } - private void AxisMap_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { - if (_axisVm != null) - { - _axisVm.OnAxisValueChanged -= _axisVm_OnAxisValueChanged; - _axisVm.PropertyChanged -= _axisVm_PropertyChanged; - _axisVm.SegmentBoundaryChanged -= _axisVm_SegmentBoundaryChanged; - } - _axisVm = DataContext as AxisMapViewModel; if (_axisVm == null) return; SetSegmentBoundaryFilter(); - _axisVm.OnAxisValueChanged += _axisVm_OnAxisValueChanged; - _axisVm.PropertyChanged += _axisVm_PropertyChanged; - _axisVm.SegmentBoundaryChanged += _axisVm_SegmentBoundaryChanged; - OnSegmentsChanged(); } - private void _axisVm_SegmentBoundaryChanged(object sender, EventArgs e) + private void ChangeSegmentBoundary() { Dispatcher.Invoke(() => { @@ -79,13 +107,6 @@ private void SetSegmentBoundaryFilter() view.Filter = SegmentFilter; } } - private void _axisVm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) - { - if (e.PropertyName == nameof(_axisVm.SegmentCount) || e.PropertyName == nameof(_axisVm.IsMultiAction)) - { - OnSegmentsChanged(); - } - } private void OnSegmentsChanged() { diff --git a/src/CustomSierraJsonConverter.cs b/src/CustomSierraJsonConverter.cs index 96d288c..5eeebfb 100644 --- a/src/CustomSierraJsonConverter.cs +++ b/src/CustomSierraJsonConverter.cs @@ -2,6 +2,7 @@ using SierraJSON; using System; using System.Linq; +using System.Reflection; namespace SierraHOTAS { @@ -154,7 +155,9 @@ private static void SerializeAxis(HOTASAxis axis) if (prop.Name == nameof(axis.SoundFileName) && string.IsNullOrEmpty((string)prop.GetValue(axis))) continue; if (prop.Name == nameof(axis.SoundVolume) && Math.Abs((float)prop.GetValue(axis) - 1.0d) < 0.01) continue; - Serializer.WriteKeyValue(prop.Name, value); + var isNoHide = prop.GetCustomAttribute(typeof(SierraJsonNoHide)); + + Serializer.WriteKeyValue(prop.Name, value, isNoHide != null); } Serializer.WriteObjectEnd(); } diff --git a/src/Models/HOTASAxis.cs b/src/Models/HOTASAxis.cs index 3ba4687..9c9fd13 100644 --- a/src/Models/HOTASAxis.cs +++ b/src/Models/HOTASAxis.cs @@ -8,11 +8,12 @@ namespace SierraHOTAS.Models { public class HOTASAxis : IHotasBaseMap { - public event EventHandler OnAxisDirectionChanged; - public event EventHandler OnAxisSegmentChanged; + public event EventHandler AxisDirectionChanged; + public event EventHandler AxisSegmentChanged; public int MapId { get; set; } public string MapName { get; set; } + [SierraJsonNoHide] public HOTASButton.ButtonType Type { get; set; } public ObservableCollection ButtonMap { get; set; } public ObservableCollection ReverseButtonMap { get; set; } @@ -106,7 +107,7 @@ private void SetDirection(int value) Direction = AxisDirection.Forward; } - OnAxisDirectionChanged?.Invoke(this, new AxisDirectionChangedEventArgs() { NewDirection = Direction }); + AxisDirectionChanged?.Invoke(this, new AxisDirectionChangedEventArgs() { NewDirection = Direction }); } private void DetectSelectedSegment(int value) @@ -121,7 +122,7 @@ private void DetectSelectedSegment(int value) _currentSegment = newSegment; IsSegmentChanged = true; - OnAxisSegmentChanged?.Invoke(this, new AxisSegmentChangedEventArgs() { NewSegment = _currentSegment }); + AxisSegmentChanged?.Invoke(this, new AxisSegmentChangedEventArgs() { NewSegment = _currentSegment }); } public void CalculateSegmentRange(int segments) diff --git a/src/Models/HOTASButton.cs b/src/Models/HOTASButton.cs index 5fc0b51..1fe7c8c 100644 --- a/src/Models/HOTASButton.cs +++ b/src/Models/HOTASButton.cs @@ -17,6 +17,7 @@ public enum ButtonType public int MapId { get; set; } public string MapName { get; set; } + [SierraJsonNoHide] public ButtonType Type { get; set; } public int ShiftModePage { get; set; } public bool IsShift { get; set; } diff --git a/src/Models/HOTASQueue.cs b/src/Models/HOTASQueue.cs index 1a660e3..28d6e9a 100644 --- a/src/Models/HOTASQueue.cs +++ b/src/Models/HOTASQueue.cs @@ -1,14 +1,13 @@ //todo can remove sharpdx dependency...replace JoystickUpdate with custom array. can do this in the joystickwrapper for the call to GetCurrentState using SharpDX.DirectInput; +using SierraHOTAS.Win32; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; -using SierraHOTAS.Win32; namespace SierraHOTAS.Models { @@ -39,7 +38,6 @@ public class HOTASQueue : IHOTASQueue private IKeyboard Keyboard { get; set; } private IJoystick Joystick { get; set; } - private ObservableCollection _buttonMap; private Dictionary> _modes; public HOTASQueue(IKeyboard keyboard) @@ -51,10 +49,9 @@ public void Listen(IJoystick joystick, Dictionary 0) _buttonMap = _modes[1]; - _jitterDetectionDictionary = new Dictionary(); _actionJobs = new BlockingCollection(); @@ -481,29 +478,15 @@ private void OnAxisChanged(JoystickUpdate state) AxisChanged?.Invoke(this, new AxisChangedEventArgs() { AxisId = (int)state.Offset, Value = state.Value, Device = null }); } - //public IHotasBaseMap GetMap(int buttonOffset) - //{ - // return _buttonMap.FirstOrDefault(m => m.MapId == buttonOffset); - //} - public IHotasBaseMap GetMap(int buttonOffset) { - var map = _buttonMap.FirstOrDefault(m => m.MapId == buttonOffset); - if (map == null) - { - Debug.WriteLine("fuck"); - } - return map; + return _modes[_mode].FirstOrDefault(m => m.MapId == buttonOffset); } private IHotasBaseMap GetMapFromParentMode(int parentModeId, int buttonOffset) { var parentMode = _modes[parentModeId]; var map = parentMode.FirstOrDefault(m => m.MapId == buttonOffset) as HOTASButton; - //if (map.ActionCatalogItem.Actions.Count > 0 && map.ShiftModePage <= 0) - //{ - // ModeSelected?.Invoke(this, new ModeSelectedEventArgs(){IsShift = true, Mode = parentModeId }); - //} return map; } @@ -517,16 +500,9 @@ private void OnButtonRelease(int buttonId) ButtonReleased?.Invoke(this, new ButtonPressedEventArgs() { ButtonId = buttonId, Device = null }); } - [Obsolete] - public void SetButtonMap(ObservableCollection buttonMap) - { - _buttonMap = buttonMap; - } - public void ActivateMode(int mode) { _mode = mode; - _buttonMap = _modes[_mode]; } public void SetModesCollection(Dictionary> modes) diff --git a/src/Models/IHOTASQueue.cs b/src/Models/IHOTASQueue.cs index 2a23de5..b0b4da4 100644 --- a/src/Models/IHOTASQueue.cs +++ b/src/Models/IHOTASQueue.cs @@ -22,7 +22,6 @@ public interface IHOTASQueue void ForceButtonPress(JoystickOffset offset, bool isDown); void Stop(); IHotasBaseMap GetMap(int buttonOffset); - void SetButtonMap(ObservableCollection buttonMap); void ActivateMode(int mode); void SetModesCollection(Dictionary> modes); } diff --git a/src/Models/MediaPlayerWrapper.cs b/src/Models/MediaPlayerWrapper.cs index a25d8b5..ab0d27f 100644 --- a/src/Models/MediaPlayerWrapper.cs +++ b/src/Models/MediaPlayerWrapper.cs @@ -21,7 +21,7 @@ public void Play() public void Close() { - _audioFile.Close(); + _audioFile?.Close(); } public void Open(string sourceFilePath) diff --git a/src/Serializer/CustomAttributes.cs b/src/Serializer/CustomAttributes.cs index afd2102..6d6ee17 100644 --- a/src/Serializer/CustomAttributes.cs +++ b/src/Serializer/CustomAttributes.cs @@ -35,7 +35,15 @@ public SierraJsonIgnore() { } } - + + [AttributeUsage(AttributeTargets.Property)] + public class SierraJsonNoHide : Attribute + { + public SierraJsonNoHide() + { + } + } + public class SierraJsonAttributes { public static PropertyInfo[] GetSerializableProperties(Object obj) diff --git a/src/Serializer/SierraJSON.cs b/src/Serializer/SierraJSON.cs index 113a348..17762e1 100644 --- a/src/Serializer/SierraJSON.cs +++ b/src/Serializer/SierraJSON.cs @@ -51,9 +51,9 @@ public static void WriteObjectEnd() Write.WriteObjectEnd(); } - public static void WriteKeyValue(string key, object value) + public static void WriteKeyValue(string key, object value, bool isNoHide = false) { - Write.WriteKeyValue(key, value); + Write.WriteKeyValue(key, value, isNoHide); } public class SierraJSONException : Exception diff --git a/src/Serializer/Write.cs b/src/Serializer/Write.cs index 9730833..9a46a71 100644 --- a/src/Serializer/Write.cs +++ b/src/Serializer/Write.cs @@ -61,9 +61,9 @@ public static void WriteObjectStart() _converterRequiresKeyValueSeparator = false; } - public static void WriteKeyValue(string key, object value) + public static void WriteKeyValue(string key, object value, bool isNoHide = false) { - if (HideValue(value)) return; + if (!isNoHide && HideValue(value)) return; if (_converterRequiresKeyValueSeparator) @@ -272,8 +272,7 @@ private static void WriteObject(object obj) var sierraObjectAttribute = (SierraJsonObject)type.GetCustomAttribute(typeof(SierraJsonObject)); var isOptIn = sierraObjectAttribute?.Option == SierraJsonObject.MemberSerialization.OptIn; - - + PropertyInfo[] propList; if (isOptIn) { diff --git a/src/ViewModels/AxisMapViewModel.cs b/src/ViewModels/AxisMapViewModel.cs index b9cce84..cf35a9b 100644 --- a/src/ViewModels/AxisMapViewModel.cs +++ b/src/ViewModels/AxisMapViewModel.cs @@ -1,4 +1,5 @@ using SierraHOTAS.Annotations; +using SierraHOTAS.Factories; using SierraHOTAS.Models; using SierraHOTAS.ViewModels.Commands; using System; @@ -6,9 +7,6 @@ using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Threading; -using SierraHOTAS.Factories; namespace SierraHOTAS.ViewModels { @@ -25,9 +23,8 @@ public class AxisMapViewModel : IBaseMapViewModel, INotifyPropertyChanged private IMediaPlayer _mediaPlayer; private readonly IDispatcher _appDispatcher; public event PropertyChangedEventHandler PropertyChanged; - public event EventHandler OnAxisValueChanged; + public event EventHandler AxisValueChanged; public event EventHandler RecordingStopped; - public event EventHandler SegmentBoundaryChanged; public bool IsDisabledForced { get; set; } public bool IsRecording { get; set; } @@ -82,6 +79,19 @@ public ObservableCollection Segments set => _hotasAxis.Segments = value; } + //not a real property that stores data. This is used only for triggering binding to the AxisMap ViewModels + private int _segmentBoundary; + public int SegmentBoundary + { + get => _segmentBoundary; + set + { + if (_segmentBoundary == value) return; + _segmentBoundary = value; + OnPropertyChanged(); + } + } + public bool IsMultiAction { get => _hotasAxis.IsMultiAction; @@ -129,6 +139,18 @@ public float SoundVolume } } + private int _axisValue; + public int AxisValue + { + get => _axisValue; + set + { + if (value == _axisValue) return; + _axisValue = value; + OnPropertyChanged(); + } + } + public AxisDirection Direction { get; set; } = AxisDirection.Forward; private ObservableCollection _buttonMap; @@ -170,8 +192,8 @@ public AxisMapViewModel(IDispatcher dispatcher, MediaPlayerFactory mediaPlayerFa _hotasAxis = map; _segmentCount = _hotasAxis.Segments.Count; - _hotasAxis.OnAxisDirectionChanged += OnAxisDirectionChanged; - _hotasAxis.OnAxisSegmentChanged += OnAxisSegmentChanged; + _hotasAxis.AxisDirectionChanged += axisDirectionChanged; + _hotasAxis.AxisSegmentChanged += axisSegmentChanged; _mediaPlayer = mediaPlayerFactory.CreateMediaPlayer(); _mediaPlayer.Volume = 0f; @@ -310,7 +332,7 @@ private void RemoveSegmentHandlers() private void Segment_PropertyChanged(object sender, PropertyChangedEventArgs e) { - SegmentBoundaryChanged?.Invoke(this, new EventArgs()); + SegmentBoundary = ((Segment)sender).Value; } /// @@ -319,18 +341,20 @@ private void Segment_PropertyChanged(object sender, PropertyChangedEventArgs e) /// public void SetAxis(int value) { + _axisValue = value; + OnPropertyChanged(nameof(AxisValue)); _appDispatcher?.Invoke(() => { - OnAxisValueChanged?.Invoke(this, new AxisChangedViewModelEventArgs() { Value = value }); + AxisValueChanged?.Invoke(this, new AxisChangedViewModelEventArgs() { Value = value }); }); } - private void OnAxisDirectionChanged(object sender, AxisDirectionChangedEventArgs e) + private void axisDirectionChanged(object sender, AxisDirectionChangedEventArgs e) { Direction = e.NewDirection; } - private void OnAxisSegmentChanged(object sender, AxisSegmentChangedEventArgs e) + private void axisSegmentChanged(object sender, AxisSegmentChangedEventArgs e) { if (string.IsNullOrWhiteSpace(SoundFileName)) return; if (sender is HOTASAxis axisMap) diff --git a/src/ViewModels/HOTASCollectionViewModel.cs b/src/ViewModels/HOTASCollectionViewModel.cs index c2c1ee8..fddf742 100644 --- a/src/ViewModels/HOTASCollectionViewModel.cs +++ b/src/ViewModels/HOTASCollectionViewModel.cs @@ -318,12 +318,14 @@ private void OnModeChanged(object sender, ModeChangedEventArgs e) private void DeviceList_KeystrokeUpSent(object sender, KeystrokeSentEventArgs e) { - AddActivity((sender as HOTASQueue)?.GetMap(e.Offset), e); + if (!(sender is IHOTASQueue q)) return; + AddActivity(q.GetMap(e.Offset), e); } private void DeviceList_KeystrokeDownSent(object sender, KeystrokeSentEventArgs e) { - AddActivity((sender as HOTASQueue)?.GetMap(e.Offset), e); + if (!(sender is IHOTASQueue q)) return; + AddActivity(q.GetMap(e.Offset), e); } private void AddActivity(IHotasBaseMap map, KeystrokeSentEventArgs e) @@ -478,13 +480,10 @@ private void RefreshDeviceList() newDevices.Remove(newDevice); - - - //TODO - find out why connecting a device after a profile is loaded doesn't re-populate all buttons - //Not all HOTASDevice Modes are being reseeded - _deviceList.ReplaceDevice(newDevice); _deviceList.ListenToDevice(newDevice); + _deviceList.Stop(); + deviceViewModel.ReplaceDevice(newDevice); deviceViewModel.RebuildMap(); diff --git a/src/Views/MainWindow.xaml.cs b/src/Views/MainWindow.xaml.cs index 0be07b6..9a5aef0 100644 --- a/src/Views/MainWindow.xaml.cs +++ b/src/Views/MainWindow.xaml.cs @@ -29,7 +29,7 @@ public partial class MainWindow : Window - //inject HOTASCollectionViewModel to this consctructor + //inject HOTASCollectionViewModel to this constructor //the ctor for HOTASCollectionViewModel should take parameters for HOTASCollection, ActionCatalog, and whatever else //figure out how to inject for all the ViewModels //register the VMs in the container in the App Onstart diff --git a/tests/AxisMapViewModelTests.cs b/tests/AxisMapViewModelTests.cs index 76846b3..2de95ac 100644 --- a/tests/AxisMapViewModelTests.cs +++ b/tests/AxisMapViewModelTests.cs @@ -494,7 +494,7 @@ public void set_axis() { var mapVm = CreateAxisMapViewModel(); - Assert.Raises(a => mapVm.OnAxisValueChanged += a, a => mapVm.OnAxisValueChanged -= a, () => mapVm.SetAxis(0)); + Assert.Raises(a => mapVm.AxisValueChanged += a, a => mapVm.AxisValueChanged -= a, () => mapVm.SetAxis(0)); } [Fact] @@ -598,7 +598,6 @@ public void open_file_command() mapVm.OpenFileCommand.Execute(default); Assert.NotEmpty(mapVm.SoundFileName); - Assert.False(subMediaPlayer.IsMuted); } [Fact] @@ -610,16 +609,6 @@ public void close_file_command() mapVm.OpenFileCommand.Execute(default); mapVm.RemoveSoundCommand.Execute(default); Assert.Empty(mapVm.SoundFileName); - Assert.True(subMediaPlayer.IsMuted); - } - - [Fact] - public void segments_property_changed() - { - var mapVm = CreateAxisMapViewModel(); - mapVm.SegmentCount = 4; - Assert.Raises(a => mapVm.SegmentBoundaryChanged += a, a => mapVm.SegmentBoundaryChanged -= a, () => mapVm.Segments[0].Value = 1); - } } } \ No newline at end of file diff --git a/tests/DeviceViewModelTests.cs b/tests/DeviceViewModelTests.cs index e23286a..6e34318 100644 --- a/tests/DeviceViewModelTests.cs +++ b/tests/DeviceViewModelTests.cs @@ -377,8 +377,8 @@ public void axis_changed() var deviceVm = CreateDeviceViewMode_AxesChanged(out _, out var hotasDevice); var axis = deviceVm.ButtonMap.First(m => m.ButtonId == (int)JoystickOffset.Slider1) as AxisMapViewModel; Assert.NotNull(axis); - Assert.Raises(a => axis.OnAxisValueChanged += a, - a => axis.OnAxisValueChanged -= a, + Assert.Raises(a => axis.AxisValueChanged += a, + a => axis.AxisValueChanged -= a, () => hotasDevice.AxisChanged += Raise.EventWith(hotasDevice, new AxisChangedEventArgs() {AxisId = axis.ButtonId, Value = 1000, Device = hotasDevice as HOTASDevice})); diff --git a/tests/HOTASAxisMapTests.cs b/tests/HOTASAxisMapTests.cs index 5259a8c..782f001 100644 --- a/tests/HOTASAxisMapTests.cs +++ b/tests/HOTASAxisMapTests.cs @@ -39,7 +39,7 @@ public void set_value_direction_changed_when_is_directional_true() map.SetAxis(800); map.SetAxis(800); Assert.True(map.Direction == AxisDirection.Forward); - Assert.Raises(a => map.OnAxisDirectionChanged += a, a => map.OnAxisDirectionChanged -= a, () => map.SetAxis(700)); + Assert.Raises(a => map.AxisDirectionChanged += a, a => map.AxisDirectionChanged -= a, () => map.SetAxis(700)); Assert.True(map.Direction == AxisDirection.Backward); } @@ -85,7 +85,7 @@ public void set_value_detect_segment_changed() map.Segments.Add(new Segment(1, 0)); map.Segments.Add(new Segment(2, 10)); map.Segments.Add(new Segment(3, 20)); - Assert.Raises(a => map.OnAxisSegmentChanged += a, a => map.OnAxisSegmentChanged -= a, () => map.SetAxis(5)); + Assert.Raises(a => map.AxisSegmentChanged += a, a => map.AxisSegmentChanged -= a, () => map.SetAxis(5)); Assert.True(map.IsSegmentChanged); } diff --git a/tests/HOTASCollectionViewModelTests.cs b/tests/HOTASCollectionViewModelTests.cs index a883f4f..dab8541 100644 --- a/tests/HOTASCollectionViewModelTests.cs +++ b/tests/HOTASCollectionViewModelTests.cs @@ -13,6 +13,7 @@ using System.Linq; using System.Windows.Threading; using NLog.LayoutRenderers; +using SierraHOTAS.Controls; using SierraHOTAS.Win32; using Xunit; using Xunit.Abstractions; @@ -951,7 +952,8 @@ public void add_activity_keystroke_down() IHOTASQueue queue = new HOTASQueue(Substitute.For()); IHotasBaseMap map = new HOTASButton() { Type = HOTASButton.ButtonType.Button, ActionName = "test action" }; - queue.SetButtonMap(new ObservableCollection() { map }); + queue.SetModesCollection(new Dictionary> { { 1, new ObservableCollection(){map} } }); + queue.ActivateMode(1); subDeviceList.KeystrokeDownSent += Raise.EventWith(queue, new KeystrokeSentEventArgs(0, 0, 0, false, false)); @@ -966,7 +968,8 @@ public void add_activity_keystroke_up() IHOTASQueue queue = new HOTASQueue(Substitute.For()); var map = new HOTASButton() { Type = HOTASButton.ButtonType.Button, ActionName = "test action" }; - queue.SetButtonMap(new ObservableCollection() { map }); + queue.SetModesCollection(new Dictionary> { { 1, new ObservableCollection(){map} } }); + queue.ActivateMode(1); subDeviceList.KeystrokeUpSent += Raise.EventWith(queue, new KeystrokeSentEventArgs(0, 0, 0, false, false)); @@ -981,8 +984,8 @@ public void add_activity_keystroke_down_for_not_axis() IHOTASQueue queue = new HOTASQueue(Substitute.For()); var map = new HOTASButton() { Type = HOTASButton.ButtonType.AxisLinear }; - - queue.SetButtonMap(new ObservableCollection() { map }); + queue.SetModesCollection(new Dictionary> { { 1, new ObservableCollection() { map } } }); + queue.ActivateMode(1); subDeviceList.KeystrokeDownSent += Raise.EventWith(queue, new KeystrokeSentEventArgs(0, 0, 0, false, false)); @@ -1000,8 +1003,8 @@ public void add_activity_keystroke_down_for_axis_forward_direction() var axisMap = new HOTASAxis() { Type = HOTASButton.ButtonType.AxisLinear, MapName = "forward", IsDirectional = false }; axisMap.ButtonMap = new ObservableCollection() { new HOTASButton() { ActionName = "button 1", MapName = "forward" } }; axisMap.ReverseButtonMap = new ObservableCollection() { new HOTASButton() { ActionName = "button 2", MapName = "reverse" } }; - - queue.SetButtonMap(new ObservableCollection() { axisMap }); + queue.SetModesCollection(new Dictionary> { { 1, new ObservableCollection() { axisMap } } }); + queue.ActivateMode(1); subDeviceList.KeystrokeDownSent += Raise.EventWith(queue, new KeystrokeSentEventArgs(0, 0, 0, false, false)); @@ -1036,7 +1039,9 @@ public void add_activity_keystroke_down_for_axis_reverse_direction() Assert.True(axisMap.Direction == AxisDirection.Backward); - queue.SetButtonMap(new ObservableCollection() { axisMap }); + queue.SetModesCollection(new Dictionary> { { 1, new ObservableCollection() { axisMap } } }); + queue.ActivateMode(1); + subDeviceList.KeystrokeDownSent += Raise.EventWith(queue, new KeystrokeSentEventArgs(0, 0, 0, false, false)); Assert.Single(hotasVm.Activity); @@ -1056,7 +1061,8 @@ public void snap_to_button() public void quick_profile_show_main_window() { var hotasVm = CreateHotasCollectionViewModel(out _, out var subDeviceList, out _, out _, out _, out var subQuickProfilePanelVm); - hotasVm.Initialize(); Assert.Raises(a => hotasVm.ShowMainWindow += a, a => hotasVm.ShowMainWindow -= a, () => subQuickProfilePanelVm.ShowWindow()); + hotasVm.Initialize(); + Assert.Raises(a => hotasVm.ShowMainWindow += a, a => hotasVm.ShowMainWindow -= a, () => subQuickProfilePanelVm.ShowWindow()); } [Fact]