mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Core - Brought device load/save logic in line with the rest of the code
This commit is contained in:
1 parent
46c035851a
commit
76d424012a
11 files changed
+161
-104
No files matched your search
@@ -23,6 +23,8 @@ public class SurfaceDeviceViewModel : ActivatableViewModelBase
|
||||
private double _dragOffsetX;
|
||||
private double _dragOffsetY;
|
||||
private bool _isSelected;
|
||||
private float _x;
|
||||
private float _y;
|
||||
|
||||
public SurfaceDeviceViewModel(ArtemisDevice device, SurfaceEditorViewModel surfaceEditorViewModel, IDeviceService deviceService, ISettingsService settingsService, IWindowService windowService)
|
||||
{
|
||||
@@ -33,6 +35,8 @@ public class SurfaceDeviceViewModel : ActivatableViewModelBase
|
||||
Device = device;
|
||||
SurfaceEditorViewModel = surfaceEditorViewModel;
|
||||
DetectInput = ReactiveCommand.CreateFromTask(ExecuteDetectInput, this.WhenAnyValue(vm => vm.CanDetectInput));
|
||||
X = device.X;
|
||||
Y = device.Y;
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> DetectInput { get; }
|
||||
@@ -47,6 +51,18 @@ public class SurfaceDeviceViewModel : ActivatableViewModelBase
|
||||
set => RaiseAndSetIfChanged(ref _isSelected, value);
|
||||
}
|
||||
|
||||
public float X
|
||||
{
|
||||
get => _x;
|
||||
set => RaiseAndSetIfChanged(ref _x, value);
|
||||
}
|
||||
|
||||
public float Y
|
||||
{
|
||||
get => _y;
|
||||
set => RaiseAndSetIfChanged(ref _y, value);
|
||||
}
|
||||
|
||||
public void StartMouseDrag(Point mouseStartPosition)
|
||||
{
|
||||
if (!IsSelected)
|
||||
@@ -73,16 +89,16 @@ public class SurfaceDeviceViewModel : ActivatableViewModelBase
|
||||
|
||||
if (Fits(x, y, ignoreOverlap))
|
||||
{
|
||||
Device.X = x;
|
||||
Device.Y = y;
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
else if (Fits(x, Device.Y, ignoreOverlap))
|
||||
{
|
||||
Device.X = x;
|
||||
X = x;
|
||||
}
|
||||
else if (Fits(Device.X, y, ignoreOverlap))
|
||||
{
|
||||
Device.Y = y;
|
||||
Y = y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,10 +116,9 @@ public class SurfaceDeviceViewModel : ActivatableViewModelBase
|
||||
|
||||
IEnumerable<SKRect> own = Device.Leds
|
||||
.Select(l => SKRect.Create(l.Rectangle.Left + x, l.Rectangle.Top + y, l.Rectangle.Width, l.Rectangle.Height));
|
||||
IEnumerable<SKRect> others = _deviceService.EnabledDevices
|
||||
.Where(d => d != Device && d.IsEnabled)
|
||||
.SelectMany(d => d.Leds)
|
||||
.Select(l => SKRect.Create(l.Rectangle.Left + l.Device.X, l.Rectangle.Top + l.Device.Y, l.Rectangle.Width, l.Rectangle.Height));
|
||||
IEnumerable<SKRect> others = SurfaceEditorViewModel.SurfaceDeviceViewModels
|
||||
.Where(vm => vm != this && vm.Device.IsEnabled)
|
||||
.SelectMany(vm => vm.Device.Leds.Select(l => SKRect.Create(l.Rectangle.Left + vm.X, l.Rectangle.Top + vm.Y, l.Rectangle.Width, l.Rectangle.Height)));
|
||||
|
||||
return !own.Any(o => others.Any(l => l.IntersectsWith(o)));
|
||||
}
|
||||
@@ -122,4 +137,10 @@ public class SurfaceDeviceViewModel : ActivatableViewModelBase
|
||||
if (viewModel.MadeChanges)
|
||||
_deviceService.SaveDevice(Device);
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
Device.X = X;
|
||||
Device.Y = Y;
|
||||
}
|
||||
}
|
||||
@@ -82,8 +82,8 @@
|
||||
<ItemsControl Name="DeviceContainer" ItemsSource="{CompiledBinding SurfaceDeviceViewModels}" ClipToBounds="False">
|
||||
<ItemsControl.Styles>
|
||||
<Style Selector="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Device.X}" />
|
||||
<Setter Property="Canvas.Top" Value="{Binding Device.Y}" />
|
||||
<Setter Property="Canvas.Left" Value="{CompiledBinding X, DataType=surfaceEditor:SurfaceDeviceViewModel}" />
|
||||
<Setter Property="Canvas.Top" Value="{CompiledBinding Y, DataType=surfaceEditor:SurfaceDeviceViewModel}" />
|
||||
</Style>
|
||||
</ItemsControl.Styles>
|
||||
<ItemsControl.ItemsPanel>
|
||||
|
||||
@@ -135,6 +135,8 @@ public class SurfaceEditorViewModel : RoutableScreen, IMainScreenViewModel
|
||||
try
|
||||
{
|
||||
_saving = true;
|
||||
foreach (SurfaceDeviceViewModel surfaceDeviceViewModel in SurfaceDeviceViewModels)
|
||||
surfaceDeviceViewModel.Apply();
|
||||
_deviceService.SaveDevices();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
Reference in new issue
Block a user