mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Merge branch 'better-databindings' into development
This commit is contained in:
commit
bb1ace0941
47 files changed
+331
-217
No files matched your search
+2
-6
@@ -38,11 +38,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
_profileEditorService = profileEditorService;
|
||||
_dataBindingsVmFactory = dataBindingsVmFactory;
|
||||
|
||||
if (Registration.Member != null)
|
||||
DisplayName = Registration.Member.Name.ToUpper();
|
||||
else
|
||||
DisplayName = Registration.LayerProperty.PropertyDescription.Name.ToUpper();
|
||||
|
||||
DisplayName = Registration.DisplayName.ToUpper();
|
||||
AlwaysApplyDataBindings = settingsService.GetSetting("ProfileEditor.AlwaysApplyDataBindings", true);
|
||||
DataBindingModes = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(typeof(DataBindingModeType)));
|
||||
EasingViewModels = new BindableCollection<TimelineEasingViewModel>();
|
||||
@@ -106,8 +102,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
base.OnInitialActivate();
|
||||
Initialize();
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
|
||||
+8
-1
@@ -6,11 +6,18 @@
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<TabControl ItemsSource="{Binding Items}" SelectedIndex="{Binding SelectedItemIndex}" DisplayMemberPath="DisplayName" Style="{StaticResource MaterialDesignTabControl}">
|
||||
<TabControl ItemsSource="{Binding Items}"
|
||||
SelectedIndex="{Binding SelectedItemIndex}"
|
||||
Style="{StaticResource MaterialDesignTabControl}" >
|
||||
<TabControl.ContentTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" TextElement.Foreground="{DynamicResource MaterialDesignBody}" />
|
||||
</DataTemplate>
|
||||
</TabControl.ContentTemplate>
|
||||
<TabControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Margin="-12 0" Text="{Binding DisplayName}"></TextBlock>
|
||||
</DataTemplate>
|
||||
</TabControl.ItemTemplate>
|
||||
</TabControl>
|
||||
</UserControl>
|
||||
+49
-5
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared.Services;
|
||||
@@ -11,7 +14,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
{
|
||||
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private ILayerProperty? _selectedDataBinding;
|
||||
private int _selectedItemIndex;
|
||||
private bool _updating;
|
||||
|
||||
public DataBindingsViewModel(IProfileEditorService profileEditorService, IDataBindingsVmFactory dataBindingsVmFactory)
|
||||
{
|
||||
@@ -24,9 +29,10 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
get => _selectedItemIndex;
|
||||
set => SetAndNotify(ref _selectedItemIndex, value);
|
||||
}
|
||||
|
||||
|
||||
private void CreateDataBindingViewModels()
|
||||
{
|
||||
int oldIndex = SelectedItemIndex;
|
||||
Items.Clear();
|
||||
|
||||
ILayerProperty layerProperty = _profileEditorService.SelectedDataBinding;
|
||||
@@ -37,26 +43,64 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
|
||||
|
||||
// Create a data binding VM for each data bindable property. These VMs will be responsible for retrieving
|
||||
// and creating the actual data bindings
|
||||
foreach (IDataBindingRegistration registration in registrations)
|
||||
Items.Add(_dataBindingsVmFactory.DataBindingViewModel(registration));
|
||||
Items.AddRange(registrations.Select(registration => _dataBindingsVmFactory.DataBindingViewModel(registration)));
|
||||
|
||||
SelectedItemIndex = 0;
|
||||
SelectedItemIndex = Items.Count < oldIndex ? 0 : oldIndex;
|
||||
}
|
||||
|
||||
private void ProfileEditorServiceOnSelectedDataBindingChanged(object sender, EventArgs e)
|
||||
{
|
||||
CreateDataBindingViewModels();
|
||||
SubscribeToSelectedDataBinding();
|
||||
|
||||
SelectedItemIndex = 0;
|
||||
}
|
||||
|
||||
private void SubscribeToSelectedDataBinding()
|
||||
{
|
||||
if (_selectedDataBinding != null)
|
||||
{
|
||||
_selectedDataBinding.DataBindingPropertyRegistered -= DataBindingRegistrationsChanged;
|
||||
_selectedDataBinding.DataBindingPropertiesCleared -= DataBindingRegistrationsChanged;
|
||||
}
|
||||
|
||||
_selectedDataBinding = _profileEditorService.SelectedDataBinding;
|
||||
if (_selectedDataBinding != null)
|
||||
{
|
||||
_selectedDataBinding.DataBindingPropertyRegistered += DataBindingRegistrationsChanged;
|
||||
_selectedDataBinding.DataBindingPropertiesCleared += DataBindingRegistrationsChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void DataBindingRegistrationsChanged(object sender, LayerPropertyEventArgs e)
|
||||
{
|
||||
if (_updating)
|
||||
return;
|
||||
|
||||
_updating = true;
|
||||
Execute.PostToUIThread(async () =>
|
||||
{
|
||||
await Task.Delay(200);
|
||||
CreateDataBindingViewModels();
|
||||
_updating = false;
|
||||
});
|
||||
}
|
||||
|
||||
#region Overrides of Screen
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
_profileEditorService.SelectedDataBindingChanged += ProfileEditorServiceOnSelectedDataBindingChanged;
|
||||
CreateDataBindingViewModels();
|
||||
SubscribeToSelectedDataBinding();
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
SelectedItemIndex = 0;
|
||||
base.OnActivate();
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
|
||||
@@ -302,7 +302,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
TimeSpan delta = DateTime.Now - _lastUpdate;
|
||||
_lastUpdate = DateTime.Now;
|
||||
|
||||
if (!AlwaysApplyDataBindings.Value || _profileEditorService.SelectedProfile == null || _profileEditorService.Playing)
|
||||
if (!AlwaysApplyDataBindings.Value || _profileEditorService.SelectedProfile == null)
|
||||
return;
|
||||
|
||||
foreach (IDataBindingRegistration dataBindingRegistration in _profileEditorService.SelectedProfile.GetAllFolders()
|
||||
|
||||
Reference in new issue
Block a user