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 /// Gets whether this module's activation was due to an override, can only be true if <see cref="IsActivated" /> is
/// true /// true
/// </summary> /// </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> /// <summary>
/// A list of activation requirements /// A list of activation requirements
@ -183,7 +189,8 @@ namespace Artemis.Core.Modules
internal virtual void InternalUpdate(double deltaTime) 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) 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) internal override void InternalUpdate(double deltaTime)
{ {
Update(deltaTime); if (!IsActivatedOverride || UpdateDuringActivationOverride)
Update(deltaTime);
lock (this) lock (this)
{ {

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Timers; using System.Timers;
using Artemis.Core.Modules;
namespace Artemis.Core namespace Artemis.Core
{ {
@ -53,6 +54,13 @@ namespace Artemis.Core
if (_timer != null) if (_timer != null)
return; 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; _lastEvent = DateTime.Now;
_timer = new Timer(Interval.TotalMilliseconds); _timer = new Timer(Interval.TotalMilliseconds);
_timer.Elapsed += TimerOnElapsed; _timer.Elapsed += TimerOnElapsed;

View File

@ -92,7 +92,7 @@
Placement="Bottom" Placement="Bottom"
CustomPopupPlacementCallback="{x:Static materialDesign:CustomPopupPlacementCallbackHelper.LargePopupCallback}" CustomPopupPlacementCallback="{x:Static materialDesign:CustomPopupPlacementCallbackHelper.LargePopupCallback}"
PlacementTarget="{Binding ElementName=ColorCodeTextBox}" PlacementTarget="{Binding ElementName=ColorCodeTextBox}"
StaysOpen="False" StaysOpen="{Binding StaysOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
PopupAnimation="Fade" PopupAnimation="Fade"
IsOpen="{Binding PopupOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"> IsOpen="{Binding PopupOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}">
<materialDesign:Card Width="200" Height="200" Margin="30" materialDesign:ShadowAssist.ShadowDepth="Depth4"> <materialDesign:Card Width="200" Height="200" Margin="30" materialDesign:ShadowAssist.ShadowDepth="Depth4">
@ -101,7 +101,7 @@
<RowDefinition Height="160" /> <RowDefinition Height="160" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </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" <Slider Grid.Row="1" Margin="8"
IsMoveToPointEnabled="True" IsMoveToPointEnabled="True"
Orientation="Horizontal" 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), public static readonly DependencyProperty PopupOpenProperty = DependencyProperty.Register(nameof(PopupOpen), typeof(bool), typeof(ColorPicker),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, PopupOpenPropertyChangedCallback)); 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), internal static readonly DependencyProperty ColorOpacityProperty = DependencyProperty.Register(nameof(ColorOpacity), typeof(byte), typeof(ColorPicker),
new FrameworkPropertyMetadata((byte) 255, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ColorOpacityPropertyChangedCallback)); new FrameworkPropertyMetadata((byte) 255, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ColorOpacityPropertyChangedCallback));
@ -54,6 +57,12 @@ namespace Artemis.UI.Shared
set => SetValue(PopupOpenProperty, value); set => SetValue(PopupOpenProperty, value);
} }
public bool StaysOpen
{
get => (bool) GetValue(StaysOpenProperty);
set => SetValue(StaysOpenProperty, value);
}
internal byte ColorOpacity internal byte ColorOpacity
{ {
get => (byte) GetValue(ColorOpacityProperty); get => (byte) GetValue(ColorOpacityProperty);
@ -92,6 +101,17 @@ namespace Artemis.UI.Shared
colorPicker._inCallback = false; 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) private static void ColorOpacityPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{ {
var colorPicker = (ColorPicker) d; var colorPicker = (ColorPicker) d;
@ -112,6 +132,12 @@ namespace Artemis.UI.Shared
private void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e) private void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e)
{ {
PopupOpen = !PopupOpen; 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 /> /// <inheritdoc />
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
return value?.ToString(); return value?.ToString()?.ToUpper();
} }
/// <inheritdoc /> /// <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; DisplayValue = model is T value ? value : default;
} }
internal override object InternalGuard => null;
} }
/// <summary> /// <summary>
@ -31,9 +33,11 @@ namespace Artemis.UI.Shared
/// </summary> /// </summary>
public abstract class DataModelDisplayViewModel : PropertyChangedBase public abstract class DataModelDisplayViewModel : PropertyChangedBase
{ {
public abstract void UpdateValue(object model);
/// <summary> /// <summary>
/// Prevents this type being implemented directly, implement <see cref="DataModelDisplayViewModel{T}" /> instead. /// Prevents this type being implemented directly, implement <see cref="DataModelDisplayViewModel{T}" /> instead.
/// </summary> /// </summary>
internal abstract void UpdateValue(object model); internal abstract object InternalGuard { get; }
} }
} }

View File

@ -33,7 +33,7 @@
<TextBlock FontWeight="Light" <TextBlock FontWeight="Light"
Text="{Binding TargetPropertyViewModel.PropertyDescription.Prefix}" Text="{Binding TargetPropertyViewModel.PropertyDescription.Prefix}"
Visibility="{Binding TargetPropertyViewModel.PropertyDescription.Prefix, Converter={StaticResource NullToVisibilityConverter}}" /> 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" <TextBlock FontWeight="Light"
Text="{Binding TargetPropertyViewModel.PropertyDescription.Affix}" Text="{Binding TargetPropertyViewModel.PropertyDescription.Affix}"
Visibility="{Binding TargetPropertyViewModel.PropertyDescription.Affix, Converter={StaticResource NullToVisibilityConverter}}" /> Visibility="{Binding TargetPropertyViewModel.PropertyDescription.Affix, Converter={StaticResource NullToVisibilityConverter}}" />

