miduo_client/Assets/ManagedResources/~Lua/Modules/Recharge/View/EveryDayGift.lua

338 lines
12 KiB
Lua

local EveryDayGift = {}
local rechargeNum = 0
function EveryDayGift:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = EveryDayGift })
return b
end
--添加事件监听(用于子类重写)
function EveryDayGift:AddListener()
end
--移除事件监听(用于子类重写)
function EveryDayGift:RemoveListener()
end
function EveryDayGift:InitComponent()
self.bg = Util.GetGameObject(self.gameObject, "rzyBg")
self.titleBgIma = Util.GetGameObject(self.bg,"bg"):GetComponent("Image")
self.titleIma = Util.GetGameObject(self.bg,"titleIma"):GetComponent("Image")
self.titleTipBg = Util.GetGameObject(self.bg,"titleTipBg"):GetComponent("Image")
self.titleTip = Util.GetGameObject(self.bg,"titleTip"):GetComponent("Text")
self.extra = Util.GetGameObject(self.bg,"extarTitle")
self.freeBtn = Util.GetGameObject(self.extra,"freeBtn")
self.freeBtnAnim = Util.GetGameObject(self.freeBtn,"UI_effect_TanSuo_Box"):GetComponent("Animator")
self.redPoint = Util.GetGameObject(self.bg,"freeBtn/redPoint")
self.oneKey = Util.GetGameObject(self.extra,"oneKey")
self.buyAllBtn = Util.GetGameObject(self.oneKey,"oneKeyBtn")
self.oriPrice = Util.GetGameObject(self.oneKey,"oriPrice"):GetComponent("Text")
self.nowPrice = Util.GetGameObject(self.oneKey,"nowPrice"):GetComponent("Text")
self.endTimeBg = Util.GetGameObject(self.bg,"tiao")
self.endTime = Util.GetGameObject(self.endTimeBg,"time"):GetComponent("Text")
self.itemPre = Util.GetGameObject(self.bg,"ItemPre")
self.scrollItem = Util.GetGameObject(self.bg,"scrollItem")
self.lightList = {
Util.GetGameObject(self.freeBtnAnim.gameObject,"bg_ray"),
Util.GetGameObject(self.freeBtnAnim.gameObject,"yinying/ray 1"),
Util.GetGameObject(self.freeBtnAnim.gameObject,"yinying/ray 2"),
Util.GetGameObject(self.freeBtnAnim.gameObject,"yinying/ray 3"),
Util.GetGameObject(self.freeBtnAnim.gameObject,"yinying/ray 4"),
}
-- 设置循环滚动,万一礼包内容不停地加
local rootHight = self.scrollItem.transform.rect.height
local width = self.scrollItem.transform.rect.width
self.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollItem.transform,
self.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 35))
self.scrollView.moveTween.MomentumAmount = 1
self.scrollView.moveTween.Strength = 2
self.ItemList = {}
self.sortingOrder = 0
end
function EveryDayGift:BindEvent()
Util.AddClick(self.buyAllBtn,function ()
PayManager.Pay(1004, function(id)
FirstRechargeManager.RefreshAccumRechargeValue(1004)
PlayerPrefs.SetInt(PlayerManager.uid.."czlb", 0)
CheckRedPointStatus(RedPointType.GrowthPackage)
self:RefreshData()
end)
end)
end
--界面打开时调用(用于子类重写)
function EveryDayGift:OnOpen(_activityConfig,_index,parent)
self.actConfig = _activityConfig
self.pageIndex = _index
self.parent = parent
self.gameObject.name = "EveryDayGift"..self.actConfig.Id
end
-- 打开,重新打开时回调
function EveryDayGift:OnShow(_sortingOrder)
self.gameObject:SetActive(true)
self.sortingOrder = _sortingOrder or self.sortingOrder
self.extra:SetActive(true)
self.actId = self.actConfig.ActId
self.actType = self.actConfig.ActiveType
if self.actConfig.IfBack == 1 then
if self.actConfig.ActiveType > 0 then
local id = ActivityGiftManager.IsActivityTypeOpen(self.actConfig.ActiveType)
if id and id > 0 then
self.actId = id
local config = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups,"PageType",self.actConfig.PageType,"ActiveType",self.actConfig.ActiveType,"ActId",id)
if config then
self.actConfig = config
end
end
end
end
if self.actConfig.Icon[3] and self.actConfig.Icon[3] ~= "" then
self.titleBgIma.sprite = Util.LoadSprite(self.actConfig.Icon[3])
end
if self.actConfig.Icon[4] and self.actConfig.Icon[4] ~= "" then
self.titleIma.gameObject:SetActive(true)
self.titleIma.sprite = Util.LoadSprite(self.actConfig.Icon[4])
self.titleIma:SetNativeSize()
self.titleIma.transform.localPosition = Vector3.New(self.actConfig.TitleImapos[1],self.actConfig.TitleImapos[2],self.actConfig.TitleImapos[3])
else
self.titleIma.gameObject:SetActive(false)
end
if self.actConfig.TitleText and self.actConfig.TitleText ~= "" then
local str = string.split(self.actConfig.TitleText,"|")
self.titleTip.text = str[1]
self.titleTip.transform.localPosition = Vector3.New((str[2] or 0),(str[3] or 0),(str[4] or 0))
self.titleTip.gameObject:SetActive(true)
else
self.titleTip.gameObject:SetActive(false)
end
self:RefreshData(true)
end
------日周月礼包------
-- 根据选择的页签刷新数据
function EveryDayGift:RefreshData(isUpdata)
if self.actConfig.RpType > 0 then
CheckRedPointStatus(self.actConfig.RpType)
end
self.shopData = DynamicActivityManager.GetGiftDataByType(self.actConfig.ShopData)
if isUpdata then
-- 刷新剩余时间
self:GetRemainTime()
-- 刷新一键购买显示
self:RefreshOneKeyShow()
self:RefreshFreeData()
end
-- 刷新商品数据
self:RefreshGiftData()
end
-- 刷新礼包的数据
function EveryDayGift:RefreshGiftData()
rechargeNum = VipManager.GetChargedNum()--已经充值的金额
self:isBought()
self.scrollView:ForeachItemGO(function(index, go)
go.gameObject:SetActive(false)
end)
local callBack = function(index, item)
self:RefreshShowData(item, self.shopData[index],index)
end
local curindex = 0
self.scrollView:SetData(self.shopData, callBack)
for i = 1 ,#self.shopData do
if self.shopData[i].DataType == DynamicActivityManager.selectIndex.dataType then
for j = 1 , #DynamicActivityManager.selectIndex.goodsId do
if (self.shopData[i].data.shopData.id or self.shopData[i].data.shopData.goodsId) == DynamicActivityManager.selectIndex.goodsId[j] then
curindex = i
break
end
end
end
if curindex ~= 0 then
break
end
end
LogGreen("curindex:"..curindex)
self.scrollView:SetIndex(curindex)
end
function EveryDayGift:isBought()
for i = 1, #self.shopData do
if self.shopData[i].data.boughtNum > 0 then
Util.SetGray(self.buyAllBtn,true)
self.buyAllBtn:GetComponent("Button").interactable = false
break
end
end
end
--刷新每一条的显示数据
function EveryDayGift:RefreshShowData(item,_data,index)
if not self.ItemList then
self.ItemList = {}
end
if not self.ItemList[item] then
local subConfig = SubUIConfig[self.actConfig.UIName[2]]
self.ItemList[item] = SubUIManager.Open(subConfig,item.transform)
end
if not _data then
item.gameObject:SetActive(false)
return
end
item.gameObject:SetActive(true)
self.ItemList[item]:SetData(_data,self,rechargeNum,self.sortingOrder)
end
-- 刷新一键购买显示
function EveryDayGift:RefreshOneKeyShow()
if self.actType ~= ActivityTypeDef.MeiRiLiBao then
self.extra.gameObject:SetActive(false)
return
end
Util.SetGray(self.buyAllBtn,false)
self.buyAllBtn:GetComponent("Button").interactable = true
-- 计算总价
local ori = 0
for i = 1 , #self.shopData do
ori = ori + self.shopData[i].data.finalNum
end
-- 计算现价
local now = 0
now = now + MoneyUtil.GetMoney(ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig,1004).Price)
self.oriPrice.text = string.format("原价:%s元",ori)
self.nowPrice.text = string.format("现价:%s元",now)
end
--每种礼包的剩余时间
function EveryDayGift:GetRemainTime()
if self.actConfig.ShowTime == 0 then
self.endTimeBg.gameObject:SetActive(false)
return
end
self.endTimeBg.gameObject:SetActive(true)
local freshTime = 0
if self.shopData and #self.shopData > 0 then
freshTime = self.shopData[#self.shopData].data.endTime
end
local UpDate = function()
local showfreshTime = freshTime - GetTimeStamp()
if showfreshTime > 0 then
-- 剩余小时
local formatTime, leftHour = TimeToHMS(showfreshTime)
if leftHour > 24 then
self.endTime.text = Language[11355]..TimeToDHMS(showfreshTime)--天时分秒
else
self.endTime.text = Language[11355]..formatTime--时分秒
end
elseif showfreshTime < 0 then
self:RefreshData()
end
end
UpDate()
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
if not self.localTimer then
self.localTimer = Timer.New(UpDate, 1, -1, true)
self.localTimer:Start()
end
end
--刷新每日免费礼包
function EveryDayGift:RefreshFreeData()
if self.actType ~= ActivityTypeDef.MeiRiLiBao then
self.extra.gameObject:SetActive(false)
return
end
local freeData = ShopManager.GetShopDataByType(SHOP_TYPE.FREE_GIFT).storeItem
local boughtNum = ShopManager.GetShopItemHadBuyTimes(SHOP_TYPE.FREE_GIFT, freeData[1].id)
local limitNum = ShopManager.GetShopItemLimitBuyCount(freeData[1].id)
local isCanBuy = limitNum - boughtNum >= 1
self.freeBtnAnim.enabled = isCanBuy
self.redPoint:SetActive(isCanBuy)
-- 光效显隐
for _, light in ipairs(self.lightList) do
light:SetActive(isCanBuy)
end
CheckRedPointStatus(RedPointType.DailyGift)
Util.AddOnceClick(self.freeBtn,function()
if isCanBuy then
ShopManager.RequestBuyShopItem(SHOP_TYPE.FREE_GIFT, freeData[1].id, 1, function()
self:RefreshFreeData()
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.GrowthPackage)
end)
end
end)
end
function EveryDayGift:OnClose()
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
self.gameObject:SetActive(false)
end
function EveryDayGift:OnDestroy()
for k,v in pairs(self.ItemList) do
SubUIManager.Close(v)
end
self.ItemList = {}
if self.scrollView then
SubUIManager.Close(self.scrollView)
end
self.scrollView=nil
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
end
--特权商城专属
function EveryDayGift:SpecialTime(t)
if not t or t < 0 then
return Language[11749]
end
local _sec = t % 60
local allMin = math.floor(t / 60)
local _min = allMin % 60
local allHour = math.floor(t / 3600)
local _hour = allHour % 24
local allDays = math.floor(t / 86400)
if allDays>=1 then
return string.format(Language[11703],allDays),allDays
else
if _hour>=1 then
return string.format(Language[11704], _hour), _hour
else
if _min>=1 then
return string.format(Language[11705], _min), _min
else
return Language[12152]
end
end
end
return Language[11749]
end
return EveryDayGift