mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Initial setup of the models and view models
This commit is contained in:
1 parent
46511022d6
commit
3004293051
38 files changed
+807
-61
No files matched your search
@@ -0,0 +1,71 @@
|
||||
<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:preview="clr-namespace:Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Preview"
|
||||
xmlns:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:vis="clr-namespace:Artemis.UI.Screens.ProfileEditor.VisualEditor.Visualizers"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Preview.PreviewView"
|
||||
x:DataType="preview:PreviewViewModel">
|
||||
<UserControl.Resources>
|
||||
<VisualBrush x:Key="LargeCheckerboardBrush" TileMode="Tile" Stretch="Uniform" SourceRect="0,0,20,20">
|
||||
<VisualBrush.Visual>
|
||||
<Canvas Width="20" Height="20">
|
||||
<Rectangle Width="10" Height="10" Fill="Black" Opacity="0.15" />
|
||||
<Rectangle Width="10" Height="10" Canvas.Left="10" />
|
||||
<Rectangle Width="10" Height="10" Canvas.Top="10" />
|
||||
<Rectangle Width="10" Height="10" Canvas.Left="10" Canvas.Top="10" Fill="Black" Opacity="0.15" />
|
||||
</Canvas>
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
</UserControl.Resources>
|
||||
<ZoomBorder Name="ZoomBorder"
|
||||
Stretch="None"
|
||||
ClipToBounds="True"
|
||||
Focusable="True"
|
||||
VerticalAlignment="Stretch"
|
||||
HorizontalAlignment="Stretch"
|
||||
Background="{StaticResource LargeCheckerboardBrush}"
|
||||
ZoomChanged="ZoomBorder_OnZoomChanged">
|
||||
<Grid Name="ContainerGrid" Background="Transparent">
|
||||
<Grid.Transitions>
|
||||
<Transitions>
|
||||
<TransformOperationsTransition Property="RenderTransform" Duration="0:0:0.2" Easing="CubicEaseOut" />
|
||||
</Transitions>
|
||||
</Grid.Transitions>
|
||||
|
||||
<!-- The bottom layer consists of devices -->
|
||||
<ItemsControl Name="DevicesContainer" ItemsSource="{CompiledBinding Devices}" ClipToBounds="False">
|
||||
<ItemsControl.Styles>
|
||||
<Style Selector="ContentPresenter" x:DataType="core:ArtemisDevice">
|
||||
<Setter Property="Canvas.Left" Value="{CompiledBinding X}" />
|
||||
<Setter Property="Canvas.Top" Value="{CompiledBinding Y}" />
|
||||
</Style>
|
||||
</ItemsControl.Styles>
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="core:ArtemisDevice">
|
||||
<shared:DeviceVisualizer Device="{CompiledBinding}" ShowColors="True" RenderOptions.BitmapInterpolationMode="MediumQuality" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<Border CornerRadius="0 0 8 0"
|
||||
VerticalAlignment="Top"
|
||||
HorizontalAlignment="Left"
|
||||
Background="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
IsVisible="{CompiledBinding ProfileConfiguration, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
<StackPanel Orientation="Horizontal" Margin="8">
|
||||
<shared:ProfileConfigurationIcon ConfigurationIcon="{CompiledBinding ProfileConfiguration.Icon}" Width="18" Height="18" CornerRadius="3" Margin="0 0 5 0" />
|
||||
<TextBlock Text="{CompiledBinding ProfileConfiguration.Name}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ZoomBorder>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Disposables.Fluent;
|
||||
using System.Reactive.Linq;
|
||||
using Artemis.UI.Screens.ProfileEditor.VisualEditor;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.PanAndZoom;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Avalonia;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Preview;
|
||||
|
||||
public partial class PreviewView : ReactiveUserControl<PreviewViewModel>
|
||||
{
|
||||
private bool _movedByUser;
|
||||
|
||||
public PreviewView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
ZoomBorder.PropertyChanged += ZoomBorderOnPropertyChanged;
|
||||
ZoomBorder.PointerMoved += ZoomBorderOnPointerMoved;
|
||||
ZoomBorder.PointerWheelChanged += ZoomBorderOnPointerWheelChanged;
|
||||
UpdateZoomBorderBackground();
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
PreviewViewModel vm = ViewModel!;
|
||||
vm.AutoFitRequested += ViewModelOnAutoFitRequested;
|
||||
Disposable.Create(() => vm.AutoFitRequested -= ViewModelOnAutoFitRequested).DisposeWith(d);
|
||||
});
|
||||
|
||||
this.WhenAnyValue(v => v.Bounds).Where(_ => !_movedByUser).Subscribe(_ => AutoFit(true));
|
||||
}
|
||||
|
||||
private void ZoomBorderOnPointerWheelChanged(object? sender, PointerWheelEventArgs e)
|
||||
{
|
||||
_movedByUser = true;
|
||||
}
|
||||
|
||||
private void ZoomBorderOnPointerMoved(object? sender, PointerEventArgs e)
|
||||
{
|
||||
if (e.GetCurrentPoint(ZoomBorder).Properties.IsMiddleButtonPressed)
|
||||
_movedByUser = true;
|
||||
}
|
||||
|
||||
private void ViewModelOnAutoFitRequested(object? sender, EventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() => AutoFit(false));
|
||||
}
|
||||
|
||||
private void ZoomBorderOnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property.Name == nameof(ZoomBorder.Background))
|
||||
UpdateZoomBorderBackground();
|
||||
}
|
||||
|
||||
private void UpdateZoomBorderBackground()
|
||||
{
|
||||
if (ZoomBorder.Background is VisualBrush visualBrush)
|
||||
visualBrush.DestinationRect = new RelativeRect(ZoomBorder.OffsetX, ZoomBorder.OffsetY, 20, 20, RelativeUnit.Absolute);
|
||||
}
|
||||
|
||||
|
||||
private void ZoomBorder_OnZoomChanged(object sender, ZoomChangedEventArgs e)
|
||||
{
|
||||
UpdateZoomBorderBackground();
|
||||
}
|
||||
|
||||
private void AutoFit(bool skipTransitions)
|
||||
{
|
||||
if (ViewModel == null || !ViewModel.Devices.Any())
|
||||
return;
|
||||
|
||||
double left = ViewModel.Devices.Select(d => d.Rectangle.Left).Min();
|
||||
double top = ViewModel.Devices.Select(d => d.Rectangle.Top).Min();
|
||||
double bottom = ViewModel.Devices.Select(d => d.Rectangle.Bottom).Max();
|
||||
double right = ViewModel.Devices.Select(d => d.Rectangle.Right).Max();
|
||||
|
||||
// Add a 10 pixel margin around the rect
|
||||
Rect scriptRect = new(new Point(left - 10, top - 10), new Point(right + 10, bottom + 10));
|
||||
|
||||
// The scale depends on the available space
|
||||
double scale = Math.Min(3, Math.Min(Bounds.Width / scriptRect.Width, Bounds.Height / scriptRect.Height));
|
||||
|
||||
// Pan and zoom to make the script fit
|
||||
ZoomBorder.Zoom(scale, 0, 0, skipTransitions);
|
||||
ZoomBorder.Pan(Bounds.Center.X - scriptRect.Center.X * scale, Bounds.Center.Y - scriptRect.Center.Y * scale, skipTransitions);
|
||||
|
||||
_movedByUser = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables.Fluent;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Preview;
|
||||
|
||||
public class PreviewViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private ObservableAsPropertyHelper<ProfileConfiguration?>? _profileConfiguration;
|
||||
|
||||
public PreviewViewModel(IProfileEditorService profileEditorService, IDeviceService deviceService)
|
||||
{
|
||||
Devices = new ObservableCollection<ArtemisDevice>(deviceService.EnabledDevices.OrderBy(d => d.ZIndex));
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
_profileConfiguration = profileEditorService.ProfileConfiguration.ToProperty(this, vm => vm.ProfileConfiguration).DisposeWith(d);
|
||||
});
|
||||
}
|
||||
|
||||
public ProfileConfiguration? ProfileConfiguration => _profileConfiguration?.Value;
|
||||
public ObservableCollection<ArtemisDevice> Devices { get; }
|
||||
|
||||
public void RequestAutoFit()
|
||||
{
|
||||
AutoFitRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public event EventHandler? AutoFitRequested;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<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:section="clr-namespace:Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Section"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Section.ConfigurationSectionView"
|
||||
x:DataType="section:ConfigurationSectionViewModel">
|
||||
<Border Classes="card" VerticalAlignment="Top">
|
||||
<StackPanel>
|
||||
<TextBlock Theme="{StaticResource SubtitleTextBlockStyle}" Text="{CompiledBinding ConfigurationSection.Name}"/>
|
||||
<Border Classes="card-separator" />
|
||||
<ScrollViewer>
|
||||
<TextBlock>Test</TextBlock>
|
||||
</ScrollViewer>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</UserControl>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using ReactiveUI.Avalonia;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Section;
|
||||
|
||||
public partial class ConfigurationSectionView: ReactiveUserControl<ConfigurationSectionViewModel>
|
||||
{
|
||||
public ConfigurationSectionView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Section;
|
||||
|
||||
public class ConfigurationSectionViewModel : ActivatableViewModelBase
|
||||
{
|
||||
public ConfigurationSection ConfigurationSection { get; }
|
||||
|
||||
public ConfigurationSectionViewModel(ConfigurationSection configurationSection)
|
||||
{
|
||||
ConfigurationSection = configurationSection;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<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:slot="clr-namespace:Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Slot"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Slot.SlotView"
|
||||
x:DataType="slot:SlotViewModel">
|
||||
Welcome to Avalonia!
|
||||
</UserControl>
|
||||
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Slot;
|
||||
|
||||
public partial class SlotView : UserControl
|
||||
{
|
||||
public SlotView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Artemis.UI.Shared;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Slot;
|
||||
|
||||
public class SlotViewModel : ActivatableViewModelBase
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<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:profileEditor="clr-namespace:Artemis.UI.Screens.ProfileEditor"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.ProfileEditor.ConfigureProfileView"
|
||||
x:DataType="profileEditor:ConfigureProfileViewModel">
|
||||
<Border Classes="router-container" Padding="8">
|
||||
<Grid RowDefinitions="0.6*, 0.6*" ColumnDefinitions="0.3*, 0.3*, 0.4*" ColumnSpacing="8" RowSpacing="8">
|
||||
<ContentControl Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Content="{CompiledBinding PreviewViewModel}" />
|
||||
|
||||
<ItemsControl Grid.Column="0" Grid.Row="1" ItemsSource="{CompiledBinding BottomLeftSections}"/>
|
||||
<ItemsControl Grid.Column="1" Grid.Row="1" ItemsSource="{CompiledBinding BottomRightSections}"/>
|
||||
<ItemsControl Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" ItemsSource="{CompiledBinding SideSections}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,11 @@
|
||||
using ReactiveUI.Avalonia;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor;
|
||||
|
||||
public partial class ConfigureProfileView : ReactiveUserControl<ConfigureProfileViewModel>
|
||||
{
|
||||
public ConfigureProfileView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Preview;
|
||||
using Artemis.UI.Screens.ProfileEditor.ConfigurationPanels.Section;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using DynamicData;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor;
|
||||
|
||||
public partial class ConfigureProfileViewModel : RoutableScreen<ProfileViewModelParameters>
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly SourceList<ConfigurationSection> _configurationSections;
|
||||
|
||||
[Notify] private ProfileConfiguration? _profileConfiguration;
|
||||
|
||||
public ConfigureProfileViewModel(IProfileService profileService, IProfileEditorService profileEditorService, PreviewViewModel previewViewModel,
|
||||
Func<ConfigurationSection, ConfigurationSectionViewModel> getConfigurationSectionViewModel)
|
||||
{
|
||||
_profileService = profileService;
|
||||
_profileEditorService = profileEditorService;
|
||||
ParameterSource = ParameterSource.Route;
|
||||
|
||||
PreviewViewModel = previewViewModel;
|
||||
|
||||
_configurationSections = new SourceList<ConfigurationSection>();
|
||||
_configurationSections.Connect()
|
||||
.Filter(s => s.Slot == 0)
|
||||
.Transform(getConfigurationSectionViewModel)
|
||||
.Bind(out ReadOnlyObservableCollection<ConfigurationSectionViewModel> bottomLeftSections)
|
||||
.Subscribe();
|
||||
_configurationSections.Connect()
|
||||
.Filter(s => s.Slot == 1)
|
||||
.Transform(getConfigurationSectionViewModel)
|
||||
.Bind(out ReadOnlyObservableCollection<ConfigurationSectionViewModel> bottomRightSections)
|
||||
.Subscribe();
|
||||
_configurationSections.Connect()
|
||||
.Filter(s => s.Slot == 2)
|
||||
.Transform(getConfigurationSectionViewModel)
|
||||
.Bind(out ReadOnlyObservableCollection<ConfigurationSectionViewModel> sideSections)
|
||||
.Subscribe();
|
||||
|
||||
BottomLeftSections = bottomLeftSections;
|
||||
BottomRightSections = bottomRightSections;
|
||||
SideSections = sideSections;
|
||||
}
|
||||
|
||||
public PreviewViewModel PreviewViewModel { get; }
|
||||
public ReadOnlyObservableCollection<ConfigurationSectionViewModel> BottomLeftSections { get; private set; }
|
||||
public ReadOnlyObservableCollection<ConfigurationSectionViewModel> BottomRightSections { get; private set; }
|
||||
public ReadOnlyObservableCollection<ConfigurationSectionViewModel> SideSections { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task OnNavigating(ProfileViewModelParameters parameters, NavigationArguments args, CancellationToken cancellationToken)
|
||||
{
|
||||
ProfileConfiguration? profileConfiguration = _profileService.ProfileCategories.SelectMany(c => c.ProfileConfigurations).FirstOrDefault(c => c.ProfileId == parameters.ProfileId);
|
||||
|
||||
// If the profile doesn't exist, cancel navigation
|
||||
if (profileConfiguration == null)
|
||||
{
|
||||
args.Cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
await _profileEditorService.ChangeCurrentProfileConfiguration(profileConfiguration);
|
||||
ProfileConfiguration = profileConfiguration;
|
||||
_configurationSections.Edit(editableSections =>
|
||||
{
|
||||
editableSections.Clear();
|
||||
editableSections.AddRange(profileConfiguration.ConfigurationSections);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task OnClosing(NavigationArguments args)
|
||||
{
|
||||
if (!args.Path.StartsWith("profile"))
|
||||
{
|
||||
ProfileConfiguration = null;
|
||||
await _profileEditorService.ChangeCurrentProfileConfiguration(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<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:profileEditor="clr-namespace:Artemis.UI.Screens.ProfileEditor"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.ProfileEditor.DesignProfileView"
|
||||
x:DataType="profileEditor:DesignProfileViewModel">
|
||||
<Border Classes="router-container">
|
||||
|
||||
<TextBlock>Design</TextBlock>
|
||||
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,11 @@
|
||||
using ReactiveUI.Avalonia;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor;
|
||||
|
||||
public partial class DesignProfileView : ReactiveUserControl<DesignProfileViewModel>
|
||||
{
|
||||
public DesignProfileView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Screens.Workshop.Library.Tabs;
|
||||
using Artemis.UI.Shared.Routing;
|
||||
using Artemis.WebClient.Workshop.Models;
|
||||
using Artemis.WebClient.Workshop.Services;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor;
|
||||
|
||||
public partial class DesignProfileViewModel : RoutableScreen<ProfileViewModelParameters>
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IWorkshopService _workshopService;
|
||||
private readonly IRouter _router;
|
||||
private readonly Func<InstalledEntry, InstalledTabItemViewModel> _getInstalledTabItemViewModel;
|
||||
|
||||
[Notify] private ProfileConfiguration? _profileConfiguration;
|
||||
[Notify] private InstalledEntry? _workshopEntry;
|
||||
[Notify] private InstalledTabItemViewModel? _entryViewModel;
|
||||
|
||||
public DesignProfileViewModel(IProfileService profileService, IWorkshopService workshopService, IRouter router, Func<InstalledEntry, InstalledTabItemViewModel> getInstalledTabItemViewModel)
|
||||
{
|
||||
_profileService = profileService;
|
||||
_workshopService = workshopService;
|
||||
_router = router;
|
||||
_getInstalledTabItemViewModel = getInstalledTabItemViewModel;
|
||||
ParameterSource = ParameterSource.Route;
|
||||
}
|
||||
|
||||
public async Task DisableAutoUpdate()
|
||||
{
|
||||
if (WorkshopEntry != null)
|
||||
{
|
||||
_workshopService.SetAutoUpdate(WorkshopEntry, false);
|
||||
}
|
||||
|
||||
if (ProfileConfiguration != null)
|
||||
{
|
||||
await _router.Navigate($"profile/{ProfileConfiguration.ProfileId}/editor");
|
||||
}
|
||||
}
|
||||
|
||||
public override Task OnNavigating(ProfileViewModelParameters parameters, NavigationArguments args, CancellationToken cancellationToken)
|
||||
{
|
||||
ProfileConfiguration = _profileService.ProfileCategories.SelectMany(c => c.ProfileConfigurations).FirstOrDefault(c => c.ProfileId == parameters.ProfileId);
|
||||
|
||||
// If the profile doesn't exist, cancel navigation
|
||||
if (ProfileConfiguration == null)
|
||||
{
|
||||
args.Cancel();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
WorkshopEntry = _workshopService.GetInstalledEntryByProfile(ProfileConfiguration);
|
||||
EntryViewModel = WorkshopEntry != null ? _getInstalledTabItemViewModel(WorkshopEntry) : null;
|
||||
if (EntryViewModel != null)
|
||||
EntryViewModel.DisplayManagement = false;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public partial class VisualEditorView : ReactiveUserControl<VisualEditorViewMode
|
||||
private void UpdateZoomBorderBackground()
|
||||
{
|
||||
if (ZoomBorder.Background is VisualBrush visualBrush)
|
||||
visualBrush.DestinationRect = new RelativeRect(ZoomBorder.OffsetX * -1, ZoomBorder.OffsetY * -1, 20, 20, RelativeUnit.Absolute);
|
||||
visualBrush.DestinationRect = new RelativeRect(ZoomBorder.OffsetX, ZoomBorder.OffsetY, 20, 20, RelativeUnit.Absolute);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -42,17 +42,25 @@ public class ProfileViewModel : RoutableHostScreen<RoutableScreen, ProfileViewMo
|
||||
args.Cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
// Redirect to the correct sub-page if no sub-page is specified
|
||||
if (args.PathSegments.Length >= 3)
|
||||
return;
|
||||
|
||||
// If the profile is from the workshop, redirect to the workshop page
|
||||
InstalledEntry? workshopEntry = _workshopService.GetInstalledEntryByProfile(profileConfiguration);
|
||||
if (workshopEntry != null && workshopEntry.AutoUpdate)
|
||||
// If the profile is configurable, go to the configuration page
|
||||
if (profileConfiguration.IsConfigurable)
|
||||
{
|
||||
if (!args.Path.EndsWith("workshop"))
|
||||
await args.Router.Navigate($"profile/{parameters.ProfileId}/configure");
|
||||
}
|
||||
// Otherwise either the workshop notice or the editor
|
||||
else
|
||||
{
|
||||
InstalledEntry? workshopEntry = _workshopService.GetInstalledEntryByProfile(profileConfiguration);
|
||||
if (workshopEntry != null && workshopEntry.AutoUpdate)
|
||||
await args.Router.Navigate($"profile/{parameters.ProfileId}/workshop");
|
||||
else
|
||||
await args.Router.Navigate($"profile/{parameters.ProfileId}/editor");
|
||||
}
|
||||
// Otherwise, show the profile editor if not already on the editor page
|
||||
else if (!args.Path.EndsWith("editor"))
|
||||
await args.Router.Navigate($"profile/{parameters.ProfileId}/editor");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user