修改设置界面

This commit is contained in:
2026-02-01 20:29:16 +08:00
parent 8a6ba7c514
commit e05561ff43
560 changed files with 1581 additions and 1187 deletions

View File

@@ -20,9 +20,8 @@ namespace NBF
[AttributeUsage(AttributeTargets.Method)]
public class UIExtensionAutoBindAttribute : BaseAttribute
{
}
[AttributeUsage(AttributeTargets.Field)]
public class InputIconAttribute : BaseAttribute
{
@@ -74,4 +73,19 @@ namespace NBF
Sort = sort;
}
}
[AttributeUsage(AttributeTargets.Method)]
public class InputInvokeAttribute : BaseAttribute
{
public string Name;
public string Key;
public bool ShowLeft;
public InputInvokeAttribute(string name, string key = "", bool showLeft = true)
{
Name = name;
Key = key;
ShowLeft = showLeft;
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using NBC;
// using Rewired;
@@ -13,6 +14,12 @@ namespace NBF
GamePad = 1
}
public struct UIInputInvoke
{
public object UIObject;
public InputInvokeAttribute InputInvoke;
}
public class InputManager : MonoService<InputManager>
{
public static bool IsOp1;
@@ -237,5 +244,20 @@ namespace NBF
OnUIPerformed?.Invoke(actionName);
OnUICanceled?.Invoke(actionName);
}
#region UI界面按键管理
private readonly Dictionary<object, List<UIInputInvoke>> _panelActions =
new Dictionary<object, List<UIInputInvoke>>();
public void On(object obj)
{
}
public void Off(object obj)
{
}
#endregion
}
}

View File

@@ -7,6 +7,7 @@ namespace NBF.Setting
public interface IMultiOption : IOptionBase
{
List<string> GetOptionNames();
bool IsDropdown { get; }
}
public abstract class MultiOption<T> : OptionBase, IMultiOption
@@ -21,6 +22,8 @@ namespace NBF.Setting
public List<string> GetOptionNames() => OptionTable.GetNames();
public virtual bool IsDropdown => false;
protected void SelectOption(T value, int defaultIndex = 0)
{

View File

@@ -51,13 +51,18 @@ namespace NBF.Setting
}
public ISettings Root { get; private set; }
public void Initialize(ISettings root)
{
Root = root;
Load();
OnInitialize();
if (!PlayerPrefs.HasKey(SaveKey))
{
OnSetDefaultValue();
}
Apply();
}
@@ -85,15 +90,14 @@ namespace NBF.Setting
public virtual void Cancel()
{
}
public virtual string GetDisplayString()
{
return GetValue().ToString();
}
public virtual int GetValue()
{
return Value;
@@ -109,6 +113,11 @@ namespace NBF.Setting
{
}
protected virtual void OnSetDefaultValue()
{
Value = DefaultValue;
SaveValue = DefaultValue;
}
protected abstract void OnApply();
}

View File

@@ -1,4 +1,6 @@
using UnityEngine;
using Unity.Collections;
using System.Collections;
namespace NBF.Setting
{
@@ -20,8 +22,15 @@ namespace NBF.Setting
protected override void OnApply()
{
// Screen.fullScreenMode = GetSelectedOption();
// Debug.Log($"FullScreenMode: {Screen.fullScreenMode} value: {GetSelectedOption()}");
Screen.fullScreenMode = GetSelectedOption();
if (Screen.fullScreenMode == FullScreenMode.ExclusiveFullScreen)
{
Screen.fullScreen = true;
}
var nmsl = KeyCode.Alpha0;
Debug.Log($"FullScreenMode: {Screen.fullScreenMode} value: {GetSelectedOption()}");
}
}
}

View File

@@ -16,19 +16,84 @@ namespace NBF.Setting
public override string Group => SettingsDef.Group.Graphic;
protected override int DefaultValue => _defaultResolution;
public override string Tab => SettingsDef.Tab.Graphic;
public override bool IsDropdown => true;
static readonly (int w, int h)[] Classic16_9 =
{
(1280, 720),
(1600, 900),
(1920, 1080),
(2560, 1440),
(3840, 2160),
};
static readonly (int w, int h)[] Classic16_10 =
{
(1280, 800),
(1680, 1050),
(1920, 1200),
(2560, 1600),
};
static readonly (int w, int h)[] Classic21_9 =
{
(2560, 1080),
(3440, 1440),
(3840, 1600),
};
static readonly (int w, int h)[] Classic32_9 =
{
(3840, 1080),
(5120, 1440),
};
protected override void OnInitialize()
{
var supportedResolutions = Screen.resolutions
.GroupBy(r => $"{r.width}x{r.height}") // 按宽高分组
.Select(g => g.OrderByDescending(r => r.refreshRateRatio).First())
.ToArray();
foreach (var resolution in supportedResolutions)
var supported = Screen.resolutions
.Select(r => (r.width, r.height))
.Distinct()
.ToHashSet();
var mainWindowDisplayInfo = Screen.mainWindowDisplayInfo; // 主窗口所在显示器的信息
float aspect = (float)Screen.currentResolution.width / Screen.currentResolution.height;
bool Near(float a, float b, float eps = 0.03f) => Mathf.Abs(a - b) <= eps;
IEnumerable<(int w, int h)> preferred =
Near(aspect, 16f / 9f) ? Classic16_9 :
Near(aspect, 16f / 10f) ? Classic16_10 :
Near(aspect, 21f / 9f) ? Classic21_9 :
Near(aspect, 32f / 9f) ? Classic32_9 :
Classic16_9; // 兜底
var list = preferred.Where(supported.Contains).ToList();
// 兜底:保证原生分辨率一定在列表里(尤其是超宽屏)
var native = (Screen.currentResolution.width, Screen.currentResolution.height);
if (!list.Contains(native) && supported.Contains(native))
list.Add(native);
// 排序(从小到大或从大到小都行)
list = list.OrderBy(x => x.w * x.h).ToList();
foreach (var resolution in list)
{
if (resolution.width < 720 || resolution.height < 720) continue;
AddOption($"{resolution.width}x{resolution.height}", resolution);
Log.Info($"Resolution {resolution.width}x{resolution.height}");
var w = resolution.w;
var h = resolution.h;
if (w > mainWindowDisplayInfo.width || h > mainWindowDisplayInfo.height) continue;
AddOption($"{w}x{h}", new Resolution()
{
width = w,
height = h,
});
Log.Info($"Resolution {w}x{h}");
}
TryGetIndex(t =>
t.width == Screen.currentResolution.width && t.height == Screen.currentResolution.height,
@@ -38,7 +103,15 @@ namespace NBF.Setting
{
_defaultResolution = 0;
}
var n = Value;
var nm = SaveValue;
if (!PlayerPrefs.HasKey(SaveKey))
{
}
}
protected override void OnApply()
{

View File

@@ -10,6 +10,7 @@ namespace NBF
public string Key;
public string Icon;
public bool IsAll;
public string Name;
// 条目可以是任意对象类型
public List<object> Items = new List<object>();