1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Layer properties - Improved error messaging

Profile editor - Fixed layer creation in selection tool not initializing the layer
Device visualizer - Better handle missing images
This commit is contained in:
SpoinkyNL 2020-06-02 22:30:11 +02:00
parent 92faafe1de
commit 1bcee06cb2
10 changed files with 46 additions and 24 deletions

View File

@ -14,6 +14,9 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Artemis.Storage\Artemis.Storage.csproj"> <ProjectReference Include="..\Artemis.Storage\Artemis.Storage.csproj">
<Private>false</Private> <Private>false</Private>

View File

@ -72,14 +72,6 @@ namespace Artemis.Core.Models.Profile
return folder; return folder;
} }
public Layer AddLayer(string name)
{
var layer = new Layer(Profile, this, name) {Order = Children.LastOrDefault()?.Order ?? 1};
layer.LayerShape = new Rectangle(layer);
AddChild(layer);
return layer;
}
public override string ToString() public override string ToString()
{ {
return $"[Folder] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}"; return $"[Folder] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";

View File

@ -130,14 +130,17 @@ namespace Artemis.Core.Models.Profile
if (propertyDescription != null) if (propertyDescription != null)
{ {
if (!typeof(BaseLayerProperty).IsAssignableFrom(propertyInfo.PropertyType)) if (!typeof(BaseLayerProperty).IsAssignableFrom(propertyInfo.PropertyType))
throw new ArtemisPluginException("Layer property with PropertyDescription attribute must be of type LayerProperty"); throw new ArtemisPluginException($"Layer property with PropertyDescription attribute must be of type LayerProperty at {path + propertyInfo.Name}");
var instance = (BaseLayerProperty) Activator.CreateInstance(propertyInfo.PropertyType, true); var instance = (BaseLayerProperty) Activator.CreateInstance(propertyInfo.PropertyType, true);
instance.Parent = this; if (instance == null)
instance.PropertyDescription = (PropertyDescriptionAttribute)propertyDescription; throw new ArtemisPluginException($"Failed to create instance of layer property at {path + propertyInfo.Name}");
instance.Layer = layer; instance.Layer = layer;
instance.Parent = this;
instance.PropertyDescription = (PropertyDescriptionAttribute) propertyDescription;
InitializeProperty(layer, path + propertyInfo.Name, instance); InitializeProperty(layer, path + propertyInfo.Name, instance);
propertyInfo.SetValue(this, instance); propertyInfo.SetValue(this, instance);
_layerProperties.Add(instance); _layerProperties.Add(instance);
} }
@ -150,16 +153,23 @@ namespace Artemis.Core.Models.Profile
throw new ArtemisPluginException("Layer property with PropertyGroupDescription attribute must be of type LayerPropertyGroup"); throw new ArtemisPluginException("Layer property with PropertyGroupDescription attribute must be of type LayerPropertyGroup");
var instance = (LayerPropertyGroup) Activator.CreateInstance(propertyInfo.PropertyType); var instance = (LayerPropertyGroup) Activator.CreateInstance(propertyInfo.PropertyType);
if (instance == null)
throw new ArtemisPluginException($"Failed to create instance of layer property group at {path + propertyInfo.Name}");
instance.Parent = this; instance.Parent = this;
instance.GroupDescription = (PropertyGroupDescriptionAttribute)propertyGroupDescription; instance.GroupDescription = (PropertyGroupDescriptionAttribute) propertyGroupDescription;
instance.InitializeProperties(layerService, layer, $"{path}{propertyInfo.Name}."); instance.InitializeProperties(layerService, layer, $"{path}{propertyInfo.Name}.");
propertyInfo.SetValue(this, instance); propertyInfo.SetValue(this, instance);
_layerPropertyGroups.Add(instance); _layerPropertyGroups.Add(instance);
} }
} }
} }
// Request the property group to populate defaults
PopulateDefaults(); PopulateDefaults();
// Apply the newly populated defaults
foreach (var layerProperty in _layerProperties.Where(p => !p.IsLoadedFromStorage)) foreach (var layerProperty in _layerProperties.Where(p => !p.IsLoadedFromStorage))
layerProperty.ApplyDefaultValue(); layerProperty.ApplyDefaultValue();
@ -167,7 +177,7 @@ namespace Artemis.Core.Models.Profile
PropertiesInitialized = true; PropertiesInitialized = true;
OnPropertyGroupInitialized(); OnPropertyGroupInitialized();
} }
internal void ApplyToEntity() internal void ApplyToEntity()
{ {
if (!PropertiesInitialized) if (!PropertiesInitialized)

View File

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
@ -25,6 +26,7 @@ namespace Artemis.Core.Services
public Layer CreateLayer(Profile profile, ProfileElement parent, string name) public Layer CreateLayer(Profile profile, ProfileElement parent, string name)
{ {
var layer = new Layer(profile, parent, name); var layer = new Layer(profile, parent, name);
parent.AddChild(layer);
// Layers have two hardcoded property groups, instantiate them // Layers have two hardcoded property groups, instantiate them
layer.General.InitializeProperties(this, layer, "General."); layer.General.InitializeProperties(this, layer, "General.");
@ -60,6 +62,7 @@ namespace Artemis.Core.Services
}; };
layer.LayerBrush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments); layer.LayerBrush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments);
layer.LayerBrush.Initialize(this); layer.LayerBrush.Initialize(this);
layer.LayerBrush.Update(0);
layer.OnLayerBrushUpdated(); layer.OnLayerBrushUpdated();
return layer.LayerBrush; return layer.LayerBrush;
} }

