diff --git a/src/Artemis.Core/Services/RgbService.cs b/src/Artemis.Core/Services/RgbService.cs index 30e359658..6d322b8d0 100644 --- a/src/Artemis.Core/Services/RgbService.cs +++ b/src/Artemis.Core/Services/RgbService.cs @@ -197,7 +197,7 @@ namespace Artemis.Core.Services public ArtemisLayout ApplyBestDeviceLayout(ArtemisDevice device) { ArtemisLayout layout; - + // Configured layout path takes precedence over all other options if (device.CustomLayoutPath != null) { @@ -239,6 +239,7 @@ namespace Artemis.Core.Services public void ApplyDeviceLayout(ArtemisDevice device, ArtemisLayout layout, bool createMissingLeds, bool removeExessiveLeds) { device.ApplyLayout(layout, createMissingLeds, removeExessiveLeds); + UpdateLedGroup(); } public ArtemisDevice? GetDevice(IRGBDevice rgbDevice) diff --git a/src/Artemis.UI.Shared/Controls/DeviceVisualizerLed.cs b/src/Artemis.UI.Shared/Controls/DeviceVisualizerLed.cs index 35adaf092..640812016 100644 --- a/src/Artemis.UI.Shared/Controls/DeviceVisualizerLed.cs +++ b/src/Artemis.UI.Shared/Controls/DeviceVisualizerLed.cs @@ -17,7 +17,7 @@ namespace Artemis.UI.Shared private SolidColorBrush? _renderColorBrush; private Color _renderColor; - + public DeviceVisualizerLed(ArtemisLed led) { Led = led; @@ -51,7 +51,7 @@ namespace Artemis.UI.Shared byte g = Led.RgbLed.Color.GetG(); byte b = Led.RgbLed.Color.GetB(); - _renderColor.A = (byte)(isDimmed ? 100 : 255); + _renderColor.A = (byte) (isDimmed ? 100 : 255); _renderColor.A = isDimmed ? Dimmed : NonDimmed; _renderColor.R = r; _renderColor.G = g; @@ -135,6 +135,8 @@ namespace Artemis.UI.Shared { try { + double width = Led.RgbLed.Size.Width - deflateAmount; + double height = Led.RgbLed.Size.Height - deflateAmount; // DisplayGeometry = Geometry.Parse(Led.RgbLed.ShapeData); DisplayGeometry = Geometry.Combine( Geometry.Empty, @@ -144,11 +146,27 @@ namespace Artemis.UI.Shared { Children = new TransformCollection { - new ScaleTransform(Led.RgbLed.Size.Width - deflateAmount, Led.RgbLed.Size.Height - deflateAmount), + new ScaleTransform(width, height), new TranslateTransform(deflateAmount / 2, deflateAmount / 2) } } ); + + if (DisplayGeometry.Bounds.Width > width) + { + DisplayGeometry = Geometry.Combine(Geometry.Empty, DisplayGeometry, GeometryCombineMode.Union, new TransformGroup + { + Children = new TransformCollection {new ScaleTransform(width / DisplayGeometry.Bounds.Width, 1)} + }); + } + + if (DisplayGeometry.Bounds.Height > height) + { + DisplayGeometry = Geometry.Combine(Geometry.Empty, DisplayGeometry, GeometryCombineMode.Union, new TransformGroup + { + Children = new TransformCollection {new ScaleTransform(1, height / DisplayGeometry.Bounds.Height)} + }); + } } catch (Exception) { diff --git a/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelDynamicViewModel.cs b/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelDynamicViewModel.cs index 55ac8e376..f7ead0cbb 100644 --- a/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelDynamicViewModel.cs +++ b/src/Artemis.UI.Shared/DataModelVisualization/Input/DataModelDynamicViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Timers; @@ -139,7 +140,11 @@ namespace Artemis.UI.Shared.Input set { if (!SetAndNotify(ref _isDataModelViewModelOpen, value)) return; - if (value) UpdateDataModelVisualization(); + if (value) + { + UpdateDataModelVisualization(); + OpenSelectedValue(DataModelViewModel); + } } } @@ -303,6 +308,21 @@ namespace Artemis.UI.Shared.Input extraDataModelViewModel.Update(_dataModelUIService, new DataModelUpdateConfiguration(LoadEventChildren)); } + private void OpenSelectedValue(DataModelVisualizationViewModel dataModelPropertiesViewModel) + { + if (DataModelPath == null) + return; + + if (dataModelPropertiesViewModel.Children.Any(c => c.DataModelPath != null && DataModelPath.Path.StartsWith(c.DataModelPath.Path))) + { + dataModelPropertiesViewModel.IsVisualizationExpanded = true; + foreach (DataModelVisualizationViewModel dataModelVisualizationViewModel in dataModelPropertiesViewModel.Children) + { + OpenSelectedValue(dataModelVisualizationViewModel); + } + } + } + #endregion #region Events diff --git a/src/Artemis.UI/Screens/Settings/Device/DeviceDialogView.xaml b/src/Artemis.UI/Screens/Settings/Device/DeviceDialogView.xaml index 7b82c904e..9e8dc0c23 100644 --- a/src/Artemis.UI/Screens/Settings/Device/DeviceDialogView.xaml +++ b/src/Artemis.UI/Screens/Settings/Device/DeviceDialogView.xaml @@ -24,110 +24,124 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Device/DeviceDialogViewModel.cs b/src/Artemis.UI/Screens/Settings/Device/DeviceDialogViewModel.cs index 97d3ce8fb..c1472c721 100644 --- a/src/Artemis.UI/Screens/Settings/Device/DeviceDialogViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Device/DeviceDialogViewModel.cs @@ -9,6 +9,7 @@ using Artemis.Core.Services; using Artemis.UI.Ninject.Factories; using Artemis.UI.Screens.Shared; using Artemis.UI.Shared.Services; +using MaterialDesignThemes.Wpf; using Ookii.Dialogs.Wpf; using RGB.NET.Layout; using Stylet; @@ -21,6 +22,7 @@ namespace Artemis.UI.Screens.Settings.Device private readonly IDialogService _dialogService; private readonly IRgbService _rgbService; private ArtemisLed _selectedLed; + private SnackbarMessageQueue _deviceMessageQueue; public DeviceDialogViewModel(ArtemisDevice device, IDeviceService deviceService, IRgbService rgbService, IDialogService dialogService, IDeviceDebugVmFactory factory) { @@ -38,9 +40,28 @@ namespace Artemis.UI.Screens.Settings.Device DisplayName = $"{device.RgbDevice.DeviceInfo.Model} | Artemis"; } + protected override void OnInitialActivate() + { + DeviceMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(5)); + Device.DeviceUpdated += DeviceOnDeviceUpdated; + base.OnInitialActivate(); + } + + protected override void OnClose() + { + Device.DeviceUpdated -= DeviceOnDeviceUpdated; + base.OnClose(); + } + public ArtemisDevice Device { get; } public PanZoomViewModel PanZoomViewModel { get; } - + + public SnackbarMessageQueue DeviceMessageQueue + { + get => _deviceMessageQueue; + set => SetAndNotify(ref _deviceMessageQueue, value); + } + public ArtemisLed SelectedLed { get => _selectedLed; @@ -50,7 +71,10 @@ namespace Artemis.UI.Screens.Settings.Device NotifyOfPropertyChange(nameof(SelectedLeds)); } } - public List SelectedLeds => SelectedLed != null ? new List { SelectedLed } : null; + + public bool CanExportLayout => Device.Layout?.IsValid ?? false; + + public List SelectedLeds => SelectedLed != null ? new List {SelectedLed} : null; public bool CanOpenImageDirectory => Device.Layout?.Image != null; @@ -165,5 +189,14 @@ namespace Artemis.UI.Screens.Settings.Device #endregion // ReSharper restore UnusedMember.Global + + #region Event handlers + + private void DeviceOnDeviceUpdated(object? sender, EventArgs e) + { + NotifyOfPropertyChange(nameof(CanExportLayout)); + } + + #endregion } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Device/Tabs/DeviceInfoTabView.xaml b/src/Artemis.UI/Screens/Settings/Device/Tabs/DeviceInfoTabView.xaml index 5b4ce48a4..3f5047fb9 100644 --- a/src/Artemis.UI/Screens/Settings/Device/Tabs/DeviceInfoTabView.xaml +++ b/src/Artemis.UI/Screens/Settings/Device/Tabs/DeviceInfoTabView.xaml @@ -91,15 +91,21 @@ - Layout file path - + Text="{Binding DefaultLayoutPath}" /> @@ -108,14 +114,19 @@ Image file path - + Text="{Binding Device.Layout.Image.LocalPath}" /> \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Device/Tabs/DeviceInfoTabViewModel.cs b/src/Artemis.UI/Screens/Settings/Device/Tabs/DeviceInfoTabViewModel.cs index e386b676a..bf97b4e21 100644 --- a/src/Artemis.UI/Screens/Settings/Device/Tabs/DeviceInfoTabViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Device/Tabs/DeviceInfoTabViewModel.cs @@ -1,4 +1,5 @@ -using Artemis.Core; +using System.Windows; +using Artemis.Core; using RGB.NET.Core; using Stylet; @@ -6,6 +7,8 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs { public class DeviceInfoTabViewModel : Screen { + private string _defaultLayoutPath; + public DeviceInfoTabViewModel(ArtemisDevice device) { Device = device; @@ -14,5 +17,23 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs public bool IsKeyboard => Device.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard; public ArtemisDevice Device { get; } + + public string DefaultLayoutPath + { + get => _defaultLayoutPath; + set => SetAndNotify(ref _defaultLayoutPath, value); + } + + public void CopyToClipboard(string content) + { + Clipboard.SetText(content); + ((DeviceDialogViewModel) Parent).DeviceMessageQueue.Enqueue("Copied path to clipboard."); + } + + protected override void OnInitialActivate() + { + DefaultLayoutPath = Device.DeviceProvider.LoadLayout(Device).FilePath; + base.OnInitialActivate(); + } } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabView.xaml b/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabView.xaml index b6e4afd4e..0d69ed4ee 100644 --- a/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabView.xaml +++ b/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabView.xaml @@ -174,20 +174,31 @@ - - - - - - + + + + + + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabViewModel.cs b/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabViewModel.cs index 19f425e70..59f3ddc57 100644 --- a/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Device/Tabs/DevicePropertiesTabViewModel.cs @@ -15,7 +15,6 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs public class DevicePropertiesTabViewModel : Screen { private readonly ICoreService _coreService; - private readonly IMessageService _messageService; private readonly IDialogService _dialogService; private readonly IRgbService _rgbService; private float _blueScale; @@ -34,13 +33,11 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs public DevicePropertiesTabViewModel(ArtemisDevice device, ICoreService coreService, IRgbService rgbService, - IMessageService messageService, IDialogService dialogService, IModelValidator validator) : base(validator) { _coreService = coreService; _rgbService = rgbService; - _messageService = messageService; _dialogService = dialogService; Device = device; @@ -115,7 +112,7 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs if (e.OriginalSource is Button) { Device.CustomLayoutPath = null; - _messageService.ShowMessage("Cleared imported layout"); + ((DeviceDialogViewModel) Parent).DeviceMessageQueue.Enqueue("Cleared imported layout."); return; } @@ -126,13 +123,13 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs if (result == true) { Device.CustomLayoutPath = dialog.FileName; - _messageService.ShowMessage($"Imported layout from {dialog.FileName}"); + ((DeviceDialogViewModel) Parent).DeviceMessageQueue.Enqueue($"Imported layout from {dialog.FileName}."); } } public async Task SelectPhysicalLayout() { - await _dialogService.ShowDialog(new Dictionary {{"device", Device}}); + await _dialogService.ShowDialogAt("DeviceDialog", new Dictionary {{"device", Device}}); } public async Task Apply() @@ -151,7 +148,8 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs Device.RedScale = RedScale / 100f; Device.GreenScale = GreenScale / 100f; Device.BlueScale = BlueScale / 100f; - + _rgbService.SaveDevice(Device); + _coreService.ModuleRenderingDisabled = false; } @@ -195,7 +193,8 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs private void DeviceOnPropertyChanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == nameof(Device.CustomLayoutPath)) _rgbService.ApplyBestDeviceLayout(Device); + if (e.PropertyName == nameof(Device.CustomLayoutPath)) + _rgbService.ApplyBestDeviceLayout(Device); } private void OnFrameRendering(object sender, FrameRenderingEventArgs e)