mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Merge branch 'feature/keyframe-copy-aste'
This commit is contained in:
commit
7805581c70
@ -16,10 +16,15 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// Gets the description attribute applied to this property
|
||||
/// </summary>
|
||||
public PropertyDescriptionAttribute PropertyDescription { get; }
|
||||
PropertyDescriptionAttribute PropertyDescription { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique path of the property on the layer
|
||||
/// The parent group of this layer property, set after construction
|
||||
/// </summary>
|
||||
LayerPropertyGroup LayerPropertyGroup { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique path of the property on the layer
|
||||
/// </summary>
|
||||
public string Path { get; }
|
||||
|
||||
@ -30,7 +35,7 @@ namespace Artemis.Core
|
||||
/// <see cref="LayerProperty{T}" />
|
||||
/// </para>
|
||||
/// </summary>
|
||||
void Initialize(RenderProfileElement profileElement, LayerPropertyGroup @group, PropertyEntity entity, bool fromStorage, PropertyDescriptionAttribute description, string path);
|
||||
void Initialize(RenderProfileElement profileElement, LayerPropertyGroup group, PropertyEntity entity, bool fromStorage, PropertyDescriptionAttribute description, string path);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list off all data binding registrations
|
||||
@ -38,7 +43,14 @@ namespace Artemis.Core
|
||||
List<IDataBindingRegistration> GetAllDataBindingRegistrations();
|
||||
|
||||
/// <summary>
|
||||
/// Updates the layer properties internal state
|
||||
/// Attempts to load and add the provided keyframe entity to the layer property
|
||||
/// </summary>
|
||||
/// <param name="keyframeEntity">The entity representing the keyframe to add</param>
|
||||
/// <returns>If succeeded the resulting keyframe, otherwise <see langword="null" /></returns>
|
||||
ILayerPropertyKeyframe? AddKeyframeEntity(KeyframeEntity keyframeEntity);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the layer properties internal state
|
||||
/// </summary>
|
||||
/// <param name="timeline">The timeline to apply to the property</param>
|
||||
void Update(Timeline timeline);
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a keyframe on a <see cref="ILayerProperty" /> containing a value and a timestamp
|
||||
/// </summary>
|
||||
public interface ILayerPropertyKeyframe
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an untyped reference to the layer property of this keyframe
|
||||
/// </summary>
|
||||
ILayerProperty UntypedLayerProperty { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The position of this keyframe in the timeline
|
||||
/// </summary>
|
||||
TimeSpan Position { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The easing function applied on the value of the keyframe
|
||||
/// </summary>
|
||||
Easings.Functions EasingFunction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entity this keyframe uses for persistent storage
|
||||
/// </summary>
|
||||
KeyframeEntity GetKeyframeEntity();
|
||||
|
||||
/// <summary>
|
||||
/// Removes the keyframe from the layer property
|
||||
/// </summary>
|
||||
void Remove();
|
||||
}
|
||||
}
|
||||
@ -118,9 +118,7 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public RenderProfileElement ProfileElement { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The parent group of this layer property, set after construction
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public LayerPropertyGroup LayerPropertyGroup { get; internal set; }
|
||||
|
||||
#endregion
|
||||
@ -282,6 +280,22 @@ namespace Artemis.Core
|
||||
OnKeyframeAdded();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ILayerPropertyKeyframe? AddKeyframeEntity(KeyframeEntity keyframeEntity)
|
||||
{
|
||||
if (keyframeEntity.Position > ProfileElement.Timeline.Length)
|
||||
return null;
|
||||
T value = CoreJson.DeserializeObject<T>(keyframeEntity.Value);
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
LayerPropertyKeyframe<T> keyframe = new LayerPropertyKeyframe<T>(
|
||||
CoreJson.DeserializeObject<T>(keyframeEntity.Value)!, keyframeEntity.Position, (Easings.Functions) keyframeEntity.EasingFunction, this
|
||||
);
|
||||
AddKeyframe(keyframe);
|
||||
return keyframe;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a keyframe from the layer property
|
||||
/// </summary>
|
||||
@ -508,6 +522,7 @@ namespace Artemis.Core
|
||||
if (!IsLoadedFromStorage)
|
||||
ApplyDefaultValue(null);
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Entity.Value != null)
|
||||
@ -517,6 +532,7 @@ namespace Artemis.Core
|
||||
{
|
||||
// ignored for now
|
||||
}
|
||||
}
|
||||
|
||||
CurrentValue = BaseValue;
|
||||
KeyframesEnabled = Entity.KeyframesEnabled;
|
||||
@ -524,12 +540,8 @@ namespace Artemis.Core
|
||||
_keyframes.Clear();
|
||||
try
|
||||
{
|
||||
_keyframes.AddRange(Entity.KeyframeEntities
|
||||
.Where(k => k.Position <= ProfileElement.Timeline.Length)
|
||||
.Select(k => new LayerPropertyKeyframe<T>(
|
||||
CoreJson.DeserializeObject<T>(k.Value)!, k.Position, (Easings.Functions) k.EasingFunction, this
|
||||
))
|
||||
);
|
||||
foreach (KeyframeEntity keyframeEntity in Entity.KeyframeEntities.Where(k => k.Position <= ProfileElement.Timeline.Length))
|
||||
AddKeyframeEntity(keyframeEntity);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
@ -559,12 +571,7 @@ namespace Artemis.Core
|
||||
Entity.Value = CoreJson.SerializeObject(BaseValue);
|
||||
Entity.KeyframesEnabled = KeyframesEnabled;
|
||||
Entity.KeyframeEntities.Clear();
|
||||
Entity.KeyframeEntities.AddRange(Keyframes.Select(k => new KeyframeEntity
|
||||
{
|
||||
Value = CoreJson.SerializeObject(k.Value),
|
||||
Position = k.Position,
|
||||
EasingFunction = (int) k.EasingFunction
|
||||
}));
|
||||
Entity.KeyframeEntities.AddRange(Keyframes.Select(k => k.GetKeyframeEntity()));
|
||||
|
||||
Entity.DataBindingEntities.Clear();
|
||||
foreach (IDataBinding dataBinding in _dataBindings)
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a keyframe on a <see cref="LayerProperty{T}" /> containing a value and a timestamp
|
||||
/// </summary>
|
||||
public class LayerPropertyKeyframe<T> : CorePropertyChanged
|
||||
public class LayerPropertyKeyframe<T> : CorePropertyChanged, ILayerPropertyKeyframe
|
||||
{
|
||||
private LayerProperty<T> _layerProperty;
|
||||
private TimeSpan _position;
|
||||
@ -45,10 +46,10 @@ namespace Artemis.Core
|
||||
set => SetAndNotify(ref _value, value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The position of this keyframe in the timeline
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public ILayerProperty UntypedLayerProperty => LayerProperty;
|
||||
|
||||
/// <inheritdoc />
|
||||
public TimeSpan Position
|
||||
{
|
||||
get => _position;
|
||||
@ -59,14 +60,21 @@ namespace Artemis.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The easing function applied on the value of the keyframe
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public Easings.Functions EasingFunction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Removes the keyframe from the layer property
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public KeyframeEntity GetKeyframeEntity()
|
||||
{
|
||||
return new KeyframeEntity
|
||||
{
|
||||
Value = CoreJson.SerializeObject(Value),
|
||||
Position = Position,
|
||||
EasingFunction = (int) EasingFunction
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Remove()
|
||||
{
|
||||
LayerProperty.RemoveKeyframe(this);
|
||||
|
||||
@ -123,7 +123,7 @@ namespace Artemis.Core
|
||||
/// Adds a profile element to the <see cref="Children" /> collection, optionally at the given position (1-based)
|
||||
/// </summary>
|
||||
/// <param name="child">The profile element to add</param>
|
||||
/// <param name="order">The order where to place the child (1-based), defaults to the end of the collection</param>
|
||||
/// <param name="order">The order where to place the child (0-based), defaults to the end of the collection</param>
|
||||
public virtual void AddChild(ProfileElement child, int? order = null)
|
||||
{
|
||||
if (Disposed)
|
||||
@ -136,31 +136,19 @@ namespace Artemis.Core
|
||||
|
||||
// Add to the end of the list
|
||||
if (order == null)
|
||||
{
|
||||
ChildrenList.Add(child);
|
||||
child.Order = ChildrenList.Count;
|
||||
}
|
||||
// Shift everything after the given order
|
||||
// Insert at the given index
|
||||
else
|
||||
{
|
||||
if (order < 0)
|
||||
order = 0;
|
||||
foreach (ProfileElement profileElement in ChildrenList.Where(c => c.Order >= order).ToList())
|
||||
profileElement.Order++;
|
||||
|
||||
int targetIndex;
|
||||
if (order == 0)
|
||||
targetIndex = 0;
|
||||
else if (order > ChildrenList.Count)
|
||||
targetIndex = ChildrenList.Count;
|
||||
else
|
||||
targetIndex = ChildrenList.FindIndex(c => c.Order == order + 1);
|
||||
|
||||
ChildrenList.Insert(targetIndex, child);
|
||||
child.Order = order.Value;
|
||||
if (order > ChildrenList.Count)
|
||||
order = ChildrenList.Count;
|
||||
ChildrenList.Insert(order.Value, child);
|
||||
}
|
||||
|
||||
child.Parent = this;
|
||||
StreamlineOrder();
|
||||
}
|
||||
|
||||
OnChildAdded();
|
||||
@ -178,10 +166,7 @@ namespace Artemis.Core
|
||||
lock (ChildrenList)
|
||||
{
|
||||
ChildrenList.Remove(child);
|
||||
|
||||
// Shift everything after the given order
|
||||
foreach (ProfileElement profileElement in ChildrenList.Where(c => c.Order > child.Order).ToList())
|
||||
profileElement.Order--;
|
||||
StreamlineOrder();
|
||||
|
||||
child.Parent = null;
|
||||
}
|
||||
@ -189,6 +174,12 @@ namespace Artemis.Core
|
||||
OnChildRemoved();
|
||||
}
|
||||
|
||||
private void StreamlineOrder()
|
||||
{
|
||||
for (int index = 0; index < ChildrenList.Count; index++)
|
||||
ChildrenList[index].Order = index;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a flattened list of all child folders
|
||||
/// </summary>
|
||||
|
||||
@ -43,7 +43,7 @@
|
||||
<PackageReference Include="SharpVectors.Reloaded" Version="1.6.0" />
|
||||
<PackageReference Include="SkiaSharp" Version="2.80.2" />
|
||||
<PackageReference Include="SkiaSharp.Views.WPF" Version="2.80.2" />
|
||||
<PackageReference Include="Stylet" Version="1.3.4" />
|
||||
<PackageReference Include="Stylet" Version="1.3.5" />
|
||||
<PackageReference Include="System.Buffers" Version="4.5.0" />
|
||||
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
|
||||
<PackageReference Include="Unclassified.NetRevisionTask" Version="0.3.0">
|
||||
|
||||
@ -156,6 +156,11 @@ namespace Artemis.UI.Shared.Services
|
||||
/// <returns>The pasted render element</returns>
|
||||
ProfileElement? PasteProfileElement(Folder target, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether a profile element is on the clipboard
|
||||
/// </summary>
|
||||
bool GetCanPasteProfileElement();
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a new profile is selected
|
||||
/// </summary>
|
||||
|
||||
@ -384,6 +384,12 @@ namespace Artemis.UI.Shared.Services
|
||||
return clipboardObject != null ? PasteClipboardData(clipboardObject, target, position) : null;
|
||||
}
|
||||
|
||||
public bool GetCanPasteProfileElement()
|
||||
{
|
||||
object? clipboardObject = JsonClipboard.GetData();
|
||||
return clipboardObject is LayerEntity || clipboardObject is FolderClipboardModel;
|
||||
}
|
||||
|
||||
private RenderProfileElement? PasteClipboardData(object clipboardObject, Folder target, int position)
|
||||
{
|
||||
RenderProfileElement? pasted = null;
|
||||
|
||||
@ -85,9 +85,9 @@
|
||||
},
|
||||
"Stylet": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.3.4, )",
|
||||
"resolved": "1.3.4",
|
||||
"contentHash": "bCEdA+AIi+TM9SQQGLYMsFRIfzZcDUDg2Mznyr72kOkcC/cdBj01/jel4/v2aoKwbFcxVjiqmpgnbsFgMEZ4zQ==",
|
||||
"requested": "[1.3.5, )",
|
||||
"resolved": "1.3.5",
|
||||
"contentHash": "9vjjaTgf5sZAGHnxQWIslD32MG5gXj7ANgS+w965L5Eh//UC3qwZDrEf226Pf+v1P/ldAJDpUySnOyGlb3TSSw==",
|
||||
"dependencies": {
|
||||
"System.Drawing.Common": "4.6.0"
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@
|
||||
<PackageReference Include="RawInput.Sharp" Version="0.0.3" />
|
||||
<PackageReference Include="Serilog" Version="2.9.0" />
|
||||
<PackageReference Include="SkiaSharp.Views.WPF" Version="2.80.2" />
|
||||
<PackageReference Include="Stylet" Version="1.3.4" />
|
||||
<PackageReference Include="Stylet" Version="1.3.5" />
|
||||
<PackageReference Include="System.Buffers" Version="4.5.0" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.Xaml.Behaviors;
|
||||
|
||||
namespace Artemis.UI.Behaviors
|
||||
@ -105,7 +106,8 @@ namespace Artemis.UI.Behaviors
|
||||
{
|
||||
item.IsSelected = true;
|
||||
// Focus the newly selected item as if was clicked
|
||||
item.Focus();
|
||||
if (FocusManager.GetIsFocusScope(item))
|
||||
item.Focus();
|
||||
if (ExpandSelected)
|
||||
item.IsExpanded = true;
|
||||
}
|
||||
|
||||
@ -160,7 +160,9 @@
|
||||
VerticalScrollBarVisibility="Hidden"
|
||||
ScrollChanged="TimelineScrollChanged">
|
||||
<Border BorderThickness="0,0,1,0" BorderBrush="{DynamicResource MaterialDesignDivider}">
|
||||
<ContentControl s:View.Model="{Binding TreeViewModel}" />
|
||||
<ContentControl s:View.Model="{Binding TreeViewModel}"
|
||||
shared:SizeObserver.Observe="True"
|
||||
shared:SizeObserver.ObservedHeight="{Binding TreeViewModelHeight, Mode=OneWayToSource}"/>
|
||||
</Border>
|
||||
</ScrollViewer>
|
||||
<materialDesign:TransitionerSlide>
|
||||
@ -197,6 +199,12 @@
|
||||
<materialDesign:CircleWipe />
|
||||
</materialDesign:TransitionerSlide.BackwardWipe>
|
||||
<Grid>
|
||||
<Grid.InputBindings>
|
||||
<KeyBinding Key="Delete" Command="{s:Action DeleteKeyframes}" s:View.ActionTarget="{Binding TimelineViewModel}"/>
|
||||
<KeyBinding Key="D" Modifiers="Control" Command="{s:Action DuplicateKeyframes}" s:View.ActionTarget="{Binding TimelineViewModel}" />
|
||||
<KeyBinding Key="C" Modifiers="Control" Command="{s:Action CopyKeyframes}" s:View.ActionTarget="{Binding TimelineViewModel}"/>
|
||||
<KeyBinding Key="V" Modifiers="Control" Command="{s:Action PasteKeyframes}" s:View.ActionTarget="{Binding TimelineViewModel}"/>
|
||||
</Grid.InputBindings>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="48" />
|
||||
<RowDefinition Height="*" />
|
||||
@ -204,7 +212,11 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Timeline headers -->
|
||||
<ScrollViewer Grid.Row="0" x:Name="TimelineHeaderScrollViewer" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" ScrollChanged="TimelineScrollChanged">
|
||||
<ScrollViewer Grid.Row="0"
|
||||
x:Name="TimelineHeaderScrollViewer"
|
||||
HorizontalScrollBarVisibility="Hidden"
|
||||
VerticalScrollBarVisibility="Hidden"
|
||||
ScrollChanged="TimelineScrollChanged">
|
||||
<Canvas Background="{DynamicResource MaterialDesignCardBackground}" Width="{Binding ActualWidth, ElementName=PropertyTimeLine}">
|
||||
<!-- Timeline segments -->
|
||||
<ContentControl Canvas.Left="{Binding EndTimelineSegmentViewModel.SegmentStartPosition}" s:View.Model="{Binding EndTimelineSegmentViewModel}" />
|
||||
|
||||
@ -35,6 +35,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
private int _rightSideIndex;
|
||||
private RenderProfileElement _selectedProfileElement;
|
||||
private DateTime _lastEffectsViewModelToggle;
|
||||
private double _treeViewModelHeight;
|
||||
|
||||
public LayerPropertiesViewModel(IProfileEditorService profileEditorService,
|
||||
ICoreService coreService,
|
||||
@ -157,6 +158,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
|
||||
public Layer SelectedLayer => SelectedProfileElement as Layer;
|
||||
public Folder SelectedFolder => SelectedProfileElement as Folder;
|
||||
|
||||
public double TreeViewModelHeight
|
||||
{
|
||||
get => _treeViewModelHeight;
|
||||
set => SetAndNotify(ref _treeViewModelHeight, value);
|
||||
}
|
||||
|
||||
|
||||
#region Segments
|
||||
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.UI.Exceptions;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Models
|
||||
{
|
||||
public class KeyframesClipboardModel
|
||||
{
|
||||
// ReSharper disable once UnusedMember.Global - For JSON.NET
|
||||
public KeyframesClipboardModel()
|
||||
{
|
||||
ClipboardModels = new List<KeyframeClipboardModel>();
|
||||
}
|
||||
|
||||
public KeyframesClipboardModel(IEnumerable<ILayerPropertyKeyframe> keyframes)
|
||||
{
|
||||
ClipboardModels = new List<KeyframeClipboardModel>();
|
||||
foreach (ILayerPropertyKeyframe keyframe in keyframes.OrderBy(k => k.Position))
|
||||
ClipboardModels.Add(new KeyframeClipboardModel(keyframe));
|
||||
}
|
||||
|
||||
public List<KeyframeClipboardModel> ClipboardModels { get; set; }
|
||||
public bool HasBeenPasted { get; set; }
|
||||
|
||||
public List<ILayerPropertyKeyframe> Paste(RenderProfileElement target, TimeSpan pastePosition)
|
||||
{
|
||||
if (target == null) throw new ArgumentNullException(nameof(target));
|
||||
if (HasBeenPasted)
|
||||
throw new ArtemisUIException("Clipboard model can only be pasted once");
|
||||
|
||||
List<ILayerPropertyKeyframe> results = new List<ILayerPropertyKeyframe>();
|
||||
if (!ClipboardModels.Any())
|
||||
return results;
|
||||
|
||||
// Determine the offset by looking at the position of the first keyframe, start pasting from there
|
||||
TimeSpan offset = pastePosition - ClipboardModels.First().KeyframeEntity.Position;
|
||||
List<ILayerProperty> properties = target.GetAllLayerProperties();
|
||||
foreach (KeyframeClipboardModel clipboardModel in ClipboardModels)
|
||||
{
|
||||
ILayerPropertyKeyframe layerPropertyKeyframe = clipboardModel.Paste(properties, offset);
|
||||
if (layerPropertyKeyframe != null)
|
||||
results.Add(layerPropertyKeyframe);
|
||||
}
|
||||
|
||||
HasBeenPasted = true;
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
public class KeyframeClipboardModel
|
||||
{
|
||||
// ReSharper disable once UnusedMember.Global - For JSON.NET
|
||||
public KeyframeClipboardModel()
|
||||
{
|
||||
}
|
||||
|
||||
public KeyframeClipboardModel(ILayerPropertyKeyframe layerPropertyKeyframe)
|
||||
{
|
||||
FeatureId = layerPropertyKeyframe.UntypedLayerProperty.LayerPropertyGroup.Feature.Id;
|
||||
Path = layerPropertyKeyframe.UntypedLayerProperty.Path;
|
||||
KeyframeEntity = layerPropertyKeyframe.GetKeyframeEntity();
|
||||
}
|
||||
|
||||
public string FeatureId { get; set; }
|
||||
public string Path { get; set; }
|
||||
public KeyframeEntity KeyframeEntity { get; set; }
|
||||
|
||||
public ILayerPropertyKeyframe Paste(List<ILayerProperty> properties, TimeSpan offset)
|
||||
{
|
||||
ILayerProperty property = properties.FirstOrDefault(p => p.LayerPropertyGroup.Feature.Id == FeatureId && p.Path == Path);
|
||||
if (property != null)
|
||||
{
|
||||
KeyframeEntity.Position += offset;
|
||||
ILayerPropertyKeyframe keyframe = property.AddKeyframeEntity(KeyframeEntity);
|
||||
KeyframeEntity.Position -= offset;
|
||||
|
||||
return keyframe;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -48,6 +48,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
}
|
||||
|
||||
public TimeSpan Position => LayerPropertyKeyframe.Position;
|
||||
public ILayerPropertyKeyframe Keyframe => LayerPropertyKeyframe;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@ -158,35 +159,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
#endregion
|
||||
|
||||
#region Context menu actions
|
||||
|
||||
public void Copy()
|
||||
{
|
||||
LayerPropertyKeyframe<T> newKeyframe = new LayerPropertyKeyframe<T>(
|
||||
LayerPropertyKeyframe.Value,
|
||||
LayerPropertyKeyframe.Position,
|
||||
LayerPropertyKeyframe.EasingFunction,
|
||||
LayerPropertyKeyframe.LayerProperty
|
||||
);
|
||||
// If possible, shift the keyframe to the right by 11 pixels
|
||||
TimeSpan desiredPosition = newKeyframe.Position + TimeSpan.FromMilliseconds(1000f / _profileEditorService.PixelsPerSecond * 11);
|
||||
if (desiredPosition <= newKeyframe.LayerProperty.ProfileElement.Timeline.Length)
|
||||
newKeyframe.Position = desiredPosition;
|
||||
// Otherwise if possible shift it to the left by 11 pixels
|
||||
else
|
||||
{
|
||||
desiredPosition = newKeyframe.Position - TimeSpan.FromMilliseconds(1000f / _profileEditorService.PixelsPerSecond * 11);
|
||||
if (desiredPosition > TimeSpan.Zero)
|
||||
newKeyframe.Position = desiredPosition;
|
||||
}
|
||||
|
||||
LayerPropertyKeyframe.LayerProperty.AddKeyframe(newKeyframe);
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
|
||||
public void Delete(bool save = true)
|
||||
{
|
||||
LayerPropertyKeyframe.LayerProperty.RemoveKeyframe(LayerPropertyKeyframe);
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
if (save)
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -196,6 +174,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
{
|
||||
bool IsSelected { get; set; }
|
||||
TimeSpan Position { get; }
|
||||
ILayerPropertyKeyframe Keyframe { get; }
|
||||
|
||||
#region Movement
|
||||
|
||||
@ -210,8 +189,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
|
||||
void PopulateEasingViewModels();
|
||||
void ClearEasingViewModels();
|
||||
void Copy();
|
||||
void Delete();
|
||||
void Delete(bool save = true);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -36,8 +36,8 @@
|
||||
MouseDown="{s:Action KeyframeMouseDown}"
|
||||
MouseUp="{s:Action KeyframeMouseUp}"
|
||||
MouseMove="{s:Action KeyframeMouseMove}"
|
||||
ContextMenuOpening="{s:Action ContextMenuOpening}"
|
||||
ContextMenuClosing="{s:Action ContextMenuClosing}">
|
||||
ContextMenuOpening="{s:Action KeyframeContextMenuOpening}"
|
||||
ContextMenuClosing="{s:Action KeyframeContextMenuClosing}">
|
||||
<Ellipse.Style>
|
||||
<Style TargetType="{x:Type Ellipse}">
|
||||
<Style.Triggers>
|
||||
@ -62,17 +62,6 @@
|
||||
</Ellipse.Style>
|
||||
<Ellipse.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Copy" Command="{s:Action Copy}" CommandParameter="{Binding}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentCopy" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Delete" Command="{s:Action Delete}" CommandParameter="{Binding}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Delete" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Easing" ItemsSource="{Binding EasingViewModels}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Creation" />
|
||||
@ -98,6 +87,28 @@
|
||||
</DataTemplate>
|
||||
</MenuItem.ItemTemplate>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Duplicate" Command="{s:Action DuplicateKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+D">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentDuplicate" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Copy" Command="{s:Action CopyKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+C">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentCopy" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Paste" Command="{s:Action PasteKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+V">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentPaste" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Delete" Command="{s:Action DeleteKeyframes}" InputGestureText="Del">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Delete" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</Ellipse.ContextMenu>
|
||||
</Ellipse>
|
||||
|
||||
@ -5,33 +5,61 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="25"
|
||||
d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:TimelineViewModel}">
|
||||
<Grid x:Name="TimelineContainerGrid"
|
||||
Background="{DynamicResource MaterialDesignToolBarBackground}"
|
||||
<Grid Background="{DynamicResource MaterialDesignToolBarBackground}"
|
||||
MouseDown="{s:Action TimelineCanvasMouseDown}"
|
||||
MouseUp="{s:Action TimelineCanvasMouseUp}"
|
||||
MouseMove="{s:Action TimelineCanvasMouseMove}"
|
||||
Margin="0 0 -1 0">
|
||||
ContextMenuOpening="{s:Action ContextMenuOpening}"
|
||||
ContextMenuClosing="{s:Action ContextMenuClosing}"
|
||||
Height="{Binding LayerPropertiesViewModel.TreeViewModelHeight}"
|
||||
VerticalAlignment="Top"
|
||||
Focusable="True">
|
||||
<Grid.Triggers>
|
||||
<EventTrigger RoutedEvent="UIElement.MouseLeftButtonDown">
|
||||
<BeginStoryboard>
|
||||
<Storyboard Storyboard.TargetName="MultiSelectionPath" Storyboard.TargetProperty="Opacity">
|
||||
<DoubleAnimation From="0" To="1" Duration="0:0:0.1" />
|
||||
<DoubleAnimation To="1" Duration="0:0:0.1" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
<EventTrigger RoutedEvent="UIElement.MouseLeftButtonUp">
|
||||
<BeginStoryboard>
|
||||
<Storyboard Storyboard.TargetName="MultiSelectionPath" Storyboard.TargetProperty="Opacity">
|
||||
<DoubleAnimation From="1" To="0" Duration="0:0:0.2" />
|
||||
<DoubleAnimation To="0" Duration="0:0:0.2" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
</Grid.Triggers>
|
||||
|
||||
<Grid.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Duplicate" Command="{s:Action DuplicateKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+D">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentDuplicate" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Copy" Command="{s:Action CopyKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+C">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentCopy" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Paste" Command="{s:Action PasteKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+V" >
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentPaste" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Delete" Command="{s:Action DeleteKeyframes}" InputGestureText="Del">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Delete" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</Grid.ContextMenu>
|
||||
<ItemsControl ItemsSource="{Binding LayerPropertyGroups}"
|
||||
MinWidth="{Binding TotalTimelineWidth}"
|
||||
HorizontalAlignment="Left">
|
||||
@ -48,7 +76,7 @@
|
||||
X1="{Binding StartSegmentEndPosition}"
|
||||
X2="{Binding StartSegmentEndPosition}"
|
||||
Y1="0"
|
||||
Y2="{Binding ActualHeight, ElementName=TimelineContainerGrid}"
|
||||
Y2="{Binding LayerPropertiesViewModel.TreeViewModelHeight}"
|
||||
HorizontalAlignment="Left"
|
||||
Visibility="{Binding LayerPropertiesViewModel.StartTimelineSegmentViewModel.SegmentEnabled, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" />
|
||||
<Line Stroke="{StaticResource PrimaryHueDarkBrush}"
|
||||
@ -57,14 +85,14 @@
|
||||
X1="{Binding MainSegmentEndPosition}"
|
||||
X2="{Binding MainSegmentEndPosition}"
|
||||
Y1="0"
|
||||
Y2="{Binding ActualHeight, ElementName=TimelineContainerGrid}" />
|
||||
Y2="{Binding LayerPropertiesViewModel.TreeViewModelHeight}" />
|
||||
<Line Stroke="{StaticResource PrimaryHueDarkBrush}"
|
||||
Opacity="0.5"
|
||||
StrokeDashArray="4 2"
|
||||
X1="{Binding EndSegmentEndPosition}"
|
||||
X2="{Binding EndSegmentEndPosition}"
|
||||
Y1="0"
|
||||
Y2="{Binding ActualHeight, ElementName=TimelineContainerGrid}"
|
||||
Y2="{Binding LayerPropertiesViewModel.TreeViewModelHeight}"
|
||||
Visibility="{Binding LayerPropertiesViewModel.EndTimelineSegmentViewModel.SegmentEnabled, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" />
|
||||
|
||||
<!-- Multi-selection rectangle -->
|
||||
|
||||
@ -3,11 +3,15 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Models;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Shared.Services.Models;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
@ -151,31 +155,120 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
|
||||
#region Context menu actions
|
||||
|
||||
public void ContextMenuOpening(object sender, EventArgs e)
|
||||
public bool CanDuplicateKeyframes => GetAllKeyframeViewModels().Any(k => k.IsSelected);
|
||||
public bool CanCopyKeyframes => GetAllKeyframeViewModels().Any(k => k.IsSelected);
|
||||
public bool CanDeleteKeyframes => GetAllKeyframeViewModels().Any(k => k.IsSelected);
|
||||
public bool CanPasteKeyframes => JsonClipboard.GetData() is KeyframesClipboardModel;
|
||||
|
||||
private TimeSpan? _contextMenuOpenPosition;
|
||||
|
||||
public void ContextMenuOpening(object sender, ContextMenuEventArgs e)
|
||||
{
|
||||
if (sender is Ellipse ellipse && ellipse.DataContext is ITimelineKeyframeViewModel viewModel)
|
||||
_contextMenuOpenPosition = GetCursorTime(new Point(e.CursorLeft, e.CursorTop));
|
||||
NotifyOfPropertyChange(nameof(CanDuplicateKeyframes));
|
||||
NotifyOfPropertyChange(nameof(CanCopyKeyframes));
|
||||
NotifyOfPropertyChange(nameof(CanDeleteKeyframes));
|
||||
NotifyOfPropertyChange(nameof(CanPasteKeyframes));
|
||||
}
|
||||
|
||||
public void ContextMenuClosing(object sender, ContextMenuEventArgs e)
|
||||
{
|
||||
_contextMenuOpenPosition = null;
|
||||
}
|
||||
|
||||
public void KeyframeContextMenuOpening(object sender, ContextMenuEventArgs e)
|
||||
{
|
||||
if (sender is FrameworkElement fe && fe.DataContext is ITimelineKeyframeViewModel viewModel)
|
||||
viewModel.PopulateEasingViewModels();
|
||||
}
|
||||
|
||||
public void ContextMenuClosing(object sender, EventArgs e)
|
||||
public void KeyframeContextMenuClosing(object sender, ContextMenuEventArgs e)
|
||||
{
|
||||
if (sender is Ellipse ellipse && ellipse.DataContext is ITimelineKeyframeViewModel viewModel)
|
||||
viewModel.ClearEasingViewModels();
|
||||
}
|
||||
|
||||
public void Copy(ITimelineKeyframeViewModel viewModel)
|
||||
public void DeleteKeyframes()
|
||||
{
|
||||
// viewModel.Copy();
|
||||
List<ITimelineKeyframeViewModel> keyframeViewModels = GetAllKeyframeViewModels();
|
||||
foreach (ITimelineKeyframeViewModel keyframeViewModel in keyframeViewModels.Where(k => k.IsSelected))
|
||||
keyframeViewModel.Copy();
|
||||
List<ITimelineKeyframeViewModel> keyframeViewModels = GetAllKeyframeViewModels().Where(k => k.IsSelected).ToList();
|
||||
foreach (ITimelineKeyframeViewModel keyframeViewModel in keyframeViewModels)
|
||||
keyframeViewModel.Delete(false);
|
||||
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void Delete(ITimelineKeyframeViewModel viewModel)
|
||||
public void DuplicateKeyframes(object sender)
|
||||
{
|
||||
List<ITimelineKeyframeViewModel> keyframeViewModels = GetAllKeyframeViewModels();
|
||||
foreach (ITimelineKeyframeViewModel keyframeViewModel in keyframeViewModels.Where(k => k.IsSelected))
|
||||
keyframeViewModel.Delete();
|
||||
TimeSpan pastePosition = GetPastePosition(sender as ITimelineKeyframeViewModel);
|
||||
|
||||
List<ILayerPropertyKeyframe> keyframes = GetAllKeyframeViewModels().Where(k => k.IsSelected).Select(k => k.Keyframe).ToList();
|
||||
List<ILayerPropertyKeyframe> newKeyframes = DuplicateKeyframes(keyframes, pastePosition);
|
||||
// Select only the newly duplicated keyframes
|
||||
foreach (ITimelineKeyframeViewModel timelineKeyframeViewModel in GetAllKeyframeViewModels())
|
||||
timelineKeyframeViewModel.IsSelected = newKeyframes.Contains(timelineKeyframeViewModel.Keyframe);
|
||||
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void CopyKeyframes()
|
||||
{
|
||||
List<ILayerPropertyKeyframe> keyframes = GetAllKeyframeViewModels().Where(k => k.IsSelected).Select(k => k.Keyframe).ToList();
|
||||
CopyKeyframes(keyframes);
|
||||
}
|
||||
|
||||
public void PasteKeyframes(object sender)
|
||||
{
|
||||
TimeSpan pastePosition = GetPastePosition(sender as ITimelineKeyframeViewModel);
|
||||
List<ILayerPropertyKeyframe> newKeyframes = PasteKeyframes(pastePosition);
|
||||
// Select only the newly pasted keyframes
|
||||
foreach (ITimelineKeyframeViewModel timelineKeyframeViewModel in GetAllKeyframeViewModels())
|
||||
timelineKeyframeViewModel.IsSelected = newKeyframes.Contains(timelineKeyframeViewModel.Keyframe);
|
||||
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
private TimeSpan GetPastePosition(ITimelineKeyframeViewModel viewModel)
|
||||
{
|
||||
TimeSpan pastePosition = _profileEditorService.CurrentTime;
|
||||
|
||||
// If a keyframe VM is provided, paste onto there
|
||||
if (viewModel != null)
|
||||
pastePosition = viewModel.Position;
|
||||
// Paste at the position the context menu was opened
|
||||
else if (_contextMenuOpenPosition != null)
|
||||
pastePosition = _contextMenuOpenPosition.Value;
|
||||
|
||||
return pastePosition;
|
||||
}
|
||||
|
||||
private List<ILayerPropertyKeyframe> DuplicateKeyframes(List<ILayerPropertyKeyframe> keyframes, TimeSpan pastePosition)
|
||||
{
|
||||
KeyframesClipboardModel clipboardModel = CoreJson.DeserializeObject<KeyframesClipboardModel>(CoreJson.SerializeObject(new KeyframesClipboardModel(keyframes), true), true);
|
||||
return PasteClipboardData(clipboardModel, pastePosition);
|
||||
}
|
||||
|
||||
private void CopyKeyframes(List<ILayerPropertyKeyframe> keyframes)
|
||||
{
|
||||
KeyframesClipboardModel clipboardModel = new KeyframesClipboardModel(keyframes);
|
||||
JsonClipboard.SetObject(clipboardModel);
|
||||
}
|
||||
|
||||
private List<ILayerPropertyKeyframe> PasteKeyframes(TimeSpan pastePosition)
|
||||
{
|
||||
KeyframesClipboardModel clipboardObject = JsonClipboard.GetData<KeyframesClipboardModel>();
|
||||
return PasteClipboardData(clipboardObject, pastePosition);
|
||||
}
|
||||
|
||||
private List<ILayerPropertyKeyframe> PasteClipboardData(KeyframesClipboardModel clipboardModel, TimeSpan pastePosition)
|
||||
{
|
||||
List<ILayerPropertyKeyframe> pasted = new List<ILayerPropertyKeyframe>();
|
||||
if (clipboardModel == null)
|
||||
return pasted;
|
||||
RenderProfileElement target = _profileEditorService.SelectedProfileElement;
|
||||
if (target == null)
|
||||
return pasted;
|
||||
|
||||
return clipboardModel.Paste(target, pastePosition);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -254,6 +347,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
// ReSharper disable once UnusedMember.Global - Called from view
|
||||
public void TimelineCanvasMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// Workaround for focus not being applied to the grid causing keybinds not to function
|
||||
((IInputElement) sender).Focus();
|
||||
|
||||
if (e.LeftButton == MouseButtonState.Released)
|
||||
return;
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Core.Services;
|
||||
@ -209,6 +210,8 @@ namespace Artemis.UI.Screens.ProfileEditor
|
||||
// Expanded status is also undone because undoing works a bit crude, that's annoying
|
||||
List<LayerPropertyGroupViewModel> beforeGroups = LayerPropertiesViewModel.GetAllLayerPropertyGroupViewModels();
|
||||
List<string> expandedPaths = beforeGroups.Where(g => g.IsExpanded).Select(g => g.LayerPropertyGroup.Path).ToList();
|
||||
// Store the focused element so we can restore it later
|
||||
IInputElement focusedElement = FocusManager.GetFocusedElement(Window.GetWindow(View));
|
||||
|
||||
if (!_profileEditorService.UndoUpdateProfile())
|
||||
{
|
||||
@ -219,7 +222,13 @@ namespace Artemis.UI.Screens.ProfileEditor
|
||||
// Restore the expanded status
|
||||
foreach (LayerPropertyGroupViewModel allLayerPropertyGroupViewModel in LayerPropertiesViewModel.GetAllLayerPropertyGroupViewModels())
|
||||
allLayerPropertyGroupViewModel.IsExpanded = expandedPaths.Contains(allLayerPropertyGroupViewModel.LayerPropertyGroup.Path);
|
||||
|
||||
// Restore the focused element
|
||||
Execute.PostToUIThread(async () =>
|
||||
{
|
||||
await Task.Delay(50);
|
||||
focusedElement?.Focus();
|
||||
});
|
||||
|
||||
_snackbarMessageQueue.Enqueue("Undid profile update", "REDO", Redo);
|
||||
}
|
||||
|
||||
@ -228,6 +237,8 @@ namespace Artemis.UI.Screens.ProfileEditor
|
||||
// Expanded status is also undone because undoing works a bit crude, that's annoying
|
||||
List<LayerPropertyGroupViewModel> beforeGroups = LayerPropertiesViewModel.GetAllLayerPropertyGroupViewModels();
|
||||
List<string> expandedPaths = beforeGroups.Where(g => g.IsExpanded).Select(g => g.LayerPropertyGroup.Path).ToList();
|
||||
// Store the focused element so we can restore it later
|
||||
IInputElement focusedElement = FocusManager.GetFocusedElement(Window.GetWindow(View));
|
||||
|
||||
if (!_profileEditorService.RedoUpdateProfile())
|
||||
{
|
||||
@ -238,6 +249,12 @@ namespace Artemis.UI.Screens.ProfileEditor
|
||||
// Restore the expanded status
|
||||
foreach (LayerPropertyGroupViewModel allLayerPropertyGroupViewModel in LayerPropertiesViewModel.GetAllLayerPropertyGroupViewModels())
|
||||
allLayerPropertyGroupViewModel.IsExpanded = expandedPaths.Contains(allLayerPropertyGroupViewModel.LayerPropertyGroup.Path);
|
||||
// Restore the focused element
|
||||
Execute.PostToUIThread(async () =>
|
||||
{
|
||||
await Task.Delay(50);
|
||||
focusedElement?.Focus();
|
||||
});
|
||||
|
||||
_snackbarMessageQueue.Enqueue("Redid profile update", "UNDO", Undo);
|
||||
}
|
||||
|
||||
@ -32,7 +32,8 @@
|
||||
HorizontalContentAlignment="Stretch"
|
||||
dd:DragDrop.IsDragSource="True"
|
||||
dd:DragDrop.IsDropTarget="True"
|
||||
dd:DragDrop.DropHandler="{Binding}">
|
||||
dd:DragDrop.DropHandler="{Binding}"
|
||||
ContextMenuOpening="{s:Action ContextMenuOpening}">
|
||||
<TreeView.InputBindings>
|
||||
<KeyBinding Key="F2" Command="{s:Action RenameElement}" s:View.ActionTarget="{Binding SelectedTreeItem}" />
|
||||
<KeyBinding Key="Delete" Command="{s:Action DeleteElement}" s:View.ActionTarget="{Binding SelectedTreeItem}" />
|
||||
@ -40,6 +41,47 @@
|
||||
<KeyBinding Key="C" Modifiers="Control" Command="{s:Action CopyElement}" s:View.ActionTarget="{Binding SelectedTreeItem}" />
|
||||
<KeyBinding Key="V" Modifiers="Control" Command="{s:Action PasteElement}" s:View.ActionTarget="{Binding SelectedTreeItem}" />
|
||||
</TreeView.InputBindings>
|
||||
<TreeView.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Add new folder" Command="{s:Action AddFolder}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="CreateNewFolder" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Add new layer" Command="{s:Action AddLayer}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="LayersPlus" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Duplicate" Command="{s:Action DuplicateElement}" InputGestureText="Ctrl+D" IsEnabled="False">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentDuplicate" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Copy" Command="{s:Action CopyElement}" InputGestureText="Ctrl+C" IsEnabled="False">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentCopy" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Paste" Command="{s:Action PasteElement}" InputGestureText="Ctrl+V">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentPaste" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Rename" Command="{s:Action RenameElement}" InputGestureText="F2" IsEnabled="False">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="RenameBox" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Delete" Command="{s:Action DeleteElement}" InputGestureText="Del" IsEnabled="False">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="TrashCan" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</TreeView.ContextMenu>
|
||||
<b:Interaction.Behaviors>
|
||||
<behaviors:TreeViewSelectionBehavior ExpandSelected="True" SelectedItem="{Binding SelectedTreeItem}" />
|
||||
</b:Interaction.Behaviors>
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Artemis.Core;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem;
|
||||
using Artemis.UI.Shared;
|
||||
@ -41,17 +42,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Global - Called from view
|
||||
public void AddFolder()
|
||||
{
|
||||
ActiveItem?.AddFolder();
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Global - Called from view
|
||||
public void AddLayer()
|
||||
{
|
||||
ActiveItem?.AddLayer();
|
||||
}
|
||||
public bool CanPasteElement => _profileEditorService.GetCanPasteProfileElement();
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
@ -79,10 +70,12 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
||||
_updatingTree = false;
|
||||
}
|
||||
|
||||
#region IDropTarget
|
||||
|
||||
private static DragDropType GetDragDropType(IDropInfo dropInfo)
|
||||
{
|
||||
TreeItemViewModel source = (TreeItemViewModel) dropInfo.Data;
|
||||
TreeItemViewModel target = (TreeItemViewModel) dropInfo.TargetItem;
|
||||
TreeItemViewModel source = (TreeItemViewModel)dropInfo.Data;
|
||||
TreeItemViewModel target = (TreeItemViewModel)dropInfo.TargetItem;
|
||||
if (source == target)
|
||||
return DragDropType.None;
|
||||
|
||||
@ -128,14 +121,14 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
||||
|
||||
public void Drop(IDropInfo dropInfo)
|
||||
{
|
||||
TreeItemViewModel source = (TreeItemViewModel) dropInfo.Data;
|
||||
TreeItemViewModel target = (TreeItemViewModel) dropInfo.TargetItem;
|
||||
TreeItemViewModel source = (TreeItemViewModel)dropInfo.Data;
|
||||
TreeItemViewModel target = (TreeItemViewModel)dropInfo.TargetItem;
|
||||
|
||||
DragDropType dragDropType = GetDragDropType(dropInfo);
|
||||
switch (dragDropType)
|
||||
{
|
||||
case DragDropType.Add:
|
||||
((TreeItemViewModel) source.Parent).RemoveExistingElement(source);
|
||||
((TreeItemViewModel)source.Parent).RemoveExistingElement(source);
|
||||
target.AddExistingElement(source);
|
||||
break;
|
||||
case DragDropType.InsertBefore:
|
||||
@ -151,6 +144,34 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
||||
Subscribe();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Context menu
|
||||
|
||||
public void AddFolder()
|
||||
{
|
||||
ActiveItem?.AddFolder();
|
||||
}
|
||||
|
||||
public void AddLayer()
|
||||
{
|
||||
ActiveItem?.AddLayer();
|
||||
}
|
||||
|
||||
public void PasteElement()
|
||||
{
|
||||
Folder rootFolder = _profileEditorService.SelectedProfile?.GetRootFolder();
|
||||
if (rootFolder != null)
|
||||
_profileEditorService.PasteProfileElement(rootFolder, rootFolder.Children.Count);
|
||||
}
|
||||
|
||||
public void ContextMenuOpening(object sender, EventArgs e)
|
||||
{
|
||||
NotifyOfPropertyChange(nameof(CanPasteElement));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void Subscribe()
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type treeItem1:FolderViewModel}}">
|
||||
<!-- Capture clicks on full tree view item -->
|
||||
<StackPanel Margin="-10" Background="Transparent">
|
||||
<StackPanel Margin="-10" Background="Transparent" ContextMenuOpening="{s:Action ContextMenuOpening}">
|
||||
<StackPanel.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Add new folder" Command="{s:Action AddFolder}">
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type treeItem1:LayerViewModel}}">
|
||||
<!-- Capture clicks on full tree view item -->
|
||||
<StackPanel Margin="-10" Background="Transparent">
|
||||
<StackPanel Margin="-10" Background="Transparent" ContextMenuOpening="{s:Action ContextMenuOpening}">
|
||||
<StackPanel.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Duplicate" Command="{s:Action DuplicateElement}" InputGestureText="Ctrl+D">
|
||||
|
||||
@ -48,6 +48,8 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
||||
set => SetAndNotify(ref _profileElement, value);
|
||||
}
|
||||
|
||||
public bool CanPasteElement => _profileEditorService.GetCanPasteProfileElement();
|
||||
|
||||
public abstract bool SupportsChildren { get; }
|
||||
|
||||
public List<TreeItemViewModel> GetAllChildren()
|
||||
@ -254,6 +256,11 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
||||
_profileEditorService.UpdateSelectedProfile();
|
||||
}
|
||||
|
||||
public void ContextMenuOpening(object sender, EventArgs e)
|
||||
{
|
||||
NotifyOfPropertyChange(nameof(CanPasteElement));
|
||||
}
|
||||
|
||||
private void Subscribe()
|
||||
{
|
||||
ProfileElement.ChildAdded += ProfileElementOnChildAdded;
|
||||
|
||||
@ -107,9 +107,9 @@
|
||||
},
|
||||
"Stylet": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.3.4, )",
|
||||
"resolved": "1.3.4",
|
||||
"contentHash": "bCEdA+AIi+TM9SQQGLYMsFRIfzZcDUDg2Mznyr72kOkcC/cdBj01/jel4/v2aoKwbFcxVjiqmpgnbsFgMEZ4zQ==",
|
||||
"requested": "[1.3.5, )",
|
||||
"resolved": "1.3.5",
|
||||
"contentHash": "9vjjaTgf5sZAGHnxQWIslD32MG5gXj7ANgS+w965L5Eh//UC3qwZDrEf226Pf+v1P/ldAJDpUySnOyGlb3TSSw==",
|
||||
"dependencies": {
|
||||
"System.Drawing.Common": "4.6.0"
|
||||
}
|
||||
@ -1410,7 +1410,7 @@
|
||||
"SharpVectors.Reloaded": "1.6.0",
|
||||
"SkiaSharp": "2.80.2",
|
||||
"SkiaSharp.Views.WPF": "2.80.2",
|
||||
"Stylet": "1.3.4",
|
||||
"Stylet": "1.3.5",
|
||||
"System.Buffers": "4.5.0",
|
||||
"System.Numerics.Vectors": "4.5.0",
|
||||
"WriteableBitmapEx": "1.6.5"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user