mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
WIP on layer properties window
This commit is contained in:
parent
99e9620db2
commit
9c32bb6ce6
@ -411,6 +411,7 @@
|
||||
<Compile Include="Modules\Games\RocketLeague\RocketLeagueViewModel.cs" />
|
||||
<Compile Include="Modules\Games\Witcher3\Witcher3ViewModel.cs" />
|
||||
<Compile Include="ViewModels\LayerEditorViewModel.cs" />
|
||||
<Compile Include="ViewModels\LayerEditor\LayerConditionViewModel.cs" />
|
||||
<Compile Include="ViewModels\OverlaysViewModel.cs" />
|
||||
<Compile Include="Modules\Overlays\VolumeDisplay\VolumeDisplayViewModel.cs" />
|
||||
<Compile Include="ViewModels\ProfileEditorViewModel.cs" />
|
||||
@ -453,6 +454,9 @@
|
||||
<Compile Include="Views\LayerEditorView.xaml.cs">
|
||||
<DependentUpon>LayerEditorView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\LayerEditor\LayerConditionView.xaml.cs">
|
||||
<DependentUpon>LayerConditionView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\OverlaysView.xaml.cs">
|
||||
<DependentUpon>OverlaysView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@ -606,6 +610,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\LayerEditor\LayerConditionView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\OverlaysView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Artemis.Models.Interfaces;
|
||||
using System;
|
||||
using Artemis.Models.Interfaces;
|
||||
|
||||
namespace Artemis.Modules.Games.TheDivision
|
||||
{
|
||||
@ -20,6 +21,7 @@ namespace Artemis.Modules.Games.TheDivision
|
||||
public TestTest TestyTest { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class TestTest
|
||||
{
|
||||
public string TestS { get; set; }
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Principal;
|
||||
using System.Windows;
|
||||
@ -53,33 +54,45 @@ namespace Artemis.Utilities
|
||||
}
|
||||
}
|
||||
|
||||
public static List<PropertyCollection> GetPropertyMap(object o)
|
||||
{
|
||||
var res = new List<PropertyCollection>();
|
||||
// No point reinventing the wheel, just serialize it to JSON and parse that
|
||||
var json = JObject.FromObject(o, JsonSerializer.CreateDefault());
|
||||
res.AddRange(JObjectToPropertyCollection(json));
|
||||
public static List<PropertyCollection> GenerateTypeMap(object o) => GenerateTypeMap(o.GetType().GetProperties());
|
||||
public static List<PropertyCollection> GenerateTypeMap<T>() => GenerateTypeMap(typeof (T).GetProperties());
|
||||
|
||||
return res;
|
||||
private static List<PropertyCollection> GenerateTypeMap(IEnumerable<PropertyInfo> getProperties,
|
||||
string path = "")
|
||||
{
|
||||
var list = new List<PropertyCollection>();
|
||||
foreach (var propertyInfo in getProperties)
|
||||
{
|
||||
var parent = new PropertyCollection
|
||||
{
|
||||
Type = propertyInfo.PropertyType.Name,
|
||||
Display = $"{path.Replace(".", " → ")}{propertyInfo.Name}",
|
||||
Path = $"{path}{propertyInfo.Name}"
|
||||
};
|
||||
|
||||
if (propertyInfo.PropertyType.BaseType?.Name == "Enum")
|
||||
{
|
||||
parent.EnumValues = Enum.GetNames(propertyInfo.PropertyType);
|
||||
parent.Type = "Enum";
|
||||
}
|
||||
|
||||
private static List<PropertyCollection> JObjectToPropertyCollection(JObject json)
|
||||
{
|
||||
var res = new List<PropertyCollection>();
|
||||
foreach (var property in json.Properties())
|
||||
{
|
||||
var parent = new PropertyCollection {Name = property.Name};
|
||||
foreach (var child in property.Children<JObject>())
|
||||
parent.Children = JObjectToPropertyCollection(child);
|
||||
|
||||
res.Add(parent);
|
||||
list.Add(parent);
|
||||
list.AddRange(GenerateTypeMap(propertyInfo.PropertyType.GetProperties(), path + $"{propertyInfo.Name}."));
|
||||
}
|
||||
return res;
|
||||
return list;
|
||||
}
|
||||
|
||||
public struct PropertyCollection
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Display { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only used if Type is an enumerable
|
||||
/// </summary>
|
||||
public string[] EnumValues { get; set; }
|
||||
|
||||
public List<PropertyCollection> Children { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,100 @@
|
||||
using System.Linq;
|
||||
using Artemis.Models.Profiles;
|
||||
using Artemis.Utilities;
|
||||
using Caliburn.Micro;
|
||||
|
||||
namespace Artemis.ViewModels.LayerEditor
|
||||
{
|
||||
public class LayerConditionViewModel<T> : Screen
|
||||
{
|
||||
private readonly LayerEditorViewModel<T> _conditionModel;
|
||||
private GeneralHelpers.PropertyCollection _selectedDataModelProp;
|
||||
private string _selectedOperator;
|
||||
private bool _userValueIsVisible;
|
||||
|
||||
public LayerConditionViewModel(LayerEditorViewModel<T> conditionModel, LayerConditionModel layerConditionModel,
|
||||
BindableCollection<GeneralHelpers.PropertyCollection> dataModelProps)
|
||||
{
|
||||
_conditionModel = conditionModel;
|
||||
|
||||
LayerConditionModel = layerConditionModel;
|
||||
DataModelProps = dataModelProps;
|
||||
Operators = new BindableCollection<string>();
|
||||
}
|
||||
|
||||
public LayerConditionModel LayerConditionModel { get; set; }
|
||||
public BindableCollection<GeneralHelpers.PropertyCollection> DataModelProps { get; set; }
|
||||
public BindableCollection<string> Operators { get; set; }
|
||||
|
||||
public GeneralHelpers.PropertyCollection SelectedDataModelProp
|
||||
{
|
||||
get { return _selectedDataModelProp; }
|
||||
set
|
||||
{
|
||||
if (value.Equals(_selectedDataModelProp)) return;
|
||||
_selectedDataModelProp = value;
|
||||
OnSelectedItemChangedAction(_selectedDataModelProp);
|
||||
NotifyOfPropertyChange(() => SelectedDataModelProp);
|
||||
}
|
||||
}
|
||||
|
||||
public string SelectedOperator
|
||||
{
|
||||
get { return _selectedOperator; }
|
||||
set
|
||||
{
|
||||
if (value == _selectedOperator) return;
|
||||
_selectedOperator = value;
|
||||
NotifyOfPropertyChange(() => SelectedOperator);
|
||||
}
|
||||
}
|
||||
|
||||
public bool UserValueIsVisible
|
||||
{
|
||||
get { return _userValueIsVisible; }
|
||||
set
|
||||
{
|
||||
if (value == _userValueIsVisible) return;
|
||||
_userValueIsVisible = value;
|
||||
NotifyOfPropertyChange(() => UserValueIsVisible);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSelectedItemChangedAction(GeneralHelpers.PropertyCollection prop)
|
||||
{
|
||||
Operators.Clear();
|
||||
if (prop.EnumValues != null)
|
||||
{
|
||||
Operators.AddRange(prop.EnumValues);
|
||||
UserValueIsVisible = false;
|
||||
}
|
||||
else
|
||||
switch (prop.Type)
|
||||
{
|
||||
case "Int32":
|
||||
Operators.AddRange(new[]
|
||||
{
|
||||
"Lower than", "Lower or equal to", "Higher than", "Higher or equal to", "Equal to",
|
||||
"Not equal to"
|
||||
});
|
||||
UserValueIsVisible = true;
|
||||
break;
|
||||
case "Boolean":
|
||||
Operators.AddRange(new[] {"False", "True"});
|
||||
UserValueIsVisible = false;
|
||||
break;
|
||||
default:
|
||||
Operators.AddRange(new[] {"Equal to", "Not equal to"});
|
||||
UserValueIsVisible = true;
|
||||
break;
|
||||
}
|
||||
|
||||
SelectedOperator = Operators.First();
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
_conditionModel.DeleteCondition(this, LayerConditionModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using Artemis.Models.Profiles;
|
||||
using Artemis.Utilities;
|
||||
using Artemis.ViewModels.LayerEditor;
|
||||
using Caliburn.Micro;
|
||||
|
||||
namespace Artemis.ViewModels
|
||||
@ -15,13 +13,19 @@ namespace Artemis.ViewModels
|
||||
public LayerEditorViewModel(LayerModel layer)
|
||||
{
|
||||
Layer = layer;
|
||||
|
||||
DataModelProps = new BindableCollection<GeneralHelpers.PropertyCollection>();
|
||||
DataModelProps.AddRange(GeneralHelpers.GetPropertyMap((T)Activator.CreateInstance(typeof(T), new object[] { })));
|
||||
DataModelProps.AddRange(GeneralHelpers.GenerateTypeMap<T>());
|
||||
|
||||
LayerConditionVms =
|
||||
new BindableCollection<LayerConditionViewModel<T>>(
|
||||
layer.LayerConditions.Select(c => new LayerConditionViewModel<T>(this, c, DataModelProps)));
|
||||
|
||||
ProposedProperties = new LayerPropertiesModel();
|
||||
GeneralHelpers.CopyProperties(ProposedProperties, Layer.LayerUserProperties);
|
||||
}
|
||||
|
||||
public BindableCollection<LayerConditionViewModel<T>> LayerConditionVms { get; set; }
|
||||
|
||||
public LayerModel Layer
|
||||
{
|
||||
get { return _layer; }
|
||||
@ -37,9 +41,22 @@ namespace Artemis.ViewModels
|
||||
|
||||
public LayerPropertiesModel ProposedProperties { get; set; }
|
||||
|
||||
public void AddCondition()
|
||||
{
|
||||
var condition = new LayerConditionModel();
|
||||
Layer.LayerConditions.Add(condition);
|
||||
LayerConditionVms.Add(new LayerConditionViewModel<T>(this, condition, DataModelProps));
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
GeneralHelpers.CopyProperties(Layer.LayerUserProperties, ProposedProperties);
|
||||
}
|
||||
|
||||
public void DeleteCondition(LayerConditionViewModel<T> layerConditionViewModel, LayerConditionModel layerConditionModel)
|
||||
{
|
||||
LayerConditionVms.Remove(layerConditionViewModel);
|
||||
Layer.LayerConditions.Remove(layerConditionModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Artemis/Artemis/Views/LayerEditor/LayerConditionView.xaml
Normal file
41
Artemis/Artemis/Views/LayerEditor/LayerConditionView.xaml
Normal file
@ -0,0 +1,41 @@
|
||||
<UserControl x:Class="Artemis.Views.LayerEditor.LayerConditionView"
|
||||
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.Views.LayerEditor"
|
||||
xmlns:cal="http://www.caliburnproject.org"
|
||||
xmlns:utilities="clr-namespace:Artemis.Utilities"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="132.061" d:DesignWidth="632.296">
|
||||
<Grid Margin="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="30" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="120" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<!-- Left -->
|
||||
<ComboBox x:Name="DataModelProps" Grid.Column="0" Width="250" MaxDropDownHeight="125"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Top" DisplayMemberPath="Display" />
|
||||
|
||||
<!-- Center -->
|
||||
<TextBlock Grid.Column="1" Text="is" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,3,0,0" />
|
||||
<ComboBox x:Name="Operators" Grid.Column="2" Width="150" MaxDropDownHeight="125" HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top" Margin="0,0,20,0" />
|
||||
|
||||
<!-- Right -->
|
||||
<Grid Grid.Column="3">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0" x:Name="UserValueIsVisible">
|
||||
<TextBox x:Name="UserValue" VerticalAlignment="Top" />
|
||||
</StackPanel>
|
||||
<Button Grid.Row="1" x:Name="Delete" Content="Delete condition" VerticalAlignment="Bottom" Width="100"
|
||||
Style="{DynamicResource SquareButtonStyle}" HorizontalAlignment="Right" />
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
28
Artemis/Artemis/Views/LayerEditor/LayerConditionView.xaml.cs
Normal file
28
Artemis/Artemis/Views/LayerEditor/LayerConditionView.xaml.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Artemis.Views.LayerEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LayerConditionView.xaml
|
||||
/// </summary>
|
||||
public partial class LayerConditionView : UserControl
|
||||
{
|
||||
public LayerConditionView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,56 +7,26 @@
|
||||
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
|
||||
xmlns:cal="http://www.caliburnproject.org"
|
||||
mc:Ignorable="d"
|
||||
Title="Artemis | Edit Layer" Height="400" Width="600"
|
||||
GlowBrush="{DynamicResource AccentColorBrush}" Icon="../logo.ico">
|
||||
Title="Artemis | Edit Layer" Height="800" Width="630"
|
||||
GlowBrush="{DynamicResource AccentColorBrush}" Icon="../logo.ico" ResizeMode="NoResize">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="10" FontSize="16" Text="Display if.." />
|
||||
<ListBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
|
||||
<ListBoxItem Margin="10, 0, 10, 0" Padding="10">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<!-- Left -->
|
||||
<Border BorderThickness="1" BorderBrush="{DynamicResource GrayBrush6}">
|
||||
<TreeView x:Name="ProfileTree" ItemsSource="{Binding Path=DataModelProps}" Width="200"
|
||||
Height="100">
|
||||
<TreeView.ItemTemplate>
|
||||
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.ItemTemplate>
|
||||
</TreeView>
|
||||
</Border>
|
||||
|
||||
<!-- Center -->
|
||||
<TextBlock Grid.Column="1" Text="is" VerticalAlignment="Top" HorizontalAlignment="Center"
|
||||
Margin="0,3,0,0" />
|
||||
<ComboBox Grid.Column="2" Width="60" IsEditable="True" MaxDropDownHeight="125"
|
||||
Style="{DynamicResource VirtualisedMetroComboBox}" HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top" ItemsSource="{Binding Path=DataModelProps}" />
|
||||
<TextBlock Grid.Column="3" Text="than" VerticalAlignment="Top" HorizontalAlignment="Center"
|
||||
Margin="0,3,0,0" />
|
||||
|
||||
<!-- Right -->
|
||||
<TextBox Grid.Column="4" Width="200" VerticalAlignment="Top" />
|
||||
<ListBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" x:Name="LayerConditionVms" />
|
||||
<Button Grid.Row="2" Grid.Column="0" x:Name="AddCondition" Content="Add condition" VerticalAlignment="Top"
|
||||
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Left" Margin="10" />
|
||||
<Button Grid.Row="3" Grid.Column="0" x:Name="Apply" Content="Apply" VerticalAlignment="Bottom"
|
||||
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Left" Margin="10" />
|
||||
</Grid>
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
|
||||
</Grid>
|
||||
</controls:MetroWindow>
|
||||
Loading…
x
Reference in New Issue
Block a user