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

SpaceEngineersModDev/SpaceEngineersBlueprintEditorInWinUI

完善材料计算功能

2416f37
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

11 个文件 +88 -50
Modified SpaceEngineersBlueprintEditor/App.xaml +1 -0
@@ -10,6 +10,7 @@
10 10 <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
11 11 <!-- Other merged dictionaries here -->
12 12 <ResourceDictionary Source="/Styles/Thickness.xaml" />
13 <ResourceDictionary Source="/Styles/Controls.xaml" />
13 14 </ResourceDictionary.MergedDictionaries>
14 15 <!-- Other app resources here -->
15 16 </ResourceDictionary>
Modified SpaceEngineersBlueprintEditor/Implements/Services/DefinitionPropertiesDisplayService.cs +2 -19
@@ -1,10 +1,8 @@
1 using Microsoft.UI.Xaml.Media;
2 using SpaceEngineersBlueprintEditor.Interface.Services;
1 using SpaceEngineersBlueprintEditor.Interface.Services;
3 2 using SpaceEngineersBlueprintEditor.Model;
4 3 using System.Collections.ObjectModel;
5 4 using System.Diagnostics.CodeAnalysis;
6 5 using Windows.Foundation;
7 using XFEExtension.NetCore.StringExtension;
8 6
9 7 namespace SpaceEngineersBlueprintEditor.Implements.Services;
10 8
@@ -12,8 +10,6 @@ internal class DefinitionPropertiesDisplayService<T> : IDefinitionPropertiesDisp
12 10 {
13 11 private ItemsView? _itemsView;
14 12 private Page? _page;
15 private bool needToTrig = false;
16 private int currentTrigger = 0;
17 13 public bool IsPageLoaded => _page is not null && _page.IsLoaded;
18 14 public event TypedEventHandler<ItemsView, ItemsViewSelectionChangedEventArgs>? SelectionChanged;
19 15
@@ -22,15 +18,7 @@ internal class DefinitionPropertiesDisplayService<T> : IDefinitionPropertiesDisp
22 18 {
23 19 _page = page;
24 20 _itemsView = itemsView;
25 _itemsView.SelectionChanged += (sender, args) => SelectionChanged?.Invoke(sender, args); ;
26 _page.Loaded += Page_Loaded;
27 }
28
29 private void Page_Loaded(object sender, RoutedEventArgs e)
30 {
31 if (needToTrig)
32 _itemsView?.Select(currentTrigger);
33 needToTrig = false;
21 _itemsView.SelectionChanged += (sender, args) => SelectionChanged?.Invoke(sender, args);
34 22 }
35 23
36 24 public void Select(T item)
@@ -40,10 +28,5 @@ internal class DefinitionPropertiesDisplayService<T> : IDefinitionPropertiesDisp
40 28 {
41 29 _itemsView.Select(itemSource.IndexOf(item));
42 30 }
43 else
44 {
45 needToTrig = true;
46 currentTrigger = itemSource.IndexOf(item);
47 }
48 31 }
49 32 }
Modified SpaceEngineersBlueprintEditor/Model/PropertyViewData.cs +2 -0
@@ -6,4 +6,6 @@ public class PropertyViewData
6 6 public object? Value { get; set; }
7 7 public bool IsValueType { get; set; }
8 8 public bool IsNotValueType => !IsValueType;
9 public bool HasValue => Value is not null;
10 public bool HasNoValue => Value is null;
9 11 }
Modified SpaceEngineersBlueprintEditor/SpaceEngineersBlueprintEditor.csproj +8 -0
@@ -16,6 +16,9 @@
16 16 <ApplicationIcon>Assets\Icons\EditorIcon.ico</ApplicationIcon>
17 17 </PropertyGroup>
18 18 <ItemGroup>
19 <Content Include="Styles\Controls.xaml">
20 <Generator>MSBuild:Compile</Generator>
21 </Content>
19 22 <Content Include="Styles\Thickness.xaml">
20 23 <Generator>MSBuild:Compile</Generator>
21 24 </Content>
@@ -28,9 +31,14 @@
28 31 </ItemGroup>
29 32
30 33 <ItemGroup>
34 <None Remove="Styles\Controls.xaml" />
31 35 <None Remove="Views\GameDefinitionsViewPage.xaml" />
32 36 </ItemGroup>
33 37
38 <ItemGroup>
39 <Page Remove="Styles\Controls.xaml" />
40 </ItemGroup>
41
34 42 <ItemGroup>
35 43 <Manifest Include="$(ApplicationManifest)" />
36 44 </ItemGroup>
Added SpaceEngineersBlueprintEditor/Styles/Controls.xaml +17 -0
@@ -0,0 +1,17 @@
1 <?xml version="1.0" encoding="utf-8"?>
2 <ResourceDictionary
3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
5 <DataTemplate x:Key="ComponentDataTemplate">
6 <ItemContainer Width="100" Height="100" Margin="4" ToolTipService.ToolTip="{Binding DefinitionBase.DisplayNameText}">
7 <Grid RowDefinitions="60, Auto" Padding="5">
8 <Image Source="{Binding ImageSource}" Width="60" Height="60" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center"/>
9 <TextBlock Grid.Row="1" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" HorizontalAlignment="Center" VerticalAlignment="Bottom" Text="{Binding DefinitionBase.DisplayNameText}"/>
10 <Grid HorizontalAlignment="Right" CornerRadius="4" VerticalAlignment="Top" Padding="1" Visibility="{Binding HasAdditionalInfo}" Background="{ThemeResource AccentFillColorDefaultBrush}">
11 <TextBlock Text="{Binding AdditionalInfo}" FontSize="12" Foreground="{ThemeResource TextOnAccentFillColorPrimaryBrush}"/>
12 </Grid>
13 <FontIcon HorizontalAlignment="Right" VerticalAlignment="Top" Glyph="{Binding CubeSize}" Visibility="{Binding HasCubeSize}"/>
14 </Grid>
15 </ItemContainer>
16 </DataTemplate>
17 </ResourceDictionary>
Modified SpaceEngineersBlueprintEditor/Utilities/Helpers/Extensions.cs +0 -1
@@ -1,7 +1,6 @@
1 1 using Microsoft.UI.Xaml.Media.Imaging;
2 2 using Microsoft.Windows.ApplicationModel.Resources;
3 3 using SpaceEngineersBlueprintEditor.Model;
4 using VRage.Game;
5 4
6 5 namespace SpaceEngineersBlueprintEditor.Utilities.Helpers;
7 6
Modified SpaceEngineersBlueprintEditor/Utilities/Helpers/SpaceEngineersHelper.cs +2 -0
@@ -38,6 +38,8 @@ public static class SpaceEngineersHelper
38 38 LoadComplete?.Invoke(null, EventArgs.Empty);
39 39 }
40 40
41 public static MyDefinitionBase? GetDefinition(int m_hash) => AllDefinitions.First(definition => definition.Id.SubtypeId.m_hash == m_hash);
42
41 43 public static string? GetGameRootPath()
42 44 {
43 45 var path = GetGameRootPath(@"C:\", @"D:\", @"E:\", @"F:\", @"G:\", @"H:\", @"I:\", @"J:\", @"K:\", @"L:\", @"M:\", @"N:\", @"O:\", @"P:\", @"Q:\", @"R:\", @"S:\", @"T:\", @"U:\", @"V:\", @"W:\", @"X:\", @"Y:\", @"Z:\");
Modified SpaceEngineersBlueprintEditor/ViewModels/BlueprintDetailPageViewModel.cs +32 -2
@@ -1,6 +1,6 @@
1 1 using CommunityToolkit.Mvvm.ComponentModel;
2 2 using CommunityToolkit.Mvvm.Input;
3 using Microsoft.UI.Xaml.Media;
3 using Microsoft.UI.Xaml.Media.Imaging;
4 4 using Sandbox.Definitions;
5 5 using SpaceEngineersBlueprintEditor.Implements.Services;
6 6 using SpaceEngineersBlueprintEditor.Interface.Services;
@@ -38,6 +38,7 @@ public partial class BlueprintDetailPageViewModel : ViewModelBase
38 38 private readonly IMessageService? messageService = GlobalServiceManager.GetService<IMessageService>();
39 39 public ObservableCollection<string> DLCList { get; } = [];
40 40 public ObservableCollection<CubeGridInfo> CubeGridList { get; } = [];
41 public ObservableCollection<DefinitionViewData> ComponentList { get; } = [];
41 42 public IBackgroundImageService? BackgroundImageService { get; set; } = GlobalServiceManager.GetService<IBackgroundImageService>();
42 43 public INavigationParameterService<BlueprintInfoViewData> NavigationParameterService { get; set; } = new NavigationParameterService<BlueprintInfoViewData>();
43 44 public BlueprintDetailPageViewModel() => NavigationParameterService.ParameterChange += NavigationParameterService_ParameterChange;
@@ -54,6 +55,7 @@ public partial class BlueprintDetailPageViewModel : ViewModelBase
54 55 TotalCubeNumber = "方块总数:加载中...";
55 56 DLCList.Clear();
56 57 CubeGridList.Clear();
58 ComponentList.Clear();
57 59 IsProgressRingVisible = true;
58 60 if (navigationViewService is not null) navigationViewService.Header = e.Name;
59 61 currentBlueprintInfoViewData = e;
@@ -65,7 +67,7 @@ public partial class BlueprintDetailPageViewModel : ViewModelBase
65 67 IsProgressRingVisible = false;
66 68 return;
67 69 }
68 await Task.Delay(100);
70 while (!SpaceEngineersHelper.IsLoadComplete) await Task.Delay(100);
69 71 await Task.Run(() =>
70 72 {
71 73 currentDefinitions = SpaceEngineerDefinitions.Load<MyObjectBuilder_Definitions>(e.FilePath);
@@ -98,6 +100,34 @@ public partial class BlueprintDetailPageViewModel : ViewModelBase
98 100 totalCubeCount += grid.CubeBlocks.Count;
99 101 CubeGridList.Add(new($"网格名称:{grid.DisplayName}", $"方块数量:{grid.CubeBlocks.Count}"));
100 102 }
103 var cubeHashDictionary = new Dictionary<int, int>();
104 var componentDictionary = new Dictionary<MyComponentDefinition, int>();
105 currentBlueprint.CubeGrids.ForEach(grid => grid.CubeBlocks.ForEach(cube =>
106 {
107 if (cubeHashDictionary.TryGetValue(cube.SubtypeId.m_hash, out int value))
108 cubeHashDictionary[cube.SubtypeId.m_hash] = ++value;
109 else
110 cubeHashDictionary.TryAdd(cube.SubtypeId.m_hash, 1);
111 }));
112 cubeHashDictionary.ForEach(cubeHashEntry =>
113 {
114 if (SpaceEngineersHelper.GetDefinition(cubeHashEntry.Key) is MyCubeBlockDefinition definition && definition is not null && definition.Components is not null && definition.Components.Length > 0)
115 {
116 definition.Components.ForEach(component =>
117 {
118 if (componentDictionary.ContainsKey(component.Definition))
119 componentDictionary[component.Definition] += component.Count * cubeHashEntry.Value;
120 else
121 componentDictionary.TryAdd(component.Definition, component.Count * cubeHashEntry.Value);
122 });
123 }
124 });
125 componentDictionary.ForEach(componentEntry => ComponentList.Add(new()
126 {
127 DefinitionBase = componentEntry.Key,
128 AdditionalInfo = $"x{componentEntry.Value}",
129 ImageSource = componentEntry.Key.Icons is not null && componentEntry.Key.Icons.Length > 0 ? new BitmapImage(new(@$"{AppPath.DefinitionImages}\{FileHelper.ChangeExtension(componentEntry.Key.Icons[0], "png")}")) : null
130 }));
101 131 TotalCubeNumber = $"方块总数:{totalCubeCount}";
102 132 TotalGridNumber = $"网格总数:{currentBlueprint.CubeGrids.Length}";
103 133 }
Modified SpaceEngineersBlueprintEditor/ViewModels/GameDefinitionsViewPageViewModel.cs +15 -12
@@ -8,7 +8,6 @@ using SpaceEngineersBlueprintEditor.SpaceEngineersCore;
8 8 using SpaceEngineersBlueprintEditor.Utilities;
9 9 using System.Collections.ObjectModel;
10 10 using VRage.Game;
11 using XFEExtension.NetCore.StringExtension;
12 11
13 12 namespace SpaceEngineersBlueprintEditor.ViewModels;
14 13
@@ -21,6 +20,8 @@ public partial class GameDefinitionsViewPageViewModel : ViewModelBase
21 20 [ObservableProperty]
22 21 private bool isProgressRingVisible = true;
23 22 [ObservableProperty]
23 private bool isUIVisible = false;
24 [ObservableProperty]
24 25 private DefinitionViewData? selectedDefinitionViewData;
25 26 private string currentParameter = "";
26 27 private readonly List<DefinitionViewData> _definitions = [];
@@ -42,31 +43,33 @@ public partial class GameDefinitionsViewPageViewModel : ViewModelBase
42 43 {
43 44 SelectedDefinitionViewData = definitionViewData;
44 45 PropertiesInfo.Clear();
46 _propertiesInfo.Clear();
45 47 foreach (var definition in SelectedDefinitionViewData.DefinitionBase.GetType().GetFields())
46 48 {
47 49 if (definition.GetValue(SelectedDefinitionViewData.DefinitionBase) is object value)
48 50 {
49 51 var valueString = value.ToString();
52 var isValueType = value.GetType().IsValueType || value.GetType().IsEnum || value.GetType() == typeof(string);
50 53 var propertyViewData = new PropertyViewData
51 54 {
52 55 PropertyName = definition.Name,
53 Value = string.IsNullOrWhiteSpace(valueString) ? "值为空" : valueString,
54 IsValueType = value.GetType().IsValueType
56 Value = string.IsNullOrWhiteSpace(valueString) ? isValueType ? "空值" : "空对象" : valueString,
57 IsValueType = isValueType
55 58 };
56 59 _propertiesInfo.Add(propertyViewData);
57 PropertiesInfo.Add(propertyViewData);
58 60 }
59 61 }
62 OnPropertiesSearchTextChanged(PropertiesSearchText);
60 63 }
61 64 }
62 65
63 66 private async void NavigationParameterService_ParameterChange(object? sender, string e)
64 67 {
65 68 currentParameter = e;
66 while (!Initializer.IsDefinitionsLoadComplete) { await Task.Delay(100); }
69 while (!Initializer.IsDefinitionsLoadComplete || !DefinitionPropertiesDisplayService.IsPageLoaded) { await Task.Delay(100); }
67 70 LoadDefinitions(GetCurrentDefinitions(currentParameter));
71 IsUIVisible = true;
68 72 IsProgressRingVisible = false;
69 while (!DefinitionPropertiesDisplayService.IsPageLoaded) { await Task.Delay(100); }
70 73 DefinitionPropertiesDisplayService.Select(Definitions.First());
71 74 }
72 75
@@ -86,16 +89,16 @@ public partial class GameDefinitionsViewPageViewModel : ViewModelBase
86 89 }
87 90 }
88 91
89 private IEnumerable<DefinitionViewData> SearchDefinitions(string definitionsName) => _definitions.Where(definition => definition.DefinitionBase.DisplayNameText is not null && definition.DefinitionBase.DisplayNameText.Contains(definitionsName, StringComparison.OrdinalIgnoreCase));
92 private IEnumerable<DefinitionViewData> SearchDefinitions(string definitionsName) => _definitions.Where(definition => definition.DefinitionBase.DisplayNameText is not null && definition.DefinitionBase.DisplayNameText.Contains(definitionsName, StringComparison.OrdinalIgnoreCase)).OrderBy(definition => definition.DefinitionBase.DisplayNameText);
90 93
91 private IEnumerable<PropertyViewData> SearchProperties(string propertiesName) => _propertiesInfo.Where(property => property.PropertyName.Contains(propertiesName, StringComparison.OrdinalIgnoreCase) || (property.Value is not null && property.Value.ToString() is string valueString && valueString.Contains(propertiesName, StringComparison.OrdinalIgnoreCase)));
94 private IEnumerable<PropertyViewData> SearchProperties(string propertiesName) => _propertiesInfo.Where(property => property.PropertyName.Contains(propertiesName, StringComparison.OrdinalIgnoreCase) || (property.Value is not null && property.Value.ToString() is string valueString && valueString.Contains(propertiesName, StringComparison.OrdinalIgnoreCase))).OrderBy(property => property.PropertyName);
92 95
93 96 private static IEnumerable<MyDefinitionBase> GetCurrentDefinitions(string currentLocation) => currentLocation switch
94 97 {
95 "Cubes" => SpaceEngineersHelper.CubeBlockDefinitions.OrderBy(definition => definition.CubeSize),
96 "Components" => SpaceEngineersHelper.ComponentDefinitions,
97 "Items" => SpaceEngineersHelper.ItemDefinitions,
98 "Scenarios" => SpaceEngineersHelper.ScenarioDefinition,
98 "Cubes" => SpaceEngineersHelper.CubeBlockDefinitions.OrderBy(definition => definition.DisplayNameText),
99 "Components" => SpaceEngineersHelper.ComponentDefinitions.OrderBy(definition => definition.DisplayNameText),
100 "Items" => SpaceEngineersHelper.ItemDefinitions.OrderBy(definition => definition.DisplayNameText),
101 "Scenarios" => SpaceEngineersHelper.ScenarioDefinition.OrderBy(definition => definition.DisplayNameText),
99 102 _ => throw new NotImplementedException()
100 103 };
101 104
Modified SpaceEngineersBlueprintEditor/Views/BlueprintDetailPage.xaml +7 -0
@@ -41,6 +41,13 @@
41 41 <Expander Header="所需DLC列表" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
42 42 <ListView ItemsSource="{x:Bind ViewModel.DLCList, Mode=OneWay}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"/>
43 43 </Expander>
44 <Expander Header="所需材料" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
45 <ItemsView ItemsSource="{x:Bind ViewModel.ComponentList, Mode=OneWay}" Padding="4" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" ItemTemplate="{StaticResource ComponentDataTemplate}">
46 <ItemsView.Layout>
47 <UniformGridLayout Orientation="Horizontal"/>
48 </ItemsView.Layout>
49 </ItemsView>
50 </Expander>
44 51 <Expander HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
45 52 <Expander.Header>
46 53 <Grid ColumnDefinitions="*, Auto, Auto" ColumnSpacing="20">
Modified SpaceEngineersBlueprintEditor/Views/GameDefinitionsViewPage.xaml +2 -16
@@ -20,25 +20,11 @@
20 20 </StackPanel>
21 21 </Grid>
22 22 </Grid>
23 <Grid ColumnDefinitions="8*, 3*" RowSpacing="20">
24 <ItemsView x:Name="definitionsItemView" Canvas.ZIndex="0" Padding="4" ItemsSource="{x:Bind ViewModel.Definitions}">
23 <Grid ColumnDefinitions="8*, 3*" RowSpacing="20" Visibility="{x:Bind ViewModel.IsUIVisible, Mode=OneWay}">
24 <ItemsView x:Name="definitionsItemView" Canvas.ZIndex="0" Padding="4" ItemsSource="{x:Bind ViewModel.Definitions}" ItemTemplate="{StaticResource ComponentDataTemplate}">
25 25 <ItemsView.Layout>
26 26 <UniformGridLayout Orientation="Horizontal" />
27 27 </ItemsView.Layout>
28 <ItemsView.ItemTemplate>
29 <DataTemplate x:DataType="model:DefinitionViewData">
30 <ItemContainer Width="100" Height="100" Margin="4" ToolTipService.ToolTip="{x:Bind DefinitionBase.DisplayNameText}">
31 <Grid RowDefinitions="60, Auto" Padding="5">
32 <Image Source="{x:Bind ImageSource}" Width="60" Height="60" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center"/>
33 <TextBlock Grid.Row="1" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" HorizontalAlignment="Center" VerticalAlignment="Bottom" Text="{x:Bind DefinitionBase.DisplayNameText}"/>
34 <Grid HorizontalAlignment="Right" CornerRadius="4" VerticalAlignment="Top" Padding="1" Visibility="{x:Bind HasAdditionalInfo}" Background="{ThemeResource AccentFillColorDefaultBrush}">
35 <TextBlock Text="{x:Bind AdditionalInfo}" FontSize="12" Foreground="{ThemeResource TextOnAccentFillColorPrimaryBrush}"/>
36 </Grid>
37 <FontIcon HorizontalAlignment="Right" VerticalAlignment="Top" Glyph="{x:Bind CubeSize}" Visibility="{x:Bind HasCubeSize}"/>
38 </Grid>
39 </ItemContainer>
40 </DataTemplate>
41 </ItemsView.ItemTemplate>
42 28 </ItemsView>
43 29 <Grid Grid.Column="1" Margin="0,0,0,24" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" CornerRadius="8">
44 30 <Grid RowDefinitions="Auto, Auto, *">