View File

@ -141,8 +141,8 @@ namespace Artemis.UI.Shared.Controls
var drawingImage = new DrawingImage(opacityDrawingGroup); var drawingImage = new DrawingImage(opacityDrawingGroup);
var image = new Image {Source = drawingImage}; var image = new Image {Source = drawingImage};
var bitmap = new RenderTargetBitmap( var bitmap = new RenderTargetBitmap(
(int) (opacityDrawingGroup.Bounds.Width * 2.5), Math.Max(1, (int) (opacityDrawingGroup.Bounds.Width * 2.5)),
(int) (opacityDrawingGroup.Bounds.Height * 2.5), Math.Max(1, (int) (opacityDrawingGroup.Bounds.Height * 2.5)),
96, 96,
96, 96,
PixelFormats.Pbgra32 PixelFormats.Pbgra32
@ -181,7 +181,6 @@ namespace Artemis.UI.Shared.Controls
deviceVisualizerLed.RenderColor(drawingContext, false); deviceVisualizerLed.RenderColor(drawingContext, false);
} }
drawingContext.Close(); drawingContext.Close();
} }
} }

View File

@ -9,7 +9,7 @@
<NeutralLanguage>en-US</NeutralLanguage> <NeutralLanguage>en-US</NeutralLanguage>
<Description>Adds third-party support for RGB keyboards to games.</Description> <Description>Adds third-party support for RGB keyboards to games.</Description>
<Copyright>Copyright © Robert Beekman - 2019</Copyright> <Copyright>Copyright © Robert Beekman - 2019</Copyright>
<AssemblyVersion>2.0.0.0</AssemblyVersion> <AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion> <FileVersion>2.0.0.0</FileVersion>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>

View File

@ -122,8 +122,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
if (!SupportsChildren) if (!SupportsChildren)
throw new ArtemisUIException("Cannot add a layer to a profile element of type " + ProfileElement.GetType().Name); throw new ArtemisUIException("Cannot add a layer to a profile element of type " + ProfileElement.GetType().Name);
var layer = _layerService.CreateLayer(ProfileElement.Profile, ProfileElement, "New layer"); _layerService.CreateLayer(ProfileElement.Profile, ProfileElement, "New layer");
ProfileElement.AddChild(layer);
UpdateProfileElements(); UpdateProfileElements();
_profileEditorService.UpdateSelectedProfile(); _profileEditorService.UpdateSelectedProfile();
} }

View File

