mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge remote-tracking branch 'origin/development' into development
This commit is contained in:
commit
4d7bc1dcf4
@ -27,7 +27,7 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// The full path to the Artemis data folder
|
||||
/// </summary>
|
||||
public static readonly string DataFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Artemis\\";
|
||||
public static readonly string DataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Artemis");
|
||||
|
||||
/// <summary>
|
||||
/// The plugin info used by core components of Artemis
|
||||
|
||||
92
src/Artemis.Core/Models/BreakableModel.cs
Normal file
92
src/Artemis.Core/Models/BreakableModel.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a default implementation for models that can have a broken state
|
||||
/// </summary>
|
||||
public abstract class BreakableModel : CorePropertyChanged, IBreakableModel
|
||||
{
|
||||
private string? _brokenState;
|
||||
private Exception? _brokenStateException;
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="BrokenStateChanged" /> event
|
||||
/// </summary>
|
||||
protected virtual void OnBrokenStateChanged()
|
||||
{
|
||||
BrokenStateChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract string BrokenDisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the broken state of this breakable model, if <see langword="null" /> this model is not broken.
|
||||
/// <para>Note: If setting this manually you are also responsible for invoking <see cref="BrokenStateChanged" /></para>
|
||||
/// </summary>
|
||||
public string? BrokenState
|
||||
{
|
||||
get => _brokenState;
|
||||
set => SetAndNotify(ref _brokenState, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the exception that caused the broken state
|
||||
/// <para>Note: If setting this manually you are also responsible for invoking <see cref="BrokenStateChanged" /></para>
|
||||
/// </summary>
|
||||
public Exception? BrokenStateException
|
||||
{
|
||||
get => _brokenStateException;
|
||||
set => SetAndNotify(ref _brokenStateException, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryOrBreak(Action action, string breakMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
action();
|
||||
ClearBrokenState(breakMessage);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SetBrokenState(breakMessage, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetBrokenState(string state, Exception? exception)
|
||||
{
|
||||
BrokenState = state ?? throw new ArgumentNullException(nameof(state));
|
||||
BrokenStateException = exception;
|
||||
OnBrokenStateChanged();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ClearBrokenState(string state)
|
||||
{
|
||||
if (state == null) throw new ArgumentNullException(nameof(state));
|
||||
if (BrokenState == null)
|
||||
return;
|
||||
|
||||
if (BrokenState != state) return;
|
||||
BrokenState = null;
|
||||
BrokenStateException = null;
|
||||
OnBrokenStateChanged();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual IEnumerable<IBreakableModel> GetBrokenHierarchy()
|
||||
{
|
||||
if (BrokenState != null)
|
||||
yield return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? BrokenStateChanged;
|
||||
}
|
||||
}
|
||||
59
src/Artemis.Core/Models/IBreakableModel.cs
Normal file
59
src/Artemis.Core/Models/IBreakableModel.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a model that can have a broken state
|
||||
/// </summary>
|
||||
public interface IBreakableModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the display name of this breakable model
|
||||
/// </summary>
|
||||
string BrokenDisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the broken state of this breakable model, if <see langword="null" /> this model is not broken.
|
||||
/// </summary>
|
||||
string? BrokenState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the exception that caused the broken state
|
||||
/// </summary>
|
||||
Exception? BrokenStateException { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Try to execute the provided action. If the action succeeded the broken state is cleared if it matches
|
||||
/// <see paramref="breakMessage" />, if the action throws an exception <see cref="BrokenState" /> and
|
||||
/// <see cref="BrokenStateException" /> are set accordingly.
|
||||
/// </summary>
|
||||
/// <param name="action">The action to attempt to execute</param>
|
||||
/// <param name="breakMessage">The message to clear on succeed or set on failure (exception)</param>
|
||||
/// <returns><see langword="true" /> if the action succeeded; otherwise <see langword="false" />.</returns>
|
||||
bool TryOrBreak(Action action, string breakMessage);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the broken state to the provided state and optional exception.
|
||||
/// </summary>
|
||||
/// <param name="state">The state to set the broken state to</param>
|
||||
/// <param name="exception">The exception that caused the broken state</param>
|
||||
public void SetBrokenState(string state, Exception? exception);
|
||||
|
||||
/// <summary>
|
||||
/// Clears the broken state and exception if <see cref="BrokenState" /> equals <see paramref="state"></see>.
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
public void ClearBrokenState(string state);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list containing all broken models, including self and any children
|
||||
/// </summary>
|
||||
IEnumerable<IBreakableModel> GetBrokenHierarchy();
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the broken state of this model changes
|
||||
/// </summary>
|
||||
event EventHandler BrokenStateChanged;
|
||||
}
|
||||
}
|
||||
@ -183,18 +183,15 @@ namespace Artemis.Core
|
||||
|
||||
lock (Timeline)
|
||||
{
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||
{
|
||||
baseLayerEffect.BaseProperties?.Update(Timeline);
|
||||
baseLayerEffect.Update(Timeline.Delta.TotalSeconds);
|
||||
}
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||
baseLayerEffect.InternalUpdate(Timeline);
|
||||
|
||||
SKPaint layerPaint = new() {FilterQuality = SKFilterQuality.Low};
|
||||
try
|
||||
{
|
||||
SKRectI rendererBounds = SKRectI.Create(0, 0, Bounds.Width, Bounds.Height);
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||
baseLayerEffect.PreProcess(canvas, rendererBounds, layerPaint);
|
||||
baseLayerEffect.InternalPreProcess(canvas, rendererBounds, layerPaint);
|
||||
|
||||
// No point rendering if the alpha was set to zero by one of the effects
|
||||
if (layerPaint.Color.Alpha == 0)
|
||||
@ -208,7 +205,7 @@ namespace Artemis.Core
|
||||
Children[index].Render(canvas, new SKPointI(Bounds.Left, Bounds.Top));
|
||||
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||
baseLayerEffect.PostProcess(canvas, rendererBounds, layerPaint);
|
||||
baseLayerEffect.InternalPostProcess(canvas, rendererBounds, layerPaint);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -228,8 +225,6 @@ namespace Artemis.Core
|
||||
if (Enabled)
|
||||
return;
|
||||
|
||||
Debug.WriteLine($"Enabling {this}");
|
||||
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
|
||||
baseLayerEffect.InternalEnable();
|
||||
|
||||
@ -248,8 +243,6 @@ namespace Artemis.Core
|
||||
if (!Enabled)
|
||||
return;
|
||||
|
||||
Debug.WriteLine($"Disabled {this}");
|
||||
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
|
||||
baseLayerEffect.InternalDisable();
|
||||
|
||||
@ -344,5 +337,15 @@ namespace Artemis.Core
|
||||
{
|
||||
RenderPropertiesUpdated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#region Overrides of BreakableModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IEnumerable<IBreakableModel> GetBrokenHierarchy()
|
||||
{
|
||||
return LayerEffects.Where(e => e.BrokenState != null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -206,6 +206,7 @@ namespace Artemis.Core
|
||||
GetType().GetProperty(nameof(Transform))!,
|
||||
typeof(PropertyGroupDescriptionAttribute)
|
||||
)!;
|
||||
|
||||
General.GroupDescription = (PropertyGroupDescriptionAttribute) generalAttribute;
|
||||
General.Initialize(this, "General.", Constants.CorePluginFeature);
|
||||
Transform.GroupDescription = (PropertyGroupDescriptionAttribute) transformAttribute;
|
||||
@ -288,7 +289,7 @@ namespace Artemis.Core
|
||||
|
||||
// Adaption hints
|
||||
Adapter.Save();
|
||||
|
||||
|
||||
SaveRenderElement();
|
||||
}
|
||||
|
||||
@ -320,7 +321,7 @@ namespace Artemis.Core
|
||||
{
|
||||
if (Disposed)
|
||||
throw new ObjectDisposedException("Layer");
|
||||
|
||||
|
||||
UpdateDisplayCondition();
|
||||
UpdateTimeline(deltaTime);
|
||||
|
||||
@ -366,9 +367,17 @@ namespace Artemis.Core
|
||||
if (Enabled)
|
||||
return;
|
||||
|
||||
LayerBrush?.InternalEnable();
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
|
||||
baseLayerEffect.InternalEnable();
|
||||
bool tryOrBreak = TryOrBreak(() => LayerBrush?.InternalEnable(), "Failed to enable layer brush");
|
||||
if (!tryOrBreak)
|
||||
return;
|
||||
|
||||
tryOrBreak = TryOrBreak(() =>
|
||||
{
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
|
||||
baseLayerEffect.InternalEnable();
|
||||
}, "Failed to enable one or more effects");
|
||||
if (!tryOrBreak)
|
||||
return;
|
||||
|
||||
Enabled = true;
|
||||
}
|
||||
@ -393,17 +402,10 @@ namespace Artemis.Core
|
||||
|
||||
General.Update(timeline);
|
||||
Transform.Update(timeline);
|
||||
if (LayerBrush != null)
|
||||
{
|
||||
LayerBrush.BaseProperties?.Update(timeline);
|
||||
LayerBrush.Update(timeline.Delta.TotalSeconds);
|
||||
}
|
||||
LayerBrush?.InternalUpdate(timeline);
|
||||
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||
{
|
||||
baseLayerEffect.BaseProperties?.Update(timeline);
|
||||
baseLayerEffect.Update(timeline.Delta.TotalSeconds);
|
||||
}
|
||||
baseLayerEffect.InternalUpdate(timeline);
|
||||
}
|
||||
|
||||
private void RenderTimeline(Timeline timeline, SKCanvas canvas, SKPointI basePosition)
|
||||
@ -477,9 +479,9 @@ namespace Artemis.Core
|
||||
{
|
||||
if (LayerBrush == null)
|
||||
throw new ArtemisCoreException("The layer is not yet ready for rendering");
|
||||
|
||||
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||
baseLayerEffect.PreProcess(canvas, bounds, layerPaint);
|
||||
baseLayerEffect.InternalPreProcess(canvas, bounds, layerPaint);
|
||||
|
||||
try
|
||||
{
|
||||
@ -492,7 +494,7 @@ namespace Artemis.Core
|
||||
LayerBrush.InternalRender(canvas, bounds, layerPaint);
|
||||
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||
baseLayerEffect.PostProcess(canvas, bounds, layerPaint);
|
||||
baseLayerEffect.InternalPostProcess(canvas, bounds, layerPaint);
|
||||
}
|
||||
|
||||
finally
|
||||
@ -722,16 +724,24 @@ namespace Artemis.Core
|
||||
|
||||
internal void ActivateLayerBrush()
|
||||
{
|
||||
LayerBrushReference? current = General.BrushReference.CurrentValue;
|
||||
if (current == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
LayerBrushReference? current = General.BrushReference.CurrentValue;
|
||||
if (current == null)
|
||||
return;
|
||||
|
||||
LayerBrushDescriptor? descriptor = current.LayerBrushProviderId != null && current.BrushType != null
|
||||
? LayerBrushStore.Get(current.LayerBrushProviderId, current.BrushType)?.LayerBrushDescriptor
|
||||
: null;
|
||||
descriptor?.CreateInstance(this);
|
||||
LayerBrushDescriptor? descriptor = current.LayerBrushProviderId != null && current.BrushType != null
|
||||
? LayerBrushStore.Get(current.LayerBrushProviderId, current.BrushType)?.LayerBrushDescriptor
|
||||
: null;
|
||||
descriptor?.CreateInstance(this);
|
||||
|
||||
OnLayerBrushUpdated();
|
||||
OnLayerBrushUpdated();
|
||||
ClearBrokenState("Failed to initialize layer brush");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SetBrokenState("Failed to initialize layer brush", e);
|
||||
}
|
||||
}
|
||||
|
||||
internal void DeactivateLayerBrush()
|
||||
@ -747,6 +757,19 @@ namespace Artemis.Core
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides of BreakableModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IEnumerable<IBreakableModel> GetBrokenHierarchy()
|
||||
{
|
||||
if (LayerBrush?.BrokenState != null)
|
||||
yield return LayerBrush;
|
||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.BrokenState != null))
|
||||
yield return baseLayerEffect;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -27,6 +27,7 @@ namespace Artemis.Core
|
||||
|
||||
UndoStack = new MaxStack<string>(20);
|
||||
RedoStack = new MaxStack<string>(20);
|
||||
Exceptions = new List<Exception>();
|
||||
|
||||
Load();
|
||||
}
|
||||
@ -77,6 +78,7 @@ namespace Artemis.Core
|
||||
|
||||
internal MaxStack<string> UndoStack { get; set; }
|
||||
internal MaxStack<string> RedoStack { get; set; }
|
||||
internal List<Exception> Exceptions { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(double deltaTime)
|
||||
@ -113,6 +115,13 @@ namespace Artemis.Core
|
||||
|
||||
foreach (ProfileScript profileScript in Scripts)
|
||||
profileScript.OnProfileRendered(canvas, canvas.LocalClipBounds);
|
||||
|
||||
if (!Exceptions.Any())
|
||||
return;
|
||||
|
||||
List<Exception> exceptions = new(Exceptions);
|
||||
Exceptions.Clear();
|
||||
throw new AggregateException($"One or more exceptions while rendering profile {Name}", exceptions);
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,5 +247,18 @@ namespace Artemis.Core
|
||||
ProfileEntity.ScriptConfigurations.Add(scriptConfiguration.Entity);
|
||||
}
|
||||
}
|
||||
|
||||
#region Overrides of BreakableModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IEnumerable<IBreakableModel> GetBrokenHierarchy()
|
||||
{
|
||||
foreach (IBreakableModel breakableModel in GetAllFolders().SelectMany(folders => folders.GetBrokenHierarchy()))
|
||||
yield return breakableModel;
|
||||
foreach (IBreakableModel breakableModel in GetAllLayers().SelectMany(layer => layer.GetBrokenHierarchy()))
|
||||
yield return breakableModel;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,7 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// Represents an element of a <see cref="Profile" />
|
||||
/// </summary>
|
||||
public abstract class ProfileElement : CorePropertyChanged, IDisposable
|
||||
public abstract class ProfileElement : BreakableModel, IDisposable
|
||||
{
|
||||
private Guid _entityId;
|
||||
private string? _name;
|
||||
@ -25,7 +25,7 @@ namespace Artemis.Core
|
||||
_profile = profile;
|
||||
ChildrenList = new List<ProfileElement>();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique ID of this profile element
|
||||
/// </summary>
|
||||
@ -121,6 +121,13 @@ namespace Artemis.Core
|
||||
return $"{nameof(EntityId)}: {EntityId}, {nameof(Order)}: {Order}, {nameof(Name)}: {Name}";
|
||||
}
|
||||
|
||||
#region Overrides of BreakableModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string BrokenDisplayName => Name ?? GetType().Name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Hierarchy
|
||||
|
||||
/// <summary>
|
||||
@ -234,7 +241,7 @@ namespace Artemis.Core
|
||||
internal abstract void Save();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -169,29 +169,29 @@ namespace Artemis.Core
|
||||
|
||||
internal static ArtemisLayout? GetDefaultLayout(ArtemisDevice device)
|
||||
{
|
||||
string layoutFolder = Path.Combine(Constants.ApplicationFolder, "DefaultLayouts\\Artemis");
|
||||
string layoutFolder = Path.Combine(Constants.ApplicationFolder, "DefaultLayouts", "Artemis");
|
||||
if (device.DeviceType == RGBDeviceType.Keyboard)
|
||||
{
|
||||
// XL layout is defined by its programmable macro keys
|
||||
if (device.Leds.Any(l => l.RgbLed.Id >= LedId.Keyboard_Programmable1 && l.RgbLed.Id <= LedId.Keyboard_Programmable32))
|
||||
{
|
||||
if (device.PhysicalLayout == KeyboardLayoutType.ANSI)
|
||||
return new ArtemisLayout(layoutFolder + "\\Keyboard\\Artemis XL keyboard-ANSI.xml", LayoutSource.Default);
|
||||
return new ArtemisLayout(layoutFolder + "\\Keyboard\\Artemis XL keyboard-ISO.xml", LayoutSource.Default);
|
||||
return new ArtemisLayout(Path.Combine(layoutFolder, "Keyboard", "Artemis XL keyboard-ANSI.xml"), LayoutSource.Default);
|
||||
return new ArtemisLayout(Path.Combine(layoutFolder, "Keyboard", "Artemis XL keyboard-ISO.xml"), LayoutSource.Default);
|
||||
}
|
||||
|
||||
// L layout is defined by its numpad
|
||||
if (device.Leds.Any(l => l.RgbLed.Id >= LedId.Keyboard_NumLock && l.RgbLed.Id <= LedId.Keyboard_NumPeriodAndDelete))
|
||||
{
|
||||
if (device.PhysicalLayout == KeyboardLayoutType.ANSI)
|
||||
return new ArtemisLayout(layoutFolder + "\\Keyboard\\Artemis L keyboard-ANSI.xml", LayoutSource.Default);
|
||||
return new ArtemisLayout(layoutFolder + "\\Keyboard\\Artemis L keyboard-ISO.xml", LayoutSource.Default);
|
||||
return new ArtemisLayout(Path.Combine(layoutFolder + "Keyboard","Artemis L keyboard-ANSI.xml"), LayoutSource.Default);
|
||||
return new ArtemisLayout(Path.Combine(layoutFolder + "Keyboard","Artemis L keyboard-ISO.xml"), LayoutSource.Default);
|
||||
}
|
||||
|
||||
// No numpad will result in TKL
|
||||
if (device.PhysicalLayout == KeyboardLayoutType.ANSI)
|
||||
return new ArtemisLayout(layoutFolder + "\\Keyboard\\Artemis TKL keyboard-ANSI.xml", LayoutSource.Default);
|
||||
return new ArtemisLayout(layoutFolder + "\\Keyboard\\Artemis TKL keyboard-ISO.xml", LayoutSource.Default);
|
||||
return new ArtemisLayout(Path.Combine(layoutFolder + "Keyboard","Artemis TKL keyboard-ANSI.xml"), LayoutSource.Default);
|
||||
return new ArtemisLayout(Path.Combine(layoutFolder + "Keyboard","Artemis TKL keyboard-ISO.xml"), LayoutSource.Default);
|
||||
}
|
||||
|
||||
// if (device.DeviceType == RGBDeviceType.Mouse)
|
||||
@ -199,21 +199,21 @@ namespace Artemis.Core
|
||||
// if (device.Leds.Count == 1)
|
||||
// {
|
||||
// if (device.Leds.Any(l => l.RgbLed.Id == LedId.Logo))
|
||||
// return new ArtemisLayout(layoutFolder + "\\Mouse\\1 LED mouse logo.xml", LayoutSource.Default);
|
||||
// return new ArtemisLayout(layoutFolder + "\\Mouse\\1 LED mouse.xml", LayoutSource.Default);
|
||||
// return new ArtemisLayout(Path.Combine(layoutFolder + "Mouse", "1 LED mouse logo.xml"), LayoutSource.Default);
|
||||
// return new ArtemisLayout(Path.Combine(layoutFolder + "Mouse", "1 LED mouse.xml"), LayoutSource.Default);
|
||||
// }
|
||||
// if (device.Leds.Any(l => l.RgbLed.Id == LedId.Logo))
|
||||
// return new ArtemisLayout(layoutFolder + "\\Mouse\\4 LED mouse logo.xml", LayoutSource.Default);
|
||||
// return new ArtemisLayout(layoutFolder + "\\Mouse\\4 LED mouse.xml", LayoutSource.Default);
|
||||
// return new ArtemisLayout(Path.Combine(layoutFolder + "Mouse", "4 LED mouse logo.xml"), LayoutSource.Default);
|
||||
// return new ArtemisLayout(Path.Combine(layoutFolder + "Mouse", "4 LED mouse.xml"), LayoutSource.Default);
|
||||
// }
|
||||
|
||||
if (device.DeviceType == RGBDeviceType.Headset)
|
||||
{
|
||||
if (device.Leds.Count == 1)
|
||||
return new ArtemisLayout(layoutFolder + "\\Headset\\Artemis 1 LED headset.xml", LayoutSource.Default);
|
||||
return new ArtemisLayout(Path.Combine(layoutFolder + "Headset", "Artemis 1 LED headset.xml"), LayoutSource.Default);
|
||||
if (device.Leds.Count == 2)
|
||||
return new ArtemisLayout(layoutFolder + "\\Headset\\Artemis 2 LED headset.xml", LayoutSource.Default);
|
||||
return new ArtemisLayout(layoutFolder + "\\Headset\\Artemis 4 LED headset.xml", LayoutSource.Default);
|
||||
return new ArtemisLayout(Path.Combine(layoutFolder + "Headset", "Artemis 2 LED headset.xml"), LayoutSource.Default);
|
||||
return new ArtemisLayout(Path.Combine(layoutFolder + "Headset", "Artemis 4 LED headset.xml"), LayoutSource.Default);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@ -61,7 +61,6 @@ namespace Artemis.Core
|
||||
if (LayoutCustomLedData.LogicalLayouts == null || !LayoutCustomLedData.LogicalLayouts.Any())
|
||||
return;
|
||||
|
||||
Uri layoutDirectory = new(Path.GetDirectoryName(DeviceLayout.FilePath)! + "\\", UriKind.Absolute);
|
||||
// Prefer a matching layout or else a default layout (that has no name)
|
||||
LayoutCustomLedDataLogicalLayout logicalLayout = LayoutCustomLedData.LogicalLayouts
|
||||
.OrderBy(l => l.Name == artemisDevice.LogicalLayout)
|
||||
@ -69,7 +68,7 @@ namespace Artemis.Core
|
||||
.First();
|
||||
|
||||
LogicalName = logicalLayout.Name;
|
||||
Image = new Uri(layoutDirectory, logicalLayout.Image);
|
||||
Image = new Uri(Path.Combine(Path.GetDirectoryName(DeviceLayout.FilePath)!, logicalLayout.Image!), UriKind.Absolute);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Ninject.Activation;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
@ -12,7 +13,7 @@ namespace Artemis.Core.Ninject
|
||||
|
||||
private static readonly ILogger Logger = new LoggerConfiguration()
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.File(Constants.DataFolder + "logs/Artemis log-.log",
|
||||
.WriteTo.File(Path.Combine(Constants.DataFolder, "logs", "Artemis log-.log"),
|
||||
rollingInterval: RollingInterval.Day,
|
||||
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}")
|
||||
.WriteTo.Console()
|
||||
|
||||
@ -8,7 +8,7 @@ namespace Artemis.Core.LayerBrushes
|
||||
/// <summary>
|
||||
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="PerLedLayerBrush{T}" /> or instead
|
||||
/// </summary>
|
||||
public abstract class BaseLayerBrush : CorePropertyChanged, IDisposable
|
||||
public abstract class BaseLayerBrush : BreakableModel, IDisposable
|
||||
{
|
||||
private LayerBrushType _brushType;
|
||||
private ILayerBrushConfigurationDialog? _configurationDialog;
|
||||
@ -134,6 +134,12 @@ namespace Artemis.Core.LayerBrushes
|
||||
}
|
||||
}
|
||||
|
||||
internal void InternalUpdate(Timeline timeline)
|
||||
{
|
||||
BaseProperties?.Update(timeline);
|
||||
TryOrBreak(() => Update(timeline.Delta.TotalSeconds), "Failed to update");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the layer brush if it isn't already enabled
|
||||
/// </summary>
|
||||
@ -142,7 +148,9 @@ namespace Artemis.Core.LayerBrushes
|
||||
if (Enabled)
|
||||
return;
|
||||
|
||||
EnableLayerBrush();
|
||||
if (!TryOrBreak(EnableLayerBrush, "Failed to enable"))
|
||||
return;
|
||||
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
@ -170,6 +178,13 @@ namespace Artemis.Core.LayerBrushes
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#region Overrides of BreakableModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string BrokenDisplayName => Descriptor.DisplayName;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -28,12 +28,12 @@ namespace Artemis.Core.LayerBrushes
|
||||
|
||||
internal override void InternalRender(SKCanvas canvas, SKRect bounds, SKPaint paint)
|
||||
{
|
||||
Render(canvas, bounds, paint);
|
||||
TryOrBreak(() => Render(canvas, bounds, paint), "Failed to render");
|
||||
}
|
||||
|
||||
internal override void Initialize()
|
||||
{
|
||||
InitializeProperties();
|
||||
TryOrBreak(InitializeProperties, "Failed to initialize");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -31,7 +31,7 @@ namespace Artemis.Core.LayerBrushes
|
||||
internal override void InternalRender(SKCanvas canvas, SKRect bounds, SKPaint paint)
|
||||
{
|
||||
// We don't want rotation on this canvas because that'll displace the LEDs, translations are applied to the points of each LED instead
|
||||
if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
|
||||
if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
|
||||
canvas.SetMatrix(canvas.TotalMatrix.PreConcat(Layer.GetTransformMatrix(true, false, false, true).Invert()));
|
||||
|
||||
using SKPath pointsPath = new();
|
||||
@ -46,34 +46,38 @@ namespace Artemis.Core.LayerBrushes
|
||||
}
|
||||
|
||||
// Apply the translation to the points of each LED instead
|
||||
if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
|
||||
if (Layer.General.TransformMode.CurrentValue == LayerTransformMode.Normal && SupportsTransformation)
|
||||
pointsPath.Transform(Layer.GetTransformMatrix(true, true, true, true).Invert());
|
||||
|
||||
SKPoint[] points = pointsPath.Points;
|
||||
for (int index = 0; index < Layer.Leds.Count; index++)
|
||||
|
||||
TryOrBreak(() =>
|
||||
{
|
||||
ArtemisLed artemisLed = Layer.Leds[index];
|
||||
SKPoint renderPoint = points[index * 2 + 1];
|
||||
if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y))
|
||||
continue;
|
||||
for (int index = 0; index < Layer.Leds.Count; index++)
|
||||
{
|
||||
ArtemisLed artemisLed = Layer.Leds[index];
|
||||
SKPoint renderPoint = points[index * 2 + 1];
|
||||
if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y))
|
||||
continue;
|
||||
|
||||
// Let the brush determine the color
|
||||
ledPaint.Color = GetColor(artemisLed, renderPoint);
|
||||
// Let the brush determine the color
|
||||
ledPaint.Color = GetColor(artemisLed, renderPoint);
|
||||
|
||||
SKRect ledRectangle = SKRect.Create(
|
||||
artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left,
|
||||
artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top,
|
||||
artemisLed.AbsoluteRectangle.Width,
|
||||
artemisLed.AbsoluteRectangle.Height
|
||||
);
|
||||
SKRect ledRectangle = SKRect.Create(
|
||||
artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left,
|
||||
artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top,
|
||||
artemisLed.AbsoluteRectangle.Width,
|
||||
artemisLed.AbsoluteRectangle.Height
|
||||
);
|
||||
|
||||
canvas.DrawRect(ledRectangle, ledPaint);
|
||||
}
|
||||
canvas.DrawRect(ledRectangle, ledPaint);
|
||||
}
|
||||
}, "Failed to render");
|
||||
}
|
||||
|
||||
internal override void Initialize()
|
||||
{
|
||||
InitializeProperties();
|
||||
TryOrBreak(InitializeProperties, "Failed to initialize");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Artemis.Core.Services;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.LayerEffects
|
||||
@ -7,7 +6,7 @@ namespace Artemis.Core.LayerEffects
|
||||
/// <summary>
|
||||
/// For internal use only, please use <see cref="LayerEffect{T}" /> instead
|
||||
/// </summary>
|
||||
public abstract class BaseLayerEffect : CorePropertyChanged, IDisposable
|
||||
public abstract class BaseLayerEffect : BreakableModel, IDisposable
|
||||
{
|
||||
private ILayerEffectConfigurationDialog? _configurationDialog;
|
||||
private LayerEffectDescriptor _descriptor;
|
||||
@ -182,6 +181,22 @@ namespace Artemis.Core.LayerEffects
|
||||
|
||||
internal virtual string GetEffectTypeName() => GetType().Name;
|
||||
|
||||
internal void InternalUpdate(Timeline timeline)
|
||||
{
|
||||
BaseProperties?.Update(timeline);
|
||||
TryOrBreak(() => Update(timeline.Delta.TotalSeconds), "Failed to update");
|
||||
}
|
||||
|
||||
internal void InternalPreProcess(SKCanvas canvas, SKRect renderBounds, SKPaint paint)
|
||||
{
|
||||
TryOrBreak(() => PreProcess(canvas, renderBounds, paint), "Failed to pre-process");
|
||||
}
|
||||
|
||||
internal void InternalPostProcess(SKCanvas canvas, SKRect renderBounds, SKPaint paint)
|
||||
{
|
||||
TryOrBreak(() => PostProcess(canvas, renderBounds, paint), "Failed to post-process");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables the layer effect if it isn't already enabled
|
||||
/// </summary>
|
||||
@ -205,5 +220,12 @@ namespace Artemis.Core.LayerEffects
|
||||
DisableLayerEffect();
|
||||
Enabled = false;
|
||||
}
|
||||
|
||||
#region Overrides of BreakableModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string BrokenDisplayName => Name;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -18,8 +18,8 @@ namespace Artemis.Core
|
||||
public static void PrepareFirstLaunch()
|
||||
{
|
||||
CreateAccessibleDirectory(Constants.DataFolder);
|
||||
CreateAccessibleDirectory(Constants.DataFolder + "plugins");
|
||||
CreateAccessibleDirectory(Constants.DataFolder + "user layouts");
|
||||
CreateAccessibleDirectory(Path.Combine(Constants.DataFolder ,"plugins"));
|
||||
CreateAccessibleDirectory(Path.Combine(Constants.DataFolder ,"user layouts"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -19,11 +19,11 @@ namespace Artemis.Storage
|
||||
if (_inUse)
|
||||
throw new Exception("Storage is already in use, can't backup now.");
|
||||
|
||||
string database = $"{dataFolder}\\database.db";
|
||||
string database = Path.Combine(dataFolder, "database.db");
|
||||
if (!File.Exists(database))
|
||||
return;
|
||||
|
||||
string backupFolder = $"{dataFolder}\\database backups";
|
||||
string backupFolder = Path.Combine(dataFolder, "database backups");
|
||||
Directory.CreateDirectory(backupFolder);
|
||||
FileSystemInfo[] files = new DirectoryInfo(backupFolder).GetFileSystemInfos();
|
||||
if (files.Length >= 5)
|
||||
@ -36,7 +36,7 @@ namespace Artemis.Storage
|
||||
oldest.Delete();
|
||||
}
|
||||
|
||||
File.Copy(database, $"{backupFolder}\\database-{DateTime.Now:yyyy-dd-M--HH-mm-ss}.db");
|
||||
File.Copy(database, Path.Combine(backupFolder, $"database-{DateTime.Now:yyyy-dd-M--HH-mm-ss}.db"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -51,7 +51,7 @@ namespace Artemis.Storage
|
||||
try
|
||||
{
|
||||
_inUse = true;
|
||||
return new LiteRepository($"FileName={dataFolder}\\database.db");
|
||||
return new LiteRepository($"FileName={Path.Combine(dataFolder, "database.db")}");
|
||||
}
|
||||
catch (LiteException e)
|
||||
{
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
mc:Ignorable="d"
|
||||
Title="Unhandled exception"
|
||||
Title="Exception | Artemis"
|
||||
Background="{DynamicResource MaterialDesignPaper}"
|
||||
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
|
||||
UseLayoutRounding="True"
|
||||
|
||||
@ -501,11 +501,17 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
|
||||
public void GoToEnd()
|
||||
{
|
||||
if (SelectedProfileElement == null)
|
||||
return;
|
||||
|
||||
ProfileEditorService.CurrentTime = SelectedProfileElement.Timeline.EndSegmentEndPosition;
|
||||
}
|
||||
|
||||
public void GoToPreviousFrame()
|
||||
{
|
||||
if (SelectedProfileElement == null)
|
||||
return;
|
||||
|
||||
double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 25).Value;
|
||||
double newTime = Math.Max(0, Math.Round((ProfileEditorService.CurrentTime.TotalMilliseconds - frameTime) / frameTime) * frameTime);
|
||||
ProfileEditorService.CurrentTime = TimeSpan.FromMilliseconds(newTime);
|
||||
@ -513,6 +519,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
|
||||
public void GoToNextFrame()
|
||||
{
|
||||
if (SelectedProfileElement == null)
|
||||
return;
|
||||
|
||||
double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 25).Value;
|
||||
double newTime = Math.Round((ProfileEditorService.CurrentTime.TotalMilliseconds + frameTime) / frameTime) * frameTime;
|
||||
newTime = Math.Min(newTime, SelectedProfileElement.Timeline.EndSegmentEndPosition.TotalMilliseconds);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Core;
|
||||
@ -20,11 +21,13 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
||||
private bool _draggingTreeView;
|
||||
private TreeItemViewModel _selectedTreeItem;
|
||||
private bool _updatingTree;
|
||||
private readonly Timer _timer;
|
||||
|
||||
public ProfileTreeViewModel(IProfileEditorService profileEditorService, IProfileTreeVmFactory profileTreeVmFactory)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_profileTreeVmFactory = profileTreeVmFactory;
|
||||
_timer = new Timer(500);
|
||||
}
|
||||
|
||||
public TreeItemViewModel SelectedTreeItem
|
||||
@ -54,12 +57,15 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
||||
{
|
||||
Subscribe();
|
||||
CreateRootFolderViewModel();
|
||||
_timer.Start();
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
Unsubscribe();
|
||||
_timer.Stop();
|
||||
_timer.Dispose();
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
@ -203,12 +209,14 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
||||
{
|
||||
_profileEditorService.SelectedProfileChanged += OnSelectedProfileChanged;
|
||||
_profileEditorService.SelectedProfileElementChanged += OnSelectedProfileElementChanged;
|
||||
_timer.Elapsed += TimerOnElapsed;
|
||||
}
|
||||
|
||||
private void Unsubscribe()
|
||||
{
|
||||
_profileEditorService.SelectedProfileChanged -= OnSelectedProfileChanged;
|
||||
_profileEditorService.SelectedProfileElementChanged -= OnSelectedProfileElementChanged;
|
||||
_timer.Elapsed -= TimerOnElapsed;
|
||||
}
|
||||
|
||||
private void OnSelectedProfileElementChanged(object sender, RenderProfileElementEventArgs e)
|
||||
@ -242,6 +250,11 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
||||
CreateRootFolderViewModel();
|
||||
}
|
||||
|
||||
private void TimerOnElapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
ActiveItem?.UpdateBrokenState();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
@ -1,17 +1,20 @@
|
||||
<UserControl
|
||||
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:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:treeItem1="clr-namespace:Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem"
|
||||
xmlns:Converters="clr-namespace:Artemis.UI.Converters" x:Class="Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem.FolderView"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type treeItem1:FolderViewModel}}">
|
||||
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:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:treeItem1="clr-namespace:Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
x:Class="Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem.FolderView"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type treeItem1:FolderViewModel}}">
|
||||
<UserControl.Resources>
|
||||
<Converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
|
||||
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
||||
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
</UserControl.Resources>
|
||||
<!-- Capture clicks on full tree view item -->
|
||||
<StackPanel Margin="-10" Background="Transparent" ContextMenuOpening="{s:Action ContextMenuOpening}">
|
||||
@ -58,18 +61,32 @@
|
||||
</StackPanel.ContextMenu>
|
||||
<Grid Margin="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<materialDesign:PackIcon Grid.Column="0"
|
||||
<Button Grid.Column="0"
|
||||
Style="{StaticResource MaterialDesignFloatingActionMiniDarkButton}"
|
||||
ToolTip="{Binding BrokenState}"
|
||||
Visibility="{Binding BrokenState, Converter={StaticResource NullToVisibilityConverter}}"
|
||||
Foreground="White"
|
||||
Background="#E74C4C"
|
||||
BorderBrush="#E74C4C"
|
||||
Width="18"
|
||||
Height="18"
|
||||
Margin="0 0 5 0"
|
||||
Command="{s:Action ShowBrokenStateExceptions}">
|
||||
<materialDesign:PackIcon Kind="AlertCircle" Height="12" Width="12" />
|
||||
</Button>
|
||||
<materialDesign:PackIcon Grid.Column="1"
|
||||
Kind="Folder"
|
||||
Visibility="{Binding IsExpanded, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}" />
|
||||
<materialDesign:PackIcon Grid.Column="0"
|
||||
<materialDesign:PackIcon Grid.Column="1"
|
||||
Kind="FolderOpen"
|
||||
Visibility="{Binding IsExpanded, Converter={x:Static s:BoolToVisibilityConverter.Instance}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding ProfileElement.Name}" Margin="10 0 0 0" VerticalAlignment="Center" />
|
||||
<ToggleButton Grid.Column="2"
|
||||
<TextBlock Grid.Column="2" Text="{Binding ProfileElement.Name}" Margin="10 0 0 0" VerticalAlignment="Center" />
|
||||
<ToggleButton Grid.Column="3"
|
||||
Style="{StaticResource MaterialDesignFlatToggleButton}"
|
||||
ToolTip="Toggle suspended state"
|
||||
Width="18"
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.LayerEffects;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared.Services;
|
||||
@ -27,12 +31,28 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
||||
set => ((Folder) ProfileElement).IsExpanded = value;
|
||||
}
|
||||
|
||||
public override void UpdateBrokenState()
|
||||
{
|
||||
List<IBreakableModel> brokenModels = ProfileElement.GetBrokenHierarchy().ToList();
|
||||
if (!brokenModels.Any())
|
||||
BrokenState = null;
|
||||
else
|
||||
{
|
||||
BrokenState = "Folder is in a broken state, click to view exception(s).\r\n" +
|
||||
$"{string.Join("\r\n", brokenModels.Select(e => $" • {e.BrokenDisplayName} - {e.BrokenState}"))}";
|
||||
}
|
||||
|
||||
foreach (TreeItemViewModel treeItemViewModel in GetChildren())
|
||||
treeItemViewModel.UpdateBrokenState();
|
||||
}
|
||||
|
||||
private void ProfileElementOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Folder.IsExpanded))
|
||||
NotifyOfPropertyChange(nameof(IsExpanded));
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region Overrides of Screen
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -6,14 +6,15 @@
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:treeItem1="clr-namespace:Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem"
|
||||
xmlns:Converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
x:Class="Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem.LayerView"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type treeItem1:LayerViewModel}}">
|
||||
<UserControl.Resources>
|
||||
<Converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
||||
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
||||
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
</UserControl.Resources>
|
||||
<!-- Capture clicks on full tree view item -->
|
||||
<StackPanel Margin="-10" Background="Transparent" ContextMenuOpening="{s:Action ContextMenuOpening}">
|
||||
@ -55,13 +56,27 @@
|
||||
</StackPanel.ContextMenu>
|
||||
<Grid Margin="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<materialDesign:PackIcon Grid.Column="0" Kind="Layers" Width="16" VerticalAlignment="Center" />
|
||||
<shared:ArtemisIcon Grid.Column="1"
|
||||
<Button Grid.Column="0"
|
||||
Style="{StaticResource MaterialDesignFloatingActionMiniDarkButton}"
|
||||
ToolTip="{Binding BrokenState}"
|
||||
Visibility="{Binding BrokenState, Converter={StaticResource NullToVisibilityConverter}}"
|
||||
Foreground="White"
|
||||
Background="#E74C4C"
|
||||
BorderBrush="#E74C4C"
|
||||
Width="18"
|
||||
Height="18"
|
||||
Margin="0 0 5 0"
|
||||
Command="{s:Action ShowBrokenStateExceptions}">
|
||||
<materialDesign:PackIcon Kind="AlertCircle" Height="12" Width="12" />
|
||||
</Button>
|
||||
<materialDesign:PackIcon Grid.Column="1" Kind="Layers" Width="16" VerticalAlignment="Center" />
|
||||
<shared:ArtemisIcon Grid.Column="2"
|
||||
VerticalAlignment="Center"
|
||||
Icon="{Binding Layer.LayerBrush.Descriptor.Icon}"
|
||||
Width="16"
|
||||
@ -69,8 +84,8 @@
|
||||
ToolTip="{Binding Layer.LayerBrush.Descriptor.DisplayName, Mode=OneWay}"
|
||||
Visibility="{Binding ShowIcons, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"
|
||||
Background="Transparent" />
|
||||
<TextBlock Grid.Column="2" Text="{Binding Layer.Name}" VerticalAlignment="Center" Margin="5 0 0 0" />
|
||||
<ToggleButton Grid.Column="3"
|
||||
<TextBlock Grid.Column="3" Text="{Binding Layer.Name}" VerticalAlignment="Center" Margin="5 0 0 0" />
|
||||
<ToggleButton Grid.Column="4"
|
||||
Style="{StaticResource MaterialDesignFlatToggleButton}"
|
||||
Width="18"
|
||||
Height="18"
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
using Artemis.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.LayerEffects;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared.Services;
|
||||
@ -9,7 +14,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
||||
public class LayerViewModel : TreeItemViewModel
|
||||
{
|
||||
private readonly IWindowManager _windowManager;
|
||||
private ILayerHintVmFactory _vmFactory;
|
||||
private readonly ILayerHintVmFactory _vmFactory;
|
||||
|
||||
public LayerViewModel(ProfileElement layer,
|
||||
IRgbService rgbService,
|
||||
@ -25,15 +30,27 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
||||
_vmFactory = vmFactory;
|
||||
}
|
||||
|
||||
public void OpenAdaptionHints()
|
||||
{
|
||||
_windowManager.ShowDialog(_vmFactory.LayerHintsDialogViewModel(Layer));
|
||||
}
|
||||
|
||||
public Layer Layer => ProfileElement as Layer;
|
||||
public bool ShowIcons => Layer?.LayerBrush != null;
|
||||
public override bool SupportsChildren => false;
|
||||
|
||||
public override bool IsExpanded { get; set; }
|
||||
|
||||
public void OpenAdaptionHints()
|
||||
{
|
||||
_windowManager.ShowDialog(_vmFactory.LayerHintsDialogViewModel(Layer));
|
||||
}
|
||||
|
||||
public override void UpdateBrokenState()
|
||||
{
|
||||
List<IBreakableModel> brokenModels = ProfileElement.GetBrokenHierarchy().ToList();
|
||||
if (!brokenModels.Any())
|
||||
BrokenState = null;
|
||||
else
|
||||
{
|
||||
BrokenState = "Layer is in a broken state, click to view exception(s).\r\n" +
|
||||
$"{string.Join("\r\n", brokenModels.Select(e => $" • {e.BrokenDisplayName} - {e.BrokenState}"))}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,6 +23,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
||||
private readonly IProfileTreeVmFactory _profileTreeVmFactory;
|
||||
private readonly IRgbService _rgbService;
|
||||
private ProfileElement _profileElement;
|
||||
private string _brokenState;
|
||||
|
||||
protected TreeItemViewModel(ProfileElement profileElement,
|
||||
IRgbService rgbService,
|
||||
@ -49,6 +50,12 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
||||
set => SetAndNotify(ref _profileElement, value);
|
||||
}
|
||||
|
||||
public string BrokenState
|
||||
{
|
||||
get => _brokenState;
|
||||
set => SetAndNotify(ref _brokenState, value);
|
||||
}
|
||||
|
||||
public bool CanPasteElement => _profileEditorService.GetCanPasteProfileElement();
|
||||
|
||||
public abstract bool SupportsChildren { get; }
|
||||
@ -286,6 +293,23 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
||||
NotifyOfPropertyChange(nameof(CanPasteElement));
|
||||
}
|
||||
|
||||
public abstract void UpdateBrokenState();
|
||||
|
||||
public async Task ShowBrokenStateExceptions()
|
||||
{
|
||||
List<IBreakableModel> broken = ProfileElement.GetBrokenHierarchy().Where(b => b.BrokenStateException != null).ToList();
|
||||
|
||||
foreach (IBreakableModel current in broken)
|
||||
{
|
||||
_dialogService.ShowExceptionDialog($"{current.BrokenDisplayName} - {current.BrokenState}", current.BrokenStateException!);
|
||||
if (broken.Last() != current)
|
||||
{
|
||||
if (!await _dialogService.ShowConfirmDialog("Broken state", "Do you want to view the next exception?"))
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Subscribe()
|
||||
{
|
||||
ProfileElement.ChildAdded += ProfileElementOnChildAdded;
|
||||
|
||||
@ -261,8 +261,14 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
|
||||
public void ResetZoomAndPan()
|
||||
{
|
||||
if (!Devices.Any())
|
||||
{
|
||||
PanZoomViewModel.Reset();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a rect surrounding all devices
|
||||
SKRect rect = new SKRect(
|
||||
SKRect rect = new(
|
||||
Devices.Min(d => d.Rectangle.Left),
|
||||
Devices.Min(d => d.Rectangle.Top),
|
||||
Devices.Max(d => d.Rectangle.Right),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user