using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class EquipGemSelectWin : Window { [SerializeField] ScrollerController m_SrollerControl; [SerializeField] Button m_Strike; [SerializeField] Button m_Close; PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } EquipGemModel model { get { return ModelCenter.Instance.GetModel(); } } EquipModel equipModel { get { return ModelCenter.Instance.GetModel(); } } public static GemEquipType gemEquipType = GemEquipType.MultiEquip; public static int equipLevel = 0; public static int equipPlace = 0; public static int equipHole = 0; static List itemGuids = new List(); bool inlayAble = false; #region Built-in protected override void BindController() { } protected override void AddListeners() { m_SrollerControl.OnRefreshCell += OnRefreshCell; m_Close.AddListener(OnClose); m_Strike.AddListener(OnStrikeBtn); } protected override void OnPreOpen() { Display(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { } protected override void OnAfterClose() { } #endregion void Display() { m_SrollerControl.Refresh(); int equipGem = 0; int[] equipGems = null; if (model.TryGetEquipGems(equipLevel, equipPlace, out equipGems)) { if (equipHole < equipGems.Length) { equipGem = equipGems[equipHole]; } } inlayAble = false; EquipGemRedpoint equipGemRedpoint; if (model.TryGetRedpoint(equipLevel, equipPlace, out equipGemRedpoint)) { var inlayRedpoint = equipGemRedpoint.GetInlayRedpoint(equipHole); inlayAble = inlayRedpoint.state == RedPointState.Simple; } m_Strike.SetActive(equipGem != 0); var isMaxLevel = model.IsEquipGemMaxLevel(equipGem); if (equipGem != 0 && !isMaxLevel) { m_SrollerControl.AddCell(ScrollerDataType.Header, 0, HandleGem); } if (equipGem != 0 && isMaxLevel) { m_SrollerControl.AddCell(ScrollerDataType.Extra2, 0, HandleGem); } itemGuids = model.GetSatisfyEquipGemGuids(equipPlace); if (itemGuids != null) { itemGuids.Sort(model.Compare); for (int i = 0; i < itemGuids.Count; i++) { m_SrollerControl.AddCell(ScrollerDataType.Normal, i, HandleGem); } } List gemTypes = null; if (model.TryGetGemTypes(equipPlace, out gemTypes)) { foreach (var type in gemTypes) { GemType gemType; if (model.TryGetGemType(type, out gemType)) { if (equipGem == 0 && gemType.shopItemId != 0) { m_SrollerControl.AddCell(ScrollerDataType.Tail, type, HandleGem); } } } foreach (var type in gemTypes) { GemType gemType; if (model.TryGetGemType(type, out gemType)) { if (gemType.getWays != null) { foreach (var getWay in gemType.getWays) { if (getWay != 0) { m_SrollerControl.AddCell(ScrollerDataType.Extra1, getWay * 100 + type, HandleGem); } } } } } } m_SrollerControl.Restart(); } void HandleGem(CellView cell) { switch (cell.type) { case ScrollerDataType.Header: CloseImmediately(); LevelUpGem(); break; case ScrollerDataType.Normal: var index = cell.index; if (index < itemGuids.Count) { OnInlayGem(itemGuids[index]); } CloseImmediately(); break; case ScrollerDataType.Tail: CloseImmediately(); ItemConfig itemConfig = ItemConfig.GetGemDataByLevelAndType(1, cell.index); var goodsConfig = StoreConfig.GetStoreCfgByItemIDEx(itemConfig.ID, 1); if (goodsConfig != null) { var storeModel = ModelCenter.Instance.GetModel(); storeModel.SetJumpToModel(itemConfig.ID); if (goodsConfig.SecondType.Length > 0) storeModel.selectSecondType = goodsConfig.SecondType[0]; } WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.StoreFunc3); break; case ScrollerDataType.Extra1: var getWay = cell.index / 100; CloseImmediately(); var config = GetItemWaysConfig.Get(getWay); if (config != null) { WindowJumpMgr.Instance.WindowJumpTo((JumpUIType)config.OpenpanelId); } break; } } void OnStrikeBtn() { var equipPosition = new Int2(equipLevel, equipPlace); var equipGuid = equipModel.GetEquip(equipPosition); if (string.IsNullOrEmpty(equipGuid)) { return; } var _pak = new CA305_tagCMEquipStonePick(); _pak.EquipIndex = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition); _pak.HoleIndex = equipHole == 3 ? (byte)10 : (byte)equipHole; GameNetSystem.Instance.SendInfo(_pak); CloseImmediately(); } void LevelUpGem() { var equipPosition = new Int2(equipLevel, equipPlace); var equipGuid = equipModel.GetEquip(equipPosition); if (string.IsNullOrEmpty(equipGuid)) { return; } int equipGem; if (!model.TryGetEquipGem(equipLevel, equipPlace, equipHole, out equipGem)) { return; } if (model.IsEquipGemMaxLevel(equipGem)) { SysNotifyMgr.Instance.ShowTip("GemFullLevelError"); return; } EquipGemLevelUpWin.equipLevel = equipLevel; EquipGemLevelUpWin.equipHole = equipHole; EquipGemLevelUpWin.equipPlace = equipPlace; EquipGemLevelUpWin.equipType = gemEquipType; WindowCenter.Instance.Open(); } void OnInlayGem(string guid) { var equipPosition = new Int2(equipLevel, equipPlace); var equipGuid = equipModel.GetEquip(equipPosition); if (string.IsNullOrEmpty(equipGuid)) { return; } var item = packModel.GetItemByGuid(guid); CA304_tagCMEquipEnchase _pak = new CA304_tagCMEquipEnchase(); _pak.HoleIndex = equipHole == 3 ? (byte)10 : (byte)equipHole; _pak.StoneIndex = (byte)item.gridIndex; _pak.EquipIndex = (byte)EquipPlaceMapConfig.GetServerPlace(equipLevel, equipPlace); GameNetSystem.Instance.SendInfo(_pak); CloseClick(); } private void OnClose() { CloseImmediately(); } private void OnRefreshCell(ScrollerDataType type, CellView _cell) { switch (type) { case ScrollerDataType.Header: { var cell = _cell as EquipGemLevelUpCell; int[] equipGems; if (model.TryGetEquipGems(equipLevel, equipPlace, out equipGems)) { if (equipHole < equipGems.Length) { cell.Display(equipGems[equipHole]); } } } break; case ScrollerDataType.Normal: { var cell = _cell as EquipGemItemCell; var index = cell.index; if (index < itemGuids.Count) { cell.Display(itemGuids[index], inlayAble && index == 0); } } break; case ScrollerDataType.Tail: { var cell = _cell as EquipGemShopCell; cell.Display(cell.index); } break; case ScrollerDataType.Extra1: { var getWay = _cell.index / 100; var gemType = _cell.index % 100; var cell = _cell as EquipGemGetWayCell; cell.Display(gemType, getWay); } break; case ScrollerDataType.Extra2: { var cell = _cell as EquipGemFlauntCell; int[] equipGems; if (model.TryGetEquipGems(equipLevel, equipPlace, out equipGems)) { if (equipHole < equipGems.Length) { cell.Display(equipGems[equipHole]); } } } break; } } bool IsBestGem(int itemId, List list) { var config = ItemConfig.Get(itemId); for (int i = 0; i < list.Count; i++) { var compareItem = list[i]; var compareConfig = ItemConfig.Get(compareItem.itemId); if (compareConfig.EffectValueB1 > config.EffectValueB1) { return false; } } return true; } } }