1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 13:28:33 +00:00

Upgrade Avalonia

This commit is contained in:
Robert 2023-07-26 22:13:40 +02:00
parent e03d6b20e9
commit ee6d295fd8
24 changed files with 337 additions and 311 deletions

View File

@ -1,3 +1,4 @@
using System;
using Artemis.Core.Services;
using Artemis.UI.Linux.DryIoc;
using Artemis.UI.Linux.Providers.Input;
@ -26,15 +27,11 @@ public class App : Application
public override void OnFrameworkInitializationCompleted()
{
if (Design.IsDesignMode)
if (ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop || Design.IsDesignMode)
return;
if (ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
return;
ArtemisBootstrapper.Initialize();
_applicationStateManager = new ApplicationStateManager(_container!, desktop.Args);
_applicationStateManager = new ApplicationStateManager(_container!, desktop.Args ?? Array.Empty<string>());
ArtemisBootstrapper.Initialize();
RegisterProviders();
}

View File

@ -1,4 +1,5 @@
using System;
using System.Reactive.Disposables;
using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Controls;
@ -26,6 +27,8 @@ public class ReactiveAppWindow<TViewModel> : AppWindow, IViewFor<TViewModel> whe
public static readonly StyledProperty<TViewModel?> ViewModelProperty = AvaloniaProperty
.Register<ReactiveAppWindow<TViewModel>, TViewModel?>(nameof(ViewModel));
private bool _micaEnabled;
/// <summary>
/// Initializes a new instance of the <see cref="ReactiveAppWindow{TViewModel}" /> class.
/// </summary>
@ -33,23 +36,33 @@ public class ReactiveAppWindow<TViewModel> : AppWindow, IViewFor<TViewModel> whe
{
// This WhenActivated block calls ViewModel's WhenActivated
// block if the ViewModel implements IActivatableViewModel.
this.WhenActivated(disposables => { });
this.WhenActivated(disposables => UI.MicaEnabled.Subscribe(ToggleMica).DisposeWith(disposables));
this.GetObservable(DataContextProperty).Subscribe(OnDataContextChanged);
this.GetObservable(ViewModelProperty).Subscribe(OnViewModelChanged);
}
/// <inheritdoc />
protected override void OnOpened(EventArgs e)
private void ToggleMica(bool enable)
{
// TODO: Move to a style and remove opacity on focus loss
base.OnOpened(e);
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !IsWindows11)
if (enable == _micaEnabled)
return;
TransparencyBackgroundFallback = Brushes.Transparent;
TransparencyLevelHint = new[] {WindowTransparencyLevel.Mica};
TryEnableMicaEffect();
if (enable)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !IsWindows11)
return;
// TransparencyBackgroundFallback = Brushes.Transparent;
TransparencyLevelHint = new[] {WindowTransparencyLevel.Mica};
Background = new SolidColorBrush(new Color(80, 0,0,0));
}
else
{
ClearValue(TransparencyLevelHintProperty);
ClearValue(BackgroundProperty);
}
_micaEnabled = enable;
}
private void OnDataContextChanged(object? value)
@ -67,32 +80,6 @@ public class ReactiveAppWindow<TViewModel> : AppWindow, IViewFor<TViewModel> whe
else if (DataContext != value) DataContext = value;
}
private void TryEnableMicaEffect()
{
// The background colors for the Mica brush are still based around SolidBackgroundFillColorBase resource
// BUT since we can't control the actual Mica brush color, we have to use the window background to create
// the same effect. However, we can't use SolidBackgroundFillColorBase directly since its opaque, and if
// we set the opacity the color become lighter than we want. So we take the normal color, darken it and
// apply the opacity until we get the roughly the correct color
// NOTE that the effect still doesn't look right, but it suffices. Ideally we need access to the Mica
// CompositionBrush to properly change the color but I don't know if we can do that or not
if (ActualThemeVariant == ThemeVariant.Dark)
{
Color2 color = this.TryFindResource("SolidBackgroundFillColorBase", ThemeVariant.Dark, out object? value) ? (Color) value : new Color2(32, 32, 32);
color = color.LightenPercent(-0.5f);
Background = new ImmutableSolidColorBrush(color, 0.78);
}
else if (ActualThemeVariant == ThemeVariant.Light)
{
// Similar effect here
Color2 color = this.TryFindResource("SolidBackgroundFillColorBase", ThemeVariant.Light, out object? value) ? (Color) value : new Color2(243, 243, 243);
color = color.LightenPercent(0.5f);
Background = new ImmutableSolidColorBrush(color, 0.9);
}
}
/// <summary>
/// The ViewModel.
/// </summary>

View File

