using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class CycleHallMissionCell : CellView { [SerializeField] ImageEx imgFinish; [SerializeField] TextEx txtTitle; [SerializeField] ButtonEx btnMissionHave; [SerializeField] List missionItemCells = new List(); [SerializeField] List missionHaves = new List(); [SerializeField] List missionGreys = new List(); [SerializeField] List missionTweens = new List(); [SerializeField] Slider buyCountGiftSlider; [SerializeField] Text buyCountGiftSliderText; int roundType; int tabType; int awardIndex; CycleHallActModel model { get { return ModelCenter.Instance.GetModel(); } } private void OnEnable() { model.PlayAnimationSync += OnPlaySyncAnimation; for (int i = 0; i < missionTweens.Count; i++) { missionTweens[i].Stop(); missionTweens[i].SetStartState(); } var act = model.GetOperationInfo(); if (act == null || !act.TryGetRoundInfoByIndex(roundType, awardIndex, out var awardInfo, out int listIndex) || awardInfo.AwardItemList == null) return; int state = model.GetAwardState(roundType, awardIndex); for (int i = 0; i < missionTweens.Count; i++) { if (i < awardInfo.AwardItemList.Length) { if (state == 1) { missionTweens[i].Play(); } } } } private void OnDisable() { model.PlayAnimationSync -= OnPlaySyncAnimation; } public void Display(int awardIndex, CellView cellView) { this.awardIndex = awardIndex; roundType = cellView.info.Value.infoInt1; tabType = cellView.info.Value.infoInt2; btnMissionHave.enabled = false; var act = model.GetOperationInfo(); if (act == null || !act.TryGetRound(roundType, out var round)) return; if (!act.TryGetRoundInfoByIndex(roundType, awardIndex, out var awardInfo, out int listIndex) || awardInfo.AwardItemList == null) return; if (model.playerInfoDict == null || !model.playerInfoDict.TryGetValue((byte)roundType, out var playerInfo) || playerInfo == null) return; int state = model.GetAwardState(roundType, awardIndex); imgFinish.SetActive(state == 2); txtTitle.text = Language.Get(StringUtility.Contact("CycleHallMissionTitle", "_", round.AwardType, "_", round.AwardTypeValue), awardInfo.NeedValue); buyCountGiftSlider.value = playerInfo.CurValue / (float)awardInfo.NeedValue; buyCountGiftSliderText.text = string.Format("{0}/{1}", playerInfo.CurValue, awardInfo.NeedValue); btnMissionHave.enabled = true; btnMissionHave.SetListener(() => { if (state == 1) { HaveMissionAward(); } }); for (int i = 0; i < missionItemCells.Count; i++) { var itemBaisc = missionItemCells[i]; if (i < awardInfo.AwardItemList.Length) { var itemInfo = awardInfo.AwardItemList[i]; itemBaisc.SetActive(true); missionHaves[i].SetActive(state == 2); missionGreys[i].SetActive(state == 2); ItemCellModel cellModel = new ItemCellModel((int)itemInfo.ItemID, false, (ulong)itemInfo.ItemCount); itemBaisc.Init(cellModel); itemBaisc.button.AddListener(() => { if (state == 1) { HaveMissionAward(); } else { ItemTipUtility.Show((int)itemInfo.ItemID); } }); } else { itemBaisc.SetActive(false); missionHaves[i].SetActive(false); missionGreys[i].SetActive(false); } } OnPlaySyncAnimation(); } public void HaveMissionAward() { var act = model.GetOperationInfo(); if (act == null || !act.TryGetRoundInfoByIndex(roundType, awardIndex, out var awardInfo, out int listIndex) || awardInfo.AwardItemList == null) return; int state = model.GetAwardState(roundType, awardIndex); if (state != 1) return; model.SendGetAward(roundType, (int)awardInfo.NeedValue); } private void OnPlaySyncAnimation() { if (tabType != 1) return; for (int i = 0; i < missionTweens.Count; i++) { missionTweens[i].Stop(); missionTweens[i].SetStartState(); } var act = model.GetOperationInfo(); if (act == null || !act.TryGetRoundInfoByIndex(roundType, awardIndex, out var awardInfo, out int listIndex) || awardInfo.AwardItemList == null) return; int state = model.GetAwardState(roundType, awardIndex); for (int i = 0; i < missionTweens.Count; i++) { if (missionTweens[i].isActiveAndEnabled && state == 1) { missionTweens[i].Play(); } } } } }