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

Data model conditions - Moved events into a separate 'mode'

This commit is contained in:
SpoinkyNL 2020-11-01 19:44:45 +01:00
parent e1eb03667e
commit 997ab005d8
26 changed files with 331 additions and 128 deletions

View File

@ -0,0 +1,31 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Artemis.Core.JsonConverters
{
/// <summary>
/// An int converter that, if required, will round float values
/// </summary>
internal class ForgivingIntConverter : JsonConverter<int>
{
public override bool CanWrite => false;
public override void WriteJson(JsonWriter writer, int value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override int ReadJson(JsonReader reader, Type objectType, int existingValue, bool hasExistingValue, JsonSerializer serializer)
{
JValue jsonValue = serializer.Deserialize<JValue>(reader);
if (jsonValue.Type == JTokenType.Float)
return (int) Math.Round(jsonValue.Value<double>());
if (jsonValue.Type == JTokenType.Integer)
return jsonValue.Value<int>();
throw new FormatException();
}
}
}

View File

@ -75,7 +75,7 @@ namespace Artemis.Core
return condition;
}
/// <summary>
/// Removes a condition from the conditional data binding's <see cref="Conditions" /> collection and disposes it
/// </summary>

View File

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.DataModelExpansions;
namespace Artemis.Core
@ -8,6 +10,45 @@ namespace Artemis.Core
/// </summary>
public class DataModelEvent<T> : IDataModelEvent where T : DataModelEventArgs
{
private bool _trackHistory;
/// <summary>
/// Creates a new instance of the <see cref="DataModelEvent{T}" /> class with history tracking disabled
/// </summary>
public DataModelEvent()
{
}
/// <summary>
/// Creates a new instance of the <see cref="DataModelEvent{T}" />
/// </summary>
/// <param name="trackHistory">A boolean indicating whether the last 20 events should be tracked</param>
public DataModelEvent(bool trackHistory)
{
_trackHistory = trackHistory;
}
/// <inheritdoc />
[DataModelProperty(Name = "Last event trigger", Description = "The time at which the event last triggered")]
public DateTime LastTrigger { get; private set; }
/// <summary>
/// Gets the event arguments of the last time the event was triggered
/// </summary>
[DataModelProperty(Description = "The arguments of the last time this event triggered")]
public T? LastEventArguments { get; private set; }
/// <inheritdoc />
[DataModelProperty(Description = "The total amount of times this event has triggered since the module was activated")]
public int TriggerCount { get; private set; }
/// <summary>
/// Gets a queue of the last 20 event arguments
/// <para>Always empty if <see cref="TrackHistory" /> is <see langword="false" /></para>
/// </summary>
[DataModelProperty(Description = "The arguments of the last time this event triggered")]
public Queue<T> EventArgumentsHistory { get; } = new Queue<T>(20);
/// <summary>
/// Trigger the event with the given <paramref name="eventArgs" />
/// </summary>
@ -21,6 +62,16 @@ namespace Artemis.Core
LastTrigger = DateTime.Now;
TriggerCount++;
if (TrackHistory)
{
lock (EventArgumentsHistory)
{
if (EventArgumentsHistory.Count == 20)
EventArgumentsHistory.Dequeue();
EventArgumentsHistory.Enqueue(eventArgs);
}
}
OnEventTriggered();
}
@ -30,26 +81,38 @@ namespace Artemis.Core
}
/// <inheritdoc />
public DateTime LastTrigger { get; private set; }
/// <inheritdoc />
public int TriggerCount { get; private set; }
/// <summary>
/// Gets the event arguments of the last time the event was triggered
/// </summary>
public T? LastEventArguments { get; private set; }
[DataModelIgnore]
public Type ArgumentsType => typeof(T);
/// <inheritdoc />
[DataModelIgnore]
public Type ArgumentsType => typeof(T);
public bool TrackHistory
{
get => _trackHistory;
set
{
EventArgumentsHistory.Clear();
_trackHistory = value;
}
}
/// <inheritdoc />
[DataModelIgnore]
public DataModelEventArgs? LastEventArgumentsUntyped => LastEventArguments;
/// <inheritdoc />
[DataModelIgnore]
public List<DataModelEventArgs> EventArgumentsHistoryUntyped => EventArgumentsHistory.Cast<DataModelEventArgs>().ToList();
/// <inheritdoc />
public event EventHandler? EventTriggered;
/// <inheritdoc />
public void Reset()
{
TriggerCount = 0;
EventArgumentsHistory.Clear();
}
}
/// <summary>
@ -57,6 +120,45 @@ namespace Artemis.Core
/// </summary>
public class DataModelEvent : IDataModelEvent
{
private bool _trackHistory;
/// <summary>
/// Creates a new instance of the <see cref="DataModelEvent" /> class with history tracking disabled
/// </summary>
public DataModelEvent()
{
}
/// <summary>
/// Creates a new instance of the <see cref="DataModelEvent" />
/// </summary>
/// <param name="trackHistory">A boolean indicating whether the last 20 events should be tracked</param>
public DataModelEvent(bool trackHistory)
{
_trackHistory = trackHistory;
}
/// <inheritdoc />
[DataModelProperty(Name = "Last event trigger", Description = "The time at which the event last triggered")]
public DateTime LastTrigger { get; private set; }
/// <summary>
/// Gets the event arguments of the last time the event was triggered
/// </summary>
[DataModelProperty(Description = "The arguments of the last time this event triggered")]
public DataModelEventArgs? LastEventArguments { get; private set; }
/// <inheritdoc />
[DataModelProperty(Description = "The total amount of times this event has triggered since the module was activated")]
public int TriggerCount { get; private set; }
/// <summary>
/// Gets a queue of the last 20 event arguments
/// <para>Always empty if <see cref="TrackHistory" /> is <see langword="false" /></para>
/// </summary>
[DataModelProperty(Description = "The arguments of the last time this event triggered")]
public Queue<DataModelEventArgs> EventArgumentsHistory { get; } = new Queue<DataModelEventArgs>(20);
/// <summary>
/// Trigger the event
/// </summary>
@ -68,6 +170,16 @@ namespace Artemis.Core
LastTrigger = DateTime.Now;
TriggerCount++;
if (TrackHistory)
{
lock (EventArgumentsHistory)
{
if (EventArgumentsHistory.Count == 20)
EventArgumentsHistory.Dequeue();
EventArgumentsHistory.Enqueue(eventArgs);
}
}
OnEventTriggered();
}
@ -75,27 +187,39 @@ namespace Artemis.Core
{
EventTriggered?.Invoke(this, EventArgs.Empty);
}
/// <inheritdoc />
public DateTime LastTrigger { get; private set; }
/// <inheritdoc />
public int TriggerCount { get; private set; }
/// <summary>
/// Gets the event arguments of the last time the event was triggered
/// </summary>
public DataModelEventArgs? LastEventArguments { get; private set; }
/// <inheritdoc />
[DataModelIgnore]
public Type ArgumentsType => typeof(DataModelEventArgs);
/// <inheritdoc />
[DataModelIgnore]
public bool TrackHistory
{
get => _trackHistory;
set
{
EventArgumentsHistory.Clear();
_trackHistory = value;
}
}
/// <inheritdoc />
[DataModelIgnore]
public DataModelEventArgs? LastEventArgumentsUntyped => LastEventArguments;
/// <inheritdoc />
[DataModelIgnore]
public List<DataModelEventArgs> EventArgumentsHistoryUntyped => EventArgumentsHistory.ToList();
/// <inheritdoc />
public event EventHandler? EventTriggered;
/// <inheritdoc />
public void Reset()
{
TriggerCount = 0;
EventArgumentsHistory.Clear();
}
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
@ -281,7 +280,7 @@ namespace Artemis.Core
Entity.Path = Path;
Entity.DataModelGuid = DataModelGuid;
Entity.WrapperType = Target switch
{
ListPredicateWrapperDataModel _ => PathWrapperType.List,

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
{
@ -19,14 +20,31 @@ namespace Artemis.Core
/// </summary>
Type ArgumentsType { get; }
/// <summary>
/// Gets or sets a boolean indicating whether the last 20 events should be tracked
/// <para>Note: setting this to <see langword="false" /> will clear the current history</para>
/// </summary>
bool TrackHistory { get; set; }
/// <summary>
/// Gets the event arguments of the last time the event was triggered by its base type
/// </summary>
public DataModelEventArgs? LastEventArgumentsUntyped { get; }
/// <summary>
/// Gets a list of the last 20 event arguments by their base type.
/// <para>Always empty if <see cref="TrackHistory" /> is <see langword="false" /></para>
/// </summary>
public List<DataModelEventArgs> EventArgumentsHistoryUntyped { get; }
/// <summary>
/// Fires when the event is triggered
/// </summary>
event EventHandler EventTriggered;
/// <summary>
/// Resets the trigger count and history of this data model event
/// </summary>
void Reset();
}
}

