mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge branch 'development'
This commit is contained in:
commit
719d95bd33
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)
|
lock (Timeline)
|
||||||
{
|
{
|
||||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||||
{
|
baseLayerEffect.InternalUpdate(Timeline);
|
||||||
baseLayerEffect.BaseProperties?.Update(Timeline);
|
|
||||||
baseLayerEffect.Update(Timeline.Delta.TotalSeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
SKPaint layerPaint = new() {FilterQuality = SKFilterQuality.Low};
|
SKPaint layerPaint = new() {FilterQuality = SKFilterQuality.Low};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SKRectI rendererBounds = SKRectI.Create(0, 0, Bounds.Width, Bounds.Height);
|
SKRectI rendererBounds = SKRectI.Create(0, 0, Bounds.Width, Bounds.Height);
|
||||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
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
|
// No point rendering if the alpha was set to zero by one of the effects
|
||||||
if (layerPaint.Color.Alpha == 0)
|
if (layerPaint.Color.Alpha == 0)
|
||||||
@ -208,7 +205,7 @@ namespace Artemis.Core
|
|||||||
Children[index].Render(canvas, new SKPointI(Bounds.Left, Bounds.Top));
|
Children[index].Render(canvas, new SKPointI(Bounds.Left, Bounds.Top));
|
||||||
|
|
||||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||||
baseLayerEffect.PostProcess(canvas, rendererBounds, layerPaint);
|
baseLayerEffect.InternalPostProcess(canvas, rendererBounds, layerPaint);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -228,8 +225,6 @@ namespace Artemis.Core
|
|||||||
if (Enabled)
|
if (Enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Debug.WriteLine($"Enabling {this}");
|
|
||||||
|
|
||||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
|
||||||
baseLayerEffect.InternalEnable();
|
baseLayerEffect.InternalEnable();
|
||||||
|
|
||||||
@ -248,8 +243,6 @@ namespace Artemis.Core
|
|||||||
if (!Enabled)
|
if (!Enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Debug.WriteLine($"Disabled {this}");
|
|
||||||
|
|
||||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
|
||||||
baseLayerEffect.InternalDisable();
|
baseLayerEffect.InternalDisable();
|
||||||
|
|
||||||
@ -344,5 +337,15 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
RenderPropertiesUpdated?.Invoke(this, EventArgs.Empty);
|
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))!,
|
GetType().GetProperty(nameof(Transform))!,
|
||||||
typeof(PropertyGroupDescriptionAttribute)
|
typeof(PropertyGroupDescriptionAttribute)
|
||||||
)!;
|
)!;
|
||||||
|
|
||||||
General.GroupDescription = (PropertyGroupDescriptionAttribute) generalAttribute;
|
General.GroupDescription = (PropertyGroupDescriptionAttribute) generalAttribute;
|
||||||
General.Initialize(this, "General.", Constants.CorePluginFeature);
|
General.Initialize(this, "General.", Constants.CorePluginFeature);
|
||||||
Transform.GroupDescription = (PropertyGroupDescriptionAttribute) transformAttribute;
|
Transform.GroupDescription = (PropertyGroupDescriptionAttribute) transformAttribute;
|
||||||
@ -288,7 +289,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
// Adaption hints
|
// Adaption hints
|
||||||
Adapter.Save();
|
Adapter.Save();
|
||||||
|
|
||||||
SaveRenderElement();
|
SaveRenderElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +321,7 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
if (Disposed)
|
if (Disposed)
|
||||||
throw new ObjectDisposedException("Layer");
|
throw new ObjectDisposedException("Layer");
|
||||||
|
|
||||||
UpdateDisplayCondition();
|
UpdateDisplayCondition();
|
||||||
UpdateTimeline(deltaTime);
|
UpdateTimeline(deltaTime);
|
||||||
|
|
||||||
@ -366,9 +367,17 @@ namespace Artemis.Core
|
|||||||
if (Enabled)
|
if (Enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LayerBrush?.InternalEnable();
|
bool tryOrBreak = TryOrBreak(() => LayerBrush?.InternalEnable(), "Failed to enable layer brush");
|
||||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
|
if (!tryOrBreak)
|
||||||
baseLayerEffect.InternalEnable();
|
return;
|
||||||
|
|
||||||
|
tryOrBreak = TryOrBreak(() =>
|
||||||
|
{
|
||||||
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
|
||||||
|
baseLayerEffect.InternalEnable();
|
||||||
|
}, "Failed to enable one or more effects");
|
||||||
|
if (!tryOrBreak)
|
||||||
|
return;
|
||||||
|
|
||||||
Enabled = true;
|
Enabled = true;
|
||||||
}
|
}
|
||||||
@ -393,17 +402,10 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
General.Update(timeline);
|
General.Update(timeline);
|
||||||
Transform.Update(timeline);
|
Transform.Update(timeline);
|
||||||
if (LayerBrush != null)
|
LayerBrush?.InternalUpdate(timeline);
|
||||||
{
|
|
||||||
LayerBrush.BaseProperties?.Update(timeline);
|
|
||||||
LayerBrush.Update(timeline.Delta.TotalSeconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||||
{
|
baseLayerEffect.InternalUpdate(timeline);
|
||||||
baseLayerEffect.BaseProperties?.Update(timeline);
|
|
||||||
baseLayerEffect.Update(timeline.Delta.TotalSeconds);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RenderTimeline(Timeline timeline, SKCanvas canvas, SKPointI basePosition)
|
private void RenderTimeline(Timeline timeline, SKCanvas canvas, SKPointI basePosition)
|
||||||
@ -477,9 +479,9 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
if (LayerBrush == null)
|
if (LayerBrush == null)
|
||||||
throw new ArtemisCoreException("The layer is not yet ready for rendering");
|
throw new ArtemisCoreException("The layer is not yet ready for rendering");
|
||||||
|
|
||||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||||
baseLayerEffect.PreProcess(canvas, bounds, layerPaint);
|
baseLayerEffect.InternalPreProcess(canvas, bounds, layerPaint);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -492,7 +494,7 @@ namespace Artemis.Core
|
|||||||
LayerBrush.InternalRender(canvas, bounds, layerPaint);
|
LayerBrush.InternalRender(canvas, bounds, layerPaint);
|
||||||
|
|
||||||
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => !e.Suspended))
|
||||||
baseLayerEffect.PostProcess(canvas, bounds, layerPaint);
|
baseLayerEffect.InternalPostProcess(canvas, bounds, layerPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
finally
|
finally
|
||||||
@ -722,16 +724,24 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
internal void ActivateLayerBrush()
|
internal void ActivateLayerBrush()
|
||||||
{
|
{
|
||||||
LayerBrushReference? current = General.BrushReference.CurrentValue;
|
try
|
||||||
if (current == null)
|
{
|
||||||
return;
|
LayerBrushReference? current = General.BrushReference.CurrentValue;
|
||||||
|
if (current == null)
|
||||||
|
return;
|
||||||
|
|
||||||
LayerBrushDescriptor? descriptor = current.LayerBrushProviderId != null && current.BrushType != null
|
LayerBrushDescriptor? descriptor = current.LayerBrushProviderId != null && current.BrushType != null
|
||||||
? LayerBrushStore.Get(current.LayerBrushProviderId, current.BrushType)?.LayerBrushDescriptor
|
? LayerBrushStore.Get(current.LayerBrushProviderId, current.BrushType)?.LayerBrushDescriptor
|
||||||
: null;
|
: null;
|
||||||
descriptor?.CreateInstance(this);
|
descriptor?.CreateInstance(this);
|
||||||
|
|
||||||
OnLayerBrushUpdated();
|
OnLayerBrushUpdated();
|
||||||
|
ClearBrokenState("Failed to initialize layer brush");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
SetBrokenState("Failed to initialize layer brush", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void DeactivateLayerBrush()
|
internal void DeactivateLayerBrush()
|
||||||
@ -747,6 +757,19 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#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>
|
/// <summary>
|
||||||
|
|||||||
@ -27,6 +27,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
UndoStack = new MaxStack<string>(20);
|
UndoStack = new MaxStack<string>(20);
|
||||||
RedoStack = new MaxStack<string>(20);
|
RedoStack = new MaxStack<string>(20);
|
||||||
|
Exceptions = new List<Exception>();
|
||||||
|
|
||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
@ -77,6 +78,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
internal MaxStack<string> UndoStack { get; set; }
|
internal MaxStack<string> UndoStack { get; set; }
|
||||||
internal MaxStack<string> RedoStack { get; set; }
|
internal MaxStack<string> RedoStack { get; set; }
|
||||||
|
internal List<Exception> Exceptions { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Update(double deltaTime)
|
public override void Update(double deltaTime)
|
||||||
@ -113,6 +115,13 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
foreach (ProfileScript profileScript in Scripts)
|
foreach (ProfileScript profileScript in Scripts)
|
||||||
profileScript.OnProfileRendered(canvas, canvas.LocalClipBounds);
|
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);
|
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>
|
/// <summary>
|
||||||
/// Represents an element of a <see cref="Profile" />
|
/// Represents an element of a <see cref="Profile" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ProfileElement : CorePropertyChanged, IDisposable
|
public abstract class ProfileElement : BreakableModel, IDisposable
|
||||||
{
|
{
|
||||||
private Guid _entityId;
|
private Guid _entityId;
|
||||||
private string? _name;
|
private string? _name;
|
||||||
@ -25,7 +25,7 @@ namespace Artemis.Core
|
|||||||
_profile = profile;
|
_profile = profile;
|
||||||
ChildrenList = new List<ProfileElement>();
|
ChildrenList = new List<ProfileElement>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the unique ID of this profile element
|
/// Gets the unique ID of this profile element
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -121,6 +121,13 @@ namespace Artemis.Core
|
|||||||
return $"{nameof(EntityId)}: {EntityId}, {nameof(Order)}: {Order}, {nameof(Name)}: {Name}";
|
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
|
#region Hierarchy
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -234,7 +241,7 @@ namespace Artemis.Core
|
|||||||
internal abstract void Save();
|
internal abstract void Save();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IDisposable
|
#region IDisposable
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -8,7 +8,7 @@ namespace Artemis.Core.LayerBrushes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="PerLedLayerBrush{T}" /> or instead
|
/// For internal use only, please use <see cref="LayerBrush{T}" /> or <see cref="PerLedLayerBrush{T}" /> or instead
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class BaseLayerBrush : CorePropertyChanged, IDisposable
|
public abstract class BaseLayerBrush : BreakableModel, IDisposable
|
||||||
{
|
{
|
||||||
private LayerBrushType _brushType;
|
private LayerBrushType _brushType;
|
||||||
private ILayerBrushConfigurationDialog? _configurationDialog;
|
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>
|
/// <summary>
|
||||||
/// Enables the layer brush if it isn't already enabled
|
/// Enables the layer brush if it isn't already enabled
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -142,7 +148,9 @@ namespace Artemis.Core.LayerBrushes
|
|||||||
if (Enabled)
|
if (Enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EnableLayerBrush();
|
if (!TryOrBreak(EnableLayerBrush, "Failed to enable"))
|
||||||
|
return;
|
||||||
|
|
||||||
Enabled = true;
|
Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,6 +178,13 @@ namespace Artemis.Core.LayerBrushes
|
|||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Overrides of BreakableModel
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string BrokenDisplayName => Descriptor.DisplayName;
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -28,12 +28,12 @@ namespace Artemis.Core.LayerBrushes
|
|||||||
|
|
||||||
internal override void InternalRender(SKCanvas canvas, SKRect bounds, SKPaint paint)
|
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()
|
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)
|
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
|
// 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()));
|
canvas.SetMatrix(canvas.TotalMatrix.PreConcat(Layer.GetTransformMatrix(true, false, false, true).Invert()));
|
||||||
|
|
||||||
using SKPath pointsPath = new();
|
using SKPath pointsPath = new();
|
||||||
@ -46,34 +46,38 @@ namespace Artemis.Core.LayerBrushes
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply the translation to the points of each LED instead
|
// 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());
|
pointsPath.Transform(Layer.GetTransformMatrix(true, true, true, true).Invert());
|
||||||
|
|
||||||
SKPoint[] points = pointsPath.Points;
|
SKPoint[] points = pointsPath.Points;
|
||||||
for (int index = 0; index < Layer.Leds.Count; index++)
|
|
||||||
|
TryOrBreak(() =>
|
||||||
{
|
{
|
||||||
ArtemisLed artemisLed = Layer.Leds[index];
|
for (int index = 0; index < Layer.Leds.Count; index++)
|
||||||
SKPoint renderPoint = points[index * 2 + 1];
|
{
|
||||||
if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y))
|
ArtemisLed artemisLed = Layer.Leds[index];
|
||||||
continue;
|
SKPoint renderPoint = points[index * 2 + 1];
|
||||||
|
if (!float.IsFinite(renderPoint.X) || !float.IsFinite(renderPoint.Y))
|
||||||
|
continue;
|
||||||
|
|
||||||
// Let the brush determine the color
|
// Let the brush determine the color
|
||||||
ledPaint.Color = GetColor(artemisLed, renderPoint);
|
ledPaint.Color = GetColor(artemisLed, renderPoint);
|
||||||
|
|
||||||
SKRect ledRectangle = SKRect.Create(
|
SKRect ledRectangle = SKRect.Create(
|
||||||
artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left,
|
artemisLed.AbsoluteRectangle.Left - Layer.Bounds.Left,
|
||||||
artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top,
|
artemisLed.AbsoluteRectangle.Top - Layer.Bounds.Top,
|
||||||
artemisLed.AbsoluteRectangle.Width,
|
artemisLed.AbsoluteRectangle.Width,
|
||||||
artemisLed.AbsoluteRectangle.Height
|
artemisLed.AbsoluteRectangle.Height
|
||||||
);
|
);
|
||||||
|
|
||||||
canvas.DrawRect(ledRectangle, ledPaint);
|
canvas.DrawRect(ledRectangle, ledPaint);
|
||||||
}
|
}
|
||||||
|
}, "Failed to render");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void Initialize()
|
internal override void Initialize()
|
||||||
{
|
{
|
||||||
InitializeProperties();
|
TryOrBreak(InitializeProperties, "Failed to initialize");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using Artemis.Core.Services;
|
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace Artemis.Core.LayerEffects
|
namespace Artemis.Core.LayerEffects
|
||||||
@ -7,7 +6,7 @@ namespace Artemis.Core.LayerEffects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// For internal use only, please use <see cref="LayerEffect{T}" /> instead
|
/// For internal use only, please use <see cref="LayerEffect{T}" /> instead
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class BaseLayerEffect : CorePropertyChanged, IDisposable
|
public abstract class BaseLayerEffect : BreakableModel, IDisposable
|
||||||
{
|
{
|
||||||
private ILayerEffectConfigurationDialog? _configurationDialog;
|
private ILayerEffectConfigurationDialog? _configurationDialog;
|
||||||
private LayerEffectDescriptor _descriptor;
|
private LayerEffectDescriptor _descriptor;
|
||||||
@ -182,6 +181,22 @@ namespace Artemis.Core.LayerEffects
|
|||||||
|
|
||||||
internal virtual string GetEffectTypeName() => GetType().Name;
|
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>
|
/// <summary>
|
||||||
/// Enables the layer effect if it isn't already enabled
|
/// Enables the layer effect if it isn't already enabled
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -205,5 +220,12 @@ namespace Artemis.Core.LayerEffects
|
|||||||
DisableLayerEffect();
|
DisableLayerEffect();
|
||||||
Enabled = false;
|
Enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Overrides of BreakableModel
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string BrokenDisplayName => Name;
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -10,7 +10,7 @@
|
|||||||
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
|
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
|
||||||
xmlns:s="https://github.com/canton7/Stylet"
|
xmlns:s="https://github.com/canton7/Stylet"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Unhandled exception"
|
Title="Exception | Artemis"
|
||||||
Background="{DynamicResource MaterialDesignPaper}"
|
Background="{DynamicResource MaterialDesignPaper}"
|
||||||
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
|
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
|
||||||
UseLayoutRounding="True"
|
UseLayoutRounding="True"
|
||||||
|
|||||||
@ -24,8 +24,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions
|
|||||||
: base(dataModelConditionListPredicate, modules, profileEditorService, dataModelUIService, conditionOperatorService, settingsService)
|
: base(dataModelConditionListPredicate, modules, profileEditorService, dataModelUIService, conditionOperatorService, settingsService)
|
||||||
{
|
{
|
||||||
_dataModelUIService = dataModelUIService;
|
_dataModelUIService = dataModelUIService;
|
||||||
DataModelPathSegment dataModelPathSegment = dataModelConditionListPredicate.LeftPath.Segments.ToList()[1];
|
|
||||||
var segmentDescription = dataModelPathSegment.GetPropertyDescription();
|
|
||||||
LeftSideColor = new SolidColorBrush(Color.FromRgb(71, 108, 188));
|
LeftSideColor = new SolidColorBrush(Color.FromRgb(71, 108, 188));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -501,11 +501,17 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
|||||||
|
|
||||||
public void GoToEnd()
|
public void GoToEnd()
|
||||||
{
|
{
|
||||||
|
if (SelectedProfileElement == null)
|
||||||
|
return;
|
||||||
|
|
||||||
ProfileEditorService.CurrentTime = SelectedProfileElement.Timeline.EndSegmentEndPosition;
|
ProfileEditorService.CurrentTime = SelectedProfileElement.Timeline.EndSegmentEndPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GoToPreviousFrame()
|
public void GoToPreviousFrame()
|
||||||
{
|
{
|
||||||
|
if (SelectedProfileElement == null)
|
||||||
|
return;
|
||||||
|
|
||||||
double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 25).Value;
|
double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 25).Value;
|
||||||
double newTime = Math.Max(0, Math.Round((ProfileEditorService.CurrentTime.TotalMilliseconds - frameTime) / frameTime) * frameTime);
|
double newTime = Math.Max(0, Math.Round((ProfileEditorService.CurrentTime.TotalMilliseconds - frameTime) / frameTime) * frameTime);
|
||||||
ProfileEditorService.CurrentTime = TimeSpan.FromMilliseconds(newTime);
|
ProfileEditorService.CurrentTime = TimeSpan.FromMilliseconds(newTime);
|
||||||
@ -513,6 +519,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
|||||||
|
|
||||||
public void GoToNextFrame()
|
public void GoToNextFrame()
|
||||||
{
|
{
|
||||||
|
if (SelectedProfileElement == null)
|
||||||
|
return;
|
||||||
|
|
||||||
double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 25).Value;
|
double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 25).Value;
|
||||||
double newTime = Math.Round((ProfileEditorService.CurrentTime.TotalMilliseconds + frameTime) / frameTime) * frameTime;
|
double newTime = Math.Round((ProfileEditorService.CurrentTime.TotalMilliseconds + frameTime) / frameTime) * frameTime;
|
||||||
newTime = Math.Min(newTime, SelectedProfileElement.Timeline.EndSegmentEndPosition.TotalMilliseconds);
|
newTime = Math.Min(newTime, SelectedProfileElement.Timeline.EndSegmentEndPosition.TotalMilliseconds);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Timers;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
@ -20,11 +21,13 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
|||||||
private bool _draggingTreeView;
|
private bool _draggingTreeView;
|
||||||
private TreeItemViewModel _selectedTreeItem;
|
private TreeItemViewModel _selectedTreeItem;
|
||||||
private bool _updatingTree;
|
private bool _updatingTree;
|
||||||
|
private readonly Timer _timer;
|
||||||
|
|
||||||
public ProfileTreeViewModel(IProfileEditorService profileEditorService, IProfileTreeVmFactory profileTreeVmFactory)
|
public ProfileTreeViewModel(IProfileEditorService profileEditorService, IProfileTreeVmFactory profileTreeVmFactory)
|
||||||
{
|
{
|
||||||
_profileEditorService = profileEditorService;
|
_profileEditorService = profileEditorService;
|
||||||
_profileTreeVmFactory = profileTreeVmFactory;
|
_profileTreeVmFactory = profileTreeVmFactory;
|
||||||
|
_timer = new Timer(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreeItemViewModel SelectedTreeItem
|
public TreeItemViewModel SelectedTreeItem
|
||||||
@ -54,12 +57,15 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
|||||||
{
|
{
|
||||||
Subscribe();
|
Subscribe();
|
||||||
CreateRootFolderViewModel();
|
CreateRootFolderViewModel();
|
||||||
|
_timer.Start();
|
||||||
base.OnInitialActivate();
|
base.OnInitialActivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnClose()
|
protected override void OnClose()
|
||||||
{
|
{
|
||||||
Unsubscribe();
|
Unsubscribe();
|
||||||
|
_timer.Stop();
|
||||||
|
_timer.Dispose();
|
||||||
base.OnClose();
|
base.OnClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,12 +209,14 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
|||||||
{
|
{
|
||||||
_profileEditorService.SelectedProfileChanged += OnSelectedProfileChanged;
|
_profileEditorService.SelectedProfileChanged += OnSelectedProfileChanged;
|
||||||
_profileEditorService.SelectedProfileElementChanged += OnSelectedProfileElementChanged;
|
_profileEditorService.SelectedProfileElementChanged += OnSelectedProfileElementChanged;
|
||||||
|
_timer.Elapsed += TimerOnElapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Unsubscribe()
|
private void Unsubscribe()
|
||||||
{
|
{
|
||||||
_profileEditorService.SelectedProfileChanged -= OnSelectedProfileChanged;
|
_profileEditorService.SelectedProfileChanged -= OnSelectedProfileChanged;
|
||||||
_profileEditorService.SelectedProfileElementChanged -= OnSelectedProfileElementChanged;
|
_profileEditorService.SelectedProfileElementChanged -= OnSelectedProfileElementChanged;
|
||||||
|
_timer.Elapsed -= TimerOnElapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSelectedProfileElementChanged(object sender, RenderProfileElementEventArgs e)
|
private void OnSelectedProfileElementChanged(object sender, RenderProfileElementEventArgs e)
|
||||||
@ -242,6 +250,11 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
|||||||
CreateRootFolderViewModel();
|
CreateRootFolderViewModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TimerOnElapsed(object sender, ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
ActiveItem?.UpdateBrokenState();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +1,20 @@
|
|||||||
<UserControl
|
<UserControl
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:s="https://github.com/canton7/Stylet"
|
xmlns:s="https://github.com/canton7/Stylet"
|
||||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||||
xmlns:treeItem1="clr-namespace:Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem"
|
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"
|
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||||
mc:Ignorable="d"
|
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||||
d:DesignHeight="450" d:DesignWidth="800"
|
x:Class="Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem.FolderView"
|
||||||
d:DataContext="{d:DesignInstance {x:Type treeItem1:FolderViewModel}}">
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800"
|
||||||
|
d:DataContext="{d:DesignInstance {x:Type treeItem1:FolderViewModel}}">
|
||||||
<UserControl.Resources>
|
<UserControl.Resources>
|
||||||
<Converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
|
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
||||||
|
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||||
</UserControl.Resources>
|
</UserControl.Resources>
|
||||||
<!-- Capture clicks on full tree view item -->
|
<!-- Capture clicks on full tree view item -->
|
||||||
<StackPanel Margin="-10" Background="Transparent" ContextMenuOpening="{s:Action ContextMenuOpening}">
|
<StackPanel Margin="-10" Background="Transparent" ContextMenuOpening="{s:Action ContextMenuOpening}">
|
||||||
@ -58,18 +61,32 @@
|
|||||||
</StackPanel.ContextMenu>
|
</StackPanel.ContextMenu>
|
||||||
<Grid Margin="10">
|
<Grid Margin="10">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
</Grid.ColumnDefinitions>
|
</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"
|
Kind="Folder"
|
||||||
Visibility="{Binding IsExpanded, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}" />
|
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"
|
Kind="FolderOpen"
|
||||||
Visibility="{Binding IsExpanded, Converter={x:Static s:BoolToVisibilityConverter.Instance}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}" />
|
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" />
|
<TextBlock Grid.Column="2" Text="{Binding ProfileElement.Name}" Margin="10 0 0 0" VerticalAlignment="Center" />
|
||||||
<ToggleButton Grid.Column="2"
|
<ToggleButton Grid.Column="3"
|
||||||
Style="{StaticResource MaterialDesignFlatToggleButton}"
|
Style="{StaticResource MaterialDesignFlatToggleButton}"
|
||||||
ToolTip="Toggle suspended state"
|
ToolTip="Toggle suspended state"
|
||||||
Width="18"
|
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;
|
||||||
|
using Artemis.Core.LayerEffects;
|
||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.UI.Ninject.Factories;
|
using Artemis.UI.Ninject.Factories;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
@ -27,12 +31,28 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
|||||||
set => ((Folder) ProfileElement).IsExpanded = value;
|
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)
|
private void ProfileElementOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.PropertyName == nameof(Folder.IsExpanded))
|
if (e.PropertyName == nameof(Folder.IsExpanded))
|
||||||
NotifyOfPropertyChange(nameof(IsExpanded));
|
NotifyOfPropertyChange(nameof(IsExpanded));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region Overrides of Screen
|
#region Overrides of Screen
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -6,14 +6,15 @@
|
|||||||
xmlns:s="https://github.com/canton7/Stylet"
|
xmlns:s="https://github.com/canton7/Stylet"
|
||||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||||
xmlns:treeItem1="clr-namespace:Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem"
|
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"
|
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||||
x:Class="Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem.LayerView"
|
x:Class="Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem.LayerView"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="450" d:DesignWidth="800"
|
d:DesignHeight="450" d:DesignWidth="800"
|
||||||
d:DataContext="{d:DesignInstance {x:Type treeItem1:LayerViewModel}}">
|
d:DataContext="{d:DesignInstance {x:Type treeItem1:LayerViewModel}}">
|
||||||
<UserControl.Resources>
|
<UserControl.Resources>
|
||||||
<Converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
||||||
|
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||||
</UserControl.Resources>
|
</UserControl.Resources>
|
||||||
<!-- Capture clicks on full tree view item -->
|
<!-- Capture clicks on full tree view item -->
|
||||||
<StackPanel Margin="-10" Background="Transparent" ContextMenuOpening="{s:Action ContextMenuOpening}">
|
<StackPanel Margin="-10" Background="Transparent" ContextMenuOpening="{s:Action ContextMenuOpening}">
|
||||||
@ -55,13 +56,27 @@
|
|||||||
</StackPanel.ContextMenu>
|
</StackPanel.ContextMenu>
|
||||||
<Grid Margin="10">
|
<Grid Margin="10">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<materialDesign:PackIcon Grid.Column="0" Kind="Layers" Width="16" VerticalAlignment="Center" />
|
<Button Grid.Column="0"
|
||||||
<shared:ArtemisIcon Grid.Column="1"
|
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"
|
VerticalAlignment="Center"
|
||||||
Icon="{Binding Layer.LayerBrush.Descriptor.Icon}"
|
Icon="{Binding Layer.LayerBrush.Descriptor.Icon}"
|
||||||
Width="16"
|
Width="16"
|
||||||
@ -69,8 +84,8 @@
|
|||||||
ToolTip="{Binding Layer.LayerBrush.Descriptor.DisplayName, Mode=OneWay}"
|
ToolTip="{Binding Layer.LayerBrush.Descriptor.DisplayName, Mode=OneWay}"
|
||||||
Visibility="{Binding ShowIcons, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"
|
Visibility="{Binding ShowIcons, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"
|
||||||
Background="Transparent" />
|
Background="Transparent" />
|
||||||
<TextBlock Grid.Column="2" Text="{Binding Layer.Name}" VerticalAlignment="Center" Margin="5 0 0 0" />
|
<TextBlock Grid.Column="3" Text="{Binding Layer.Name}" VerticalAlignment="Center" Margin="5 0 0 0" />
|
||||||
<ToggleButton Grid.Column="3"
|
<ToggleButton Grid.Column="4"
|
||||||
Style="{StaticResource MaterialDesignFlatToggleButton}"
|
Style="{StaticResource MaterialDesignFlatToggleButton}"
|
||||||
Width="18"
|
Width="18"
|
||||||
Height="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.Core.Services;
|
||||||
using Artemis.UI.Ninject.Factories;
|
using Artemis.UI.Ninject.Factories;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
@ -9,7 +14,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
|||||||
public class LayerViewModel : TreeItemViewModel
|
public class LayerViewModel : TreeItemViewModel
|
||||||
{
|
{
|
||||||
private readonly IWindowManager _windowManager;
|
private readonly IWindowManager _windowManager;
|
||||||
private ILayerHintVmFactory _vmFactory;
|
private readonly ILayerHintVmFactory _vmFactory;
|
||||||
|
|
||||||
public LayerViewModel(ProfileElement layer,
|
public LayerViewModel(ProfileElement layer,
|
||||||
IRgbService rgbService,
|
IRgbService rgbService,
|
||||||
@ -25,15 +30,27 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
|||||||
_vmFactory = vmFactory;
|
_vmFactory = vmFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenAdaptionHints()
|
|
||||||
{
|
|
||||||
_windowManager.ShowDialog(_vmFactory.LayerHintsDialogViewModel(Layer));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Layer Layer => ProfileElement as Layer;
|
public Layer Layer => ProfileElement as Layer;
|
||||||
public bool ShowIcons => Layer?.LayerBrush != null;
|
public bool ShowIcons => Layer?.LayerBrush != null;
|
||||||
public override bool SupportsChildren => false;
|
public override bool SupportsChildren => false;
|
||||||
|
|
||||||
public override bool IsExpanded { get; set; }
|
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 IProfileTreeVmFactory _profileTreeVmFactory;
|
||||||
private readonly IRgbService _rgbService;
|
private readonly IRgbService _rgbService;
|
||||||
private ProfileElement _profileElement;
|
private ProfileElement _profileElement;
|
||||||
|
private string _brokenState;
|
||||||
|
|
||||||
protected TreeItemViewModel(ProfileElement profileElement,
|
protected TreeItemViewModel(ProfileElement profileElement,
|
||||||
IRgbService rgbService,
|
IRgbService rgbService,
|
||||||
@ -49,6 +50,12 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
|||||||
set => SetAndNotify(ref _profileElement, value);
|
set => SetAndNotify(ref _profileElement, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string BrokenState
|
||||||
|
{
|
||||||
|
get => _brokenState;
|
||||||
|
set => SetAndNotify(ref _brokenState, value);
|
||||||
|
}
|
||||||
|
|
||||||
public bool CanPasteElement => _profileEditorService.GetCanPasteProfileElement();
|
public bool CanPasteElement => _profileEditorService.GetCanPasteProfileElement();
|
||||||
|
|
||||||
public abstract bool SupportsChildren { get; }
|
public abstract bool SupportsChildren { get; }
|
||||||
@ -286,6 +293,23 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
|||||||
NotifyOfPropertyChange(nameof(CanPasteElement));
|
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()
|
private void Subscribe()
|
||||||
{
|
{
|
||||||
ProfileElement.ChildAdded += ProfileElementOnChildAdded;
|
ProfileElement.ChildAdded += ProfileElementOnChildAdded;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user