public void ButtonAddListening(Button button, UIViewAction callBack, bool isScale, params object[] parameter) { button.onClick.AddListener(() => { callBack(parameter); }); //if (isScale) //{ // this.ButtonAddScaleResult(button); //} }
/// <summary> /// 更新单个热键 /// </summary> /// <param name="key"></param> private void UpdateHotkeyElement(UIViewAction key) { if (key.State < 0 || key.State >= key.StateList.Count) { return; } Transform outer = OwnerView.State.GetActionBox(); Transform parent = outer ? outer : FindComponent <Transform>("Content/HotkeyBox"); UIViewActionState keyState = key.StateList[key.State]; OwnerView.AddHotKey(key.ID, keyState.Hotkey, (callback) => { key.FireEvent(callback); }, keyState.Time, parent, keyState.Text); OwnerView.SetHotKeyVisible(key.ID, key.Visible); OwnerView.SetHotKeyEnabled(key.ID, key.Enabled); OwnerView.SetHotKeyDescription(key.ID, keyState.Text); }
/// <summary> /// 更新所有热键 /// </summary> private void UpdateAllHotkeyElements() { RemoveAllHotkeyElement(); if (!OwnerView.Focused) { return; } OwnerView.State.OnActionStateChanged -= OnHotkeyStateChanged; if (Config.HasValue) { int pageIndex = OwnerView.State.GetPageIndex(); if (pageIndex < Config.Value.LabelIdLength) { CfgEternityProxy cfg = GameFacade.Instance.RetrieveProxy(ProxyName.CfgEternityProxy) as CfgEternityProxy; UiLabelConfig?pageCfg = cfg.GetUIPage((uint)Config.Value.LabelId(pageIndex)); if (pageCfg.HasValue) { int count = pageCfg.Value.HotkeyLength; for (int i = 0; i < count; i++) { UiHotkeyConfig?hotkeyCfg = cfg.GetUIHotkey(pageCfg.Value.Hotkey(i)); if (!hotkeyCfg.HasValue) { continue; } UIViewAction key = OwnerView.State.GetAction(hotkeyCfg.Value.Id); UpdateHotkeyElement(key); m_HotKeyIDs.Add(key.ID); } } } } if (m_HotKeyIDs.Count > 0) { OwnerView.State.OnActionStateChanged += OnHotkeyStateChanged; } }
/// <summary> /// 重置所有热键状态 /// </summary> private void ResetAllHotkeyState() { if (!Config.HasValue) { return; } int pageIndex = OwnerView.State.GetPageIndex(); if (pageIndex < 0 || pageIndex >= Config.Value.LabelIdLength) { return; } CfgEternityProxy cfg = GameFacade.Instance.RetrieveProxy(ProxyName.CfgEternityProxy) as CfgEternityProxy; UiLabelConfig?pageCfg = cfg.GetUIPage((uint)Config.Value.LabelId(pageIndex)); if (!pageCfg.HasValue) { return; } int count = pageCfg.Value.HotkeyLength; for (int i = 0; i < count; i++) { UiHotkeyConfig?hotkeyCfg = cfg.GetUIHotkey(pageCfg.Value.Hotkey(i)); if (!hotkeyCfg.HasValue) { continue; } UIViewAction key = OwnerView.State.GetAction(hotkeyCfg.Value.Id); key.StateList.Clear(); string hotkey = ""; string text = ""; float time = 0; int arg = 0; int stateCount = Mathf.Max(hotkeyCfg.Value.HotKeyLength, hotkeyCfg.Value.TimeLength, hotkeyCfg.Value.TextLength); for (int j = 0; j < stateCount; j++) { if (j < hotkeyCfg.Value.HotKeyLength) { hotkey = hotkeyCfg.Value.HotKey(j); } if (j < hotkeyCfg.Value.TextLength) { text = GetLocalization(hotkeyCfg.Value.Text(j)); } if (j < hotkeyCfg.Value.TimeLength) { time = hotkeyCfg.Value.Time(j); } if (j < hotkeyCfg.Value.ArgsLength) { arg = hotkeyCfg.Value.Args(j); } key.StateList.Add(new UIViewActionState() { Hotkey = hotkey, Text = text, Time = time, Arg = arg }); } key.State = hotkeyCfg.Value.NormalState; } }
/// <summary> /// 重置所有动作状态 /// </summary> private void ResetAllActionState() { int pageIndex = GetPageIndex(); if (pageIndex < 0 || pageIndex >= UIConfig.Value.LabelIdLength) { return; } CfgEternityProxy cfg = GameFacade.Instance.RetrieveProxy(ProxyName.CfgEternityProxy) as CfgEternityProxy; GameLocalizationProxy localization = GameFacade.Instance.RetrieveProxy(ProxyName.GameLocalizationProxy) as GameLocalizationProxy; UiLabelConfig?pageCfg = cfg.GetUIPage((uint)UIConfig.Value.LabelId(pageIndex)); if (!pageCfg.HasValue) { return; } int count = pageCfg.Value.HotkeyLength; for (int i = 0; i < count; i++) { UiHotkeyConfig?hotkeyCfg = cfg.GetUIHotkey(pageCfg.Value.Hotkey(i)); if (!hotkeyCfg.HasValue) { continue; } UIViewAction key = GetAction(hotkeyCfg.Value.Id); string hotkey = ""; string text = ""; float time = 0; int arg = 0; key.StateList.Clear(); if (key.ID == UIAction.Common_Sort) { var sortItems = GetPage().Sorters; for (int j = 0; j < sortItems.Length; j++) { if (j < hotkeyCfg.Value.HotKeyLength) { hotkey = hotkeyCfg.Value.HotKey(j); } if (j < hotkeyCfg.Value.TimeLength) { time = hotkeyCfg.Value.Time(j); } if (j < hotkeyCfg.Value.ArgsLength) { arg = hotkeyCfg.Value.Args(j); } text = sortItems[j].Label; key.StateList.Add(new UIViewActionState() { Hotkey = hotkey, Text = text, Time = time, Arg = arg }); } } else { int stateCount = Mathf.Max(hotkeyCfg.Value.HotKeyLength, hotkeyCfg.Value.TimeLength, hotkeyCfg.Value.TextLength); for (int j = 0; j < stateCount; j++) { if (j < hotkeyCfg.Value.HotKeyLength) { hotkey = hotkeyCfg.Value.HotKey(j); } if (j < hotkeyCfg.Value.TextLength) { text = localization.GetString(hotkeyCfg.Value.Text(j)); } if (j < hotkeyCfg.Value.TimeLength) { time = hotkeyCfg.Value.Time(j); } if (j < hotkeyCfg.Value.ArgsLength) { arg = hotkeyCfg.Value.Args(j); } key.StateList.Add(new UIViewActionState() { Hotkey = hotkey, Text = text, Time = time, Arg = arg }); } } key.State = Mathf.Min(Mathf.Max(0, hotkeyCfg.Value.NormalState), key.StateList.Count - 1); } }