using Snxxz.UI; using System; using System.Collections; using System.Collections.Generic; using TableConfig; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class ComposeToolsWin : Window { [SerializeField] GameObject composeUIShowObj; [SerializeField] GameObject noneComposeObj; [SerializeField] ScrollerController cellCtrl; [SerializeField] List sourceItemlist = new List(); [SerializeField] List previewItemlist = new List(); [SerializeField] Text successRateText; [SerializeField] Button composeAllBtn; [SerializeField] Button composeBtn; [SerializeField] UIEffect composeEffect; ComposeWinModel _composeWinModel; ComposeWinModel composeWinModel { get { return _composeWinModel ?? (_composeWinModel = ModelCenter.Instance.GetModel()); } } private Dictionary>> firstTypeDict = null; private Dictionary> secondTypeDict = null; private List thirdTypelist = null; private int curSecondType = 0; private int curThirdType = 0; private int preSecondType = 0; [SerializeField] int initSuccessRate = 10000; ItemCompoundConfig compoundModel = null; SelectEquipModel _selectModel; private Dictionary> fixedItemIndexDict = new Dictionary>(); SelectEquipModel selectModel { get { return _selectModel ?? (_selectModel = 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(); } } AchievementGuideEffect guidEffect = null; bool isJumpTo; protected override void BindController() { cellCtrl.OnRefreshCell += RefreshCell; cellCtrl.lockType = EnhanceLockType.KeepVertical; composeWinModel.ResetModelEvent += ResetModel; } protected override void AddListeners() { composeBtn.AddListener(OnClickComposeBtn); composeAllBtn.AddListener(OnClickComposeAllBtn); } protected override void OnPreOpen() { DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent += OnComposeAnswer; firstTypeDict = composeWinModel.GetFirstTypeModel((int)ComposeFuncType.Item); isJumpTo = false; if (AchievementGoto.guideAchievementId != 0) { SuccessConfig successConfig = Config.Instance.Get(AchievementGoto.guideAchievementId); if (successConfig.Type == 69) { isJumpTo = true; curSecondType = composeWinModel.secondType; curThirdType = composeWinModel.thirdType; secondTypeDict = composeWinModel.GetSecondTypeModel((int)ComposeFuncType.Item,composeWinModel.secondType); ClickSecondTypeUICtrl(); composeWinModel.ResetJumpToModel(); } } else { if (composeWinModel.secondType != 0) { isJumpTo = true; curSecondType = composeWinModel.secondType; curThirdType = composeWinModel.thirdType; secondTypeDict = composeWinModel.GetSecondTypeModel((int)ComposeFuncType.Item, composeWinModel.secondType); ClickSecondTypeUICtrl(); composeWinModel.ResetJumpToModel(); } else if(composeWinModel.composeToolRed.state == RedPointState.Simple) { foreach(var second in composeWinModel.secondTypeRedDict.Keys) { if(composeWinModel.secondTypeRedDict[second].state == RedPointState.Simple) { string key = StringUtility.Contact(second,10); foreach(var third in composeWinModel.thirdTypeRedDict.Keys) { if(composeWinModel.thirdTypeRedDict[third].state == RedPointState.Simple) { string thirdType = third.Substring(key.Length,third.Length - key.Length); isJumpTo = true; curSecondType = second; curThirdType = int.Parse(thirdType); secondTypeDict = composeWinModel.GetSecondTypeModel((int)ComposeFuncType.Item, second); ClickSecondTypeUICtrl(); composeWinModel.ResetJumpToModel(); break; } } break; } } } } CreateCell(); if (curSecondType == 0) { RefreshUI(null); } } protected override void OnAfterOpen() { this.transform.SetAsLastSibling(); StartCoroutine(SetOffestPos()); } protected override void OnPreClose() { DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent -= OnComposeAnswer; } protected override void OnAfterClose() { } private void ResetModel() { curSecondType = 0; curThirdType = 0; preSecondType = 0; compoundModel = null; } private void CreateCell() { cellCtrl.Refresh(); if(firstTypeDict != null) { foreach (int secondType in firstTypeDict.Keys) { cellCtrl.AddCell(ScrollerDataType.Header,secondType); if(secondType == curSecondType) { foreach (int thirdType in firstTypeDict[secondType].Keys) { if (thirdType != 0) { ItemCompoundConfig compoundConfig = firstTypeDict[secondType][thirdType][0]; int makeID = ConfigParse.GetMultipleStr(compoundConfig.makeID)[0]; if(secondType != 3) { cellCtrl.AddCell(ScrollerDataType.Normal, thirdType); } else { if (composeWinModel.IsComposeJobLimit(makeID)) { cellCtrl.AddCell(ScrollerDataType.Normal, thirdType); } } } } } } } cellCtrl.Restart(); if (secondTypeDict != null) { if (secondTypeDict.Count >= 1 && curSecondType != 0) { int remain = curSecondType - firstTypeDict.Count; if (remain > 0) { cellCtrl.JumpIndex(curSecondType - remain); } else { cellCtrl.JumpIndex(curSecondType - 1); } } } } private IEnumerator SetOffestPos() { yield return null; if (curThirdType >= 5) { cellCtrl.JumpIndex(curThirdType*50, 0, EnhancedUI.EnhancedScroller.EnhancedScroller.TweenType.immediate); } CheckJumpModel(); } private void CheckJumpModel() { if (compoundModel != null) { RefreshUI(compoundModel); if (isJumpTo) { isJumpTo = false; bool isCanCompose = true; if (!composeWinModel.IsEnoughFixedMat(compoundModel) || !composeWinModel.IsEnoughUnfixedMat(compoundModel)) { MessageWin.Inst.ShowFixedTip(Language.Get("Compose101")); isCanCompose = false; } else if (!composeWinModel.IsEnoughMoney(compoundModel)) { MessageWin.Inst.ShowFixedTip(Language.Get("L1006")); isCanCompose = false; } if (isCanCompose) { guidEffect = AchievementGuideEffectPool.Require(1); guidEffect.transform.SetParentEx(composeBtn.transform, Vector3.zero, Quaternion.identity, Vector3.one); } } } } private void RefreshCell(ScrollerDataType type, CellView cell) { Image icon = cell.transform.Find("BtnIcon").GetComponent(); Text name = cell.transform.Find("BtnText").GetComponent(); Button cellBtn = cell.GetComponent