1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Profile editor - Added F5 hotkey to toggle normal profile playback

Profile editor - Disable toolbar and tools during normal profile playback
Layer conditions - Properly apply Skip To End stop-mode on profile start
This commit is contained in:
Robert 2021-07-02 23:18:50 +02:00
parent 472bcccdb6
commit 51a5724adf
14 changed files with 110 additions and 37 deletions

View File

@ -397,7 +397,7 @@ namespace Artemis.Core
if (conditionMet && !DisplayConditionMet && Timeline.IsFinished)
Timeline.JumpToStart();
// If regular conditions are no longer met, jump to the end segment if stop mode requires it
if (!conditionMet && DisplayConditionMet && Timeline.StopMode == TimelineStopMode.SkipToEnd)
if (!conditionMet && Timeline.StopMode == TimelineStopMode.SkipToEnd)
Timeline.JumpToEndSegment();
}
else if (conditionMet)

View File

@ -216,7 +216,8 @@ namespace Artemis.Core.Services
if (shouldBeActive)
{
profileConfiguration.Update();
shouldBeActive = profileConfiguration.ActivationConditionMet;
if (!profileConfiguration.IsBeingEdited)
shouldBeActive = profileConfiguration.ActivationConditionMet;
}
try

View File

@ -163,6 +163,9 @@ namespace Artemis.UI.Shared.Services
{
lock (_selectedProfileLock)
{
if (SuspendEditing)
throw new ArtemisSharedUIException("Cannot change the selected profile while editing is suspended");
if (SelectedProfileConfiguration == profileConfiguration)
return;
@ -170,17 +173,21 @@ namespace Artemis.UI.Shared.Services
throw new ArtemisSharedUIException("Cannot select a disposed profile");
_logger.Verbose("ChangeSelectedProfileConfiguration {profile}", profileConfiguration);
if (SelectedProfileConfiguration != null)
SaveSelectedProfileConfiguration();
ChangeSelectedProfileElement(null);
ProfileConfigurationEventArgs profileConfigurationElementEvent = new(profileConfiguration, SelectedProfileConfiguration);
// No need to deactivate the profile, if needed it will be deactivated next update
if (SelectedProfileConfiguration != null)
SelectedProfileConfiguration.IsBeingEdited = false;
// The new profile may need activation
PreviousSelectedProfileConfiguration = SelectedProfileConfiguration;
SelectedProfileConfiguration = profileConfiguration;
;
// The new profile may need activation
if (SelectedProfileConfiguration != null)
{
SelectedProfileConfiguration.IsBeingEdited = true;

View File

@ -462,7 +462,7 @@
The profile is currently running in normal mode and the timeline cannot be edited.
</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody2TextBlock}" TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center">
Press <Run Text="F5" FontWeight="Bold"/> to toggle between editor mode and normal mode. Auto-switching can be disabled in the options menu.
Press <Run Text="F5" FontWeight="Bold"/> to switch between editor mode and normal mode. Auto-switching can be disabled in the options menu.
</TextBlock>
</StackPanel>
</Border>

View File

@ -26,6 +26,8 @@
<UserControl.InputBindings>
<KeyBinding Command="{s:Action Undo}" Modifiers="Control" Key="Z" />
<KeyBinding Command="{s:Action Redo}" Modifiers="Control" Key="Y" />
<KeyBinding Command="{s:Action ToggleSuspend}" Key="F5" />
<KeyBinding Command="{s:Action ToggleAutoSuspend}" Modifiers="Ctrl" Key="F5" />
</UserControl.InputBindings>
<Grid ClipToBounds="True">
@ -97,6 +99,17 @@
Command="{s:Action Paste}"
InputGestureText="Ctrl+V" />
</MenuItem>
<MenuItem Header="_Run">
<MenuItem Header="_Switch run mode"
Icon="{materialDesign:PackIcon Kind=SwapHorizontal}"
Command="{s:Action ToggleSuspend}"
InputGestureText="F5" />
<MenuItem Header="Run Profile on Focus Loss"
ToolTip="If enabled, regular profile playback is resumed on focus loss"
IsCheckable="True"
IsChecked="{Binding StopOnFocusLoss.Value}"
InputGestureText="Ctrl+F5" />
</MenuItem>
<MenuItem Header="_Scripting" IsEnabled="False">
<MenuItem Header="_Profile Scripts"
Icon="{materialDesign:PackIcon Kind=BookEdit}"
@ -119,10 +132,7 @@
<MenuItem Header="Display Data Model Values"
IsCheckable="True"
IsChecked="{Binding ShowDataModelValues.Value}"/>
<MenuItem Header="Run Profile on Focus Loss"
ToolTip="If enabled, regular profile playback is resumed on focus loss"
IsCheckable="True"
IsChecked="{Binding StopOnFocusLoss.Value}"/>
<MenuItem Header="Apply All Data Bindings During Edit"
ToolTip="If enabled, updates all data bindings instead of only the one you are editing"
IsCheckable="True"

View File

@ -37,7 +37,8 @@ namespace Artemis.UI.Screens.ProfileEditor
private LayerPropertiesViewModel _layerPropertiesViewModel;
private ProfileTreeViewModel _profileTreeViewModel;
private ProfileViewModel _profileViewModel;
private bool _suspendedManually;
public ProfileEditorViewModel(ProfileViewModel profileViewModel,
ProfileTreeViewModel profileTreeViewModel,
DisplayConditionsViewModel dataModelConditionsViewModel,
@ -62,7 +63,7 @@ namespace Artemis.UI.Screens.ProfileEditor
_eventAggregator = eventAggregator;
_scriptVmFactory = scriptVmFactory;
_sidebarVmFactory = sidebarVmFactory;
DisplayName = "Profile Editor";
DialogService = dialogService;
@ -105,6 +106,12 @@ namespace Artemis.UI.Screens.ProfileEditor
set => SetAndNotify(ref _profileViewModel, value);
}
public bool SuspendedManually
{
get => _suspendedManually;
set => SetAndNotify(ref _suspendedManually, value);
}
public PluginSetting<GridLength> SidePanelsWidth => _settingsService.GetSetting("ProfileEditor.SidePanelsWidth", new GridLength(385));
public PluginSetting<GridLength> DataModelConditionsHeight => _settingsService.GetSetting("ProfileEditor.DataModelConditionsHeight", new GridLength(345));
public PluginSetting<GridLength> BottomPanelsHeight => _settingsService.GetSetting("ProfileEditor.BottomPanelsHeight", new GridLength(265));
@ -168,6 +175,17 @@ namespace Artemis.UI.Screens.ProfileEditor
_messageService.ShowMessage("Redid profile update", "UNDO", Undo);
}
public void ToggleSuspend()
{
_profileEditorService.SuspendEditing = !_profileEditorService.SuspendEditing;
SuspendedManually = _profileEditorService.SuspendEditing;
}
public void ToggleAutoSuspend()
{
StopOnFocusLoss.Value = !StopOnFocusLoss.Value;
}
#region Overrides of Screen
protected override void OnInitialActivate()
@ -194,6 +212,8 @@ namespace Artemis.UI.Screens.ProfileEditor
_profileEditorService.SelectedProfileElementChanged -= ProfileEditorServiceOnSelectedProfileElementChanged;
_eventAggregator.Unsubscribe(this);
SaveWorkspaceSettings();
_profileEditorService.SuspendEditing = false;
_profileEditorService.ChangeSelectedProfileConfiguration(null);
base.OnClose();
@ -210,7 +230,7 @@ namespace Artemis.UI.Screens.ProfileEditor
{
NotifyOfPropertyChange(nameof(HasSelectedElement));
}
private void SaveWorkspaceSettings()
{
SidePanelsWidth.Save();
@ -322,7 +342,7 @@ namespace Artemis.UI.Screens.ProfileEditor
/// <inheritdoc />
public void Handle(MainWindowFocusChangedEvent message)
{
if (!StopOnFocusLoss.Value)
if (!StopOnFocusLoss.Value || SuspendedManually)
return;
_profileEditorService.SuspendEditing = !message.IsFocused;

View File

@ -87,7 +87,8 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
Execute.PostToUIThread(async () =>
{
await Task.Delay(1500);
SelectedTreeItem = ActiveItem.GetAllChildren().FirstOrDefault(c => c.ProfileElement == _profileEditorService.SelectedProfileElement);
if (ActiveItem != null)
SelectedTreeItem = ActiveItem.GetAllChildren().FirstOrDefault(c => c.ProfileElement == _profileEditorService.SelectedProfileElement);
});
}

View File

@ -1,4 +1,4 @@
<UserControl x:Class="Artemis.UI.Screens.ProfileEditor.Visualization.ProfileView"
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@ -7,9 +7,13 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:visualization="clr-namespace:Artemis.UI.Screens.ProfileEditor.Visualization"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:Converters="clr-namespace:Artemis.UI.Converters" x:Class="Artemis.UI.Screens.ProfileEditor.Visualization.ProfileView"
mc:Ignorable="d"
d:DesignHeight="510.9" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type visualization:ProfileViewModel}}">
<UserControl.Resources>
<Converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
@ -27,13 +31,16 @@
<ListBoxItem ToolTip="Pan over different parts of the surface - Ctrl">
<materialDesign:PackIcon Kind="HandLeft" />
</ListBoxItem>
<ListBoxItem ToolTip="Transform layer shape (hold SHIFT for incremental changes and X/Y snapping) - Ctrl+T" IsEnabled="{Binding CanSelectEditTool}">
<ListBoxItem ToolTip="Transform layer shape (hold SHIFT for incremental changes and X/Y snapping) - Ctrl+T"
IsEnabled="{Binding CanSelectEditTool}">
<materialDesign:PackIcon Kind="TransitConnectionVariant" />
</ListBoxItem>
<ListBoxItem ToolTip="Change layer selection (hold SHIFT to add to existing selection) - Ctrl+Q">
<ListBoxItem ToolTip="Change layer selection (hold SHIFT to add to existing selection) - Ctrl+Q"
IsEnabled="{Binding SuspendedEditing, Converter={StaticResource InverseBooleanConverter}, Mode=OneWay}">
<materialDesign:PackIcon Kind="SelectionDrag" />
</ListBoxItem>
<ListBoxItem ToolTip="Remove from layer selection - Ctrl+W">
<ListBoxItem ToolTip="Remove from layer selection - Ctrl+W"
IsEnabled="{Binding SuspendedEditing, Converter={StaticResource InverseBooleanConverter}, Mode=OneWay}">
<materialDesign:PackIcon Kind="SelectOff" />
</ListBoxItem>
</ListBox>
@ -71,7 +78,7 @@
</VisualBrush>
</Grid.Background>
<Grid Name="DeviceDisplayGrid">
<Grid x:Name="DeviceDisplayGrid">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="{Binding PanZoomViewModel.Zoom}" ScaleY="{Binding PanZoomViewModel.Zoom}" />
@ -85,7 +92,7 @@
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Canvas.Left" Value="{Binding X}" />
<Setter Property="Canvas.Top" Value="{Binding Y}" />
</Style>
@ -94,13 +101,13 @@
<DataTemplate>
<shared:DeviceVisualizer Device="{Binding}"
ShowColors="True"
HighlightedLeds="{Binding DataContext.HighlightedLeds, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Mode=OneWay}" />
HighlightedLeds="{Binding DataContext.HighlightedLeds, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<Grid Name="EditorDisplayGrid"
<Grid x:Name="EditorDisplayGrid"
Visibility="{Binding SuspendedEditing, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}"
shared:SizeObserver.Observe="True"
shared:SizeObserver.ObservedHeight="{Binding PanZoomViewModel.CanvasHeight}"
@ -118,7 +125,7 @@
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Canvas.Left" Value="{Binding X}" />
<Setter Property="Canvas.Top" Value="{Binding Y}" />
</Style>
@ -130,9 +137,9 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<StackPanel Orientation="Vertical" VerticalAlignment="Bottom" HorizontalAlignment="Right"
Margin="10" ZIndex="1">
Margin="10" Panel.ZIndex="1">
<Slider Orientation="Vertical"
HorizontalAlignment="Center"
Margin="0 10"

