设置分组
This commit is contained in:
@@ -5,8 +5,8 @@ namespace NBF
|
||||
{
|
||||
public interface ISettings
|
||||
{
|
||||
List<OptionBase> GetOptionsByGroup(string group);
|
||||
IEnumerable<string> GetAllGroups();
|
||||
List<OptionBase> GetOptionsByTab(string group);
|
||||
IEnumerable<string> GetAllTabs();
|
||||
T GetSettingOption<T>() where T : OptionBase;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,11 @@ namespace NBF.Setting
|
||||
/// </summary>
|
||||
public abstract string Group { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 所在分切页
|
||||
/// </summary>
|
||||
public abstract string Tab { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 默认值
|
||||
/// </summary>
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
{
|
||||
public abstract int MinValue { get; }
|
||||
public abstract int MaxValue { get; }
|
||||
|
||||
public virtual int ShowRate => 0;
|
||||
|
||||
public override void SetValue(int value)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98f6ee319dd5406e9cce3495ebf843e3
|
||||
timeCreated: 1749538582
|
||||
@@ -12,6 +12,7 @@ namespace NBF.Setting
|
||||
{
|
||||
public override string Name => "AnisotropicMode";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
|
||||
protected override int DefaultValue => (int)AnisotropicFiltering.Enable;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace NBF.Setting
|
||||
{
|
||||
public override string Name => "FullScreenMode";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
protected override int DefaultValue => (int)FullScreenMode.ExclusiveFullScreen;
|
||||
|
||||
protected override void OnInitialize()
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace NBF.Setting
|
||||
{
|
||||
public override string Name => "GlobalAnisotropicFilteringLimits";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
protected override int DefaultValue => (int)AnisotropicLevelEnum.x4;
|
||||
|
||||
protected override void OnInitialize()
|
||||
@@ -54,6 +55,5 @@ namespace NBF.Setting
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ namespace NBF.Setting
|
||||
{
|
||||
public override string Name => "MsaaSample";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
protected override int DefaultValue => (int)MsaaSampleEnum.Off;
|
||||
|
||||
protected override void OnInitialize()
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace NBF.Setting
|
||||
private int _defaultQualityLevel;
|
||||
public override string Name => "QualityLevel";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
protected override int DefaultValue => _defaultQualityLevel;
|
||||
|
||||
protected override void OnInitialize()
|
||||
@@ -29,6 +30,5 @@ namespace NBF.Setting
|
||||
{
|
||||
QualitySettings.SetQualityLevel(GetSelectedOption());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,14 @@ namespace NBF.Setting
|
||||
{
|
||||
public override string Name => "RenderScale";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
public override int MinValue => 1;
|
||||
public override int MaxValue => 20;
|
||||
|
||||
protected override int DefaultValue => 10;
|
||||
|
||||
public override int ShowRate => 10;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
SetValue(10);
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace NBF.Setting
|
||||
public override string Name => "Resolution";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
protected override int DefaultValue => _defaultResolution;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace NBF.Setting
|
||||
public override string Name => "TextureQuality";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
protected override int DefaultValue => (int)TextureQualityEnum.FullRes;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace NBF.Setting
|
||||
public override string Name => "VSync";
|
||||
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
protected override int DefaultValue => 0;
|
||||
|
||||
protected override void OnApply()
|
||||
@@ -19,6 +19,5 @@ namespace NBF.Setting
|
||||
//垂直同步
|
||||
QualitySettings.vSyncCount = GetSelectedOption() ? 1 : 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 283a2fdc117b4b4c8c5e9a5245740a8e
|
||||
timeCreated: 1749538578
|
||||
@@ -19,7 +19,10 @@ namespace NBF.Setting
|
||||
{
|
||||
private SettingLanguage _defaultLanguage;
|
||||
public override string Name => "Language";
|
||||
public override string Group => SettingsDef.Group.SoundAndLanguage;
|
||||
public override string Group => SettingsDef.Group.Language;
|
||||
|
||||
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
|
||||
|
||||
protected override int DefaultValue => (int)_defaultLanguage;
|
||||
|
||||
protected override void OnInitialize()
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab9087f7f0a74aaa8a8824e2ec55657d
|
||||
timeCreated: 1749537412
|
||||
@@ -0,0 +1,26 @@
|
||||
using NBC;
|
||||
|
||||
namespace NBF.Setting
|
||||
{
|
||||
[Sort(3)]
|
||||
public class AmbientVolumeSetting : RangeOption
|
||||
{
|
||||
public override string Name => "AmbientVolume";
|
||||
public override string Group => SettingsDef.Group.Sound;
|
||||
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
|
||||
public override int MinValue => 0;
|
||||
public override int MaxValue => 100;
|
||||
|
||||
protected override int DefaultValue => 100;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
SetValue(10);
|
||||
}
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
SoundManager.Inst.SetVolume(AudioChannelType.Ambient, GetValue() / 100f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e841f4c4a4954318b67235033e58576b
|
||||
timeCreated: 1749537896
|
||||
@@ -0,0 +1,26 @@
|
||||
using NBC;
|
||||
|
||||
namespace NBF.Setting
|
||||
{
|
||||
[Sort(1)]
|
||||
public class MasterVolumeSetting : RangeOption
|
||||
{
|
||||
public override string Name => "MasterVolume";
|
||||
public override string Group => SettingsDef.Group.Sound;
|
||||
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
|
||||
public override int MinValue => 0;
|
||||
public override int MaxValue => 100;
|
||||
|
||||
protected override int DefaultValue => 100;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
SetValue(10);
|
||||
}
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
SoundManager.Inst.SetMasterVolume(GetValue() / 100f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e2fca480fb44b0a8d38fd15d2ef1413
|
||||
timeCreated: 1749537486
|
||||
@@ -0,0 +1,26 @@
|
||||
using NBC;
|
||||
|
||||
namespace NBF.Setting
|
||||
{
|
||||
[Sort(2)]
|
||||
public class PlayerVolumeSetting : RangeOption
|
||||
{
|
||||
public override string Name => "PlayerVolume";
|
||||
public override string Group => SettingsDef.Group.Sound;
|
||||
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
|
||||
public override int MinValue => 0;
|
||||
public override int MaxValue => 100;
|
||||
|
||||
protected override int DefaultValue => 100;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
SetValue(10);
|
||||
}
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
SoundManager.Inst.SetVolume(AudioChannelType.Player, GetValue() / 100f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f421f4166fe4bd3a31c78f5a8e47364
|
||||
timeCreated: 1749537942
|
||||
@@ -0,0 +1,26 @@
|
||||
using NBC;
|
||||
|
||||
namespace NBF.Setting
|
||||
{
|
||||
[Sort(4)]
|
||||
public class UIVolumeSetting : RangeOption
|
||||
{
|
||||
public override string Name => "UIVolume";
|
||||
public override string Group => SettingsDef.Group.Sound;
|
||||
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
|
||||
public override int MinValue => 0;
|
||||
public override int MaxValue => 100;
|
||||
|
||||
protected override int DefaultValue => 100;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
SetValue(10);
|
||||
}
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
SoundManager.Inst.SetVolume(AudioChannelType.UI, GetValue() / 100f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a63098af5bd4b36929f75a58e2a5159
|
||||
timeCreated: 1749537834
|
||||
@@ -25,7 +25,7 @@ namespace NBF
|
||||
|
||||
list.SortBySortAttribute();
|
||||
|
||||
AddRangeToGroup(list);
|
||||
AddRangeToTab(list);
|
||||
}
|
||||
|
||||
public void LoadAllSettings()
|
||||
@@ -63,55 +63,55 @@ namespace NBF
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定 Group 的所有 OptionBase
|
||||
/// 获取指定 Tab 的所有 OptionBase
|
||||
/// </summary>
|
||||
public List<OptionBase> GetOptionsByGroup(string group)
|
||||
public List<OptionBase> GetOptionsByTab(string group)
|
||||
{
|
||||
if (string.IsNullOrEmpty(group))
|
||||
{
|
||||
throw new ArgumentException("Group name cannot be null or empty.");
|
||||
throw new ArgumentException("Tab name cannot be null or empty.");
|
||||
}
|
||||
|
||||
return _dictionary.TryGetValue(group, out var options) ? options : new List<OptionBase>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有 Group 名字列表
|
||||
/// 获取所有 Tab 名字列表
|
||||
/// </summary>
|
||||
public IEnumerable<string> GetAllGroups()
|
||||
public IEnumerable<string> GetAllTabs()
|
||||
{
|
||||
return _dictionary.Keys;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将 OptionBase 按 Group 分类存入字典
|
||||
/// 将 OptionBase 按 Tab 分类存入字典
|
||||
/// </summary>
|
||||
private void AddToGroup(OptionBase option)
|
||||
private void AddToTab(OptionBase option)
|
||||
{
|
||||
if (option == null) return;
|
||||
|
||||
if (string.IsNullOrEmpty(option.Group)) return;
|
||||
if (string.IsNullOrEmpty(option.Tab)) return;
|
||||
|
||||
// 如果字典中没有该 Group,则新建一个 List 并加入字典
|
||||
if (!_dictionary.ContainsKey(option.Group))
|
||||
// 如果字典中没有该 Tab,则新建一个 List 并加入字典
|
||||
if (!_dictionary.ContainsKey(option.Tab))
|
||||
{
|
||||
_dictionary[option.Group] = new List<OptionBase>();
|
||||
_dictionary[option.Tab] = new List<OptionBase>();
|
||||
}
|
||||
|
||||
// 将 Option 添加到对应的 Group List 中
|
||||
_dictionary[option.Group].Add(option);
|
||||
// 将 Option 添加到对应的 Tab List 中
|
||||
_dictionary[option.Tab].Add(option);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加 OptionBase 到字典
|
||||
/// </summary>
|
||||
private void AddRangeToGroup(IEnumerable<OptionBase> options)
|
||||
private void AddRangeToTab(IEnumerable<OptionBase> options)
|
||||
{
|
||||
if (options == null) return;
|
||||
|
||||
foreach (var option in options)
|
||||
{
|
||||
AddToGroup(option);
|
||||
AddToTab(option);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
namespace NBF
|
||||
{
|
||||
public class SettingsDef
|
||||
public static class SettingsDef
|
||||
{
|
||||
public class Group
|
||||
public static class Group
|
||||
{
|
||||
public const string Graphic = "Graphic";
|
||||
public const string Keyboard = "Keyboard";
|
||||
public const string Controller = "Controller";
|
||||
public const string Language = "Language";
|
||||
public const string Sound = "Sound";
|
||||
}
|
||||
|
||||
public static class Tab
|
||||
{
|
||||
public const string Graphic = "Graphic";
|
||||
public const string Keyboard = "Keyboard";
|
||||
|
||||
Reference in New Issue
Block a user