//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Friday, January 05, 2018 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using TableConfig; using System.Collections.Generic; using System; using Snxxz.UI; using EnhancedUI.EnhancedScroller; //坐骑属性面板赋值赋值 namespace Snxxz.UI { public class MountPanelAssignment : MonoBehaviour { [SerializeField] RawImage m_MountRawImg; [SerializeField] Text m_HpTxt;//当前生命 [SerializeField] Text m_AtkTxt;//当前攻击 [SerializeField] Text m_SpeedTxt;//当前速度 [SerializeField] Text m_PutTxt;//战斗力 [SerializeField] RedpointBehaviour m_RedPointJH;//激活红点 [SerializeField] UIEffect m_Uieffect3;//经验条特效 [SerializeField] Transform GroupSkill; [SerializeField] GameObject m_YiJieSuo;//解锁面板 [SerializeField] GameObject m_BottomOperate;//关于经验条 [SerializeField] Text m_MountLVNum; [SerializeField] Text m_ExpNum; [SerializeField] IntensifySmoothSlider m_IntensifySmoothSlider; [SerializeField] GameObject m_WeiJieSuo;//未解锁面板 [SerializeField] Button m_NotUnlockButton; [SerializeField] Image m_NotUnlockImageBG; [SerializeField] Image m_ImmageBG;//背景框品质 [SerializeField] Text m_NotUnlockTxt; [SerializeField] GameObject m_ManJie;//满阶面板 [SerializeField] GameObject m_Deblocking;//激活按钮 [SerializeField] GameObject m_TrainButtonGroup;//已激活按钮组 [SerializeField] GameObject m_TrainBtn_1;//一倍驯养 [SerializeField] RedpointBehaviour m_Redpoint_1; [SerializeField] Image IconImage1; [SerializeField] Text m_Text1; [Header("控制绳子")] [SerializeField] GameObject Skillimage1; [SerializeField] GameObject Skillimage2; [SerializeField] GameObject Skillimage3; private float timePlay = 0;//坐骑动作播放时间 List Skillimage = new List(); [SerializeField] ScrollerController allPetSkillCtrl;//所有的技能 private int mount_ID = 0;//用来标记坐骑的ID PlayerMountDatas m_MountModel; PlayerMountDatas mountModel { get { return m_MountModel ?? (m_MountModel = ModelCenter.Instance.GetModel()); } } GetItemPathModel _GetItemPath; GetItemPathModel GetItemPath { get { return _GetItemPath ?? (_GetItemPath = ModelCenter.Instance.GetModel()); } } PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } RidingAndPetActivationModel ridingModel { get { return ModelCenter.Instance.GetModel(); } } private int pitchOnHorseID = 0; private void Start() { Skillimage.Clear(); Skillimage.Add(Skillimage1); Skillimage.Add(Skillimage2); Skillimage.Add(Skillimage3); m_NotUnlockButton.AddListener(OnClickNotUnlockButton); } private void OnEnable() { PlayerMountDatas.Event_MountHA301U += OnMountHA301Update; allPetSkillCtrl.OnRefreshCell += RefreshAllMountSkillCell; FlySkillIconWin.FlySkillID += FlySkillID; CreateAllMountSkill(); } private void OnDisable() { mount_ID = 0; PlayerMountDatas.Event_MountHA301U -= OnMountHA301Update; allPetSkillCtrl.OnRefreshCell -= RefreshAllMountSkillCell; FlySkillIconWin.FlySkillID -= FlySkillID; m_MountRawImg.gameObject.SetActive(false); } private void LateUpdate() { timePlay += Time.deltaTime; if (timePlay >= GeneralConfig.Instance.PetDanceInterval) { timePlay = 0; if (UI3DModelExhibition.Instance.NpcModelHorse != null) { var animator = UI3DModelExhibition.Instance.NpcModelHorse.GetComponent(); if (animator != null) { StartCoroutine("FrameDelay"); } } } } IEnumerator FrameDelay() { yield return null; if (UI3DModelExhibition.Instance.NpcModelHorse != null) { var animator = UI3DModelExhibition.Instance.NpcModelHorse.GetComponent(); animator.Play(GAStaticDefine.State_Dance); } } private void FlySkillID(int skillID) { int Index = 0; Index = GetAllMountSkill.FindIndex((x) => { return x.SkillID == skillID; }); if (Index == -1) { Index = 0; } int line = Index / 3; allPetSkillCtrl.JumpIndex(line); allPetSkillCtrl.JumpIndex(-50, 0, EnhancedScroller.TweenType.immediate); } private void OnMountHA301Update(int _HorseID) { m_Uieffect3.Play(); SoundPlayer.Instance.PlayUIAudio(19); ToAddSorting(); allPetSkillCtrl.m_Scorller.RefreshActiveCellViews(); if (pitchOnHorseID != 0 && pitchOnHorseID!= _HorseID) { PanelAssignment(pitchOnHorseID); } else { PanelAssignment(_HorseID); } } private void OnClickDeblockingButton() { FuncConfigConfig _tagfun = Config.Instance.Get("HorseUpItem"); ItemConfig _tagchine = Config.Instance.Get(int.Parse(_tagfun.Numerical1)); GetItemPath.SetChinItemModel(_tagchine.ID); } private void OnClickNotUnlockButton() { HorseConfig _Horse = Config.Instance.Get(pitchOnHorseID); ItemConfig _item = Config.Instance.Get(_Horse.UnlockItemID); GetItemPath.SetPetMatUnlockModel(_item.ID); } public void PanelAssignment(int mountID) { pitchOnHorseID = mountID; MountAttribute(mountID); PanelClassify(mountID); ShowHorse(mountID); MountSkill(mountID); TheMountButton(); if (WindowCenter.Instance.Get().AchievementGuideEffect2 != null) { AchievementGuideEffectPool.Recycle(WindowCenter.Instance.Get().AchievementGuideEffect2); } } private void ShowHorse(int HorseID) { if (!m_MountRawImg.gameObject.activeSelf) { m_MountRawImg.gameObject.SetActive(true); } if (HorseID != mount_ID) { HorseConfig _model = Config.Instance.Get(HorseID); UI3DModelExhibition.Instance.BeginShowHourse(_model.Model, m_MountRawImg); mount_ID = HorseID; if (UI3DModelExhibition.Instance.NpcModelHorse != null) { var animator = UI3DModelExhibition.Instance.NpcModelHorse.GetComponent(); if (animator != null) { if (this.gameObject.activeInHierarchy) { StartCoroutine("FrameDelay"); } else { animator.Play(GAStaticDefine.State_Dance); } } } } } private void MountAttribute(int mountID)//坐骑属性面板赋值 { //Dictionary dicStone = Bonuses(); int _HPP = 0;//生命 int _AttT = 0;//攻击 int _SpeE = 0;//速度 Dictionary addAttrDict510 = ridingModel.GetAllMountProperty(); Dictionary addAttrDict511 = ridingModel.GetAllMountPropertyQuality(); if (mountModel._DicHorse.Count == 0) { m_HpTxt.text = (_HPP /*+ dicStone[6]*/).ToString(); m_AtkTxt.text = (_AttT /*+ dicStone[7]*/).ToString(); m_SpeedTxt.text = _SpeE.ToString(); m_PutTxt.text = "0"; } else { foreach (int key in mountModel._DicHorse.Keys) { HorseUpConfig tagMode = HorseUpConfig.GetHorseIDAndLV(key, mountModel._DicHorse[key].Lv); string[] str = ConfigParse.GetMultipleStr(tagMode.AttrValue); if (str.Length != 0) { _HPP += int.Parse(str[0]); _AttT += int.Parse(str[1]); if (int.Parse(str[2]) > _SpeE) { _SpeE = int.Parse(str[2]); } } } float addHp = 0; float addAtk = 0; if (addAttrDict510.ContainsKey((int)AttrEnum.HP)) { addHp += addAttrDict510[(int)AttrEnum.HP]; } if (addAttrDict511.ContainsKey((int)AttrEnum.HP)) { addHp += addAttrDict511[(int)AttrEnum.HP]; } if (addAttrDict510.ContainsKey((int)AttrEnum.ATK)) { addAtk += addAttrDict510[(int)AttrEnum.ATK]; } if (addAttrDict511.ContainsKey((int)AttrEnum.ATK)) { addAtk += addAttrDict511[(int)AttrEnum.ATK]; } m_HpTxt.text = ((int)(_HPP /*+ dicStone[6]*/ + addHp)).ToString(); m_AtkTxt.text = ((int)(_AttT /*+ dicStone[7]*/ + addAtk)).ToString(); m_SpeedTxt.text = _SpeE.ToString(); int fightNumberA = 0; foreach (int key in mountModel.GetMountSkillAndItem.Keys) { fightNumberA += fightNumber(key); } int initialForce = 0; foreach (var key in mountModel._DicHorse.Keys) { HorseConfig horseConfig = Config.Instance.Get(key); initialForce += horseConfig.InitFightPower; } Dictionary AddPowerDic = new Dictionary(); AddPowerDic.Clear(); AddPowerDic.Add(6, (_HPP /*+ dicStone[6]*/)); AddPowerDic.Add(7, (_AttT /*+ dicStone[7]*/)); int AddPower = UIHelper.GetFightPower(AddPowerDic); m_PutTxt.text = (fightNumberA + AddPower + initialForce).ToString(); } } Dictionary Bonuses()//属性加成 { Dictionary dic = new Dictionary(); dic.Clear(); dic.Add(6, 0);//生命 dic.Add(7, 0);//攻击 dic.Add(8, 0);//防御 foreach (int key in mountModel._DicMountItem.Keys) { if (mountModel._DicMountItem[key] != 0) { ItemConfig itemModel = Config.Instance.Get(key); if (dic.ContainsKey(itemModel.Effect1)) { dic[itemModel.Effect1] += itemModel.EffectValueA1 * mountModel._DicMountItem[key]; } if (dic.ContainsKey(itemModel.Effect2)) { dic[itemModel.Effect2] += itemModel.EffectValueA2 * mountModel._DicMountItem[key]; } if (dic.ContainsKey(itemModel.Effect3)) { dic[itemModel.Effect3] += itemModel.EffectValueA3 * mountModel._DicMountItem[key]; } if (dic.ContainsKey(itemModel.Effect4)) { dic[itemModel.Effect4] += itemModel.EffectValueA4 * mountModel._DicMountItem[key]; } if (dic.ContainsKey(itemModel.Effect5)) { dic[itemModel.Effect5] += itemModel.EffectValueA5 * mountModel._DicMountItem[key]; } } } return dic; } private void PanelClassify(int mountID)//面板分类 { if (WindowCenter.Instance.Get().AchievementGuideEffect1 != null) { AchievementGuideEffectPool.Recycle(WindowCenter.Instance.Get().AchievementGuideEffect1); } if (mountModel._DicHorse.ContainsKey(mountID)) { var configHorse = Config.Instance.Get(mountID); if (mountModel._DicHorse[mountID].Lv >= configHorse.MaxLV) { m_ManJie.SetActive(true); m_YiJieSuo.SetActive(false); m_WeiJieSuo.SetActive(false); m_Deblocking.SetActive(false); m_TrainButtonGroup.SetActive(false); //满阶 } else { IsExpSlider(mountID); m_YiJieSuo.SetActive(true); m_WeiJieSuo.SetActive(false); m_ManJie.SetActive(false); m_Deblocking.SetActive(false); m_TrainButtonGroup.SetActive(true); m_Redpoint_1.redpointId = mountModel.ASingleFeedRedPoint[mountID].id; //为满街 } } else { m_RedPointJH.redpointId = mountModel.DeblockingRedPoint[mountID].id; m_WeiJieSuo.SetActive(true); m_ManJie.SetActive(false); m_YiJieSuo.SetActive(false); m_Deblocking.SetActive(true); m_TrainButtonGroup.SetActive(false); HorseConfig _Horse = Config.Instance.Get(mountID); ItemConfig _item = Config.Instance.Get(_Horse.UnlockItemID); m_NotUnlockImageBG.SetSprite(_item.IconKey); m_ImmageBG.SetItemBackGround(_item.ItemColor); int UnlockItemID = Config.Instance.Get(mountID).UnlockItemID; int MaterialNumber = playerPack.GetItemCountByID(PackType.rptItem, UnlockItemID);//获取背包解锁材料的数量 int UnlockItemCnt = Config.Instance.Get(mountID).UnlockItemCnt; if (MaterialNumber >= UnlockItemCnt) { m_NotUnlockTxt.text = "" + MaterialNumber + "/" + UnlockItemCnt + ""; } else { m_NotUnlockTxt.text = "" + MaterialNumber + "" + "/" + UnlockItemCnt + ""; } } } private void IsExpSlider(int mountID) { if (mountModel._DicHorse.ContainsKey(mountID)) { m_BottomOperate.SetActive(true); int horseMaxLv = Config.Instance.Get(mountID).MaxLV; if (mountModel._DicHorse[mountID].Lv >= horseMaxLv) { m_ExpNum.text = Language.Get("Z1029"); m_IntensifySmoothSlider.stage = mountModel._DicHorse[mountID].Lv; m_IntensifySmoothSlider.value = 1f; m_IntensifySmoothSlider.delay = 0f; m_IntensifySmoothSlider.ResetStage(); } else { int exp = mountModel._DicHorse[mountID].Exp; HorseUpConfig horseUp = HorseUpConfig.GetHorseIDAndLV(mountID, mountModel._DicHorse[mountID].Lv); int expMax = horseUp.NeedExp; m_ExpNum.text = exp + "/" + expMax; if (mount_ID != mountID) { m_IntensifySmoothSlider.stage = mountModel._DicHorse[mountID].Lv; m_IntensifySmoothSlider.delay = 0f; m_IntensifySmoothSlider.ResetStage(); m_IntensifySmoothSlider.value = (float)Math.Round((float)exp / expMax, 2, MidpointRounding.AwayFromZero); } else { m_IntensifySmoothSlider.delay = 0.1f; m_IntensifySmoothSlider.stage = mountModel._DicHorse[mountID].Lv; m_IntensifySmoothSlider.value = (float)Math.Round((float)exp / expMax, 2, MidpointRounding.AwayFromZero); } } m_MountLVNum.text = mountModel._DicHorse[mountID].Lv + Language.Get("Z1041"); } else { m_BottomOperate.SetActive(false); } } List MountSkills = new List(); private void MountSkill(int HorseID)//关于坐骑技能 { MountSkills.Clear(); foreach (var key in mountModel.GetMountSkillAndItem.Keys) { if (mountModel.GetMountSkillAndItem[key].HorseID == HorseID) { MountSkills.Add(mountModel.GetMountSkillAndItem[key]); } } for (int i = 0; i < Skillimage.Count; i++) { Skillimage[i].SetActive(false); } for (int i = 0; i < GroupSkill.childCount; i++) { if (i < MountSkills.Count) { if (i < Skillimage.Count) { Skillimage[i].SetActive(true); } GroupSkill.GetChild(i).gameObject.SetActive(true); UIEffect uie = GroupSkill.GetChild(i).GetComponent(); if (mountModel.ListEffectSkill.Contains(MountSkills[i].SkillID)) { if (!uie.IsPlaying) { uie.Play(); } } else { if (uie.IsPlaying) { uie.Stop(); } } SkillButtonPet mountSkill = GroupSkill.GetChild(i).gameObject.GetComponent(); int curMountLv = 0; if (mountModel._DicHorse.ContainsKey(MountSkills[i].HorseID)) { curMountLv = mountModel._DicHorse[MountSkills[i].HorseID].Lv; } if (curMountLv >= MountSkills[i].HorseLV) { mountSkill.SetModel(MountSkills[i].SkillID, MountSkills[i].HorseLV, true, HorseID, SkillType.MountSkill); } else { mountSkill.SetModel(MountSkills[i].SkillID, MountSkills[i].HorseLV, false, HorseID, SkillType.MountSkill); } } else { GroupSkill.GetChild(i).gameObject.SetActive(false); } } } List GetAllMountSkill = new List(); private void CreateAllMountSkill()//所有坐骑技能 { GetAllMountSkill.Clear(); foreach (int key in mountModel.GetMountSkillAndItem.Keys) { GetAllMountSkill.Add(mountModel.GetMountSkillAndItem[key]); } ToAddSorting(); allPetSkillCtrl.Refresh(); int line = GetAllMountSkill.Count / 3; int remain = GetAllMountSkill.Count % 3; if (remain > 0) { line += 1; } for (int i = 0; i < line; i++) { allPetSkillCtrl.AddCell(ScrollerDataType.Header, i); } allPetSkillCtrl.Restart(); } void ToAddSorting() { GetAllMountSkill.Sort(Compare); } int Compare(HorseSkillClass x, HorseSkillClass y) { bool havex = IsDeblocking(x.SkillID); bool havey = IsDeblocking(y.SkillID); if (havex.CompareTo(havey) != 0) { return -havex.CompareTo(havey); } if (x.HorseID.CompareTo(y.HorseID) != 0) { return x.HorseID.CompareTo(y.HorseID); } if (x.HorseLV.CompareTo(y.HorseLV) != 0) { return x.HorseLV.CompareTo(y.HorseLV); } return 1; } private bool IsDeblocking(int SkillID)//是否解锁 { if (mountModel.GetMountSkillAndItem.ContainsKey(SkillID)) { int mountID = mountModel.GetMountSkillAndItem[SkillID].HorseID; int mountLv = mountModel.GetMountSkillAndItem[SkillID].HorseLV; if (mountModel._DicHorse.ContainsKey(mountID) && mountModel._DicHorse[mountID].Lv >= mountLv) { return true; } else { return false; } } else { return false; } } private void RefreshAllMountSkillCell(ScrollerDataType type, CellView cell) { int length = cell.transform.childCount; for (int i = 0; i < length; i++) { int cellCnt = cell.index * 3 + (i + 1); SkillButtonPet skillButton = cell.transform.GetChild(i).GetComponent(); FunctionUnlockFlyObjectTarget functionUnlockFlyObjectTarget = cell.transform.GetChild(i).GetComponent(); if (cellCnt <= GetAllMountSkill.Count) { skillButton.gameObject.SetActive(true); HorseSkillClass horseSkillClass = GetAllMountSkill[cellCnt - 1]; skillButton.SetModel(horseSkillClass.SkillID, horseSkillClass.HorseLV, IsDeblocking(horseSkillClass.SkillID), horseSkillClass.HorseID, SkillType.MountSkill, true); functionUnlockFlyObjectTarget.IdList = new int[] { horseSkillClass.SkillID }; functionUnlockFlyObjectTarget.Z_UnLockType = FunctionUnlockType.Skill; FunctionUnlockFlyObjectTargetCenter.Register(FunctionUnlockType.Skill, new int[] { horseSkillClass.SkillID }, functionUnlockFlyObjectTarget); } else { skillButton.gameObject.SetActive(false); } } } private void TheMountButton() { FuncConfigConfig _tagfun = Config.Instance.Get("HorseUpItem"); ItemConfig _tagchine = Config.Instance.Get(int.Parse(_tagfun.Numerical1)); IconImage1.SetSprite(_tagchine.IconKey); int mountDanNum = playerPack.GetItemCountByID(PackType.rptItem, int.Parse(_tagfun.Numerical1)); m_Text1.text = string.Format(Language.Get("Remaining_Z1"), mountDanNum); } private int fightNumber(int SkillID) { int fightNum = 0; if (IsDeblocking(SkillID)) { SkillConfig skillconfig = Config.Instance.Get(SkillID); fightNum = skillconfig.FightPower; } return fightNum; } } }