using System.Collections.Generic; using FairyGUI; using Game.Battle; using Articy.Unity; using Articy.Touhou; using Articy.Unity.Interfaces; namespace Game { public class PageCombo : UIPageBase { private Dictionary> _skillCombo = new Dictionary>(); private Dictionary _skill2Index = new Dictionary(); private Dictionary _index2Skill = new Dictionary(); public PageCombo() { } protected override void OnCreate() { CreateUI(false); InitComboTree(); InitComboList(); } private void InitComboTree() { var comboTree = Util.GetConfig(GameConst.ComboTree); var queue = new Queue(); var firstPins = (comboTree as IInputPinsOwner).GetInputPins(); foreach (var pin in firstPins) { var firstConns = pin.GetOutgoingConnections(); foreach (var conn in firstConns) { queue.Enqueue(conn.Target); } } var frontNode = new Dictionary(); var comboFrag = new Dictionary>(); int countMax = 1000; while (queue.Count > 0) { if (countMax-- <= 0) { break; } var nodeNow = queue.Dequeue() as DialogueFragment; var key = nodeNow.TechnicalName; var speaker = nodeNow.Speaker; var comboStr = nodeNow.MenuText; if (!comboFrag.ContainsKey(key)) { var comboList = new List(comboStr.Split(' ')); if (frontNode.ContainsKey(key)) { var preCombo = comboFrag[frontNode[key]]; comboList.InsertRange(0, preCombo); } comboFrag[key] = comboList; } var nextPins = (nodeNow as IOutputPinsOwner).GetOutputPins(); foreach (var pin in nextPins) { var nextConns = pin.GetOutgoingConnections(); foreach (var conn in nextConns) { var nextKey = conn.Target.TechnicalName; if (frontNode.ContainsKey(nextKey)) { continue; } frontNode[nextKey] = key; queue.Enqueue(conn.Target); } } } foreach (var combo in comboFrag) { var frag = Util.GetConfig(combo.Key) as DialogueFragment; var skill = frag.Speaker as SkillMaster; if (skill == null) { continue; } _skillCombo[skill.TechnicalName] = combo.Value; } } private void InitComboList() { View.m_ComboList.m_ComboList.RemoveChildrenToPool(); var i = 0; foreach (var skillItem in _skillCombo) { _skill2Index[skillItem.Key] = i; _index2Skill[i] = skillItem.Key; i++; } View.m_ComboList.m_ComboList.SetVirtualAndLoop(); View.m_ComboList.m_ComboList.itemRenderer = (int index, GObject obj) => { var key = _index2Skill[index]; var comboItem = obj as ViewComboItem; var skill = Util.GetSkillMasterConfig(key); var skillName = skill.Skill.Name; comboItem.m_SkillName.text = skillName; comboItem.m_CastCount.text = $"{index}"; comboItem.m_ComboList.RemoveChildrenToPool(); foreach (var item in _skillCombo[key]) { if (string.IsNullOrEmpty(item)) { continue; } var comboKey = comboItem.m_ComboList.AddItemFromPool() as ViewComboKey; if (item == "*") { comboKey.m_c2.selectedIndex = 1; } else { comboKey.m_c2.selectedIndex = 0; var text = item; if (text.StartsWith("↑")) { text = text.Substring(1); comboKey.m_c1.selectedIndex = 1; } else if (text.StartsWith("↓")) { text = text.Substring(1); comboKey.m_c1.selectedIndex = 2; } else { comboKey.m_c1.selectedIndex = 0; } comboKey.m_key.text = text; } } }; View.m_ComboList.m_ComboList.numItems = _skillCombo.Count; } protected override void OnCreateBind() { var master = Util.GetMaster(); BindSkill(master); //绑定技能 } private void BindSkill(GameEntity entity) { var skill = entity.skill; BindData(skill.SkillId, (_, now) => { if (string.IsNullOrEmpty(now)) { return; } if (_skill2Index.ContainsKey(now)) { var count = _skillCombo.Count; var targetIndex = (_skill2Index[now] - 2 + count) % count; View.m_ComboList.m_ComboList.ScrollToView(targetIndex, true, true); } }); } protected override void OnDestroy() { } protected override void OnOpen() { } protected override void OnClose() { } public override void Update() { } } }