mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Data model conditions - Moved events into a separate 'mode'
This commit is contained in:
1 parent
e1eb03667e
commit
997ab005d8
26 files changed
+331
-128
No files matched your search
-14
@@ -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<>);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-17
@@ -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();
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
+25
-20
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
|
||||
DataModelConditionEventPredicate.DataModelConditionEvent.EventArgumentType
|
||||
);
|
||||
|
||||
return wrapper.CreateViewModel(_dataModelUIService);
|
||||
return wrapper.CreateViewModel(_dataModelUIService, new DataModelUpdateConfiguration(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
-7
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
|
||||
DataModelConditionListPredicate.DataModelConditionList.ListType
|
||||
);
|
||||
|
||||
return wrapper.CreateViewModel(_dataModelUIService);
|
||||
return wrapper.CreateViewModel(_dataModelUIService, new DataModelUpdateConfiguration(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
{
|
||||
lock (MainDataModel)
|
||||
{
|
||||
MainDataModel.Update(_dataModelUIService);
|
||||
MainDataModel.Update(_dataModelUIService, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user