local UIGachaMainLimit = UIViewClass() local GiveItemId = DataSheetManager.ConstData:GetDataByID("LimitDrawCardGiveItemId").IntValue local ProgressStr = "%s(%d/%d)" local HintTextIDS = "IDS_LimitDrawCard_GiveHint" --日本多语言需要修改背景大小 local ReceivedBGWidth = 160 local ReceivedBGHeight = 40 -------------------------------- 系统函数 ------------------------------------------- function UIGachaMainLimit:OnOpened(context) self.activityId = context.activityId self.activityType = context.activityType self.drawCardPoolId = context.drawCardPoolId self.drawCardStoreId = context.drawCardStoreId self.heroType = context.heroType local drawData = DataSheetManager.DrawCardData:GetDataByID(self.drawCardPoolId) self:InitView(drawData) self:RegistSystemEvent(EventID.UI_OperationActivity_InfoChanged, self.InitActivityInfo) self:RegistSystemEvent(EventID.UI_GachaLimit_Refresh, self.RefreshPanel) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_OperationActivity_CloseView, self.OnCloseActivitySelf) self.itemStoreID = drawData.ItemStoreID local consumeId = drawData.Item local consumeData = DataSheetManager.ItemData:GetDataByID(consumeId) local consumeName = UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[consumeData.Name]), consumeData.Color) local giveItemData = DataSheetManager.ItemData:GetDataByID(GiveItemId) local giveItemName = UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[giveItemData.Name]), giveItemData.Color) self.txt_Info.text = string.FormatByIdsId(Const_IDS[HintTextIDS], consumeName, giveItemName) self.toggle_Skip.isOn = CTL.ActivityGacha.IsSkipAnim(self.activityType) self:InitActivityInfo() CTL.GoldenHeroMain.SetIsOpenedActivity(self.activityId, true) -- 打开界面时停止自动寻路 防止抽卡TimeLine和剧情重叠 NotSyncBattleSetter.StopAutoFightPathInTown() --停止现在的寻路 CTL.ActivityGacha.TryReOpenDrawCardResult() self:InitChooseView(true) end function UIGachaMainLimit:InitChooseView(isInit) local activityPoolInfo = MDL.ActivityGacha.GetActivityDrawInfo(self.activityId) local activityPoolID = activityPoolInfo.cardPoolId local modelData = {} if self.activityType == MDL.OperationActivity.ActivityType.GoldenHero then modelData = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(self.heroType) elseif self.activityType == MDL.OperationActivity.ActivityType.SuperGold then modelData = DataSheetManager.SuperGoldActivityModeData:GetDataByHeroType(self.heroType) end local curDrawCardPoolID = activityPoolID > 0 and activityPoolID or modelData.DrawCardPoolID if activityPoolID <= 0 then if self.activityType == MDL.OperationActivity.ActivityType.GoldenHero then self.curHeroID = modelData.SynergyBossHeroID elseif self.activityType == MDL.OperationActivity.ActivityType.SuperGold then self.curHeroID = modelData.HeroID end else if self.activityType == MDL.OperationActivity.ActivityType.GoldenHero then for k, v in DataSheetManager.GoldHeroActivityModeData:GetEnumerator() do if v.DrawCardPoolID == curDrawCardPoolID then self.curHeroID = v.SynergyBossHeroID break end end elseif self.activityType == MDL.OperationActivity.ActivityType.SuperGold then for k, v in DataSheetManager.SuperGoldActivityModeData:GetEnumerator() do if v.DrawCardPoolID == curDrawCardPoolID then self.curHeroID = v.HeroID break end end end end local isCanSwitchCardHero = CTL.ActivityGacha.IsCanSwitchCardHero(self.activityId, self.drawCardStoreId, self.curHeroID, true, self.activityType) UIUtils.SetActive(self.btn_Switch, isCanSwitchCardHero) if isInit then if isCanSwitchCardHero and not activityPoolInfo.isOpen then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGoldHeroOptional, { drawCardType = CTL.DrawCard.DrawCardType.Limit, heroType = self.heroType, activityId = self.activityId, activityType = self.activityType, drawCardStoreId = self.drawCardStoreId}) end end end function UIGachaMainLimit:InitView(drawData) self.canClaimReward = false self.drawCardRewardData = nil --标题 UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS[drawData.PoolName]) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) CTL.GoldenHeroMain.OpenCurrencyPanel(self.heroType, self.__viewClassPath, self.currency_Info, {activityType = MDL.OperationActivity.ActivityType.GoldenHero, activityId = self.activityId, title = "IDS_DrawCard_Title_QuickBuy"}) end function UIGachaMainLimit:OnCloseActivitySelf(viewClassPath, activityId) if viewClassPath == self.__viewClassPath then if self.activityId and activityId == self.activityId then self:CloseSubViews() self:CloseView(true) end end end function UIGachaMainLimit:InitActivityInfo() local endTime = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, self.activityId).endTime self.leftTime = endTime - UTL.Time.GetServerTimestamp() self:RefreshEndTime(self.leftTime) self:StartRepeatFunc(self.OnUpdateFun, 1) self:RefreshPanel() end function UIGachaMainLimit:CloseSubViews() UIManager.CloseView(Const_UI_Lua.UIEnum.UIGachaRewardLimit) UIManager.CloseView(Const_UI_Lua.UIEnum.UIGachaSummary) UIManager.CloseView(Const_UI_Lua.UIEnum.UIGachaGetLimit) end function UIGachaMainLimit:OnUpdateFun(deltaTime, timeSinceUpdate) self:RefreshEndTime(self.leftTime - timeSinceUpdate) if self.leftTime - timeSinceUpdate <= 0 then self:CheckIfFuncUnlock() end end function UIGachaMainLimit:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIGachaMainLimit:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Exchange then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGachaShop, {drawCardType = CTL.DrawCard.DrawCardType.Limit, activityId = self.activityId, activityType = self.activityType, drawCardPoolId = self.drawCardPoolId, drawCardStoreId = self.drawCardStoreId, heroType = self.heroType}) elseif comp == self.btn_Info or comp == self.btn_ProbabilityInfo then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGachaSummary, {drawCardType = CTL.DrawCard.DrawCardType.Limit, activityId = self.activityId, activityType = self.activityType, drawCardPoolId = self.drawCardPoolId}) elseif comp == self.btn_RewardInfo then self:OnClickRewardInfo() elseif comp == self.btn_Reward then self:OnClickBottomReward() elseif comp == self.btn_Gacha1 then self:DrawCardProcess(1) elseif comp == self.btn_Gacha10 then self:DrawCardProcess(10) elseif comp == self.btn_Switch then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGoldHeroOptional, { drawCardType = CTL.DrawCard.DrawCardType.Limit, heroType = self.heroType, activityId = self.activityId, activityType = self.activityType, drawCardStoreId = self.drawCardStoreId}) else self:OnOtherButtonClicked(comp) end end function UIGachaMainLimit:OnClickRewardInfo() local info = MDL.ActivityGacha.GetActivityDrawInfo(self.activityId) UIManager.OpenView(Const_UI_Lua.UIEnum.UIGachaRewardLimit, {activityId = self.activityId, poolId = self.drawCardPoolId, curRewardIndex = self:GetRewardIndex(info), curDrawCount = info.drawCount}) end function UIGachaMainLimit:OnClickBottomReward() if self.canClaimReward then local rewardIndex = self:GetRewardIndex(MDL.ActivityGacha.GetActivityDrawInfo(self.activityId)) MDL.ActivityGacha.RequestActivityDrawNumReward(self.activityId, self.activityType, rewardIndex + 1) else UTL.ItemTips.ShowCommonTipsById(self.drawCardRewardData.Item_Table[1].ItemID) end end function UIGachaMainLimit:OnOtherButtonClicked(comp) --可以被重写的方法 end ----------------------------------------------------------------------------------- function UIGachaMainLimit:RefreshPanel() self:RefreshDrawCardConsumeItem() if GameAppInfo.IsJapanesePackage() then self:SetJapanRewardInfo() else self:SetCommonRewardInfo() end self:InitChooseView() end function UIGachaMainLimit:SetCommonRewardInfo() self.state_JP:SetState(0) local info = MDL.ActivityGacha.GetActivityDrawInfo(self.activityId) local rewardIndex = self:GetRewardIndex(info) local _ , drawCardRewardData = DataSheetManager.DrawCardReward:TryGetDataByID_ChildID(self.drawCardPoolId, rewardIndex + 1) self.drawCardRewardData = drawCardRewardData local isMaxReward = false if not self.drawCardRewardData then self.drawCardRewardData = DataSheetManager.DrawCardReward:GetDataByID_ChildID(self.drawCardPoolId, rewardIndex) isMaxReward = true end local drawCount = info.drawCount > self.drawCardRewardData.DrawNum and self.drawCardRewardData.DrawNum or info.drawCount UIUtils.SetLabel(self.lab_Score, string.format(ProgressStr, UIUtils.GetLocalizedTxt(Const_IDS.IDS_DrawCard_LimitAccumulativeHint), drawCount, self.drawCardRewardData.DrawNum)) self.slider_Score.value = drawCount / self.drawCardRewardData.DrawNum self.canClaimReward = not isMaxReward and drawCount == self.drawCardRewardData.DrawNum self:SetProgressItemIcon() if self.canClaimReward then self.group_Available:PlayUIEffect() else self.group_Available:StopUIEffect() end UIUtils.SetActive(self.group_Received, isMaxReward) self:UIAdjustRegion(isMaxReward) end function UIGachaMainLimit:SetJapanRewardInfo() self.state_JP:SetState(1) local info = MDL.ActivityGacha.GetActivityDrawInfo(self.activityId) local drawCount = info.drawCount local stageDrawNum local probability for i, v in DataSheetManager.GoldHeroProbabilityShow:GetEnumerator() do if drawCount < v.RewardNum then probability = v.ProbabilityShow stageDrawNum = v.RewardNum break end end self.txt_Probability.text = "" self.txt_ProbabilityTip.text = string.FormatByIdsKey("IDS_Japan_GoldHero_Tips2", drawCount, stageDrawNum, probability) end function UIGachaMainLimit:GetRewardIndex(drawInfo) return drawInfo.rewardIndex end function UIGachaMainLimit:SetProgressItemIcon() UTL.Item.SetItemIcon(self.img_Item, self.drawCardRewardData.Item_Table[1].ItemID) self.txt_ItemNum.text = self.drawCardRewardData.Item_Table[1].ItemNum end function UIGachaMainLimit:RefreshDrawCardConsumeItem() local itemId, countInBag = CTL.ActivityGacha.GetConsumeItemInfos(self.drawCardPoolId) UTL.Item.SetCurrencyImageIcon(self.img_Icon_One, itemId) UIUtils.SetLabel(self.txt_One, CTL.ActivityGacha.GetGachaCostNumShow(itemId, 1)) UTL.Item.SetCurrencyImageIcon(self.img_Icon_Ten, itemId) UIUtils.SetLabel(self.txt_Ten, CTL.ActivityGacha.GetGachaCostNumShow(itemId, 10)) self.btn_Gacha1:SetRedPoint(countInBag > 0) self.btn_Gacha10:SetRedPoint(countInBag >= 10) end function UIGachaMainLimit:RefreshEndTime(endTime) if endTime > UTL.Time.TotalSecondsOneDay then -- 超过一天 UIUtils.SetLabel(self.lab_RemainTime, UTL.Time.GetShowTimeByMinutes(endTime / UTL.Time.TotalSecondsOneMinute)) elseif endTime <= UTL.Time.TotalSecondsOneDay and endTime >= UTL.Time.TotalSecondsOneHour then UIUtils.SetLabel(self.lab_RemainTime, UTL.Time.FormatTimeClockBySeconds(endTime)) else UIUtils.SetLabel(self.lab_RemainTime, UTL.Time.FormatTimeSeconds(endTime)) end end function UIGachaMainLimit:DrawCardProcess(drawCount) local itemId, countInBag = CTL.ActivityGacha.GetConsumeItemInfos(self.drawCardPoolId) if countInBag >= drawCount then local endTime = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, self.activityId).endTime local leftTime = endTime - UTL.Time.GetServerTimestamp() if leftTime < UTL.Time.TotalSecondsOneMinute then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Monopoly_EndTips) return end if CTL.ActivityGacha.IsCanSwitchCardHero(self.activityId, self.drawCardStoreId, self.curHeroID, true, self.activityType) then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_COMMON_PROMPT, Const_IDS.IDS_GoldHeroChoose_Hint_9, function () MDL.ActivityGacha.RequestActivityDrawCard(self.activityId, self.activityType, drawCount) end) else MDL.ActivityGacha.RequestActivityDrawCard(self.activityId, self.activityType, drawCount) end else if self.itemStoreID > 0 then --弹出购买道具框 local store = MDL.OperationActivity.StoreGoodsData:GetDataByID(self.itemStoreID) local currencyID = store.MoneyID local currencyCount = store.BuyPrice UIManager.OpenView(Const_UI_Lua.UIEnum.UIItemBuyPanel, {ItemId = itemId, ItemStoreId = self.itemStoreID, CurrencyId = currencyID, CurrencyCount = currencyCount}) else CTL.OperationActivity.OpenGetActivityItemPanel(itemId, self.activityId, self.activityType) end end end function UIGachaMainLimit:OnClosed() UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) end function UIGachaMainLimit:OnValueChanged(comp, value) if comp == self.toggle_Skip then CTL.ActivityGacha.SetSkipAnim(self.activityType, value) end end function UIGachaMainLimit:RefreshChangeCardInfo(activityId) if self.activityId == activityId then UIManager.CloseView(Const_UI_Lua.UIEnum.UIGoldHeroOptionalPupup) UIManager.CloseView(Const_UI_Lua.UIEnum.UIGoldHeroOptional) self:CloseView(true) CTL.GoldenHeroMain.OpenDrawCardMainPanel(self.activityId) end end function UIGachaMainLimit:UIAdjustRegion(isMaxReward) if isMaxReward and GameAppInfo.IsJapanesePackage() then UIUtils.ChangeWidth(self.group_Received.gameObject, ReceivedBGWidth) UIUtils.ChangeHeight(self.group_Received.gameObject, ReceivedBGHeight) end end return UIGachaMainLimit