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:
parent
92faafe1de
commit
1bcee06cb2
@ -14,6 +14,9 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Artemis.Storage\Artemis.Storage.csproj">
|
||||
<Private>false</Private>
|
||||
|
||||
@ -72,14 +72,6 @@ namespace Artemis.Core.Models.Profile
|
||||
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()
|
||||
{
|
||||
return $"[Folder] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
|
||||
|
||||
@ -130,14 +130,17 @@ namespace Artemis.Core.Models.Profile
|
||||
if (propertyDescription != null)
|
||||
{
|
||||
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);
|
||||
instance.Parent = this;
|
||||
instance.PropertyDescription = (PropertyDescriptionAttribute)propertyDescription;
|
||||
if (instance == null)
|
||||
throw new ArtemisPluginException($"Failed to create instance of layer property at {path + propertyInfo.Name}");
|
||||
|
||||
instance.Layer = layer;
|
||||
|
||||
instance.Parent = this;
|
||||
instance.PropertyDescription = (PropertyDescriptionAttribute) propertyDescription;
|
||||
InitializeProperty(layer, path + propertyInfo.Name, instance);
|
||||
|
||||
propertyInfo.SetValue(this, 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");
|
||||
|
||||
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.GroupDescription = (PropertyGroupDescriptionAttribute)propertyGroupDescription;
|
||||
instance.GroupDescription = (PropertyGroupDescriptionAttribute) propertyGroupDescription;
|
||||
instance.InitializeProperties(layerService, layer, $"{path}{propertyInfo.Name}.");
|
||||
|
||||
propertyInfo.SetValue(this, instance);
|
||||
_layerPropertyGroups.Add(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Request the property group to populate defaults
|
||||
PopulateDefaults();
|
||||
|
||||
// Apply the newly populated defaults
|
||||
foreach (var layerProperty in _layerProperties.Where(p => !p.IsLoadedFromStorage))
|
||||
layerProperty.ApplyDefaultValue();
|
||||
|
||||
@ -167,7 +177,7 @@ namespace Artemis.Core.Models.Profile
|
||||
PropertiesInitialized = true;
|
||||
OnPropertyGroupInitialized();
|
||||
}
|
||||
|
||||
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
if (!PropertiesInitialized)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Plugins.LayerBrush;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
@ -25,6 +26,7 @@ namespace Artemis.Core.Services
|
||||
public Layer CreateLayer(Profile profile, ProfileElement parent, string name)
|
||||
{
|
||||
var layer = new Layer(profile, parent, name);
|
||||
parent.AddChild(layer);
|
||||
|
||||
// Layers have two hardcoded property groups, instantiate them
|
||||
layer.General.InitializeProperties(this, layer, "General.");
|
||||
@ -60,6 +62,7 @@ namespace Artemis.Core.Services
|
||||
};
|
||||
layer.LayerBrush = (BaseLayerBrush) _kernel.Get(descriptor.LayerBrushType, arguments);
|
||||
layer.LayerBrush.Initialize(this);
|
||||
layer.LayerBrush.Update(0);
|
||||
layer.OnLayerBrushUpdated();
|
||||
return layer.LayerBrush;
|
||||
}
|
||||
|
||||
@ -141,8 +141,8 @@ namespace Artemis.UI.Shared.Controls
|
||||
var drawingImage = new DrawingImage(opacityDrawingGroup);
|
||||
var image = new Image {Source = drawingImage};
|
||||
var bitmap = new RenderTargetBitmap(
|
||||
(int) (opacityDrawingGroup.Bounds.Width * 2.5),
|
||||
(int) (opacityDrawingGroup.Bounds.Height * 2.5),
|
||||
Math.Max(1, (int) (opacityDrawingGroup.Bounds.Width * 2.5)),
|
||||
Math.Max(1, (int) (opacityDrawingGroup.Bounds.Height * 2.5)),
|
||||
96,
|
||||
96,
|
||||
PixelFormats.Pbgra32
|
||||
@ -181,7 +181,6 @@ namespace Artemis.UI.Shared.Controls
|
||||
deviceVisualizerLed.RenderColor(drawingContext, false);
|
||||
}
|
||||
|
||||
|
||||
drawingContext.Close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<Description>Adds third-party support for RGB keyboards to games.</Description>
|
||||
<Copyright>Copyright © Robert Beekman - 2019</Copyright>
|
||||
<AssemblyVersion>2.0.0.0</AssemblyVersion>
|
||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||
<FileVersion>2.0.0.0</FileVersion>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
|
||||
@ -122,8 +122,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileTree.TreeItem
|
||||
if (!SupportsChildren)
|
||||
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");
|
||||
ProfileElement.AddChild(layer);
|
||||
_layerService.CreateLayer(ProfileElement.Profile, ProfileElement, "New layer");
|
||||
UpdateProfileElements();
|
||||
_profileEditorService.UpdateSelectedProfile();
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
private void Update()
|
||||
{
|
||||
IsSelected = _profileEditorService.SelectedProfileElement == Layer;
|
||||
|
||||
CreateLayerGeometry();
|
||||
CreateShapeGeometry();
|
||||
CreateViewportRectangle();
|
||||
@ -223,6 +224,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
|
||||
private void ProfileEditorServiceOnProfilePreviewUpdated(object sender, EventArgs e)
|
||||
{
|
||||
if (!Layer.Transform.PropertiesInitialized || !Layer.General.PropertiesInitialized)
|
||||
return;
|
||||
|
||||
CreateShapeGeometry();
|
||||
CreateViewportRectangle();
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.LayerBrush;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Extensions;
|
||||
@ -24,6 +25,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle<MainWindowFocusChangedEvent>, IHandle<MainWindowKeyEvent>
|
||||
{
|
||||
private readonly ILayerEditorService _layerEditorService;
|
||||
private readonly ILayerService _layerService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IProfileLayerVmFactory _profileLayerVmFactory;
|
||||
private readonly ISettingsService _settingsService;
|
||||
@ -35,6 +37,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
|
||||
public ProfileViewModel(IProfileEditorService profileEditorService,
|
||||
ILayerEditorService layerEditorService,
|
||||
ILayerService layerService,
|
||||
ISurfaceService surfaceService,
|
||||
ISettingsService settingsService,
|
||||
IEventAggregator eventAggregator,
|
||||
@ -42,6 +45,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_layerEditorService = layerEditorService;
|
||||
_layerService = layerService;
|
||||
_surfaceService = surfaceService;
|
||||
_settingsService = settingsService;
|
||||
_profileLayerVmFactory = profileLayerVmFactory;
|
||||
@ -228,7 +232,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
ActiveToolViewModel = new EditToolViewModel(this, _profileEditorService, _layerEditorService);
|
||||
break;
|
||||
case 2:
|
||||
ActiveToolViewModel = new SelectionToolViewModel(this, _profileEditorService);
|
||||
ActiveToolViewModel = new SelectionToolViewModel(this, _profileEditorService, _layerService);
|
||||
break;
|
||||
case 3:
|
||||
ActiveToolViewModel = new SelectionRemoveToolViewModel(this, _profileEditorService);
|
||||
|
||||
@ -3,6 +3,8 @@ using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.Properties;
|
||||
using Artemis.UI.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 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))
|
||||
{
|
||||
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
|
||||
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);
|
||||
ProfileEditorService.ChangeSelectedProfileElement(newLayer);
|
||||
ProfileEditorService.UpdateSelectedProfileElement();
|
||||
ProfileEditorService.UpdateSelectedProfile();
|
||||
}
|
||||
// If no folder selected, apply it to a new layer in the root folder
|
||||
else
|
||||
{
|
||||
var rootFolder = ProfileEditorService.SelectedProfile.GetRootFolder();
|
||||
var newLayer = rootFolder.AddLayer("New layer");
|
||||
var newLayer = _layerService.CreateLayer(rootFolder.Profile, rootFolder, "New layer");
|
||||
newLayer.AddLeds(selectedLeds);
|
||||
ProfileEditorService.ChangeSelectedProfileElement(newLayer);
|
||||
ProfileEditorService.UpdateSelectedProfileElement();
|
||||
ProfileEditorService.UpdateSelectedProfile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user