PluginConfig.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using BepInEx.Configuration;
  2. using PerformanceScope.Core;
  3. namespace PerformanceScope
  4. {
  5. /// <summary>
  6. /// 插件配置项定义。所有绑定项以静态属性暴露,供服务层直接读取。
  7. /// 配置界面由 BepInEx ConfigurationManager 提供(默认 F1,可在其配置中改键)。
  8. /// </summary>
  9. internal static class PluginConfig
  10. {
  11. private const string SectionGeneral = "1. 通用";
  12. private const string SectionResolution = "2. 镜内分辨率";
  13. public static ConfigEntry<bool> EnableMod { get; private set; }
  14. public static ConfigEntry<bool> EnableLogging { get; private set; }
  15. public static ConfigEntry<bool> VerboseLogging { get; private set; }
  16. public static ConfigEntry<OpticResolutionMode> Mode { get; private set; }
  17. public static ConfigEntry<float> ScreenHeightRatio { get; private set; }
  18. public static ConfigEntry<int> AbsolutePixels { get; private set; }
  19. public static ConfigEntry<bool> ApplyWhileScoped { get; private set; }
  20. /// <summary>绑定全部配置项并立即落盘,生成带注释的初始配置文件。</summary>
  21. public static void Init(ConfigFile config)
  22. {
  23. EnableMod = config.Bind(
  24. SectionGeneral,
  25. "启用模组",
  26. true,
  27. new ConfigDescription(
  28. "总开关。关闭后恢复游戏默认镜内分辨率。",
  29. null,
  30. new ConfigurationManagerAttributes { Order = 1 }));
  31. EnableLogging = config.Bind(
  32. SectionGeneral,
  33. "启用日志",
  34. false,
  35. new ConfigDescription(
  36. "输出本模组的常规/诊断/警告日志(错误日志始终输出)。",
  37. null,
  38. new ConfigurationManagerAttributes { Order = 2 }));
  39. VerboseLogging = config.Bind(
  40. SectionGeneral,
  41. "详细日志",
  42. false,
  43. new ConfigDescription(
  44. "在启用日志的基础上输出更详细的诊断信息。",
  45. null,
  46. new ConfigurationManagerAttributes { IsAdvanced = true, Order = 3 }));
  47. Mode = config.Bind(
  48. SectionResolution,
  49. "取值方式",
  50. // 默认不改变游戏行为;玩家显式选择后再生效(4K 下 0.7 反而会高于默认 1024)。
  51. OpticResolutionMode.GameDefault,
  52. new ConfigDescription(
  53. "游戏默认 / 屏幕高度比例 / 绝对像素。",
  54. // 枚举无需 AcceptableValueList(ConfigurationManager 会自动渲染为下拉框)
  55. null,
  56. new ConfigurationManagerAttributes { Order = 1 }));
  57. ScreenHeightRatio = config.Bind(
  58. SectionResolution,
  59. "屏幕高度比例",
  60. 0.5f,
  61. new ConfigDescription(
  62. "镜内边长 = round(屏幕高度 × 该值)。",
  63. new AcceptableValueRange<float>(ResolutionMath.MinRatio, ResolutionMath.MaxRatio),
  64. new ConfigurationManagerAttributes { ShowRangeAsPercent = true, Order = 2 }));
  65. AbsolutePixels = config.Bind(
  66. SectionResolution,
  67. "绝对像素",
  68. ResolutionMath.GameDefaultResolution,
  69. new ConfigDescription(
  70. "镜内方形 RenderTexture 的边长(像素)。",
  71. new AcceptableValueRange<int>(ResolutionMath.MinResolution, ResolutionMath.MaxResolution),
  72. new ConfigurationManagerAttributes { Order = 3 }));
  73. ApplyWhileScoped = config.Bind(
  74. SectionResolution,
  75. "瞄准中立即应用",
  76. true,
  77. new ConfigDescription(
  78. "关闭时,瞄准镜内期间的改动会推迟到退出镜内后应用,以避免画面闪烁。",
  79. null,
  80. new ConfigurationManagerAttributes { Order = 4 }));
  81. config.Save();
  82. }
  83. }
  84. }