@ -55,6 +55,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
private void Update() private void Update()
{ {
IsSelected = _profileEditorService.SelectedProfileElement == Layer; IsSelected = _profileEditorService.SelectedProfileElement == Layer;
CreateLayerGeometry(); CreateLayerGeometry();
CreateShapeGeometry(); CreateShapeGeometry();
CreateViewportRectangle(); CreateViewportRectangle();
@ -223,6 +224,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
private void ProfileEditorServiceOnProfilePreviewUpdated(object sender, EventArgs e) private void ProfileEditorServiceOnProfilePreviewUpdated(object sender, EventArgs e)
{ {
if (!Layer.Transform.PropertiesInitialized || !Layer.General.PropertiesInitialized)
return;
CreateShapeGeometry(); CreateShapeGeometry();
CreateViewportRectangle(); CreateViewportRectangle();
} }

View File

@ -9,6 +9,7 @@ using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.LayerBrush; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.Models; using Artemis.Core.Plugins.Models;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage.Interfaces; using Artemis.Core.Services.Storage.Interfaces;
using Artemis.UI.Events; using Artemis.UI.Events;
using Artemis.UI.Extensions; using Artemis.UI.Extensions;
@ -24,6 +25,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle<MainWindowFocusChangedEvent>, IHandle<MainWindowKeyEvent> public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle<MainWindowFocusChangedEvent>, IHandle<MainWindowKeyEvent>
{ {
private readonly ILayerEditorService _layerEditorService; private readonly ILayerEditorService _layerEditorService;
private readonly ILayerService _layerService;
private readonly IProfileEditorService _profileEditorService; private readonly IProfileEditorService _profileEditorService;
private readonly IProfileLayerVmFactory _profileLayerVmFactory; private readonly IProfileLayerVmFactory _profileLayerVmFactory;
private readonly ISettingsService _settingsService; private readonly ISettingsService _settingsService;
@ -35,6 +37,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
public ProfileViewModel(IProfileEditorService profileEditorService, public ProfileViewModel(IProfileEditorService profileEditorService,
ILayerEditorService layerEditorService, ILayerEditorService layerEditorService,
ILayerService layerService,
ISurfaceService surfaceService, ISurfaceService surfaceService,
ISettingsService settingsService, ISettingsService settingsService,
IEventAggregator eventAggregator, IEventAggregator eventAggregator,
@ -42,6 +45,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
{ {
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
_layerEditorService = layerEditorService; _layerEditorService = layerEditorService;
_layerService = layerService;
_surfaceService = surfaceService; _surfaceService = surfaceService;
_settingsService = settingsService; _settingsService = settingsService;
_profileLayerVmFactory = profileLayerVmFactory; _profileLayerVmFactory = profileLayerVmFactory;
@ -228,7 +232,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
ActiveToolViewModel = new EditToolViewModel(this, _profileEditorService, _layerEditorService); ActiveToolViewModel = new EditToolViewModel(this, _profileEditorService, _layerEditorService);
break; break;
case 2: case 2:
ActiveToolViewModel = new SelectionToolViewModel(this, _profileEditorService); ActiveToolViewModel = new SelectionToolViewModel(this, _profileEditorService, _layerService);
break; break;
case 3: case 3:
ActiveToolViewModel = new SelectionRemoveToolViewModel(this, _profileEditorService); ActiveToolViewModel = new SelectionRemoveToolViewModel(this, _profileEditorService);

View File

@ -3,6 +3,8 @@ using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Services;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Properties; using Artemis.UI.Properties;
using Artemis.UI.Services.Interfaces; using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services.Interfaces; using Artemis.UI.Shared.Services.Interfaces;
@ -11,8 +13,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{ {
public class SelectionToolViewModel : VisualizationToolViewModel public class SelectionToolViewModel : VisualizationToolViewModel
{ {
public SelectionToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService) private readonly ILayerService _layerService;
public SelectionToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerService layerService)
: base(profileViewModel, profileEditorService)
{ {
_layerService = layerService;
using (var stream = new MemoryStream(Resources.aero_crosshair)) using (var stream = new MemoryStream(Resources.aero_crosshair))
{ {
Cursor = new Cursor(stream); Cursor = new Cursor(stream);
@ -48,19 +54,21 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
// If no layer selected, apply it to a new layer in the selected folder // If no layer selected, apply it to a new layer in the selected folder
else if (ProfileEditorService.SelectedProfileElement is Folder folder) else if (ProfileEditorService.SelectedProfileElement is Folder folder)
{ {
var newLayer = folder.AddLayer("New layer"); var newLayer = _layerService.CreateLayer(folder.Profile, folder, "New layer");
newLayer.AddLeds(selectedLeds); newLayer.AddLeds(selectedLeds);
ProfileEditorService.ChangeSelectedProfileElement(newLayer); ProfileEditorService.ChangeSelectedProfileElement(newLayer);
ProfileEditorService.UpdateSelectedProfileElement(); ProfileEditorService.UpdateSelectedProfileElement();
ProfileEditorService.UpdateSelectedProfile();
} }
// If no folder selected, apply it to a new layer in the root folder // If no folder selected, apply it to a new layer in the root folder
else else
{ {
var rootFolder = ProfileEditorService.SelectedProfile.GetRootFolder(); var rootFolder = ProfileEditorService.SelectedProfile.GetRootFolder();
var newLayer = rootFolder.AddLayer("New layer"); var newLayer = _layerService.CreateLayer(rootFolder.Profile, rootFolder, "New layer");
newLayer.AddLeds(selectedLeds); newLayer.AddLeds(selectedLeds);
ProfileEditorService.ChangeSelectedProfileElement(newLayer); ProfileEditorService.ChangeSelectedProfileElement(newLayer);
ProfileEditorService.UpdateSelectedProfileElement(); ProfileEditorService.UpdateSelectedProfileElement();
ProfileEditorService.UpdateSelectedProfile();
} }
} }