1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Plugins - Added timed updates

Modules - Added option to disable updates while activation is overridden
Display conditions - Added SKColor support
Data bindings - Added SKColor support
This commit is contained in:
Robert 2020-09-16 20:17:54 +02:00
parent d9017c67b4
commit 2eb4d615ae
48 changed files with 269 additions and 100 deletions

View File

@ -93,7 +93,13 @@ namespace Artemis.Core.Modules
/// Gets whether this module's activation was due to an override, can only be true if <see cref="IsActivated" /> is
/// true
/// </summary>
public bool IsActivatedOverride { get; set; }
public bool IsActivatedOverride { get; private set; }
/// <summary>
/// Gets whether this module should update if <see cref="IsActivatedOverride" /> is true
/// <para>Defaults to <c>true</c></para>
/// </summary>
public bool UpdateDuringActivationOverride { get; protected set; } = true;
/// <summary>
/// A list of activation requirements
@ -180,10 +186,11 @@ namespace Artemis.Core.Modules
return false;
}
internal virtual void InternalUpdate(double deltaTime)
{
Update(deltaTime);
if (!IsActivatedOverride || UpdateDuringActivationOverride)
Update(deltaTime);
}
internal virtual void InternalRender(double deltaTime, ArtemisSurface surface, SKCanvas canvas, SKImageInfo canvasInfo)

View File

@ -141,7 +141,8 @@ namespace Artemis.Core.Modules
internal override void InternalUpdate(double deltaTime)
{
Update(deltaTime);
if (!IsActivatedOverride || UpdateDuringActivationOverride)
Update(deltaTime);
lock (this)
{

View File

@ -1,5 +1,6 @@
using System;
using System.Timers;
using Artemis.Core.Modules;
namespace Artemis.Core
{
@ -53,6 +54,13 @@ namespace Artemis.Core
if (_timer != null)
return;
// Don't update during override if that is disabled on the module
if (PluginInfo.Instance is Module module)
{
if (module.IsActivatedOverride && !module.UpdateDuringActivationOverride)
return;
}
_lastEvent = DateTime.Now;
_timer = new Timer(Interval.TotalMilliseconds);
_timer.Elapsed += TimerOnElapsed;

View File

@ -92,7 +92,7 @@
Placement="Bottom"
CustomPopupPlacementCallback="{x:Static materialDesign:CustomPopupPlacementCallbackHelper.LargePopupCallback}"
PlacementTarget="{Binding ElementName=ColorCodeTextBox}"
StaysOpen="False"
StaysOpen="{Binding StaysOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
PopupAnimation="Fade"
IsOpen="{Binding PopupOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}">
<materialDesign:Card Width="200" Height="200" Margin="30" materialDesign:ShadowAssist.ShadowDepth="Depth4">
@ -101,7 +101,7 @@
<RowDefinition Height="160" />
<RowDefinition />
</Grid.RowDefinitions>
<materialDesign:ColorPicker Grid.Row="0" Color="{Binding Color, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
<materialDesign:ColorPicker Grid.Row="0" Color="{Binding Color, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" MouseUp="ColorGradient_OnMouseUp" />
<Slider Grid.Row="1" Margin="8"
IsMoveToPointEnabled="True"
Orientation="Horizontal"

View File

@ -18,6 +18,9 @@ namespace Artemis.UI.Shared
public static readonly DependencyProperty PopupOpenProperty = DependencyProperty.Register(nameof(PopupOpen), typeof(bool), typeof(ColorPicker),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, PopupOpenPropertyChangedCallback));
public static readonly DependencyProperty StaysOpenProperty = DependencyProperty.Register(nameof(StaysOpen), typeof(bool), typeof(ColorPicker),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, StaysOpenPropertyChangedCallback));
internal static readonly DependencyProperty ColorOpacityProperty = DependencyProperty.Register(nameof(ColorOpacity), typeof(byte), typeof(ColorPicker),
new FrameworkPropertyMetadata((byte) 255, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ColorOpacityPropertyChangedCallback));
@ -54,6 +57,12 @@ namespace Artemis.UI.Shared
set => SetValue(PopupOpenProperty, value);
}
public bool StaysOpen
{
get => (bool) GetValue(StaysOpenProperty);
set => SetValue(StaysOpenProperty, value);
}
internal byte ColorOpacity
{
get => (byte) GetValue(ColorOpacityProperty);
@ -92,6 +101,17 @@ namespace Artemis.UI.Shared
colorPicker._inCallback = false;
}
private static void StaysOpenPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var colorPicker = (ColorPicker) d;
if (colorPicker._inCallback)
return;
colorPicker._inCallback = true;
colorPicker.OnPropertyChanged(nameof(PopupOpen));
colorPicker._inCallback = false;
}
private static void ColorOpacityPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var colorPicker = (ColorPicker) d;
@ -112,6 +132,12 @@ namespace Artemis.UI.Shared
private void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e)
{
PopupOpen = !PopupOpen;
e.Handled = true;
}
private void ColorGradient_OnMouseUp(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
}
}
}