View File

@ -146,7 +146,7 @@ namespace Artemis.Core.Services
{
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
Converters = new List<JsonConverter> {new SKColorConverter()}
Converters = new List<JsonConverter> {new SKColorConverter(), new ForgivingIntConverter()}
};
}

View File

@ -131,6 +131,8 @@ namespace Artemis.UI.Shared.Input
}
}
public bool LoadEventChildren { get; set; } = true;
public void ChangeDataModel(DataModelPropertiesViewModel dataModel)
{
if (DataModelViewModel != null)
@ -199,17 +201,17 @@ namespace Artemis.UI.Shared.Input
private void OnUpdateTimerOnElapsed(object sender, ElapsedEventArgs e)
{
// if (!IsDataModelViewModelOpen)
// return;
//
// UpdateDataModelVisualization();
if (!IsDataModelViewModelOpen)
return;
UpdateDataModelVisualization();
}
private void UpdateDataModelVisualization()
{
DataModelViewModel.Update(_dataModelUIService);
DataModelViewModel.Update(_dataModelUIService, new DataModelUpdateConfiguration(LoadEventChildren));
foreach (DataModelPropertiesViewModel extraDataModelViewModel in ExtraDataModelViewModels)
extraDataModelViewModel.Update(_dataModelUIService);
extraDataModelViewModel.Update(_dataModelUIService, new DataModelUpdateConfiguration(LoadEventChildren));
}
#endregion

View File

@ -1,4 +1,6 @@
using Artemis.Core;
using System;
using System.Linq;
using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.UI.Shared.Services;
@ -6,12 +8,36 @@ namespace Artemis.UI.Shared
{
public class DataModelEventViewModel : DataModelVisualizationViewModel
{
private Type _displayValueType;
internal DataModelEventViewModel(DataModel dataModel, DataModelVisualizationViewModel parent, DataModelPath dataModelPath) : base(dataModel, parent, dataModelPath)
{
}
public override void Update(IDataModelUIService dataModelUIService)
public Type DisplayValueType
{
get => _displayValueType;
set => SetAndNotify(ref _displayValueType, value);
}
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
DisplayValueType = DataModelPath?.GetPropertyType();
if (configuration != null)
{
if (configuration.CreateEventChildren)
PopulateProperties(dataModelUIService, configuration);
else if (Children.Any())
Children.Clear();
}
// Only update children if the parent is expanded
if (Parent != null && !Parent.IsRootViewModel && !Parent.IsVisualizationExpanded)
return;
foreach (DataModelVisualizationViewModel dataModelVisualizationViewModel in Children)
dataModelVisualizationViewModel.Update(dataModelUIService, configuration);
}
public override object GetCurrentValue()

View File

@ -39,17 +39,17 @@ namespace Artemis.UI.Shared
public override string DisplayPath => null;
public override void Update(IDataModelUIService dataModelUIService)
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
((ListPredicateWrapperDataModel) DataModel).UntypedValue = DisplayValue;
PopulateProperties(dataModelUIService);
PopulateProperties(dataModelUIService, configuration);
if (DisplayViewModel == null)
return;
if (IsVisualizationExpanded && !DisplayViewModel.IsVisualizationExpanded)
DisplayViewModel.IsVisualizationExpanded = IsVisualizationExpanded;
DisplayViewModel.Update(dataModelUIService);
DisplayViewModel.Update(dataModelUIService, null);
}
public override object GetCurrentValue()

View File

@ -39,7 +39,7 @@ namespace Artemis.UI.Shared
return DisplayValue;
}
public override void Update(IDataModelUIService dataModelUIService)
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
// Display value gets updated by parent, don't do anything if it is null
if (DisplayValue == null)

