Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SettingsManager.cs
浏览该文件的文档.
1using System.Reflection;
2using System.Text;
3using System.Xml.Linq;
4using Engine;
6using Engine.Input;
8using XmlUtilities;
9
10namespace Game {
11 public static class SettingsManager {
12 public static float m_soundsVolume;
13
14 public static float m_musicVolume;
15
16 public static float m_brightness;
17
19
20 public static WindowMode m_windowMode;
21
23
25
26 public static bool UsePrimaryMemoryBank { get; set; }
27
28 public static bool AllowInitialIntro { get; set; }
29 public static bool DeleteWorldNeedToText { get; set; }
30
31 public static bool CreativeDragMaxStacking { get; set; }
32
33 public static float Touchoffset { get; set; }
34
35 public const string fName = "SettingsManager";
36
37 public static float SoundsVolume {
38 get => m_soundsVolume;
39 set => m_soundsVolume = MathUtils.Saturate(value);
40 }
41
42 public static float MusicVolume {
43 get => m_musicVolume;
44 set => m_musicVolume = MathUtils.Saturate(value);
45 }
46
47 public static int VisibilityRange { get; set; }
48
49 public static bool UseVr { get; set; }
50
51 public static float UIScale { get; set; }
52
54 get => m_resolutionMode;
55 set {
56 if (value != m_resolutionMode) {
57 m_resolutionMode = value;
58 SettingChanged?.Invoke("ResolutionMode");
59 }
60 }
61 }
62
63 public static float ViewAngle { get; set; }
64
65 public static SkyRenderingMode SkyRenderingMode { get; set; }
66
67 public static bool TerrainMipmapsEnabled { get; set; }
68
69 public static bool ObjectsShadowsEnabled { get; set; }
70
71 public static float Brightness {
72 get => m_brightness;
73 set {
74 value = Math.Clamp(value, 0f, 1f);
75 if (value != m_brightness) {
76 m_brightness = value;
77 SettingChanged?.Invoke("Brightness");
78 }
79 }
80 }
81
82 public static int PresentationInterval { get; set; }
83
84 public static bool ShowGuiInScreenshots { get; set; }
85
86 public static bool ShowLogoInScreenshots { get; set; }
87
88 public static ScreenshotSize ScreenshotSize { get; set; }
89#pragma warning disable CS0649
91#pragma warning restore CS0649
92
94 get { return m_screenshotSizeCustom; }
95 set {
96 int max = Math.Min(Display.MaxTextureSize, 16384);
97 int width = MathUtils.Clamp(value.X, 120, max);
98 int height = MathUtils.Clamp(value.Y, 120, max);
99 value = new Point2(width, height);
100 }
101 }
102 public static int[] ScreenshotSizeCustomWidths = [
103 80,
104 160,
105 320,
106 480,
107 640,
108 800,
109 960,
110 1280,
111 1600,
112 1920, //default
113 2560,
114 3840,
115 5120,
116 6144,
117 7680,
118 10240,
119 12288,
120 15360
121 ];
123
126 set {
128 int widthMax = Math.Min(Display.MaxTextureSize, 16384);
130 value = ScreenshotSizeCustomWidths.GetLastIndexOfAnyInRange(0,widthMax);
131 }
132 }
133 }
134
135 private static int GetLastIndexOfAnyInRange(this int[] array,int minValue,int maxValue) {
136 for (int i = array.Length - 1; i >= 0; i--) {
137 if (array[i] >= minValue && array[i] <= maxValue)
138 return i;
139 }
140 return 0;
141 }
142
143 public static float[] ScreenshotSizeCustomAspectRatios = [
144 1f,
145 4f / 5f,
146 3f / 4f,
147 2f / 3f,
148 10f / 16f,
149 9f / 16f, //default
150 0.5f,
151 27f / 64f,
152 9f / 32f,
153 27f / 128f
154 ];
155
156 public static string[] ScreenshotSizeCustomAspectRatiosNames = [
157 "1:1",
158 "5:4",
159 "4:3",
160 "3:2",
161 "16:10",
162 "16:9",
163 "18:9",
164 "21:9",
165 "32:9",
166 "42:9"
167 ];
175
176 public static WindowMode WindowMode {
177#if BROWSER
178 get => Window.WindowMode;
179 set {
180 value = value == WindowMode.Fullscreen ? WindowMode.Fullscreen : WindowMode.Fixed;
181 Window.WindowMode = value;
182 m_windowMode = value;
183 }
184#else
185 get => m_windowMode;
186 set {
187 if (value != m_windowMode) {
188 if (value == WindowMode.Borderless) {
193 }
194 else if (value == WindowMode.Fullscreen
195 && m_windowMode != WindowMode.Borderless) {
198 }
199 Window.WindowMode = value;
200 m_windowMode = value;
201 if (value == WindowMode.Resizable) {
204 }
205 }
207 "WindowModeChanged",
208 loader => {
209 loader.WindowModeChanged(value);
210 return false;
211 }
212 );
213 }
214#endif
215 }
216
217 #region 简单设置项
218
219 public static GuiSize GuiSize { get; set; }
220
221 public static bool HideMoveLookPads { get; set; }
222
223 public static bool HideCrosshair { get; set; }
224
225 public static string BlocksTextureFileName { get; set; }
226
227 public static MoveControlMode MoveControlMode { get; set; }
228
229 public static LookControlMode LookControlMode { get; set; }
230
231 public static bool LeftHandedLayout { get; set; }
232
233 public static bool FlipVerticalAxis { get; set; }
234
235 public static float MoveSensitivity { get; set; }
236
237 public static float LookSensitivity { get; set; }
238
239 public static float GamepadDeadZone { get; set; }
240
241 public static float GamepadCursorSpeed { get; set; }
242
246 public static float GamepadTriggerThreshold { get; set; }
247
248 public static float CreativeDigTime { get; set; }
249
250 public static float CreativeReach { get; set; }
251
252 public static float MinimumHoldDuration { get; set; }
253
254 public static float MinimumDragDistance { get; set; }
255
256 public static bool AutoJump { get; set; }
257
258 public static bool HorizontalCreativeFlight { get; set; }
259
260 public static string DropboxAccessToken { get; set; }
261
262 public static string MotdUpdateUrl { get; set; }
263
264 public static string MotdUpdateCheckUrl { get; set; }
265 public static string ScpboxAccessToken { get; set; }
266
267 public static string ScpboxUserInfo { get; set; }
268
269 public static bool MotdUseBackupUrl { get; set; }
270
271 public static double MotdUpdatePeriodHours { get; set; }
272
273 public static DateTime MotdLastUpdateTime { get; set; }
274
275 public static string MotdLastDownloadedData { get; set; }
276
277 public static string UserId { get; set; }
278
279 public static string LastLaunchedVersion { get; set; }
280
281 public static CommunityContentMode CommunityContentMode { get; set; }
282
284
285 public static bool MultithreadedTerrainUpdate { get; set; }
286
287 public static int IsolatedStorageMigrationCounter { get; set; }
288
289 public static bool DisplayFpsCounter { get; set; }
290
291 public static bool DisplayFpsRibbon { get; set; }
292
293 public static int NewYearCelebrationLastYear { get; set; }
294
295 public static ScreenLayout ScreenLayout1 { get; set; }
296
297 public static ScreenLayout ScreenLayout2 { get; set; }
298
299 public static ScreenLayout ScreenLayout3 { get; set; }
300
301 public static ScreenLayout ScreenLayout4 { get; set; }
302
303 public static bool UpsideDownLayout { get; set; }
304
305 #endregion
306
307 public static bool FullScreenMode {
308 get => Window.WindowMode == WindowMode.Fullscreen;
309 set {
310 if (value && Window.WindowMode != WindowMode.Fullscreen) {
311 Window.WindowMode = WindowMode.Fullscreen;
312 }
313 else if (!value
314 && Window.WindowMode == WindowMode.Fullscreen) {
315 Window.WindowMode = WindowMode.Resizable;
316 }
317#if !BROWSER
319 "WindowModeChanged",
320 loader => {
321 loader.WindowModeChanged(WindowMode);
322 return false;
323 }
324 );
325#endif
326 }
327 }
328
329 public static bool DisplayLog { get; set; }
330
331 public static string BulletinTime { get; set; }
332
333 public static bool DragHalfInSplit { get; set; }
334
335 public static bool ShortInventoryLooping { get; set; }
336
337 public static float LowFPSToTimeDeceleration { get; set; }
338
339 public static bool UseAPISleepTimeAcceleration { get; set; }
340
341 public static float MoveWidgetMarginX { get; set; }
342 public static float MoveWidgetMarginY { get; set; }
343
344 [Obsolete("该变量目前尚未使用,有待后续API版本完善。后续完善后模组可能用到,为了向未来兼容别删")]
345 public static float MoveWidgetSize { get; set; }
346
347 public static int AnimatedTextureRefreshLimit { get; set; }
348
349 public static bool FileAssociationEnabled {
350 get {
351#if WINDOWS
352 return field;
353#elif ANDROID
354 return true;
355#else
356 return false;
357#endif
358 }
359 set {
360#if WINDOWS
361 field = value;
362#endif
363 }
364 }
365
366 public static string DisabledMods {
367 get {
368 List<string> result = [];
369 foreach ((string packageName, HashSet<string> versions) in ModsManager.DisabledMods) {
370 if (versions.Count == 0) {
371 continue;
372 }
373 result.Add(packageName);
374 result.Add(versions.Count.ToString());
375 foreach (string version in versions) {
376 result.Add(version);
377 }
378 }
379 return string.Join(";", result);
380 }
381 set {
382 if (string.IsNullOrEmpty(value)) {
383 return;
384 }
385 string[] array = value.Split(';');
386 Dictionary<string, HashSet<string>> result = [];
387 int i = 0;
388 while (i < array.Length) {
389 string packageName = array[i++];
390 if (int.TryParse(array[i++], out int count)) {
391 HashSet<string> versions = new(count);
392 int end = i + count;
393 while (i < end) {
394 versions.Add(array[i++]);
395 }
396 result.Add(packageName, versions);
397 }
398 }
400 }
401 }
402
403 public static bool SafeMode { get; set; }
404
405 public static bool AdaptEdgeToEdgeDisplay { get; set; }
406
407 public static event Action<string> SettingChanged;
408 public static ValuesDictionary KeyboardMappingSettings { get; set; }
409 public static ValuesDictionary GamepadMappingSettings { get; set; }
410 public static ValuesDictionary CameraManageSettings { get; set; }
411
412 public static string CommunityServerUserInfos {
413 get {
414 if (CommunityServerManager.UserInfos.Count == 0) {
415 return string.Empty;
416 }
417 List<string> results = [];
419 results.Add(info.ToString());
420 }
421 return string.Join("||", results);
422 }
423 set {
424 if (string.IsNullOrEmpty(value)) {
425 return;
426 }
427 string[] array1 = value.Split("||", StringSplitOptions.RemoveEmptyEntries);
428 foreach (string str in array1) {
430 if (info != null) {
432 }
433 }
434 }
435 }
436
441
446
448
449 public static string DatabaseClassSubstitutes {
450 get {
451 if (m_databaseClassSubstitutes == null) {
452 if (ModsManager.ClassSubstitutes.Count > 0) {
453 StringBuilder sb = new();
454 foreach ((string guid, List<ModsManager.ClassSubstitute> substitutes) in ModsManager.ClassSubstitutes) {
455 if (substitutes.Count == 0) {
456 continue;
457 }
458 sb.Append($"{guid},");
459 foreach (ModsManager.ClassSubstitute substitute in substitutes) {
460 sb.Append($"{substitute.PackageName},{substitute.ClassName},");
461 }
462 sb.Length--;
463 sb.Append(";");
464 }
465 m_databaseClassSubstitutes = sb.ToString();
466 }
467 else {
468 m_databaseClassSubstitutes = string.Empty;
469 }
470 }
472 }
473 set {
475 if (string.IsNullOrEmpty(value)) {
476 return;
477 }
478 string[] array1 = value.Split(';');
479 foreach (string str in array1) {
480 string[] array2 = str.Split(',');
481 if (array2.Length < 5) {
482 continue;
483 }
484 string guid = array2[0];
485 List<ModsManager.ClassSubstitute> substitutes = [];
486 for (int i = 1; i < array2.Length; i += 2) {
487 substitutes.Add(new ModsManager.ClassSubstitute(array2[i], array2[i + 1]));
488 }
489 ModsManager.OldClassSubstitutes.Add(guid, substitutes);
490 }
491 }
492 }
493
494 public static string DatabaseSelectedClassSubstitutes {
495 get {
497 StringBuilder sb = new();
498 foreach ((string guid, ModsManager.ClassSubstitute substitute) in ModsManager.SelectedClassSubstitutes) {
499 sb.Append($"{guid},{substitute.PackageName},{substitute.ClassName};");
500 }
501 sb.Length--;
502 return sb.ToString();
503 }
504 return string.Empty;
505 }
506 set {
507 if (string.IsNullOrEmpty(value)) {
508 return;
509 }
510 string[] array = value.Split(';');
511 foreach (string str in array) {
512 string[] array2 = str.Split(',');
513 if (array2.Length == 3) {
514 ModsManager.SelectedClassSubstitutes.Add(array2[0], new ModsManager.ClassSubstitute(array2[1], array2[2]));
515 }
516 }
517 }
518 }
519
520 static readonly Lock m_saveLock = new();
521
522 public static void Initialize() {
523 {
524 DisplayLog = false;
525 DragHalfInSplit = true;
526 ShortInventoryLooping = false;
528 VisibilityRange = 128;
529 ViewAngle = 1f;
530 TerrainMipmapsEnabled = false;
534 m_soundsVolume = 1.0f;
535 m_musicVolume = 0.2f;
536 m_brightness = 0.8f;
537 ShowGuiInScreenshots = false;
539 ScreenshotSize = ScreenshotSize.ScreenSize;
543 HideMoveLookPads = false;
544 HideCrosshair = false;
545 AllowInitialIntro = true;
546 DeleteWorldNeedToText = false;
547 BlocksTextureFileName = string.Empty;
548 LookControlMode = LookControlMode.EntireScreen;
549 FlipVerticalAxis = false;
550#if ANDROID || BROWSER
551 UIScale = 0.9f;
552 AutoJump = true;
553#else
554 UIScale = 0.75f;
555 AutoJump = false;
556#endif
557 MoveSensitivity = 0.5f;
558 LookSensitivity = 0.5f;
559 GamepadDeadZone = 0.16f;
562 CreativeDigTime = 0.33f;
563 CreativeReach = 7.5f;
564 MinimumHoldDuration = 0.25f;
567 DropboxAccessToken = string.Empty;
568 ScpboxAccessToken = string.Empty;
569 MotdUpdateUrl = $"{CommunityServerManager.CurrentChineseInfo.ApiUrl}/com/motd?v={0}&l={1}";
570 MotdUpdateCheckUrl = $"{CommunityServerManager.CurrentChineseInfo.ApiUrl}com/motd?v={0}&cmd=version_check&platform={1}&apiv={2}&l={3}";
572 MotdLastUpdateTime = DateTime.MinValue;
573 MotdLastDownloadedData = string.Empty;
574 UserId = string.Empty;
575 LastLaunchedVersion = string.Empty;
581 ScreenLayout2 = Window.ScreenSize.X / (float)Window.ScreenSize.Y > 1.33333337f
582 ? ScreenLayout.DoubleVertical
583 : ScreenLayout.DoubleHorizontal;
584 ScreenLayout3 = Window.ScreenSize.X / (float)Window.ScreenSize.Y > 1.33333337f
585 ? ScreenLayout.TripleVertical
586 : ScreenLayout.TripleHorizontal;
587 ScreenLayout4 = ScreenLayout.Quadruple;
588 BulletinTime = string.Empty;
589 ScpboxUserInfo = string.Empty;
594 //MoveWidgetSize = 1f;
597#if BROWSER
599#else
601#endif
603 SafeMode = false;
608 }
609 LoadSettings();
611 Window.Deactivated += delegate { SaveSettings(); };
612 }
613
616 KeyboardMappingSettings.SetValue("MoveLeft", Key.A);
617 KeyboardMappingSettings.SetValue("MoveRight", Key.D);
618 KeyboardMappingSettings.SetValue("MoveFront", Key.W);
619 KeyboardMappingSettings.SetValue("MoveBack", Key.S);
620 KeyboardMappingSettings.SetValue("MoveUp", Key.Space);
621 KeyboardMappingSettings.SetValue("MoveDown", Key.Shift);
622 KeyboardMappingSettings.SetValue("Jump", Key.Space);
623 KeyboardMappingSettings.SetValue("Dig", MouseButton.Left);
624 KeyboardMappingSettings.SetValue("Hit", MouseButton.Left);
625 KeyboardMappingSettings.SetValue("Interact", MouseButton.Right);
626 KeyboardMappingSettings.SetValue("Aim", MouseButton.Right);
627 KeyboardMappingSettings.SetValue("ToggleCrouch", Key.Shift);
628 KeyboardMappingSettings.SetValue("ToggleMount", Key.R);
629 KeyboardMappingSettings.SetValue("ToggleFly", Key.F);
630 KeyboardMappingSettings.SetValue("PickBlockType", MouseButton.Middle);
631 KeyboardMappingSettings.SetValue("ToggleInventory", Key.E);
632 KeyboardMappingSettings.SetValue("ToggleClothing", Key.C);
633 KeyboardMappingSettings.SetValue("TakeScreenshot", Key.P);
634 KeyboardMappingSettings.SetValue("SwitchCameraMode", Key.V);
635 KeyboardMappingSettings.SetValue("TimeOfDay", Key.T);
636 KeyboardMappingSettings.SetValue("Lightning", Key.L);
637 KeyboardMappingSettings.SetValue("Precipitation", Key.K);
638 KeyboardMappingSettings.SetValue("Fog", Key.J);
639 KeyboardMappingSettings.SetValue("Drop", Key.Q);
640 KeyboardMappingSettings.SetValue("EditItem", Key.G);
641 KeyboardMappingSettings.SetValue("KeyboardHelp", Key.H);
642 }
643
644 public static void InitializeGamepadMappingSettings() {
646 GamepadMappingSettings.SetValue("MoveUp", GamePadButton.A);
647 GamepadMappingSettings.SetValue("MoveDown", GamePadButton.RightShoulder);
648 GamepadMappingSettings.SetValue("Jump", GamePadButton.A);
649 GamepadMappingSettings.SetValue("Dig", GamePadTrigger.Right);
650 GamepadMappingSettings.SetValue("Hit", GamePadTrigger.Right);
651 GamepadMappingSettings.SetValue("Interact", GamePadTrigger.Left);
652 GamepadMappingSettings.SetValue("Aim", GamePadTrigger.Left);
653 GamepadMappingSettings.SetValue("ToggleCrouch", GamePadButton.RightShoulder);
654 GamepadMappingSettings.SetValue("ToggleMount", GamePadButton.DPadUp);
655 GamepadMappingSettings.SetValue("ToggleFly", GamePadButton.Null);
656 GamepadMappingSettings.SetValue("PickBlockType", GamePadButton.Null);
657 GamepadMappingSettings.SetValue("ToggleInventory", GamePadButton.X);
658 GamepadMappingSettings.SetValue("ToggleClothing", GamePadButton.Y);
659 GamepadMappingSettings.SetValue("TakeScreenshot", GamePadButton.Null);
660 GamepadMappingSettings.SetValue("SwitchCameraMode", GamePadButton.DPadDown);
661 GamepadMappingSettings.SetValue("TimeOfDay", GamePadButton.Null);
662 GamepadMappingSettings.SetValue("Lightning", GamePadButton.Null);
663 GamepadMappingSettings.SetValue("Precipitation", GamePadButton.Null);
664 GamepadMappingSettings.SetValue("Fog", GamePadButton.Null);
665 GamepadMappingSettings.SetValue("Drop", GamePadButton.B);
666 GamepadMappingSettings.SetValue("EditItem", GamePadButton.LeftShoulder);
667 GamepadMappingSettings.SetValue("GamepadHelp", GamePadButton.Start);
668 GamepadMappingSettings.SetValue("Back", GamePadButton.Back);
669 }
670
671 public static void InitializeCameraManageSettings() { //键表示摄像机的类名,值表示摄像机的排序(小于0则禁用)
673 CameraManageSettings.SetValue("Game.FppCamera", 0);
674 CameraManageSettings.SetValue("Game.TppCamera", 1);
675 CameraManageSettings.SetValue("Game.OrbitCamera", 2);
676 CameraManageSettings.SetValue("Game.FixedCamera", 3);
677 }
678
679 public static object GetKeyboardMapping(string keyName, bool throwIfNotFound = true) {
680 if (KeyboardMappingSettings.TryGetValue(keyName, out object result)) { //原版设置
681 return result;
682 }
683 foreach (ValuesDictionary item in ModSettingsManager.ModKeyboardMapSettings.Values) { //模组设置
684 if (item.TryGetValue(keyName, out object result2)) {
685 return result2;
686 }
687 }
688 return throwIfNotFound ? throw new ArgumentException(string.Format(LanguageControl.Get(fName, "1"), keyName)) : null;
689 }
690
691 public static object GetGamepadMapping(string keyName, bool throwIfNotFound = true) {
692 if (GamepadMappingSettings.TryGetValue(keyName, out object result)) { //原版设置
693 return result;
694 }
695 foreach (ValuesDictionary item in ModSettingsManager.ModGamepadMapSettings.Values) { //模组设置
696 if (item.TryGetValue(keyName, out object result2)) {
697 return result2;
698 }
699 }
700 return throwIfNotFound ? throw new ArgumentException(string.Format(LanguageControl.Get(fName, "1"), keyName)) : null;
701 }
702
703 public static int GetCameraManageSetting(string keyName, bool throwIfNotFound = true) {
704 if (CameraManageSettings.TryGetValue(keyName, out object result)) { //原版设置
705 return Convert.ToInt32(result);
706 }
707 foreach (ValuesDictionary item in ModSettingsManager.ModCameraManageSettings.Values) { //模组设置
708 if (item.TryGetValue(keyName, out object result2)) {
709 return Convert.ToInt32(result2);
710 }
711 }
712 return throwIfNotFound ? throw new ArgumentException(string.Format(LanguageControl.Get(fName, "2"), keyName)) : -1;
713 }
714
720 public static void SetKeyboardMapping(string keyName, object value) {
721 if (KeyboardMappingSettings.ContainsKey(keyName)) { //原版设置
722 KeyboardMappingSettings[keyName] = value;
723 }
724 else {
725 foreach (ValuesDictionary item in ModSettingsManager.ModKeyboardMapSettings.Values) { //模组设置
726 if (item.ContainsKey(keyName)) {
727 item[keyName] = value;
728 break;
729 }
730 }
731 }
732 }
733
739 public static void SetGamepadMapping(string keyName, object value) {
740 if (GamepadMappingSettings.ContainsKey(keyName)) { //原版设置
741 GamepadMappingSettings[keyName] = value;
742 }
743 else {
744 foreach (ValuesDictionary item in ModSettingsManager.ModGamepadMapSettings.Values) { //模组设置
745 if (item.ContainsKey(keyName)) {
746 item[keyName] = value;
747 break;
748 }
749 }
750 }
751 }
752
758 public static void SetCameraManageSetting(string keyName, int value) {
759 if (CameraManageSettings.ContainsKey(keyName)) { //原版设置
760 CameraManageSettings[keyName] = value;
761 }
762 else {
763 foreach (ValuesDictionary item in ModSettingsManager.ModCameraManageSettings.Values) { //模组设置
764 if (item.ContainsKey(keyName)) {
765 item[keyName] = value;
766 break;
767 }
768 }
769 }
770 }
771
775 public static bool LoadSettings() {
777 try {
778 //加载原生设置
780 using (Stream stream = Storage.OpenFile(ModsManager.SettingPath, OpenFileMode.Read)) {
781 XElement xElement = XmlUtils.LoadXmlFromStream(stream, null, true);
782 if (xElement.Elements("Configs").Any()) //往下适配低版本Settings.xml
783 {
785 }
786 else {
787 ValuesDictionary valuesDictionary = new();
788 valuesDictionary.ApplyOverrides(xElement);
789 foreach (string name in valuesDictionary.Keys) {
790 try {
791 PropertyInfo propertyInfo = (from pi in typeof(SettingsManager).GetRuntimeProperties()
792 where pi.Name == name && pi.GetMethod.IsStatic && pi.GetMethod.IsPublic && pi.SetMethod.IsPublic
793 select pi).FirstOrDefault();
794 if (propertyInfo is not null) {
795 object value = valuesDictionary.GetValue<object>(name);
796 if (propertyInfo.PropertyType == typeof(ValuesDictionary)
797 && value is ValuesDictionary vd2) {
798 ValuesDictionary vd3 = propertyInfo.GetValue(null) as ValuesDictionary;
799 vd3.ApplyOverrides(vd2);
800 }
801 else {
802 propertyInfo.SetValue(null, value, null);
803 }
804 }
805 }
806 catch (Exception ex) {
807 if (!LanguageControl.TryGet(out string str, fName, "3")) {
808 str = "Setting \"{0}\" could not be loaded. Reason: {1}";
809 }
810 Log.Warning(string.Format(str, name, ex));
811 }
812 }
813 }
814 }
815 if (!LanguageControl.TryGet(out string info, fName, "4")) {
816 info = "Loaded settings.";
817 }
818 Log.Information(info);
819 return true;
820 }
821 return false;
822 }
823 catch (Exception e) {
824 if (!LanguageControl.TryGet(out string str, fName, "5")) {
825 str = "Loading settings failed.";
826 }
828 return false;
829 }
830 }
831
832 public static void SaveSettings() {
833 if (!m_saveLock.TryEnter(0)) {
834 return;
835 }
836 try {
837 try {
840 }
841 catch (Exception) {
842 //ignore
843 }
844 ValuesDictionary settingsValuesDictionary = new();
845 //原生设置
846 XElement xElement = new("Settings");
847 foreach (PropertyInfo item in from pi in typeof(SettingsManager).GetRuntimeProperties()
848 where pi.GetMethod.IsStatic && pi.GetMethod.IsPublic && pi.SetMethod.IsPublic
849 select pi) {
850 try {
851 object value = item.GetValue(null, null);
852 settingsValuesDictionary.SetValue(item.Name, value);
853 }
854 catch (Exception ex) {
855 if (!LanguageControl.TryGet(out string str, fName, "6")) {
856 str = "Setting \"{0}\" could not be saved. Reason: {1}";
857 }
858 Log.Warning(string.Format(str, item.Name, ex));
859 }
860 }
861 settingsValuesDictionary.Save(xElement);
864 }
865 //保存
866 using (Stream stream = Storage.OpenFile(ModsManager.SettingPath, OpenFileMode.Create)) {
867 XmlUtils.SaveXmlToStream(xElement, stream, Encoding.UTF8, true);
868 }
869 if (!LanguageControl.TryGet(out string info, fName, "7")) {
870 info = "Saved settings.";
871 }
872 Log.Information(info);
873 }
874 catch (Exception e) {
875 if (!LanguageControl.TryGet(out string str, fName, "8")) {
876 str = "Saving settings failed.";
877 }
879 }
880 finally {
881 m_saveLock.Exit();
882 }
883 }
884 }
885}
static void Information(object message)
定义 Log.cs:56
static void Warning(object message)
定义 Log.cs:68
static int Clamp(int x, int min, int max)
static float Saturate(float x)
static void CreateDirectory(string path)
static bool DirectoryExists(string path)
static Stream OpenFile(string path, OpenFileMode openFileMode)
static bool FileExists(string path)
static Point2 ScreenSize
static bool HasWideNotch
static Point2 Size
static Point2 Position
static Action Deactivated
static WindowMode WindowMode
static void ReportExceptionToUser(string additionalMessage, Exception e)
static bool TryGet(out string result, params string[] keys)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static Dictionary< string, ValuesDictionary > ModGamepadMapSettings
储存每个模组的手柄键位映射设置,键:模组包名,值:模组的键位映射设置
static Dictionary< string, ValuesDictionary > ModCameraManageSettings
储存每个模组的相机设置,键:模组包名,值:模组的相机设置
static Dictionary< string, ValuesDictionary > ModKeyboardMapSettings
储存每个模组的键盘鼠标键位映射设置,键:模组包名,值:模组的键位映射设置
static WindowMode m_windowMode
static int GetCameraManageSetting(string keyName, bool throwIfNotFound=true)
static int m_screenshotSizeCustomAspectRatioIndex
static CommunityContentMode CommunityContentMode
static ResolutionMode m_resolutionMode
static Action< string > SettingChanged
static string[] ScreenshotSizeCustomAspectRatiosNames
static string DatabaseSelectedClassSubstitutes
static void SetCameraManageSetting(string keyName, int value)
仅用于修改现有相机配置,添加相机配置请使用ModLoader.GetCameraList
static Point2 m_screenshotSizeCustom
static string CommunityServerUserInfos
static object GetKeyboardMapping(string keyName, bool throwIfNotFound=true)
static int GetLastIndexOfAnyInRange(this int[] array, int minValue, int maxValue)
static MoveControlMode MoveControlMode
static Point2 m_resizableWindowPosition
static string LastSelectedChineseCommunityInfo
static LookControlMode LookControlMode
static ScreenLayout ScreenLayout2
static ValuesDictionary GamepadMappingSettings
static int m_screenshotSizeCustomWidthIndex
static ValuesDictionary CameraManageSettings
static Point2 m_resizableWindowSize
static void InitializeCameraManageSettings()
static float GamepadTriggerThreshold
手柄扳机触发阈值,范围0~1,默认0.5。扳机的按压幅度只有超过这个数时才会被视为“按下”状态,越小则越容易触发。
static int[] ScreenshotSizeCustomWidths
static readonly Lock m_saveLock
static ScreenshotSize ScreenshotSize
static float[] ScreenshotSizeCustomAspectRatios
static void SetKeyboardMapping(string keyName, object value)
仅用于修改现有键盘鼠标键位,添加键位请使用ModLoader.GetKeyboardMappings
static string DatabaseClassSubstitutes
static string LastSelectedOriginalCommunityInfo
static ScreenLayout ScreenLayout4
static ScreenLayout ScreenLayout3
static object GetGamepadMapping(string keyName, bool throwIfNotFound=true)
static CommunityContentMode OriginalCommunityContentMode
static ResolutionMode ResolutionMode
static void InitializeGamepadMappingSettings()
static ScreenLayout ScreenLayout1
static DateTime MotdLastUpdateTime
static SkyRenderingMode SkyRenderingMode
static void InitializeKeyboardMappingSettings()
static string m_databaseClassSubstitutes
static int ScreenshotSizeCustomAspectRatioIndex
static ValuesDictionary KeyboardMappingSettings
static void SetGamepadMapping(string keyName, object value)
仅用于修改现有手柄键位,添加键位请使用ModLoader.GetGamepadMappings
static bool LoadSettings()
文件存在则读取并返回真否则返回假
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static string DocPath
static Dictionary< string, List< ClassSubstitute > > ClassSubstitutes
static string SettingPath
static Dictionary< string, ClassSubstitute > SelectedClassSubstitutes
static Dictionary< string, List< ClassSubstitute > > OldClassSubstitutes
static void LoadConfigs()
static Dictionary< string, HashSet< string > > DisabledMods
static void LoadConfigsFromXml(XElement xElement)
static void SaveConfigs()
void ApplyOverrides(ValuesDictionary overridesValuesDictionary)
static XElement LoadXmlFromStream(Stream stream, Encoding encoding, bool throwOnError)
static void SaveXmlToStream(XElement node, Stream stream, Encoding encoding, bool throwOnError)
static readonly Point2 Zero