mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Datamodel - Added bool and enum support
Layer properties - Added bool support
Draggable float - Housekeeping 🙃
This commit is contained in:
parent
a3290c40f8
commit
c661b64404
@ -0,0 +1,26 @@
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class BoolLayerProperty : LayerProperty<bool>
|
||||
{
|
||||
internal BoolLayerProperty()
|
||||
{
|
||||
KeyframesSupported = false;
|
||||
DataBindingsSupported = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts an <see cref="BoolLayerProperty" /> to a <see cref="bool" />
|
||||
/// </summary>
|
||||
public static implicit operator bool(BoolLayerProperty p)
|
||||
{
|
||||
return p.CurrentValue;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateCurrentValue(float keyframeProgress, float keyframeProgressEased)
|
||||
{
|
||||
throw new ArtemisCoreException("Boolean properties do not support keyframes.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -21,6 +21,15 @@ namespace Artemis.Plugins.DataModelExpansions.TestData.DataModels
|
||||
// You can even have classes in your datamodel, just don't forget to instantiate them ;)
|
||||
[DataModelProperty(Name = "A class within the datamodel")]
|
||||
public PluginSubDataModel PluginSubDataModel { get; set; }
|
||||
|
||||
public Team Team { get; set; }
|
||||
public bool IsWinning { get; set; }
|
||||
}
|
||||
|
||||
public enum Team
|
||||
{
|
||||
Blue,
|
||||
Orange
|
||||
}
|
||||
|
||||
public class PluginSubDataModel
|
||||
|
||||
@ -141,7 +141,7 @@ namespace Artemis.UI.Shared
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
||||
stepSize = stepSize * 10;
|
||||
|
||||
var value = (float) UltimateRoundingFunction(startValue + stepSize * (x - startX), stepSize, 0.5m);
|
||||
var value = (float) RoundToNearestOf(startValue + stepSize * (x - startX), stepSize);
|
||||
if (Min != null)
|
||||
value = Math.Max(value, Min.Value);
|
||||
if (Max != null)
|
||||
@ -217,9 +217,15 @@ namespace Artemis.UI.Shared
|
||||
return float.TryParse(fullText, out _);
|
||||
}
|
||||
|
||||
private static decimal UltimateRoundingFunction(decimal amountToRound, decimal nearstOf, decimal fairness)
|
||||
/// <summary>
|
||||
/// Rounds the provided decimal to the nearest value of x with a given threshold
|
||||
/// Source: https://stackoverflow.com/a/25922075/5015269
|
||||
/// </summary>
|
||||
/// <param name="input">The value to round</param>
|
||||
/// <param name="nearestOf">The value to round down towards</param>
|
||||
private static decimal RoundToNearestOf(decimal input, decimal nearestOf)
|
||||
{
|
||||
return Math.Floor(amountToRound / nearstOf + fairness) * nearstOf;
|
||||
return Math.Floor(input / nearestOf + 0.5m) * nearestOf;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,7 +106,7 @@ namespace Artemis.UI.Shared
|
||||
if (typeViewModel != null)
|
||||
return new DataModelListPropertyViewModel(DataModel, this, PropertyInfo) {DisplayViewModel = typeViewModel};
|
||||
// For primitives, create a property view model, it may be null that is fine
|
||||
if (listType.IsPrimitive || listType == typeof(string))
|
||||
if (listType.IsPrimitive || listType.IsEnum || listType == typeof(string))
|
||||
return new DataModelListPropertyViewModel(DataModel, this, PropertyInfo) {ListType = listType};
|
||||
// For other value types create a child view model
|
||||
if (listType.IsClass || listType.IsStruct())
|
||||
|
||||
@ -169,11 +169,11 @@ namespace Artemis.UI.Shared
|
||||
IsMatchingFilteredTypes = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (looseMatch)
|
||||
IsMatchingFilteredTypes = filteredTypes.Any(t => t.IsCastableFrom(PropertyInfo.PropertyType));
|
||||
IsMatchingFilteredTypes = filteredTypes.Any(t => t.IsCastableFrom(PropertyInfo.PropertyType) || t == typeof(Enum) && PropertyInfo.PropertyType.IsEnum);
|
||||
else
|
||||
IsMatchingFilteredTypes = filteredTypes.Any(t => t == PropertyInfo.PropertyType);
|
||||
IsMatchingFilteredTypes = filteredTypes.Any(t => t == PropertyInfo.PropertyType || t == typeof(Enum) && PropertyInfo.PropertyType.IsEnum);
|
||||
}
|
||||
|
||||
public DataModelVisualizationViewModel GetChildForCondition(DisplayConditionPredicate predicate, DisplayConditionSide side)
|
||||
@ -241,7 +241,7 @@ namespace Artemis.UI.Shared
|
||||
if (typeViewModel != null)
|
||||
return new DataModelPropertyViewModel(DataModel, this, propertyInfo) {DisplayViewModel = typeViewModel, Depth = depth};
|
||||
// For primitives, create a property view model, it may be null that is fine
|
||||
if (propertyInfo.PropertyType.IsPrimitive || propertyInfo.PropertyType == typeof(string))
|
||||
if (propertyInfo.PropertyType.IsPrimitive || propertyInfo.PropertyType.IsEnum || propertyInfo.PropertyType == typeof(string))
|
||||
return new DataModelPropertyViewModel(DataModel, this, propertyInfo) {Depth = depth};
|
||||
if (typeof(IList).IsAssignableFrom(propertyInfo.PropertyType))
|
||||
return new DataModelListViewModel(DataModel, this, propertyInfo) {Depth = depth};
|
||||
|
||||
@ -179,6 +179,9 @@ namespace Artemis.UI.Shared.Services
|
||||
// Fall back on a VM that supports the type through conversion
|
||||
if (match == null)
|
||||
match = _registeredDataModelEditors.FirstOrDefault(d => d.CompatibleConversionTypes.Contains(propertyType));
|
||||
// Lastly try getting an enum VM if the provided type is an enum
|
||||
if (match == null && propertyType.IsEnum)
|
||||
match = _registeredDataModelEditors.FirstOrDefault(d => d.SupportedType == typeof(Enum));
|
||||
|
||||
if (match != null)
|
||||
{
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
<UserControl x:Class="Artemis.UI.DefaultTypes.DataModel.Input.BoolDataModelInputView"
|
||||
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.UI.DefaultTypes.DataModel.Input"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
||||
</UserControl.Resources>
|
||||
<ComboBox Width="140"
|
||||
materialDesign:ComboBoxAssist.ClassicMode="True"
|
||||
materialDesign:ValidationAssist.UsePopup="True"
|
||||
HorizontalAlignment="Left">
|
||||
<ComboBoxItem Content="True" IsSelected="{Binding InputValue}" />
|
||||
<ComboBoxItem Content="False" IsSelected="{Binding InputValue, Converter={StaticResource InverseBooleanConverter}}"/>
|
||||
</ComboBox>
|
||||
</UserControl>
|
||||
@ -0,0 +1,12 @@
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.UI.Shared;
|
||||
|
||||
namespace Artemis.UI.DefaultTypes.DataModel.Input
|
||||
{
|
||||
public class BoolDataModelInputViewModel : DataModelInputViewModel<bool>
|
||||
{
|
||||
public BoolDataModelInputViewModel(DataModelPropertyAttribute targetDescription, bool initialValue) : base(targetDescription, initialValue)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
<UserControl x:Class="Artemis.UI.DefaultTypes.DataModel.Input.EnumDataModelInputView"
|
||||
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<ComboBox Width="140"
|
||||
materialDesign:ComboBoxAssist.ClassicMode="True"
|
||||
materialDesign:ValidationAssist.UsePopup="True"
|
||||
HorizontalAlignment="Left"
|
||||
ItemsSource="{Binding Path=EnumValues}"
|
||||
SelectedValuePath="Value"
|
||||
DisplayMemberPath="Description"
|
||||
SelectedValue="{Binding Path=InputValue}" />
|
||||
</UserControl>
|
||||
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.UI.Shared;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.DefaultTypes.DataModel.Input
|
||||
{
|
||||
public class EnumDataModelInputViewModel : DataModelInputViewModel<Enum>
|
||||
{
|
||||
public EnumDataModelInputViewModel(DataModelPropertyAttribute targetDescription, Enum initialValue) : base(targetDescription, initialValue)
|
||||
{
|
||||
EnumValues = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(initialValue.GetType()));
|
||||
}
|
||||
|
||||
public BindableCollection<ValueDescription> EnumValues { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
<UserControl x:Class="Artemis.UI.PropertyInput.BoolPropertyInputView"
|
||||
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
||||
</UserControl.Resources>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Width="10" Text="{Binding LayerProperty.PropertyDescription.InputPrefix}" />
|
||||
<ComboBox Width="132"
|
||||
Margin="0 2"
|
||||
Padding="0 -1"
|
||||
Height="15"
|
||||
materialDesign:ComboBoxAssist.ClassicMode="True"
|
||||
materialDesign:ValidationAssist.UsePopup="True"
|
||||
HorizontalAlignment="Left">
|
||||
<ComboBoxItem Content="True" IsSelected="{Binding InputValue}" />
|
||||
<ComboBoxItem Content="False" IsSelected="{Binding InputValue, Converter={StaticResource InverseBooleanConverter}}" />
|
||||
</ComboBox>
|
||||
<TextBlock Width="10" Text="{Binding LayerProperty.PropertyDescription.InputAffix}" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@ -0,0 +1,15 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
namespace Artemis.UI.PropertyInput
|
||||
{
|
||||
public class BoolPropertyInputViewModel : PropertyInputViewModel<bool>
|
||||
{
|
||||
public BoolPropertyInputViewModel(LayerProperty<bool> layerProperty, IProfileEditorService profileEditorService) : base(layerProperty, profileEditorService)
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsEnabled => true;
|
||||
}
|
||||
}
|
||||
@ -34,7 +34,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
profileEditorService.SelectedProfileElementUpdated += (sender, args) => Update();
|
||||
profileEditorService.ProfilePreviewUpdated += (sender, args) => Update();
|
||||
}
|
||||
|
||||
|
||||
public SKPath ShapePath
|
||||
{
|
||||
get => _shapePath;
|
||||
|
||||
@ -40,6 +40,8 @@ namespace Artemis.UI.Services
|
||||
_dataModelUIService.RegisterDataModelInput<IntDataModelInputViewModel>(Constants.CorePluginInfo, Constants.IntegralNumberTypes);
|
||||
_dataModelUIService.RegisterDataModelInput<SKColorDataModelInputViewModel>(Constants.CorePluginInfo, null);
|
||||
_dataModelUIService.RegisterDataModelInput<StringDataModelInputViewModel>(Constants.CorePluginInfo, null);
|
||||
_dataModelUIService.RegisterDataModelInput<EnumDataModelInputViewModel>(Constants.CorePluginInfo, null);
|
||||
_dataModelUIService.RegisterDataModelInput<BoolDataModelInputViewModel>(Constants.CorePluginInfo, null);
|
||||
|
||||
_registeredBuiltInDataModelInputs = true;
|
||||
}
|
||||
@ -57,6 +59,7 @@ namespace Artemis.UI.Services
|
||||
_profileEditorService.RegisterPropertyInput<SKPointPropertyInputViewModel>(Constants.CorePluginInfo);
|
||||
_profileEditorService.RegisterPropertyInput<SKSizePropertyInputViewModel>(Constants.CorePluginInfo);
|
||||
_profileEditorService.RegisterPropertyInput(typeof(EnumPropertyInputViewModel<>), Constants.CorePluginInfo);
|
||||
_profileEditorService.RegisterPropertyInput<BoolPropertyInputViewModel>(Constants.CorePluginInfo);
|
||||
|
||||
_registeredBuiltInPropertyEditors = true;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user