mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Change profile editor VMs to use event aggregator
This commit is contained in:
parent
b590c5fed9
commit
8a596f1426
@ -152,7 +152,9 @@
|
|||||||
<Compile Include="Converters\InverseBooleanConverter.cs" />
|
<Compile Include="Converters\InverseBooleanConverter.cs" />
|
||||||
<Compile Include="Converters\NullToImageConverter.cs" />
|
<Compile Include="Converters\NullToImageConverter.cs" />
|
||||||
<Compile Include="Converters\NullToVisibilityConverter.cs" />
|
<Compile Include="Converters\NullToVisibilityConverter.cs" />
|
||||||
<Compile Include="Events\MainWindowFocusChangedEvent.cs" />
|
<Compile Include="Events\MainWindowFocusChanged.cs" />
|
||||||
|
<Compile Include="Events\ProfileEditorSelectedElementChanged.cs" />
|
||||||
|
<Compile Include="Events\ProfileEditorSelectedProfileChanged.cs" />
|
||||||
<Compile Include="Utilities\BindableSelectedItemBehavior.cs" />
|
<Compile Include="Utilities\BindableSelectedItemBehavior.cs" />
|
||||||
<Compile Include="Utilities\TriggerTracing.cs" />
|
<Compile Include="Utilities\TriggerTracing.cs" />
|
||||||
<Compile Include="Exceptions\ArtemisCoreException.cs" />
|
<Compile Include="Exceptions\ArtemisCoreException.cs" />
|
||||||
|
|||||||
12
src/Artemis.UI/Events/MainWindowFocusChanged.cs
Normal file
12
src/Artemis.UI/Events/MainWindowFocusChanged.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
namespace Artemis.UI.Events
|
||||||
|
{
|
||||||
|
public class MainWindowFocusChanged
|
||||||
|
{
|
||||||
|
public MainWindowFocusChanged(bool isFocused)
|
||||||
|
{
|
||||||
|
IsFocused = isFocused;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsFocused { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,14 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Artemis.UI.Events
|
|
||||||
{
|
|
||||||
public class MainWindowFocusChangedEvent : EventArgs
|
|
||||||
{
|
|
||||||
public MainWindowFocusChangedEvent(bool isFocused)
|
|
||||||
{
|
|
||||||
IsFocused = isFocused;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsFocused { get; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
15
src/Artemis.UI/Events/ProfileEditorSelectedElementChanged.cs
Normal file
15
src/Artemis.UI/Events/ProfileEditorSelectedElementChanged.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using Artemis.Core.Models.Profile;
|
||||||
|
using Artemis.Core.Models.Profile.Abstract;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Events
|
||||||
|
{
|
||||||
|
public class ProfileEditorSelectedElementChanged
|
||||||
|
{
|
||||||
|
public ProfileEditorSelectedElementChanged(ProfileElement profileElement)
|
||||||
|
{
|
||||||
|
ProfileElement = profileElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProfileElement ProfileElement { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/Artemis.UI/Events/ProfileEditorSelectedProfileChanged.cs
Normal file
14
src/Artemis.UI/Events/ProfileEditorSelectedProfileChanged.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using Artemis.Core.Models.Profile;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Events
|
||||||
|
{
|
||||||
|
public class ProfileEditorSelectedProfileChanged
|
||||||
|
{
|
||||||
|
public ProfileEditorSelectedProfileChanged(Profile profile)
|
||||||
|
{
|
||||||
|
Profile = profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Profile Profile { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,22 +1,8 @@
|
|||||||
using Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.ProfileElement;
|
using Stylet;
|
||||||
using Stylet;
|
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Module.ProfileEditor
|
namespace Artemis.UI.Screens.Module.ProfileEditor
|
||||||
{
|
{
|
||||||
public class ProfileEditorPanelViewModel : Screen
|
public class ProfileEditorPanelViewModel : Screen
|
||||||
{
|
{
|
||||||
public ProfileEditorViewModel ProfileEditorViewModel { get; set; }
|
|
||||||
|
|
||||||
public virtual void ActiveProfileChanged()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void ActiveProfileUpdated()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void ProfileElementSelected(ProfileElementViewModel profileElement)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8,12 +8,12 @@ using Artemis.Core.Plugins.Abstract;
|
|||||||
using Artemis.Core.Plugins.Models;
|
using Artemis.Core.Plugins.Models;
|
||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.Core.Services.Storage.Interfaces;
|
using Artemis.Core.Services.Storage.Interfaces;
|
||||||
|
using Artemis.UI.Events;
|
||||||
using Artemis.UI.Screens.Module.ProfileEditor.Dialogs;
|
using Artemis.UI.Screens.Module.ProfileEditor.Dialogs;
|
||||||
using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions;
|
using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions;
|
||||||
using Artemis.UI.Screens.Module.ProfileEditor.ElementProperties;
|
using Artemis.UI.Screens.Module.ProfileEditor.ElementProperties;
|
||||||
using Artemis.UI.Screens.Module.ProfileEditor.LayerElements;
|
using Artemis.UI.Screens.Module.ProfileEditor.LayerElements;
|
||||||
using Artemis.UI.Screens.Module.ProfileEditor.ProfileElements;
|
using Artemis.UI.Screens.Module.ProfileEditor.ProfileElements;
|
||||||
using Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.ProfileElement;
|
|
||||||
using Artemis.UI.Screens.Module.ProfileEditor.Visualization;
|
using Artemis.UI.Screens.Module.ProfileEditor.Visualization;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services.Interfaces;
|
||||||
using Stylet;
|
using Stylet;
|
||||||
@ -22,14 +22,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
|||||||
{
|
{
|
||||||
public class ProfileEditorViewModel : Conductor<ProfileEditorPanelViewModel>.Collection.AllActive
|
public class ProfileEditorViewModel : Conductor<ProfileEditorPanelViewModel>.Collection.AllActive
|
||||||
{
|
{
|
||||||
|
private readonly IEventAggregator _eventAggregator;
|
||||||
private readonly IProfileService _profileService;
|
private readonly IProfileService _profileService;
|
||||||
private readonly ISettingsService _settingsService;
|
private readonly ISettingsService _settingsService;
|
||||||
|
|
||||||
public ProfileEditorViewModel(ProfileModule module, ICollection<ProfileEditorPanelViewModel> viewModels, IProfileService profileService,
|
public ProfileEditorViewModel(ProfileModule module, ICollection<ProfileEditorPanelViewModel> viewModels, IProfileService profileService,
|
||||||
IDialogService dialogService, ISettingsService settingsService)
|
IDialogService dialogService, ISettingsService settingsService, IEventAggregator eventAggregator)
|
||||||
{
|
{
|
||||||
_profileService = profileService;
|
_profileService = profileService;
|
||||||
_settingsService = settingsService;
|
_settingsService = settingsService;
|
||||||
|
_eventAggregator = eventAggregator;
|
||||||
|
|
||||||
DisplayName = "Profile editor";
|
DisplayName = "Profile editor";
|
||||||
Module = module;
|
Module = module;
|
||||||
@ -76,12 +78,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
|||||||
|
|
||||||
var oldProfile = Module.ActiveProfile;
|
var oldProfile = Module.ActiveProfile;
|
||||||
Module.ChangeActiveProfile(profile);
|
Module.ChangeActiveProfile(profile);
|
||||||
|
_eventAggregator.Publish(new ProfileEditorSelectedProfileChanged(SelectedProfile));
|
||||||
foreach (var panelViewModel in Items)
|
|
||||||
{
|
|
||||||
panelViewModel.ProfileEditorViewModel = this;
|
|
||||||
panelViewModel.ActiveProfileChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldProfile != null)
|
if (oldProfile != null)
|
||||||
_profileService.UpdateProfile(oldProfile, false);
|
_profileService.UpdateProfile(oldProfile, false);
|
||||||
@ -141,11 +138,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
|||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
LoadProfiles();
|
LoadProfiles();
|
||||||
foreach (var panelViewModel in Items)
|
_eventAggregator.Publish(new ProfileEditorSelectedProfileChanged(SelectedProfile));
|
||||||
{
|
|
||||||
panelViewModel.ProfileEditorViewModel = this;
|
|
||||||
panelViewModel.ActiveProfileChanged();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
base.OnActivate();
|
base.OnActivate();
|
||||||
}
|
}
|
||||||
@ -195,19 +188,5 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
|||||||
if (!activeProfile.IsActivated)
|
if (!activeProfile.IsActivated)
|
||||||
Module.ChangeActiveProfile(activeProfile);
|
Module.ChangeActiveProfile(activeProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnProfileUpdated(ProfileEditorPanelViewModel source = null)
|
|
||||||
{
|
|
||||||
_profileService.UpdateProfile(SelectedProfile, true);
|
|
||||||
|
|
||||||
foreach (var panelViewModel in Items.Where(p => p != source))
|
|
||||||
panelViewModel.ActiveProfileUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnProfileElementSelected(ProfileElementViewModel profileElement, ProfileEditorPanelViewModel source = null)
|
|
||||||
{
|
|
||||||
foreach (var panelViewModel in Items.Where(p => p != source))
|
|
||||||
panelViewModel.ProfileElementSelected(profileElement);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,17 +1,25 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Artemis.Core.Models.Profile;
|
using Artemis.Core.Models.Profile;
|
||||||
|
using Artemis.Core.Services.Storage.Interfaces;
|
||||||
|
using Artemis.UI.Events;
|
||||||
using Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.ProfileElement;
|
using Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.ProfileElement;
|
||||||
using GongSolutions.Wpf.DragDrop;
|
using GongSolutions.Wpf.DragDrop;
|
||||||
|
using Stylet;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
||||||
{
|
{
|
||||||
public class ProfileElementsViewModel : ProfileEditorPanelViewModel, IDropTarget
|
public class ProfileElementsViewModel : ProfileEditorPanelViewModel, IDropTarget
|
||||||
{
|
{
|
||||||
|
private readonly IProfileService _profileService;
|
||||||
|
private readonly IEventAggregator _eventAggregator;
|
||||||
private ProfileElementViewModel _selectedProfileElement;
|
private ProfileElementViewModel _selectedProfileElement;
|
||||||
|
|
||||||
public ProfileElementsViewModel()
|
public ProfileElementsViewModel(IProfileService profileService, IEventAggregator eventAggregator)
|
||||||
{
|
{
|
||||||
|
_profileService = profileService;
|
||||||
|
_eventAggregator = eventAggregator;
|
||||||
|
|
||||||
CreateRootFolderViewModel();
|
CreateRootFolderViewModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +31,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
_selectedProfileElement = value;
|
_selectedProfileElement = value;
|
||||||
ProfileEditorViewModel.OnProfileElementSelected(_selectedProfileElement, this);
|
_eventAggregator.Publish(new ProfileEditorSelectedElementChanged(_selectedProfileElement.ProfileElement));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +73,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_profileService.UpdateProfile(this.RootFolder.P);
|
||||||
ProfileEditorViewModel.OnProfileUpdated(this);
|
ProfileEditorViewModel.OnProfileUpdated(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -158,10 +158,10 @@
|
|||||||
<StackPanel ZIndex="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="10">
|
<StackPanel ZIndex="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="10">
|
||||||
<materialDesign:Card Padding="8">
|
<materialDesign:Card Padding="8">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<CheckBox Style="{StaticResource MaterialDesignCheckBox}">
|
<CheckBox Style="{StaticResource MaterialDesignCheckBox}" IsChecked="{Binding HighlightSelectedLayer.Value}">
|
||||||
Highlight selected layer
|
Highlight selected layer
|
||||||
</CheckBox>
|
</CheckBox>
|
||||||
<CheckBox Style="{StaticResource MaterialDesignCheckBox}" Margin="10 0 0 0">
|
<CheckBox Style="{StaticResource MaterialDesignCheckBox}" Margin="10 0 0 0" IsChecked="{Binding PauseRenderingOnFocusLoss.Value}">
|
||||||
Pause visualization on focus loss
|
Pause visualization on focus loss
|
||||||
</CheckBox>
|
</CheckBox>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@ -20,32 +20,29 @@ using Point = System.Windows.Point;
|
|||||||
|
|
||||||
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||||
{
|
{
|
||||||
public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle<MainWindowFocusChangedEvent>
|
public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle<ProfileEditorSelectedElementChanged>, IHandle<MainWindowFocusChanged>
|
||||||
{
|
{
|
||||||
private readonly ISettingsService _settingsService;
|
private readonly ISettingsService _settingsService;
|
||||||
private readonly TimerUpdateTrigger _updateTrigger;
|
private readonly ISurfaceService _surfaceService;
|
||||||
|
private TimerUpdateTrigger _updateTrigger;
|
||||||
|
|
||||||
public ProfileViewModel(ISurfaceService surfaceService, ISettingsService settingsService, IEventAggregator eventAggregator)
|
public ProfileViewModel(ISurfaceService surfaceService, ISettingsService settingsService, IEventAggregator eventAggregator)
|
||||||
{
|
{
|
||||||
|
_surfaceService = surfaceService;
|
||||||
_settingsService = settingsService;
|
_settingsService = settingsService;
|
||||||
Devices = new ObservableCollection<ProfileDeviceViewModel>();
|
Devices = new ObservableCollection<ProfileDeviceViewModel>();
|
||||||
|
Cursor = null;
|
||||||
|
|
||||||
Execute.PostToUIThread(() =>
|
Execute.PostToUIThread(() =>
|
||||||
{
|
{
|
||||||
SelectionRectangle = new RectangleGeometry();
|
SelectionRectangle = new RectangleGeometry();
|
||||||
PanZoomViewModel = new PanZoomViewModel();
|
PanZoomViewModel = new PanZoomViewModel();
|
||||||
});
|
});
|
||||||
Cursor = null;
|
|
||||||
|
|
||||||
ApplySurfaceConfiguration(surfaceService.ActiveSurface);
|
ApplySurfaceConfiguration(surfaceService.ActiveSurface);
|
||||||
|
CreateUpdateTrigger();
|
||||||
|
|
||||||
// Borrow RGB.NET's update trigger but limit the FPS
|
eventAggregator.Subscribe(this);
|
||||||
var targetFpsSetting = settingsService.GetSetting("Core.TargetFrameRate", 25);
|
|
||||||
var editorTargetFpsSetting = settingsService.GetSetting("ProfileEditor.TargetFrameRate", 15);
|
|
||||||
var targetFps = Math.Min(targetFpsSetting.Value, editorTargetFpsSetting.Value);
|
|
||||||
_updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / targetFps};
|
|
||||||
_updateTrigger.Update += UpdateLeds;
|
|
||||||
|
|
||||||
surfaceService.ActiveSurfaceConfigurationChanged += OnActiveSurfaceConfigurationChanged;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsInitializing { get; private set; }
|
public bool IsInitializing { get; private set; }
|
||||||
@ -57,6 +54,18 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
|||||||
|
|
||||||
public Cursor Cursor { get; set; }
|
public Cursor Cursor { get; set; }
|
||||||
|
|
||||||
|
private void CreateUpdateTrigger()
|
||||||
|
{
|
||||||
|
// Borrow RGB.NET's update trigger but limit the FPS
|
||||||
|
var targetFpsSetting = _settingsService.GetSetting("Core.TargetFrameRate", 25);
|
||||||
|
var editorTargetFpsSetting = _settingsService.GetSetting("ProfileEditor.TargetFrameRate", 15);
|
||||||
|
var targetFps = Math.Min(targetFpsSetting.Value, editorTargetFpsSetting.Value);
|
||||||
|
_updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / targetFps};
|
||||||
|
_updateTrigger.Update += UpdateLeds;
|
||||||
|
|
||||||
|
_surfaceService.ActiveSurfaceConfigurationChanged += OnActiveSurfaceConfigurationChanged;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnActiveSurfaceConfigurationChanged(object sender, SurfaceConfigurationEventArgs e)
|
private void OnActiveSurfaceConfigurationChanged(object sender, SurfaceConfigurationEventArgs e)
|
||||||
{
|
{
|
||||||
ApplySurfaceConfiguration(e.Surface);
|
ApplySurfaceConfiguration(e.Surface);
|
||||||
@ -119,7 +128,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
|||||||
_updateTrigger.Start();
|
_updateTrigger.Start();
|
||||||
base.OnActivate();
|
base.OnActivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDeactivate()
|
protected override void OnDeactivate()
|
||||||
{
|
{
|
||||||
HighlightSelectedLayer.Save();
|
HighlightSelectedLayer.Save();
|
||||||
@ -250,9 +259,23 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public void Handle(MainWindowFocusChangedEvent message)
|
#region EventAggregator handlers
|
||||||
|
|
||||||
|
public void Handle(ProfileEditorSelectedElementChanged message)
|
||||||
{
|
{
|
||||||
Console.WriteLine(message);
|
if (HighlightSelectedLayer.Value)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Handle(MainWindowFocusChanged message)
|
||||||
|
{
|
||||||
|
if (PauseRenderingOnFocusLoss.Value && !message.IsFocused)
|
||||||
|
_updateTrigger.Stop();
|
||||||
|
else if (PauseRenderingOnFocusLoss.Value && message.IsFocused)
|
||||||
|
_updateTrigger.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ namespace Artemis.UI.Screens
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_lostFocus = true;
|
_lostFocus = true;
|
||||||
_eventAggregator.Publish(new MainWindowFocusChangedEvent(false));
|
_eventAggregator.Publish(new MainWindowFocusChanged(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WindowActivated()
|
public void WindowActivated()
|
||||||
@ -152,7 +152,7 @@ namespace Artemis.UI.Screens
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_lostFocus = false;
|
_lostFocus = false;
|
||||||
_eventAggregator.Publish(new MainWindowFocusChangedEvent(true));
|
_eventAggregator.Publish(new MainWindowFocusChanged(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user