mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Profile editor - Integrated visual scripting
This commit is contained in:
1 parent
372991a69b
commit
66ea718316
96 files changed
+2413
-238
No files matched your search
+52
@@ -0,0 +1,52 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
xmlns:dataBinding="clr-namespace:Artemis.UI.Screens.ProfileEditor.Properties.DataBinding"
|
||||
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.ProfileEditor.Properties.DataBinding.DataBindingView"
|
||||
x:DataType="dataBinding:DataBindingViewModel">
|
||||
<Grid RowDefinitions="48,*">
|
||||
<Grid Grid.Row="0" ColumnDefinitions="Auto,Auto,*">
|
||||
<TextBlock Grid.Column="0"
|
||||
Classes="h5"
|
||||
VerticalAlignment="Center"
|
||||
Text="{CompiledBinding LayerProperty.PropertyDescription.Name}"
|
||||
Margin="10 0" />
|
||||
<ToggleSwitch Grid.Column="1"
|
||||
OnContent="Data binding enabled"
|
||||
OffContent="Data binding disabled"
|
||||
VerticalAlignment="Center"
|
||||
IsChecked="{CompiledBinding DataBindingEnabled}" />
|
||||
<Button Grid.Column="2"
|
||||
Classes="icon-button"
|
||||
ToolTip.Tip="Open editor"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="10"
|
||||
Command="{Binding OpenEditor}">
|
||||
<avalonia:MaterialIcon Kind="OpenInNew"></avalonia:MaterialIcon>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<ContentControl Grid.Row="1"
|
||||
IsVisible="{CompiledBinding NodeScriptViewModel, Converter={x:Static ObjectConverters.IsNotNull}}"
|
||||
Content="{CompiledBinding NodeScriptViewModel}" />
|
||||
|
||||
<StackPanel Grid.Row="1"
|
||||
VerticalAlignment="Center"
|
||||
IsVisible="{CompiledBinding NodeScriptViewModel, Converter={x:Static ObjectConverters.IsNull}}">
|
||||
<TextBlock TextAlignment="Center" Classes="h5">To use data bindings enable them in with the toggle above.</TextBlock>
|
||||
<TextBlock TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center" Foreground="{DynamicResource TextFillColorSecondary}">
|
||||
When you enable data bindings you can no longer use keyframes or normal values for this property.
|
||||
</TextBlock>
|
||||
<controls:HyperlinkButton HorizontalAlignment="Center"
|
||||
NavigateUri="https://wiki.artemis-rgb.com/en/guides/user/profiles/data-bindings"
|
||||
Margin="0 10">
|
||||
Learn more
|
||||
</controls:HyperlinkButton>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.Properties.DataBinding
|
||||
{
|
||||
public partial class DataBindingView : ReactiveUserControl<DataBindingViewModel>
|
||||
{
|
||||
public DataBindingView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.VisualScripting;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor.Commands;
|
||||
using Avalonia.Controls.Mixins;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.Properties.DataBinding;
|
||||
|
||||
public class DataBindingViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IWindowService _windowService;
|
||||
private ObservableAsPropertyHelper<bool>? _dataBindingEnabled;
|
||||
private ObservableAsPropertyHelper<ILayerProperty?>? _layerProperty;
|
||||
private ObservableAsPropertyHelper<NodeScriptViewModel?>? _nodeScriptViewModel;
|
||||
|
||||
public DataBindingViewModel(IProfileEditorService profileEditorService, INodeVmFactory nodeVmFactory, IWindowService windowService)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_windowService = windowService;
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
_layerProperty = profileEditorService.LayerProperty.ToProperty(this, vm => vm.LayerProperty).DisposeWith(d);
|
||||
_nodeScriptViewModel = profileEditorService.LayerProperty
|
||||
.Select(p => p != null ? p.BaseDataBinding.GetObservable() : Observable.Never<IDataBinding>())
|
||||
.Switch()
|
||||
.Select(b => b.IsEnabled ? nodeVmFactory.NodeScriptViewModel((NodeScript) b.Script, false) : null)
|
||||
.ToProperty(this, vm => vm.NodeScriptViewModel)
|
||||
.DisposeWith(d);
|
||||
_dataBindingEnabled = profileEditorService.LayerProperty
|
||||
.Select(p => p != null ? p.BaseDataBinding.GetObservable() : Observable.Never<IDataBinding>())
|
||||
.Switch()
|
||||
.Select(b => b.IsEnabled)
|
||||
.ToProperty(this, vm => vm.DataBindingEnabled)
|
||||
.DisposeWith(d);
|
||||
});
|
||||
}
|
||||
|
||||
public ILayerProperty? LayerProperty => _layerProperty?.Value;
|
||||
public NodeScriptViewModel? NodeScriptViewModel => _nodeScriptViewModel?.Value;
|
||||
|
||||
public bool DataBindingEnabled
|
||||
{
|
||||
get => _dataBindingEnabled?.Value ?? false;
|
||||
set
|
||||
{
|
||||
if (LayerProperty != null)
|
||||
_profileEditorService.ExecuteCommand(new ChangeDataBindingEnabled(LayerProperty, value));
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OpenEditor()
|
||||
{
|
||||
if (LayerProperty != null && LayerProperty.BaseDataBinding.IsEnabled)
|
||||
await _windowService.ShowDialogAsync<NodeScriptWindowViewModel, bool>(("nodeScript", LayerProperty.BaseDataBinding.Script));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user