View File

@ -15,7 +15,7 @@ namespace Artemis.UI.Shared
/// <inheritdoc />
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value?.ToString();
return value?.ToString()?.ToUpper();
}
/// <inheritdoc />

View File

@ -20,10 +20,12 @@ namespace Artemis.UI.Shared
{
}
internal override void UpdateValue(object model)
public override void UpdateValue(object model)
{
DisplayValue = model is T value ? value : default;
}
internal override object InternalGuard => null;
}
/// <summary>
@ -31,9 +33,11 @@ namespace Artemis.UI.Shared
/// </summary>
public abstract class DataModelDisplayViewModel : PropertyChangedBase
{
public abstract void UpdateValue(object model);
/// <summary>
/// Prevents this type being implemented directly, implement <see cref="DataModelDisplayViewModel{T}" /> instead.
/// </summary>
internal abstract void UpdateValue(object model);
internal abstract object InternalGuard { get; }
}
}

View File

@ -33,7 +33,7 @@
<TextBlock FontWeight="Light"
Text="{Binding TargetPropertyViewModel.PropertyDescription.Prefix}"
Visibility="{Binding TargetPropertyViewModel.PropertyDescription.Prefix, Converter={StaticResource NullToVisibilityConverter}}" />
<TextBlock Text="{Binding Value}" />
<ContentControl s:View.Model="{Binding DisplayViewModel}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
<TextBlock FontWeight="Light"
Text="{Binding TargetPropertyViewModel.PropertyDescription.Affix}"
Visibility="{Binding TargetPropertyViewModel.PropertyDescription.Affix, Converter={StaticResource NullToVisibilityConverter}}" />

View File

