using Snxxz.UI; using System; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class ComposeWingsWin : Window { [SerializeField] GameObject composeUIShowObj; [SerializeField] GameObject noneComposeObj; [SerializeField] ScrollerController cellCtrl; [Header("固定物品和非固定物品")] [SerializeField] List fixedAndUnfixeds = new List(); [Header("合成物品")] [SerializeField] List makeItems = new List(); [Header("附加物品")] [SerializeField] List extraAddItems = new List(); [Header("合成物品目标特效")] [SerializeField] List composeTargetEffects = new List(); [SerializeField] Text successRateText; [SerializeField] Button helpBtn; [SerializeField] Button composeBtn; [SerializeField] Button onekeyPutBtn; [SerializeField] GameObject composeItemSelectObj; [SerializeField] UIEffect oneMatEffect; [SerializeField] UIEffect twoMatEffect; [SerializeField] UIEffect threeMatEffect; [SerializeField] UIEffect successEffect; [SerializeField] UIEffect failMatEffect; ComposeWinModel _composeWinModel; ComposeWinModel composeWinModel { get { return _composeWinModel ?? (_composeWinModel = 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; private int successRate = 0; [SerializeField] int initSuccessRate = 2000; ItemCompoundConfig compoundModel = null; SelectEquipModel _selectModel; SelectEquipModel selectModel { get { return _selectModel ?? (_selectModel = ModelCenter.Instance.GetModel()); } } PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } AchievementGuideEffect guidEffect = null; private bool IsComposeBind = false; protected override void BindController() { cellCtrl.OnRefreshCell += RefreshTypeCell; cellCtrl.lockType = EnhanceLockType.KeepVertical; composeWinModel.ResetModelEvent += ResetModel; } protected override void AddListeners() { composeBtn.AddListener(OnClickComposeBtn); onekeyPutBtn.AddListener(OnClickOnekeyPutBtn); } protected override void OnPreOpen() { composeWinModel.UpdateSecondTypeEvent += UpdateSecondType; composeWinModel.UpdateThirdTypeEvent += UpdateThirdType; composeWinModel.UpdateReduceEvent += UpdateReduce; selectModel.UpdateSelectEvent += UpdateSelect; DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent += OnComposeAnswer; UIEventTrigger.Get(helpBtn.gameObject).OnDown = OnClickHelpBtn; UIEventTrigger.Get(helpBtn.gameObject).OnUp = OnDownUp; Display(); } protected override void OnAfterOpen() { cellCtrl.vertical = true; this.transform.SetAsLastSibling(); } protected override void OnPreClose() { DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent -= OnComposeAnswer; composeWinModel.UpdateReduceEvent -= UpdateReduce; composeWinModel.UpdateSecondTypeEvent -= UpdateSecondType; composeWinModel.UpdateThirdTypeEvent -= UpdateThirdType; selectModel.UpdateSelectEvent -= UpdateSelect; } protected override void OnAfterClose() { } #region 新的逻辑 private void Display() { composeWinModel.TryGetFirstTypeData((int)ComposeFuncType.Wings, out firstTypeData); if (firstTypeData == null) return; IsComposeBind = false; DefaultSelect(); CreateTypeCell(); JumpIndex(); } private void DefaultSelect() { bool isJumpTo = false; var achieveId = AchievementGoto.guideAchievementId; SuccessConfig successConfig = SuccessConfig.Get(achieveId); if (successConfig != null && successConfig.Type == 69) { isJumpTo = true; curSecondType = composeWinModel.secondType; curThirdType = composeWinModel.thirdType; composeWinModel.ResetJumpToModel(); } else { if (composeWinModel.secondType != 0) { isJumpTo = true; curSecondType = composeWinModel.secondType; curThirdType = composeWinModel.thirdType; composeWinModel.ResetJumpToModel(); } } composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Wings, curSecondType, curThirdType, out thirdTypeData); if (thirdTypeData != null) { RefreshUI(thirdTypeData.itemCompound); if (isJumpTo) { isJumpTo = false; bool isCanCompose = true; if (!composeWinModel.IsEnoughFixedMat(thirdTypeData.itemCompound)) { ServerTipDetails.DisplayNormalTip(Language.Get("Compose101")); isCanCompose = false; } else if (!composeWinModel.IsEnoughMoney(thirdTypeData.itemCompound)) { ServerTipDetails.DisplayNormalTip(Language.Get("Z1011")); isCanCompose = false; } if (isCanCompose) { guidEffect = AchievementGuideEffectPool.Require(1); guidEffect.transform.SetParentEx(composeBtn.transform, Vector3.zero, Quaternion.identity, Vector3.one); } } } 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(); composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Wings, curSecondType, curThirdType, out thirdTypeData); if (thirdTypeData != null) { noneComposeObj.SetActive(false); composeUIShowObj.SetActive(true); RefreshUI(thirdTypeData.itemCompound); } else { RefreshUI(null); noneComposeObj.SetActive(true); composeUIShowObj.SetActive(false); } } private void JumpIndex() { if (firstTypeData == null) return; var secondTypeDict = firstTypeData.secondTypeDict; if (secondTypeDict.Count >= 1 && curSecondType != 0) { 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; } } if (curThirdType >= 4) { curIndex = curIndex + curThirdType - 2; } return curIndex; } private void RefreshTypeCell(ScrollerDataType type, CellView cell) { switch (type) { case ScrollerDataType.Header: ComposeWinModel.ComposeSecondTypeData _secondTypeData = null; ComposeFirstTypeCell firstTypeCell = cell.GetComponent(); composeWinModel.TryGetSecondTypeData((int)ComposeFuncType.Wings, cell.index, out _secondTypeData); if (_secondTypeData != null) { var thirdTypeDict = _secondTypeData.thirdTypeDict; foreach (var third in thirdTypeDict.Keys) { firstTypeCell.SetDisplay((int)ComposeFuncType.Wings, cell.index, third, curSecondType); break; } } break; case ScrollerDataType.Normal: ComposeSecondTypeCell secondTypeCell = cell.GetComponent(); secondTypeCell.SetDisplay((int)ComposeFuncType.Wings, curSecondType, cell.index, curThirdType); break; } } private void UpdateSecondType(int secondType) { curThirdType = 0; curSecondType = secondType; composeWinModel.TryGetSecondTypeData((int)ComposeFuncType.Wings,secondType, out secondTypeData); OnClickSecondType(); CreateTypeCell(); JumpIndex(); } private void OnClickSecondType() { if (secondTypeData == null) return; var thirdTypeDict = secondTypeData.thirdTypeDict; 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; selectModel.ClearSelectModel(); if (guidEffect != null) { AchievementGuideEffectPool.Recycle(guidEffect); guidEffect = null; } } } private void UpdateThirdType(int thirdType) { composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Wings, curSecondType, thirdType, out thirdTypeData); curThirdType = thirdType; OnClickThirdType(); CreateTypeCell(); } private void OnClickThirdType() { if (thirdTypeData == null) return; if (preThirdType != curThirdType) { preThirdType = curThirdType; } selectModel.ClearSelectModel(); } private void UpdateComposeMat() { int[] makeIds = compoundModel.makeID; for (int i = 0; i < makeItems.Count; i++) { var matCell = makeItems[i]; if (makeIds != null && i < makeIds.Length) { matCell.SetDisplay(compoundModel, NeedMatType.MakeItem, false, "", makeIds[i]); } else { matCell.SetDisplay(compoundModel, NeedMatType.Nothing, true); } } int[] fixedIds = compoundModel.itemID; int[] fixedDisplays = compoundModel.itemDisplay; int[] unfixedIds = compoundModel.unfixedItemID; int[] unfixedDisplays = compoundModel.unfixedItemDisplay; for (int i = 0; i < fixedAndUnfixeds.Count; i++) { var matCell = fixedAndUnfixeds[i]; matCell.SetDisplay(compoundModel, NeedMatType.Nothing, true); } for (int i = 0; i < fixedDisplays.Length; i++) { var fixedDisplay = fixedDisplays[i]; if (fixedDisplay != 0) { var matCell = fixedAndUnfixeds[fixedDisplay - 1]; int fixedId = fixedIds[i]; matCell.SetDisplay(compoundModel, NeedMatType.fixedItem, false, "", fixedId); } } for (int i = 0; i < unfixedDisplays.Length; i++) { var unfixedDisplay = unfixedDisplays[i]; if (unfixedDisplay != 0) { var matCell = fixedAndUnfixeds[unfixedDisplay - 1]; matCell.SetDisplay(compoundModel, NeedMatType.unfixedItem, false, UIHelper.ReplaceNewLine(Language.Get("ComposeWin_PutInText_1"))); } } int maxAddNum = compoundModel.addonsCountMax; for(int i = 0; i < extraAddItems.Count; i++) { var matCell = extraAddItems[i]; if(i < maxAddNum) { matCell.SetDisplay(compoundModel,NeedMatType.addItem,false, UIHelper.ReplaceNewLine(Language.Get("ComposeWin_AddRateText_1"))); } else { matCell.SetDisplay(compoundModel, NeedMatType.Nothing, true); } } } private void UpdateSelect(ComposeMatCell matCell, int itemIndex, SelectItemType selectType) { switch (selectType) { case SelectItemType.unfixed: matCell.SetDisplay(compoundModel, NeedMatType.unfixedItem, false, "", 0, itemIndex); IsComposeBind = ChangeFixedMatUI(); break; case SelectItemType.addons: matCell.SetDisplay(compoundModel, NeedMatType.addItem, false, "", 0, itemIndex); successRateText.text = Language.Get("HallowsWin_Success", StringUtility.Contact(RefreshComposeSuccessRate(initSuccessRate) / 100, "%")); if (successRate >= compoundModel.successUpper) { SysNotifyMgr.Instance.ShowTip("ComposeFullToAdd"); } break; } } private void UpdateReduce(ComposeMatCell matCell, NeedMatType matType) { switch (matType) { case NeedMatType.unfixedItem: matCell.SetDisplay(compoundModel, matType, false, UIHelper.ReplaceNewLine(Language.Get("ComposeWin_PutInText_1"))); IsComposeBind = ChangeFixedMatUI(); break; case NeedMatType.addItem: matCell.SetDisplay(compoundModel, matType, false, UIHelper.ReplaceNewLine(Language.Get("ComposeWin_AddRateText_1"))); successRateText.text = Language.Get("HallowsWin_Success", StringUtility.Contact(RefreshComposeSuccessRate(initSuccessRate) / 100, "%")); break; } } #endregion private void ResetModel() { curSecondType = 0; curThirdType = 0; successRate = 0; compoundModel = null; if (!WindowJumpMgr.Instance.IsJumpState) { preSecondType = 0; preThirdType = 0; } } private void RefreshUI(ItemCompoundConfig compoundModel) { this.compoundModel = compoundModel; if (compoundModel == null) return; successRate = compoundModel.successRate; successRateText.text = Language.Get("HallowsWin_Success", StringUtility.Contact(compoundModel.successRate / 100, "%")); composeWinModel.SetCurComposeModel(compoundModel); UpdateComposeMat(); composeItemSelectObj.SetActive(compoundModel.secondType < 4); } private bool ChangeFixedMatUI() { if (compoundModel == null) return false; var packType = composeWinModel.GetPackTypeByMakerId(compoundModel.makeID); SinglePackModel singlePack = playerPack.GetSinglePackModel(packType); if (singlePack == null) return false; bool isBind = false; Dictionary unfixedMatDict = selectModel.GetHaveUnfixedSelectItem(); foreach(var model in unfixedMatDict.Values) { if(model.itemInfo.IsBind == 1) { isBind = true; break; } } int[] fixedIds = compoundModel.itemID; int[] fixedCounts = compoundModel.itemCount; int[] fixedDisplays = compoundModel.itemDisplay; for (int i = 0; i < fixedDisplays.Length; i++) { var fixedDisplay = fixedDisplays[i]; if (fixedDisplay != 0) { var matCell = fixedAndUnfixeds[fixedDisplay - 1]; int fixedId = fixedIds[i]; var bindIcon = matCell.itemCell.bindIcon; bindIcon.gameObject.SetActive(false); if (isBind) { List list = null; singlePack.GetItemCountByID(fixedId, out list); if (list != null) { for (int j = 0; j < list.Count; j++) { if (list[j].itemInfo.IsBind == 1) { bindIcon.gameObject.SetActive(true); break; } } } } } } return isBind; } public int RefreshComposeSuccessRate(int initRate) { Dictionary addSelectItemDict = selectModel.GetHaveAddSelectItem(); if (addSelectItemDict == null) return initRate; successRate = initRate; Debug.Log("RefreshComposeSuccessRate;"+ addSelectItemDict.Count); foreach (var index in addSelectItemDict.Keys) { successRate = composeWinModel.GetComposeSuccessRate(compoundModel,addSelectItemDict[index],successRate); } return successRate; } private void OnClickOnekeyPutBtn() { if (compoundModel == null) return; if (successRate >= compoundModel.successUpper) { SysNotifyMgr.Instance.ShowTip("ComposeFullToAdd"); return; } List onekeyPutlist = selectModel.GetOneKeyPutModel(); if(onekeyPutlist.Count < 1) { SysNotifyMgr.Instance.ShowTip("ComposeNothingToAdd"); return; } var addSelectItemDict = selectModel.GetHaveAddSelectItem(); int maxAddNum = compoundModel.addonsCountMax; for (int i = 0; i < extraAddItems.Count; i++) { var matCell = extraAddItems[i]; if(i < maxAddNum && matCell.itemModel == null) { for (int j = 0; j < onekeyPutlist.Count; j++) { var itemIndex = onekeyPutlist[j].itemInfo.ItemPlace; if (!addSelectItemDict.ContainsKey(itemIndex)) { if (successRate < compoundModel.successUpper) { selectModel.AddHaveAddSelectItem(itemIndex); UpdateSelect(matCell, itemIndex, SelectItemType.addons); break; } else { return; } } } } } } private void OnClickComposeBtn() { if (compoundModel == null) return; bool isTrailer = composeWinModel.IsTrailerByLevel(compoundModel); if (isTrailer) { ServerTipDetails.DisplayNormalTip(Language.Get("FuncOpenLv", compoundModel.levelNeed)); return; } SetFixedMatIndex(); composeWinModel.SendComposeRequest(compoundModel, fixedItemIndexDict, GetPlayMatEffect(), 1, successRate); } private void SetFixedMatIndex() { fixedItemIndexDict.Clear(); if (compoundModel == null) return; var packType = composeWinModel.GetPackTypeByMakerId(compoundModel.makeID); SinglePackModel singlePack = playerPack.GetSinglePackModel(packType); if (singlePack == null) return; int isBind = 0; if(IsComposeBind) { isBind = 1; } else { isBind = 0; } int[] fixedIds = compoundModel.itemID; int[] fixedCounts = compoundModel.itemCount; for (int i = 0; i < fixedIds.Length; i++) { List itemIndexlist = singlePack.ItemIndexlistByIsBind(fixedIds[i], fixedCounts[i],isBind); if (itemIndexlist != null) { fixedItemIndexDict.Add(fixedIds[i], itemIndexlist); } } } private UIEffect GetPlayMatEffect() { if(compoundModel == null) return null; int[] fixedIds = compoundModel.itemID; int matTypeCnt = compoundModel.unfixedItemCount + fixedIds.Length; switch (matTypeCnt) { case 1: return oneMatEffect; case 2: return twoMatEffect; case 3: return threeMatEffect; } return null; } private void OnComposeAnswer(HA814_tagMCMakeItemAnswer answer) { if (answer.MakeType != (int)MakeType.Def_mitItemCompound) return; if (answer.Result == 1) { successEffect.Play(); int[] makeIds = compoundModel.makeID; for (int i = 0; i < composeTargetEffects.Count; i++) { var targetEffect = composeTargetEffects[i]; if (i < makeIds.Length) { if(makeIds[i] == answer.MakeItemID) { targetEffect.Play(); break; } } } } else { failMatEffect.Play(); } RefreshUI(compoundModel); selectModel.ClearSelectModel(); } private void OnDownUp(GameObject go) { WindowCenter.Instance.Close(); } private void OnClickHelpBtn(GameObject go) { if(compoundModel != null) { WindowCenter.Instance.Open(); } } } }