Core - Reworked profile render override for the editor and new previewer

This commit is contained in:
Robert committed 2023-08-10 11:54:37 +02:00
1 parent c6a318b6e3
commit d2b8123a30
42 files changed
+812 -399

No files matched your search

@@ -1,4 +1,3 @@
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
@@ -9,9 +8,4 @@ public partial class EntryTypeView : ReactiveUserControl<EntryTypeViewModel>
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
@@ -1,6 +1,6 @@
using System;
using System.Reactive;
using System.Reactive.Linq;
using Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
using Artemis.WebClient.Workshop;
using ReactiveUI;
@@ -1,4 +1,3 @@
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
@@ -9,9 +8,4 @@ public partial class LoginStepView : ReactiveUserControl<LoginStepView>
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
@@ -0,0 +1,51 @@
using System.Reactive;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Screens.ProfileEditor.ProfileTree.Dialogs;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using FluentAvalonia.Core;
using ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
public class ProfileAdaptionHintsLayerViewModel : ViewModelBase
{
private readonly IWindowService _windowService;
private readonly IProfileService _profileService;
private readonly ObservableAsPropertyHelper<string> _adaptionHintText;
private int _adaptionHintCount;
public Layer Layer { get; }
public ProfileAdaptionHintsLayerViewModel(Layer layer, IWindowService windowService, IProfileService profileService)
{
_windowService = windowService;
_profileService = profileService;
_adaptionHintText = this.WhenAnyValue(vm => vm.AdaptionHintCount).Select(c => c == 1 ? "1 adaption hint" : $"{c} adaption hints").ToProperty(this, vm => vm.AdaptionHintText);
Layer = layer;
EditAdaptionHints = ReactiveCommand.CreateFromTask(ExecuteEditAdaptionHints);
AdaptionHintCount = layer.Adapter.AdaptionHints.Count;
}
public ReactiveCommand<Unit, Unit> EditAdaptionHints { get; }
public int AdaptionHintCount
{
get => _adaptionHintCount;
private set => RaiseAndSetIfChanged(ref _adaptionHintCount, value);
}
public string AdaptionHintText => _adaptionHintText.Value;
private async Task ExecuteEditAdaptionHints()
{
await _windowService.ShowDialogAsync<LayerHintsDialogViewModel, bool>(Layer);
_profileService.SaveProfile(Layer.Profile, true);
AdaptionHintCount = Layer.Adapter.AdaptionHints.Count;
}
}
@@ -0,0 +1,67 @@
<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:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:profile="clr-namespace:Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile.ProfileAdaptionHintsStepView"
x:DataType="profile:ProfileAdaptionHintsStepViewModel">
<Grid ColumnDefinitions="*,Auto" RowDefinitions="Auto,Auto, *">
<Grid.Styles>
<Styles>
<Style Selector="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"></Setter>
</Style>
</Styles>
</Grid.Styles>
<TextBlock Grid.Row="0" Theme="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap">
Set up profile adaption hints
</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" TextWrapping="Wrap">
Add hints below to help decide where to place this each layer when the profile is imported by another user.
</TextBlock>
<controls:HyperlinkButton Grid.Row="0"
Grid.Column="1"
VerticalAlignment="Top"
NavigateUri="https://wiki.artemis-rgb.com/guides/user/profiles/layers/adaption-hints?mtm_campaign=artemis&amp;mtm_kwd=workshop-wizard">
Learn more about adaption hints
</controls:HyperlinkButton>
<ItemsRepeater ItemsSource="{CompiledBinding Layers}" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="0 10 0 0">
<ItemsRepeater.ItemTemplate>
<DataTemplate DataType="profile:ProfileAdaptionHintsLayerViewModel">
<StackPanel>
<Border Classes="card-separator" />
<Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="*,*">
<avalonia:MaterialIcon Grid.Column="0"
Grid.Row="0"
Grid.RowSpan="2"
Width="25"
Height="25"
Margin="5 0 10 0"
Kind="{CompiledBinding Layer.LayerBrush.Descriptor.Icon, FallbackValue=QuestionMark}" />
<TextBlock Grid.Column="1" Grid.Row="0" Text="{CompiledBinding Layer.Name}" />
<TextBlock Grid.Column="1"
Grid.Row="1"
VerticalAlignment="Top"
Classes="subtitle"
Classes.danger="{CompiledBinding !AdaptionHintCount}"
Text="{CompiledBinding AdaptionHintText}">
</TextBlock>
<Button Grid.Column="2"
Grid.Row="0"
Grid.RowSpan="2"
Command="{Binding EditAdaptionHints}">
Edit hints
</Button>
</Grid>
</StackPanel>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
</UserControl>
@@ -0,0 +1,11 @@
using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
public partial class ProfileAdaptionHintsStepView : ReactiveUserControl<ProfileAdaptionHintsStepViewModel>
{
public ProfileAdaptionHintsStepView()
{
InitializeComponent();
}
}
@@ -0,0 +1,66 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Screens.ProfileEditor.ProfileTree.Dialogs;
using Artemis.UI.Shared.Services;
using DynamicData;
using ReactiveUI;
using DynamicData.Aggregation;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
public class ProfileAdaptionHintsStepViewModel : SubmissionViewModel
{
private readonly IWindowService _windowService;
private readonly IProfileService _profileService;
private readonly SourceList<ProfileAdaptionHintsLayerViewModel> _layers;
public ProfileAdaptionHintsStepViewModel(IWindowService windowService, IProfileService profileService, Func<Layer, ProfileAdaptionHintsLayerViewModel> getLayerViewModel)
{
_windowService = windowService;
_profileService = profileService;
_layers = new SourceList<ProfileAdaptionHintsLayerViewModel>();
_layers.Connect().Bind(out ReadOnlyObservableCollection<ProfileAdaptionHintsLayerViewModel> layers).Subscribe();
GoBack = ReactiveCommand.Create(() => State.ChangeScreen<ProfileSelectionStepViewModel>());
Continue = ReactiveCommand.Create(ExecuteContinue, _layers.Connect().AutoRefresh(l => l.AdaptionHintCount).Filter(l => l.AdaptionHintCount == 0).IsEmpty());
EditAdaptionHints = ReactiveCommand.CreateFromTask<Layer>(ExecuteEditAdaptionHints);
Layers = layers;
this.WhenActivated((CompositeDisposable _) =>
{
if (State.EntrySource is ProfileConfiguration profileConfiguration && profileConfiguration.Profile != null)
{
_layers.Edit(l =>
{
l.Clear();
l.AddRange(profileConfiguration.Profile.GetAllLayers().Select(getLayerViewModel));
});
}
});
}
public override ReactiveCommand<Unit, Unit> Continue { get; }
public override ReactiveCommand<Unit, Unit> GoBack { get; }
public ReactiveCommand<Layer, Unit> EditAdaptionHints { get; }
public ReadOnlyObservableCollection<ProfileAdaptionHintsLayerViewModel> Layers { get; }
private async Task ExecuteEditAdaptionHints(Layer layer)
{
await _windowService.ShowDialogAsync<LayerHintsDialogViewModel, bool>(layer);
_profileService.SaveProfile(layer.Profile, true);
}
private void ExecuteContinue()
{
if (Layers.Any(l => l.AdaptionHintCount == 0))
return;
}
}
@@ -0,0 +1,56 @@
<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:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:profile="clr-namespace:Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile.ProfileSelectionStepView"
x:DataType="profile:ProfileSelectionStepViewModel">
<Grid RowDefinitions="Auto,*">
<StackPanel>
<StackPanel.Styles>
<Styles>
<Style Selector="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"></Setter>
</Style>
</Styles>
</StackPanel.Styles>
<TextBlock Theme="{StaticResource TitleTextBlockStyle}" TextWrapping="Wrap">
Profile selection
</TextBlock>
<TextBlock TextWrapping="Wrap">
Please select the profile you want to share, a preview will be shown below.
</TextBlock>
<ComboBox ItemsSource="{CompiledBinding Profiles}" SelectedItem="{CompiledBinding SelectedProfile}"
Width="460"
VerticalContentAlignment="Center"
Height="50"
Margin="0 15"
PlaceholderText="Select a profile">
<ComboBox.ItemTemplate>
<DataTemplate DataType="core:ProfileConfiguration">
<Grid RowDefinitions="Auto,*" ColumnDefinitions="Auto,*">
<shared:ProfileConfigurationIcon Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
ConfigurationIcon="{CompiledBinding Icon}"
VerticalAlignment="Center"
Width="22"
Height="22"
Margin="0 0 10 0" />
<TextBlock Grid.Row="0" Grid.Column="1" Text="{CompiledBinding Name}" TextTrimming="CharacterEllipsis"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{CompiledBinding Category.Name}" TextTrimming="CharacterEllipsis" Classes="subtitle"></TextBlock>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
<Border Grid.Row="1" Classes="card" Padding="0" ClipToBounds="True" IsVisible="{CompiledBinding SelectedProfile, Converter={x:Static ObjectConverters.IsNotNull}}">
<ContentControl Content="{CompiledBinding ProfilePreview}"></ContentControl>
</Border>
</Grid>
</UserControl>
@@ -0,0 +1,11 @@
using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
public partial class ProfileSelectionStepView : ReactiveUserControl<ProfileSelectionStepViewModel>
{
public ProfileSelectionStepView()
{
InitializeComponent();
}
}
@@ -0,0 +1,83 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Repositories.Interfaces;
using Artemis.UI.Screens.Workshop.Profile;
using ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.Profile;
public class ProfileSelectionStepViewModel : SubmissionViewModel
{
private readonly IProfileService _profileService;
private readonly IProfileCategoryRepository _profileCategoryRepository;
private ProfileConfiguration? _selectedProfile;
/// <inheritdoc />
public ProfileSelectionStepViewModel(IProfileService profileService, ProfilePreviewViewModel profilePreviewViewModel)
{
_profileService = profileService;
// Use copies of the profiles, the originals are used by the core and could be disposed
Profiles = new ObservableCollection<ProfileConfiguration>(_profileService.ProfileConfigurations.Select(_profileService.CloneProfileConfiguration));
ProfilePreview = profilePreviewViewModel;
GoBack = ReactiveCommand.Create(() => State.ChangeScreen<EntryTypeViewModel>());
Continue = ReactiveCommand.Create(ExecuteContinue, this.WhenAnyValue(vm => vm.SelectedProfile).Select(p => p != null));
this.WhenAnyValue(vm => vm.SelectedProfile).Subscribe(p => Update(p));
this.WhenActivated((CompositeDisposable _) =>
{
if (State.EntrySource is ProfileConfiguration profileConfiguration)
SelectedProfile = Profiles.FirstOrDefault(p => p.ProfileId == profileConfiguration.ProfileId);
});
}
private void Update(ProfileConfiguration? profileConfiguration)
{
ProfilePreview.ProfileConfiguration = null;
foreach (ProfileConfiguration configuration in Profiles)
{
if (configuration == profileConfiguration)
_profileService.ActivateProfile(configuration);
else
_profileService.DeactivateProfile(configuration);
}
ProfilePreview.ProfileConfiguration = profileConfiguration;
}
public ObservableCollection<ProfileConfiguration> Profiles { get; }
public ProfilePreviewViewModel ProfilePreview { get; }
public ProfileConfiguration? SelectedProfile
{
get => _selectedProfile;
set => RaiseAndSetIfChanged(ref _selectedProfile, value);
}
/// <inheritdoc />
public override ReactiveCommand<Unit, Unit> Continue { get; }
/// <inheritdoc />
public override ReactiveCommand<Unit, Unit> GoBack { get; }
private void ExecuteContinue()
{
if (SelectedProfile == null)
return;
State.EntrySource = SelectedProfile;
State.Name = SelectedProfile.Name;
State.Icon = SelectedProfile.Icon.GetIconStream();
State.ChangeScreen<ProfileAdaptionHintsStepViewModel>();
}
}
@@ -1,10 +0,0 @@
<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:steps="clr-namespace:Artemis.UI.Screens.Workshop.SubmissionWizard.Steps"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.ProfileSelectionStepView"
x:DataType="steps:ProfileSelectionStepViewModel">
Welcome to Avalonia!
</UserControl>
@@ -1,18 +0,0 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
public partial class ProfileSelectionStepView : UserControl
{
public ProfileSelectionStepView()
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
@@ -1,13 +0,0 @@
using System.Reactive;
using ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
public class ProfileSelectionStepViewModel : SubmissionViewModel
{
/// <inheritdoc />
public override ReactiveCommand<Unit, Unit> Continue { get; }
/// <inheritdoc />
public override ReactiveCommand<Unit, Unit> GoBack { get; }
}
@@ -1,4 +1,3 @@
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
@@ -9,9 +8,4 @@ public partial class ValidateEmailStepView : ReactiveUserControl<ValidateEmailSt
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
@@ -1,4 +1,3 @@
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
@@ -9,9 +8,4 @@ public partial class WelcomeStepView : ReactiveUserControl<WelcomeStepViewModel>
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
@@ -7,8 +7,8 @@ namespace Artemis.UI.Screens.Workshop.SubmissionWizard;
public class SubmissionWizardState
{
private readonly SubmissionWizardViewModel _wizardViewModel;
private readonly IContainer _container;
private readonly SubmissionWizardViewModel _wizardViewModel;
public SubmissionWizardState(SubmissionWizardViewModel wizardViewModel, IContainer container)
{
@@ -27,6 +27,8 @@ public class SubmissionWizardState
public List<int> Tags { get; set; } = new();
public List<Stream> Images { get; set; } = new();
public object? EntrySource { get; set; }
public void ChangeScreen<TSubmissionViewModel>() where TSubmissionViewModel : SubmissionViewModel
{
_wizardViewModel.Screen = _container.Resolve<TSubmissionViewModel>();