View File

@ -45,7 +45,7 @@ namespace Artemis.UI.Shared
public BindableCollection<DataModelVisualizationViewModel> ListChildren { get; set; }
public override void Update(IDataModelUIService dataModelUIService)
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
if (Parent != null && !Parent.IsVisualizationExpanded)
return;
@ -83,7 +83,7 @@ namespace Artemis.UI.Shared
dataModelListPropertyViewModel.Index = index;
}
child.Update(dataModelUIService);
child.Update(dataModelUIService, configuration);
index++;
}

View File

@ -26,7 +26,7 @@ namespace Artemis.UI.Shared
set => SetAndNotify(ref _displayValue, value);
}
public override void Update(IDataModelUIService dataModelUIService)
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
DisplayValueType = DataModelPath?.GetPropertyType();
@ -38,14 +38,14 @@ namespace Artemis.UI.Shared
DisplayValue = null;
// Always populate properties
PopulateProperties(dataModelUIService);
PopulateProperties(dataModelUIService, configuration);
// Only update children if the parent is expanded
if (Parent != null && !Parent.IsRootViewModel && !Parent.IsVisualizationExpanded)
return;
foreach (DataModelVisualizationViewModel dataModelVisualizationViewModel in Children)
dataModelVisualizationViewModel.Update(dataModelUIService);
dataModelVisualizationViewModel.Update(dataModelUIService, configuration);
}
public override object GetCurrentValue()

