using DG.Tweening; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class YunShiXBActWin : Window { [SerializeField] List startItems;//ËùÓÐÆøÅÝÆðʼ×ø±ê [SerializeField] Transform transStartQianTong;//ǩͲÆðʼ×ø±ê [SerializeField] List transStartQian;//ËùÓÐÇ©×ÓÆðʼ×ø±ê [SerializeField] List yunShiXBItems;//ËùÓÐÆøÅÝ [SerializeField] Transform transQianTong;//ǩͲ [SerializeField] List transQian;//ËùÓÐÇ©×Ó [SerializeField] Transform oneEnd;//µ¥³éÆøÅÝÄ¿µÄµØ×ø±ê [SerializeField] List manyEnds;//¶à³éÆøÅÝÄ¿µÄµØ×ø±ê [SerializeField] Transform transItemMissEnd;//ËùÓÐÆøÅÝÏûʧµãÄ¿µÄµØ×ø±ê [SerializeField] Transform transQianTongMissEnd;//ǩͲĿµÄµØ×ø±ê [SerializeField] List qianPositionTweens = new List(); [SerializeField] RotationTween qianTongRotationTween; [SerializeField] UIEffect qianTongUIEffect; [SerializeField] List haveUIEffects; [SerializeField] TextEx actTime; [SerializeField] ButtonEx btnXBOne; [SerializeField] ButtonEx btnXBMany; [SerializeField] ButtonEx btnRate; [SerializeField] TextEx txtXBOne; [SerializeField] TextEx txtXBMany; [SerializeField] TextEx txtXBOneCount; [SerializeField] TextEx txtXBManyCount; [SerializeField] ButtonEx btnSkip; [SerializeField] ImageEx imgSkip; [SerializeField] TextEx txtHasCnt; [SerializeField] List sliders = new List(); [SerializeField] List itemCells = new List(); [SerializeField] List imgGreys = new List(); [SerializeField] List imgHaves = new List(); [SerializeField] List needCnts = new List(); [SerializeField] List awardRotationTweens = new List(); int type; HappyXBModel happyXBModel { get { return ModelCenter.Instance.GetModelEx(); } } YunShiXBActModel model { get { return ModelCenter.Instance.GetModelEx(); } } PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } protected override void AddListeners() { btnSkip.SetListener(() => { model.isSkipXB = !model.isSkipXB; RefreshSkipUI(); }); btnRate.SetListener(() => { WindowCenter.Instance.Open(); }); btnXBOne.SetListener(() => { if (!happyXBModel.IsHaveOneXBTool(type)) { SysNotifyMgr.Instance.ShowTip("YunShiXBAct01"); return; } if (!model.isSkipXB) { MoveAndDisappear(); } happyXBModel.SendXBQuest(type, 0, 2); }); btnXBMany.SetListener(() => { int toolCnt = 0; int needToolCnt = 0; if (!happyXBModel.IsHaveManyXBTool(type, out toolCnt, out needToolCnt) || toolCnt < needToolCnt) { SysNotifyMgr.Instance.ShowTip("YunShiXBAct01"); return; } if (!model.isSkipXB) { MoveAndDisappear(); } happyXBModel.CheckXBManyLimit(0, type, 2); }); } protected override void BindController() { } protected override void OnPreOpen() { WindowCenter.Instance.uiRoot.eventSystem.enabled = true; happyXBModel.RefreshXBTypeInfoAct += OnRefreshXBTypeInfoAct; model.PlayAnimationSync += OnPlaySyncAnimation; packModel.refreshItemCountEvent += OnRefreshItemCountEvent; happyXBModel.RefreshXBResultAct += RefreshXBResult; OperationYunShi act; OperationTimeHepler.Instance.TryGetOperation(YunShiXBActModel.operaType, out act); if (act == null) return; type = act.treasureType; var xbInfo = happyXBModel.GetXBInfoByType(type); if (xbInfo == null) return; if (type == 105) { happyXBModel.title = HappXBTitle.YunShi1; } else if (type == 106) { happyXBModel.title = HappXBTitle.YunShi2; } else if (type == 107) { happyXBModel.title = HappXBTitle.YunShi3; } else if (type == 108) { happyXBModel.title = HappXBTitle.YunShi4; } Display(); actTime.text = StringUtility.Contact(Language.Get("RidingPetBossQuestTime", act.ToDisplayTime()), Language.Get("YunShi04")); } protected override void OnPreClose() { happyXBModel.RefreshXBTypeInfoAct -= OnRefreshXBTypeInfoAct; model.PlayAnimationSync -= OnPlaySyncAnimation; packModel.refreshItemCountEvent -= OnRefreshItemCountEvent; happyXBModel.RefreshXBResultAct -= RefreshXBResult; } private void RefreshXBResult() { if (model.isSkipXB) { ShowGetItem(); } } private void OnRefreshItemCountEvent(PackType type, int arg2, int arg3) { Display(); model.IsPlayAnimation = true; } private void OnRefreshXBTypeInfoAct() { Display(); model.IsPlayAnimation = true; } protected override void OnAfterOpen() { Reset(); for (int i = 0; i < awardRotationTweens.Count; i++) { awardRotationTweens[i].Stop(); awardRotationTweens[i].SetStartState(); } var xbInfo = happyXBModel.GetXBInfoByType(type); if (xbInfo == null) return; var award = TreasureCntAwardConfig.GetAwardIndexDict(type); if (award == null) return; var list = award.Keys.ToList(); list.Sort(); if (list == null) return; for (int i = 0; i < model.AwardCellCount; i++) { if (i < list.Count) { int id = award[list[i]]; if (!TreasureCntAwardConfig.Has(id)) continue; TreasureCntAwardConfig config = TreasureCntAwardConfig.Get(id); int state = model.GetAwardState(xbInfo.treasureCount, config.NeedTreasureCnt, xbInfo.treasureCntAward, config.AwardIndex); if (state == 1) { awardRotationTweens[i].Play(); } } else { awardRotationTweens[i].Stop(); awardRotationTweens[i].SetStartState(); } } } protected override void OnAfterClose() { StopAllCoroutines(); } private void OnPlaySyncAnimation() { for (int i = 0; i < awardRotationTweens.Count; i++) { awardRotationTweens[i].Stop(); awardRotationTweens[i].SetStartState(); } var xbInfo = happyXBModel.GetXBInfoByType(type); if (xbInfo == null) return; var award = TreasureCntAwardConfig.GetAwardIndexDict(type); if (award == null) return; var list = award.Keys.ToList(); list.Sort(); if (list == null) return; for (int i = 0; i < model.AwardCellCount; i++) { if (i < list.Count) { int id = award[list[i]]; if (!TreasureCntAwardConfig.Has(id)) continue; TreasureCntAwardConfig config = TreasureCntAwardConfig.Get(id); int state = model.GetAwardState(xbInfo.treasureCount, config.NeedTreasureCnt, xbInfo.treasureCntAward, config.AwardIndex); if (awardRotationTweens[i].isActiveAndEnabled && state == 1) { awardRotationTweens[i].Play(); } } else { awardRotationTweens[i].Stop(); awardRotationTweens[i].SetStartState(); } } } private void Reset() { qianTongUIEffect.Stop(); for (int i = 0; i < haveUIEffects.Count; i++) { haveUIEffects[i].Stop(); } for (int i = 0; i < yunShiXBItems.Count; i++) { int gridIndex = i + 1; yunShiXBItems[i].transform.position = startItems[i].position; yunShiXBItems[i].SetActive(true); yunShiXBItems[i].Display(gridIndex); } qianTongRotationTween.Stop(); for (int i = 0; i < qianPositionTweens.Count; i++) { qianPositionTweens[i].Stop(); } transQianTong.transform.position = transStartQianTong.transform.position; transQianTong.transform.rotation = transStartQianTong.transform.rotation; for (int i = 0; i < transStartQian.Count; i++) { transQian[i].transform.position = transStartQian[i].transform.position; transQian[i].transform.rotation = transStartQian[i].transform.rotation; } } public void MoveAndDisappear() { WindowCenter.Instance.uiRoot.eventSystem.enabled = false; Sequence sequence = DOTween.Sequence(); foreach (YunShiXBItem item in yunShiXBItems) { sequence.Join(item.transform.DOMove(transItemMissEnd.position, 0.22f).SetEase(Ease.InOutSine).OnComplete(() => { item.SetActive(false); })); } sequence.Join(transQianTong.transform.DORotate(new Vector3(0, 0, -5), 0.3f).SetEase(Ease.InOutSine).OnComplete(() => { qianTongUIEffect.Play(); })); sequence.Join(transQianTong.transform.DOMove(transQianTongMissEnd.position, 0.5f).SetEase(Ease.InOutSine)); sequence.OnComplete(() => { ShakeQianTong(); }); } private void ShowGetItem() { if (happyXBModel.title == HappXBTitle.YunShi1 || happyXBModel.title == HappXBTitle.YunShi2 || happyXBModel.title == HappXBTitle.YunShi3 || happyXBModel.title == HappXBTitle.YunShi4) { var xbItemlist = happyXBModel.rangelist; List itemList = new List(); for (int i = 0; i < xbItemlist.Count; i++) { XBGetItem xbItem = xbItemlist[i]; itemList.Add(new Item(xbItem.itemId, (ulong)xbItem.count)); } ItemLogicUtility.Instance.ShowGetItem(itemList, seconds: 0, func: () =>{ happyXBModel.rangelist.Clear(); }); Reset(); WindowCenter.Instance.uiRoot.eventSystem.enabled = true; } } public void ShakeQianTong() { qianTongRotationTween.Play(); for (int i = 0; i < qianPositionTweens.Count; i++) { qianPositionTweens[i].duration = 0.3f; qianPositionTweens[i].Play(); } var xbItemlist = happyXBModel.rangelist; if (xbItemlist.IsNullOrEmpty()) { Reset(); WindowCenter.Instance.uiRoot.eventSystem.enabled = true; return; } for (int i = 0; i < qianPositionTweens.Count; i++) { qianPositionTweens[i].duration = 0.3f; } Sequence moveSequence = DOTween.Sequence(); moveSequence.AppendInterval(1.5f); if (xbItemlist.Count == 1) { YunShiXBItem item = yunShiXBItems[0]; yunShiXBItems[0].transform.position = haveUIEffects[0].transform.position; Vector3 targetPosition = oneEnd.position; XBGetItem xbItem = happyXBModel.rangelist[0]; DG.Tweening.Tween tween = item.transform.DOMove(targetPosition, 0.05f).SetDelay(0.05f).SetEase(Ease.InOutSine) .OnStart(() => { haveUIEffects[0].Play(); yunShiXBItems[0].Display(xbItem.itemId, xbItem.count); yunShiXBItems[0].SetActive(true); for (int i = 0; i < qianPositionTweens.Count; i++) { qianPositionTweens[i].duration = 0.1f; } }); moveSequence.Append(tween); } else { for (int i = 0; i < yunShiXBItems.Count; i++) { if (i < xbItemlist.Count) { int index = i; YunShiXBItem item = yunShiXBItems[i]; yunShiXBItems[i].transform.position = haveUIEffects[i].transform.position; Vector3 targetPosition = manyEnds[i].position; XBGetItem xbItem = happyXBModel.rangelist[i]; DG.Tweening.Tween tween = item.transform.DOMove(targetPosition, 0.1f).SetDelay(0.1f).SetEase(Ease.InOutSine) .OnStart(() => { haveUIEffects[index].Play(); yunShiXBItems[index].Display(xbItem.itemId, xbItem.count); yunShiXBItems[index].SetActive(true); for (int i = 0; i < qianPositionTweens.Count; i++) { qianPositionTweens[i].duration = 0.1f; } }); moveSequence.Append(tween); } } } moveSequence.OnComplete(() => { for (int i = 0; i < qianPositionTweens.Count; i++) { qianPositionTweens[i].duration = 0.3f; } Sequence sequence = DOTween.Sequence(); sequence.Join(transQianTong.transform.DORotate(new Vector3(0, 0, 0), 0.2f).SetEase(Ease.InOutSine)); sequence.Join(transQianTong.transform.DOMove(transStartQianTong.position, 0.2f).SetEase(Ease.InOutSine)); sequence.OnComplete(() => { qianTongRotationTween.Stop(); for (int i = 0; i < qianPositionTweens.Count; i++) { qianPositionTweens[i].Stop(); qianPositionTweens[i].SetStartState(); } Clock.AlarmAfter(0.5, ShowGetItem); }); }); } private void RefreshSkipUI() { imgSkip.SetActive(model.isSkipXB); } private void HaveAllAward() { var xbInfo = happyXBModel.GetXBInfoByType(type); if (xbInfo == null) return; var award = TreasureCntAwardConfig.GetAwardIndexDict(type); if (award == null) return; var list = award.Keys.ToList(); list.Sort(); if (list == null) return; for (int i = 0; i < model.AwardCellCount; i++) { if (i < list.Count) { int id = award[list[i]]; if (!TreasureCntAwardConfig.Has(id)) continue; TreasureCntAwardConfig config = TreasureCntAwardConfig.Get(id); int state = model.GetAwardState(xbInfo.treasureCount, config.NeedTreasureCnt, xbInfo.treasureCntAward, config.AwardIndex); if (state == 1) { model.SendGetAward(type, config.NeedTreasureCnt); } } } } private void Display() { var xbInfo = happyXBModel.GetXBInfoByType(type); if (xbInfo == null) return; var award = TreasureCntAwardConfig.GetAwardIndexDict(type); if (award == null) return; var list = award.Keys.ToList(); list.Sort(); if (list == null) return; var funcSet = happyXBModel.GetXBFuncSet(type); if (funcSet == null) return; int toolCnt0 = packModel.GetItemCountByID(PackType.Item, funcSet.costToolIds[0]); int toolCnt1 = packModel.GetItemCountByID(PackType.Item, funcSet.costToolIds[1]); txtXBOneCount.text = StringUtility.Contact(toolCnt0, "/", funcSet.xbNums[0]); txtXBManyCount.text = StringUtility.Contact(toolCnt1, "/", funcSet.xbNums[1]); txtXBOne.text = Language.Get("YunShi07", funcSet.xbNums[0]); txtXBMany.text = Language.Get("YunShi07", funcSet.xbNums[1]); RefreshSkipUI(); txtHasCnt.text = xbInfo.treasureCount.ToString(); for (int i = 0; i < model.AwardCellCount; i++) { if (i < list.Count) { int id = award[list[i]]; if (!TreasureCntAwardConfig.Has(id)) continue; TreasureCntAwardConfig config = TreasureCntAwardConfig.Get(id); int state = model.GetAwardState(xbInfo.treasureCount, config.NeedTreasureCnt, xbInfo.treasureCntAward, config.AwardIndex); int[][] awardItemArr = config.AwardItemList; int itemID = awardItemArr[0][0]; int itemCount = awardItemArr[0][1]; ItemCellModel cellModel = new ItemCellModel(itemID, false, (ulong)itemCount); itemCells[i].Init(cellModel); itemCells[i].SetActive(true); itemCells[i].button.SetListener(() => { if (state == 1) { HaveAllAward(); } else { ItemTipUtility.Show(itemID); } }); imgGreys[i].SetActive(state == 2); imgHaves[i].SetActive(state == 2); needCnts[i].SetActive(true); needCnts[i].text = config.NeedTreasureCnt.ToString(); if (state != 0) { sliders[i].value = 1; } else { if (i == 0) { float value = Mathf.Floor((xbInfo.treasureCount / (float)config.NeedTreasureCnt) * 1000f) / 1000f; sliders[i].value = value; } else { int lastId = award[list[i - 1]]; if (!TreasureCntAwardConfig.Has(lastId)) continue; TreasureCntAwardConfig lastIdConfig = TreasureCntAwardConfig.Get(lastId); float value = Mathf.Floor(((xbInfo.treasureCount - lastIdConfig.NeedTreasureCnt) / (float)(config.NeedTreasureCnt - lastIdConfig.NeedTreasureCnt)) * 1000f) / 1000f; sliders[i].value = Mathf.Min(value, 1); } } } else { itemCells[i].SetActive(false); needCnts[i].SetActive(false); sliders[i].SetActive(false); imgGreys[i].SetActive(false); imgHaves[i].SetActive(false); } } } } }