@ -1,19 +1,21 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared.Services;
using Stylet;
// Remove, annoying while working on it
#pragma warning disable 1591
namespace Artemis.UI.Shared.Input
{
public class DataModelStaticViewModel : PropertyChangedBase
public class DataModelStaticViewModel : PropertyChangedBase, IDisposable
{
private readonly IDataModelUIService _dataModelUIService;
private readonly Window _rootView;
private Brush _buttonBrush = new SolidColorBrush(Color.FromRgb(171, 71, 188));
private DataModelDisplayViewModel _displayViewModel;
private DataModelInputViewModel _inputViewModel;
private string _placeholder = "Enter a value";
private DataModelPropertyAttribute _targetDescription;
@ -25,6 +27,15 @@ namespace Artemis.UI.Shared.Input
{
TargetType = targetType;
_dataModelUIService = dataModelUIService;
DisplayViewModel = _dataModelUIService.GetDataModelDisplayViewModel(TargetType, true);
_rootView = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
if (_rootView != null)
{
_rootView.MouseUp += RootViewOnMouseUp;
_rootView.KeyUp += RootViewOnKeyUp;
}
}
public Brush ButtonBrush
@ -39,6 +50,12 @@ namespace Artemis.UI.Shared.Input
set => SetAndNotify(ref _transitionIndex, value);
}
public DataModelDisplayViewModel DisplayViewModel
{
get => _displayViewModel;
set => SetAndNotify(ref _displayViewModel, value);
}
public DataModelInputViewModel InputViewModel
{
get => _inputViewModel;
@ -60,7 +77,11 @@ namespace Artemis.UI.Shared.Input
public object Value
{
get => _value;
set => SetAndNotify(ref _value, value);
set
{
if (!SetAndNotify(ref _value, value)) return;
DisplayViewModel?.UpdateValue(_value);
}
}
public string Placeholder
@ -69,6 +90,19 @@ namespace Artemis.UI.Shared.Input
set => SetAndNotify(ref _placeholder, value);
}
#region IDisposable
public void Dispose()
{
if (_rootView != null)
{
_rootView.MouseUp -= RootViewOnMouseUp;
_rootView.KeyUp -= RootViewOnKeyUp;
}
}
#endregion
public void ActivateInputViewModel()
{
TransitionIndex = 1;
@ -102,6 +136,30 @@ namespace Artemis.UI.Shared.Input
Value = value;
}
#region Event handlers
private void RootViewOnKeyUp(object sender, KeyEventArgs e)
{
if (InputViewModel == null)
return;
if (e.Key == Key.Escape)
InputViewModel.Cancel();
else if (e.Key == Key.Enter)
InputViewModel.Submit();
}
private void RootViewOnMouseUp(object sender, MouseButtonEventArgs e)
{
if (InputViewModel == null)
return;
if (sender is FrameworkElement frameworkElement && !frameworkElement.IsDescendantOf(InputViewModel.View))
InputViewModel.Submit();
}
#endregion
#region Events
public event EventHandler<DataModelInputStaticEventArgs> ValueUpdated;

View File

@ -38,8 +38,8 @@ namespace Artemis.UI.Shared
if (DisplayValue == null)
return;
if (DisplayViewModel == null && dataModelUIService.RegisteredDataModelDisplays.Any(d => d.SupportedType == DisplayValue.GetType()))
dataModelUIService.GetDataModelDisplayViewModel(DisplayValue.GetType());
if (DisplayViewModel == null)
DisplayViewModel = dataModelUIService.GetDataModelDisplayViewModel(DisplayValue.GetType(), true);
ListType = DisplayValue.GetType();
UpdateDisplayParameters();

View File

@ -9,9 +9,6 @@ namespace Artemis.UI.Shared
{
private object _displayValue;
private DataModelDisplayViewModel _displayViewModel;
private bool _showNull;
private bool _showToString;
private bool _showViewModel;
internal DataModelPropertyViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, PropertyInfo propertyInfo) : base(dataModel, parent, propertyInfo)
{
@ -29,31 +26,13 @@ namespace Artemis.UI.Shared
set => SetAndNotify(ref _displayViewModel, value);
}
public bool ShowToString
{
get => _showToString;
set => SetAndNotify(ref _showToString, value);
}
public bool ShowNull
{
get => _showNull;
set => SetAndNotify(ref _showNull, value);
}
public bool ShowViewModel
{
get => _showViewModel;
set => SetAndNotify(ref _showViewModel, value);
}
public override void Update(IDataModelUIService dataModelUIService)
{
if (Parent != null && !Parent.IsVisualizationExpanded && !Parent.IsRootViewModel)
return;
if (DisplayViewModel == null && dataModelUIService.RegisteredDataModelDisplays.Any(d => d.SupportedType == PropertyInfo.PropertyType))
dataModelUIService.GetDataModelDisplayViewModel(PropertyInfo.PropertyType);
if (DisplayViewModel == null)
DisplayViewModel = dataModelUIService.GetDataModelDisplayViewModel(PropertyInfo.PropertyType, true);
DisplayValue = GetCurrentValue();
UpdateDisplayParameters();
@ -61,10 +40,6 @@ namespace Artemis.UI.Shared
protected void UpdateDisplayParameters()
{
ShowToString = DisplayValue != null && DisplayViewModel == null;
ShowNull = DisplayValue == null;
ShowViewModel = DisplayValue != null && DisplayViewModel != null;
DisplayViewModel?.UpdateValue(DisplayValue);
}
}

View File

@ -0,0 +1,23 @@
<UserControl x:Class="Artemis.UI.Shared.DefaultTypes.DataModel.Display.DefaultDataModelDisplayView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Shared.DefaultTypes.DataModel.Display"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:DefaultDataModelDisplayViewModel}">
<Grid>
<!-- Value display -->
<TextBlock Text="{Binding DisplayValue, Mode=OneWay}"
FontFamily="Consolas"
HorizontalAlignment="Right"
Visibility="{Binding ShowToString, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
<TextBlock Text="null"
FontFamily="Consolas"
HorizontalAlignment="Right"
Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}"
Visibility="{Binding ShowNull, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
</Grid>
</UserControl>

View File

