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

SpaceEngineersModDev/SpaceEngineersBlueprintEditorInWinUI

完善大部分蓝图编辑功能

34076bf
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

21 个文件 +557 -21
Modified SpaceEngineersBlueprintEditor/App.xaml.cs +0 -1
@@ -30,7 +30,6 @@ public partial class App : Application
30 30 if (SystemProfile.GameRootPath.IsNullOrEmpty())
31 31 SystemProfile.GameRootPath = SpaceEngineersHelper.GetGameRootPath();
32 32 Initializer.Initialize(SpaceEngineersPath.SpaceEngineerContentPath, SpaceEngineersPath.UserGameDataRoot);
33 GlobalServiceManager.GetService<IMessageService>()?.ShowMessage("游戏集定义加载完成", "完成", InfoBarSeverity.Success);
34 33 }
35 34 catch (Exception ex)
36 35 {
Added SpaceEngineersBlueprintEditor/Implements/Services/DialogService.cs +9 -0
@@ -0,0 +1,9 @@
1 using SpaceEngineersBlueprintEditor.Interface.Services;
2
3 namespace SpaceEngineersBlueprintEditor.Implements.Services;
4
5 public class DialogService : IDialogService
6 {
7 private readonly Dictionary<string, ContentDialog> dialogDictionary = [];
8 public Dictionary<string, ContentDialog> DialogDictionary => dialogDictionary;
9 }
Modified SpaceEngineersBlueprintEditor/Implements/Services/NavigationViewService.cs +2 -0
@@ -17,6 +17,8 @@ internal class NavigationViewService : GlobalServiceBase, INavigationViewService
17 17
18 18 public NavigationView? NavigationView => navigationView;
19 19
20 public XamlRoot? XamlRoot => navigationView?.XamlRoot;
21
20 22 [MemberNotNull(nameof(navigationView))]
21 23 public void Initialize(NavigationView view, Frame frame)
22 24 {
Added SpaceEngineersBlueprintEditor/Interface/Services/IDialogService.cs +8 -0
@@ -0,0 +1,8 @@
1 namespace SpaceEngineersBlueprintEditor.Interface.Services;
2
3 public interface IDialogService
4 {
5 Dictionary<string, ContentDialog> DialogDictionary { get; }
6 void RegisterDialog(ContentDialog contentDialog) => DialogDictionary.Add(contentDialog.Name, contentDialog);
7 async Task<ContentDialogResult> ShowDialog(string dialogName) => await DialogDictionary[dialogName].ShowAsync();
8 }
Modified SpaceEngineersBlueprintEditor/Interface/Services/INavigationViewService.cs +1 -0
@@ -7,5 +7,6 @@ public interface INavigationViewService : IAutoNavigable, IGlobalService
7 7 void Initialize(NavigationView navigationView, Frame frame);
8 8 object? SelectedItem { get; }
9 9 string? Header { get; set; }
10 XamlRoot? XamlRoot { get; }
10 11 NavigationViewItem? GetSelectedItem(Type type, object? parameter = null);
11 12 }
Added SpaceEngineersBlueprintEditor/Model/BlueprintModel.cs +9 -0
@@ -0,0 +1,9 @@
1 using VRage.Game;
2
3 namespace SpaceEngineersBlueprintEditor.Model;
4
5 public class BlueprintModel
6 {
7 public MyObjectBuilder_Definitions? BlueprintDefinitions { get; set; }
8 public BlueprintInfoViewData? ViewData { get; set; }
9 }
Added SpaceEngineersBlueprintEditor/Model/BlueprintPropertyViewData.cs +26 -0
@@ -0,0 +1,26 @@
1 using CommunityToolkit.Mvvm.ComponentModel;
2 using Microsoft.UI.Xaml.Media;
3 using SpaceEngineersBlueprintEditor.ViewModels;
4 using System.Collections;
5 using XFEExtension.NetCore.XFETransform;
6
7 namespace SpaceEngineersBlueprintEditor.Model;
8
9 public partial class BlueprintPropertyViewData : ViewModelBase
10 {
11 [ObservableProperty]
12 private object? value;
13 [ObservableProperty]
14 private string? valueInString;
15 public Type? Type { get; set; }
16 public string? Name { get; set; }
17 public string? CustomName { get; set; }
18 public BlueprintPropertyViewData? Parent { get; set; }
19 public ImageSource? CubeImage { get; set; }
20 public List<BlueprintPropertyViewData> Children { get; set; } = [];
21 public bool IsEnumerable => Type is not null && Type.IsAssignableTo(typeof(IEnumerable)) && Type != typeof(string);
22 public bool IsBasicType => Type is not null && (XFEConverter.IsBasicType(Type) || Type.IsAssignableTo(typeof(Enum)));
23 public bool IsNotBasicType => !IsBasicType;
24
25 partial void OnValueChanged(object? value) => ValueInString = string.IsNullOrEmpty(Value?.ToString()) ? "值为空" : Value?.ToString();
26 }
Modified SpaceEngineersBlueprintEditor/SpaceEngineersBlueprintEditor.csproj +3 -3
@@ -55,10 +55,10 @@
55 55 <PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
56 56 <PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.2.241112-preview1" />
57 57 <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
58 <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240923002" />
58 <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.241114003" />
59 59 <PackageReference Include="System.Drawing.Common" Version="9.0.0" />
60 <PackageReference Include="WinUIEx" Version="2.4.2" />
61 <PackageReference Include="XFEExtension.NetCore" Version="3.2.0" />
60 <PackageReference Include="WinUIEx" Version="2.5.0" />
61 <PackageReference Include="XFEExtension.NetCore" Version="3.2.1" />
62 62 <PackageReference Include="XFEExtension.NetCore.AutoConfig" Version="1.3.0" />
63 63 <PackageReference Include="XFEExtension.NetCore.AutoPath" Version="1.0.1" />
64 64 <PackageReference Include="XFEExtension.NetCore.TodoHighLight" Version="1.0.0" />
Modified SpaceEngineersBlueprintEditor/Styles/Controls.xaml +16 -0
@@ -14,4 +14,20 @@
14 14 </Grid>
15 15 </ItemContainer>
16 16 </DataTemplate>
17
18 <DataTemplate x:Key="BlueprintDataTemplate">
19 <TreeViewItem ItemsSource="{Binding Children}">
20 <Grid Padding="0,0,5,0">
21 <Grid.ColumnDefinitions>
22 <ColumnDefinition Width="*"/>
23 <ColumnDefinition Width="150"/>
24 </Grid.ColumnDefinitions>
25 <StackPanel Orientation="Horizontal" Spacing="20">
26 <FontIcon VerticalAlignment="Center" Glyph="{Binding Icon}"/>
27 <TextBlock VerticalAlignment="Center" Text="{Binding Name}"/>
28 </StackPanel>
29 <TextBlock VerticalAlignment="Center" HorizontalAlignment="Right" TextTrimming="CharacterEllipsis" Text="{Binding ValueInString}" Grid.Column="1" Visibility="{Binding IsBasicType}" Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"/>
30 </Grid>
31 </TreeViewItem>
32 </DataTemplate>
17 33 </ResourceDictionary>
Modified SpaceEngineersBlueprintEditor/Utilities/Helpers/Extensions.cs +8 -0
@@ -1,6 +1,7 @@
1 1 using Microsoft.UI.Xaml.Media.Imaging;
2 2 using Microsoft.Windows.ApplicationModel.Resources;
3 3 using SpaceEngineersBlueprintEditor.Model;
4 using XFEExtension.NetCore.FileExtension;
4 5
5 6 namespace SpaceEngineersBlueprintEditor.Utilities.Helpers;
6 7
@@ -9,4 +10,11 @@ public static class Extensions
9 10 private static readonly ResourceLoader _resourceLoader = new();
10 11 public static string GetLocalized(this string resourceKey) => _resourceLoader.GetString(resourceKey);
11 12 public static BlueprintInfoViewData ToBlueprintInfoViewData(this BlueprintInfo blueprintInfo) => new(new BitmapImage(blueprintInfo.HasImage ? new(blueprintInfo.ImagePath) : new Uri("ms-appx:///Assets/Images/BlueprintDrag.png", UriKind.RelativeOrAbsolute)), !blueprintInfo.HasBlueprint, blueprintInfo.Name, blueprintInfo.FileSize, blueprintInfo.BlueprintPath);
13 public static BlueprintInfoViewData ToBlueprintInfoViewData(this string blueprintFile)
14 {
15 var rootPath = Path.GetDirectoryName(blueprintFile);
16 var imagePath = $@"{rootPath}\thumb.png";
17 var hasImage = File.Exists(imagePath);
18 return new(new BitmapImage(hasImage ? new(imagePath) : new Uri("ms-appx:///Assets/Images/BlueprintDrag.png", UriKind.RelativeOrAbsolute)), !hasImage, Path.GetFileName(rootPath)!, new FileInfo(blueprintFile).Length.FileSize(), blueprintFile);
19 }
12 20 }
Modified SpaceEngineersBlueprintEditor/Utilities/Helpers/SpaceEngineersHelper.cs +110 -1
@@ -1,6 +1,10 @@
1 using Microsoft.Win32;
1 using Microsoft.UI.Xaml.Media.Imaging;
2 using Microsoft.Win32;
2 3 using Sandbox.Definitions;
4 using SpaceEngineersBlueprintEditor.Model;
3 5 using SpaceEngineersBlueprintEditor.SpaceEngineersCore;
6 using System.Collections;
7 using System.Reflection;
4 8 using VRage.Collections;
5 9 using VRage.Game;
6 10
@@ -15,6 +19,111 @@ public static class SpaceEngineersHelper
15 19 public static IEnumerable<MyComponentDefinition> ComponentDefinitions => AllDefinitions.Where(definition => definition is MyComponentDefinition).Cast<MyComponentDefinition>();
16 20 public static IEnumerable<MyPhysicalItemDefinition> ItemDefinitions => AllDefinitions.Where(definition => definition is MyPhysicalItemDefinition).Cast<MyPhysicalItemDefinition>();
17 21 public static IEnumerable<MyScenarioDefinition> ScenarioDefinition => AllDefinitions.Where(definition => definition is MyScenarioDefinition).Cast<MyScenarioDefinition>();
22
23 public static void AnalyzeBlueprint(BlueprintPropertyViewData blueprintPropertyViewData, params string[] exceptedName)
24 {
25 if (CheckIfNull(blueprintPropertyViewData))
26 return;
27 if (IsSpecialObject(blueprintPropertyViewData))
28 return;
29 foreach (var member in blueprintPropertyViewData.Type!.GetMembers())
30 {
31 Type? type = null;
32 try
33 {
34 if (member is FieldInfo fieldInfo && !exceptedName.Contains(fieldInfo.Name) && fieldInfo.IsPublic)
35 {
36 type = fieldInfo.FieldType;
37 var value = fieldInfo.GetValue(blueprintPropertyViewData.Value);
38 blueprintPropertyViewData.Children.Add(new()
39 {
40 Type = type,
41 Name = fieldInfo.Name,
42 Value = value,
43 Parent = blueprintPropertyViewData
44 });
45 }
46 else if (member is PropertyInfo propertyInfo && !exceptedName.Contains(propertyInfo.Name) && propertyInfo.CanWrite && propertyInfo.IsMemberPublic())
47 {
48 type = propertyInfo.PropertyType;
49 var value = propertyInfo.GetValue(blueprintPropertyViewData.Value);
50 blueprintPropertyViewData.Children.Add(new()
51 {
52 Type = type,
53 Name = propertyInfo.Name,
54 Value = value,
55 Parent = blueprintPropertyViewData
56 });
57 }
58 }
59 catch (Exception ex)
60 {
61 blueprintPropertyViewData.Children.Add(new()
62 {
63 Type = type,
64 Name = $"错误异常:{ex.Message}",
65 Parent = blueprintPropertyViewData
66 });
67 }
68 }
69 }
70
71 private static bool CheckIfNull(BlueprintPropertyViewData blueprintPropertyViewData)
72 {
73 if (blueprintPropertyViewData.Value is null || blueprintPropertyViewData.Type is null)
74 {
75 blueprintPropertyViewData.Children.Add(new()
76 {
77 Name = "空对象",
78 Parent = blueprintPropertyViewData
79 });
80 return true;
81 }
82 return false;
83 }
84
85 private static bool IsSpecialObject(BlueprintPropertyViewData blueprintPropertyViewData)
86 {
87 if (blueprintPropertyViewData.Type!.IsAssignableTo(typeof(IEnumerable)))
88 {
89 AddArrayOrEnumerableChildren<IEnumerable>(blueprintPropertyViewData);
90 return true;
91 }
92 return false;
93 }
94
95 private static void AddArrayOrEnumerableChildren<T>(BlueprintPropertyViewData blueprintPropertyViewData) where T : IEnumerable
96 {
97 foreach (var item in (T)blueprintPropertyViewData.Value!)
98 {
99 var type = item.GetType();
100 var child = new BlueprintPropertyViewData()
101 {
102 Type = type,
103 Name = type.Name,
104 Value = item,
105 Parent = blueprintPropertyViewData
106 };
107 SetDetail(child, item);
108 blueprintPropertyViewData.Children.Add(child);
109 }
110 }
111
112 public static void SetDetail(BlueprintPropertyViewData blueprintPropertyViewData, object? value)
113 {
114 if (value is MyObjectBuilder_CubeBlock myObjectBuilder_CubeBlock)
115 {
116 var cubeBlock = MyDefinitionManager.Static.GetCubeBlockDefinition(myObjectBuilder_CubeBlock);
117 blueprintPropertyViewData.Name = cubeBlock.DisplayNameText;
118 blueprintPropertyViewData.CubeImage = new BitmapImage(new(@$"{AppPath.DefinitionImages}\{FileHelper.ChangeExtension(cubeBlock.Icons[0], "png")}"));
119 blueprintPropertyViewData.CustomName = value is MyObjectBuilder_TerminalBlock myObjectBuilder_TerminalBlock ? myObjectBuilder_TerminalBlock.CustomName : string.Empty;
120 }
121 else if (value is MyObjectBuilder_CubeGrid myObjectBuilder_CubeGrid)
122 {
123 blueprintPropertyViewData.Name = myObjectBuilder_CubeGrid.DisplayName;
124 }
125 }
126
18 127 public static async Task LoadDefinitionViewDataListAsync()
19 128 {
20 129 await Helper.Wait(() => Initializer.IsDefinitionsLoadComplete);
Added SpaceEngineersBlueprintEditor/Utilities/Selector/ShipBlueprintItemTemplateSelector.cs +37 -0
@@ -0,0 +1,37 @@
1 using SpaceEngineersBlueprintEditor.Model;
2 using VRage.Game;
3
4 namespace SpaceEngineersBlueprintEditor.Utilities.Selector;
5
6 public partial class ShipBlueprintItemTemplateSelector : DataTemplateSelector
7 {
8 public DataTemplate? DefaultTemplate { get; set; }
9 public DataTemplate? CubeItemTemplate { get; set; }
10 public DataTemplate? GridItemTemplate { get; set; }
11 public DataTemplate? ObjectItemTemplate { get; set; }
12 public DataTemplate? EnumerableTemplate { get; set; }
13 public DataTemplate? ValueItemTemplate { get; set; }
14
15 protected override DataTemplate? SelectTemplateCore(object item)
16 {
17 if (item is TreeViewNode treeViewNode && treeViewNode.Content is BlueprintPropertyViewData blueprintPropertyViewData)
18 {
19 if (blueprintPropertyViewData.IsBasicType)
20 return ValueItemTemplate;
21 else if (blueprintPropertyViewData.IsEnumerable)
22 return EnumerableTemplate;
23 else if (blueprintPropertyViewData.Type is not null)
24 {
25 if (blueprintPropertyViewData.Type.IsAssignableTo(typeof(MyObjectBuilder_CubeBlock)))
26 return CubeItemTemplate;
27 else if (blueprintPropertyViewData.Type.IsAssignableTo(typeof(MyObjectBuilder_CubeGrid)))
28 return GridItemTemplate;
29 else
30 return ObjectItemTemplate;
31 }
32 else
33 return ObjectItemTemplate;
34 }
35 return DefaultTemplate;
36 }
37 }
Modified SpaceEngineersBlueprintEditor/ViewModels/BlueprintDetailPageViewModel.cs +6 -2
Modified SpaceEngineersBlueprintEditor/ViewModels/BlueprintEditPageViewModel.cs +143 -6
Modified SpaceEngineersBlueprintEditor/ViewModels/BlueprintsViewPageViewModel.cs +2 -1
Modified SpaceEngineersBlueprintEditor/Views/AppShellPage.xaml.cs +2 -1
Modified SpaceEngineersBlueprintEditor/Views/BlueprintDetailPage.xaml.cs +2 -1
Modified SpaceEngineersBlueprintEditor/Views/BlueprintEditPage.xaml +126 -1
Modified SpaceEngineersBlueprintEditor/Views/BlueprintEditPage.xaml.cs +45 -3
Modified SpaceEngineersBlueprintEditor/Views/BlueprintsViewPage.xaml +1 -1
Modified SpaceEngineersBlueprintEditor/Views/BlueprintsViewPage.xaml.cs +1 -0