View File

@ -33,7 +33,7 @@ namespace Artemis.UI.Shared
set => SetAndNotify(ref _displayViewModel, value);
}
public override void Update(IDataModelUIService dataModelUIService)
public override void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
if (Parent != null && !Parent.IsVisualizationExpanded && !Parent.IsRootViewModel)
return;

View File

@ -87,8 +87,9 @@ namespace Artemis.UI.Shared
/// <summary>
/// Updates the datamodel and if in an parent, any children
/// </summary>
/// <param name="dataModelUIService"></param>
public abstract void Update(IDataModelUIService dataModelUIService);
/// <param name="dataModelUIService">The data model UI service used during update</param>
/// <param name="configuration">The configuration to apply while updating</param>
public abstract void Update(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration);
public virtual object GetCurrentValue()
{
@ -147,7 +148,7 @@ namespace Artemis.UI.Shared
return 0;
}
internal void PopulateProperties(IDataModelUIService dataModelUIService)
internal void PopulateProperties(IDataModelUIService dataModelUIService, DataModelUpdateConfiguration dataModelUpdateConfiguration)
{
if (IsRootViewModel && DataModel == null)
return;
@ -260,4 +261,14 @@ namespace Artemis.UI.Shared
#endregion
}
public class DataModelUpdateConfiguration
{
public bool CreateEventChildren { get; }
public DataModelUpdateConfiguration(bool createEventChildren)
{
CreateEventChildren = createEventChildren;
}
}
}

View File

@ -6,21 +6,21 @@ namespace Artemis.UI.Shared
{
public static class DataModelWrapperExtensions
{
public static DataModelPropertiesViewModel CreateViewModel(this EventPredicateWrapperDataModel wrapper, IDataModelUIService dataModelUIService)
public static DataModelPropertiesViewModel CreateViewModel(this EventPredicateWrapperDataModel wrapper, IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
DataModelPropertiesViewModel viewModel = new DataModelPropertiesViewModel(wrapper, null, new DataModelPath(wrapper));
viewModel.Update(dataModelUIService);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(dataModelUIService);
viewModel.Update(dataModelUIService, configuration);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(dataModelUIService, configuration);
viewModel.Children.First().IsVisualizationExpanded = true;
return viewModel;
}
public static DataModelPropertiesViewModel CreateViewModel(this ListPredicateWrapperDataModel wrapper, IDataModelUIService dataModelUIService)
public static DataModelPropertiesViewModel CreateViewModel(this ListPredicateWrapperDataModel wrapper, IDataModelUIService dataModelUIService, DataModelUpdateConfiguration configuration)
{
DataModelPropertiesViewModel viewModel = new DataModelPropertiesViewModel(wrapper, null, new DataModelPath(wrapper));
viewModel.Update(dataModelUIService);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(dataModelUIService);
viewModel.Update(dataModelUIService, configuration);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(dataModelUIService, configuration);
viewModel.Children.First().IsVisualizationExpanded = true;
return viewModel;

View File

@ -37,8 +37,8 @@ namespace Artemis.UI.Shared.Services
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModelExpansion, viewModel, new DataModelPath(dataModelExpansion)));
// Update to populate children
viewModel.Update(this);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(this);
viewModel.Update(this, null);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(this, null);
return viewModel;
}
@ -67,8 +67,8 @@ namespace Artemis.UI.Shared.Services
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModel, viewModel, null));
// Update to populate children
viewModel.Update(this);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(this);
viewModel.Update(this, null);
viewModel.UpdateRequested += (sender, args) => viewModel.Update(this, null);
return viewModel;
}
@ -173,7 +173,7 @@ namespace Artemis.UI.Shared.Services
else
result = _kernel.Get<DefaultDataModelDisplayViewModel>();
if (result != null)
if (result != null)
result.PropertyDescription = description;
return result;