@ -1,29 +1,29 @@
using System;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Input.Platform;
using IContainer = DryIoc.IContainer;
using Avalonia.Threading;
using DryIoc;
namespace Artemis.UI.Shared;
/// <summary>
/// Static UI helpers.
/// Static UI helpers.
/// </summary>
public static class UI
{
private static readonly BehaviorSubject<bool> MicaEnabledSubject = new(false);
public static EventLoopScheduler BackgroundScheduler = new(ts => new Thread(ts));
static UI()
{
KeyBindingsEnabled = InputElement.GotFocusEvent.Raised.Select(e => e.Item2.Source is not TextBox).StartWith(true);
}
public static EventLoopScheduler BackgroundScheduler = new EventLoopScheduler(ts => new Thread(ts));
internal static void ClearCache()
{
DeviceVisualizer.BitmapCache.Clear();
MicaEnabled = MicaEnabledSubject.AsObservable();
}
/// <summary>
@ -40,4 +40,24 @@ public static class UI
/// Gets a boolean indicating whether hotkeys are to be disabled.
/// </summary>
public static IObservable<bool> KeyBindingsEnabled { get; }
/// <summary>
/// Gets a boolean indicating whether the Mica effect should be enabled.
/// </summary>
public static IObservable<bool> MicaEnabled { get; }
/// <summary>
/// Changes whether Mica should be enabled.
/// </summary>
/// <param name="enabled"></param>
public static void SetMicaEnabled(bool enabled)
{
if (MicaEnabledSubject.Value != enabled)
Dispatcher.UIThread.Invoke(() => MicaEnabledSubject.OnNext(enabled));
}
internal static void ClearCache()
{
DeviceVisualizer.BitmapCache.Clear();
}
}

View File

@ -43,8 +43,8 @@ public class App : Application
{
if (ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop || Design.IsDesignMode || _shutDown)
return;
_applicationStateManager = new ApplicationStateManager(_container!, desktop.Args);
_applicationStateManager = new ApplicationStateManager(_container!, desktop.Args ?? Array.Empty<string>());
ArtemisBootstrapper.Initialize();
RegisterProviders(_container!);
}
@ -52,11 +52,14 @@ public class App : Application
private void RegisterProviders(IContainer container)
{
IInputService inputService = container.Resolve<IInputService>();
inputService.AddInputProvider(container.Resolve<InputProvider>(serviceKey: WindowsInputProvider.Id));
inputService.AddInputProvider(container.Resolve<InputProvider>(WindowsInputProvider.Id));
}
private bool FocusExistingInstance()
{
if (Design.IsDesignMode)
return false;
_artemisMutex = new Mutex(true, "Artemis-3c24b502-64e6-4587-84bf-9072970e535f", out bool createdNew);
return !createdNew && RemoteFocus();
}

View File

@ -54,6 +54,7 @@
<ItemGroup>
<UpToDateCheckInput Remove="Screens\Workshop\Categories\Profile\ProfileDetailsView.axaml" />
<UpToDateCheckInput Remove="Screens\Workshop\Categories\Profile\ProfileListView.axaml" />
<UpToDateCheckInput Remove="Controls\AcrylicBlur\AcrylicBlur.axaml" />
</ItemGroup>
<ItemGroup>
@ -61,5 +62,9 @@
<DependentUpon>ProfileListEntryView.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Update="Screens\Workshop\SubmissionWizard\SubmissionWizardView.axaml.cs">
<DependentUpon>StartupWizardView.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
</Project>

View File

@ -1,22 +0,0 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Artemis.UI.Controls"
xmlns:acrylicBlur="clr-namespace:Artemis.UI.Controls.AcrylicBlur"
x:ClassModifier="internal">
<ControlTheme x:Key="{x:Type acrylicBlur:AcrylicBlur}" TargetType="acrylicBlur:AcrylicBlur">
<Setter Property="Template">
<ControlTemplate>
<ContentPresenter Name="PART_ContentPresenter"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Padding="{TemplateBinding Padding}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"/>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>

View File

