//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Thursday, July 26, 2018 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class ViewHorseDetailWin : Window { [SerializeField] ScrollerController m_Controller; [SerializeField] Text m_FightPower; [SerializeField] PropertyBehaviour[] m_Propertys; [SerializeField] HorseSkill[] m_HorseSkills; [SerializeField] ScrollerController m_SkillController; [SerializeField] RawImage m_RawModel; [SerializeField] Button m_HorseStone; [SerializeField] Button m_CloseBtn; [SerializeField, Header("技能一行个数")] int m_LineCount = 3; public int selectHorse { get; private set; } public int lineCount { get { return m_LineCount; } } List skills = new List(); [NonSerialized] public List displayTotalSkills = new List(); [NonSerialized] public List unlockTotalSkills = new List(); RoleParticularModel model { get { return ModelCenter.Instance.GetModel(); } } MountModel mountModel { get { return ModelCenter.Instance.GetModel(); } } #region Built-in protected override void BindController() { } protected override void AddListeners() { m_Controller.OnRefreshCell += OnRefreshCell; m_SkillController.OnRefreshCell += OnRefreshSkillCell; m_HorseStone.onClick.AddListener(OnHorseStone); m_CloseBtn.onClick.AddListener(CloseClick); } protected override void OnPreOpen() { Display(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { } protected override void OnAfterClose() { } #endregion void Display() { RoleParticularModel.ViewPlayerData data = model.GetViewPlayerData(model.viewPlayer); if (data == null) { return; } var horses = data.rolePlusData.horses; selectHorse = horses[0].id; m_Controller.Refresh(); for (int i = 0; i < horses.Count; i++) { CellInfo info = CellInfo.Default; info.infoInt1 = horses[i].lv; m_Controller.AddCell(ScrollerDataType.Header, horses[i].id, info); } m_Controller.Restart(); m_FightPower.text = model.GetHorseFightPower(horses).ToString(); DisplayModel(selectHorse); DisplayProperty(horses); DisplaySkills(horses[0].id, horses[0].lv); DisplayTotalSkills(horses); } public void SelectHorse(int _id) { selectHorse = _id; RoleParticularModel.ViewPlayerData data = model.GetViewPlayerData(model.viewPlayer); if (data == null) { return; } var horses = data.rolePlusData.horses; var horse = horses.Find((x) => { return x.id == selectHorse; }); if (!horse.Equals(default(RoleParticularModel.HorseInfo))) { DisplaySkills(horse.id, horse.lv); DisplayModel(horse.id); } m_Controller.m_Scorller.RefreshActiveCellViews(); } void DisplayProperty(List horses) { Dictionary dict = new Dictionary(); model.GetHorseProperty(horses, ref dict); var index = 0; foreach (var key in dict.Keys) { if (index < m_Propertys.Length) { m_Propertys[index].gameObject.SetActive(true); m_Propertys[index].Display(key, dict[key]); } index++; } for (int i = index; i < m_Propertys.Length; i++) { m_Propertys[i].gameObject.SetActive(false); } } private void OnHorseStone() { model.viewPetStone = false; WindowCenter.Instance.Open(); } void DisplaySkills(int id, int lv) { HorseUpConfig.GetHorseSkills(id, lv, false, ref skills); for (int i = 0; i < m_HorseSkills.Length; i++) { if (i < skills.Count) { m_HorseSkills[i].SetActive(true); var condition = HorseUpConfig.GetSkillCondition(id, skills[i]); m_HorseSkills[i].Display(id, skills[i], lv >= condition ? 0 : condition); } else { m_HorseSkills[i].SetActive(false); } } } void DisplayTotalSkills(List horses) { displayTotalSkills.Clear(); unlockTotalSkills.Clear(); for (int i = 0; i < horses.Count; i++) { HorseUpConfig.GetHorseSkills(horses[i].id, horses[i].lv, true, ref skills); unlockTotalSkills.AddRange(skills); foreach (var id in skills) { var config = SkillConfig.Get(id); var effect = SkillConfig.GetSkillEffectValue(config); var skillId = 0; if (mountModel.TryGetIntegrationSkill(effect, out skillId)) { if (!displayTotalSkills.Contains(skillId)) { displayTotalSkills.Add(skillId); } continue; } displayTotalSkills.Add(id); } } displayTotalSkills.Sort(Compare); m_SkillController.Refresh(); var line = Mathf.CeilToInt((float)displayTotalSkills.Count / m_LineCount); for (int i = 0; i < line; i++) { m_SkillController.AddCell(ScrollerDataType.Header, i); } m_SkillController.Restart(); } void DisplayModel(int id) { m_RawModel.gameObject.SetActive(true); var config = HorseConfig.Get(id); UI3DModelExhibition.Instance.ShowHourse(config.Model, m_RawModel); if (UI3DModelExhibition.Instance.NpcModelHorse != null) { var animator = UI3DModelExhibition.Instance.NpcModelHorse.GetComponent(); if (animator != null) { animator.Play(GAStaticDefine.State_Dance); } } } private void OnRefreshCell(ScrollerDataType type, CellView cell) { var lv = cell.info.HasValue ? cell.info.Value.infoInt1 : 0; ViewHorseSelectCell selectCell = cell as ViewHorseSelectCell; selectCell.Display(cell.index, lv, this); } private void OnRefreshSkillCell(ScrollerDataType type, CellView cell) { var line = cell.index; ViewHorseSkillCell skillCell = cell as ViewHorseSkillCell; skillCell.Display(line, this); } int Compare(int lhs, int rhs) { var lhs_config = SkillConfig.Get(lhs); var rhs_config = SkillConfig.Get(rhs); var lhs_Id = 0; var rhs_Id = 0; var lhs_effect = SkillConfig.GetSkillEffectValue(lhs_config); var rhs_effect = SkillConfig.GetSkillEffectValue(rhs_config); var lhs_integration = mountModel.TryGetIntegrationSkill(lhs_effect, out lhs_Id); var rhs_integration = mountModel.TryGetIntegrationSkill(rhs_effect, out rhs_Id); if (lhs_integration != rhs_integration) { return -lhs_integration.CompareTo(rhs_integration); } if (lhs_integration && rhs_integration) { return lhs_config.Effect1.CompareTo(rhs_config.Effect1); } var lhs_horseInfo = mountModel.GetMountSkillAndItem[lhs]; var rhs_horseInfo = mountModel.GetMountSkillAndItem[rhs]; if (lhs_horseInfo.HorseID != rhs_horseInfo.HorseID) { return lhs_horseInfo.HorseID.CompareTo(rhs_horseInfo.HorseID); } if (lhs_horseInfo.HorseLV.CompareTo(rhs_horseInfo.HorseLV) != 0) { return lhs_horseInfo.HorseLV.CompareTo(rhs_horseInfo.HorseLV); } return 0; } [Serializable] public class HorseSkill { [SerializeField] RectTransform m_Container; [SerializeField] Button m_SkillBtn; [SerializeField] RectTransform m_ContainerLock; [SerializeField] Text m_Condition; [SerializeField] Image m_SkillIcon; [SerializeField] UIEffect m_Effect; int horseId = 0; int skillId = 0; public void Display(int id, int _skillId, int condition) { var config = SkillConfig.Get(_skillId); if (config != null) { m_SkillIcon.SetSprite(config.IconName); } horseId = id; skillId = _skillId; m_ContainerLock.gameObject.SetActive(condition > 0); if (condition > 0) { m_Condition.text = Language.Get("LoadIconLV", condition); } m_SkillBtn.RemoveAllListeners(); m_SkillBtn.AddListener(OnClickSkill); m_Effect.StopImediatly(); var model = ModelCenter.Instance.GetModel(); if (model.ListEffectSkill != null && model.ListEffectSkill.Contains(_skillId)) { m_Effect.Play(); } } private void OnClickSkill() { var config = HorseConfig.Get(horseId); var skillConfig = SkillConfig.Get(skillId); var label1 = skillConfig.Description; var label2 = Language.Get("pet_SkillTipLv", config.Name, HorseUpConfig.GetSkillCondition(horseId, skillId)); SkillDetails.ShowSkillDetails(skillId, SkillDetails.SkillSourceType.ViewHorsePet, skillConfig.FightPower, label1, label2); } public void SetActive(bool active) { m_Container.gameObject.SetActive(active); } } } }