返回提交历史
Modified
SpaceEngineersBlueprintEditor/App.xaml.cs
+1
-1
Added
SpaceEngineersBlueprintEditor/Blueprint.cs
+12
-0
Added
SpaceEngineersBlueprintEditor/Implements/GlobalServiceBase.cs
+9
-0
Added
SpaceEngineersBlueprintEditor/Implements/Services/BlueprintDropService.cs
+88
-0
Modified
SpaceEngineersBlueprintEditor/Implements/Services/NavigationParameterService.cs
+1
-1
Modified
SpaceEngineersBlueprintEditor/Implements/Services/NavigationService.cs
+30
-26
Modified
SpaceEngineersBlueprintEditor/Implements/Services/NavigationViewService.cs
+12
-14
Modified
SpaceEngineersBlueprintEditor/Implements/Services/SettingService.cs
+2
-2
Modified
SpaceEngineersBlueprintEditor/Interface/INavigable.cs
+1
-1
Added
SpaceEngineersBlueprintEditor/Interface/Services/IFileDropService.cs
+9
-0
Added
SpaceEngineersBlueprintEditor/Interface/Services/IGlobalService.cs
+3
-0
Modified
SpaceEngineersBlueprintEditor/Interface/Services/INavigationService.cs
+2
-2
Modified
SpaceEngineersBlueprintEditor/MainWindow.xaml
+6
-2
Modified
SpaceEngineersBlueprintEditor/MainWindow.xaml.cs
+1
-1
Modified
SpaceEngineersBlueprintEditor/SpaceEngineersBlueprintEditor.csproj
+3
-2
Added
SpaceEngineersBlueprintEditor/Utilities/GlobalServiceManager.cs
+10
-0
Added
SpaceEngineersBlueprintEditor/ViewModels/BlueprintEditPageViewModel.cs
+33
-0
Modified
SpaceEngineersBlueprintEditor/ViewModels/SettingPageViewModel.cs
+0
-3
Modified
SpaceEngineersBlueprintEditor/Views/AppShellPage.xaml
+3
-5
Modified
SpaceEngineersBlueprintEditor/Views/AppShellPage.xaml.cs
+1
-1
Added
SpaceEngineersBlueprintEditor/Views/BlueprintEditPage.xaml
+47
-0
Added
SpaceEngineersBlueprintEditor/Views/BlueprintEditPage.xaml.cs
+35
-0
Deleted
SpaceEngineersBlueprintEditor/Views/BlueprintEditorPage.xaml
+0
-15
Deleted
SpaceEngineersBlueprintEditor/Views/BlueprintEditorPage.xaml.cs
+0
-41
SpaceEngineersModDev/SpaceEngineersBlueprintEditorInWinUI
添加全局服务管理器
79affcc
代码差异
24 个文件
+309
-117
@@ -13,7 +13,7 @@ public partial class App : Application
13
13
{
14
14
this.InitializeComponent();
15
15
PageManager.RegisterPage(typeof(AppShellPage));
16
PageManager.RegisterPage(typeof(BlueprintEditorPage));
16
PageManager.RegisterPage(typeof(BlueprintEditPage));
17
17
PageManager.RegisterPage(typeof(BlueprintsViewPage));
18
18
PageManager.RegisterPage(typeof(SettingPage));
19
19
}
@@ -0,0 +1,12 @@
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
7
namespace SpaceEngineersBlueprintEditor
8
{
9
class Blueprint
10
{
11
}
12
}
@@ -0,0 +1,9 @@
1
using SpaceEngineersBlueprintEditor.Interface.Services;
2
using SpaceEngineersBlueprintEditor.Utilities;
3
4
namespace SpaceEngineersBlueprintEditor.Implements;
5
6
public abstract class GlobalServiceBase : IGlobalService
7
{
8
protected GlobalServiceBase() => GlobalServiceManager.RegisterGlobalService(this);
9
}
@@ -0,0 +1,88 @@
1
using Microsoft.UI.Composition;
2
using Microsoft.UI.Xaml.Media;
3
using Microsoft.UI.Xaml.Media.Imaging;
4
using SpaceEngineersBlueprintEditor.Interface.Services;
5
using System.Diagnostics.CodeAnalysis;
6
using System.Numerics;
7
using Windows.ApplicationModel.DataTransfer;
8
using Windows.Storage;
9
using Windows.UI;
10
11
namespace SpaceEngineersBlueprintEditor.Implements.Services;
12
13
internal class BlueprintDropService : IFileDropService
14
{
15
private string currentPath = "";
16
private UIElement? dropContainerElement;
17
private Compositor? _compositor;
18
private SpringVector3NaturalMotionAnimation? _springAnimation;
19
public event EventHandler<(string, DragEventArgs)>? Drop;
20
21
[MemberNotNull(nameof(dropContainerElement), nameof(_compositor))]
22
public void Initialize(UIElement element, Compositor compositor)
23
{
24
_compositor = compositor;
25
dropContainerElement = element;
26
dropContainerElement.DragEnter += DropContainerElement_DragEnter;
27
dropContainerElement.DragLeave += DropContainerElement_DragLeave;
28
dropContainerElement.Drop += DropContainerElement_Drop;
29
}
30
31
private void DropContainerElement_DragEnter(object sender, DragEventArgs e)
32
{
33
if (e.DataView.Contains(StandardDataFormats.StorageItems))
34
{
35
var waiter = e.DataView.GetStorageItemsAsync();
36
waiter.Wait();
37
var items = waiter.GetResults();
38
if (items.Count == 1 && items[0] is StorageFile storageFile && storageFile.Name.ToLower().EndsWith(".sbc"))
39
{
40
currentPath = storageFile.Path;
41
if (dropContainerElement is not null && _compositor is not null)
42
{
43
CreateOrUpdateSpringAnimation(1.3f);
44
dropContainerElement.StartAnimation(_springAnimation);
45
if (dropContainerElement is Panel panel)
46
panel.Background = new SolidColorBrush(Color.FromArgb(128, 128, 128, 128));
47
}
48
e.AcceptedOperation = DataPackageOperation.Copy;
49
e.DragUIOverride.Caption = "DragFileToEditorText".GetLocalized();
50
e.DragUIOverride.SetContentFromBitmapImage(new BitmapImage(new Uri("ms-appx:///Assets/Images/BlueprintDrag.png", UriKind.RelativeOrAbsolute)));
51
e.DragUIOverride.IsGlyphVisible = false;
52
}
53
}
54
}
55
56
private void DropContainerElement_DragLeave(object sender, DragEventArgs e)
57
{
58
if (dropContainerElement is not null && _compositor is not null)
59
{
60
CreateOrUpdateSpringAnimation(1.0f);
61
dropContainerElement.StartAnimation(_springAnimation);
62
if (dropContainerElement is Panel panel)
63
panel.Background = new SolidColorBrush();
64
}
65
}
66
67
private void DropContainerElement_Drop(object sender, DragEventArgs e)
68
{
69
if (dropContainerElement is not null && _compositor is not null)
70
{
71
CreateOrUpdateSpringAnimation(1.0f);
72
dropContainerElement.StartAnimation(_springAnimation);
73
if (dropContainerElement is Panel panel)
74
panel.Background = new SolidColorBrush();
75
}
76
Drop?.Invoke(this, (currentPath, e));
77
}
78
79
private void CreateOrUpdateSpringAnimation(float finalValue)
80
{
81
if (_springAnimation is null)
82
{
83
_springAnimation = (_compositor ??= App.MainWindow.Compositor).CreateSpringVector3Animation();
84
_springAnimation.Target = "Scale";
85
}
86
_springAnimation.FinalValue = new Vector3(finalValue);
87
}
88
}
@@ -2,7 +2,7 @@
2
2
3
3
namespace SpaceEngineersBlueprintEditor.Implements.Services;
4
4
5
public class NavigationParameterService : INavigationParameterService
5
internal class NavigationParameterService : INavigationParameterService
6
6
{
7
7
private object? _parameter;
8
8
@@ -1,53 +1,57 @@
1
using SpaceEngineersBlueprintEditor.Interface.Services;
1
using Microsoft.UI.Xaml.Hosting;
2
using SpaceEngineersBlueprintEditor.Interface.Services;
2
3
using SpaceEngineersBlueprintEditor.Utilities;
4
using System.Numerics;
3
5
4
6
namespace SpaceEngineersBlueprintEditor.Implements.Services;
5
7
6
internal class NavigationService : INavigationService
8
internal class NavigationService : GlobalServiceBase, INavigationService
7
9
{
8
10
private Frame? frame;
9
private readonly List<Page> navigationStack = [];
11
private readonly List<(Page, object?)> navigationStack = [];
10
12
public bool CanGoBack => navigationStack.Count > 1;
11
13
public bool CanGoForward => Frame is not null && Frame.CanGoForward;
12
14
public Frame? Frame { get => frame; set => frame = value; }
13
15
14
public List<Page> NavigationStack => navigationStack;
16
public List<(Page, object?)> NavigationStack => navigationStack;
15
17
16
18
public event EventHandler<Type>? Navigated;
17
19
18
public void GoBack()
19
{
20
if (navigationStack.Count > 1 && Frame is not null)
21
{
22
navigationStack.RemoveAt(navigationStack.Count - 1);
23
var lastPage = navigationStack.Last();
24
Frame.Content = lastPage;
25
Navigated?.Invoke(Frame, lastPage.GetType());
26
}
27
}
20
public void GoBack() => NavigateTo(navigationStack[^2].Item1.GetType(), navigationStack[^2].Item2, true);
28
21
29
22
public void GoForward() => Frame?.GoForward();
30
23
31
public void NavigateTo(Type type, object? parameter = null)
24
public void NavigateTo(Type type, object? parameter = null, bool goBack = false)
32
25
{
33
if (Frame is not null && (navigationStack.Count == 0 || navigationStack.Last().GetType() != type || parameter is not null && navigationStack.Last().GetParameter() != parameter))
26
if (Frame is not null && (navigationStack.Count == 0 || navigationStack.Last().Item1.GetType() != type || parameter is not null && navigationStack.Last().Item2 != parameter))
34
27
{
35
if (PageManager.CurrentPages.TryGetValue(type.FullName!, out var page))
36
{
37
page.SetParameter(parameter);
38
navigationStack.Add(page);
39
Frame.Content = page;
40
}
41
else
28
if (!PageManager.CurrentPages.TryGetValue(type.FullName!, out var currentPage))
42
29
{
43
30
var instance = Activator.CreateInstance(type);
44
31
if (instance is Page pageInstance)
45
32
{
46
pageInstance.SetParameter(parameter);
47
navigationStack.Add(pageInstance);
48
Frame.Content = pageInstance;
33
currentPage = pageInstance;
49
34
}
50
35
}
36
if (goBack)
37
{
38
navigationStack.RemoveAt(navigationStack.Count - 1);
39
}
40
else
41
{
42
currentPage?.SetParameter(parameter);
43
navigationStack.Add((currentPage!, parameter));
44
}
45
var compositor = App.MainWindow.Compositor;
46
var pageCompositor = ElementCompositionPreview.GetElementVisual(currentPage);
47
pageCompositor.Offset = new Vector3(0, 100, 0);
48
var slideUpAnimation = compositor.CreateVector3KeyFrameAnimation();
49
slideUpAnimation.Target = "Offset";
50
slideUpAnimation.InsertKeyFrame(0f, new Vector3(0, 100, 0));
51
slideUpAnimation.InsertKeyFrame(1f, new Vector3(0, 0, 0), compositor.CreateCubicBezierEasingFunction(new Vector2(0.1f, 0.0f), new Vector2(0.0f, 1f)));
52
slideUpAnimation.Duration = TimeSpan.FromSeconds(0.3);
53
pageCompositor.StartAnimation("Offset", slideUpAnimation);
54
Frame.Content = currentPage;
51
55
Navigated?.Invoke(Frame, type);
52
56
}
53
57
}
@@ -1,10 +1,10 @@
1
1
using SpaceEngineersBlueprintEditor.Interface.Services;
2
using SpaceEngineersBlueprintEditor.Utilities;
3
2
using SpaceEngineersBlueprintEditor.Utilities.Addition;
3
using System.Diagnostics.CodeAnalysis;
4
4
5
5
namespace SpaceEngineersBlueprintEditor.Implements.Services;
6
6
7
internal class NavigationViewService : INavigationViewService
7
internal class NavigationViewService : GlobalServiceBase, INavigationViewService
8
8
{
9
9
private NavigationView? navigationView;
10
10
private readonly INavigationService navigationService = new NavigationService();
@@ -12,6 +12,7 @@ internal class NavigationViewService : INavigationViewService
12
12
13
13
public object? SelectedItem => navigationView?.SelectedItem;
14
14
15
[MemberNotNull(nameof(navigationView))]
15
16
public void Initialize(NavigationView view, Frame frame)
16
17
{
17
18
navigationService.Frame = frame;
@@ -41,30 +42,27 @@ internal class NavigationViewService : INavigationViewService
41
42
42
43
public void NavigateTo<T>(object? parameter = null) where T : Page => NavigationService.NavigateTo<T>(parameter);
43
44
44
public void NavigateTo(Type type, object? parameter = null) => NavigationService.NavigateTo(type, parameter);
45
public void NavigateTo(Type type, object? parameter = null, bool goBack = false) => NavigationService.NavigateTo(type, parameter, goBack);
45
46
46
47
public void NavigateTo(string pageName, object? parameter = null) => NavigationService.NavigateTo(pageName, parameter);
47
48
48
49
public NavigationViewItem? GetSelectedItem(Type type) => navigationView is null ? null : GetSelectedItem(navigationView.MenuItems, navigationView.FooterMenuItems, type);
49
private static NavigationViewItem? GetSelectedItem(IEnumerable<object> menuItems, IEnumerable<object> footerMenuItems, Type pageType)
50
private NavigationViewItem? GetSelectedItem(IEnumerable<object> menuItems, IEnumerable<object> footerMenuItems, Type pageType)
50
51
{
51
52
var footerResult = GetSelectedItem(footerMenuItems, pageType);
52
53
if (footerResult is null)
53
54
return GetSelectedItem(menuItems, pageType);
54
55
return footerResult;
55
56
}
56
private static NavigationViewItem? GetSelectedItem(IEnumerable<object> menuItems, Type pageType)
57
private NavigationViewItem? GetSelectedItem(IEnumerable<object> menuItems, Type pageType)
57
58
{
58
if (PageManager.CurrentPages.TryGetValue(pageType.FullName!, out var page))
59
foreach (var item in menuItems.OfType<NavigationViewItem>())
59
60
{
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
}
61
if (item.GetNavigateTo() is string pageName && pageName == pageType.FullName && NavigationService.NavigationStack.Last().Item2 == item.GetNavigationParameter())
62
return item;
63
var selectedChild = GetSelectedItem(item.MenuItems, pageType);
64
if (selectedChild != null)
65
return selectedChild;
68
66
}
69
67
return null;
70
68
}
@@ -4,7 +4,7 @@ using SpaceEngineersBlueprintEditor.Model;
4
4
5
5
namespace SpaceEngineersBlueprintEditor.Implements.Services;
6
6
7
internal class SettingService : ISettingService
7
internal class SettingService : GlobalServiceBase, ISettingService
8
8
{
9
9
private readonly Dictionary<object, IProfileInfoEntry> settingControls = [];
10
10
@@ -20,7 +20,7 @@ internal class SettingService : ISettingService
20
20
21
21
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
22
22
{
23
if (settingControls.TryGetValue(sender, out var profileInfo)&& profileInfo is ComboBoxProfileInfoEntry comboBoxProfileInfo && e.AddedItems.Count > 0 && e.AddedItems[0] is ComboBoxItem comboBoxItem && comboBoxItem.Tag is string value)
23
if (settingControls.TryGetValue(sender, out var profileInfo) && profileInfo is ComboBoxProfileInfoEntry comboBoxProfileInfo && e.AddedItems.Count > 0 && e.AddedItems[0] is ComboBoxItem comboBoxItem && comboBoxItem.Tag is string value)
24
24
ProfileHelper.SetProfileValue(comboBoxProfileInfo.ProfilePath, comboBoxProfileInfo.ProfileSaveFunc.Invoke(value));
25
25
}
26
26
@@ -3,6 +3,6 @@
3
3
public interface INavigable
4
4
{
5
5
void NavigateTo<T>(object? parameter = null) where T : Page;
6
void NavigateTo(Type type, object? parameter = null);
6
void NavigateTo(Type type, object? parameter = null, bool goBack = false);
7
7
void NavigateTo(string pageName, object? parameter = null);
8
8
}
@@ -0,0 +1,9 @@
1
using Microsoft.UI.Composition;
2
3
namespace SpaceEngineersBlueprintEditor.Interface.Services;
4
5
public interface IFileDropService
6
{
7
event EventHandler<(string, DragEventArgs)> Drop;
8
void Initialize(UIElement element, Compositor compositor);
9
}
@@ -0,0 +1,3 @@
1
namespace SpaceEngineersBlueprintEditor.Interface.Services;
2
3
public interface IGlobalService { }
@@ -6,6 +6,6 @@ public interface INavigationService : INavigable
6
6
bool CanGoBack { get; }
7
7
bool CanGoForward { get; }
8
8
Frame? Frame { get; set; }
9
List<Page> NavigationStack { get; }
10
public void GoBack();
9
List<(Page, object?)> NavigationStack { get; }
10
void GoBack();
11
11
}