@ -1,45 +0,0 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
namespace Artemis.UI.Controls.AcrylicBlur;
public class AcrylicBlur : ContentControl
{
private static readonly ImmutableExperimentalAcrylicMaterial DefaultAcrylicMaterial = (ImmutableExperimentalAcrylicMaterial) new ExperimentalAcrylicMaterial()
{
MaterialOpacity = 0.1,
TintColor = new Color(255, 7, 7, 7),
TintOpacity = 1,
PlatformTransparencyCompensationLevel = 0
}.ToImmutable();
public static readonly StyledProperty<ExperimentalAcrylicMaterial?> MaterialProperty =
AvaloniaProperty.Register<AcrylicBlur, ExperimentalAcrylicMaterial?>(nameof(Material));
public ExperimentalAcrylicMaterial? Material
{
get => GetValue(MaterialProperty);
set => SetValue(MaterialProperty, value);
}
public static readonly StyledProperty<int> BlurProperty = AvaloniaProperty.Register<AcrylicBlur, int>(nameof(Blur));
public int Blur
{
get => GetValue(BlurProperty);
set => SetValue(BlurProperty, value);
}
static AcrylicBlur()
{
AffectsRender<AcrylicBlur>(MaterialProperty);
AffectsRender<AcrylicBlur>(BlurProperty);
}
public override void Render(DrawingContext context)
{
ImmutableExperimentalAcrylicMaterial mat = Material != null ? (ImmutableExperimentalAcrylicMaterial) Material.ToImmutable() : DefaultAcrylicMaterial;
context.Custom(new AcrylicBlurRenderOperation(this, mat, Blur, new Rect(default, Bounds.Size)));
}
}

View File

@ -1,138 +0,0 @@
using System;
using System.IO;
using Avalonia;
using Avalonia.Media;
using Avalonia.Platform;
using Avalonia.Rendering.SceneGraph;
using Avalonia.Skia;
using Avalonia.Threading;
using SkiaSharp;
namespace Artemis.UI.Controls.AcrylicBlur;
public class AcrylicBlurRenderOperation : ICustomDrawOperation
{
private static SKShader? _acrylicNoiseShader;
private readonly AcrylicBlur _acrylicBlur;
private readonly ImmutableExperimentalAcrylicMaterial _material;
private readonly int _blur;
private readonly Rect _bounds;
private SKImage? _backgroundSnapshot;
private bool _disposed;
public AcrylicBlurRenderOperation(AcrylicBlur acrylicBlur, ImmutableExperimentalAcrylicMaterial material, int blur, Rect bounds)
{
_acrylicBlur = acrylicBlur;
_material = material;
_blur = blur;
_bounds = bounds;
}
public void Dispose()
{
if (_disposed)
return;
_backgroundSnapshot?.Dispose();
_disposed = true;
}
public bool HitTest(Point p) => _bounds.Contains(p);
static SKColorFilter CreateAlphaColorFilter(double opacity)
{
if (opacity > 1)
opacity = 1;
byte[] c = new byte[256];
byte[] a = new byte[256];
for (int i = 0; i < 256; i++)
{
c[i] = (byte) i;
a[i] = (byte) (i * opacity);
}
return SKColorFilter.CreateTable(a, c, c, c);
}
public void Render(ImmediateDrawingContext context)
{
if (_disposed)
throw new ObjectDisposedException(nameof(AcrylicBlurRenderOperation));
ISkiaSharpApiLeaseFeature? leaseFeature = context.PlatformImpl.GetFeature<ISkiaSharpApiLeaseFeature>();
if (leaseFeature == null)
return;
using ISkiaSharpApiLease lease = leaseFeature.Lease();
if (!lease.SkCanvas.TotalMatrix.TryInvert(out SKMatrix currentInvertedTransform) || lease.SkSurface == null)
return;
if (lease.SkCanvas.GetLocalClipBounds(out SKRect bounds) && !bounds.Contains(SKRect.Create(bounds.Left, bounds.Top, (float) _acrylicBlur.Bounds.Width, (float) _acrylicBlur.Bounds.Height)))
{
Dispatcher.UIThread.Invoke(() => _acrylicBlur.InvalidateVisual());
}
else
{
_backgroundSnapshot?.Dispose();
_backgroundSnapshot = lease.SkSurface.Snapshot();
}
_backgroundSnapshot ??= lease.SkSurface.Snapshot();
using SKShader? backdropShader = SKShader.CreateImage(_backgroundSnapshot, SKShaderTileMode.Clamp, SKShaderTileMode.Clamp, currentInvertedTransform);
using SKSurface? blurred = SKSurface.Create(
lease.GrContext,
false,
new SKImageInfo((int) Math.Ceiling(_bounds.Width), (int) Math.Ceiling(_bounds.Height), SKImageInfo.PlatformColorType, SKAlphaType.Premul)
);
using (SKImageFilter? filter = SKImageFilter.CreateBlur(_blur, _blur, SKShaderTileMode.Clamp))
using (SKPaint blurPaint = new SKPaint {Shader = backdropShader, ImageFilter = filter})
{
blurred.Canvas.DrawRect(0, 0, (float) _bounds.Width, (float) _bounds.Height, blurPaint);
using (SKImage? blurSnap = blurred.Snapshot())
using (SKShader? blurSnapShader = SKShader.CreateImage(blurSnap))
using (SKPaint blurSnapPaint = new SKPaint {Shader = blurSnapShader, IsAntialias = true})
{
// Rendering twice to reduce opacity
lease.SkCanvas.DrawRect(0, 0, (float) _bounds.Width, (float) _bounds.Height, blurSnapPaint);
lease.SkCanvas.DrawRect(0, 0, (float) _bounds.Width, (float) _bounds.Height, blurSnapPaint);
}
//return;
using SKPaint acrylliPaint = new SKPaint();
acrylliPaint.IsAntialias = true;
double opacity = 1;
const double noiseOpacity = 0.0225;
Color tintColor = _material.TintColor;
SKColor tint = new SKColor(tintColor.R, tintColor.G, tintColor.B, tintColor.A);
if (_acrylicNoiseShader == null)
{
using Stream? stream = typeof(SkiaPlatform).Assembly.GetManifestResourceStream("Avalonia.Skia.Assets.NoiseAsset_256X256_PNG.png");
using SKBitmap? bitmap = SKBitmap.Decode(stream);
_acrylicNoiseShader = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat).WithColorFilter(CreateAlphaColorFilter(noiseOpacity));
}
using (SKShader? backdrop = SKShader.CreateColor(new SKColor(_material.MaterialColor.R, _material.MaterialColor.G, _material.MaterialColor.B, _material.MaterialColor.A)))
using (SKShader? tintShader = SKShader.CreateColor(tint))
using (SKShader? effectiveTint = SKShader.CreateCompose(backdrop, tintShader))
using (SKShader? compose = SKShader.CreateCompose(effectiveTint, _acrylicNoiseShader))
{
acrylliPaint.Shader = compose;
acrylliPaint.IsAntialias = true;
lease.SkCanvas.DrawRect(0, 0, (float) _bounds.Width, (float) _bounds.Height, acrylliPaint);
}
}
}
public Rect Bounds => _bounds.Inflate(4);
public bool Equals(ICustomDrawOperation? other)
{
return other is AcrylicBlurRenderOperation op && op._bounds == _bounds && op._material.Equals(_material);
}
}

