From fbd319beb91ac9e7031649b1eff8920d84ac3aa8 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sat, 24 Oct 2020 20:09:51 +0200 Subject: [PATCH] Data model conditions - Added event predicates (WIP commit) --- .../Artemis.Core.csproj.DotSettings | 1 + .../Conditions/DataModelConditionEvent.cs | 50 ++++++ .../DataModelConditionEventPredicate.cs | 154 ++++++++++++++++++ .../DataModelConditionListPredicate.cs | 6 +- .../EventPredicateWrapperDataModel.cs | 37 +++++ .../ListPredicateWrapperDataModel.cs | 6 + .../Profile/DataModel/DataModelEvent.cs | 12 +- .../Profile/DataModel/IDataModelEvent.cs | 2 +- .../DataModelConditionEventEntity.cs | 5 +- .../DataModelConditionEventPredicateEntity.cs | 6 + .../Entities/Profile/DataModelPathEntity.cs | 9 + .../Artemis.UI.Shared.csproj.DotSettings | 1 + .../Extensions/DataModelWrapperExtensions.cs | 17 ++ .../Ninject/Factories/IVMFactory.cs | 3 +- .../DataModelConditionEventView.xaml | 24 ++- .../DataModelConditionEventViewModel.cs | 25 +++ .../DataModelConditionGroupViewModel.cs | 42 +++-- .../DataModelConditionListViewModel.cs | 2 +- .../DataModelConditionEventPredicateView.xaml | 94 +++++++++++ ...taModelConditionEventPredicateView.xaml.cs | 26 +++ ...taModelConditionEventPredicateViewModel.cs | 69 ++++++++ .../DataModelConditionListPredicateView.xaml | 10 -- .../DisplayConditionsViewModel.cs | 2 +- .../DataBindingConditionViewModel.cs | 2 +- 24 files changed, 568 insertions(+), 37 deletions(-) create mode 100644 src/Artemis.Core/Models/Profile/Conditions/DataModelConditionEventPredicate.cs create mode 100644 src/Artemis.Core/Models/Profile/Conditions/Wrappers/EventPredicateWrapperDataModel.cs rename src/Artemis.Core/Models/Profile/Conditions/{ => Wrappers}/ListPredicateWrapperDataModel.cs (81%) create mode 100644 src/Artemis.Storage/Entities/Profile/Conditions/DataModelConditionEventPredicateEntity.cs create mode 100644 src/Artemis.UI.Shared/Extensions/DataModelWrapperExtensions.cs create mode 100644 src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionEventPredicateView.xaml create mode 100644 src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionEventPredicateView.xaml.cs create mode 100644 src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionEventPredicateViewModel.cs diff --git a/src/Artemis.Core/Artemis.Core.csproj.DotSettings b/src/Artemis.Core/Artemis.Core.csproj.DotSettings index 06398867e..705d6dc5c 100644 --- a/src/Artemis.Core/Artemis.Core.csproj.DotSettings +++ b/src/Artemis.Core/Artemis.Core.csproj.DotSettings @@ -1,4 +1,5 @@  + True True True True diff --git a/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionEvent.cs b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionEvent.cs index be0cf0e81..53f1f27c8 100644 --- a/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionEvent.cs +++ b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionEvent.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Artemis.Storage.Entities.Profile.Abstract; using Artemis.Storage.Entities.Profile.Conditions; @@ -39,6 +40,7 @@ namespace Artemis.Core /// public DataModelPath? EventPath { get; private set; } + public Type? EventArgumentType { get; set; } internal DataModelConditionEventEntity Entity { get; set; } @@ -57,6 +59,11 @@ namespace Artemis.Core return false; _eventTriggered = false; + + // If there is a child (root group), it must evaluate to true whenever the event triggered + if (Children.Any()) + return Children[0].Evaluate(); + // If there are no children, we always evaluate to true whenever the event triggered return true; } @@ -84,6 +91,31 @@ namespace Artemis.Core EventPath?.Dispose(); EventPath = path != null ? new DataModelPath(path) : null; SubscribeToEventPath(); + + // Remove the old root group that was tied to the old data model + while (Children.Any()) + RemoveChild(Children[0]); + + if (EventPath != null) + { + EventArgumentType = GetEventArgumentType(); + // Create a new root group + AddChild(new DataModelConditionGroup(this)); + } + else + { + EventArgumentType = null; + } + } + + private Type? GetEventArgumentType() + { + if (EventPath == null || !EventPath.IsValid) + return null; + + // Cannot rely on EventPath.GetValue() because part of the path might be null + Type eventType = EventPath.GetPropertyType()!; + return eventType.IsGenericType ? eventType.GetGenericArguments()[0] : typeof(DataModelEventArgs); } #region IDisposable @@ -117,6 +149,12 @@ namespace Artemis.Core // Target list EventPath?.Save(); Entity.EventPath = EventPath?.Entity; + + // Children + Entity.Children.Clear(); + Entity.Children.AddRange(Children.Select(c => c.GetEntity())); + foreach (DataModelConditionPart child in Children) + child.Save(); } internal override DataModelConditionPartEntity GetEntity() @@ -137,6 +175,18 @@ namespace Artemis.Core EventPath = eventPath; SubscribeToEventPath(); + + EventArgumentType = GetEventArgumentType(); + // There should only be one child and it should be a group + if (Entity.Children.FirstOrDefault() is DataModelConditionGroupEntity rootGroup) + { + AddChild(new DataModelConditionGroup(this, rootGroup)); + } + else + { + Entity.Children.Clear(); + AddChild(new DataModelConditionGroup(this)); + } } private bool PointsToEvent(DataModelPath dataModelPath) diff --git a/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionEventPredicate.cs b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionEventPredicate.cs new file mode 100644 index 000000000..97e8ad1fb --- /dev/null +++ b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionEventPredicate.cs @@ -0,0 +1,154 @@ +using System; +using Artemis.Storage.Entities.Profile; +using Artemis.Storage.Entities.Profile.Conditions; + +namespace Artemis.Core +{ + /// + /// A predicate like evaluated inside a + /// + public class DataModelConditionEventPredicate : DataModelConditionPredicate + { + /// + /// Creates a new instance of the class + /// + /// + /// + public DataModelConditionEventPredicate(DataModelConditionPart parent, ProfileRightSideType predicateType) + : base(parent, predicateType, new DataModelConditionEventPredicateEntity()) + { + DataModelConditionEvent = null!; + ApplyParentEvent(); + Initialize(); + } + + internal DataModelConditionEventPredicate(DataModelConditionPart parent, DataModelConditionEventPredicateEntity entity) + : base(parent, entity) + { + DataModelConditionEvent = null!; + ApplyParentEvent(); + Initialize(); + } + + /// + /// Gets the data model condition event this predicate belongs to + /// + public DataModelConditionEvent DataModelConditionEvent { get; private set; } + + private void ApplyParentEvent() + { + DataModelConditionPart? current = Parent; + while (current != null) + { + if (current is DataModelConditionEvent parentEvent) + { + DataModelConditionEvent = parentEvent; + return; + } + + current = current.Parent; + } + + if (DataModelConditionEvent == null) + throw new ArtemisCoreException("This data model condition event predicate does not belong to a data model condition event"); + } + + private object? GetEventPathValue(DataModelPath path, object target) + { + if (!(path.Target is EventPredicateWrapperDataModel wrapper)) + throw new ArtemisCoreException("Data model condition event predicate has a path with an invalid target"); + + wrapper.UntypedArguments = target; + return path.GetValue(); + } + + #region Initialization + + protected override void InitializeLeftPath() + { + if (Entity.LeftPath != null) + LeftPath = DataModelConditionEvent.EventArgumentType != null + ? new DataModelPath(EventPredicateWrapperDataModel.Create(DataModelConditionEvent.EventArgumentType), Entity.LeftPath) + : null; + } + + protected override void InitializeRightPath() + { + if (PredicateType == ProfileRightSideType.Dynamic && Entity.RightPath != null) + { + // Right side dynamic using event arguments + if (Entity.RightPath.WrapperType == PathWrapperType.Event) + { + RightPath = DataModelConditionEvent.EventArgumentType != null + ? new DataModelPath(EventPredicateWrapperDataModel.Create(DataModelConditionEvent.EventArgumentType), Entity.RightPath) + : null; + } + // Right side dynamic + else + RightPath = new DataModelPath(null, Entity.RightPath); + } + } + + #endregion + + #region Modification + + /// + public override Type? GetPreferredRightSideType() + { + Type? preferredType = Operator?.RightSideType; + Type? leftSideType = LeftPath?.GetPropertyType(); + if (preferredType == null) + return null; + + if (leftSideType != null && preferredType.IsAssignableFrom(leftSideType)) + preferredType = leftSideType; + + return preferredType; + } + + #endregion + + #region Evaluation + + /// + /// Not supported for event predicates, always returns false + /// + public override bool Evaluate() + { + return false; + } + + internal override bool EvaluateObject(object target) + { + if (Operator == null || LeftPath == null || !LeftPath.IsValid) + return false; + + // Compare with a static value + if (PredicateType == ProfileRightSideType.Static) + { + object? leftSideValue = GetEventPathValue(LeftPath, target); + if (leftSideValue != null && leftSideValue.GetType().IsValueType && RightStaticValue == null) + return false; + + return Operator.InternalEvaluate(leftSideValue, RightStaticValue); + } + + if (RightPath == null || !RightPath.IsValid) + return false; + + // Compare with dynamic values + if (PredicateType == ProfileRightSideType.Dynamic) + { + // If the path targets a property inside the event, evaluate on the event path value instead of the right path value + if (RightPath.Target is EventPredicateWrapperDataModel) + return Operator.InternalEvaluate(GetEventPathValue(LeftPath, target), GetEventPathValue(RightPath, target)); + return Operator.InternalEvaluate(GetEventPathValue(LeftPath, target), RightPath.GetValue()); + } + + return false; + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionListPredicate.cs b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionListPredicate.cs index 06f520fe6..c5033f1a3 100644 --- a/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionListPredicate.cs +++ b/src/Artemis.Core/Models/Profile/Conditions/DataModelConditionListPredicate.cs @@ -1,4 +1,5 @@ using System; +using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile.Conditions; namespace Artemis.Core @@ -76,11 +77,12 @@ namespace Artemis.Core if (PredicateType == ProfileRightSideType.Dynamic && Entity.RightPath != null) { // Right side dynamic inside the list - // TODO: Come up with a general wrapper solution because this will clash with events - if (Entity.RightPath.DataModelGuid == Constants.CorePluginInfo.Guid) + if (Entity.RightPath.WrapperType == PathWrapperType.List) + { RightPath = DataModelConditionList.ListType != null ? new DataModelPath(ListPredicateWrapperDataModel.Create(DataModelConditionList.ListType), Entity.RightPath) : null; + } // Right side dynamic else RightPath = new DataModelPath(null, Entity.RightPath); diff --git a/src/Artemis.Core/Models/Profile/Conditions/Wrappers/EventPredicateWrapperDataModel.cs b/src/Artemis.Core/Models/Profile/Conditions/Wrappers/EventPredicateWrapperDataModel.cs new file mode 100644 index 000000000..aee8d2adc --- /dev/null +++ b/src/Artemis.Core/Models/Profile/Conditions/Wrappers/EventPredicateWrapperDataModel.cs @@ -0,0 +1,37 @@ +using System; +using Artemis.Core.DataModelExpansions; + +namespace Artemis.Core +{ + internal class EventPredicateWrapperDataModel : EventPredicateWrapperDataModel + { + [DataModelProperty(Name = "Event arguments", Description = "The arguments provided when the event triggers")] + public T Arguments => (UntypedArguments is T typedArguments ? typedArguments : default)!; + } + + /// + /// Represents a datamodel that wraps the event arguments of an event + /// + public abstract class EventPredicateWrapperDataModel : DataModel + { + internal EventPredicateWrapperDataModel() + { + PluginInfo = Constants.CorePluginInfo; + } + + [DataModelIgnore] + public object? UntypedArguments { get; set; } + + /// + /// Creates a new instance of the class + /// + public static EventPredicateWrapperDataModel Create(Type type) + { + object? instance = Activator.CreateInstance(typeof(EventPredicateWrapperDataModel<>).MakeGenericType(type)); + if (instance == null) + throw new ArtemisCoreException($"Failed to create an instance of EventPredicateWrapperDataModel for type {type.Name}"); + + return (EventPredicateWrapperDataModel) instance; + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/Conditions/ListPredicateWrapperDataModel.cs b/src/Artemis.Core/Models/Profile/Conditions/Wrappers/ListPredicateWrapperDataModel.cs similarity index 81% rename from src/Artemis.Core/Models/Profile/Conditions/ListPredicateWrapperDataModel.cs rename to src/Artemis.Core/Models/Profile/Conditions/Wrappers/ListPredicateWrapperDataModel.cs index 7c436e8aa..1c8a3d458 100644 --- a/src/Artemis.Core/Models/Profile/Conditions/ListPredicateWrapperDataModel.cs +++ b/src/Artemis.Core/Models/Profile/Conditions/Wrappers/ListPredicateWrapperDataModel.cs @@ -9,6 +9,9 @@ namespace Artemis.Core public T Value => (UntypedValue is T typedValue ? typedValue : default)!; } + /// + /// Represents a datamodel that wraps a value in a list + /// public abstract class ListPredicateWrapperDataModel : DataModel { internal ListPredicateWrapperDataModel() @@ -19,6 +22,9 @@ namespace Artemis.Core [DataModelIgnore] public object? UntypedValue { get; set; } + /// + /// Creates a new instance of the class + /// public static ListPredicateWrapperDataModel Create(Type type) { object? instance = Activator.CreateInstance(typeof(ListPredicateWrapperDataModel<>).MakeGenericType(type)); diff --git a/src/Artemis.Core/Models/Profile/DataModel/DataModelEvent.cs b/src/Artemis.Core/Models/Profile/DataModel/DataModelEvent.cs index 79e719881..ac3d39dfe 100644 --- a/src/Artemis.Core/Models/Profile/DataModel/DataModelEvent.cs +++ b/src/Artemis.Core/Models/Profile/DataModel/DataModelEvent.cs @@ -58,6 +58,9 @@ namespace Artemis.Core /// public void Trigger() { + DataModelEventArgs eventArgs = new DataModelEventArgs {TriggerTime = DateTime.Now}; + + LastEventArguments = eventArgs; LastTrigger = DateTime.Now; TriggerCount++; @@ -74,10 +77,15 @@ namespace Artemis.Core /// public int TriggerCount { get; private set; } - + + /// + /// Gets the event arguments of the last time the event was triggered + /// + public DataModelEventArgs? LastEventArguments { get; private set; } + /// [DataModelIgnore] - public Type? ArgumentsType => null; + public Type ArgumentsType => typeof(DataModelEventArgs); /// public event EventHandler? EventTriggered; diff --git a/src/Artemis.Core/Models/Profile/DataModel/IDataModelEvent.cs b/src/Artemis.Core/Models/Profile/DataModel/IDataModelEvent.cs index c31606967..e0e26b059 100644 --- a/src/Artemis.Core/Models/Profile/DataModel/IDataModelEvent.cs +++ b/src/Artemis.Core/Models/Profile/DataModel/IDataModelEvent.cs @@ -17,7 +17,7 @@ namespace Artemis.Core /// /// Gets the type of arguments this event contains /// - Type? ArgumentsType { get; } + Type ArgumentsType { get; } /// /// Fires when the event is triggered diff --git a/src/Artemis.Storage/Entities/Profile/Conditions/DataModelConditionEventEntity.cs b/src/Artemis.Storage/Entities/Profile/Conditions/DataModelConditionEventEntity.cs index cd710f0d5..141f5bb08 100644 --- a/src/Artemis.Storage/Entities/Profile/Conditions/DataModelConditionEventEntity.cs +++ b/src/Artemis.Storage/Entities/Profile/Conditions/DataModelConditionEventEntity.cs @@ -1,4 +1,5 @@ -using Artemis.Storage.Entities.Profile.Abstract; +using System.Collections.Generic; +using Artemis.Storage.Entities.Profile.Abstract; namespace Artemis.Storage.Entities.Profile.Conditions { @@ -6,7 +7,7 @@ namespace Artemis.Storage.Entities.Profile.Conditions { public DataModelConditionEventEntity() { - + Children = new List(); } public DataModelPathEntity EventPath { get; set; } diff --git a/src/Artemis.Storage/Entities/Profile/Conditions/DataModelConditionEventPredicateEntity.cs b/src/Artemis.Storage/Entities/Profile/Conditions/DataModelConditionEventPredicateEntity.cs new file mode 100644 index 000000000..fee134489 --- /dev/null +++ b/src/Artemis.Storage/Entities/Profile/Conditions/DataModelConditionEventPredicateEntity.cs @@ -0,0 +1,6 @@ +namespace Artemis.Storage.Entities.Profile.Conditions +{ + public class DataModelConditionEventPredicateEntity : DataModelConditionPredicateEntity + { + } +} \ No newline at end of file diff --git a/src/Artemis.Storage/Entities/Profile/DataModelPathEntity.cs b/src/Artemis.Storage/Entities/Profile/DataModelPathEntity.cs index b1e9a3241..b4a2b03b5 100644 --- a/src/Artemis.Storage/Entities/Profile/DataModelPathEntity.cs +++ b/src/Artemis.Storage/Entities/Profile/DataModelPathEntity.cs @@ -6,5 +6,14 @@ namespace Artemis.Storage.Entities.Profile { public string Path { get; set; } public Guid? DataModelGuid { get; set; } + + public PathWrapperType WrapperType { get; set; } + } + + public enum PathWrapperType + { + None, + List, + Event } } \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj.DotSettings b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj.DotSettings index 82d8ff190..1292ea906 100644 --- a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj.DotSettings +++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj.DotSettings @@ -7,6 +7,7 @@ True True True + True True True True diff --git a/src/Artemis.UI.Shared/Extensions/DataModelWrapperExtensions.cs b/src/Artemis.UI.Shared/Extensions/DataModelWrapperExtensions.cs new file mode 100644 index 000000000..fe4b6b2e8 --- /dev/null +++ b/src/Artemis.UI.Shared/Extensions/DataModelWrapperExtensions.cs @@ -0,0 +1,17 @@ +using Artemis.Core; + +namespace Artemis.UI.Shared +{ + public static class DataModelWrapperExtensions + { + public static DataModelPropertiesViewModel CreateViewModel(this EventPredicateWrapperDataModel wrapper) + { + return new DataModelPropertiesViewModel(wrapper, null, new DataModelPath(wrapper)); + } + + public static DataModelPropertiesViewModel CreateViewModel(this ListPredicateWrapperDataModel wrapper) + { + return new DataModelPropertiesViewModel(wrapper, null, new DataModelPath(wrapper)); + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Ninject/Factories/IVMFactory.cs b/src/Artemis.UI/Ninject/Factories/IVMFactory.cs index d0bfc092b..28a691220 100644 --- a/src/Artemis.UI/Ninject/Factories/IVMFactory.cs +++ b/src/Artemis.UI/Ninject/Factories/IVMFactory.cs @@ -65,11 +65,12 @@ namespace Artemis.UI.Ninject.Factories public interface IDataModelConditionsVmFactory : IVmFactory { - DataModelConditionGroupViewModel DataModelConditionGroupViewModel(DataModelConditionGroup dataModelConditionGroup, bool isListGroup); + DataModelConditionGroupViewModel DataModelConditionGroupViewModel(DataModelConditionGroup dataModelConditionGroup, ConditionGroupType groupType); DataModelConditionListViewModel DataModelConditionListViewModel(DataModelConditionList dataModelConditionList); DataModelConditionEventViewModel DataModelConditionEventViewModel(DataModelConditionEvent dataModelConditionEvent); DataModelConditionGeneralPredicateViewModel DataModelConditionGeneralPredicateViewModel(DataModelConditionGeneralPredicate dataModelConditionGeneralPredicate); DataModelConditionListPredicateViewModel DataModelConditionListPredicateViewModel(DataModelConditionListPredicate dataModelConditionListPredicate); + DataModelConditionEventPredicateViewModel DataModelConditionEventPredicateViewModel(DataModelConditionEventPredicate dataModelConditionEventPredicate); } public interface ILayerPropertyVmFactory : IVmFactory diff --git a/src/Artemis.UI/Screens/ProfileEditor/Conditions/DataModelConditionEventView.xaml b/src/Artemis.UI/Screens/ProfileEditor/Conditions/DataModelConditionEventView.xaml index 6c33a5b79..83b9d75c6 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Conditions/DataModelConditionEventView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Conditions/DataModelConditionEventView.xaml @@ -1,12 +1,12 @@  @@ -21,9 +21,10 @@ + - + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionEventPredicateView.xaml.cs b/src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionEventPredicateView.xaml.cs new file mode 100644 index 000000000..5ce43cf28 --- /dev/null +++ b/src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionEventPredicateView.xaml.cs @@ -0,0 +1,26 @@ +using System.Windows; +using System.Windows.Controls; + +namespace Artemis.UI.Screens.ProfileEditor.Conditions +{ + /// + /// Interaction logic for DataModelConditionEventPredicateView.xaml + /// + public partial class DataModelConditionEventPredicateView : UserControl + { + public DataModelConditionEventPredicateView() + { + InitializeComponent(); + } + + private void PropertyButton_OnClick(object sender, RoutedEventArgs e) + { + // DataContext is not set when using left button, I don't know why but there it is + if (sender is Button button && button.ContextMenu != null) + { + button.ContextMenu.DataContext = button.DataContext; + button.ContextMenu.IsOpen = true; + } + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionEventPredicateViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionEventPredicateViewModel.cs new file mode 100644 index 000000000..3b44342fd --- /dev/null +++ b/src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionEventPredicateViewModel.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Media; +using Artemis.Core; +using Artemis.Core.Services; +using Artemis.UI.Shared; +using Artemis.UI.Shared.Services; + +namespace Artemis.UI.Screens.ProfileEditor.Conditions +{ + public class DataModelConditionEventPredicateViewModel : DataModelConditionPredicateViewModel + { + private readonly IDataModelUIService _dataModelUIService; + private readonly IProfileEditorService _profileEditorService; + + public DataModelConditionEventPredicateViewModel(DataModelConditionEventPredicate dataModelConditionEventPredicate, + IProfileEditorService profileEditorService, + IDataModelUIService dataModelUIService, + IConditionOperatorService conditionOperatorService, + ISettingsService settingsService) + : base(dataModelConditionEventPredicate, profileEditorService, dataModelUIService, conditionOperatorService, settingsService) + { + _profileEditorService = profileEditorService; + _dataModelUIService = dataModelUIService; + + LeftSideColor = new SolidColorBrush(Color.FromRgb(185, 164, 10)); + Initialize(); + } + + public DataModelConditionEventPredicate DataModelConditionEventPredicate => (DataModelConditionEventPredicate) Model; + + public override void Initialize() + { + base.Initialize(); + + DataModelPropertiesViewModel eventDataModel = GetEventDataModel(); + LeftSideSelectionViewModel.ChangeDataModel(eventDataModel); + } + + protected override List GetSupportedInputTypes() + { + IReadOnlyCollection editors = _dataModelUIService.RegisteredDataModelEditors; + List supportedInputTypes = editors.Select(e => e.SupportedType).ToList(); + supportedInputTypes.AddRange(editors.Where(e => e.CompatibleConversionTypes != null).SelectMany(e => e.CompatibleConversionTypes)); + + return supportedInputTypes; + } + + protected override Type GetLeftSideType() + { + return LeftSideSelectionViewModel.DataModelPath?.GetPropertyType(); + } + + protected override List GetExtraRightSideDataModelViewModels() + { + return new List {GetEventDataModel()}; + } + + private DataModelPropertiesViewModel GetEventDataModel() + { + EventPredicateWrapperDataModel wrapper = EventPredicateWrapperDataModel.Create( + DataModelConditionEventPredicate.DataModelConditionEvent.EventArgumentType + ); + + return wrapper.CreateViewModel(); + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionListPredicateView.xaml b/src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionListPredicateView.xaml index 7b6ba3bb8..d5629fec7 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionListPredicateView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Conditions/Predicate/DataModelConditionListPredicateView.xaml @@ -5,7 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:s="https://github.com/canton7/Stylet" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" - xmlns:converters="clr-namespace:Artemis.UI.Converters" xmlns:utilities="clr-namespace:Artemis.UI.Utilities" xmlns:DataModelConditions="clr-namespace:Artemis.UI.Screens.ProfileEditor.Conditions" x:Class="Artemis.UI.Screens.ProfileEditor.Conditions.DataModelConditionListPredicateView" @@ -17,16 +16,7 @@ - - - - - - - - - diff --git a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs index b5f75e0c9..43a47f107 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/DisplayConditions/DisplayConditionsViewModel.cs @@ -86,7 +86,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions if (e.RenderProfileElement.DisplayCondition == null) e.RenderProfileElement.DisplayCondition = new DataModelConditionGroup(null); - ActiveItem = _dataModelConditionsVmFactory.DataModelConditionGroupViewModel(e.RenderProfileElement.DisplayCondition, false); + ActiveItem = _dataModelConditionsVmFactory.DataModelConditionGroupViewModel(e.RenderProfileElement.DisplayCondition, ConditionGroupType.General); ActiveItem.IsRootGroup = true; ActiveItem.Update(); diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/DataBindingConditionViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/DataBindingConditionViewModel.cs index 89b2a4e96..345a67a83 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/DataBindingConditionViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/ConditionalDataBinding/DataBindingConditionViewModel.cs @@ -22,7 +22,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio _profileEditorService = profileEditorService; DataBindingCondition = dataBindingCondition; - ActiveItem = dataModelConditionsVmFactory.DataModelConditionGroupViewModel(DataBindingCondition.Condition, false); + ActiveItem = dataModelConditionsVmFactory.DataModelConditionGroupViewModel(DataBindingCondition.Condition, ConditionGroupType.General); ActiveItem.IsRootGroup = true; ActiveItem.Update(); ActiveItem.Updated += ActiveItemOnUpdated;