View File

@ -232,12 +232,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
if (CanSelectEditTool == false && ActiveToolIndex == 1)
ActivateToolByIndex(2);
}
private void ProfileEditorServiceOnSuspendEditingChanged(object? sender, EventArgs e)
{
NotifyOfPropertyChange(nameof(SuspendedEditing));
}
#region Buttons
private void ActivateToolByIndex(int value)
@ -315,7 +310,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
TimeSpan delta = DateTime.Now - _lastUpdate;
_lastUpdate = DateTime.Now;
if (!_settingsService.GetSetting("ProfileEditor.AlwaysApplyDataBindings", true).Value || _profileEditorService.SelectedProfile == null)
if (SuspendedEditing || !_settingsService.GetSetting("ProfileEditor.AlwaysApplyDataBindings", true).Value || _profileEditorService.SelectedProfile == null)
return;
foreach (IDataBindingRegistration dataBindingRegistration in _profileEditorService.SelectedProfile.GetAllFolders()
@ -396,6 +391,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
ActivateToolByIndex(2);
}
private void ProfileEditorServiceOnSuspendEditingChanged(object? sender, EventArgs e)
{
NotifyOfPropertyChange(nameof(SuspendedEditing));
UpdateCanSelectEditTool();
}
public void Handle(MainWindowKeyEvent message)
{
if (message.KeyDown)

View File

@ -32,6 +32,9 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
{
base.MouseUp(sender, e);
if (ProfileEditorService.SuspendEditing)
return;
Point position = PanZoomViewModel.GetRelativeMousePosition(sender, e);
Rect selectedRect = new(MouseDownStartPosition, position);

View File

@ -37,6 +37,9 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
{
base.MouseUp(sender, e);
if (ProfileEditorService.SuspendEditing)
return;
Point position = PanZoomViewModel.GetRelativeMousePosition(sender, e);
Rect selectedRect = new(MouseDownStartPosition, position);

View File

@ -20,6 +20,7 @@
UseLayoutRounding="True"
Deactivated="{s:Action WindowDeactivated}"
Activated="{s:Action WindowActivated}"
StateChanged="{s:Action WindowStateChanged}"
KeyDown="{s:Action WindowKeyDown}"
KeyUp="{s:Action WindowKeyUp}"
MouseDown="{s:Action WindowMouseDown}"

View File

@ -1,5 +1,6 @@
using System;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
@ -79,8 +80,7 @@ namespace Artemis.UI.Screens
public void WindowDeactivated()
{
WindowState windowState = ((Window) View).WindowState;
if (windowState == WindowState.Minimized)
if (_lostFocus)
return;
_lostFocus = true;
@ -91,13 +91,30 @@ namespace Artemis.UI.Screens
{
if (!_lostFocus)
return;
if (!((MaterialWindow)View).IsActive)
return;
_lostFocus = false;
_eventAggregator.Publish(new MainWindowFocusChangedEvent(true));
}
// This is required because Windows incorrectly tells the window it is activated when minimizing using the taskbar
public void WindowStateChanged()
{
if (((Window) View).WindowState == WindowState.Minimized)
WindowDeactivated();
else
WindowActivated();
}
#region Overrides of Screen
/// <inheritdoc />
protected override void OnStateChanged(ScreenState previousState, ScreenState newState)
{
base.OnStateChanged(previousState, newState);
}
#endregion
public void WindowKeyDown(object sender, KeyEventArgs e)
{
_eventAggregator.Publish(new MainWindowKeyEvent(sender, true, e));

View File

@ -153,6 +153,8 @@ namespace Artemis.UI.Screens.Sidebar
foreach (SidebarCategoryViewModel sidebarCategoryViewModel in Items)
sidebarCategoryViewModel.SelectedProfileConfiguration = sidebarCategoryViewModel.Items.FirstOrDefault(i => i.ProfileConfiguration == profileConfiguration);
if (_profileEditorService.SuspendEditing)
_profileEditorService.SuspendEditing = false;
_profileEditorService.ChangeSelectedProfileConfiguration(profileConfiguration);
if (profileConfiguration != null)
{