View File

@ -47,25 +47,11 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions.Abstract
return true;
}
// Event
if (IsEvent(newType))
{
if (this is DataModelConditionEventViewModel)
return false;
groupViewModel.ConvertToConditionEvent(this);
return true;
}
// Predicate
if (this is DataModelConditionPredicateViewModel)
return false;
groupViewModel.ConvertToPredicate(this);
return true;
}
protected bool IsEvent(Type type)
{
return type == typeof(DataModelEvent) || type.IsGenericType && type.GetGenericTypeDefinition() == typeof(DataModelEvent<>);
}
}
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;
@ -32,19 +32,11 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
{
LeftSideSelectionViewModel = _dataModelUIService.GetDynamicSelectionViewModel(_profileEditorService.GetCurrentModule());
LeftSideSelectionViewModel.PropertySelected += LeftSideSelectionViewModelOnPropertySelected;
LeftSideSelectionViewModel.LoadEventChildren = false;
IReadOnlyCollection<DataModelVisualizationRegistration> editors = _dataModelUIService.RegisteredDataModelEditors;
List<Type> supportedInputTypes = editors.Select(e => e.SupportedType).ToList();
supportedInputTypes.AddRange(editors.Where(e => e.CompatibleConversionTypes != null).SelectMany(e => e.CompatibleConversionTypes));
supportedInputTypes.Add(typeof(IEnumerable<>));
// Events are only supported in the root group enforce that here
if (Parent is DataModelConditionGroupViewModel groupViewModel && groupViewModel.IsRootGroup)
{
supportedInputTypes.Add(typeof(DataModelEvent));
supportedInputTypes.Add(typeof(DataModelEvent<>));
}
List<Type> supportedInputTypes = new List<Type> {typeof(DataModelEvent), typeof(DataModelEvent<>)};
LeftSideSelectionViewModel.FilterTypes = supportedInputTypes.ToArray();
LeftSideSelectionViewModel.ButtonBrush = new SolidColorBrush(Color.FromRgb(185, 164, 10));
LeftSideSelectionViewModel.Placeholder = "Select an event";
@ -84,11 +76,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
public void ApplyEvent()
{
Type newType = LeftSideSelectionViewModel.DataModelPath.GetPropertyType();
bool converted = ConvertIfRequired(newType);
if (converted)
return;
DataModelConditionEvent.UpdateEvent(LeftSideSelectionViewModel.DataModelPath);
_profileEditorService.UpdateSelectedProfileElement();

View File

@ -18,6 +18,7 @@
<ResourceDictionary Source="pack://application:,,,/Artemis.UI;component/ResourceDictionaries/DataModelConditions.xaml" />
</ResourceDictionary.MergedDictionaries>
<Converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
<utilities:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
</ResourceDictionary>
</UserControl.Resources>
@ -109,12 +110,20 @@
</Button.Style>
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Add condition" ToolTip="A condition that compares with another value" Command="{s:Action AddCondition}">
<MenuItem Header="Add condition" ToolTip="A condition that evaluates the state of a property in the data model" Command="{s:Action AddCondition}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Equal" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Add group" ToolTip="A group can contain conditions and other groups" Command="{s:Action AddGroup}">
<MenuItem Header="Add event condition"
ToolTip="An event condition that responds to data model events"
Command="{s:Action AddEventCondition}"
Visibility="{Binding Data.CanAddEventCondition, Source={StaticResource DataContextProxy}, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="LightningBolt" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Add group" ToolTip="A group for conditions and other groups" Command="{s:Action AddGroup}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="CodeParentheses" />
</MenuItem.Icon>

View File

@ -40,15 +40,21 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
});
}
public ConditionGroupType GroupType { get; set; }
public ConditionGroupType GroupType { get; }
public DataModelConditionGroup DataModelConditionGroup => (DataModelConditionGroup) Model;
public bool IsRootGroup
{
get => _isRootGroup;
set => SetAndNotify(ref _isRootGroup, value);
set
{
if (!SetAndNotify(ref _isRootGroup, value)) return;
NotifyOfPropertyChange(nameof(CanAddEventCondition));
}
}
public bool CanAddEventCondition => IsRootGroup && GroupType == ConditionGroupType.General;
public bool IsEventGroup
{
get => _isEventGroup;
@ -94,6 +100,23 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
_profileEditorService.UpdateSelectedProfileElement();
}
public void AddEventCondition()
{
if (!CanAddEventCondition)
return;
// Find a good spot for the event, behind the last existing event
int index = 0;
DataModelConditionPart existing = DataModelConditionGroup.Children.LastOrDefault(c => c is DataModelConditionEvent);
if (existing != null)
index = DataModelConditionGroup.Children.IndexOf(existing) + 1;
DataModelConditionGroup.AddChild(new DataModelConditionEvent(DataModelConditionGroup), index);
Update();
_profileEditorService.UpdateSelectedProfileElement();
}
public void AddGroup()
{
DataModelConditionGroup.AddChild(new DataModelConditionGroup(DataModelConditionGroup));
@ -171,24 +194,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
Update();
}
public void ConvertToConditionEvent(DataModelConditionViewModel predicateViewModel)
{
// Remove the old child
DataModelConditionGroup.RemoveChild(predicateViewModel.Model);
DataModelConditionPart rootGroup = DataModelConditionGroup;
while (rootGroup.Parent != null)
rootGroup = rootGroup.Parent;
// Insert an event at the start of the root group
DataModelConditionEvent conditionEvent = new DataModelConditionEvent(rootGroup);
conditionEvent.UpdateEvent(predicateViewModel.LeftSideSelectionViewModel.DataModelPath);
rootGroup.AddChild(conditionEvent, 0);
// Update to switch the VMs
Update();
}
public void ConvertToPredicate(DataModelConditionViewModel listViewModel)
{
// Store the old index and remove the old predicate

View File

@ -73,13 +73,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
supportedInputTypes.AddRange(editors.Where(e => e.CompatibleConversionTypes != null).SelectMany(e => e.CompatibleConversionTypes));
supportedInputTypes.Add(typeof(IEnumerable<>));
// Events are only supported in the root group enforce that here
if (Parent is DataModelConditionGroupViewModel groupViewModel && groupViewModel.IsRootGroup)
{
supportedInputTypes.Add(typeof(DataModelEvent));
supportedInputTypes.Add(typeof(DataModelEvent<>));
}
LeftSideSelectionViewModel.FilterTypes = supportedInputTypes.ToArray();
LeftSideSelectionViewModel.ButtonBrush = new SolidColorBrush(Color.FromRgb(71, 108, 188));
LeftSideSelectionViewModel.Placeholder = "Select a list";

View File

@ -67,7 +67,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
DataModelConditionEventPredicate.DataModelConditionEvent.EventArgumentType
);
return wrapper.CreateViewModel(_dataModelUIService);
return wrapper.CreateViewModel(_dataModelUIService, new DataModelUpdateConfiguration(false));
}
}
}