View File

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

View File

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

View File

@ -9,9 +9,6 @@ namespace Artemis.UI.Shared
{ {
private object _displayValue; private object _displayValue;
private DataModelDisplayViewModel _displayViewModel; private DataModelDisplayViewModel _displayViewModel;
private bool _showNull;
private bool _showToString;
private bool _showViewModel;
internal DataModelPropertyViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, PropertyInfo propertyInfo) : base(dataModel, parent, propertyInfo) 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); 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) public override void Update(IDataModelUIService dataModelUIService)
{ {
if (Parent != null && !Parent.IsVisualizationExpanded && !Parent.IsRootViewModel) if (Parent != null && !Parent.IsVisualizationExpanded && !Parent.IsRootViewModel)
return; return;
if (DisplayViewModel == null && dataModelUIService.RegisteredDataModelDisplays.Any(d => d.SupportedType == PropertyInfo.PropertyType)) if (DisplayViewModel == null)
dataModelUIService.GetDataModelDisplayViewModel(PropertyInfo.PropertyType); DisplayViewModel = dataModelUIService.GetDataModelDisplayViewModel(PropertyInfo.PropertyType, true);
DisplayValue = GetCurrentValue(); DisplayValue = GetCurrentValue();
UpdateDisplayParameters(); UpdateDisplayParameters();
@ -61,10 +40,6 @@ namespace Artemis.UI.Shared
protected void UpdateDisplayParameters() protected void UpdateDisplayParameters()
{ {
ShowToString = DisplayValue != null && DisplayViewModel == null;
ShowNull = DisplayValue == null;
ShowViewModel = DisplayValue != null && DisplayViewModel != null;
DisplayViewModel?.UpdateValue(DisplayValue); 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.DataModelExpansions;
using Artemis.Core.Modules; using Artemis.Core.Modules;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.UI.Shared.DefaultTypes.DataModel.Display;
using Artemis.UI.Shared.Input; using Artemis.UI.Shared.Input;
using Ninject; using Ninject;
using Ninject.Parameters; 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) lock (_registeredDataModelDisplays)
{ {
var match = _registeredDataModelDisplays.FirstOrDefault(d => d.SupportedType == propertyType); var match = _registeredDataModelDisplays.FirstOrDefault(d => d.SupportedType == propertyType);
if (match != null) if (match != null)
return (DataModelDisplayViewModel) _kernel.Get(match.ViewModelType); 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 RemoveDataModelInput(DataModelVisualizationRegistration registration);
void RemoveDataModelDisplay(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); DataModelInputViewModel GetDataModelInputViewModel(Type propertyType, DataModelPropertyAttribute description, object initialValue, Action<object, bool> updateCallback);
DataModelDynamicViewModel GetDynamicSelectionViewModel(Module module); DataModelDynamicViewModel GetDynamicSelectionViewModel(Module module);

View File

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

View File

@ -1,7 +1,7 @@
using Artemis.UI.Shared; using Artemis.UI.Shared;
using SkiaSharp; using SkiaSharp;
namespace Artemis.UI.DataModelVisualization.Display namespace Artemis.UI.DefaultTypes.DataModel.Display
{ {
public class SKColorDataModelDisplayViewModel : DataModelDisplayViewModel<SKColor> 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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 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.Core.DataModelExpansions;
using Artemis.UI.Shared; using Artemis.UI.Shared;
namespace Artemis.UI.DataModelVisualization.Input namespace Artemis.UI.DefaultTypes.DataModel.Input
{ {
public class DoubleDataModelInputViewModel : DataModelInputViewModel<double> 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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 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.Core.DataModelExpansions;
using Artemis.UI.Shared; using Artemis.UI.Shared;
namespace Artemis.UI.DataModelVisualization.Input namespace Artemis.UI.DefaultTypes.DataModel.Input
{ {
public class IntDataModelInputViewModel : DataModelInputViewModel<int> 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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

View File

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

View File

@ -105,10 +105,22 @@
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Margin="0 2">Input</TextBlock> <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="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>
</Grid> </Grid>
</materialDesign:Card> </materialDesign:Card>

View File

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

View File

@ -79,11 +79,13 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
private void ParameterSelectionViewModelOnPropertySelected(object sender, DataModelInputDynamicEventArgs e) private void ParameterSelectionViewModelOnPropertySelected(object sender, DataModelInputDynamicEventArgs e)
{ {
Modifier.UpdateParameter(e.DataModelVisualizationViewModel.DataModel, e.DataModelVisualizationViewModel.PropertyPath); Modifier.UpdateParameter(e.DataModelVisualizationViewModel.DataModel, e.DataModelVisualizationViewModel.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement();
} }
private void StaticInputViewModelOnValueUpdated(object sender, DataModelInputStaticEventArgs e) private void StaticInputViewModelOnValueUpdated(object sender, DataModelInputStaticEventArgs e)
{ {
Modifier.UpdateParameter(e.Value); Modifier.UpdateParameter(e.Value);
_profileEditorService.UpdateSelectedProfileElement();
} }
private void Update() private void Update()
@ -155,6 +157,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
DynamicSelectionViewModel.Dispose(); DynamicSelectionViewModel.Dispose();
DynamicSelectionViewModel.PropertySelected -= ParameterSelectionViewModelOnPropertySelected; 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}" /> <TextBlock Grid.Column="1" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
<!-- Value display --> <!-- Value display -->
<TextBlock Grid.Column="2" <ContentControl Grid.Column="2" s:View.Model="{Binding DisplayViewModel}" FontFamily="Consolas" />
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}" />
</Grid> </Grid>
</HierarchicalDataTemplate> </HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListPropertyViewModel}"> <HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListPropertyViewModel}">

View File

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

View File

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