using vnxbqy.UI; using UnityEngine; using System.Collections.Generic; using UnityEngine.UI; using System.Linq; using System; public class TreasureLuckyDrawBehavior : MonoBehaviour { [SerializeField] List btnTreasureTagList = new List(); [SerializeField] List btnTreasureTagFakeList = new List(); //为了实现遮挡效果做的假按钮,实际点击btnTreasureTagList [SerializeField] List imgTreasureTagList = new List(); [SerializeField] List txtTreasureTagList = new List(); [SerializeField] TextEx txtGuaranteCount; [SerializeField] ButtonEx btnOneGo; [SerializeField] TextEx txtOneGo; [SerializeField] ImageEx imgOneIcon; [SerializeField] TextEx txtOneCount; [SerializeField] TextEx txtOneFree; [SerializeField] ButtonEx btnManyGo; [SerializeField] TextEx txtManyGo; [SerializeField] ImageEx imgManyIcon; [SerializeField] TextEx txtManyCount; [SerializeField] Button btnSkip; [SerializeField] Image imgSkip; [SerializeField] RichText txtTip; [SerializeField] UIEffect uiEffect; [SerializeField] TextEx todayMaxText; const int MaxTreasureTypeTabCount = 4; int type; HappyXBModel XBModel { get { return ModelCenter.Instance.GetModel(); } } RoleParticularModel model { get { return ModelCenter.Instance.GetModelEx(); } } PackModel playerPack { get { return ModelCenter.Instance.GetModel(); } } StoreModel storeModel { get { return ModelCenter.Instance.GetModel(); } } public void Display(int type) { this.type = type; XBTypeInfo typeInfo = XBModel.GetXBInfoByType(type); if (typeInfo == null) { typeInfo = new XBTypeInfo() { xbType = type, luckValue = 0, freeCountToday = 0, treasureCount = 0, }; } var funcSet = XBModel.GetXBFuncSet(type); bool isHaveFree = XBModel.IsHaveFreeXB(type); int toolCnt0 = playerPack.GetItemCountByID(PackType.Item, funcSet.costToolIds[0]); int toolCnt1 = playerPack.GetItemCountByID(PackType.Item, funcSet.costToolIds[1]); int luckValue = typeInfo.luckValue; var config = TreasureSetConfig.Get(type); int fullLuck = config.FullLucky; int onceLucky = config.OnceLucky; int guaranteCount = (fullLuck - luckValue) / onceLucky; ShowTreasureTagBtn(); txtOneFree.SetActive(isHaveFree); imgOneIcon.SetActive(!isHaveFree); txtOneCount.SetActive(!isHaveFree); RefreshSkipUI(); TreasurePavilionModel.Instance.UpdateLuckyDrawRedpoint(); txtGuaranteCount.text = Language.Get("TreasurePavilion05", guaranteCount); txtOneGo.text = Language.Get("HappyXB101", funcSet.xbNums[0]); txtManyGo.text = Language.Get("HappyXB101", funcSet.xbNums[1]); txtOneCount.text = StringUtility.Contact(toolCnt0, "/", funcSet.xbNums[0]); txtManyCount.text = StringUtility.Contact(toolCnt1, "/", funcSet.xbNums[1]); txtTip.text = Language.Get("TreasurePavilion07", Language.Get("TreasurePavilion06")); ItemConfig itemConfig1 = ItemConfig.Get(funcSet.costToolIds[0]); ItemConfig itemConfig2 = ItemConfig.Get(funcSet.costToolIds[1]); if (itemConfig1 != null) { imgOneIcon.SetSprite(itemConfig1.IconKey); } if (itemConfig2 != null) { imgManyIcon.SetSprite(itemConfig2.IconKey); } todayMaxText.text = Language.Get("TreasureCntTodayMax", config.DailyMaxCount); } void ShowTreasureTagBtn() { int[] xbIDArr = TreasurePavilionModel.Instance.xbIDArr; var luckyDrawFuncIDDict = TreasurePavilionModel.Instance.luckyDrawFuncIDDict; var keyList = luckyDrawFuncIDDict.Keys.ToList(); for (int i = 0; i < MaxTreasureTypeTabCount; i++) { if (i < xbIDArr.Length) { if (!luckyDrawFuncIDDict.ContainsKey(xbIDArr[i])) continue; if (!FuncOpen.Instance.IsFuncOpen(luckyDrawFuncIDDict[xbIDArr[i]])) continue; btnTreasureTagList[i].SetActiveIL(true); btnTreasureTagFakeList[i].SetActiveIL(true); imgTreasureTagList[i].SetActiveIL(TreasurePavilionModel.Instance.xbIndex == i); txtTreasureTagList[i].GetComponent().text = Language.Get("TreasureTypeTabTitle_" + i); } else { btnTreasureTagList[i].SetActiveIL(false); btnTreasureTagFakeList[i].SetActiveIL(false); } } } private void RefreshSkipUI() { imgSkip.SetActive(XBModel.isJumpGubaoXB); } private Clock animationTimeoutClock; private void RefreshXBResult() { if (XBModel.isJumpGubaoXB) { TreasurePavilionModel.Instance.isEffectPlaying = false; WindowCenter.Instance.Open(); } else { uiEffect.Play(); animationTimeoutClock = Clock.AlarmAfter(4f, () => { uiEffect.Stop(); OnCompleted(); }); } } // 取消定时器(如果有) void StopClock() { if (animationTimeoutClock != null) { Clock.Stop(animationTimeoutClock); animationTimeoutClock = null; } } void Awake() { btnSkip.SetListener(() => { XBModel.isJumpGubaoXB = !XBModel.isJumpGubaoXB; RefreshSkipUI(); }); for (int i = 0; i < btnTreasureTagList.Count; i++) { int index = i; int[] xbIDArr = TreasurePavilionModel.Instance.xbIDArr; btnTreasureTagList[i].SetListener(() => { if (index < xbIDArr.Length) { TreasurePavilionModel.Instance.xbIndex = index; if (index == 0) { XBModel.title = HappXBTitle.Gubao1; } else if (index == 1) { XBModel.title = HappXBTitle.Gubao2; } else if (index == 2) { XBModel.title = HappXBTitle.Gubao3; } else if (index == 3) { XBModel.title = HappXBTitle.Gubao4; } Display(type); } }); } btnOneGo.SetListener(() => { if (TreasurePavilionModel.Instance.isEffectPlaying) return; var config = TreasureSetConfig.Get(type); if (XBModel.GetXBInfoByType(type).treasureCountToday + config.TreasureCountList[0] > config.DailyMaxCount) { SysNotifyMgr.Instance.ShowTip("XBTodayMax"); return; } TreasurePavilionModel.Instance.isEffectPlaying = true; if (XBModel.IsHaveFreeXB(type)) { XBModel.SendXBQuest(type, 0, 1); } else { var funcSet = XBModel.GetXBFuncSet(type); if (XBModel.IsHaveOneXBTool(type)) { XBModel.SendXBQuest(type, 0, 2); } else { TreasurePavilionModel.Instance.isEffectPlaying = false; int moneyType = XBModel.XBCostTypeDict[type]; int costToolCount = funcSet.costToolNums[0]; int xbOneMoney = TreasureSetConfig.Get(type).CostMoneyList[0]; if (UIHelper.GetMoneyCnt(moneyType) >= (ulong)xbOneMoney) { storeModel.UseMoneyCheck(xbOneMoney, () => { TreasurePavilionModel.Instance.isEffectPlaying = true; XBModel.SendXBQuest(type, 0, 0); }, 4, fullTip: Language.Get("TreasurePavilion08", xbOneMoney, moneyType, funcSet.costToolIds[0], costToolCount)); } else { SysNotifyMgr.Instance.ShowTip("LackMoney", moneyType); } } } }); btnManyGo.SetListener(() => { if (TreasurePavilionModel.Instance.isEffectPlaying) return; var config = TreasureSetConfig.Get(type); if (XBModel.GetXBInfoByType(type).treasureCountToday + config.TreasureCountList[1] > config.DailyMaxCount) { SysNotifyMgr.Instance.ShowTip("XBTodayMax"); return; } TreasurePavilionModel.Instance.isEffectPlaying = true; var funcSet = XBModel.GetXBFuncSet(type); int toolCnt = 0; int needToolCnt = 0; int needMoney = 0; if (XBModel.IsHaveManyXBToolEx(type, out toolCnt, out needToolCnt, out needMoney)) { if (toolCnt >= needToolCnt) { XBModel.CheckXBManyLimit(0, type, 2); return; } } TreasurePavilionModel.Instance.isEffectPlaying = false; int moneyType = XBModel.XBCostTypeDict[type]; int xbManyMoney = needMoney == 0 ? funcSet.xbPrices[1] : needMoney; if (UIHelper.GetMoneyCnt(moneyType) >= (ulong)xbManyMoney) { storeModel.UseMoneyCheck(xbManyMoney, () => { TreasurePavilionModel.Instance.isEffectPlaying = true; XBModel.SendXBQuest(type, 1, toolCnt > 0 ? 2 : 0); }, 4, fullTip: Language.Get("TreasurePavilion08", xbManyMoney, moneyType, funcSet.costToolIds[1], needToolCnt - toolCnt)); } else { SysNotifyMgr.Instance.ShowTip("LackMoney", moneyType); } }); } void OnEnable() { XBModel.RefreshXBResultAct += RefreshXBResult; XBModel.RefreshXBTypeInfoAct += RefreshXBTypeInfo; uiEffect.OnComplete += OnCompleted; } void OnDisable() { XBModel.RefreshXBResultAct -= RefreshXBResult; XBModel.RefreshXBTypeInfoAct -= RefreshXBTypeInfo; uiEffect.OnComplete -= OnCompleted; } private void RefreshXBTypeInfo() { Display(type); } public void OnCompleted() { StopClock(); TreasurePavilionModel.Instance.isEffectPlaying = false; WindowCenter.Instance.Open(); } public void Open() { gameObject.SetActive(true); } public void Close() { gameObject.SetActive(false); } }