View File

@ -34,13 +34,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
supportedInputTypes.AddRange(editors.Where(e => e.CompatibleConversionTypes != null).SelectMany(e => e.CompatibleConversionTypes));
supportedInputTypes.Add(typeof(IEnumerable<>));
// Events are only supported in the root group enforce that here
if (Parent is DataModelConditionGroupViewModel groupViewModel && groupViewModel.IsRootGroup)
{
supportedInputTypes.Add(typeof(DataModelEvent));
supportedInputTypes.Add(typeof(DataModelEvent<>));
}
return supportedInputTypes;
}

View File

@ -77,7 +77,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
DataModelConditionListPredicate.DataModelConditionList.ListType
);
return wrapper.CreateViewModel(_dataModelUIService);
return wrapper.CreateViewModel(_dataModelUIService, new DataModelUpdateConfiguration(true));
}
}
}

View File

@ -135,6 +135,25 @@
<ContentControl Grid.Column="2" s:View.Model="{Binding DisplayViewModel}" FontFamily="Consolas" />
</Grid>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelEventViewModel}" ItemsSource="{Binding Children}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
<Run>[</Run><Run Text="{Binding DisplayValueType, Converter={StaticResource TypeToStringConverter}, Mode=OneWay}" /><Run>]</Run>
</TextBlock>
<TextBlock Grid.Column="1" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
<TextBlock Grid.Column="2"
Text="{Binding CountDisplay, Mode=OneWay}"
FontFamily="Consolas"
HorizontalAlignment="Right" />
</Grid>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListPropertiesViewModel}" ItemsSource="{Binding DisplayViewModel.Children}">
<TextBlock>
<Run>List item [</Run><Run Text="{Binding Index, Mode=OneWay}" /><Run>]</Run>

View File

@ -99,7 +99,7 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
{
lock (MainDataModel)
{
MainDataModel.Update(_dataModelUIService);
MainDataModel.Update(_dataModelUIService, null);
}
}