local GiftPopUI = class("GiftPopUI", BaseUI) local MAX_ITEM_NUM = 4 local MAX_GIFT_ID = 90102 function GiftPopUI:ctor(params) params = params or {} self.actType = PayManager.PURCHARSE_TYPE.ACT_GIFT self.actId = DataManager.ArenaData:getGiftId() DataManager.ArenaData:cleaShowPopGift() end function GiftPopUI:isFullScreen() return false end function GiftPopUI:getPrefabPath() return "assets/prefabs/ui/arena/arena_gift_pop_ui.prefab" end function GiftPopUI:onLoadRootComplete() if not self.actType or not self.actId then self:closeUI() return end self.uiMap = self.root:genAllChildren() self.uiMap["gift_pop_ui.close_btn"]:addClickListener(function() self:closeUI() end) self.titleTx = self.uiMap["gift_pop_ui.bg.title"] self.banner = self.uiMap["gift_pop_ui.bg.banner"] self.offNode = self.uiMap["gift_pop_ui.bg.off_img"] self.offText = self.uiMap["gift_pop_ui.bg.off_img.text"] self.rewardCellList = {} for i = 1, MAX_ITEM_NUM do table.insert(self.rewardCellList, CellManager:addCellComp(self.uiMap["gift_pop_ui.bg.item_node.pop_reward_cell_" .. i], GConst.TYPEOF_LUA_CLASS.POP_REWARD_CELL)) end self.itemNodeLayout = self.uiMap["gift_pop_ui.bg.item_node"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_HORIZONTAL_OR_VERTICAL_LAYOUT) self.timeNode = self.uiMap["gift_pop_ui.bg.time_node"] self.timeText = self.uiMap["gift_pop_ui.bg.time_node.text"] self.buyBtn = self.uiMap["gift_pop_ui.bg.buy_btn"] self.buyBtnTx = self.uiMap["gift_pop_ui.bg.buy_btn.text"] self.buyBtnIcon = self.uiMap["gift_pop_ui.bg.buy_btn.icon"] self.buyBtn:addClickListener(function() self:onClickGift() end) self:scheduleGlobal(function() self:updateTime() end, 1) self:refresh() end function GiftPopUI:refresh() self.titleTx:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_40)) -- self.banner:setTexture(GIFT_BG_NAME[self.actType][type]) local cfgInfo = PayManager:getGiftConfigInfo(self.actType, self.actId) if cfgInfo then local off = cfgInfo.value or 0 if off < 100 then -- 统一为百分比格式 off = off * 100 end if off > 0 then self.offNode:setVisible(true) self.offText:setText(tostring(off) .. "%") else self.offNode:setVisible(false) end end local rewards = cfgInfo.reward or {} for i = 1, MAX_ITEM_NUM do for i = 1, MAX_ITEM_NUM do if i <= #rewards then self.rewardCellList[i]:setVisible(true, 0.8) self.rewardCellList[i]:refresh(rewards[i].id, rewards[i].num, true) else self.rewardCellList[i]:setVisible(false) end end end self.itemNodeLayout:RefreshLayout() local rechargeId = cfgInfo.recharge_id if rechargeId then self.buyBtnTx:setText(GFunc.getFormatPrice(rechargeId)) end -- 上报 local giftType = PayManager:getGiftType(self.actType, self.actId) BIReport:postPayUIShow(giftType, self.actId) self:updateTime() end function GiftPopUI:updateTime() local hasTime = true local remainTime = DataManager.ArenaData:getGiftRemainTime() if remainTime <= 0 then self:closeUI() end self.timeText:setText(Time:formatNumTime(remainTime)) self.timeNode:setVisible(hasTime) end function GiftPopUI:onClickGift() PayManager:purchasePackage(self.actId, self.actType) end return GiftPopUI