//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Monday, March 11, 2019 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class EquipStrengthWin : Window { [SerializeField] ScrollerController m_Controller; [SerializeField] Transform m_ContainerStrength; [SerializeField] Transform m_ContainerEmpty; [SerializeField] GameObject m_NotEquipped;//未装备 [SerializeField] EquipStrengthFull m_EquipStrengthFull;//满级 [SerializeField] EquipStrengthUpper m_EquipStrengthUpper;//强化上限 [SerializeField] EquipStrengthRein m_EquipStrengthRein;//可强化 [SerializeField] EquipEvolution m_EquipEvolution;//进阶 [SerializeField] GameObject m_BottomFrame; [SerializeField] Button m_StrengBtn; [SerializeField] Button m_AutomaticBtn; [SerializeField] Button m_StopBtn; [SerializeField] UIEffect m_UIEffect1A; [SerializeField] UIEffect m_UIEffect1B; [SerializeField] UIEffect m_UIEffect1C; EquipStrengthModel model { get { return ModelCenter.Instance.GetModel(); } } EquipGemModel equipGemModel { get { return ModelCenter.Instance.GetModel(); } } EquipModel equipModel { get { return ModelCenter.Instance.GetModel(); } } PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } EquipStarModel equipStarModel { get { return ModelCenter.Instance.GetModel(); } } private bool IsAutomaticBool = false; private float WaitTime = 0.1f; private float Times = 0f; #region Built-in protected override void BindController() { } protected override void AddListeners() { m_Controller.OnRefreshCell += OnRefreshCell; m_StrengBtn.AddListener(OnClickStrengBtn); m_AutomaticBtn.AddListener(OnClickAutomaticBtn); m_StopBtn.AddListener(OnClickStopBtn); } protected override void OnPreOpen() { model.IsChangeBool = true; IsAutomaticBool = false; Times = 0f; m_StopBtn.gameObject.SetActive(false); m_AutomaticBtn.gameObject.SetActive(true); OpenSelect();//默认选择 DisplayEquips(); SetStrengthenedState(); model.SelectEquipRefresh += SelectEquipRefresh; model.SelectLevelRefresh += SelectLevelRefresh; model.EquipStrengthUpdate += EquipStrengthUpdate; model.EquipStrengthLvUpdate += EquipStrengthLvUpdate; PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshEvent; m_Controller.JumpIndex(GetJumpIndex(model.SelectLevel, model.SelectEquipPlace)); } protected override void OnAfterOpen() { } protected override void OnPreClose() { model.SelectEquipRefresh -= SelectEquipRefresh; model.SelectLevelRefresh -= SelectLevelRefresh; model.EquipStrengthUpdate -= EquipStrengthUpdate; model.EquipStrengthLvUpdate -= EquipStrengthLvUpdate; PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent; } protected override void OnAfterClose() { } protected override void LateUpdate() { if (IsAutomaticBool) { Times += Time.deltaTime; var isBool = StrengtheBool(); var upperLimitBool = UpperLimitBool(); if (Times >= WaitTime && isBool && upperLimitBool) { Times = 0; int itemIndex = EquipPlaceMapConfig.GetServerPlace(model.SelectLevel, model.SelectEquipPlace); model.SendEquip(itemIndex); } else if (!isBool || !upperLimitBool) { IsAutomaticBool = false; OnClickStopBtn(); } } else { Times = 0f; } } #endregion int GetJumpIndex(int selectLevel, int selectPlace) { var jumpIndex = 0; var equipSets = equipModel.GetAllEquipSets(); foreach (var level in equipSets) { if (level > selectLevel) { return jumpIndex; } var equipSet = equipModel.GetEquipSet(level); if (equipSet == null) { continue; } if (equipSet.unLocked) { var slotCount = equipGemModel.GetUnlockEquipSlotCount(level); if (slotCount > 0) { jumpIndex++; if (equipGemModel.selectLevel == level) { var places = equipGemModel.GetMosaicEquipPlaces(); foreach (var place in places) { if (equipSet.IsSlotUnLocked(place)) { if (selectLevel == level && selectPlace == place) { return jumpIndex; } jumpIndex++; } } } } } } return 0; } private void OnClickStrengBtn() { if (StrengtheBool()) { int itemIndex = EquipPlaceMapConfig.GetServerPlace(model.SelectLevel, model.SelectEquipPlace); model.SendEquip(itemIndex); } } private void OnClickAutomaticBtn() { if (StrengtheBool()) { IsAutomaticBool = true; m_StopBtn.gameObject.SetActive(true); m_AutomaticBtn.gameObject.SetActive(false); } } private void OnClickStopBtn() { IsAutomaticBool = false; m_StopBtn.gameObject.SetActive(false); m_AutomaticBtn.gameObject.SetActive(true); } private void EquipStrengthLvUpdate() { if (!m_UIEffect1B.IsPlaying) { m_UIEffect1B.Play(); } } private void EquipStrengthUpdate() { if (!m_UIEffect1A.IsPlaying) { m_UIEffect1A.Play(); } m_UIEffect1C.Play(); if (model.SelectLevel != -1) { SetStrengthenedState(); m_Controller.m_Scorller.RefreshActiveCellViews(); } } void DisplayEquips() { m_Controller.Refresh(); var equipSets = equipModel.GetAllEquipSets(); foreach (var level in equipSets) { var equipSet = equipModel.GetEquipSet(level); if (equipSet == null) { continue; } if (equipSet.unLocked) { var slotCount = equipGemModel.GetUnlockEquipSlotCount(level); if (slotCount > 0) { m_Controller.AddCell(ScrollerDataType.Header, level); if (model.SelectLevel == level) { var places = equipGemModel.GetMosaicEquipPlaces(); foreach (var place in places) { if (equipSet.IsSlotUnLocked(place)) { m_Controller.AddCell(ScrollerDataType.Normal, level * 1000 + place); } } } } } } m_Controller.Restart(); } private void SelectEquipRefresh() { m_Controller.m_Scorller.RefreshActiveCellViews(); model.IsChangeBool = true; SetStrengthenedState(); if (IsAutomaticBool) { Times = 0f; OnClickStopBtn(); IsAutomaticBool = false; } } private void SelectLevelRefresh() { model.IsChangeBool = true; if (IsAutomaticBool) { Times = 0f; OnClickStopBtn(); IsAutomaticBool = false; } DisplayEquips(); SetStrengthenedState(); } private void OnRefreshCell(ScrollerDataType type, CellView cell) { switch (type) { case ScrollerDataType.Header: var equipGemHeadCell = cell as EquipStrengthHeadBehaviour; equipGemHeadCell.Display(cell.index); break; case ScrollerDataType.Normal: var level = cell.index / 1000; var place = cell.index % 1000; var equipSelectCell = cell as EquipStrengthSelectBehaviour; equipSelectCell.Display(level, place); break; } } private void SetStrengthenedState() { if (model.SelectLevel == -1) { m_ContainerEmpty.gameObject.SetActive(true); m_ContainerStrength.gameObject.SetActive(false); return; } m_ContainerEmpty.gameObject.SetActive(false); m_ContainerStrength.gameObject.SetActive(true); m_NotEquipped.SetActive(false); m_EquipStrengthFull.gameObject.SetActive(false); m_EquipStrengthUpper.gameObject.SetActive(false); m_EquipStrengthRein.gameObject.SetActive(false); m_EquipEvolution.gameObject.SetActive(false); int equipLevel = model.SelectLevel; int equipPlace = model.SelectEquipPlace; var equipSet = equipModel.GetEquipSet(equipLevel); string equipGuid = string.Empty; equipGuid = equipSet.GetEquip(equipPlace); var equiped = !string.IsNullOrEmpty(equipGuid); if (equiped) { int equipIndex = EquipPlaceMapConfig.GetServerPlace(equipLevel, equipPlace); var item = packModel.GetItemByGuid(equipGuid); var maxStar = EquipStarModel.GetMaxStarLevel(item.config.ItemColor, equipLevel); int star = Mathf.Min(maxStar, equipStarModel.GetStarLevel(new Int2(equipLevel, equipPlace))); int equipLv = 0; int advancedLv = 0; if (model.EquipStrengthDic.ContainsKey(equipIndex))//获取当前强化等级 { equipLv = model.EquipStrengthDic[equipIndex].StrengthLevel; advancedLv = model.EquipStrengthDic[equipIndex].EvolveLV; } int equipType = EquipStrengthModel.GetEquipStrengthType(equipPlace); var itemPlusMaxConfig = ItemPlusMaxConfig.GetEquipTypeAndEquipStar(equipType, star);//获取强化等级上限值 if (itemPlusMaxConfig == null) { DebugEx.LogError("未查找到表数据"); return; } int maxLv = model.GetEquipLevelMax(equipType, maxStar);//获取最大强化等级 m_EquipEvolution.gameObject.SetActive(true); m_EquipEvolution.SetEquipEvolution(equipPlace, advancedLv); if (equipLv >= maxLv)//满级 { m_BottomFrame.SetActive(false); m_EquipStrengthFull.gameObject.SetActive(true); m_EquipStrengthFull.SetEquipStrengthFull(equipGuid, equipLevel, equipPlace); } else if (maxLv > equipLv && equipLv >= itemPlusMaxConfig.levelMax)//强化上限 { m_BottomFrame.SetActive(true); m_EquipStrengthUpper.gameObject.SetActive(true); m_EquipStrengthUpper.SetEquipStrengthUpper(equipGuid, equipLevel, equipPlace); } else if (itemPlusMaxConfig.levelMax > equipLv)//可强化过 { m_BottomFrame.SetActive(true); m_EquipStrengthRein.gameObject.SetActive(true); m_EquipStrengthRein.SetEquipStrengthRein(equipGuid, equipLevel, equipPlace); } } else { m_BottomFrame.SetActive(false); m_NotEquipped.SetActive(true); } } private void OpenSelect() { model.SelectLevel = -1; model.SelectEquipPlace = -1; if (!model.jumpEquipPosition.Equals(Int2.zero)) { model.SelectLevel = model.jumpEquipPosition.x; model.SelectEquipPlace = model.jumpEquipPosition.y; model.jumpEquipPosition = Int2.zero; return; } var equipSets = equipModel.GetAllEquipSets(); foreach (var level in equipSets) { var equipSet = equipModel.GetEquipSet(level); if (equipSet == null) { continue; } if (equipSet.unLocked) { var slotCount = equipGemModel.GetUnlockEquipSlotCount(level); if (slotCount > 0) { if (model.SelectLevel == -1) { model.SelectLevel = level; } if (model.SelectLevel == level) { var places = equipGemModel.GetMosaicEquipPlaces(); foreach (var place in places) { if (model.SelectEquipPlace == -1) { model.SelectEquipPlace = place; } } } } } } } private bool StrengtheBool() { if (m_EquipStrengthUpper.gameObject.activeSelf) { int equipType = EquipStrengthModel.GetEquipStrengthType(model.SelectEquipPlace); var equipPosition = new Int2(model.SelectLevel, model.SelectEquipPlace); var star = equipStarModel.GetEquipStarLevel(equipPosition); var equipGuid = equipModel.GetEquip(equipPosition); var item = packModel.GetItemByGuid(equipGuid); var maxStar = EquipStarModel.GetMaxStarLevel(item.config.ItemColor, model.SelectEquipPlace); star = Mathf.Min(star, maxStar); var equipMaxLv = model.GetEquipLevelMax(equipType, star); SysNotifyMgr.Instance.ShowTip("EquipStrengthLimitError_1", star, equipMaxLv); return false; } var itemPlus = model.GetEquipConfig(model.SelectLevel, model.SelectEquipPlace); if (itemPlus == null) { return false; } ulong money = UIHelper.GetMoneyCnt(3); ulong needMoney = (ulong)itemPlus.costCount; if (money < needMoney) { ItemTipUtility.Show(2100); return false; } return true; } private bool UpperLimitBool() { bool isBool = false; var equipPosition = new Int2(model.SelectLevel, model.SelectEquipPlace); int equipIndex = EquipSet.ClientPlaceToServerPlace(equipPosition); int star = equipStarModel.GetStarLevel(equipPosition); int equipLv = 0; if (model.EquipStrengthDic.ContainsKey(equipIndex))//获取当前强化等级 { equipLv = model.EquipStrengthDic[equipIndex].StrengthLevel; } int equipType = EquipStrengthModel.GetEquipStrengthType(model.SelectEquipPlace); var itemPlusMaxConfig = ItemPlusMaxConfig.GetEquipTypeAndEquipStar(equipType, star);//获取强化等级上限值 if (itemPlusMaxConfig.levelMax > equipLv) { isBool = true; } else { isBool = false; } return isBool; } private void PlayerDataRefreshEvent(PlayerDataType dataType) { if (dataType == PlayerDataType.Silver) { m_EquipStrengthRein.DisplayMoney(); m_EquipStrengthUpper.DisplayMoney(); } } } }