mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Implemented layer LED assignment
Added a centralised ProfileEditorSurface for communication between VMs Prefixed Surface, Device and Led with Artemis to differentiate them better
This commit is contained in:
1 parent
c7a5532c34
commit
16decaae42
50 files changed
+556
-662
No files matched your search
@@ -5,6 +5,7 @@ using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services;
|
||||
@@ -13,21 +14,26 @@ using Artemis.UI.Events;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Screens.Shared;
|
||||
using Artemis.UI.Screens.SurfaceEditor;
|
||||
using Artemis.UI.Screens.SurfaceEditor.Visualization;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
using Point = System.Windows.Point;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
{
|
||||
public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle<ProfileEditorSelectedElementChanged>, IHandle<MainWindowFocusChanged>
|
||||
public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle<MainWindowFocusChangedEvent>
|
||||
{
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
private TimerUpdateTrigger _updateTrigger;
|
||||
|
||||
public ProfileViewModel(ISurfaceService surfaceService, ISettingsService settingsService, IEventAggregator eventAggregator)
|
||||
public ProfileViewModel(IProfileEditorService profileEditorService,
|
||||
ISurfaceService surfaceService,
|
||||
ISettingsService settingsService,
|
||||
IEventAggregator eventAggregator)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_surfaceService = surfaceService;
|
||||
_settingsService = settingsService;
|
||||
Devices = new ObservableCollection<ProfileDeviceViewModel>();
|
||||
@@ -42,6 +48,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
ApplySurfaceConfiguration(surfaceService.ActiveSurface);
|
||||
CreateUpdateTrigger();
|
||||
|
||||
_profileEditorService.SelectedProfileElementChanged += OnSelectedProfileElementChanged;
|
||||
_profileEditorService.SelectedProfileElementUpdated += OnSelectedProfileElementChanged;
|
||||
eventAggregator.Subscribe(this);
|
||||
}
|
||||
|
||||
@@ -71,7 +79,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
ApplySurfaceConfiguration(e.Surface);
|
||||
}
|
||||
|
||||
private void ApplySurfaceConfiguration(Surface surface)
|
||||
private void ApplySurfaceConfiguration(ArtemisSurface surface)
|
||||
{
|
||||
// Make sure all devices have an up-to-date VM
|
||||
foreach (var surfaceDeviceConfiguration in surface.Devices)
|
||||
@@ -120,11 +128,27 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLedsDimStatus()
|
||||
{
|
||||
if (HighlightSelectedLayer.Value && _profileEditorService.SelectedProfileElement is Layer layer)
|
||||
{
|
||||
foreach (var led in Devices.SelectMany(d => d.Leds))
|
||||
led.IsDimmed = !layer.Leds.Contains(led.Led);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var led in Devices.SelectMany(d => d.Leds))
|
||||
led.IsDimmed = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
HighlightSelectedLayer = _settingsService.GetSetting("ProfileEditor.HighlightSelectedLayer", true);
|
||||
PauseRenderingOnFocusLoss = _settingsService.GetSetting("ProfileEditor.PauseRenderingOnFocusLoss", true);
|
||||
|
||||
HighlightSelectedLayer.SettingChanged += HighlightSelectedLayerOnSettingChanged;
|
||||
|
||||
_updateTrigger.Start();
|
||||
base.OnActivate();
|
||||
}
|
||||
@@ -138,6 +162,45 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
base.OnDeactivate();
|
||||
}
|
||||
|
||||
#region Context menu actions
|
||||
|
||||
public bool CanApplyToLayer { get; set; }
|
||||
|
||||
public void CreateLayer()
|
||||
{
|
||||
}
|
||||
|
||||
public void ApplyToLayer()
|
||||
{
|
||||
if (!(_profileEditorService.SelectedProfileElement is Layer layer))
|
||||
return;
|
||||
|
||||
layer.ClearLeds();
|
||||
layer.AddLeds(Devices.SelectMany(d => d.Leds).Where(vm => vm.IsSelected).Select(vm => vm.Led));
|
||||
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void SelectAll()
|
||||
{
|
||||
foreach (var ledVm in Devices.SelectMany(d => d.Leds))
|
||||
ledVm.IsSelected = true;
|
||||
}
|
||||
|
||||
public void InverseSelection()
|
||||
{
|
||||
foreach (var ledVm in Devices.SelectMany(d => d.Leds))
|
||||
ledVm.IsSelected = !ledVm.IsSelected;
|
||||
}
|
||||
|
||||
public void ClearSelection()
|
||||
{
|
||||
foreach (var ledVm in Devices.SelectMany(d => d.Leds))
|
||||
ledVm.IsSelected = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Selection
|
||||
|
||||
private MouseDragStatus _mouseDragStatus;
|
||||
@@ -188,10 +251,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
{
|
||||
foreach (var profileLedViewModel in device.Leds)
|
||||
{
|
||||
if (PanZoomViewModel.TransformContainingRect(profileLedViewModel.Led.AbsoluteLedRectangle.ToWindowsRect(1)).IntersectsWith(selectedRect))
|
||||
profileLedViewModel.SelectionStatus = SelectionStatus.Selected;
|
||||
if (PanZoomViewModel.TransformContainingRect(profileLedViewModel.Led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1)).IntersectsWith(selectedRect))
|
||||
profileLedViewModel.IsSelected = true;
|
||||
else if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
|
||||
profileLedViewModel.SelectionStatus = SelectionStatus.None;
|
||||
profileLedViewModel.IsSelected = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,10 +273,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
{
|
||||
foreach (var profileLedViewModel in device.Leds)
|
||||
{
|
||||
if (PanZoomViewModel.TransformContainingRect(profileLedViewModel.Led.AbsoluteLedRectangle.ToWindowsRect(1)).IntersectsWith(selectedRect))
|
||||
profileLedViewModel.SelectionStatus = SelectionStatus.Selected;
|
||||
if (PanZoomViewModel.TransformContainingRect(profileLedViewModel.Led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1)).IntersectsWith(selectedRect))
|
||||
profileLedViewModel.IsSelected = true;
|
||||
else if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
|
||||
profileLedViewModel.SelectionStatus = SelectionStatus.None;
|
||||
profileLedViewModel.IsSelected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,17 +322,24 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
|
||||
#endregion
|
||||
|
||||
#region EventAggregator handlers
|
||||
#region Event handlers
|
||||
|
||||
public void Handle(ProfileEditorSelectedElementChanged message)
|
||||
private void HighlightSelectedLayerOnSettingChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (HighlightSelectedLayer.Value)
|
||||
{
|
||||
}
|
||||
UpdateLedsDimStatus();
|
||||
}
|
||||
|
||||
public void Handle(MainWindowFocusChanged message)
|
||||
private void OnSelectedProfileElementChanged(object sender, EventArgs e)
|
||||
{
|
||||
UpdateLedsDimStatus();
|
||||
CanApplyToLayer = _profileEditorService.SelectedProfileElement is Layer;
|
||||
}
|
||||
|
||||
public void Handle(MainWindowFocusChangedEvent message)
|
||||
{
|
||||
if (PauseRenderingOnFocusLoss == null || ScreenState != ScreenState.Active)
|
||||
return;
|
||||
|
||||
if (PauseRenderingOnFocusLoss.Value && !message.IsFocused)
|
||||
_updateTrigger.Stop();
|
||||
else if (PauseRenderingOnFocusLoss.Value && message.IsFocused)
|
||||
|
||||
Reference in new issue
Block a user