XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

SpaceEngineersModDev/SpaceEngineersBlueprintEditorInWinUI

更换导航服务为自动导航

0e35d2f
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

23 个文件 +227 -72
Modified SpaceEngineersBlueprintEditor/App.xaml.cs +1 -0
@@ -17,6 +17,7 @@ public partial class App : Application
17 17 PageManager.RegisterPage(typeof(MainPage));
18 18 PageManager.RegisterPage(typeof(BlueprintEditPage));
19 19 PageManager.RegisterPage(typeof(BlueprintsViewPage));
20 PageManager.RegisterPage(typeof(BlueprintDetailPage));
20 21 PageManager.RegisterPage(typeof(SettingPage));
21 22 Task.Run(BlueprintsManager.LoadBlueprintsAsync);
22 23 UnhandledException += App_UnhandledException;
Added SpaceEngineersBlueprintEditor/Implements/Services/AutoNavigationService.cs +47 -0
@@ -0,0 +1,47 @@
1 using Microsoft.UI.Xaml.Media.Animation;
2 using Microsoft.UI.Xaml.Navigation;
3 using SpaceEngineersBlueprintEditor.Interface.Services;
4 using SpaceEngineersBlueprintEditor.Utilities;
5
6 namespace SpaceEngineersBlueprintEditor.Implements.Services;
7
8 internal class AutoNavigationService : GlobalServiceBase, IAutoNavigationService
9 {
10 private Frame? frame;
11 public bool CanGoBack => frame is not null && frame.CanGoBack;
12 public bool CanGoForward => frame is not null && frame.CanGoForward;
13 public Frame? Frame
14 {
15 get => frame;
16 set
17 {
18 if (value is not null)
19 {
20 value.Navigated += (s, e) => Navigated?.Invoke(s, e);
21 if (frame is not null)
22 frame.Navigated -= (s, e) => Navigated?.Invoke(s, e);
23 frame = value;
24 }
25 }
26 }
27
28 public event NavigatedEventHandler? Navigated;
29
30 public void GoBack() => frame?.GoBack();
31
32 public void GoForward() => frame?.GoForward();
33
34 public void NavigateTo(string pageType, object? parameter = null, NavigationTransitionInfo? navigationTransitionInfo = null)
35 {
36 if (PageManager.PageDefinitions.TryGetValue(pageType, out var type))
37 NavigateTo(type, parameter, navigationTransitionInfo);
38 }
39
40 public void NavigateTo(Type type, object? parameter = null, NavigationTransitionInfo? navigationTransitionInfo = null)
41 {
42 if (frame?.SourcePageType != type || (frame.Content is Page page && !Equals(page.GetParameter(), parameter)))
43 frame?.Navigate(type, parameter, navigationTransitionInfo);
44 }
45
46 public void NavigateTo<T>(object? parameter = null, NavigationTransitionInfo? navigationTransitionInfo = null) where T : Page => NavigateTo(typeof(T), parameter, navigationTransitionInfo);
47 }
Renamed SpaceEngineersBlueprintEditor/Implements/Services/CustomNavigationService.cs +1 -1
@@ -5,7 +5,7 @@ using System.Numerics;
5 5
6 6 namespace SpaceEngineersBlueprintEditor.Implements.Services;
7 7
8 internal class NavigationService : GlobalServiceBase, INavigationService
8 internal class NavigationService : GlobalServiceBase, ICustomNavigationService
9 9 {
10 10 private Frame? frame;
11 11 private readonly List<(Page, object?)> navigationStack = [];
Modified SpaceEngineersBlueprintEditor/Implements/Services/NavigationParameterService.cs +5 -5
@@ -2,15 +2,15 @@
2 2
3 3 namespace SpaceEngineersBlueprintEditor.Implements.Services;
4 4
5 internal class NavigationParameterService : INavigationParameterService
5 internal class NavigationParameterService<T> : INavigationParameterService<T>
6 6 {
7 private object? _parameter;
7 private T? _parameter = default;
8 8
9 public object? Parameter { get => _parameter; }
9 public T? Parameter { get => _parameter; }
10 10
11 public event EventHandler<object?>? ParameterChange;
11 public event EventHandler<T>? ParameterChange;
12 12
13 public void OnParameterChange(object? parameter)
13 public void OnParameterChange(T parameter)
14 14 {
15 15 _parameter = parameter;
16 16 ParameterChange?.Invoke(this, parameter);
Modified SpaceEngineersBlueprintEditor/Implements/Services/NavigationViewService.cs +20 -19
@@ -1,4 +1,6 @@
1 using SpaceEngineersBlueprintEditor.Interface.Services;
1 using Microsoft.UI.Xaml.Media.Animation;
2 using Microsoft.UI.Xaml.Navigation;
3 using SpaceEngineersBlueprintEditor.Interface.Services;
2 4 using SpaceEngineersBlueprintEditor.Utilities.Addition;
3 5 using System.Diagnostics.CodeAnalysis;
4 6
@@ -7,8 +9,8 @@ namespace SpaceEngineersBlueprintEditor.Implements.Services;
7 9 internal class NavigationViewService : GlobalServiceBase, INavigationViewService
8 10 {
9 11 private NavigationView? navigationView;
10 private readonly NavigationService navigationService = new();
11 public INavigationService NavigationService => navigationService;
12 private readonly AutoNavigationService navigationService = new();
13 public IAutoNavigationService NavigationService => navigationService;
12 14
13 15 public object? SelectedItem => navigationView?.SelectedItem;
14 16
@@ -22,10 +24,10 @@ internal class NavigationViewService : GlobalServiceBase, INavigationViewService
22 24 navigationService.Navigated += NavigationService_Navigated;
23 25 }
24 26
25 private void NavigationService_Navigated(object? sender, Type e)
27 private void NavigationService_Navigated(object? sender, NavigationEventArgs e)
26 28 {
27 if (navigationView is not null)
28 navigationView.SelectedItem = GetSelectedItem(e);
29 if (navigationView is not null && GetSelectedItem(e.SourcePageType, e.Parameter) is NavigationViewItem navigationViewItem)
30 navigationView.SelectedItem = navigationViewItem;
29 31 }
30 32
31 33 private void NavigationView_BackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args)
@@ -40,35 +42,34 @@ internal class NavigationViewService : GlobalServiceBase, INavigationViewService
40 42 NavigateTo(targetUrl, args.InvokedItemContainer.GetValue(NavigationAddition.NavigateParameterProperty) is string parameter ? parameter : null);
41 43 }
42 44
43 public void NavigateTo<T>(object? parameter = null) where T : Page => navigationService.NavigateTo<T>(parameter);
44
45 public void NavigateTo(Type type, object? parameter = null, bool goBack = false) => navigationService.NavigateTo(type, parameter, goBack);
46
47 public void NavigateTo(string pageName, object? parameter = null) => navigationService.NavigateTo(pageName, parameter);
48
49 public NavigationViewItem? GetSelectedItem(Type type) => navigationView is null ? null : GetSelectedItem(navigationView.MenuItems, navigationView.FooterMenuItems, type);
50 private NavigationViewItem? GetSelectedItem(IEnumerable<object> menuItems, IEnumerable<object> footerMenuItems, Type pageType)
45 public NavigationViewItem? GetSelectedItem(Type type, object? parameter = null) => navigationView is null ? null : GetSelectedItem(navigationView.MenuItems, navigationView.FooterMenuItems, type, parameter);
46 private NavigationViewItem? GetSelectedItem(IEnumerable<object> menuItems, IEnumerable<object> footerMenuItems, Type pageType, object? parameter)
51 47 {
52 var footerResult = GetSelectedItem(footerMenuItems, pageType);
48 var footerResult = GetSelectedItem(footerMenuItems, pageType, parameter);
53 49 if (footerResult is null)
54 return GetSelectedItem(menuItems, pageType);
50 return GetSelectedItem(menuItems, pageType, parameter);
55 51 return footerResult;
56 52 }
57 private NavigationViewItem? GetSelectedItem(IEnumerable<object> menuItems, Type pageType)
53 private static NavigationViewItem? GetSelectedItem(IEnumerable<object> menuItems, Type pageType, object? parameter)
58 54 {
59 55 foreach (var item in menuItems.OfType<NavigationViewItem>())
60 56 {
61 57 if (item.GetNavigateTo() is string pageName && pageName == pageType.FullName)
62 58 {
63 var parameter = navigationService.NavigationStack.Last().Item2;
64 59 var itemParameter = item.GetNavigationParameter();
65 60 if (parameter is string && Equals(parameter, itemParameter) || parameter == itemParameter)
66 61 return item;
67 62 }
68 var selectedChild = GetSelectedItem(item.MenuItems, pageType);
63 var selectedChild = GetSelectedItem(item.MenuItems, pageType, parameter);
69 64 if (selectedChild != null)
70 65 return selectedChild;
71 66 }
72 67 return null;
73 68 }
69
70 public void NavigateTo(string pageType, object? parameter = null, NavigationTransitionInfo? navigationTransitionInfo = null) => navigationService.NavigateTo(pageType, parameter, navigationTransitionInfo);
71
72 public void NavigateTo(Type type, object? parameter = null, NavigationTransitionInfo? navigationTransitionInfo = null) => navigationService.NavigateTo(type, parameter, navigationTransitionInfo);
73
74 public void NavigateTo<T>(object? parameter = null, NavigationTransitionInfo? navigationTransitionInfo = null) where T : Page => navigationService.NavigateTo<T>(parameter, navigationTransitionInfo);
74 75 }
Added SpaceEngineersBlueprintEditor/Interface/IAutoNavigable.cs +10 -0
@@ -0,0 +1,10 @@
1 using Microsoft.UI.Xaml.Media.Animation;
2
3 namespace SpaceEngineersBlueprintEditor.Interface;
4
5 public interface IAutoNavigable
6 {
7 void NavigateTo(string pageType, object? parameter = null, NavigationTransitionInfo? navigationTransitionInfo = null);
8 void NavigateTo(Type type, object? parameter = null, NavigationTransitionInfo? navigationTransitionInfo = null);
9 void NavigateTo<T>(object? parameter = null, NavigationTransitionInfo? navigationTransitionInfo = null) where T : Page;
10 }
Renamed SpaceEngineersBlueprintEditor/Interface/ICustomNavigable.cs +1 -1
@@ -1,6 +1,6 @@
1 1 namespace SpaceEngineersBlueprintEditor.Interface;
2 2
3 public interface INavigable
3 public interface ICustomNavigable
4 4 {
5 5 void NavigateTo<T>(object? parameter = null) where T : Page;
6 6 void NavigateTo(Type type, object? parameter = null, bool goBack = false);
Added SpaceEngineersBlueprintEditor/Interface/Services/IAutoNavigationService.cs +8 -0
@@ -0,0 +1,8 @@
1 using Microsoft.UI.Xaml.Navigation;
2
3 namespace SpaceEngineersBlueprintEditor.Interface.Services;
4
5 public interface IAutoNavigationService : INavigationService, IAutoNavigable
6 {
7 event NavigatedEventHandler Navigated;
8 }
Added SpaceEngineersBlueprintEditor/Interface/Services/ICustomNavigationService.cs +7 -0
@@ -0,0 +1,7 @@
1 namespace SpaceEngineersBlueprintEditor.Interface.Services;
2
3 public interface ICustomNavigationService : INavigationService, ICustomNavigable
4 {
5 event EventHandler<Type> Navigated;
6 List<(Page, object?)> NavigationStack { get; }
7 }
Modified SpaceEngineersBlueprintEditor/Interface/Services/INavigationParameterService.cs +4 -4
@@ -1,8 +1,8 @@
1 1 namespace SpaceEngineersBlueprintEditor.Interface.Services;
2 2
3 public interface INavigationParameterService
3 public interface INavigationParameterService<T>
4 4 {
5 object? Parameter { get; }
6 event EventHandler<object?> ParameterChange;
7 void OnParameterChange(object? parameter);
5 T? Parameter { get; }
6 event EventHandler<T> ParameterChange;
7 void OnParameterChange(T parameter);
8 8 }
Modified SpaceEngineersBlueprintEditor/Interface/Services/INavigationService.cs +1 -3
@@ -1,11 +1,9 @@
1 1 namespace SpaceEngineersBlueprintEditor.Interface.Services;
2 2
3 public interface INavigationService : INavigable, IGlobalService
3 public interface INavigationService : IGlobalService
4 4 {
5 event EventHandler<Type> Navigated;
6 5 bool CanGoBack { get; }
7 6 bool CanGoForward { get; }
8 7 Frame? Frame { get; set; }
9 List<(Page, object?)> NavigationStack { get; }
10 8 void GoBack();
11 9 }
Modified SpaceEngineersBlueprintEditor/Interface/Services/INavigationViewService.cs +3 -3
@@ -1,9 +1,9 @@
1 1 namespace SpaceEngineersBlueprintEditor.Interface.Services;
2 2
3 public interface INavigationViewService : INavigable
3 public interface INavigationViewService : IAutoNavigable
4 4 {
5 INavigationService NavigationService { get; }
5 IAutoNavigationService NavigationService { get; }
6 6 void Initialize(NavigationView navigationView, Frame frame);
7 7 object? SelectedItem { get; }
8 NavigationViewItem? GetSelectedItem(Type type);
8 NavigationViewItem? GetSelectedItem(Type type, object? parameter = null);
9 9 }
Modified SpaceEngineersBlueprintEditor/SpaceEngineersBlueprintEditor.csproj +6 -0
Modified SpaceEngineersBlueprintEditor/ViewModels/AppShellPageViewModel.cs +2 -3
Added SpaceEngineersBlueprintEditor/ViewModels/BlueprintDetailPageViewModel.cs +19 -0
Modified SpaceEngineersBlueprintEditor/ViewModels/BlueprintEditPageViewModel.cs +3 -2
Modified SpaceEngineersBlueprintEditor/ViewModels/BlueprintsViewPageViewModel.cs +7 -9
Modified SpaceEngineersBlueprintEditor/ViewModels/MainPageViewModel.cs +2 -2
Added SpaceEngineersBlueprintEditor/Views/BlueprintDetailPage.xaml +14 -0
Added SpaceEngineersBlueprintEditor/Views/BlueprintDetailPage.xaml.cs +31 -0
Modified SpaceEngineersBlueprintEditor/Views/BlueprintEditPage.xaml.cs +13 -8
Modified SpaceEngineersBlueprintEditor/Views/BlueprintsViewPage.xaml +4 -3
Modified SpaceEngineersBlueprintEditor/Views/BlueprintsViewPage.xaml.cs +18 -9