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

SpaceEngineersModDev/SpaceEngineersBlueprintEditorInWinUI

fix-修复CommandBarFlyout控件的显示bug add-新增全局背景设置

9df8da0
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

16 个文件 +178 -28
Modified SpaceEngineersBlueprintEditor/App.xaml.cs +1 -1
@@ -40,7 +40,7 @@ public partial class App : Application
40 40 {
41 41 if (GlobalServiceManager.GetService<IMessageService>() is IMessageService messageService)
42 42 {
43 messageService.ShowMessage(e.Message, "错误:", InfoBarSeverity.Error);
43 messageService.ShowMessage(e.Message, "错误", InfoBarSeverity.Error);
44 44 e.Handled = true;
45 45 }
46 46 }
Deleted SpaceEngineersBlueprintEditor/Assets/Images/thumb.png +0 -0
二进制文件已变更,无法进行逐行预览。
Added SpaceEngineersBlueprintEditor/Implements/Services/BackgroundImageService.cs +43 -0
@@ -0,0 +1,43 @@
1 using Microsoft.UI;
2 using Microsoft.UI.Xaml.Media;
3 using SpaceEngineersBlueprintEditor.Interface.Services;
4 using System.Diagnostics.CodeAnalysis;
5 using Windows.UI;
6
7 namespace SpaceEngineersBlueprintEditor.Implements.Services;
8
9 class BackgroundImageService : GlobalServiceBase, IBackgroundImageService
10 {
11 private Page? _page;
12 private Grid? _grid;
13
14 [MemberNotNull(nameof(_page), nameof(_grid))]
15 public void Initialize(Page page, Grid grid)
16 {
17 _page = page;
18 _grid = grid;
19 }
20
21 public void ResetBackground()
22 {
23 if (_page is not null)
24 _page.Background = new SolidColorBrush(Colors.Transparent);
25 if (_grid is not null)
26 _grid.Background = new SolidColorBrush(Colors.Transparent);
27 }
28
29 public void SetBackgroundImage(ImageSource imageSource)
30 {
31 if (_page is not null)
32 _page.Background = new ImageBrush
33 {
34 ImageSource = imageSource
35 };
36 if (_grid is not null)
37 _grid.Background = new AcrylicBrush
38 {
39 TintLuminosityOpacity = 0,
40 TintColor = Colors.Transparent
41 };
42 }
43 }
Added SpaceEngineersBlueprintEditor/Interface/Services/IBackgroundImageService.cs +10 -0
@@ -0,0 +1,10 @@
1 using Microsoft.UI.Xaml.Media;
2
3 namespace SpaceEngineersBlueprintEditor.Interface.Services;
4
5 public interface IBackgroundImageService : IGlobalService
6 {
7 void Initialize(Page page, Grid grid);
8 void SetBackgroundImage(ImageSource imageSource);
9 void ResetBackground();
10 }
Modified SpaceEngineersBlueprintEditor/Model/BlueprintInfoViewData.cs +2 -2
@@ -2,9 +2,9 @@
2 2
3 3 namespace SpaceEngineersBlueprintEditor.Model;
4 4
5 public class BlueprintInfoViewData(ImageSource? blueprintImage, bool noBlueprint, string name, string fileSize, string filePath)
5 public class BlueprintInfoViewData(ImageSource blueprintImage, bool noBlueprint, string name, string fileSize, string filePath)
6 6 {
7 public ImageSource? BlueprintImage { get; set; } = blueprintImage;
7 public ImageSource BlueprintImage { get; set; } = blueprintImage;
8 8 public bool NoBlueprint { get; set; } = noBlueprint;
9 9 public string Name { get; set; } = name;
10 10 public string FileSize { get; set; } = fileSize;
Modified SpaceEngineersBlueprintEditor/Utilities/BlueprintsManager.cs +1 -2
@@ -1,5 +1,4 @@
1 using SpaceEngineersBlueprintEditor.Interface.Services;
2 using SpaceEngineersBlueprintEditor.Model;
1 using SpaceEngineersBlueprintEditor.Model;
3 2 using XFEExtension.NetCore.FileExtension;
4 3
5 4 namespace SpaceEngineersBlueprintEditor.Utilities;
Added SpaceEngineersBlueprintEditor/Utilities/Helpers/FileHelper.cs +30 -0
@@ -0,0 +1,30 @@
1 namespace SpaceEngineersBlueprintEditor.Utilities.Helpers;
2
3 public static class FileHelper
4 {
5 public static string GetCopyFileName(string originalName, int currentNum = 1)
6 {
7 var currentFileName = @$"{Path.GetDirectoryName(originalName)}\{Path.GetFileNameWithoutExtension(originalName)}_{currentNum}{Path.GetExtension(originalName)}";
8 if (File.Exists(currentFileName) || Directory.Exists(currentFileName))
9 return GetCopyFileName(originalName, ++currentNum);
10 return currentFileName;
11 }
12
13 public static void CopyDirectory(string sourceDirectory, string targetDirectory, bool overwrite = false)
14 {
15 if (!Directory.Exists(sourceDirectory)) throw new DirectoryNotFoundException($"源目录未找到: {sourceDirectory}");
16 if (!Directory.Exists(targetDirectory))
17 Directory.CreateDirectory(targetDirectory);
18 foreach (string file in Directory.GetFiles(sourceDirectory))
19 {
20 string targetFile = Path.Combine(targetDirectory, Path.GetFileName(file));
21 File.Copy(file, targetFile, overwrite);
22 }
23 foreach (string subDir in Directory.GetDirectories(sourceDirectory))
24 {
25 string subDirectoryName = Path.GetFileName(subDir);
26 string newTargetDirectory = Path.Combine(targetDirectory, subDirectoryName);
27 CopyDirectory(subDir, newTargetDirectory, overwrite);
28 }
29 }
30 }
Modified SpaceEngineersBlueprintEditor/ViewModels/AppShellPageViewModel.cs +1 -0
@@ -12,6 +12,7 @@ public partial class AppShellPageViewModel : ViewModelBase
12 12 [ObservableProperty]
13 13 bool canGoBack;
14 14 public INavigationViewService NavigationViewService { get; set; } = new NavigationViewService();
15 public IBackgroundImageService BackgroundImageService { get; set; } = new BackgroundImageService();
15 16 public IMessageService MessageService { get; set; } = new MessageService();
16 17
17 18 public AppShellPageViewModel() => NavigationViewService.NavigationService.Navigated += NavigationService_Navigated;
Modified SpaceEngineersBlueprintEditor/ViewModels/BlueprintDetailPageViewModel.cs +2 -1
@@ -7,7 +7,8 @@ namespace SpaceEngineersBlueprintEditor.ViewModels;
7 7
8 8 public partial class BlueprintDetailPageViewModel : ViewModelBase
9 9 {
10 private INavigationViewService? navigationViewService = GlobalServiceManager.GetService<INavigationViewService>();
10 private readonly INavigationViewService? navigationViewService = GlobalServiceManager.GetService<INavigationViewService>();
11 public IBackgroundImageService? BackgroundImageService { get; set; } = GlobalServiceManager.GetService<IBackgroundImageService>();
11 12 public INavigationParameterService<BlueprintInfoViewData> NavigationParameterService { get; set; } = new NavigationParameterService<BlueprintInfoViewData>();
12 13 public BlueprintDetailPageViewModel()
13 14 {
Modified SpaceEngineersBlueprintEditor/ViewModels/BlueprintsViewPageViewModel.cs +52 -7
@@ -4,17 +4,24 @@ using SpaceEngineersBlueprintEditor.Implements.Services;
4 4 using SpaceEngineersBlueprintEditor.Interface.Services;
5 5 using SpaceEngineersBlueprintEditor.Model;
6 6 using SpaceEngineersBlueprintEditor.Utilities;
7 using SpaceEngineersBlueprintEditor.Views;
7 8 using System.Collections.ObjectModel;
9 using System.Diagnostics;
8 10
9 11 namespace SpaceEngineersBlueprintEditor.ViewModels;
10 12
11 13 public partial class BlueprintsViewPageViewModel : ViewModelBase
12 14 {
13 15 private string currentParameter = "";
16 private BlueprintInfoViewData? currentBlueprintInfoViewData;
14 17 private readonly IMessageService? messageService = GlobalServiceManager.GetService<IMessageService>();
15 18 [ObservableProperty]
16 19 private string searchText = "";
17 public INavigationParameterService<string> NavigationParameterService { get; set; } = new NavigationParameterService<string>();
20 [ObservableProperty]
21 private string copyFolderText = "";
22 [ObservableProperty]
23 private string deleteEnsureText = "";
24 public INavigationParameterService<object> NavigationParameterService { get; set; } = new NavigationParameterService<object>();
18 25 public ObservableCollection<BlueprintInfoViewData> BlueprintInfoViewDataList { get; set; } = [];
19 26
20 27 public BlueprintsViewPageViewModel()
@@ -46,15 +53,23 @@ public partial class BlueprintsViewPageViewModel : ViewModelBase
46 53 BlueprintInfoViewDataList.Add(info.ToBlueprintInfoViewData());
47 54 }
48 55
49 private async void NavigationParameterService_ParameterChange(object? sender, string e)
56 private async void NavigationParameterService_ParameterChange(object? sender, object e)
50 57 {
51 currentParameter = e;
52 await BlueprintsManager.LoadBlueprintsAsync();
53 BlueprintInfoViewDataList.Clear();
54 LoadCurrentBlueprints();
58 if (e is string stringParameter)
59 {
60 currentParameter = stringParameter;
61 await BlueprintsManager.LoadBlueprintsAsync();
62 BlueprintInfoViewDataList.Clear();
63 LoadCurrentBlueprints();
64 }
65 else if (e is BlueprintInfoViewData blueprintInfoViewData && Path.GetDirectoryName(blueprintInfoViewData.FilePath) is string path)
66 {
67 currentBlueprintInfoViewData = blueprintInfoViewData;
68 DeleteEnsureText = $"Are you sure to delete {blueprintInfoViewData.Name}?";
69 CopyFolderText = Path.GetFileName(FileHelper.GetCopyFileName(path)) ?? throw new NullReferenceException("Can't get the folder name");
70 }
55 71 }
56 72
57
58 73 [RelayCommand]
59 74 async Task RefreshBlueprints()
60 75 {
@@ -65,4 +80,34 @@ public partial class BlueprintsViewPageViewModel : ViewModelBase
65 80 OnSearchTextChanged(SearchText);
66 81 messageService?.ShowMessage("刷新成功", "完成", InfoBarSeverity.Success);
67 82 }
83
84 [RelayCommand]
85 void OpenFolder()
86 {
87 if (currentBlueprintInfoViewData is not null && Path.GetDirectoryName(currentBlueprintInfoViewData.FilePath) is string path)
88 Process.Start("explorer.exe", path);
89 }
90
91 [RelayCommand]
92 async Task CopyTo()
93 {
94 if (currentBlueprintInfoViewData is not null && Path.GetDirectoryName(currentBlueprintInfoViewData.FilePath) is string path && await BlueprintsViewPage.Current?.copyToContentDialog.ShowAsync() == ContentDialogResult.Primary)
95 {
96 var targetPath = $@"{Path.GetDirectoryName(path)}\{CopyFolderText}";
97 FileHelper.CopyDirectory(path, targetPath);
98 messageService?.ShowMessage($"已复制至:{targetPath}", "完成", InfoBarSeverity.Success);
99 await RefreshBlueprints();
100 }
101 }
102
103 [RelayCommand]
104 async Task DeleteBlueprint()
105 {
106 if (currentBlueprintInfoViewData is not null && Path.GetDirectoryName(currentBlueprintInfoViewData.FilePath) is string path)
107 {
108 Directory.Delete(path, true);
109 messageService?.ShowMessage($"已删除:{path}", "完成", InfoBarSeverity.Success);
110 await RefreshBlueprints();
111 }
112 }
68 113 }
Modified SpaceEngineersBlueprintEditor/Views/AppShellPage.xaml +2 -1
@@ -7,7 +7,8 @@
7 7 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8 8 xmlns:add="using:SpaceEngineersBlueprintEditor.Utilities.Addition"
9 9 mc:Ignorable="d" Loaded="Page_Loaded">
10 <Grid>
10
11 <Grid x:Name="mainGrid">
11 12 <Grid x:Name="appTitleBar" Canvas.ZIndex="1" Height="{Binding ElementName=navigationView, Path=CompactPaneLength}" IsHitTestVisible="True" VerticalAlignment="Top">
12 13 <Image Source="/Assets/Icons/EditorIcon.ico" HorizontalAlignment="Left" Width="16" Height="16"/>
13 14 <TextBlock x:Uid="AppShell_AppTitle" VerticalAlignment="Center" TextWrapping="NoWrap" Margin="28,0,0,0"/>
Modified SpaceEngineersBlueprintEditor/Views/AppShellPage.xaml.cs +1 -0
@@ -17,6 +17,7 @@ public sealed partial class AppShellPage : Page
17 17 App.MainWindow?.SetTitleBar(appTitleBar);
18 18 ViewModel.NavigationViewService.Initialize(navigationView, navigationFrame);
19 19 ViewModel.MessageService.Initialize(messageStackPanel, DispatcherQueue);
20 ViewModel.BackgroundImageService.Initialize(this, mainGrid);
20 21 ViewModel.NavigationViewService.NavigateTo<MainPage>();
21 22 }
22 23
Modified SpaceEngineersBlueprintEditor/Views/BlueprintDetailPage.xaml +14 -4
@@ -9,10 +9,20 @@
9 9 mc:Ignorable="d">
10 10
11 11 <Grid>
12 <ScrollView>
13 <StackPanel>
14 <TextBlock Style="{ThemeResource SubtitleTextBlockStyle}"/>
15 <Image x:Name="detailPreviewImage" Source="{x:Bind Parameter.BlueprintImage}" Width="350" Stretch="Uniform" HorizontalAlignment="Left" VerticalAlignment="Top"/>
12 <Grid>
13
14 </Grid>
15 <ScrollView Canvas.ZIndex="0">
16 <StackPanel Orientation="Vertical">
17 <Grid HorizontalAlignment="Left" VerticalAlignment="Top" ColumnDefinitions="350, *" ColumnSpacing="20" RowDefinitions="*, *, *, *, *, *" RowSpacing="20">
18 <Image x:Name="detailPreviewImage" Grid.RowSpan="6" Source="{x:Bind Parameter.BlueprintImage}" Width="350" Stretch="Uniform"/>
19 <TextBlock Grid.Column="1" Grid.Row="0" Text="蓝图基本信息:"/>
20 <!--<TextBlock Grid.Column="1" Grid.Row="1" Text="{x:Bind 蓝图作者:}"/>
21 <TextBlock Grid.Column="1" Grid.Row="4" Text="{x:Bind 蓝图大小}"/>
22 <TextBlock Grid.Column="1" Grid.Row="5" Text="{x:Bind 蓝图位置:}"/>
23 <TextBlock Grid.Column="1" Grid.Row="2" Text="{x:Bind 是否可破坏:}"/>
24 <TextBlock Grid.Column="1" Grid.Row="3" Text="{x:Bind 是否可在游戏内编辑:}"/>-->
25 </Grid>
16 26 </StackPanel>
17 27 </ScrollView>
18 28 </Grid>
Modified SpaceEngineersBlueprintEditor/Views/BlueprintDetailPage.xaml.cs +4 -0
Modified SpaceEngineersBlueprintEditor/Views/BlueprintsViewPage.xaml +12 -9
Modified SpaceEngineersBlueprintEditor/Views/BlueprintsViewPage.xaml.cs +3 -1