diff --git a/Assets/PlayerInputControl.inputactions b/Assets/PlayerInputControl.inputactions index 91a80884c..6db89102e 100644 --- a/Assets/PlayerInputControl.inputactions +++ b/Assets/PlayerInputControl.inputactions @@ -1018,6 +1018,15 @@ "processors": "", "interactions": "Hold", "initialStateCheck": false + }, + { + "name": "Reset", + "type": "Button", + "id": "b8805b50-7544-4249-b3b8-f6554dfb7a93", + "expectedControlType": "", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -1350,6 +1359,17 @@ "action": "Up", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "3069f356-c73e-4bac-88f5-88bd6d746bc2", + "path": "/r", + "interactions": "", + "processors": "", + "groups": "", + "action": "Reset", + "isComposite": false, + "isPartOfComposite": false } ] } diff --git a/Assets/Resources/Fgui/Common/Common_fui.bytes b/Assets/Resources/Fgui/Common/Common_fui.bytes index 084276293..4d453ce38 100644 Binary files a/Assets/Resources/Fgui/Common/Common_fui.bytes and b/Assets/Resources/Fgui/Common/Common_fui.bytes differ diff --git a/Assets/Resources/Fgui/Main/Main_fui.bytes b/Assets/Resources/Fgui/Main/Main_fui.bytes index d3062af0c..cf48ddf1d 100644 Binary files a/Assets/Resources/Fgui/Main/Main_fui.bytes and b/Assets/Resources/Fgui/Main/Main_fui.bytes differ diff --git a/Assets/Scripts/Common/Attrobites/Attributes.cs b/Assets/Scripts/Common/Attrobites/Attributes.cs index b512318ca..9944be87e 100644 --- a/Assets/Scripts/Common/Attrobites/Attributes.cs +++ b/Assets/Scripts/Common/Attrobites/Attributes.cs @@ -6,6 +6,17 @@ namespace NBF { } + [AttributeUsage(AttributeTargets.Class)] + public class UIBindAttribute : BaseAttribute + { + public int Id; + + public UIBindAttribute(int id) + { + this.Id = id; + } + } + [AttributeUsage(AttributeTargets.Field)] public class InputIconAttribute : BaseAttribute { @@ -57,5 +68,4 @@ namespace NBF Sort = sort; } } - } \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Input/InputManager.cs b/Assets/Scripts/Common/Services/Input/InputManager.cs index 0805fe885..c9d867ac0 100644 --- a/Assets/Scripts/Common/Services/Input/InputManager.cs +++ b/Assets/Scripts/Common/Services/Input/InputManager.cs @@ -64,12 +64,13 @@ namespace NBF { InputCursorExtension.InputInit(); DontDestroyOnLoad(gameObject); + PlayerInputControl = new PlayerInputControl(); + PlayerInputControl.Enable(); } private void Start() { - PlayerInputControl = new PlayerInputControl(); - PlayerInputControl.Enable(); + AddEvent(); } diff --git a/Assets/Scripts/Common/Services/Settings/Base/GamepadOption.cs b/Assets/Scripts/Common/Services/Settings/Base/GamepadOption.cs new file mode 100644 index 000000000..5e5aaba89 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/GamepadOption.cs @@ -0,0 +1,18 @@ +using UnityEngine.InputSystem; + +namespace NBF.Setting +{ + public abstract class GamepadOption : InputOption + { + protected override bool IsBindingContains(InputBinding binding) + { + var path = binding.path; + if (path.Contains("")) + { + return true; + } + + return false; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/GamepadOption.cs.meta b/Assets/Scripts/Common/Services/Settings/Base/GamepadOption.cs.meta new file mode 100644 index 000000000..806cb1347 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/GamepadOption.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 49041e6a08b744038368d7010acf61ea +timeCreated: 1750408186 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/InputOption.cs b/Assets/Scripts/Common/Services/Settings/Base/InputOption.cs index 285f497a9..bc4829e87 100644 --- a/Assets/Scripts/Common/Services/Settings/Base/InputOption.cs +++ b/Assets/Scripts/Common/Services/Settings/Base/InputOption.cs @@ -1,21 +1,84 @@ -using UnityEngine.InputSystem; +using UnityEngine; +using UnityEngine.InputSystem; namespace NBF.Setting { public abstract class InputOption : OptionBase { + private int _bindingIndex = 0; public abstract InputAction InputAction { get; } + public int BindingIndex => _bindingIndex; + protected override int DefaultValue => 0; - + + /// + /// 保存的值 + /// + protected string InputSaveValue; + + public override bool HaveNotApple() + { + return !InputAction.SaveBindingOverridesAsJson().Equals(InputSaveValue); + } + + public override void Apply() + { + // 保存绑定 + PlayerPrefs.SetString(SaveKey, InputAction.SaveBindingOverridesAsJson()); + SaveValue = Value; + OnApply(); + } + + public override void Load() + { + for (int i = 0; i < InputAction.bindings.Count; i++) + { + var binding = InputAction.bindings[i]; + if (IsBindingContains(binding)) + { + _bindingIndex = i; + break; + } + } + + var value = PlayerPrefs.GetString(SaveKey, string.Empty); + InputSaveValue = value; + if (!string.IsNullOrEmpty(InputSaveValue)) + { + InputAction.LoadBindingOverridesFromJson(InputSaveValue); + } + } + + public override void Reset() + { + if (InputAction.bindings[BindingIndex].isComposite) + { + // It's a composite. Remove overrides from part bindings. + for (var i = BindingIndex + 1; + i < InputAction.bindings.Count && InputAction.bindings[i].isPartOfComposite; + ++i) + InputAction.RemoveBindingOverride(i); + } + else + { + InputAction.RemoveBindingOverride(BindingIndex); + } + } + public override string GetDisplayString() { if (InputAction != null) { - return InputAction.GetBindingDisplayString(); + return InputAction.GetBindingDisplayString(BindingIndex); } return base.GetDisplayString(); } + + protected virtual bool IsBindingContains(InputBinding binding) + { + return true; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/KeyBoardOption.cs b/Assets/Scripts/Common/Services/Settings/Base/KeyBoardOption.cs index 264807d11..e7150ee69 100644 --- a/Assets/Scripts/Common/Services/Settings/Base/KeyBoardOption.cs +++ b/Assets/Scripts/Common/Services/Settings/Base/KeyBoardOption.cs @@ -4,6 +4,15 @@ namespace NBF.Setting { public abstract class KeyBoardOption : InputOption { - + protected override bool IsBindingContains(InputBinding binding) + { + var path = binding.path; + if (path.Contains("") || path.Contains("")) + { + return true; + } + + return false; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs b/Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs index 909ce01e8..612fc4f74 100644 --- a/Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs +++ b/Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs @@ -45,7 +45,7 @@ namespace NBF.Setting /// protected int SaveValue; - public bool HaveNotApple() + public virtual bool HaveNotApple() { return !Value.Equals(SaveValue); } @@ -64,21 +64,21 @@ namespace NBF.Setting /// /// 加载用户的设置 /// - public void Load() + public virtual void Load() { var value = PlayerPrefs.GetInt(SaveKey, DefaultValue); Value = value; SaveValue = value; } - public void Apply() + public virtual void Apply() { PlayerPrefs.SetInt(SaveKey, Value); SaveValue = Value; OnApply(); } - public void Reset() + public virtual void Reset() { Value = DefaultValue; } diff --git a/Assets/Scripts/Def/InputDef.cs b/Assets/Scripts/Def/InputDef.cs index 9e056b876..db041cf3f 100644 --- a/Assets/Scripts/Def/InputDef.cs +++ b/Assets/Scripts/Def/InputDef.cs @@ -18,6 +18,9 @@ namespace NBF [InputIcon("icon_controller_129", "icon_controller_1")] public const string Enter = "Enter"; + [InputIcon("icon_controller_129", "icon_controller_1")] + public const string Reset = "Reset"; + [InputIcon("icon_controller_127", "icon_controller_19")] public const string Tab = "Tab"; diff --git a/Assets/Scripts/Def/UIDef.cs b/Assets/Scripts/Def/UIDef.cs index 565405ac2..db009bd0d 100644 --- a/Assets/Scripts/Def/UIDef.cs +++ b/Assets/Scripts/Def/UIDef.cs @@ -83,5 +83,19 @@ namespace NBF [InspectorName("订购市场")] ReserveBazaar = 22 } + + public class ID + { + public const int Loading = 1; + public const int Home = 2; + public const int SettingPanel = 3; + public const int HelpPanel = 4; + public const int MapPanel = 5; + + public const int ShopPanel = 10; + public const int MakePanel = 11; + public const int BagPanel = 12; + public const int FishBagPanel = 13; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Fishing/PlayerInputControl.cs b/Assets/Scripts/Fishing/PlayerInputControl.cs index 199a8b95a..33440ed45 100644 --- a/Assets/Scripts/Fishing/PlayerInputControl.cs +++ b/Assets/Scripts/Fishing/PlayerInputControl.cs @@ -1106,6 +1106,15 @@ namespace NBF ""processors"": """", ""interactions"": ""Hold"", ""initialStateCheck"": false + }, + { + ""name"": ""Reset"", + ""type"": ""Button"", + ""id"": ""b8805b50-7544-4249-b3b8-f6554dfb7a93"", + ""expectedControlType"": """", + ""processors"": """", + ""interactions"": """", + ""initialStateCheck"": false } ], ""bindings"": [ @@ -1438,6 +1447,17 @@ namespace NBF ""action"": ""Up"", ""isComposite"": false, ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""3069f356-c73e-4bac-88f5-88bd6d746bc2"", + ""path"": ""/r"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Reset"", + ""isComposite"": false, + ""isPartOfComposite"": false } ] } @@ -1556,6 +1576,7 @@ namespace NBF m_UI_Left = m_UI.FindAction("Left", throwIfNotFound: true); m_UI_Down = m_UI.FindAction("Down", throwIfNotFound: true); m_UI_Up = m_UI.FindAction("Up", throwIfNotFound: true); + m_UI_Reset = m_UI.FindAction("Reset", throwIfNotFound: true); } ~@PlayerInputControl() @@ -2129,6 +2150,7 @@ namespace NBF private readonly InputAction m_UI_Left; private readonly InputAction m_UI_Down; private readonly InputAction m_UI_Up; + private readonly InputAction m_UI_Reset; /// /// Provides access to input actions defined in input action map "UI". /// @@ -2185,6 +2207,10 @@ namespace NBF /// public InputAction @Up => m_Wrapper.m_UI_Up; /// + /// Provides access to the underlying input action "UI/Reset". + /// + public InputAction @Reset => m_Wrapper.m_UI_Reset; + /// /// Provides access to the underlying input action map instance. /// public InputActionMap Get() { return m_Wrapper.m_UI; } @@ -2243,6 +2269,9 @@ namespace NBF @Up.started += instance.OnUp; @Up.performed += instance.OnUp; @Up.canceled += instance.OnUp; + @Reset.started += instance.OnReset; + @Reset.performed += instance.OnReset; + @Reset.canceled += instance.OnReset; } /// @@ -2287,6 +2316,9 @@ namespace NBF @Up.started -= instance.OnUp; @Up.performed -= instance.OnUp; @Up.canceled -= instance.OnUp; + @Reset.started -= instance.OnReset; + @Reset.performed -= instance.OnReset; + @Reset.canceled -= instance.OnReset; } /// @@ -2729,6 +2761,13 @@ namespace NBF /// /// void OnUp(InputAction.CallbackContext context); + /// + /// Method invoked when associated input action "Reset" is either , or . + /// + /// + /// + /// + void OnReset(InputAction.CallbackContext context); } } } diff --git a/Assets/Scripts/NBC/UI/Runtime/UIManager.cs b/Assets/Scripts/NBC/UI/Runtime/UIManager.cs index c744d2639..8ca43353e 100644 --- a/Assets/Scripts/NBC/UI/Runtime/UIManager.cs +++ b/Assets/Scripts/NBC/UI/Runtime/UIManager.cs @@ -129,7 +129,7 @@ namespace NBC _uiArray.Add(uiName, panel); } - public IUIPanel GetUI() + public T GetUI() where T : class { IUIPanel wind = null; Type type = typeof(T); @@ -141,7 +141,7 @@ namespace NBC break; } - return wind; + return wind as T; } public IUIPanel GetUI(Type type) diff --git a/Assets/Scripts/UI/Common/Panel/MessageBox.Designer.cs b/Assets/Scripts/UI/Common/Panel/MessageBox.Designer.cs index e3579bb71..b7186e927 100644 --- a/Assets/Scripts/UI/Common/Panel/MessageBox.Designer.cs +++ b/Assets/Scripts/UI/Common/Panel/MessageBox.Designer.cs @@ -19,12 +19,10 @@ namespace NBF public GImage box; [AutoFind(Name = "TextTitle")] public GTextField TextTitle; - [AutoFind(Name = "TextContent")] - public GTextField TextContent; - [AutoFind(Name = "BtnConfirm")] - public BtnTitleInputControl BtnConfirm; [AutoFind(Name = "BtnCancel")] public BtnTitleInputControl BtnCancel; + [AutoFind(Name = "BtnConfirm")] + public BtnTitleInputControl BtnConfirm; public override string[] GetDependPackages(){ return new string[] {}; } diff --git a/Assets/Scripts/UI/Common/Panel/MessageBox.cs b/Assets/Scripts/UI/Common/Panel/MessageBox.cs index 54610f47a..dcc8e194a 100644 --- a/Assets/Scripts/UI/Common/Panel/MessageBox.cs +++ b/Assets/Scripts/UI/Common/Panel/MessageBox.cs @@ -59,10 +59,10 @@ namespace NBF protected override void OnShow() { - TextTitle.SetLanguage(_title); + // TextTitle.SetLanguage(_title); BtnConfirm.SetLanguage(_confirmText); BtnCancel.SetLanguage(_cancelText); - TextContent.SetLanguage(_content); + TextTitle.SetLanguage(_content); MessageStyle.selectedIndex = _style; } diff --git a/Assets/Scripts/UI/Settings/KeyboardInput.cs b/Assets/Scripts/UI/Settings/KeyboardInput.cs index 847e51cd2..34474300e 100644 --- a/Assets/Scripts/UI/Settings/KeyboardInput.cs +++ b/Assets/Scripts/UI/Settings/KeyboardInput.cs @@ -1,10 +1,8 @@ // 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖 -using UnityEngine; + using FairyGUI; -using NBC; using NBF.Setting; -using UnityEngine.InputSystem; namespace NBF { @@ -20,7 +18,7 @@ namespace NBF if (option is KeyBoardOption) { TextKeyboard.visible = true; - TextKeyboard.text = option.GetDisplayString(); + TextKeyboard.text = option.GetDisplayString(); // + "- " + string.Join(",", list); } } } diff --git a/Assets/Scripts/UI/Settings/SettingInputItem.cs b/Assets/Scripts/UI/Settings/SettingInputItem.cs index 7078f8de4..c583a6d9a 100644 --- a/Assets/Scripts/UI/Settings/SettingInputItem.cs +++ b/Assets/Scripts/UI/Settings/SettingInputItem.cs @@ -1,36 +1,80 @@ // 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖 -using System.Globalization; -using UnityEngine; using FairyGUI; using NBC; using NBF.Setting; +using UnityEngine.InputSystem; namespace NBF { public partial class SettingInputItem : GButton { - public OptionBase Option; + public InputOption Option; + private InputActionRebindingExtensions.RebindingOperation rebindingOperation; + private void OnInited() { + BtnKeyboard.onClick.Set(OnClickRebind); + onChanged.Add(SelfChanged); } - public void SetData(OptionBase option) + public void SetData(InputOption option) { Option = option; TextName.SetLanguage(Option.Name); - SetShow(); + UpdateValueText(); } - private void SetShow() + public void OnClickRebind() { + // InputWaitingPanel.Show(true); + // UI.Inst.OpenUI(); + // 取消当前绑定 + var settingPanel = UI.Inst.GetUI(); + settingPanel.InputWait.visible = true; + Option.InputAction.Disable(); + + // 开始重绑定操作 + rebindingOperation = Option.InputAction.PerformInteractiveRebinding(Option.BindingIndex) + .OnMatchWaitForAnother(0.1f) + .OnComplete(operation => RebindComplete()) + .OnCancel(operation => RebindCanceled()) + .Start(); + } + + private void RebindComplete() + { + rebindingOperation.Dispose(); UpdateValueText(); + Option.InputAction.Enable(); + + var settingPanel = UI.Inst.GetUI(); + settingPanel.InputWait.visible = false; + // UI.Inst.HideUI(); + // startRebindObject.SetActive(true); + // waitingForInputObject.SetActive(false); + } + + private void RebindCanceled() + { + rebindingOperation.Dispose(); + Option.InputAction.Enable(); + // UI.Inst.HideUI(); + } + + + private void SelfChanged(EventContext context) + { + if (!selected) + { + // RebindOver(); + } } private void UpdateValueText() { - BtnKeyboard.SetData(Option as InputOption); + BtnKeyboard.SetData(Option); } } } \ No newline at end of file diff --git a/Assets/Scripts/UI/Settings/SettingPanel.Designer.cs b/Assets/Scripts/UI/Settings/SettingPanel.Designer.cs index 37e8c9342..33af10bbb 100644 --- a/Assets/Scripts/UI/Settings/SettingPanel.Designer.cs +++ b/Assets/Scripts/UI/Settings/SettingPanel.Designer.cs @@ -23,6 +23,8 @@ namespace NBF public GImage BottomLine; [AutoFind(Name = "Mask")] public GLabel Mask; + [AutoFind(Name = "InputWait")] + public GComponent InputWait; public override string[] GetDependPackages(){ return new string[] {"Common"}; } diff --git a/Assets/Scripts/UI/Settings/SettingPanel.cs b/Assets/Scripts/UI/Settings/SettingPanel.cs index 118ce7e82..f3ffa540b 100644 --- a/Assets/Scripts/UI/Settings/SettingPanel.cs +++ b/Assets/Scripts/UI/Settings/SettingPanel.cs @@ -10,6 +10,7 @@ using UIPanel = NBC.UIPanel; namespace NBF { + [UIBind(UIDef.ID.SettingPanel)] public partial class SettingPanel : UIPanel { public override string UIPackName => "Main"; @@ -64,7 +65,7 @@ namespace NBF { // TextTitle.text = Lan.Get(_currentGroup); _nowSelectIndex = -1; - + if (string.IsNullOrEmpty(_currentTab)) return; var options = Settings.Instance.GetOptionsByTab(_currentTab); Dictionary> groupOptions = new Dictionary>(); @@ -82,8 +83,8 @@ namespace NBF _canSelectIndex.Clear(); List.RemoveChildrenToPool(); - - + + var url = UIPackage.GetItemURL(UIPackName, "SettingSubTitleItem"); foreach (var key in groupOptions.Keys) { @@ -99,7 +100,7 @@ namespace NBF { if (List.AddItemFromPool(SettingInputItem.URL) is SettingInputItem item) { - item.SetData(option); + item.SetData(option as InputOption); var index = List.GetChildIndex(item); _canSelectIndex.Add(index); } @@ -125,7 +126,7 @@ namespace NBF private void OnApplySettings() { var options = Settings.Instance.GetOptionsByTab(_currentTab); - + Log.Info("OnApplySettings"); foreach (var option in options) { option.Apply(); @@ -140,6 +141,8 @@ namespace NBF { option.Reset(); } + + ResetSettingList(); } private void OnUICanceled(string action) @@ -174,6 +177,13 @@ namespace NBF { OnApplySettings(); } + else if (action == InputDef.UI.Reset) + { + MessageBox.Show("是否重置为默认?", (ret) => + { + if (ret) OnResetSettings(); + }); + } } diff --git a/FGUIProject/assets/Common/Panel/MessageBox.xml b/FGUIProject/assets/Common/Panel/MessageBox.xml index 6510ef78b..b66e74754 100644 --- a/FGUIProject/assets/Common/Panel/MessageBox.xml +++ b/FGUIProject/assets/Common/Panel/MessageBox.xml @@ -11,22 +11,19 @@ - + - - - - - -