using Snxxz.UI; using System; using System.Collections.Generic; using System.Linq; using TableConfig; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class ComposeEquipWin : Window { [SerializeField] ScrollerController cellCtrl; [SerializeField] ScrollerController equipTypeLineCellCtrl; [SerializeField] GameObject increaseRateItem; [SerializeField] GameObject increaseGridCell; [SerializeField] Text increaseText; [SerializeField] PushSwitchBtn switchBtn; [SerializeField] List sourceItemlist = new List(); [SerializeField] List previewItemlist = new List(); [SerializeField] Text successRateText; [SerializeField] Text dismantleText; [SerializeField] Button helpBtn; [SerializeField] Button composeBtn; [SerializeField] Button onekeyPutBtn; [SerializeField] GameObject notChooseBG; [SerializeField] GameObject chooseComposeEquip; [SerializeField] GameObject composeEquip; [SerializeField] UIEffect composeEffect; [SerializeField] UIEffect successEffect; [SerializeField] UIEffect failEffect; ComposeWinModel _composeWinModel; ComposeWinModel composeWinModel { get { return _composeWinModel ?? (_composeWinModel = ModelCenter.Instance.GetModel()); } } ItemTipsModel _itemTipsModel; ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel()); } } PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } GetItemPathModel ItemPathModel { get { return ModelCenter.Instance.GetModel(); } } ComposeWinModel.ComposeFirstTypeData firstTypeData; ComposeWinModel.ComposeSecondTypeData secondTypeData; ComposeWinModel.ComposeThirdTypeData thirdTypeData; Dictionary> fixedItemIndexDict = new Dictionary>(); private int curSecondType = 0; private int curThirdType = 0; private int preSecondType = 0; private int preThirdType = 0; [SerializeField] int initSuccessRate = 0; private int curComposeEquipIndex = -1; ItemCompoundConfig compoundModel = null; bool isIncreaseRate = false; int successRate = 0; SelectEquipModel _selectModel; SelectEquipModel selectModel { get { return _selectModel ?? (_selectModel = ModelCenter.Instance.GetModel()); } } protected override void BindController() { cellCtrl.OnRefreshCell += RefreshTypeCell; cellCtrl.vertical = true; cellCtrl.lockType = EnhanceLockType.KeepVertical; equipTypeLineCellCtrl.OnRefreshCell += RefreshEquipTypeLineCell; composeWinModel.ResetModelEvent += ResetModel; } protected override void AddListeners() { composeBtn.AddListener(OnClickComposeBtn); onekeyPutBtn.AddListener(OnClickOnekeyPutBtn); } protected override void OnPreOpen() { composeWinModel.UpdateSecondTypeEvent += UpdateSecondType; composeWinModel.UpdateThirdTypeEvent += UpdateThirdType; selectModel.selectEquipEvent += RefreshSelectItem; DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent += OnComposeAnswer; UIEventTrigger.Get(helpBtn.gameObject).OnDown = OnClickHelpBtn; UIEventTrigger.Get(helpBtn.gameObject).OnUp = OnDownUp; Display(); } protected override void OnAfterOpen() { this.transform.SetAsLastSibling(); } protected override void OnPreClose() { selectModel.selectEquipEvent -= RefreshSelectItem; DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent -= OnComposeAnswer; composeWinModel.UpdateSecondTypeEvent -= UpdateSecondType; composeWinModel.UpdateThirdTypeEvent -= UpdateThirdType; } protected override void OnAfterClose() { } #region 新的逻辑 private void Display() { composeWinModel.TryGetFirstTypeData((int)ComposeFuncType.Equip,out firstTypeData); if (firstTypeData == null ) return; isIncreaseRate = false; successRate = 0; DefaultSelect(); CreateTypeCell(); } private void DefaultSelect() { bool isJumpTo = false; if (composeWinModel.secondType != 0) { isJumpTo = true; curSecondType = composeWinModel.secondType; curThirdType = composeWinModel.thirdType; composeWinModel.ResetJumpToModel(); } //CreateCell(); if (compoundModel != null) { RefreshUI(compoundModel); if (isJumpTo) { isJumpTo = false; if (!composeWinModel.IsEnoughFixedMat(compoundModel) || !composeWinModel.IsEnoughUnfixedMat(compoundModel)) { MessageWin.Inst.ShowFixedTip(Language.Get("Compose101")); } else if (!composeWinModel.IsEnoughMoney(compoundModel)) { MessageWin.Inst.ShowFixedTip(Language.Get("Z1011")); } } } else { RefreshUI(null); } } private void CreateTypeCell() { if (firstTypeData == null) return; cellCtrl.Refresh(); foreach(var second in firstTypeData.secondTypeDict.Keys) { cellCtrl.AddCell(ScrollerDataType.Header,second); if(second == curSecondType) { var thirdTypeDict = firstTypeData.secondTypeDict[second].thirdTypeDict; foreach(var third in thirdTypeDict.Keys) { if (third != 0) { cellCtrl.AddCell(ScrollerDataType.Normal,third); } } } } cellCtrl.Restart(); JumpIndex(); if (curThirdType != 0) { composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Equip, curSecondType, curThirdType, out thirdTypeData); ChangeUIState(false, true, false); if(thirdTypeData != null) { ItemConfig itemConfig = Config.Instance.Get(thirdTypeData.itemCompound.makeID[0]); if (itemConfig != null && itemConfig.ItemColor == 6) { dismantleText.gameObject.SetActive(true); } else { dismantleText.gameObject.SetActive(false); } } } else { RefreshUI(null); dismantleText.gameObject.SetActive(false); ChangeUIState(true, false, false); } } private void RefreshTypeCell(ScrollerDataType type, CellView cell) { switch (type) { case ScrollerDataType.Header: ComposeWinModel.ComposeSecondTypeData _secondTypeData = null; ComposeFirstTypeCell firstTypeCell = cell.GetComponent(); composeWinModel.TryGetSecondTypeData((int)ComposeFuncType.Equip, cell.index, out _secondTypeData); if (_secondTypeData != null) { var thirdTypeDict = _secondTypeData.thirdTypeDict; foreach (var third in thirdTypeDict.Keys) { ComposeWinModel.ComposeThirdTypeData thirdTypeData = null; composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Equip, cell.index, third, out thirdTypeData); firstTypeCell.SetDisplay((int)ComposeFuncType.Equip, cell.index, third, curSecondType); break; } } break; case ScrollerDataType.Normal: ComposeSecondTypeCell secondTypeCell = cell.GetComponent(); secondTypeCell.SetDisplay((int)ComposeFuncType.Equip, curSecondType, cell.index, curThirdType); if(curThirdType == cell.index) { CreateEquipTypeLineCell(); } break; } } private void JumpIndex() { if (firstTypeData == null) return; var secondTypeDict = firstTypeData.secondTypeDict; if (secondTypeDict.Count >= 1 && curSecondType != 0 && curThirdType >= 1) { cellCtrl.JumpIndex(GetCurIndex(curSecondType)); } } private int GetCurIndex(int secondType) { if (firstTypeData == null) return 0; int curIndex = 0; var secondTypeDict = firstTypeData.secondTypeDict; List secondlist = secondTypeDict.Keys.ToList(); for (int i = 0; i < secondlist.Count; i++) { if (secondType == secondlist[i]) { curIndex = i; break; } } return curIndex; } private void UpdateSecondType(int secondType) { curThirdType = 0; curSecondType = secondType; composeWinModel.TryGetSecondTypeData((int)ComposeFuncType.Equip,secondType,out secondTypeData); OnClickSecondType(); CreateTypeCell(); } private void OnClickSecondType() { if (secondTypeData == null) return; var thirdTypeDict = secondTypeData.thirdTypeDict; if (curThirdType == 0) { foreach (var thirdType in thirdTypeDict.Keys) { if (thirdType != 0) { if (preSecondType == curSecondType) { curSecondType = 0; preSecondType = 0; } else { curThirdType = thirdType; } } break; } } if (preSecondType != curSecondType) { preSecondType = curSecondType; curComposeEquipIndex = -1; selectModel.ClearSelectModel(); } } private void UpdateThirdType(int thirdType) { composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Equip, curSecondType,thirdType, out thirdTypeData); if(thirdTypeData != null) { bool isTrailer = composeWinModel.IsTrailerByLevel(thirdTypeData.itemCompound); if (isTrailer) { MessageWin.Inst.ShowFixedTip(StringUtility.Contact(thirdTypeData.itemCompound.levelNeed, "级开启")); return; } } curThirdType = thirdType; OnClickThirdType(); CreateTypeCell(); } private void OnClickThirdType() { if (thirdTypeData == null) return; if (preThirdType != curThirdType) { preThirdType = curThirdType; } curComposeEquipIndex = -1; selectModel.ClearSelectModel(); } private void CreateEquipTypeLineCell() { List thirdTypeDatas = null; bool isthird = composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Equip, curSecondType, curThirdType, out thirdTypeDatas); if (!isthird) return; if (thirdTypeDatas.Count > 1) { ChangeUIState(false, true, false); equipTypeLineCellCtrl.Refresh(); int line = thirdTypeDatas.Count / 3; if (thirdTypeDatas.Count % 3 > 0) { line += 1; } int i = 0; for (i = 0; i < line; i++) { equipTypeLineCellCtrl.AddCell(ScrollerDataType.Header, i); } equipTypeLineCellCtrl.Restart(); } else { if (thirdTypeDatas.Count > 0) { ItemCompoundConfig tagItemCompound = thirdTypeDatas[0].itemCompound; ClickEquipTypeCell(tagItemCompound, 0); RefreshUI(tagItemCompound); } } if (curComposeEquipIndex != -1) { ItemCompoundConfig tagItemCompound = thirdTypeDatas[curComposeEquipIndex].itemCompound; ClickEquipTypeCell(tagItemCompound, curComposeEquipIndex); } } private void ChangeUIState(params bool[] isShows) { notChooseBG.SetActive(isShows[0]); chooseComposeEquip.SetActive(isShows[1]); composeEquip.SetActive(isShows[2]); } #endregion private void ResetModel() { curSecondType = 0; curThirdType = 0; preSecondType = 0; preThirdType = 0; curComposeEquipIndex = -1; compoundModel = null; } private void RefreshEquipTypeLineCell(ScrollerDataType type, CellView cell) { List thirdTypeDatas = null; composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Equip, curSecondType, curThirdType, out thirdTypeDatas); int i = 0; for(i = 0; i < cell.transform.childCount; i++) { GameObject typeCell = cell.transform.GetChild(i).gameObject; int index = (cell.transform.childCount) * cell.index + i; if(index < thirdTypeDatas.Count) { typeCell.SetActive(true); ItemCompoundConfig tagItemCompound = thirdTypeDatas[index].itemCompound; ItemConfig tagChinItem = Config.Instance.Get(tagItemCompound.makeID[0]); Image icon = typeCell.transform.Find("EquipIcon").GetComponent(); Image bgIcon = typeCell.transform.Find("EquipBG").GetComponent(); Text nameText = typeCell.transform.Find("BtnText").GetComponent(); Button cellBtn = typeCell.GetComponent