Scripting - Core implementation (#629)

Scripting - Added plugin classes
Layers - Fix certain blend modes not working as intended
UI - Add customizable header per page
Profile editor - Hide the regular header
Profile editor - Added a new toolbar
This commit is contained in:
Robert Beekman authored and GitHub committed 2021-06-19 09:48:16 +02:00
1 parent d749ab5bbd
commit 048864fe78
47 files changed
+1599 -237

No files matched your search

@@ -7,8 +7,7 @@
xmlns:s="https://github.com/canton7/Stylet"
xmlns:profileEditor="clr-namespace:Artemis.UI.Screens.ProfileEditor"
xmlns:behaviors="clr-namespace:Artemis.UI.Behaviors"
xmlns:dataTemplateSelectors="clr-namespace:Artemis.UI.DataTemplateSelectors"
xmlns:profile="clr-namespace:Artemis.Core;assembly=Artemis.Core"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
mc:Ignorable="d"
behaviors:InputBindingBehavior.PropagateInputBindingsToWindow="True"
d:DesignHeight="450" d:DesignWidth="800"
@@ -29,70 +28,202 @@
<KeyBinding Command="{s:Action Redo}" Modifiers="Control" Key="Y" />
</UserControl.InputBindings>
<Grid Margin="10">
<Grid ClipToBounds="True">
<Grid.ColumnDefinitions>
<!-- Left side -->
<ColumnDefinition Width="*" MinWidth="100" />
<!-- Side panels resize -->
<ColumnDefinition Width="Auto" />
<!-- Side panels -->
<ColumnDefinition Width="{Binding SidePanelsWidth.Value, Mode=TwoWay}" MinWidth="100" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<shared:ProfileConfigurationIcon Grid.Row="0"
Grid.Column="0"
Width="25"
Height="25"
Margin="25 -5 25 0"
ToolTip="{Binding ProfileConfiguration.Name}"
ConfigurationIcon="{Binding ProfileConfiguration.Icon}" />
<Menu Grid.Row="0" Grid.Column="1" IsMainMenu="True" Margin="0 -4 0 0">
<MenuItem Header="_File">
<MenuItem Header="New" Icon="{materialDesign:PackIcon Kind=Plus}">
<MenuItem Header="Folder"
Icon="{materialDesign:PackIcon Kind=Folder}"
Command="{s:Action AddFolder}"
s:View.ActionTarget="{Binding ProfileTreeViewModel}" />
<MenuItem Header="Layer"
Icon="{materialDesign:PackIcon Kind=Layers}"
Command="{s:Action AddLayer}"
s:View.ActionTarget="{Binding ProfileTreeViewModel}" />
</MenuItem>
<Separator />
<MenuItem Header="View properties"
Icon="{materialDesign:PackIcon Kind=Settings}"
Command="{s:Action ViewProperties}"/>
<MenuItem Header="Suspend profile"
IsCheckable="True"
IsChecked="{Binding ProfileConfiguration.IsSuspended}" />
<Separator />
<MenuItem Header="Export profile"
Icon="{materialDesign:PackIcon Kind=Export}"
Command="{s:Action ExportProfile}" />
<MenuItem Header="Duplicate profile"
Icon="{materialDesign:PackIcon Kind=ContentDuplicate}"
Command="{s:Action DuplicateProfile}" />
<Separator />
<MenuItem Header="Delete profile"
Icon="{materialDesign:PackIcon Kind=Trash}"
Command="{s:Action DeleteProfile}" />
</MenuItem>
<MenuItem Header="_Edit" SubmenuOpened="{s:Action EditMenuOpened}">
<MenuItem Header="_Duplicate"
Icon="{materialDesign:PackIcon Kind=ContentDuplicate}"
Command="{s:Action Duplicate}"
InputGestureText="Ctrl+D"
IsEnabled="{Binding HasSelectedElement}"/>
<MenuItem Header="_Copy"
Icon="{materialDesign:PackIcon Kind=ContentCopy}"
Command="{s:Action Copy}"
InputGestureText="Ctrl+C"
IsEnabled="{Binding HasSelectedElement}"/>
<MenuItem Header="_Paste"
Icon="{materialDesign:PackIcon Kind=ContentPaste}"
Command="{s:Action Paste}"
InputGestureText="Ctrl+V" />
</MenuItem>
<MenuItem Header="_Scripting" IsEnabled="False">
<MenuItem Header="_Profile scripts"
Icon="{materialDesign:PackIcon Kind=BookEdit}" />
<MenuItem Header="_Layer scripts"
Icon="{materialDesign:PackIcon Kind=Layers}"
IsEnabled="{Binding HasSelectedElement}"/>
<MenuItem Header="_Property scripts"
Icon="{materialDesign:PackIcon Kind=FormTextbox}"
IsEnabled="{Binding HasSelectedElement}"/>
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="Artemis wiki"
Icon="{materialDesign:PackIcon Kind=BookEdit}"
Command="{s:Action OpenUrl}"
CommandParameter="https://wiki.artemis-rgb.com/" />
<Separator />
<MenuItem Header="Editor"
Icon="{materialDesign:PackIcon Kind=Edit}"
Command="{s:Action OpenUrl}"
CommandParameter="https://wiki.artemis-rgb.com/en/guides/user/profiles" />
<MenuItem Header="Layers"
Icon="{materialDesign:PackIcon Kind=Layers}"
Command="{s:Action OpenUrl}"
CommandParameter="https://wiki.artemis-rgb.com/guides/user/profiles/layers" />
<MenuItem Header="Display conditions"
Icon="{materialDesign:PackIcon Kind=NotEqual}"
Command="{s:Action OpenUrl}"
CommandParameter="https://wiki.artemis-rgb.com/guides/user/profiles/conditions" />
<MenuItem Header="Timeline"
Icon="{materialDesign:PackIcon Kind=Stopwatch}"
Command="{s:Action OpenUrl}"
CommandParameter="https://wiki.artemis-rgb.com/guides/user/profiles/timeline" />
<MenuItem Header="Data bindings"
Icon="{materialDesign:PackIcon Kind=VectorLink}"
Command="{s:Action OpenUrl}"
CommandParameter="https://wiki.artemis-rgb.com/guides/user/profiles/data-bindings" />
<MenuItem Header="Scripting"
Icon="{materialDesign:PackIcon Kind=CodeJson}"
Command="{s:Action OpenUrl}"
CommandParameter="https://wiki.artemis-rgb.com/guides/user/profiles/scripting" />
<Separator />
<MenuItem Header="Report a bug"
Icon="{materialDesign:PackIcon Kind=Github}"
Command="{s:Action OpenUrl}"
CommandParameter="https://github.com/Artemis-RGB/Artemis/issues" />
<MenuItem Header="Get help on Discord"
Icon="{materialDesign:PackIcon Kind=Discord}"
Command="{s:Action OpenUrl}"
CommandParameter="https://discord.gg/S3MVaC9" />
</MenuItem>
</Menu>
<Button Grid.Row="0"
Grid.Column="2"
Style="{StaticResource MaterialDesignIconForegroundButton}"
ToolTip="Open debugger"
Margin="10 -4 10 0"
Width="34"
Height="34"
Command="{s:Action OpenDebugger}">
<materialDesign:PackIcon Kind="Matrix" Width="20" Height="20" />
</Button>
<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="10 -5 10 10">
<Grid.ColumnDefinitions>
<!-- Left side -->
<ColumnDefinition Width="*" MinWidth="100" />
<!-- Side panels resize -->
<ColumnDefinition Width="Auto" />
<!-- Side panels -->
<ColumnDefinition Width="{Binding SidePanelsWidth.Value, Mode=TwoWay}" MinWidth="100" />
</Grid.ColumnDefinitions>
<!-- Left side -->
<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<!-- Design area -->
<RowDefinition Height="*" MinHeight="200" />
<!-- Bottom panels resize -->
<RowDefinition Height="Auto" />
<!-- Bottom panels -->
<RowDefinition Height="{Binding BottomPanelsHeight.Value, Mode=TwoWay}" MinHeight="108" />
</Grid.RowDefinitions>
<!-- Left side -->
<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<!-- Design area -->
<RowDefinition Height="*" MinHeight="200" />
<materialDesign:Card Grid.Row="0" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding ProfileViewModel, IsAsync=True}" />
</materialDesign:Card>
<!-- Bottom panels resize -->
<RowDefinition Height="Auto" />
<GridSplitter Grid.Row="1" Grid.Column="0" Height="5" HorizontalAlignment="Stretch" Cursor="SizeNS" Margin="0 5" />
<!-- Bottom panels -->
<RowDefinition Height="{Binding BottomPanelsHeight.Value, Mode=TwoWay}" MinHeight="108" />
</Grid.RowDefinitions>
<!-- Design area -->
<materialDesign:Card Grid.Row="0" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding ProfileViewModel, IsAsync=True}" />
</materialDesign:Card>
<Grid Grid.Row="2">
<!-- Layer elements -->
<materialDesign:Card Grid.Column="0" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding LayerPropertiesViewModel, IsAsync=True}" />
</materialDesign:Card>
</Grid>
</Grid>
<!-- Bottom panels resize -->
<GridSplitter Grid.Row="1" Grid.Column="0" Height="5" HorizontalAlignment="Stretch" Cursor="SizeNS" Margin="0 5" />
<!-- Side panels resize -->
<GridSplitter Grid.Row="0" Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Cursor="SizeWE" Margin="5 0" />
<!-- Bottom panels -->
<Grid Grid.Row="2">
<!-- Layer elements -->
<materialDesign:Card Grid.Column="0" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding LayerPropertiesViewModel, IsAsync=True}" />
<!-- Side panels -->
<Grid Grid.Row="0" Grid.Column="2">
<Grid.RowDefinitions>
<!-- Profile elements -->
<RowDefinition Height="*" MinHeight="100" />
<!-- Conditions resize -->
<RowDefinition Height="Auto" />
<!-- Display conditions -->
<RowDefinition Height="{Binding DataModelConditionsHeight.Value, Mode=TwoWay}" MinHeight="100" />
</Grid.RowDefinitions>
<!-- Profile elements -->
<materialDesign:Card Grid.Row="0" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding ProfileTreeViewModel, IsAsync=True}" Margin="0,-1,-0.2,1" />
</materialDesign:Card>
<!-- Conditions resize -->
<GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" Cursor="SizeNS" Margin="0 5" />
<!-- Display conditions -->
<materialDesign:Card Grid.Row="2" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding DisplayConditionsViewModel, IsAsync=True}" />
</materialDesign:Card>
</Grid>
</Grid>
<!-- Side panels resize -->
<GridSplitter Grid.Row="0" Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Cursor="SizeWE" Margin="5 0" />
<!-- Side panels -->
<Grid Grid.Row="0" Grid.Column="2">
<Grid.RowDefinitions>
<!-- Profile elements -->
<RowDefinition Height="*" MinHeight="100" />
<!-- Conditions resize -->
<RowDefinition Height="Auto" />
<!-- Display conditions -->
<RowDefinition Height="{Binding DataModelConditionsHeight.Value, Mode=TwoWay}" MinHeight="100" />
</Grid.RowDefinitions>
<!-- Profile elements -->
<materialDesign:Card Grid.Row="0" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding ProfileTreeViewModel, IsAsync=True}" Margin="0,-1,-0.2,1" />
</materialDesign:Card>
<!-- Conditions resize -->
<GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" Cursor="SizeNS" Margin="0 5" />
<!-- Display conditions -->
<materialDesign:Card Grid.Row="2" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding DisplayConditionsViewModel, IsAsync=True}" />
</materialDesign:Card>
</Grid>
</Grid>
</UserControl>
@@ -5,18 +5,25 @@ using System.Windows;
using System.Windows.Input;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Events;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.DisplayConditions;
using Artemis.UI.Screens.ProfileEditor.LayerProperties;
using Artemis.UI.Screens.ProfileEditor.ProfileTree;
using Artemis.UI.Screens.ProfileEditor.Visualization;
using Artemis.UI.Screens.Sidebar.Dialogs;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Stylet;
using ProfileConfigurationEventArgs = Artemis.UI.Shared.ProfileConfigurationEventArgs;
namespace Artemis.UI.Screens.ProfileEditor
{
public class ProfileEditorViewModel : Screen, IMainScreenViewModel
public class ProfileEditorViewModel : MainScreenViewModel
{
private readonly IMessageService _messageService;
private readonly ISidebarVmFactory _sidebarVmFactory;
private readonly IEventAggregator _eventAggregator;
private readonly IProfileEditorService _profileEditorService;
private readonly IProfileService _profileService;
private readonly ISettingsService _settingsService;
@@ -37,12 +44,14 @@ namespace Artemis.UI.Screens.ProfileEditor
IProfileService profileService,
IDialogService dialogService,
ISettingsService settingsService,
IMessageService messageService)
IMessageService messageService,
ISidebarVmFactory sidebarVmFactory)
{
_profileEditorService = profileEditorService;
_profileService = profileService;
_settingsService = settingsService;
_messageService = messageService;
_sidebarVmFactory = sidebarVmFactory;
DisplayName = "Profile Editor";
DialogService = dialogService;
@@ -60,6 +69,8 @@ namespace Artemis.UI.Screens.ProfileEditor
public IDialogService DialogService { get; }
public ProfileConfiguration ProfileConfiguration => _profileEditorService.SelectedProfileConfiguration;
public DisplayConditionsViewModel DisplayConditionsViewModel
{
get => _displayConditionsViewModel;
@@ -176,20 +187,96 @@ namespace Artemis.UI.Screens.ProfileEditor
_messageService.ShowMessage("Redid profile update", "UNDO", Undo);
}
#region Menu
public bool HasSelectedElement => _profileEditorService.SelectedProfileElement != null;
public bool CanPaste => _profileEditorService.GetCanPasteProfileElement();
public async Task ViewProperties()
{
await _sidebarVmFactory.SidebarProfileConfigurationViewModel(_profileEditorService.SelectedProfileConfiguration).ViewProperties();
}
public void DuplicateProfile()
{
ProfileConfigurationExportModel export = _profileService.ExportProfile(ProfileConfiguration);
_profileService.ImportProfile(ProfileConfiguration.Category, export, true, false, "copy");
}
public async Task DeleteProfile()
{
await _sidebarVmFactory.SidebarProfileConfigurationViewModel(_profileEditorService.SelectedProfileConfiguration).Delete();
}
public async Task ExportProfile()
{
await _sidebarVmFactory.SidebarProfileConfigurationViewModel(_profileEditorService.SelectedProfileConfiguration).Export();
}
public void Copy()
{
if (_profileEditorService.SelectedProfileElement != null)
_profileEditorService.CopyProfileElement(_profileEditorService.SelectedProfileElement);
}
public void Duplicate()
{
if (_profileEditorService.SelectedProfileElement != null)
_profileEditorService.DuplicateProfileElement(_profileEditorService.SelectedProfileElement);
}
public void Paste()
{
if (_profileEditorService.SelectedProfileElement != null && _profileEditorService.SelectedProfileElement.Parent is Folder parent)
_profileEditorService.PasteProfileElement(parent, _profileEditorService.SelectedProfileElement.Order - 1);
else
{
Folder rootFolder = _profileEditorService.SelectedProfile?.GetRootFolder();
if (rootFolder != null)
_profileEditorService.PasteProfileElement(rootFolder, rootFolder.Children.Count);
}
}
public void OpenUrl(string url)
{
Core.Utilities.OpenUrl(url);
}
public void EditMenuOpened()
{
NotifyOfPropertyChange(nameof(CanPaste));
}
#endregion
protected override void OnInitialActivate()
{
_profileEditorService.SelectedProfileChanged += ProfileEditorServiceOnSelectedProfileChanged;
_profileEditorService.SelectedProfileElementChanged += ProfileEditorServiceOnSelectedProfileElementChanged;
LoadWorkspaceSettings();
base.OnInitialActivate();
}
protected override void OnClose()
{
_profileEditorService.SelectedProfileChanged -= ProfileEditorServiceOnSelectedProfileChanged;
_profileEditorService.SelectedProfileElementChanged -= ProfileEditorServiceOnSelectedProfileElementChanged;
SaveWorkspaceSettings();
_profileEditorService.ChangeSelectedProfileConfiguration(null);
base.OnClose();
}
private void ProfileEditorServiceOnSelectedProfileChanged(object sender, ProfileConfigurationEventArgs e)
{
NotifyOfPropertyChange(nameof(ProfileConfiguration));
}
private void ProfileEditorServiceOnSelectedProfileElementChanged(object sender, RenderProfileElementEventArgs e)
{
NotifyOfPropertyChange(nameof(HasSelectedElement));
}
private void LoadWorkspaceSettings()
{
SidePanelsWidth = _settingsService.GetSetting("ProfileEditor.SidePanelsWidth", new GridLength(385));
@@ -100,7 +100,7 @@
</ItemsControl>
</Grid>
<Grid Name="EditorDisplayGrid"
<Grid Name="EditorDisplayGrid"
shared:SizeObserver.Observe="True"
shared:SizeObserver.ObservedHeight="{Binding PanZoomViewModel.CanvasHeight}"
shared:SizeObserver.ObservedWidth="{Binding PanZoomViewModel.CanvasWidth}">
@@ -133,13 +133,13 @@
<StackPanel ZIndex="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="10" Cursor="Arrow">
<materialDesign:Card Padding="8">
<StackPanel Orientation="Horizontal">
<CheckBox Style="{StaticResource MaterialDesignCheckBox}"
<CheckBox Style="{StaticResource MaterialDesignCheckBox}"
IsChecked="{Binding FocusSelectedLayer.Value}"
ToolTip="If selected, dims all LEDs that are not part of the selected layer">
Focus selected layer
</CheckBox>
<CheckBox Style="{StaticResource MaterialDesignCheckBox}"
Margin="10 0 0 0"
<CheckBox Style="{StaticResource MaterialDesignCheckBox}"
Margin="10 0 0 0"
IsChecked="{Binding AlwaysApplyDataBindings.Value}"
ToolTip="If selected, updates all data bindings instead of only the one you are editing">
Apply all data bindings in editor
@@ -150,14 +150,13 @@
<StackPanel Orientation="Vertical" VerticalAlignment="Bottom" HorizontalAlignment="Right"
Margin="10" ZIndex="1">
<Slider Margin="0,0,14,0"
Orientation="Vertical"
<Slider Orientation="Vertical"
HorizontalAlignment="Center"
Margin="0 10"
Height="120"
Minimum="10"
Maximum="250"
Height="100"
FocusVisualStyle="{x:Null}"
Value="{Binding PanZoomViewModel.ZoomPercentage}"
Style="{StaticResource MaterialDesignDiscreteSlider}" />
Value="{Binding PanZoomViewModel.ZoomPercentage}" />
<Button Command="{s:Action ResetZoomAndPan}"
Style="{StaticResource MaterialDesignFloatingActionMiniButton}"
HorizontalAlignment="Right"