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

SpaceEngineersModDev/SpaceEngineersBlueprintEditorInWinUI

完善带参数导航功能

5f17aab
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

19 个文件 +135 -37
Added SpaceEngineersBlueprintEditor/Assets/Images/thumb.png +0 -0
二进制文件已变更,无法进行逐行预览。
Added SpaceEngineersBlueprintEditor/Implements/Services/NavigationParameterService.cs +18 -0
@@ -0,0 +1,18 @@
1 using SpaceEngineersBlueprintEditor.Interface.Services;
2
3 namespace SpaceEngineersBlueprintEditor.Implements.Services;
4
5 public class NavigationParameterService : INavigationParameterService
6 {
7 private object? _parameter;
8
9 public object? Parameter { get => _parameter; }
10
11 public event EventHandler<object?>? ParameterChange;
12
13 public void OnParameterChange(object? parameter)
14 {
15 _parameter = parameter;
16 ParameterChange?.Invoke(this, parameter);
17 }
18 }
Modified SpaceEngineersBlueprintEditor/Implements/Services/NavigationService.cs +7 -5
@@ -28,12 +28,13 @@ internal class NavigationService : INavigationService
28 28
29 29 public void GoForward() => Frame?.GoForward();
30 30
31 public void NavigateTo(Type type)
31 public void NavigateTo(Type type, object? parameter = null)
32 32 {
33 if (Frame is not null && (navigationStack.Count == 0 || navigationStack.Last().GetType() != type))
33 if (Frame is not null && (navigationStack.Count == 0 || navigationStack.Last().GetType() != type || parameter is not null && navigationStack.Last().GetParameter() != parameter))
34 34 {
35 35 if (PageManager.CurrentPages.TryGetValue(type.FullName!, out var page))
36 36 {
37 page.SetParameter(parameter);
37 38 navigationStack.Add(page);
38 39 Frame.Content = page;
39 40 }
@@ -42,6 +43,7 @@ internal class NavigationService : INavigationService
42 43 var instance = Activator.CreateInstance(type);
43 44 if (instance is Page pageInstance)
44 45 {
46 pageInstance.SetParameter(parameter);
45 47 navigationStack.Add(pageInstance);
46 48 Frame.Content = pageInstance;
47 49 }
@@ -50,11 +52,11 @@ internal class NavigationService : INavigationService
50 52 }
51 53 }
52 54
53 public void NavigateTo<T>() where T : Page => NavigateTo(typeof(T));
55 public void NavigateTo<T>(object? parameter = null) where T : Page => NavigateTo(typeof(T), parameter);
54 56
55 public void NavigateTo(string pageName)
57 public void NavigateTo(string pageName, object? parameter = null)
56 58 {
57 59 if (PageManager.PageDefinitions.TryGetValue(pageName, out var pageType))
58 NavigateTo(pageType);
60 NavigateTo(pageType, parameter);
59 61 }
60 62 }
Modified SpaceEngineersBlueprintEditor/Implements/Services/NavigationViewService.cs +15 -11
@@ -1,5 +1,6 @@
1 1 using SpaceEngineersBlueprintEditor.Interface.Services;
2 2 using SpaceEngineersBlueprintEditor.Utilities;
3 using SpaceEngineersBlueprintEditor.Utilities.Addition;
3 4
4 5 namespace SpaceEngineersBlueprintEditor.Implements.Services;
5 6
@@ -34,15 +35,15 @@ internal class NavigationViewService : INavigationViewService
34 35
35 36 private void NavigationView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
36 37 {
37 if (args.InvokedItemContainer is ContentControl contentControl && contentControl.Tag is string tag)
38 NavigateTo(tag);
38 if (args.InvokedItemContainer.GetValue(NavigationAddition.NavigateToProperty) is string targetUrl)
39 NavigateTo(targetUrl, args.InvokedItemContainer.GetValue(NavigationAddition.NavigateParameterProperty) is string parameter ? parameter : null);
39 40 }
40 41
41 public void NavigateTo<T>() where T : Page => NavigationService.NavigateTo<T>();
42 public void NavigateTo<T>(object? parameter = null) where T : Page => NavigationService.NavigateTo<T>(parameter);
42 43
43 public void NavigateTo(Type type) => NavigationService.NavigateTo(type);
44 public void NavigateTo(Type type, object? parameter = null) => NavigationService.NavigateTo(type, parameter);
44 45
45 public void NavigateTo(string pageName) => NavigationService.NavigateTo(pageName);
46 public void NavigateTo(string pageName, object? parameter = null) => NavigationService.NavigateTo(pageName, parameter);
46 47
47 48 public NavigationViewItem? GetSelectedItem(Type type) => navigationView is null ? null : GetSelectedItem(navigationView.MenuItems, navigationView.FooterMenuItems, type);
48 49 private static NavigationViewItem? GetSelectedItem(IEnumerable<object> menuItems, IEnumerable<object> footerMenuItems, Type pageType)
@@ -54,13 +55,16 @@ internal class NavigationViewService : INavigationViewService
54 55 }
55 56 private static NavigationViewItem? GetSelectedItem(IEnumerable<object> menuItems, Type pageType)
56 57 {
57 foreach (var item in menuItems.OfType<NavigationViewItem>())
58 if (PageManager.CurrentPages.TryGetValue(pageType.FullName!, out var page))
58 59 {
59 if (item.Tag is string tag && PageManager.PageDefinitions.TryGetValue(tag, out var type) && type == pageType)
60 return item;
61 var selectedChild = GetSelectedItem(item.MenuItems, pageType);
62 if (selectedChild != null)
63 return selectedChild;
60 foreach (var item in menuItems.OfType<NavigationViewItem>())
61 {
62 if (item.GetNavigateTo() is string pageName && pageName == pageType.FullName && page.GetParameter() == item.GetNavigationParameter())
63 return item;
64 var selectedChild = GetSelectedItem(item.MenuItems, pageType);
65 if (selectedChild != null)
66 return selectedChild;
67 }
64 68 }
65 69 return null;
66 70 }
Modified SpaceEngineersBlueprintEditor/Implements/Services/SettingService.cs +1 -1
@@ -35,7 +35,7 @@ internal class SettingService : ISettingService
35 35
36 36 public void RegisterEvents()
37 37 {
38 foreach (var comboBox in settingControls.Keys.Where(control => control is ComboBox).Cast<ComboBox>())
38 foreach (var comboBox in settingControls.Keys.OfType<ComboBox>())
39 39 comboBox.SelectionChanged += ComboBox_SelectionChanged;
40 40 }
41 41 }
Modified SpaceEngineersBlueprintEditor/Interface/INavigable.cs +3 -3
@@ -2,7 +2,7 @@
2 2
3 3 public interface INavigable
4 4 {
5 void NavigateTo<T>() where T : Page;
6 void NavigateTo(Type type);
7 void NavigateTo(string pageName);
5 void NavigateTo<T>(object? parameter = null) where T : Page;
6 void NavigateTo(Type type, object? parameter = null);
7 void NavigateTo(string pageName, object? parameter = null);
8 8 }
Added SpaceEngineersBlueprintEditor/Interface/Services/INavigationParameterService.cs +8 -0
@@ -0,0 +1,8 @@
1 namespace SpaceEngineersBlueprintEditor.Interface.Services;
2
3 public interface INavigationParameterService
4 {
5 object? Parameter { get; }
6 event EventHandler<object?> ParameterChange;
7 void OnParameterChange(object? parameter);
8 }
Modified SpaceEngineersBlueprintEditor/MainWindow.xaml.cs +4 -0
@@ -1,3 +1,5 @@
1 using Windows.UI.ViewManagement;
2
1 3 namespace SpaceEngineersBlueprintEditor;
2 4
3 5 /// <summary>
@@ -5,10 +7,12 @@ namespace SpaceEngineersBlueprintEditor;
5 7 /// </summary>
6 8 public sealed partial class MainWindow : Window
7 9 {
10 public static UISettings UISettings { get; set; } = new UISettings();
8 11 public MainWindow()
9 12 {
10 13 this.InitializeComponent();
11 14 ExtendsContentIntoTitleBar = true;
12 15 AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/Icons/EditorIcon.ico"));
16 UISettings.ColorValuesChanged += (_, _) => DispatcherQueue.TryEnqueue(() => AppThemeHelper.ChangeTheme(SystemProfile.Theme));
13 17 }
14 18 }
Modified SpaceEngineersBlueprintEditor/Profiles/CrossVersionProfiles/SystemProfile.cs +1 -4
@@ -9,8 +9,5 @@ public partial class SystemProfile
9 9 [ProfileProperty]
10 10 private ElementTheme theme = ElementTheme.Default;
11 11
12 static partial void SetThemeProperty(ElementTheme value)
13 {
14 AppThemeHelper.ChangeTheme(value);
15 }
12 static partial void SetThemeProperty(ElementTheme value) => AppThemeHelper.ChangeTheme(value);
16 13 }
Modified SpaceEngineersBlueprintEditor/SpaceEngineersBlueprintEditor.csproj +1 -0
@@ -26,6 +26,7 @@
26 26 <None Remove="Assets\Images\EditorIcon300x300.png" />
27 27 <None Remove="Assets\Images\EditorIcon50x50.png" />
28 28 <None Remove="Assets\Images\EditorIcon88x88.png" />
29 <None Remove="Assets\Images\thumb.png" />
29 30 <None Remove="Assets\蓝图编辑器图标.png" />
30 31 <None Remove="Styles\Thickness.xaml" />
31 32 <None Remove="Views\AppShellPage.xaml" />
Added SpaceEngineersBlueprintEditor/Utilities/Addition/NavigationAddition.cs +14 -0
@@ -0,0 +1,14 @@
1 namespace SpaceEngineersBlueprintEditor.Utilities.Addition;
2
3 public class NavigationAddition
4 {
5 public static string GetNavigateTo(NavigationViewItem item) => (string)item.GetValue(NavigateToProperty);
6 public static void SetNavigateTo(NavigationViewItem item, string value) => item.SetValue(NavigateToProperty, value);
7
8 public static readonly DependencyProperty NavigateToProperty = DependencyProperty.RegisterAttached("NavigateTo", typeof(string), typeof(NavigationAddition), new PropertyMetadata(""));
9
10 public static object GetNavigateParameter(NavigationViewItem item) => item.GetValue(NavigateParameterProperty);
11 public static void SetNavigateParameter(NavigationViewItem item, object value) => item.SetValue(NavigateParameterProperty, value);
12
13 public static readonly DependencyProperty NavigateParameterProperty = DependencyProperty.RegisterAttached("NavigateParameter", typeof(object), typeof(NavigationAddition), new PropertyMetadata(null));
14 }
Modified SpaceEngineersBlueprintEditor/Utilities/Helpers/AppThemeHelper.cs +10 -1
@@ -4,7 +4,7 @@ using Windows.UI.ViewManagement;
4 4
5 5 namespace SpaceEngineersBlueprintEditor.Utilities.Helpers;
6 6
7 public class AppThemeHelper
7 public static class AppThemeHelper
8 8 {
9 9 public static void ChangeTheme(ElementTheme theme)
10 10 {
@@ -12,6 +12,7 @@ public class AppThemeHelper
12 12 {
13 13 rootElement.RequestedTheme = theme;
14 14 }
15
15 16 if (theme == ElementTheme.Default)
16 17 {
17 18 var uiSettings = new UISettings();
@@ -55,4 +56,12 @@ public class AppThemeHelper
55 56
56 57 App.MainWindow.AppWindow.TitleBar.BackgroundColor = Colors.Transparent;
57 58 }
59
60 public static ApplicationTheme ToAppTheme(this ElementTheme theme) => theme switch
61 {
62 ElementTheme.Default => App.Current.RequestedTheme,
63 ElementTheme.Light => ApplicationTheme.Light,
64 ElementTheme.Dark => ApplicationTheme.Dark,
65 _ => throw new NotImplementedException()
66 };
58 67 }
Added SpaceEngineersBlueprintEditor/Utilities/Helpers/NavigationHelper.cs +11 -0
@@ -0,0 +1,11 @@
1 using SpaceEngineersBlueprintEditor.Utilities.Addition;
2
3 namespace SpaceEngineersBlueprintEditor.Utilities.Helpers;
4
5 public static class NavigationHelper
6 {
7 public static void SetParameter(this Page page, object? parameter) => page.GetType().GetProperty("Parameter")?.SetValue(page, parameter);
8 public static object? GetParameter(this Page page) => page.GetType().GetProperty("Parameter")?.GetValue(page);
9 public static string? GetNavigateTo(this NavigationViewItem navigationViewItem) => navigationViewItem.GetValue(NavigationAddition.NavigateToProperty).ToString();
10 public static object? GetNavigationParameter(this NavigationViewItem navigationViewItem) => navigationViewItem.GetValue(NavigationAddition.NavigateParameterProperty);
11 }
Modified SpaceEngineersBlueprintEditor/Utilities/Helpers/ProfileHelper.cs +1 -1
Added SpaceEngineersBlueprintEditor/ViewModels/BlueprintsViewPageViewModel.cs +19 -0
Modified SpaceEngineersBlueprintEditor/Views/AppShellPage.xaml +7 -7
Modified SpaceEngineersBlueprintEditor/Views/AppShellPage.xaml.cs +3 -2
Modified SpaceEngineersBlueprintEditor/Views/BlueprintsViewPage.xaml.cs +11 -0
Modified SpaceEngineersBlueprintEditor/Views/SettingPage.xaml.cs +1 -2