local UIFirstChargePanel = UIViewClass() local AWARD_PARAM = "Day%dReward" local DAY_SUM = 3 local TITLE_PATH = "UI_FirstCharge/sc_msz_0%s.png" local TITLE_PATH_VN = "UI_FirstCharge/sczy_msz_0%s.png" local FirstCharge_Red = { [1] = CTL.RedPoint.RedPointKey["FirstCharge_Tab1"], [2] = CTL.RedPoint.RedPointKey["FirstCharge_Tab2"], [3] = CTL.RedPoint.RedPointKey["FirstCharge_Tab3"], } function UIFirstChargePanel:OnCreated() UIUtils.SetActive(self.img_Info, false) UIUtils.SetActive(self.clickMask, false) for i,v in DataSheetManager.FirstCharge:GetEnumerator() do local data = v local num = data.RechargeAmount local toggle = self.group_Tab:GetToggle(i - 1) toggle:SetText(tostring(num)) end self.lastSelectTab = nil self.rewardContainer = {} end function UIFirstChargePanel:OnOpened(context) local isOpenAndPush = self.context and self.context.isOpenAndPush or false if not CTL.Unlock.CheckIfFuncUnlock(MDL.Unlock.FunctionType.FirstCharge, self, isOpenAndPush) then return end if isOpenAndPush then UIManager.ActiveUIModle(false, "UIFirstChargePanel") end self:RegistSystemEvent(EventID.UI_Update_FirstChargeInfo, self.UpdateInfo) self:RegistSystemEvent(EventID.UI_Shop_Recharge, self.UpdateInfo) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.CheckIfFuncUnlock) for i = 1, DAY_SUM do local redKey = FirstCharge_Red[i] self:RegistSystemEvent(redKey, self.RefreshFirstChargeRed) end self:UpdateInfo() self:RefreshFirstChargeRed() self:SetPushStyle(LuaConst.PushStyleEnum.HIDE) end function UIFirstChargePanel:CheckIfFuncUnlock() CTL.Unlock.CheckIfFuncUnlock(MDL.Unlock.FunctionType.FirstCharge, self) end function UIFirstChargePanel:RefreshFirstChargeRed() for i = 1, DAY_SUM do local redKey = FirstCharge_Red[i] self.group_Tab:SetRedPoint(i - 1, CTL.RedPoint.GetRedPointActive(redKey)) end end function UIFirstChargePanel:GetGiftInfo(gifts, giftType) for _,v in ipairs(gifts) do if v.giftType == giftType then return v end end return nil end function UIFirstChargePanel:UpdateInfo() local info = MDL.FirstCharge.GetFirstChargeInfo() --tab数量 --优先选中可领取的页签 local selectTab = self.lastSelectTab or MDL.FirstCharge.GetLastSelectTab() local tabNum = #info.gifts for i,v in DataSheetManager.FirstCharge:GetEnumerator() do if tabNum >= i then self.group_Tab:SetToggleActive(i, true) if selectTab == nil then local vo = self:GetGiftInfo(info.gifts, i) if vo.isFinish == false then for _, receive in ipairs(vo.dayReceived) do if receive == false then selectTab = i - 1 break end end end end else if tabNum > 0 and i == tabNum + 1 then self.group_Tab:SetToggleActive(i, true) else self.group_Tab:SetToggleActive(i, false) end end end if self.lastSelectTab then --已经选中的标签,刷新时候不切换 self:OnTabClick(self.lastSelectTab, true) else if selectTab == nil then selectTab = 0 end self.group_Tab:SelectIndex(selectTab) end end function UIFirstChargePanel:OnTabClick(index, isForce) if index == self.lastSelectTab and isForce == false then return end self.lastSelectTab = index UIUtils.SetActive(self.group_Prompt, true) if GameAppInfo.IsVietnamPackage() then if index == 0 then UIUtils.SetLabelText(self.txt_Prompt,Const_IDS.IDS_FirstCharge_ZhaoYun1) elseif index == 1 then UIUtils.SetLabelText(self.txt_Prompt,Const_IDS.IDS_FirstCharge_ZhaoYunShenBing1) else UIUtils.SetActive(self.group_Prompt, false) end else if index == 0 then UIUtils.SetLabelText(self.txt_Prompt,Const_IDS.IDS_FirstCharge_HealingGenerals) elseif index == 1 then UIUtils.SetLabelText(self.txt_Prompt,Const_IDS.IDS_FirstCharge_XiaoQiaoShenBing1) else UIUtils.SetActive(self.group_Prompt, false) end end self.state_Name:SetState(index) self.state_Title:SetState(index) if GameAppInfo.IsVietnamPackage() and index + 1 == 1 then UIUtils.SetLocalizationImage(self.img_Title, string.format(TITLE_PATH_VN, index + 1)) else UIUtils.SetLocalizationImage(self.img_Title, string.format(TITLE_PATH, index + 1)) end self.img_Title:SetNativeSize() self.state_Hero:SetState(index) self.img_Hero:SetNativeSize() UIUtils.SetActive(self.btn_Check, index == 0) self.getRewardID = nil table.clear(self.rewardContainer) local configData = DataSheetManager.FirstCharge:GetDataByID(index + 1) self.txt_PackageName.text = configData.TotalAmount --再充值x元 local reChargeAmount = configData.RechargeAmount local curChargeTokens = MDL.Currency.GetTotalRechargeTokens() if curChargeTokens >= reChargeAmount then UIUtils.SetActive(self.group_ChargeAmount, false) else UIUtils.SetActive(self.group_ChargeAmount, true) self.lab_ChargeNum.text = string.FormatByIdsId(Const_IDS.IDS_FirstCharge_Charge, reChargeAmount - curChargeTokens) end local info = MDL.FirstCharge.GetFirstChargeInfo() local vo = self:GetGiftInfo(info.gifts, index + 1) if vo == nil then for i = 1, #self.group_Days do UIUtils.SetActive(self.group_Days[i].img_Received, false) self.group_Days[i].state_HighLight:SetState(0) self:SetDayAward(self.group_Days[i].group_Award, configData, i) end elseif vo.isFinish then for i = 1, #self.group_Days do UIUtils.SetActive(self.group_Days[i].img_Received, true) self.group_Days[i].state_HighLight:SetState(0) self:SetDayAward(self.group_Days[i].group_Award, configData, i) end else local days = #vo.dayReceived for i = 1, #self.group_Days do local isHighlight = false if days >= i then if vo.dayReceived[i] == true then UIUtils.SetActive(self.group_Days[i].img_Received, true) else UIUtils.SetActive(self.group_Days[i].img_Received, false) isHighlight = true if self.getRewardID == nil then self.getRewardID = configData.ID end end else UIUtils.SetActive(self.group_Days[i].img_Received, false) if isHighlight == false and i == days + 1 and self.getRewardID == nil then isHighlight = true end end if isHighlight then self.group_Days[i].state_HighLight:SetState(1) self.group_Days[i].img_HighLight:PlayUIEffect() else self.group_Days[i].state_HighLight:SetState(0) self.group_Days[i].img_HighLight:StopUIEffect() end self:SetDayAward(self.group_Days[i].group_Award, configData, i) end end --按钮文本 if self.getRewardID then UIUtils.SetLabelText(self.lab_Collect, Const_IDS.IDS_FirstCharge_Receive) self.btn_Get:SetRedPoint(true) self.btn_Get:SetGray(false) UIUtils.SetGray(self.lab_Collect, false) self.effect_Get:PlayUIEffect() else if vo == nil then UIUtils.SetLabel(self.lab_Collect, UTL.Color.FormatTextByColor("562514", UIUtils.GetLocalizedTxt(Const_IDS.IDS_FirstCharge_RechargeCollection))) self.btn_Get:SetRedPoint(false) self.btn_Get:SetGray(false) UIUtils.SetGray(self.lab_Collect, false) self.effect_Get:PlayUIEffect() else self.btn_Get:SetRedPoint(false) self.btn_Get:SetGray(true, false) UIUtils.SetGray(self.lab_Collect, true) self.effect_Get:StopUIEffect() if vo.isFinish then UIUtils.SetLabelText(self.lab_Collect, Const_IDS.IDS_FirstCharge_Received) else UIUtils.SetLabelText(self.lab_Collect, Const_IDS.IDS_FirstCharge_Nextday) end end end end function UIFirstChargePanel:SetDayAward(group_Award, configData, index) local rewardParam = string.format(AWARD_PARAM, index) local rewardID = configData[rewardParam] local award = DataSheetManager.FirstChargeReward:GetDataByID(rewardID) for i = 1, #group_Award do UTL.Item.SetItemCell(group_Award[i], award.Item_Table[i].ItemID, award.Item_Table[i].ItemNum) self.rewardContainer[group_Award[i].event_Click] = award.Item_Table[i].ItemID end end function UIFirstChargePanel:OnValueChanged(comp, index) if comp == self.group_Tab then self:OnTabClick(index, false) end end function UIFirstChargePanel:OnClosed() MDL.FirstCharge.SetLastSelectTab(self.lastSelectTab) local isOpenAndPush = self.context and self.context.isOpenAndPush or false if isOpenAndPush then UIManager.ActiveUIModle(true, "UIFirstChargePanel") end end function UIFirstChargePanel:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIFirstChargePanel:OnButtonClicked(comp) if comp == self.btn_Close then if self.context and self.context.isOpenAndPush then self:CloseView(true) else self:CloseView() end MDL.FirstCharge.SetLastSelectTab(nil) elseif comp == self.btn_Info then UIUtils.SetActive(self.img_Info, true) UIUtils.SetActive(self.clickMask, true) elseif comp == self.clickMask then UIUtils.SetActive(self.img_Info, false) UIUtils.SetActive(self.clickMask, false) elseif comp == self.btn_Check then --跳转武将 local heroID = DataSheetManager.ConstData:GetDataByID("FirstChargeHero").IntValue UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroSelectPanel, { heroID = heroID }) elseif comp == self.btn_Get then if self.getRewardID then MDL.FirstCharge.FirstChargeGiftReq(self.getRewardID) else --跳转充值界面 CTL.ItemSources.ExecuteSourceFunctionById(MDL.ItemSources.SourceType.Recharge) end else local awardID = self.rewardContainer[comp] if awardID then UTL.ItemTips.ShowCommonTipsById(awardID) end end end return UIFirstChargePanel