local UILuckyLotteryMain = UIViewClass() local AnimDelayTime = 1.4 local SelectDelayTime = 1 function UILuckyLotteryMain:OnOpened(context) self.activityId = context.activityId UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_LuckyLottery_Title) self:RegistSystemEvent(EventID.UI_LuckyLottery_InfoUpdate, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_LuckyLottery_RedPointUpdate, self.RefreshRp) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshLuckyStarNum) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshPoolCost) self.modeData = MDL.OperationActivity.LuckyLotteryModeData:GetDataByActivityID(self.activityId) --活动时间 local activityInfo = MDL.OperationActivity.GetOperationActivityInfo(MDL.OperationActivity.ActivityType.LuckyLottery, self.activityId) local startTime = os.date(UTL.Time.FormatDateEnum.MDHM, activityInfo.startTime) local endTime = os.date(UTL.Time.FormatDateEnum.MDHM, activityInfo.endTime) self.txt_Time.text = UIUtils.GetLocalizedTxt(Const_IDS.IDS_GoldHeroActivity_TimeHint1) .. ":"..startTime .. " - " .. endTime self:RefreshPanel() MDL.Friend.SendRefreshFriendInfos() end function UILuckyLotteryMain:RefreshPanel(refreshType) if self.drawAnim then self:StopUIAnimation(self.drawAnim, false, true) self.drawAnim = nil end if refreshType == MDL.LuckyLottery.PoolRefresh.Draw then UIUtils.SetActive(self.btn_Block, true) self.drawAnim = self:PlayUIAnimation("Draw") self.effect_Draw:PlayUIEffect() self:StartRepeatFunc(self.SendDrawReq, AnimDelayTime, 1) elseif refreshType == MDL.LuckyLottery.PoolRefresh.SelectReward then UIUtils.SetActive(self.btn_Block, true) self.effect_SelectReward:PlayUIEffect() self:StartRepeatFunc(self.RefreshPanel, SelectDelayTime, 1) else UIUtils.SetActive(self.btn_Block, false) self:RefreshLuckyStarNum() self:RefreshPoolInfo() self:RefreshAccumulateReward() self:RefreshRp(self.activityId) end end function UILuckyLotteryMain:SendDrawReq() MDL.LuckyLottery.ActivityLuckyLotteryOptReq(self.activityId) end function UILuckyLotteryMain:OnButtonClicked(comp) if comp == self.btn_Gift then UIManager.OpenView(Const_UI_Lua.UIEnum.UILuckyLotteryDirectGift, {activityId = self.activityId}) elseif comp == self.btn_LuckyBox then UIManager.OpenView(Const_UI_Lua.UIEnum.UILuckyLotteryFriendPopUp, {activityId = self.activityId}) elseif comp == self.btn_SelectReward then UIManager.OpenView(Const_UI_Lua.UIEnum.UILuckyLotterySelectReward, {activityId = self.activityId}) elseif comp == self.btn_Draw then if self.isEnough then self:RefreshPanel(MDL.LuckyLottery.PoolRefresh.Draw) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_LuckyLottery_MainHint_6) end elseif comp == self.UITemplateTitlePanel.btn_close then self:CloseView() elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.UITemplateTitlePanel.btn_Info then -- 玩法说明 UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.LuckyLottery}) else for i, v in ipairs(self.group_AccumulateReward) do if comp == v.btn_Reward then local data = MDL.OperationActivity.LuckyLotteryAccumulationReward:GetDataByActivityID_ID(self.activityId, i) if CTL.LuckyLottery.IsNumRewardClaimed(self.activityId, i) or MDL.LuckyLottery.GetLotteryNum(self.activityId) < data.DrawNum then UTL.ItemTips.ShowCommonTipsById(data.ItemID) else MDL.LuckyLottery.ActivityLuckyLotteryRewardReq(self.activityId, i) end return end end for i, v in ipairs(self.group_Ball) do if comp == v.btn_Reward then local rewardIdList = MDL.LuckyLottery.GetPoolIdList(self.activityId) if rewardIdList[i] then local data = MDL.OperationActivity.LuckyLotteryOptionalReward:GetDataByActivityID_ID(self.activityId, rewardIdList[i]) UTL.ItemTips.ShowCommonTipsById(data.ItemID) return end end end end end function UILuckyLotteryMain:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UILuckyLotteryMain:RefreshRp(activityId) if activityId == self.activityId then self.btn_LuckyBox:SetRedPoint(CTL.LuckyLottery.IsHasFriendReward(self.activityId)) self.btn_Draw:SetRedPoint(CTL.LuckyLottery.IsCanDraw(self.activityId)) self.btn_SelectReward:SetRedPoint(CTL.LuckyLottery.IsPoolUnset(self.activityId)) self.btn_Gift:SetRedPoint(CTL.LuckyLottery.GetDailyRedPoint()) end end function UILuckyLotteryMain:RefreshLuckyStarNum() local num = UTL.Item.GetItemStockCount(self.modeData.LuckyStarItemID) self.txt_LuckyStarNum.text = num self.state_LuckyBox:SetState(num == 0 and 0 or 1) end function UILuckyLotteryMain:RefreshPoolInfo() self:RefreshPoolReward() self:RefreshPoolCost() end function UILuckyLotteryMain:RefreshPoolReward() local rewardIdList = MDL.LuckyLottery.GetPoolIdList(self.activityId) for i, v in ipairs(self.group_Ball) do local rewardId = rewardIdList[i] if rewardId then local data = MDL.OperationActivity.LuckyLotteryOptionalReward:GetDataByActivityID_ID(self.activityId, rewardId) UIUtils.SetActive(v.img_None, false) UIUtils.SetActive(v.img_Item, true) UIUtils.SetActive(v.txt_Num, true) UIUtils.SetActive(v.group_GetMask, CTL.LuckyLottery.IsPoolRewardClaimed(self.activityId, rewardId)) UTL.Item.ItemIconWithoutBg(v.img_Item, data.ItemID) CTL.LuckyLottery.SetQualityBg(v.img_Quality, data.ItemID) v.txt_Num.text = data.ItemNum if data.FinalRewardSign > 0 then v.effect_Grand:PlayUIEffect() else v.effect_Grand:StopUIEffect() end else CTL.LuckyLottery.SetQualityBg(v.img_Quality) UIUtils.SetActive(v.img_None, true) UIUtils.SetActive(v.group_GetMask, false) UIUtils.SetActive(v.img_Item, false) UIUtils.SetActive(v.txt_Num, false) end end end function UILuckyLotteryMain:RefreshPoolCost() if not CTL.LuckyLottery.IsPoolRewardSelected(self.activityId) then self.state_Pool:SetState(2) self.btn_SelectReward:SetRedPoint(true) return end local lotteryNum = MDL.LuckyLottery.GetLotteryNum(self.activityId) if lotteryNum == MDL.LuckyLottery.GetTotalPoolRewardNum(self.activityId) then --奖池已经抽取完毕 self.state_Pool:SetState(1) self.isPoolFinish = true else self.state_Pool:SetState(0) local costData = MDL.OperationActivity.LuckyLotteryDrawCost:GetDataByActivityID_ID(self.activityId, lotteryNum + 1) local totalNeedNum = costData.TotalNum if totalNeedNum > 0 then UIUtils.SetActive(self.group_Cost.gameObject, true) local friendLotteryNum = UTL.Item.GetItemStockCount(self.modeData.FriendLotteryItemID) local friendLotteryShowNum = friendLotteryNum >= costData.FriendLotteryItemMaxNum and costData.FriendLotteryItemMaxNum or friendLotteryNum local temp = { {itemId = self.modeData.LotteryItemID, itemNum = totalNeedNum - friendLotteryShowNum}, {itemId = self.modeData.FriendLotteryItemID, itemNum = friendLotteryShowNum}, } local tempTotalNum = 0 for i, v in ipairs(self.group_Cost) do local data = temp[i] if data then if data.itemNum > 0 then UTL.Item.ItemIconWithoutBg(v.img_Icon, data.itemId) local hasNum = UTL.Item.GetItemStockCount(data.itemId) tempTotalNum = tempTotalNum + math.min(data.itemNum, hasNum) if hasNum >= data.itemNum then v.txt_Num.text = data.itemNum else v.txt_Num.text = UTL.Color.FormatRedColor(data.itemNum) end UIUtils.SetActive(v.gameObject, true) else UIUtils.SetActive(v.gameObject, false) end end end self.isEnough = tempTotalNum >= totalNeedNum if costData.FriendLotteryItemMaxNum > 0 then self.txt_CostInfo.text = string.FormatByIdsKey("IDS_LuckyLottery_MainHint_4", costData.FriendLotteryItemMaxNum) else self.txt_CostInfo.text = "" end else self.isEnough = true self.state_Pool:SetState(3) end self.btn_Draw:SetRedPoint(self.isEnough) self.isPoolFinish = false end end function UILuckyLotteryMain:RefreshAccumulateReward() local dataTable = MDL.OperationActivity.LuckyLotteryAccumulationReward:GetDataByActivityID_ID(self.activityId) local drawNum = MDL.LuckyLottery.GetLotteryNum(self.activityId) self.txt_Accumulate.text = UIUtils.GetLocalizedTxt(Const_IDS.IDS_LuckyLottery_MainHint_3) .. drawNum for i, v in ipairs(self.group_AccumulateReward) do local data = dataTable[i] if data then UIUtils.SetActive(v.gameObject, true) local itemId = data.ItemID UTL.Item.ItemIconWithoutBg(v.img_Item, itemId) UTL.Color.SetQualityImageByType(v.img_Quality, DataSheetManager.ItemData:GetDataByID(itemId).Color, UTL.Color.QualityType.StoreGoodsIconBase) v.txt_Num.text = "x" .. data.ItemNum local needNum = data.DrawNum v.txt_Accumulate.text = needNum local isEnough = drawNum >= needNum if CTL.LuckyLottery.IsNumRewardClaimed(self.activityId, data.ID) then v.state_Get:SetState(1) v.effect_Reward:StopUIEffect() v.btn_Reward:SetRedPoint(false) else v.state_Get:SetState(0) if isEnough then v.effect_Reward:PlayUIEffect() v.btn_Reward:SetRedPoint(true) else v.effect_Reward:StopUIEffect() v.btn_Reward:SetRedPoint(false) end end else UIUtils.SetActive(v.gameObject, false) end end end return UILuckyLotteryMain