View File

@ -10,7 +10,7 @@
Icon="/Assets/Images/Logo/application.ico"
Title="Artemis 2.0"
MinWidth="600"
MinHeight="400"
MinHeight="400"
PointerReleased="InputElement_OnPointerReleased">
<windowing:AppWindow.Styles>
<Styles>

View File

@ -20,11 +20,11 @@ namespace Artemis.UI.Screens.Root;
public class RootViewModel : RoutableScreen<IMainScreenViewModel>, IMainWindowProvider
{
private readonly IRouter _router;
private readonly ICoreService _coreService;
private readonly IDebugService _debugService;
private readonly DefaultTitleBarViewModel _defaultTitleBarViewModel;
private readonly IClassicDesktopStyleApplicationLifetime _lifeTime;
private readonly IRouter _router;
private readonly ISettingsService _settingsService;
private readonly IUpdateService _updateService;
private readonly IWindowService _windowService;
@ -41,6 +41,7 @@ public class RootViewModel : RoutableScreen<IMainScreenViewModel>, IMainWindowPr
SidebarViewModel sidebarViewModel,
DefaultTitleBarViewModel defaultTitleBarViewModel)
{
Shared.UI.SetMicaEnabled(settingsService.GetSetting("UI.EnableMica", true).Value);
WindowSizeSetting = settingsService.GetSetting<WindowSize?>("WindowSize");
SidebarViewModel = sidebarViewModel;
@ -61,7 +62,7 @@ public class RootViewModel : RoutableScreen<IMainScreenViewModel>, IMainWindowPr
OpenDebugger = ReactiveCommand.CreateFromTask(ExecuteOpenDebugger);
Exit = ReactiveCommand.CreateFromTask(ExecuteExit);
this.WhenAnyValue(vm => vm.Screen).Subscribe(UpdateTitleBarViewModel);
Task.Run(() =>
{
if (_updateService.Initialize())
@ -85,6 +86,8 @@ public class RootViewModel : RoutableScreen<IMainScreenViewModel>, IMainWindowPr
set => RaiseAndSetIfChanged(ref _titleBarViewModel, value);
}
public static PluginSetting<WindowSize?>? WindowSizeSetting { get; private set; }
public void GoBack()
{
_router.GoBack();
@ -95,8 +98,6 @@ public class RootViewModel : RoutableScreen<IMainScreenViewModel>, IMainWindowPr
_router.GoForward();
}
public static PluginSetting<WindowSize?>? WindowSizeSetting { get; private set; }
private void UpdateTitleBarViewModel(IMainScreenViewModel? viewModel)
{
if (viewModel?.TitleBarViewModel != null)

View File

@ -44,6 +44,19 @@
</StackPanel>
</Grid>
<Border Classes="card-separator" />
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
<StackPanel Grid.Column="0">
<TextBlock>Enable Mica effect</TextBlock>
<TextBlock Classes="subtitle" TextWrapping="Wrap">
The Mica effect is the semi-transparent effect used by the application window, the colors are based on your wallpaper.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ToggleSwitch IsChecked="{CompiledBinding EnableMica.Value}" OnContent="Yes" OffContent="No" MinWidth="0" Margin="0 -10" />
</StackPanel>
</Grid>
<Border Classes="card-separator" />
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
<StackPanel Grid.Column="0">

View File

@ -30,9 +30,9 @@ public class GeneralTabViewModel : ActivatableViewModelBase
private readonly IAutoRunProvider? _autoRunProvider;
private readonly IDebugService _debugService;
private readonly PluginSetting<LayerBrushReference> _defaultLayerBrushDescriptor;
private readonly INotificationService _notificationService;
private readonly ISettingsService _settingsService;
private readonly IUpdateService _updateService;
private readonly INotificationService _notificationService;
private readonly IWindowService _windowService;
private bool _startupWizardOpen;
@ -74,12 +74,14 @@ public class GeneralTabViewModel : ActivatableViewModelBase
{
UIAutoRun.SettingChanged += UIAutoRunOnSettingChanged;
UIAutoRunDelay.SettingChanged += UIAutoRunDelayOnSettingChanged;
EnableMica.SettingChanged += EnableMicaOnSettingChanged;
Dispatcher.UIThread.InvokeAsync(ApplyAutoRun);
Disposable.Create(() =>
{
UIAutoRun.SettingChanged -= UIAutoRunOnSettingChanged;
UIAutoRunDelay.SettingChanged -= UIAutoRunDelayOnSettingChanged;
EnableMica.SettingChanged -= EnableMicaOnSettingChanged;
_settingsService.SaveAllSettings();
}).DisposeWith(d);
@ -146,6 +148,7 @@ public class GeneralTabViewModel : ActivatableViewModelBase
public PluginSetting<bool> UIAutoRun => _settingsService.GetSetting("UI.AutoRun", false);
public PluginSetting<int> UIAutoRunDelay => _settingsService.GetSetting("UI.AutoRunDelay", 15);
public PluginSetting<bool> UIShowOnStartup => _settingsService.GetSetting("UI.ShowOnStartup", true);
public PluginSetting<bool> EnableMica => _settingsService.GetSetting("UI.EnableMica", true);
public PluginSetting<bool> UICheckForUpdates => _settingsService.GetSetting("UI.Updating.AutoCheck", true);
public PluginSetting<bool> UIAutoUpdate => _settingsService.GetSetting("UI.Updating.AutoInstall", true);
public PluginSetting<bool> ProfileEditorShowDataModelValues => _settingsService.GetSetting("ProfileEditor.ShowDataModelValues", false);
@ -238,4 +241,9 @@ public class GeneralTabViewModel : ActivatableViewModelBase
_windowService.ShowExceptionDialog("Failed to apply auto-run", exception);
}
}
private void EnableMicaOnSettingChanged(object? sender, EventArgs e)
{
Shared.UI.SetMicaEnabled(EnableMica.Value);
}
}

View File

@ -9,9 +9,9 @@
x:Class="Artemis.UI.Screens.Workshop.CurrentUser.CurrentUserView"
x:DataType="currentUser:CurrentUserViewModel">
<Panel IsVisible="{CompiledBinding !Loading}">
<Panel Name="Container" IsVisible="{CompiledBinding !Loading}">
<!-- Signed out -->
<Ellipse Height="28" Width="28" IsVisible="{CompiledBinding Name, Converter={x:Static StringConverters.IsNullOrEmpty}}">
<Ellipse Height="{CompiledBinding Bounds.Height, ElementName=Container}" Width="{CompiledBinding Bounds.Height, ElementName=Container}" IsVisible="{CompiledBinding Name, Converter={x:Static StringConverters.IsNullOrEmpty}}">
<Ellipse.ContextFlyout>
<MenuFlyout>
<MenuItem Header="Login" Command="{CompiledBinding Login}">
@ -27,7 +27,7 @@
</Ellipse>
<!-- Signed in -->
<Ellipse Height="28" Width="28" IsVisible="{CompiledBinding Name, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" Name="UserMenu">
<Ellipse Height="{CompiledBinding Bounds.Height, ElementName=Container}" Width="{CompiledBinding Bounds.Height, ElementName=Container}" IsVisible="{CompiledBinding Name, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" Name="UserMenu">
<Ellipse.ContextFlyout>
<Flyout>
<Grid ColumnDefinitions="Auto,*" RowDefinitions="*,*,*" MinWidth="300">

View File

@ -4,8 +4,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:home="clr-namespace:Artemis.UI.Screens.Workshop.Home"
xmlns:controls="clr-namespace:Artemis.UI.Controls"
xmlns:acrylicBlur="clr-namespace:Artemis.UI.Controls.AcrylicBlur"
mc:Ignorable="d" d:DesignWidth="1200" d:DesignHeight="800"
x:Class="Artemis.UI.Screens.Workshop.Home.WorkshopHomeView"
x:DataType="home:WorkshopHomeViewModel">
@ -39,43 +37,42 @@
</TextBlock.Effect>
</TextBlock>
<StackPanel Grid.Row="1" Margin="30 -75 30 0" Spacing="10" Orientation="Horizontal" VerticalAlignment="Top">
<Border CornerRadius="{DynamicResource ControlCornerRadius}" ClipToBounds="True">
<acrylicBlur:AcrylicBlur Blur="17">
<Button Width="150" Height="180" Command="{CompiledBinding Navigate}" CommandParameter="workshop/profiles/1" VerticalContentAlignment="Top">
<StackPanel>
<avalonia:MaterialIcon Kind="FolderVideo" HorizontalAlignment="Left" Width="60" Height="60" Margin="0 5" />
<TextBlock TextWrapping="Wrap" FontSize="16" Margin="0 5">Profiles</TextBlock>
<TextBlock TextWrapping="Wrap" FontSize="12" Opacity="0.8">Browse new profiles created by other users.</TextBlock>
</StackPanel>
</Button>
</acrylicBlur:AcrylicBlur>
</Border>
<StackPanel Margin="30 -75 30 0" Grid.Row="1">
<StackPanel Spacing="10" Orientation="Horizontal" VerticalAlignment="Top">
<Button Width="150" Height="180" Command="{CompiledBinding AddSubmission}" VerticalContentAlignment="Top">
<StackPanel>
<avalonia:MaterialIcon Kind="CloudUpload" HorizontalAlignment="Left" Width="60" Height="60" Margin="0 5" />
<TextBlock TextWrapping="Wrap" FontSize="16" Margin="0 5">Add submission</TextBlock>
<TextBlock TextWrapping="Wrap" FontSize="12" Opacity="0.8">Upload your own creations to the workshop!</TextBlock>
</StackPanel>
</Button>
<Button Width="150" Height="180" Command="{CompiledBinding Navigate}" CommandParameter="workshop/profiles/1" VerticalContentAlignment="Top">
<StackPanel>
<avalonia:MaterialIcon Kind="FolderVideo" HorizontalAlignment="Left" Width="60" Height="60" Margin="0 5" />
<TextBlock TextWrapping="Wrap" FontSize="16" Margin="0 5">Profiles</TextBlock>
<TextBlock TextWrapping="Wrap" FontSize="12" Opacity="0.8">Browse new profiles created by other users.</TextBlock>
</StackPanel>
</Button>
<Border CornerRadius="{DynamicResource ControlCornerRadius}" ClipToBounds="True">
<acrylicBlur:AcrylicBlur Blur="17">
<Button Width="150" Height="180" Command="{CompiledBinding Navigate}" CommandParameter="workshop/layouts/1" VerticalContentAlignment="Top">
<StackPanel>
<avalonia:MaterialIcon Kind="KeyboardVariant" HorizontalAlignment="Left" Width="60" Height="60" Margin="0 5" />
<TextBlock TextWrapping="Wrap" FontSize="16" Margin="0 5">Layouts</TextBlock>
<TextBlock TextWrapping="Wrap" FontSize="12" Opacity="0.8">Layouts make your devices look great in the editor.</TextBlock>
</StackPanel>
</Button>
</acrylicBlur:AcrylicBlur>
</Border>
<Button Width="150" Height="180" Command="{CompiledBinding Navigate}" CommandParameter="workshop/layouts/1" VerticalContentAlignment="Top">
<StackPanel>
<avalonia:MaterialIcon Kind="KeyboardVariant" HorizontalAlignment="Left" Width="60" Height="60" Margin="0 5" />
<TextBlock TextWrapping="Wrap" FontSize="16" Margin="0 5">Layouts</TextBlock>
<TextBlock TextWrapping="Wrap" FontSize="12" Opacity="0.8">Layouts make your devices look great in the editor.</TextBlock>
</StackPanel>
</Button>
</StackPanel>
<TextBlock Classes="h4" Margin="0 15 0 5">Featured submissions</TextBlock>
<TextBlock>Not yet implemented, here we'll show submissions we think are worth some extra attention.</TextBlock>
<TextBlock Classes="h4" Margin="0 15 0 5">Recently updated</TextBlock>
<TextBlock>Not yet implemented, here we'll a few of the most recent uploads/updates to the workshop.</TextBlock>
</StackPanel>
<Grid Grid.Row="1" Width="320" Height="200">
<Grid>
<Rectangle Fill="Aqua" Height="200" Width="100" HorizontalAlignment="Left" VerticalAlignment="Top" />
<Ellipse Fill="Magenta" Height="152" Width="152" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Rectangle Fill="Yellow" Height="100" Width="80" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
</Grid>
<acrylicBlur:AcrylicBlur Margin="12" Blur="17">
<TextBlock>Test</TextBlock>
</acrylicBlur:AcrylicBlur>
</Grid>
</Grid>
</Border>
</UserControl>

View File

@ -1,6 +1,10 @@
using System.Reactive;
using System.Threading;
using System.Threading.Tasks;
using Artemis.UI.Screens.Workshop.SubmissionWizard;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Routing;
using Artemis.UI.Shared.Services;
using Artemis.WebClient.Workshop;
using ReactiveUI;
@ -8,13 +12,22 @@ namespace Artemis.UI.Screens.Workshop.Home;
public class WorkshopHomeViewModel : ActivatableViewModelBase, IWorkshopViewModel
{
public WorkshopHomeViewModel(IRouter router)
private readonly IWindowService _windowService;
public WorkshopHomeViewModel(IRouter router, IWindowService windowService)
{
_windowService = windowService;
AddSubmission = ReactiveCommand.CreateFromTask(ExecuteAddSubmission);
Navigate = ReactiveCommand.CreateFromTask<string>(async r => await router.Navigate(r));
}
public ReactiveCommand<string, Unit> Navigate { get; set; }
public ReactiveCommand<Unit, Unit> AddSubmission { get; }
public ReactiveCommand<string, Unit> Navigate { get; }
private async Task ExecuteAddSubmission(CancellationToken arg)
{
await _windowService.ShowDialogAsync<SubmissionWizardViewModel>();
}
public EntryType? EntryType => null;
}

View File

@ -48,6 +48,8 @@
</AutoCompleteBox.ItemTemplate>
</AutoCompleteBox>
<ContentControl HorizontalAlignment="Right"
Width="28"
Height="28"
Margin="0 0 50 0"
Content="{CompiledBinding CurrentUserViewModel}"
windowing:AppWindow.AllowInteractionInTitleBar="True"/>

View File

@ -0,0 +1,11 @@
<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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Workshop.SubmissionWizard.Steps.WelcomeStepView">
<StackPanel>
<TextBlock>Welcome to the Workshop Submission Wizard 🧙</TextBlock>
<TextBlock>Here we'll take you, step by step, through the process of uploading your submission to the workshop.</TextBlock>
</StackPanel>
</UserControl>

View File

@ -0,0 +1,17 @@
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
public partial class WelcomeStepView : ReactiveUserControl<WelcomeStepViewModel>
{
public WelcomeStepView()
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}

View File

@ -0,0 +1,22 @@
using System.Reactive;
using ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
public class WelcomeStepViewModel : SubmissionViewModel
{
#region Overrides of SubmissionViewModel
/// <inheritdoc />
public override ReactiveCommand<Unit, Unit> Continue { get; }
/// <inheritdoc />
public override ReactiveCommand<Unit, Unit> GoBack { get; } = null!;
public WelcomeStepViewModel()
{
ShowGoBack = false;
}
#endregion
}

View File

@ -0,0 +1,56 @@
<Window 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:submissionWizard="clr-namespace:Artemis.UI.Screens.Workshop.SubmissionWizard"
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:ui="clr-namespace:Artemis.UI"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Workshop.SubmissionWizard.SubmissionWizardView"
x:DataType="submissionWizard:SubmissionWizardViewModel"
Icon="/Assets/Images/Logo/application.ico"
Title="Artemis | Workshop submission wizard"
Width="1000"
Height="735"
WindowStartupLocation="CenterOwner">
<Grid Margin="15" RowDefinitions="Auto,*,Auto">
<Grid RowDefinitions="*,*" ColumnDefinitions="Auto,*,Auto" Margin="0 0 0 15">
<ContentControl Grid.Column="0" Grid.RowSpan="2" Width="65" Height="65" VerticalAlignment="Center" Margin="0 0 20 0" Content="{CompiledBinding CurrentUserViewModel}"/>
<TextBlock Grid.Row="0" Grid.Column="1" FontSize="36" VerticalAlignment="Bottom" Text="{CompiledBinding CurrentUserViewModel.Name, FallbackValue=Not logged in}"/>
<StackPanel Grid.Row="0" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Bottom" Orientation="Horizontal">
<controls:HyperlinkButton Classes="icon-button" ToolTip.Tip="View Wiki" NavigateUri="https://wiki.artemis-rgb.com?mtm_campaign=artemis&amp;mtm_kwd=workshop-wizard">
<avalonia:MaterialIcon Kind="BookOpenOutline" />
</controls:HyperlinkButton>
</StackPanel>
<TextBlock Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Top"
Classes="subtitle"
Text="New workshop submission" />
</Grid>
<Border Classes="card" Grid.Row="1" Grid.Column="0">
<controls:Frame Name="Frame" IsNavigationStackEnabled="False" CacheSize="0">
<controls:Frame.NavigationPageFactory>
<ui:PageFactory/>
</controls:Frame.NavigationPageFactory>
</controls:Frame>
</Border>
<StackPanel Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Orientation="Horizontal" Spacing="5" Margin="0 15 0 0">
<Button Command="{CompiledBinding Screen.GoBack}" IsVisible="{CompiledBinding Screen.ShowGoBack}">
Back
</Button>
<Button Command="{CompiledBinding Screen.Continue}" IsVisible="{CompiledBinding !Screen.ShowFinish}" Width="80">
Continue
</Button>
<Button Command="{CompiledBinding Screen.Continue}" IsVisible="{CompiledBinding Screen.ShowFinish}" Width="80">
Finish
</Button>
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,33 @@
using System;
using System.Reactive.Disposables;
using Artemis.UI.Shared;
using Avalonia;
using Avalonia.Threading;
using ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard;
public partial class SubmissionWizardView : ReactiveAppWindow<SubmissionWizardViewModel>
{
public SubmissionWizardView()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
this.WhenActivated(d => ViewModel.WhenAnyValue(vm => vm.Screen).Subscribe(Navigate).DisposeWith(d));
}
private void Navigate(SubmissionViewModel viewModel)
{
try
{
Dispatcher.UIThread.Invoke(() => Frame.NavigateFromObject(viewModel));
}
catch (Exception)
{
// ignored
}
}
}

