完成设置按键绑定和取消绑定

This commit is contained in:
bob
2025-06-23 10:52:47 +08:00
parent 07ebc1a1a7
commit 2024bfb990
4 changed files with 39 additions and 2 deletions

View File

@@ -25,8 +25,8 @@ namespace NBF.Setting
public override void Apply() public override void Apply()
{ {
// 保存绑定 // 保存绑定
PlayerPrefs.SetString(SaveKey, InputAction.SaveBindingOverridesAsJson()); InputSaveValue = InputAction.SaveBindingOverridesAsJson();
SaveValue = Value; PlayerPrefs.SetString(SaveKey, InputSaveValue);
OnApply(); OnApply();
} }
@@ -66,6 +66,18 @@ namespace NBF.Setting
} }
} }
public override void Cancel()
{
if (!string.IsNullOrEmpty(InputSaveValue))
{
InputAction.LoadBindingOverridesFromJson(InputSaveValue);
}
else
{
Reset();
}
}
public override string GetDisplayString() public override string GetDisplayString()
{ {
if (InputAction != null) if (InputAction != null)

View File

@@ -83,6 +83,12 @@ namespace NBF.Setting
Value = DefaultValue; Value = DefaultValue;
} }
public virtual void Cancel()
{
}
public virtual string GetDisplayString() public virtual string GetDisplayString()
{ {
return GetValue().ToString(); return GetValue().ToString();

View File

@@ -131,6 +131,7 @@ namespace NBF
{ {
option.Apply(); option.Apply();
} }
Notices.Success("TEXT_OP_SUCCESS");
} }
private void OnResetSettings() private void OnResetSettings()
@@ -240,6 +241,7 @@ namespace NBF
{ {
if (b) if (b)
{ {
CancelAndBack();
Hide(); Hide();
} }
}); });
@@ -250,6 +252,23 @@ namespace NBF
} }
} }
private void CancelAndBack()
{
var groupNames = Settings.Instance.GetAllTabs();
foreach (var group in groupNames)
{
var options = Settings.Instance.GetOptionsByTab(group);
foreach (var option in options)
{
if (option.HaveNotApple())
{
option.Cancel();
}
}
}
}
protected override void OnHide() protected override void OnHide()
{ {
base.OnHide(); base.OnHide();

Binary file not shown.