local UIGachaMain = UIViewClass() local EventSystem = require('Event/EventSystem') local BG_PATH = ConstAssetPathConfig.BG_PATH local CONST_REWARD_COUNT = DataSheetManager.ConstData:GetDataByID("SelectionHeroFrequency").IntValue function UIGachaMain:OnCreated() UIUtils.SetActive(self.group_Cumulative, false) UIUtils.SetActive(self.group_Select, false) end function UIGachaMain:OnOpened(context) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) UIManager.ActiveUIModle(false, "UIGachaMain") local isSkipAnim = MDL.DrawCard.GetIsSkipAnim() self.toggle_UseCard.isOn = isSkipAnim self.isSkipAnim = isSkipAnim self:RegistSystemEvent(EventID.UI_DrawCard_Refresh_MainUI, self.RefreshUI) self:RegistSystemEvent(EventID.UI_DrawCard_Refresh_RedCardDrawCount, self.RefreshRedCardDrawCount) self:RegistSystemEvent(EventID.UI_DrawCard_OnCloseGamePlay, self.OnCloseGamePlay) self.curCardPoolId = 0 self:InitCardPool() -- 打开界面时停止自动寻路 防止抽卡TimeLine和剧情重叠 NotSyncBattleSetter.StopAutoFightPathInTown() --停止现在的寻路 -- 共鸣延迟显示恢复 MDL.FormationResonance.CloseDelayResonanceShow() -- 直接抽卡引导 if context then MDL.DrawCard.RequestDrawCard(context.cardPoolId, context.drawNum) end -- 防止抽卡动画中触发任务对话 导致结束后回到主界面内容重叠 if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIDialogueNormalView) then CameraController.Instance:SetTalkSystem(false, nil) UIManager.CloseView(Const_UI_Lua.UIEnum.UIDialogueNormalView) end self.AnyPortraitObj = TK2API.GetInstance(BG_PATH, nil) self.AnyPortraitObj.transform:SetParent(self.DynamicBG.transform, false) self.AnyPortraitObj.transform:SetLocalScale(100, 100, 1) UIUtils.SetActive(self.btn_Exchange, MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Shop)) UIUtils.SetActive(self.group_JPTips, GameAppInfo.IsJapanesePackage()) end function UIGachaMain:OnCloseGamePlay() self:CloseView(true) end function UIGachaMain:OnFocusChanged(isFocus) if isFocus then CTL.HeroSelect.ForceOpenRelationPopup() end end function UIGachaMain:InitCardPool() self.index = 0 self.cardPoolCfgData = MDL.DrawCard.GetCardPoolCfgData() -- if #self.cardPoolCfgData > 0 then self.index = 1 end self:Left() end function UIGachaMain:Left() self.index = self.index - 1 if self.index <= 0 then self.index = 1 end self:RefreshCardPoolData() end function UIGachaMain:Right() self.index = self.index + 1 if self.index >= #self.cardPoolCfgData then self.index = #self.cardPoolCfgData end self:RefreshCardPoolData() end function UIGachaMain:RefreshCardPoolData() self.curCardPoolId = self.cardPoolCfgData[self.index].ID MDL.DrawCard.SetCurCardPoolID(self.curCardPoolId) UIUtils.SetLabel(self.UITemplateTitlePanel.lab_Title, CTL.ActivityGacha.GetGachatTitleName(self.curCardPoolId)) if self.loc_Title.CurState == 0 then CTL.ActivityGacha.SetTitleImage(self.img_GachaTitle, self.curCardPoolId) end local DrawCardGiveItemId = DataSheetManager.ConstData:GetDataByID("DrawCardGiveItemId").IntValue local itemData= DataSheetManager.ItemData:GetDataByID(DrawCardGiveItemId) local costItemData = DataSheetManager.ItemData:GetDataByID(MDL.DrawCard.GetCardDataByID(self.curCardPoolId).Item) local costItemColorText = UTL.Color.FormatQualityText(UTL.Item.GetItemDataSpliceByType(MDL.DrawCard.GetCardDataByID(self.curCardPoolId).Item).Name, costItemData.Color) local itemColorText = UTL.Color.FormatQualityText(UTL.Item.GetItemDataSpliceByType(DrawCardGiveItemId).Name, itemData.Color) self.txt_Info.text = string.FormatByIdsId(Const_IDS.IDS_DrawCard_Tip_BuyItemSendDraw,costItemColorText,itemColorText) local DrawCardGiveItemNum = DataSheetManager.ConstData:GetDataByID("DrawCardGiveItemNum").IntValue local itemId, countInBag, costNum, itemStoreId = MDL.DrawCard.GetConstItemAndNum(self.curCardPoolId) self.itemId = itemId self.itemStoreId = itemStoreId UTL.Item.SetCurrencyImageIcon(self.img_Icon_one, itemId) UIUtils.SetLabel(self.txt_One, CTL.ActivityGacha.GetGachaCostNumShow(itemId, MDL.DrawCard.GetFreeCount(self.curCardPoolId) > 0 and 0 or 1)) UTL.Item.SetCurrencyImageIcon(self.img_Icon_ten, itemId) UIUtils.SetLabel(self.txt_Ten, CTL.ActivityGacha.GetGachaCostNumShow(itemId, 10)) self:RefreshFreeCount() --刷新今日剩余次数 local DailyLeftTimes = UIUtils.GetLocalizedTxt(Const_IDS.IDS_DrawCard_Tip_DailyLeftTimes) local displayCount = string.Concat(DailyLeftTimes, MDL.DrawCard.DisplayLeftCountPerDay()) self.lab_Times.text = displayCount if GameAppInfo.IsJapanesePackage() then UIUtils.SetActive(self.lab_RedHeroTip, false) self.txt_RedHeroTip.text = string.FormatByIdsKey("IDS_JP_Recruit_Tips4", MDL.DrawCard.GetRedCardDrawCount(self.curCardPoolId)) else --刷新抽卡保底机制 local getRedHeroState = MDL.DrawCard.GetRedHeroState() if MDL.DrawCard.IsNewDrawCardPlayer() and getRedHeroState= CONST_REWARD_COUNT}, Const_UI_Lua.UIEnum.UISelectReward) end end function UIGachaMain:OnValueChanged(comp) if comp == self.toggle_UseCard then self.isSkipAnim = not self.isSkipAnim MDL.DrawCard.SetIsSkipAnim(self.isSkipAnim) end end function UIGachaMain:ProcessDrawCradOne() local canBuy, ids = MDL.DrawCard.CanDrawCardByOne() if not canBuy then CTL.Tips.AddTipsMsg(ids) return end if self.hasFreeCount then --免费购买 MDL.DrawCard.RequestDrawCard(self.curCardPoolId, 1, self.isSkipAnim, true) else local itemId, countInBag, costNum, itemStoreId = MDL.DrawCard.GetConstItemAndNum(self.curCardPoolId) --付费购买 if countInBag >= 1 then --购买 MDL.DrawCard.RequestDrawCard(self.curCardPoolId, 1, self.isSkipAnim, true) else --弹出购买道具框 local store = MDL.OperationActivity.StoreGoodsData:GetDataByID(self.itemStoreId) local currencyID = store.MoneyID local currencyCount = store.BuyPrice UIManager.OpenView(Const_UI_Lua.UIEnum.UIItemBuyPanel, {ItemId = self.itemId, ItemStoreId = self.itemStoreId, CurrencyId = currencyID, CurrencyCount = currencyCount}) end end end function UIGachaMain:ProcessDrawCradTen() local canBuy, ids = MDL.DrawCard.CanDrawCardByTen() if not canBuy then CTL.Tips.AddTipsMsg(ids) return end local itemId, countInBag, costNum, itemStoreId = MDL.DrawCard.GetConstItemAndNum(self.curCardPoolId) if countInBag >= 10 then --购买 MDL.DrawCard.RequestDrawCard(self.curCardPoolId, 10, self.isSkipAnim, false) else --弹出购买道具框 local store = MDL.OperationActivity.StoreGoodsData:GetDataByID(self.itemStoreId) local currencyID = store.MoneyID local currencyCount = store.BuyPrice UIManager.OpenView(Const_UI_Lua.UIEnum.UIItemBuyPanel, {ItemId = self.itemId, ItemStoreId = self.itemStoreId, CurrencyId = currencyID, CurrencyCount = currencyCount, leftNumByNext = self.leftNumByNext}) end end -- ----------------消息回调---------------------------- function UIGachaMain:RefreshUI() self:RefreshCardPoolData() end function UIGachaMain:OnClosed() if self.AnyPortraitObj then TK2API.ReturnInstance(BG_PATH, self.AnyPortraitObj) self.AnyPortraitObj = nil end UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) UIManager.ActiveUIModle(true, "UIGachaMain") end return UIGachaMain