@ -0,0 +1,26 @@
namespace Artemis.UI.Shared.DefaultTypes.DataModel.Display
{
public class DefaultDataModelDisplayViewModel : DataModelDisplayViewModel<object>
{
private bool _showNull;
private bool _showToString;
public bool ShowToString
{
get => _showToString;
set => SetAndNotify(ref _showToString, value);
}
public bool ShowNull
{
get => _showNull;
set => SetAndNotify(ref _showNull, value);
}
protected override void OnDisplayValueUpdated()
{
ShowToString = DisplayValue != null;
ShowNull = DisplayValue == null;
}
}
}

View File

@ -5,6 +5,7 @@ using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.Core.Modules;
using Artemis.Core.Services;
using Artemis.UI.Shared.DefaultTypes.DataModel.Display;
using Artemis.UI.Shared.Input;
using Ninject;
using Ninject.Parameters;
@ -158,14 +159,14 @@ namespace Artemis.UI.Shared.Services
}
}
public DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType)
public DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType, bool fallBackToDefault)
{
lock (_registeredDataModelDisplays)
{
var match = _registeredDataModelDisplays.FirstOrDefault(d => d.SupportedType == propertyType);
if (match != null)
return (DataModelDisplayViewModel) _kernel.Get(match.ViewModelType);
return null;
return !fallBackToDefault ? null : _kernel.Get<DefaultDataModelDisplayViewModel>();
}
}

View File

@ -19,7 +19,7 @@ namespace Artemis.UI.Shared.Services
void RemoveDataModelInput(DataModelVisualizationRegistration registration);
void RemoveDataModelDisplay(DataModelVisualizationRegistration registration);
DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType);
DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType, bool fallBackToDefault = false);
DataModelInputViewModel GetDataModelInputViewModel(Type propertyType, DataModelPropertyAttribute description, object initialValue, Action<object, bool> updateCallback);
DataModelDynamicViewModel GetDynamicSelectionViewModel(Module module);

View File

@ -315,10 +315,19 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="DataModelVisualization\Input\DoubleDataModelInputView.xaml">
<Page Update="DefaultTypes\DataModel\Display\SKColorDataModelDisplayView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="DataModelVisualization\Input\IntDataModelInputView.xaml">
<Page Update="DefaultTypes\DataModel\Input\DoubleDataModelInputView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="DefaultTypes\DataModel\Input\IntDataModelInputView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="DefaultTypes\DataModel\Input\SKColorDataModelInputView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="DefaultTypes\DataModel\Input\StringDataModelInputView.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>

View File

@ -1,10 +1,10 @@
<UserControl x:Class="Artemis.UI.DataModelVisualization.Display.SKColorDataModelDisplayView"
<UserControl x:Class="Artemis.UI.DefaultTypes.DataModel.Display.SKColorDataModelDisplayView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:display="clr-namespace:Artemis.UI.DataModelVisualization.Display"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:display="clr-namespace:Artemis.UI.DefaultTypes.DataModel.Display"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type display:SKColorDataModelDisplayViewModel}}">
@ -16,7 +16,6 @@
<shared:ColorToStringConverter x:Key="SKColorToStringConverter" />
<shared:SKColorToColorConverter x:Key="SKColorToColorConverter" />
</ResourceDictionary>
</UserControl.Resources>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock x:Name="HexDisplay"

View File

