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

SpaceEngineersModDev/SpaceEngineersBlueprintEditorInWinUI

添加SettingService服务

740f7c7
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

23 个文件 +324 -232
Renamed SpaceEngineersBlueprintEditor/Implements/Services/NavigationService.cs +1 -1
@@ -1,7 +1,7 @@
1 1 using SpaceEngineersBlueprintEditor.Interface.Services;
2 2 using SpaceEngineersBlueprintEditor.Utilities;
3 3
4 namespace SpaceEngineersBlueprintEditor.Services;
4 namespace SpaceEngineersBlueprintEditor.Implements.Services;
5 5
6 6 internal class NavigationService : INavigationService
7 7 {
Renamed SpaceEngineersBlueprintEditor/Implements/Services/NavigationViewService.cs +1 -1
@@ -1,7 +1,7 @@
1 1 using SpaceEngineersBlueprintEditor.Interface.Services;
2 2 using SpaceEngineersBlueprintEditor.Utilities;
3 3
4 namespace SpaceEngineersBlueprintEditor.Services;
4 namespace SpaceEngineersBlueprintEditor.Implements.Services;
5 5
6 6 internal class NavigationViewService : INavigationViewService
7 7 {
Added SpaceEngineersBlueprintEditor/Implements/Services/SettingService.cs +41 -0
@@ -0,0 +1,41 @@
1 using SpaceEngineersBlueprintEditor.Interface;
2 using SpaceEngineersBlueprintEditor.Interface.Services;
3 using SpaceEngineersBlueprintEditor.Model;
4
5 namespace SpaceEngineersBlueprintEditor.Implements.Services;
6
7 internal class SettingService : ISettingService
8 {
9 private readonly Dictionary<object, IProfileInfoEntry> settingControls = [];
10
11 public Dictionary<object, IProfileInfoEntry> SettingControls => settingControls;
12
13 public void AddComboBox(ComboBox comboBox, Func<string, object?> saveFunc, Func<List<object>, object?, object?> loadFunc)
14 {
15 if (comboBox.Tag is string profilePath)
16 settingControls.Add(comboBox, new ComboBoxProfileInfoEntry(profilePath, saveFunc, loadFunc));
17 else
18 throw new NullReferenceException();
19 }
20
21 private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
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)
24 ProfileHelper.SetProfileValue(comboBoxProfileInfo.ProfilePath, comboBoxProfileInfo.ProfileSaveFunc.Invoke(value));
25 }
26
27 public void Initialize()
28 {
29 foreach (var item in settingControls)
30 {
31 if (item.Key is ComboBox comboBox && item.Value is ComboBoxProfileInfoEntry comboBoxProfileInfo)
32 comboBox.SelectedItem = comboBoxProfileInfo.ProfileLoadFunc.Invoke([.. comboBox.Items], ProfileHelper.GetProfileValue(comboBoxProfileInfo.ProfilePath));
33 }
34 }
35
36 public void RegisterEvents()
37 {
38 foreach (var comboBox in settingControls.Keys.Where(control => control is ComboBox).Cast<ComboBox>())
39 comboBox.SelectionChanged += ComboBox_SelectionChanged;
40 }
41 }
Added SpaceEngineersBlueprintEditor/Interface/IProfileInfoEntry.cs +6 -0
@@ -0,0 +1,6 @@
1 namespace SpaceEngineersBlueprintEditor.Interface;
2
3 public interface IProfileInfoEntry
4 {
5 string ProfilePath { get; }
6 }
Added SpaceEngineersBlueprintEditor/Interface/Services/ISettingService.cs +9 -0
@@ -0,0 +1,9 @@
1 namespace SpaceEngineersBlueprintEditor.Interface.Services;
2
3 public interface ISettingService
4 {
5 Dictionary<object, IProfileInfoEntry> SettingControls { get; }
6 void AddComboBox(ComboBox comboBox, Func<string, object?> saveFunc, Func<List<object>, object?, object?> loadFunc);
7 void Initialize();
8 void RegisterEvents();
9 }
Modified SpaceEngineersBlueprintEditor/MainWindow.xaml.cs +1 -4
@@ -1,10 +1,7 @@
1 // To learn more about WinUI, the WinUI project structure,
2 // and more about our project templates, see: http://aka.ms/winui-project-info.
3
4 1 namespace SpaceEngineersBlueprintEditor;
5 2
6 3 /// <summary>
7 /// An empty window that can be used on its own or navigated to within a Frame.
4 /// ������
8 5 /// </summary>
9 6 public sealed partial class MainWindow : Window
10 7 {
Added SpaceEngineersBlueprintEditor/Model/ComboBoxProfileInfoEntry.cs +5 -0
@@ -0,0 +1,5 @@
1 using SpaceEngineersBlueprintEditor.Interface;
2
3 namespace SpaceEngineersBlueprintEditor.Model;
4
5 public record class ComboBoxProfileInfoEntry(string ProfilePath, Func<string, object?> ProfileSaveFunc, Func<List<object>, object?, object?> ProfileLoadFunc) : IProfileInfoEntry { }
Added SpaceEngineersBlueprintEditor/Profiles/CacheProfiles/AppCacheProfile.cs +11 -0
@@ -0,0 +1,11 @@
1 using SpaceEngineersBlueprintEditor.Utilities;
2 using XFEExtension.NetCore.AutoConfig;
3
4 namespace SpaceEngineersBlueprintEditor.Profiles.CacheProfiles;
5
6 public partial class AppCacheProfile
7 {
8 public AppCacheProfile() => ProfilePath = @$"{AppPath.CacheProfile}\{typeof(AppCacheProfile)}.xpf";
9 [ProfileProperty]
10 private string cacheText = "";
11 }
Added SpaceEngineersBlueprintEditor/Profiles/CrossVersionProfiles/SystemProfile.cs +16 -0
@@ -0,0 +1,16 @@
1 using SpaceEngineersBlueprintEditor.Utilities;
2 using XFEExtension.NetCore.AutoConfig;
3
4 namespace SpaceEngineersBlueprintEditor.Profiles.CrossVersionProfiles;
5
6 public partial class SystemProfile
7 {
8 SystemProfile() => ProfilePath = $@"{AppPath.LocalProfile}\{nameof(SystemProfile)}.xpf";
9 [ProfileProperty]
10 private ElementTheme theme = ElementTheme.Default;
11
12 static partial void SetThemeProperty(ElementTheme value)
13 {
14 AppThemeHelper.ChangeTheme(value);
15 }
16 }
Deleted SpaceEngineersBlueprintEditor/Profiles/SystemProfile.cs +0 -9
@@ -1,9 +0,0 @@
1 using XFEExtension.NetCore.AutoConfig;
2
3 namespace SpaceEngineersBlueprintEditor.Profiles;
4
5 public partial class SystemProfile
6 {
7 [ProfileProperty]
8 private ElementTheme theme;
9 }
Modified SpaceEngineersBlueprintEditor/SpaceEngineersBlueprintEditor.csproj +6 -0
@@ -72,6 +72,8 @@
72 72 <ItemGroup>
73 73 <Using Include="Microsoft.UI.Xaml" />
74 74 <Using Include="Microsoft.UI.Xaml.Controls" />
75 <Using Include="SpaceEngineersBlueprintEditor.Profiles.CacheProfiles" />
76 <Using Include="SpaceEngineersBlueprintEditor.Profiles.CrossVersionProfiles" />
75 77 <Using Include="SpaceEngineersBlueprintEditor.Utilities.Helpers" />
76 78 </ItemGroup>
77 79 <ItemGroup>
@@ -85,6 +87,10 @@
85 87 <Generator>MSBuild:Compile</Generator>
86 88 </Page>
87 89 </ItemGroup>
90 <ItemGroup>
91 <Folder Include="Profiles\CurrentVersionProfiles\" />
92 <Folder Include="Profiles\SynProfiles\" />
93 </ItemGroup>
88 94
89 95 <!--
90 96 Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
Modified SpaceEngineersBlueprintEditor/Strings/en-us/Resources.resw +58 -16
@@ -117,58 +117,100 @@
117 117 <resheader name="writer">
118 118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119 119 </resheader>
120 <data name="ShellItem_EditorPage.Content" xml:space="preserve">
120 <data name="AppShell_ShellItem_EditorPage.Content" xml:space="preserve">
121 121 <value>Edit Blueprint</value>
122 <comment>编辑蓝图</comment>
122 123 </data>
123 <data name="ShellMenu_ViewBlurprints.Content" xml:space="preserve">
124 <data name="AppShell_ShellMenu_ViewBlurprints.Content" xml:space="preserve">
124 125 <value>View Blueprints</value>
126 <comment>查看蓝图列表</comment>
125 127 </data>
126 <data name="ShellItem_ViewLocalBlueprints.Content" xml:space="preserve">
128 <data name="AppShell_ShellItem_ViewLocalBlueprints.Content" xml:space="preserve">
127 129 <value>Local Blueprints</value>
130 <comment>本地蓝图</comment>
128 131 </data>
129 <data name="ShellItem_AppSetting.Content" xml:space="preserve">
132 <data name="AppShell_ShellItem_AppSetting.Content" xml:space="preserve">
130 133 <value>Setting</value>
134 <comment>设置</comment>
131 135 </data>
132 <data name="ShellItem_ViewWorkshopBlueprints.Content" xml:space="preserve">
136 <data name="AppShell_ShellItem_ViewWorkshopBlueprints.Content" xml:space="preserve">
133 137 <value>Workshop Blueprints</value>
138 <comment>工坊蓝图</comment>
134 139 </data>
135 <data name="ShellItem_ViewCloudBlueprints.Content" xml:space="preserve">
140 <data name="AppShell_ShellItem_ViewCloudBlueprints.Content" xml:space="preserve">
136 141 <value>Cloud Blueprints</value>
142 <comment>云端蓝图</comment>
137 143 </data>
138 144 <data name="AppDisplayName" xml:space="preserve">
139 145 <value>SpaceEngineersBlueprintEditor</value>
146 <comment>太空工程师蓝图修改器</comment>
140 147 </data>
141 148 <data name="DragFileToEditorText" xml:space="preserve">
142 149 <value>Drag Blueprint Here</value>
150 <comment>拖动蓝图文件至此处</comment>
143 151 </data>
144 <data name="AppInfo_Author.Header" xml:space="preserve">
152 <data name="SettingPage_AppInfo_Author.Header" xml:space="preserve">
145 153 <value>Author</value>
154 <comment>作者</comment>
146 155 </data>
147 <data name="AppInfo_Contact.Header" xml:space="preserve">
156 <data name="SettingPage_AppInfo_Contact.Header" xml:space="preserve">
148 157 <value>Contact Us</value>
158 <comment>联系我们</comment>
149 159 </data>
150 <data name="AppInfo_Expander.Description" xml:space="preserve">
160 <data name="SettingPage_AppInfo_Expander.Description" xml:space="preserve">
151 161 <value>CopyRight © 2024 XFEstudio. All rights reserved.</value>
162 <comment>版权所有 © 2024 XFEstudio. All rights reserved.</comment>
152 163 </data>
153 <data name="AppInfo_Expander.Header" xml:space="preserve">
164 <data name="SettingPage_AppInfo_Expander.Header" xml:space="preserve">
154 165 <value>SpaceEngineers Blueprint Editor</value>
166 <comment>太空工程师蓝图修改器</comment>
155 167 </data>
156 <data name="AppInfo_GithubProject.Header" xml:space="preserve">
168 <data name="SettingPage_AppInfo_GithubProject.Header" xml:space="preserve">
157 169 <value>Github Repo</value>
170 <comment>Github仓库</comment>
158 171 </data>
159 <data name="AppInfo_Contact_Bilibili.Content" xml:space="preserve">
172 <data name="SettingPage_AppInfo_Contact_Bilibili.Content" xml:space="preserve">
160 173 <value>Bilibili</value>
174 <comment>哔哩哔哩</comment>
161 175 </data>
162 <data name="AppInfo_Contact_Github.Content" xml:space="preserve">
176 <data name="SettingPage_AppInfo_Contact_Github.Content" xml:space="preserve">
163 177 <value>Github</value>
178 <comment>Github</comment>
164 179 </data>
165 <data name="AppInfo_Contact_QQ.Content" xml:space="preserve">
180 <data name="SettingPage_AppInfo_Contact_QQ.Content" xml:space="preserve">
166 181 <value>SpaceEnginners Group</value>
182 <comment>太空工程师交流群</comment>
167 183 </data>
168 <data name="AppInfo_Contact_Twitter.Content" xml:space="preserve">
184 <data name="SettingPage_AppInfo_Contact_Twitter.Content" xml:space="preserve">
169 185 <value>Twitter(X)</value>
186 <comment>推特(X)</comment>
170 187 </data>
171 <data name="AppInfo_Contact_Youtube.Content" xml:space="preserve">
188 <data name="SettingPage_AppInfo_Contact_Youtube.Content" xml:space="preserve">
172 189 <value>Youtube</value>
190 <comment>油管</comment>
191 </data>
192 <data name="AppShell_AppTitle.Text" xml:space="preserve">
193 <value>SpaceEngineers Blueprint Editor</value>
194 <comment>太空工程师蓝图修改器</comment>
195 </data>
196 <data name="SettingPage_AppTheme.Header" xml:space="preserve">
197 <value>App theme</value>
198 <comment>色彩模式</comment>
199 </data>
200 <data name="SettingPage_AppTheme.Description" xml:space="preserve">
201 <value>The app theme to display</value>
202 <comment>编辑器显示的颜色主题</comment>
203 </data>
204 <data name="SettingPage_AppTheme_Light.Content" xml:space="preserve">
205 <value>Light</value>
206 <comment>浅色</comment>
207 </data>
208 <data name="SettingPage_AppTheme_Default.Content" xml:space="preserve">
209 <value>Use system setting</value>
210 <comment>跟随系统</comment>
211 </data>
212 <data name="SettingPage_AppTheme_Dark.Content" xml:space="preserve">
213 <value>Dark</value>
214 <comment>深色</comment>
173 215 </data>
174 216 </root>
Deleted SpaceEngineersBlueprintEditor/Strings/zh-cn/Resources.resw +0 -174
Added SpaceEngineersBlueprintEditor/Utilities/Helpers/AppThemeHelper.cs +58 -0
Added SpaceEngineersBlueprintEditor/Utilities/Helpers/ProfileHelper.cs +72 -0
Modified SpaceEngineersBlueprintEditor/ViewModels/AppShellPageViewModel.cs +1 -1
Modified SpaceEngineersBlueprintEditor/ViewModels/SettingPageViewModel.cs +7 -1
Modified SpaceEngineersBlueprintEditor/Views/AppShellPage.xaml +7 -7
Modified SpaceEngineersBlueprintEditor/Views/AppShellPage.xaml.cs +1 -1
Modified SpaceEngineersBlueprintEditor/Views/BlueprintEditorPage.xaml.cs +1 -1
Modified SpaceEngineersBlueprintEditor/Views/BlueprintsViewPage.xaml.cs +1 -1
Modified SpaceEngineersBlueprintEditor/Views/SettingPage.xaml +17 -14
Modified SpaceEngineersBlueprintEditor/Views/SettingPage.xaml.cs +4 -1