mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Data model debugger - Added module filtering
Data model debugger - Added search input (disabled & not yet implemented) Data model debugger - Finished list support
This commit is contained in:
parent
58e07ae5bd
commit
8e01d1f63e
@ -64,6 +64,15 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
public DataModel GetPluginDataModel(Plugin plugin)
|
||||
{
|
||||
if (plugin is Module module)
|
||||
return module.InternalDataModel;
|
||||
if (plugin is BaseDataModelExpansion dataModelExpansion)
|
||||
return dataModelExpansion.InternalDataModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void PluginServiceOnPluginEnabled(object sender, PluginEventArgs e)
|
||||
{
|
||||
if (e.PluginInfo.Instance is Module module && module.InternalExpandsMainDataModel)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Artemis.Core.Models;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
|
||||
namespace Artemis.Core.Services.Interfaces
|
||||
@ -19,5 +20,11 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="baseDataModelExpansion"></param>
|
||||
void RemoveExpansion(DataModel baseDataModelExpansion);
|
||||
|
||||
/// <summary>
|
||||
/// If found, returns the data model of the provided plugin
|
||||
/// </summary>
|
||||
/// <param name="plugin">Should be a module with a data model or a data model expansion</param>
|
||||
DataModel GetPluginDataModel(Plugin plugin);
|
||||
}
|
||||
}
|
||||
@ -33,7 +33,7 @@ namespace Artemis.UI.DataModelVisualization
|
||||
foreach (var item in List)
|
||||
{
|
||||
DataModelVisualizationViewModel child;
|
||||
if (Children.Count < index)
|
||||
if (Children.Count <= index)
|
||||
{
|
||||
child = CreateChild(item);
|
||||
Children.Add(child);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
|
||||
namespace Artemis.UI.DataModelVisualization
|
||||
@ -12,25 +11,13 @@ namespace Artemis.UI.DataModelVisualization
|
||||
Parent = parent;
|
||||
PropertyDescription = propertyDescription;
|
||||
}
|
||||
|
||||
public bool IsListProperty { get; set; }
|
||||
public string ListDescription { get; set; }
|
||||
public Type PropertyType { get; set; }
|
||||
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (PropertyInfo != null && Parent?.Model != null)
|
||||
{
|
||||
IsListProperty = false;
|
||||
Model = PropertyInfo.GetValue(Parent.Model);
|
||||
PropertyType = PropertyInfo.PropertyType;
|
||||
}
|
||||
else if (Parent is DataModelListViewModel listViewModel)
|
||||
{
|
||||
IsListProperty = true;
|
||||
ListDescription = $"List item [{listViewModel.List.IndexOf(Model)}]";
|
||||
PropertyType = Model.GetType();
|
||||
}
|
||||
|
||||
UpdateListStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using Humanizer;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.DataModelVisualization
|
||||
@ -45,6 +43,8 @@ namespace Artemis.UI.DataModelVisualization
|
||||
|
||||
foreach (var dataModelVisualizationViewModel in Children)
|
||||
dataModelVisualizationViewModel.Update();
|
||||
|
||||
UpdateListStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,11 +10,16 @@ namespace Artemis.UI.DataModelVisualization
|
||||
{
|
||||
public abstract class DataModelVisualizationViewModel : PropertyChangedBase
|
||||
{
|
||||
public PropertyInfo PropertyInfo { get; protected set; }
|
||||
public DataModelPropertyAttribute PropertyDescription { get; protected set; }
|
||||
public PropertyInfo PropertyInfo { get; protected set; }
|
||||
public Type PropertyType { get; set; }
|
||||
|
||||
public DataModelVisualizationViewModel Parent { get; protected set; }
|
||||
public object Model { get; set; }
|
||||
|
||||
public bool IsListProperty { get; set; }
|
||||
public string ListDescription { get; set; }
|
||||
|
||||
public abstract void Update();
|
||||
|
||||
protected DataModelVisualizationViewModel CreateChild(PropertyInfo propertyInfo)
|
||||
@ -59,5 +64,20 @@ namespace Artemis.UI.DataModelVisualization
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void UpdateListStatus()
|
||||
{
|
||||
if (Parent is DataModelListViewModel listViewModel)
|
||||
{
|
||||
IsListProperty = true;
|
||||
ListDescription = $"List item [{listViewModel.List.IndexOf(Model)}]";
|
||||
PropertyType = Model.GetType();
|
||||
}
|
||||
else
|
||||
{
|
||||
IsListProperty = false;
|
||||
PropertyType = PropertyInfo?.PropertyType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,16 +8,74 @@
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:wpf="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:plugins="clr-namespace:Artemis.Core.Plugins.Abstract;assembly=Artemis.Core"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:DataModelDebugViewModel}">
|
||||
<UserControl.Resources>
|
||||
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<TreeView ItemsSource="{Binding MainDataModel.Children}" HorizontalContentAlignment="Stretch">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="0" Margin="0 0 0 5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="0.5*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="0.5*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<!-- Property searching (nyi) -->
|
||||
<wpf:PackIcon Grid.Column="0" Kind="Search" VerticalAlignment="Center"/>
|
||||
<TextBox Grid.Column="1" wpf:HintAssist.Hint="Search property" VerticalAlignment="Center" Margin="5 0" IsEnabled="False"/>
|
||||
|
||||
<!-- Module filtering -->
|
||||
<TextBlock Grid.Column="3" VerticalAlignment="Center">Filter module</TextBlock>
|
||||
<ToggleButton Grid.Column="4"
|
||||
VerticalAlignment="Center"
|
||||
Margin="5 0"
|
||||
Style="{StaticResource MaterialDesignSwitchToggleButton}"
|
||||
IsChecked="{Binding IsModuleFilterEnabled}" />
|
||||
<ComboBox Grid.Column="5"
|
||||
VerticalAlignment="Center"
|
||||
wpf:HintAssist.Hint="Select a module"
|
||||
IsEditable="True"
|
||||
TextSearch.TextPath="DisplayName"
|
||||
Margin="5 0 0 0"
|
||||
IsEnabled="{Binding IsModuleFilterEnabled}"
|
||||
SelectedItem="{Binding SelectedModule}"
|
||||
ItemsSource="{Binding Modules}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel d:DataContext="{d:DesignInstance Type=plugins:Module}" Orientation="Horizontal">
|
||||
<wpf:PackIcon Kind="{Binding DisplayIcon}" VerticalAlignment="Center" Margin="0 0 5 0"/>
|
||||
<TextBlock Text="{Binding DisplayName}" VerticalAlignment="Center"></TextBlock>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
<TreeView Grid.Row="1" ItemsSource="{Binding MainDataModel.Children}" HorizontalContentAlignment="Stretch">
|
||||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelViewModel}" ItemsSource="{Binding Children}">
|
||||
<TextBlock Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding PropertyDescription.Name}"
|
||||
ToolTip="{Binding PropertyDescription.Description}"
|
||||
Visibility="{Binding IsListProperty, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}" />
|
||||
<Grid Visibility="{Binding IsListProperty, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
|
||||
<Run>[</Run><Run Text="{Binding PropertyType.Name, Mode=OneWay}" /><Run>]</Run>
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="1" Text="{Binding ListDescription}" ToolTip="{Binding PropertyDescription.Description}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</HierarchicalDataTemplate>
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListViewModel}" ItemsSource="{Binding Children}">
|
||||
<Grid>
|
||||
@ -30,10 +88,10 @@
|
||||
[List]
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="1" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding Count, Mode=OneWay}"
|
||||
FontFamily="Consolas"
|
||||
HorizontalAlignment="Right"/>
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding Count, Mode=OneWay}"
|
||||
FontFamily="Consolas"
|
||||
HorizontalAlignment="Right" />
|
||||
</Grid>
|
||||
</HierarchicalDataTemplate>
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelPropertyViewModel}">
|
||||
@ -47,24 +105,24 @@
|
||||
<Run>[</Run><Run Text="{Binding PropertyType.Name, Mode=OneWay}" /><Run>]</Run>
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding PropertyDescription.Name}"
|
||||
Text="{Binding PropertyDescription.Name}"
|
||||
ToolTip="{Binding PropertyDescription.Description}"
|
||||
Visibility="{Binding IsListProperty, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}"/>
|
||||
Visibility="{Binding IsListProperty, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}" />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding ListDescription}"
|
||||
Text="{Binding ListDescription}"
|
||||
ToolTip="{Binding PropertyDescription.Description}"
|
||||
Visibility="{Binding IsListProperty, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"/>
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding Model, Mode=OneWay}"
|
||||
FontFamily="Consolas"
|
||||
Visibility="{Binding IsListProperty, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding Model, Mode=OneWay}"
|
||||
FontFamily="Consolas"
|
||||
HorizontalAlignment="Right"
|
||||
Visibility="{Binding Model, Converter={StaticResource NullToVisibilityConverter}}"/>
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="null"
|
||||
FontFamily="Consolas"
|
||||
Visibility="{Binding Model, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="null"
|
||||
FontFamily="Consolas"
|
||||
HorizontalAlignment="Right"
|
||||
Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}"
|
||||
Visibility="{Binding Model, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}"/>
|
||||
Visibility="{Binding Model, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
|
||||
</Grid>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.Resources>
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
using System.Timers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Timers;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.DataModelVisualization;
|
||||
using Artemis.UI.Services;
|
||||
using Stylet;
|
||||
@ -8,11 +12,15 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
public class DataModelDebugViewModel : Screen
|
||||
{
|
||||
private readonly IDataModelVisualizationService _dataModelVisualizationService;
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly Timer _updateTimer;
|
||||
private bool _isModuleFilterEnabled;
|
||||
private Core.Plugins.Abstract.Module _selectedModule;
|
||||
|
||||
public DataModelDebugViewModel(IDataModelVisualizationService dataModelVisualizationService)
|
||||
public DataModelDebugViewModel(IDataModelVisualizationService dataModelVisualizationService, IPluginService pluginService)
|
||||
{
|
||||
_dataModelVisualizationService = dataModelVisualizationService;
|
||||
_pluginService = pluginService;
|
||||
_updateTimer = new Timer(500);
|
||||
_updateTimer.Elapsed += (sender, args) => MainDataModel.Update();
|
||||
|
||||
@ -21,15 +29,65 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
|
||||
public DataModelViewModel MainDataModel { get; set; }
|
||||
|
||||
public string PropertySearch { get; set; }
|
||||
public List<Core.Plugins.Abstract.Module> Modules { get; set; }
|
||||
|
||||
public Core.Plugins.Abstract.Module SelectedModule
|
||||
{
|
||||
get => _selectedModule;
|
||||
set
|
||||
{
|
||||
_selectedModule = value;
|
||||
GetDataModel();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsModuleFilterEnabled
|
||||
{
|
||||
get => _isModuleFilterEnabled;
|
||||
set
|
||||
{
|
||||
_isModuleFilterEnabled = value;
|
||||
|
||||
if (!IsModuleFilterEnabled)
|
||||
SelectedModule = null;
|
||||
else
|
||||
GetDataModel();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
MainDataModel = _dataModelVisualizationService.GetMainDataModelVisualization();
|
||||
GetDataModel();
|
||||
_updateTimer.Start();
|
||||
_pluginService.PluginEnabled += PluginServiceOnPluginToggled;
|
||||
_pluginService.PluginDisabled += PluginServiceOnPluginToggled;
|
||||
|
||||
PopulateModules();
|
||||
}
|
||||
|
||||
protected override void OnDeactivate()
|
||||
{
|
||||
_updateTimer.Stop();
|
||||
_pluginService.PluginEnabled -= PluginServiceOnPluginToggled;
|
||||
_pluginService.PluginDisabled -= PluginServiceOnPluginToggled;
|
||||
}
|
||||
|
||||
private void GetDataModel()
|
||||
{
|
||||
MainDataModel = SelectedModule != null
|
||||
? _dataModelVisualizationService.GetPluginDataModelVisualization(SelectedModule)
|
||||
: _dataModelVisualizationService.GetMainDataModelVisualization();
|
||||
}
|
||||
|
||||
private void PluginServiceOnPluginToggled(object? sender, PluginEventArgs e)
|
||||
{
|
||||
PopulateModules();
|
||||
}
|
||||
|
||||
private void PopulateModules()
|
||||
{
|
||||
Modules = _pluginService.GetPluginsOfType<Core.Plugins.Abstract.Module>().Where(p => p.Enabled).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.DataModelVisualization;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
|
||||
@ -17,14 +18,26 @@ namespace Artemis.UI.Services
|
||||
{
|
||||
var viewModel = new DataModelViewModel();
|
||||
foreach (var dataModelExpansion in _dataModelService.DataModelExpansions)
|
||||
viewModel.Children.Add(new DataModelViewModel(null,dataModelExpansion, dataModelExpansion.DataModelDescription, viewModel));
|
||||
viewModel.Children.Add(new DataModelViewModel(null, dataModelExpansion, dataModelExpansion.DataModelDescription, viewModel));
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public DataModelViewModel GetPluginDataModelVisualization(Plugin plugin)
|
||||
{
|
||||
var dataModel = _dataModelService.GetPluginDataModel(plugin);
|
||||
if (dataModel == null)
|
||||
return null;
|
||||
|
||||
var viewModel = new DataModelViewModel();
|
||||
viewModel.Children.Add(new DataModelViewModel(null, dataModel, dataModel.DataModelDescription, viewModel));
|
||||
return viewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IDataModelVisualizationService : IArtemisUIService
|
||||
{
|
||||
public DataModelViewModel GetMainDataModelVisualization();
|
||||
DataModelViewModel GetMainDataModelVisualization();
|
||||
DataModelViewModel GetPluginDataModelVisualization(Plugin plugin);
|
||||
}
|
||||
}
|
||||
@ -31,7 +31,6 @@ namespace Artemis.Plugins.Modules.General
|
||||
|
||||
DataModel.IntsList[0] = _rand.Next();
|
||||
DataModel.IntsList[2] = _rand.Next();
|
||||
|
||||
base.Update(deltaTime);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user