mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
UI - Updated Stylet
Keyframes - Finished copy/paste implementation
This commit is contained in:
1 parent
0fd30aef2d
commit
dd73c1e4c9
14 files changed
+177
-64
No files matched your search
@@ -199,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="*" />
|
||||
@@ -206,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}" />
|
||||
|
||||
+64
-10
@@ -1,32 +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 KeyframeClipboardModel
|
||||
public class KeyframesClipboardModel
|
||||
{
|
||||
public Dictionary<string, KeyframeEntity> KeyframeEntities { get; set; }
|
||||
public KeyframeClipboardModel(List<ILayerPropertyKeyframe> keyframes)
|
||||
// ReSharper disable once UnusedMember.Global - For JSON.NET
|
||||
public KeyframesClipboardModel()
|
||||
{
|
||||
KeyframeEntities = new Dictionary<string, KeyframeEntity>();
|
||||
foreach (ILayerPropertyKeyframe keyframe in keyframes)
|
||||
{
|
||||
KeyframeEntities.Add(keyframe.UntypedLayerProperty.Path, );
|
||||
}
|
||||
ClipboardModels = new List<KeyframeClipboardModel>();
|
||||
}
|
||||
|
||||
public void Paste(RenderProfileElement target, TimeSpan pastePosition)
|
||||
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 bool HasBeenPasted { get; set; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,6 @@
|
||||
Height="{Binding LayerPropertiesViewModel.TreeViewModelHeight}"
|
||||
VerticalAlignment="Top"
|
||||
Focusable="True">
|
||||
<Grid.InputBindings>
|
||||
<KeyBinding Key="Delete" Command="{s:Action DeleteKeyframes}" />
|
||||
<KeyBinding Key="D" Modifiers="Control" Command="{s:Action DuplicateKeyframes}" />
|
||||
<KeyBinding Key="C" Modifiers="Control" Command="{s:Action CopyKeyframes}" />
|
||||
<KeyBinding Key="V" Modifiers="Control" Command="{s:Action PasteKeyframes}" />
|
||||
</Grid.InputBindings>
|
||||
<Grid.Triggers>
|
||||
<EventTrigger RoutedEvent="UIElement.MouseLeftButtonDown">
|
||||
<BeginStoryboard>
|
||||
@@ -43,12 +37,12 @@
|
||||
</Grid.Triggers>
|
||||
<Grid.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Duplicate" Command="{s:Action DuplicateKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+D" IsEnabled="False">
|
||||
<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" IsEnabled="False">
|
||||
<MenuItem Header="Copy" Command="{s:Action CopyKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+C">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentCopy" />
|
||||
</MenuItem.Icon>
|
||||
@@ -59,7 +53,7 @@
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Delete" Command="{s:Action DeleteKeyframes}" InputGestureText="Del" IsEnabled="False">
|
||||
<MenuItem Header="Delete" Command="{s:Action DeleteKeyframes}" InputGestureText="Del">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Delete" />
|
||||
</MenuItem.Icon>
|
||||
|
||||
+30
-18
@@ -158,13 +158,17 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
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 KeyframeClipboardModel;
|
||||
public bool CanPasteKeyframes => JsonClipboard.GetData() is KeyframesClipboardModel;
|
||||
|
||||
private TimeSpan? _contextMenuOpenPosition;
|
||||
|
||||
public void ContextMenuOpening(object sender, ContextMenuEventArgs e)
|
||||
{
|
||||
_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)
|
||||
@@ -193,12 +197,17 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void DuplicateKeyframes(ITimelineKeyframeViewModel viewModel = null)
|
||||
public void DuplicateKeyframes(object sender)
|
||||
{
|
||||
TimeSpan pastePosition = GetPastePosition(viewModel);
|
||||
TimeSpan pastePosition = GetPastePosition(sender as ITimelineKeyframeViewModel);
|
||||
|
||||
List<ILayerPropertyKeyframe> keyframes = GetAllKeyframeViewModels().Where(k => k.IsSelected).Select(k => k.Keyframe).ToList();
|
||||
DuplicateKeyframes(keyframes, pastePosition);
|
||||
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()
|
||||
@@ -207,10 +216,15 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
CopyKeyframes(keyframes);
|
||||
}
|
||||
|
||||
public void PasteKeyframes(ITimelineKeyframeViewModel viewModel = null)
|
||||
public void PasteKeyframes(object sender)
|
||||
{
|
||||
TimeSpan pastePosition = GetPastePosition(viewModel);
|
||||
PasteKeyframes(pastePosition);
|
||||
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)
|
||||
@@ -226,26 +240,26 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
|
||||
return pastePosition;
|
||||
}
|
||||
|
||||
public List<ILayerPropertyKeyframe> DuplicateKeyframes(List<ILayerPropertyKeyframe> keyframes, TimeSpan pastePosition)
|
||||
|
||||
private List<ILayerPropertyKeyframe> DuplicateKeyframes(List<ILayerPropertyKeyframe> keyframes, TimeSpan pastePosition)
|
||||
{
|
||||
KeyframeClipboardModel clipboardModel = CoreJson.DeserializeObject<KeyframeClipboardModel>(CoreJson.SerializeObject(new KeyframeClipboardModel(keyframes), true), true);
|
||||
KeyframesClipboardModel clipboardModel = CoreJson.DeserializeObject<KeyframesClipboardModel>(CoreJson.SerializeObject(new KeyframesClipboardModel(keyframes), true), true);
|
||||
return PasteClipboardData(clipboardModel, pastePosition);
|
||||
}
|
||||
|
||||
public void CopyKeyframes(List<ILayerPropertyKeyframe> keyframes)
|
||||
private void CopyKeyframes(List<ILayerPropertyKeyframe> keyframes)
|
||||
{
|
||||
KeyframeClipboardModel clipboardModel = new KeyframeClipboardModel(keyframes);
|
||||
KeyframesClipboardModel clipboardModel = new KeyframesClipboardModel(keyframes);
|
||||
JsonClipboard.SetObject(clipboardModel);
|
||||
}
|
||||
|
||||
public List<ILayerPropertyKeyframe> PasteKeyframes(TimeSpan pastePosition)
|
||||
private List<ILayerPropertyKeyframe> PasteKeyframes(TimeSpan pastePosition)
|
||||
{
|
||||
KeyframeClipboardModel clipboardObject = JsonClipboard.GetData<KeyframeClipboardModel>();
|
||||
KeyframesClipboardModel clipboardObject = JsonClipboard.GetData<KeyframesClipboardModel>();
|
||||
return PasteClipboardData(clipboardObject, pastePosition);
|
||||
}
|
||||
|
||||
private List<ILayerPropertyKeyframe> PasteClipboardData(KeyframeClipboardModel clipboardModel, TimeSpan pastePosition)
|
||||
private List<ILayerPropertyKeyframe> PasteClipboardData(KeyframesClipboardModel clipboardModel, TimeSpan pastePosition)
|
||||
{
|
||||
List<ILayerPropertyKeyframe> pasted = new List<ILayerPropertyKeyframe>();
|
||||
if (clipboardModel == null)
|
||||
@@ -254,9 +268,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
|
||||
if (target == null)
|
||||
return pasted;
|
||||
|
||||
clipboardModel.Paste(target, pastePosition);
|
||||
|
||||
return pasted;
|
||||
return clipboardModel.Paste(target, pastePosition);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanPasteElement => _profileEditorService.GetCanPaste();
|
||||
public bool CanPasteElement => _profileEditorService.GetCanPasteProfileElement();
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
|
||||
set => SetAndNotify(ref _profileElement, value);
|
||||
}
|
||||
|
||||
public bool CanPasteElement => _profileEditorService.GetCanPaste();
|
||||
public bool CanPasteElement => _profileEditorService.GetCanPasteProfileElement();
|
||||
|
||||
public abstract bool SupportsChildren { get; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user