View File

@ -0,0 +1,47 @@
using System.Reactive;
using Artemis.UI.Screens.Workshop.CurrentUser;
using Artemis.UI.Screens.Workshop.SubmissionWizard.Steps;
using Artemis.UI.Shared;
using ReactiveUI;
namespace Artemis.UI.Screens.Workshop.SubmissionWizard;
public class SubmissionWizardViewModel : DialogViewModelBase<bool>
{
private SubmissionViewModel _screen;
public SubmissionWizardViewModel(CurrentUserViewModel currentUserViewModel)
{
_screen = new WelcomeStepViewModel();
CurrentUserViewModel = currentUserViewModel;
}
public CurrentUserViewModel CurrentUserViewModel { get; }
public SubmissionViewModel Screen
{
get => _screen;
set => RaiseAndSetIfChanged(ref _screen, value);
}
}
public abstract class SubmissionViewModel : ActivatableViewModelBase
{
private bool _showFinish;
private bool _showGoBack = true;
public abstract ReactiveCommand<Unit, Unit> Continue { get; }
public abstract ReactiveCommand<Unit, Unit> GoBack { get; }
public bool ShowGoBack
{
get => _showGoBack;
set => RaiseAndSetIfChanged(ref _showGoBack, value);
}
public bool ShowFinish
{
get => _showFinish;
set => RaiseAndSetIfChanged(ref _showFinish, value);
}
}

View File

@ -13,7 +13,6 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<MergeResourceInclude Source="TreeView.axaml"></MergeResourceInclude>
<MergeResourceInclude Source="/Controls/AcrylicBlur/AcrylicBlur.axaml"></MergeResourceInclude>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Styles.Resources>

View File

@ -1,6 +1,6 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AvaloniaVersion>11.0.0</AvaloniaVersion>
<AvaloniaVersion>11.0.1</AvaloniaVersion>
<FluentAvaloniaVersion>2.0.0</FluentAvaloniaVersion>
<RGBDotNetVersion>2.0.0-prerelease.83</RGBDotNetVersion>
<SkiaSharpVersion>2.88.3</SkiaSharpVersion>