mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Plugins - Implemented features enable/disable UI
This commit is contained in:
1 parent
e812929215
commit
c146479393
38 files changed
+571
-164
No files matched your search
@@ -4,7 +4,7 @@ using Microsoft.Xaml.Behaviors;
|
||||
|
||||
namespace Artemis.UI.Shared
|
||||
{
|
||||
public class PutCursorAtEndTextBoxBehavior : Behavior<UIElement>
|
||||
public class PutCursorAtEndTextBox : Behavior<UIElement>
|
||||
{
|
||||
private TextBox _textBox;
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Microsoft.Xaml.Behaviors;
|
||||
|
||||
namespace Artemis.UI.Shared
|
||||
{
|
||||
public class ScrollParentWhenAtMax : Behavior<FrameworkElement>
|
||||
{
|
||||
protected override void OnAttached()
|
||||
{
|
||||
base.OnAttached();
|
||||
AssociatedObject.PreviewMouseWheel += PreviewMouseWheel;
|
||||
}
|
||||
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
AssociatedObject.PreviewMouseWheel -= PreviewMouseWheel;
|
||||
base.OnDetaching();
|
||||
}
|
||||
|
||||
private void PreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
||||
{
|
||||
ScrollViewer scrollViewer = GetVisualChild<ScrollViewer>(AssociatedObject);
|
||||
double scrollPos = scrollViewer.ContentVerticalOffset;
|
||||
if (scrollPos == scrollViewer.ScrollableHeight && e.Delta < 0
|
||||
|| scrollPos == 0 && e.Delta > 0)
|
||||
{
|
||||
e.Handled = true;
|
||||
MouseWheelEventArgs e2 = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
|
||||
e2.RoutedEvent = UIElement.MouseWheelEvent;
|
||||
AssociatedObject.RaiseEvent(e2);
|
||||
}
|
||||
}
|
||||
|
||||
private static T GetVisualChild<T>(DependencyObject parent) where T : Visual
|
||||
{
|
||||
T child = default;
|
||||
|
||||
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
|
||||
for (int i = 0; i < numVisuals; i++)
|
||||
{
|
||||
Visual v = (Visual) VisualTreeHelper.GetChild(parent, i);
|
||||
child = v as T;
|
||||
if (child == null) child = GetVisualChild<T>(v);
|
||||
if (child != null) break;
|
||||
}
|
||||
|
||||
return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core;
|
||||
using SkiaSharp;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Shared
|
||||
{
|
||||
@@ -14,13 +14,13 @@ namespace Artemis.UI.Shared
|
||||
/// Converts <see cref="T:Artemis.Core.Models.Profile.ColorGradient" /> into a
|
||||
/// <see cref="T:System.Windows.Media.GradientStopCollection" />.
|
||||
/// </summary>
|
||||
[ValueConversion(typeof(BindableCollection<ColorGradientStop>), typeof(GradientStopCollection))]
|
||||
[ValueConversion(typeof(List<ColorGradientStop>), typeof(GradientStopCollection))]
|
||||
public class ColorGradientToGradientStopsConverter : IValueConverter
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
BindableCollection<ColorGradientStop> colorGradients = (BindableCollection<ColorGradientStop>) value;
|
||||
List<ColorGradientStop> colorGradients = (List<ColorGradientStop>) value;
|
||||
GradientStopCollection collection = new GradientStopCollection();
|
||||
if (colorGradients == null)
|
||||
return collection;
|
||||
@@ -34,7 +34,7 @@ namespace Artemis.UI.Shared
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
GradientStopCollection collection = (GradientStopCollection) value;
|
||||
BindableCollection<ColorGradientStop> colorGradients = new BindableCollection<ColorGradientStop>();
|
||||
List<ColorGradientStop> colorGradients = new List<ColorGradientStop>();
|
||||
if (collection == null)
|
||||
return colorGradients;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Artemis.UI.Shared.Services
|
||||
public DataModelPropertiesViewModel GetMainDataModelVisualization()
|
||||
{
|
||||
DataModelPropertiesViewModel viewModel = new DataModelPropertiesViewModel(null, null, null);
|
||||
foreach (DataModel dataModelExpansion in _dataModelService.GetDataModels())
|
||||
foreach (DataModel dataModelExpansion in _dataModelService.GetDataModels().OrderBy(d => d.DataModelDescription.Name))
|
||||
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModelExpansion, viewModel, new DataModelPath(dataModelExpansion)));
|
||||
|
||||
// Update to populate children
|
||||
@@ -42,6 +42,25 @@ namespace Artemis.UI.Shared.Services
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public void UpdateModules(DataModelPropertiesViewModel mainDataModelVisualization)
|
||||
{
|
||||
List<DataModelVisualizationViewModel> disabledChildren = mainDataModelVisualization.Children.Where(d => !d.DataModel.Feature.IsEnabled).ToList();
|
||||
foreach (DataModelVisualizationViewModel child in disabledChildren)
|
||||
mainDataModelVisualization.Children.Remove(child);
|
||||
|
||||
foreach (DataModel dataModelExpansion in _dataModelService.GetDataModels().OrderBy(d => d.DataModelDescription.Name))
|
||||
{
|
||||
if (mainDataModelVisualization.Children.All(c => c.DataModel != dataModelExpansion))
|
||||
{
|
||||
mainDataModelVisualization.Children.Add(
|
||||
new DataModelPropertiesViewModel(dataModelExpansion, mainDataModelVisualization, new DataModelPath(dataModelExpansion))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mainDataModelVisualization.Update(this, null);
|
||||
}
|
||||
|
||||
public DataModelPropertiesViewModel GetPluginDataModelVisualization(PluginFeature pluginFeature, bool includeMainDataModel)
|
||||
{
|
||||
if (includeMainDataModel)
|
||||
@@ -64,7 +83,7 @@ namespace Artemis.UI.Shared.Services
|
||||
return null;
|
||||
|
||||
DataModelPropertiesViewModel viewModel = new DataModelPropertiesViewModel(null, null, null);
|
||||
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModel, viewModel, null));
|
||||
viewModel.Children.Add(new DataModelPropertiesViewModel(dataModel, viewModel, new DataModelPath(dataModel)));
|
||||
|
||||
// Update to populate children
|
||||
viewModel.Update(this, null);
|
||||
|
||||
@@ -7,22 +7,114 @@ using Artemis.UI.Shared.Input;
|
||||
|
||||
namespace Artemis.UI.Shared.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// A service for UI related data model tasks
|
||||
/// </summary>
|
||||
public interface IDataModelUIService : IArtemisSharedUIService
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a read-only list of all registered data model editors
|
||||
/// </summary>
|
||||
IReadOnlyCollection<DataModelVisualizationRegistration> RegisteredDataModelEditors { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only list of all registered data model displays
|
||||
/// </summary>
|
||||
IReadOnlyCollection<DataModelVisualizationRegistration> RegisteredDataModelDisplays { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a data model visualization view model for the main data model
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A data model visualization view model containing all data model expansions and modules that expand the main
|
||||
/// data model
|
||||
/// </returns>
|
||||
DataModelPropertiesViewModel GetMainDataModelVisualization();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a data model visualization view model for the data model of the provided plugin feature
|
||||
/// </summary>
|
||||
/// <param name="pluginFeature">The plugin feature to create hte data model visualization view model for</param>
|
||||
/// <param name="includeMainDataModel">Whether or not also to include the main data model</param>
|
||||
/// <returns>A data model visualization view model containing the data model of the provided feature</returns>
|
||||
DataModelPropertiesViewModel GetPluginDataModelVisualization(PluginFeature pluginFeature, bool includeMainDataModel);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the children of the provided main data model visualization, removing disabled children and adding newly
|
||||
/// enabled children
|
||||
/// </summary>
|
||||
void UpdateModules(DataModelPropertiesViewModel mainDataModelVisualization);
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new data model editor
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the editor</typeparam>
|
||||
/// <param name="plugin">The plugin this editor belongs to</param>
|
||||
/// <param name="compatibleConversionTypes">A collection of extra types this editor supports</param>
|
||||
/// <returns>A registration that can be used to remove the editor</returns>
|
||||
DataModelVisualizationRegistration RegisterDataModelInput<T>(Plugin plugin, IReadOnlyCollection<Type> compatibleConversionTypes) where T : DataModelInputViewModel;
|
||||
|
||||
/// <summary>
|
||||
/// Registers a new data model display
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the display</typeparam>
|
||||
/// <param name="plugin">The plugin this display belongs to</param>
|
||||
/// <returns>A registration that can be used to remove the display</returns>
|
||||
DataModelVisualizationRegistration RegisterDataModelDisplay<T>(Plugin plugin) where T : DataModelDisplayViewModel;
|
||||
|
||||
/// <summary>
|
||||
/// Removes a data model editor
|
||||
/// </summary>
|
||||
/// <param name="registration">
|
||||
/// The registration of the editor as returned by <see cref="RegisterDataModelInput{T}" />
|
||||
/// </param>
|
||||
void RemoveDataModelInput(DataModelVisualizationRegistration registration);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a data model display
|
||||
/// </summary>
|
||||
/// <param name="registration">
|
||||
/// The registration of the display as returned by <see cref="RegisterDataModelDisplay{T}" />
|
||||
/// </param>
|
||||
void RemoveDataModelDisplay(DataModelVisualizationRegistration registration);
|
||||
|
||||
/// <summary>
|
||||
/// Creates the most appropriate display view model for the provided <paramref name="propertyType" /> that can display
|
||||
/// a value
|
||||
/// </summary>
|
||||
/// <param name="propertyType">The type of data model property to find a display view model for</param>
|
||||
/// <param name="description">The description of the data model property</param>
|
||||
/// <param name="fallBackToDefault">
|
||||
/// If <see langword="true"></see>, a simple .ToString() display view model will be
|
||||
/// returned if nothing else is found
|
||||
/// </param>
|
||||
/// <returns>The most appropriate display view model for the provided <paramref name="propertyType"></paramref></returns>
|
||||
DataModelDisplayViewModel GetDataModelDisplayViewModel(Type propertyType, DataModelPropertyAttribute description, bool fallBackToDefault = false);
|
||||
|
||||
/// <summary>
|
||||
/// Creates the most appropriate input view model for the provided <paramref name="propertyType" /> that allows
|
||||
/// inputting a value
|
||||
/// </summary>
|
||||
/// <param name="propertyType">The type of data model property to find a display view model for</param>
|
||||
/// <param name="description">The description of the data model property</param>
|
||||
/// <param name="initialValue">The initial value to show in the input</param>
|
||||
/// <param name="updateCallback">A function to call whenever the input was updated (submitted or not)</param>
|
||||
/// <returns>The most appropriate input view model for the provided <paramref name="propertyType" /></returns>
|
||||
DataModelInputViewModel GetDataModelInputViewModel(Type propertyType, DataModelPropertyAttribute description, object initialValue, Action<object, bool> updateCallback);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a view model that allows selecting a value from the data model
|
||||
/// </summary>
|
||||
/// <param name="module"></param>
|
||||
/// <returns>A view model that allows selecting a value from the data model</returns>
|
||||
DataModelDynamicViewModel GetDynamicSelectionViewModel(Module module);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a view model that allows entering a value matching the target data model type
|
||||
/// </summary>
|
||||
/// <param name="targetType">The type of data model property to allow input for</param>
|
||||
/// <param name="targetDescription">The description of the target data model property</param>
|
||||
/// <returns>A view model that allows entering a value matching the target data model type</returns>
|
||||
DataModelStaticViewModel GetStaticInputViewModel(Type targetType, DataModelPropertyAttribute targetDescription);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user