@ -1,7 +1,7 @@
using Artemis.UI.Shared;
using SkiaSharp;
namespace Artemis.UI.DataModelVisualization.Display
namespace Artemis.UI.DefaultTypes.DataModel.Display
{
public class SKColorDataModelDisplayViewModel : DataModelDisplayViewModel<SKColor>
{

View File

@ -1,4 +1,4 @@
<UserControl x:Class="Artemis.UI.DataModelVisualization.Input.DoubleDataModelInputView"
<UserControl x:Class="Artemis.UI.DefaultTypes.DataModel.Input.DoubleDataModelInputView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

View File

@ -4,7 +4,7 @@ using System.Windows.Input;
using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared;
namespace Artemis.UI.DataModelVisualization.Input
namespace Artemis.UI.DefaultTypes.DataModel.Input
{
public class DoubleDataModelInputViewModel : DataModelInputViewModel<double>
{

View File

@ -1,4 +1,4 @@
<UserControl x:Class="Artemis.UI.DataModelVisualization.Input.IntDataModelInputView"
<UserControl x:Class="Artemis.UI.DefaultTypes.DataModel.Input.IntDataModelInputView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

View File

@ -3,7 +3,7 @@ using System.Windows.Input;
using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared;
namespace Artemis.UI.DataModelVisualization.Input
namespace Artemis.UI.DefaultTypes.DataModel.Input
{
public class IntDataModelInputViewModel : DataModelInputViewModel<int>
{

View File

@ -0,0 +1,20 @@
<UserControl x:Class="Artemis.UI.DefaultTypes.DataModel.Input.SKColorDataModelInputView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Artemis.UI.Shared;component/Resources/ArtemisShared.xaml" />
</ResourceDictionary.MergedDictionaries>
<shared:SKColorToColorConverter x:Key="SKColorToColorConverter" />
</ResourceDictionary>
</UserControl.Resources>
<shared:ColorPicker VerticalAlignment="Center" Color="{Binding InputValue, Converter={StaticResource SKColorToColorConverter}}" StaysOpen="True" Width="140"/>
</UserControl>

View File

@ -0,0 +1,13 @@
using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared;
using SkiaSharp;
namespace Artemis.UI.DefaultTypes.DataModel.Input
{
public class SKColorDataModelInputViewModel : DataModelInputViewModel<SKColor>
{
public SKColorDataModelInputViewModel(DataModelPropertyAttribute targetDescription, SKColor initialValue) : base(targetDescription, initialValue)
{
}
}
}

View File

@ -1,4 +1,4 @@
<UserControl x:Class="Artemis.UI.DataModelVisualization.Input.StringDataModelInputView"
<UserControl x:Class="Artemis.UI.DefaultTypes.DataModel.Input.StringDataModelInputView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

View File

@ -1,7 +1,7 @@
using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared;
namespace Artemis.UI.DataModelVisualization.Input
namespace Artemis.UI.DefaultTypes.DataModel.Input
{
public class StringDataModelInputViewModel : DataModelInputViewModel<string>
{

View File

@ -105,10 +105,22 @@
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Margin="0 2">Input</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="0 2" FontFamily="Consolas" Text="{Binding TestInputValue}" />
<ContentControl Grid.Row="0"
Grid.Column="1"
s:View.Model="{Binding TestInputValue}"
Margin="0 2"
FontFamily="Consolas"
VerticalAlignment="Stretch"
HorizontalAlignment="Right" />
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0 2">Output</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="1" Margin="0 2" FontFamily="Consolas" Text="{Binding TestResultValue}" />
<ContentControl Grid.Row="1"
Grid.Column="1"
s:View.Model="{Binding TestResultValue}"
Margin="0 2"
FontFamily="Consolas"
VerticalAlignment="Stretch"
HorizontalAlignment="Right" />
</Grid>
</Grid>
</materialDesign:Card>

View File

@ -13,6 +13,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{
private readonly IDataBindingsVmFactory _dataBindingsVmFactory;
private readonly IProfileEditorService _profileEditorService;
private readonly IDataModelUIService _dataModelUIService;
private DataBinding<TLayerProperty, TProperty> _dataBinding;
private int _easingTime;
private bool _isEasingTimeEnabled;
@ -26,10 +27,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
public DataBindingViewModel(DataBindingRegistration<TLayerProperty, TProperty> registration,
IProfileEditorService profileEditorService,
IDataModelUIService dataModelUIService,
IDataBindingsVmFactory dataBindingsVmFactory)
{
Registration = registration;
_profileEditorService = profileEditorService;
_dataModelUIService = dataModelUIService;
_dataBindingsVmFactory = dataBindingsVmFactory;
if (Registration.Member != null)
@ -39,6 +42,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
DataBindingModes = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(typeof(DataBindingModeType)));
EasingViewModels = new BindableCollection<TimelineEasingViewModel>();
TestInputValue = _dataModelUIService.GetDataModelDisplayViewModel(typeof(TProperty), true);
TestResultValue = _dataModelUIService.GetDataModelDisplayViewModel(typeof(TProperty), true);
DataBinding = Registration.DataBinding;
@ -49,6 +54,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
public BindableCollection<ValueDescription> DataBindingModes { get; }
public BindableCollection<TimelineEasingViewModel> EasingViewModels { get; }
public DataModelDisplayViewModel TestInputValue { get; }
public DataModelDisplayViewModel TestResultValue { get; }
public DataBindingModeType SelectedDataBindingMode
{
@ -102,18 +109,6 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
set => SetAndNotify(ref _dataBinding, value);
}
public TProperty TestInputValue
{
get => _testInputValue;
set => SetAndNotify(ref _testInputValue, value);
}
public TProperty TestResultValue
{
get => _testResultValue;
set => SetAndNotify(ref _testResultValue, value);
}
public void Dispose()
{
_profileEditorService.ProfilePreviewUpdated -= ProfileEditorServiceOnProfilePreviewUpdated;
@ -222,18 +217,15 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
{
if (DataBinding == null)
{
TestInputValue = default;
TestResultValue = default;
TestInputValue.UpdateValue(default);
TestResultValue.UpdateValue(default);
return;
}
var currentValue = ActiveItem?.GetTestValue() ?? default(TProperty);
var currentValue = Registration.Converter.ConvertFromObject(ActiveItem?.GetTestValue() ?? default(TProperty));
TestInputValue = Registration.Converter.ConvertFromObject(currentValue);
if (DataBinding != null)
TestResultValue = DataBinding.GetValue(TestInputValue);
else
TestInputValue = default;
TestInputValue.UpdateValue(currentValue);
TestResultValue.UpdateValue(DataBinding != null ? DataBinding.GetValue(currentValue) : default);
}
private void EnableDataBinding()

View File

@ -79,11 +79,13 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
private void ParameterSelectionViewModelOnPropertySelected(object sender, DataModelInputDynamicEventArgs e)
{
Modifier.UpdateParameter(e.DataModelVisualizationViewModel.DataModel, e.DataModelVisualizationViewModel.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement();
}
private void StaticInputViewModelOnValueUpdated(object sender, DataModelInputStaticEventArgs e)
{
Modifier.UpdateParameter(e.Value);
_profileEditorService.UpdateSelectedProfileElement();
}
private void Update()
@ -155,6 +157,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
DynamicSelectionViewModel.Dispose();
DynamicSelectionViewModel.PropertySelected -= ParameterSelectionViewModelOnPropertySelected;
}
if (StaticInputViewModel != null)
{
StaticInputViewModel.Dispose();
}
}
}
}

View File

@ -97,21 +97,7 @@
<TextBlock Grid.Column="1" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
<!-- Value display -->
<TextBlock Grid.Column="2"
Text="{Binding DisplayValue, Mode=OneWay}"
FontFamily="Consolas"
HorizontalAlignment="Right"
Visibility="{Binding ShowToString, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
<TextBlock Grid.Column="2"
Text="null"
FontFamily="Consolas"
HorizontalAlignment="Right"
Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}"
Visibility="{Binding ShowNull, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
<ContentControl Grid.Column="2"
s:View.Model="{Binding DisplayViewModel}"
FontFamily="Consolas"
Visibility="{Binding ShowViewModel, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
<ContentControl Grid.Column="2" s:View.Model="{Binding DisplayViewModel}" FontFamily="Consolas" />
</Grid>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListPropertyViewModel}">

View File

@ -1,6 +1,6 @@
using Artemis.Core;
using Artemis.UI.DataModelVisualization.Display;
using Artemis.UI.DataModelVisualization.Input;
using Artemis.UI.DefaultTypes.DataModel.Display;
using Artemis.UI.DefaultTypes.DataModel.Input;
using Artemis.UI.PropertyInput;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services;
@ -36,9 +36,10 @@ namespace Artemis.UI.Services
if (_registeredBuiltInDataModelInputs)
return;
_dataModelUIService.RegisterDataModelInput<StringDataModelInputViewModel>(Constants.CorePluginInfo, null);
_dataModelUIService.RegisterDataModelInput<IntDataModelInputViewModel>(Constants.CorePluginInfo, Constants.IntegralNumberTypes);
_dataModelUIService.RegisterDataModelInput<DoubleDataModelInputViewModel>(Constants.CorePluginInfo, Constants.FloatNumberTypes);
_dataModelUIService.RegisterDataModelInput<IntDataModelInputViewModel>(Constants.CorePluginInfo, Constants.IntegralNumberTypes);
_dataModelUIService.RegisterDataModelInput<SKColorDataModelInputViewModel>(Constants.CorePluginInfo, null);
_dataModelUIService.RegisterDataModelInput<StringDataModelInputViewModel>(Constants.CorePluginInfo, null);
_registeredBuiltInDataModelInputs = true;
}

View File

@ -18,6 +18,7 @@ namespace Artemis.Plugins.Modules.General
DisplayName = "General";
DisplayIcon = "AllInclusive";
ExpandsDataModel = true;
ModuleTabs = new List<ModuleTab> {new ModuleTab<GeneralViewModel>("General")};
}