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

834 lines
35 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

local GiftView = quick_class("GiftView")
local shopItemConfig = ConfigManager.GetConfig(ConfigName.StoreConfig)
local rechargeCommodityConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
local rechargeNum
local DataType={
Shop = 1,--商品
Direct = 2,--直购
}
local timerList={}--时间预设容器
local Title_BG_NAME = {
[DirectBuyType.DAILY_GIFT] = "l_mrlb_banner_zh",
[DirectBuyType.FINDTREASURE_GIFT] = "t_tqsc_banner_zh",
[SHOP_TYPE.VIP_GIFT] = "c_czlb_banner_zh",--成长礼包
}
function GiftView:ctor(mainPanel, gameObject)
self.mainPanel = mainPanel
self.gameObject = gameObject
self:InitComponent(gameObject)
self:BindEvent()
self.ItemList = {}
end
--添加事件监听(用于子类重写)
function GiftView:AddListener()
-- Game.GlobalEvent:AddEvent(GameEvent.GrowGift.RechargeGift, GiftView.refresh)
end
--移除事件监听(用于子类重写)
function GiftView:RemoveListener()
-- Game.GlobalEvent:RemoveEvent(GameEvent.GrowGift.RechargeGift, GiftView.refresh)
end
function GiftView:InitComponent(gameObject)
self.spLoader = SpriteLoader.New()
self.itemPre = Util.GetGameObject(gameObject, "rzyBg/ItemPre")
self.itemPre2 = Util.GetGameObject(gameObject, "rzyBg/ItemPre2")
self.itemPre3 = Util.GetGameObject(gameObject, "rzyBg/ItemPre3")--成长礼包
self.bg = Util.GetGameObject(gameObject, "rzyBg")
self.titleBg = Util.GetGameObject(gameObject, "rzyBg/bg"):GetComponent("Image")
self.dayGiftIcon=Util.GetGameObject(gameObject,"rzyBg/dailygift")
self.freeBtn=Util.GetGameObject(gameObject,"rzyBg/freeBtn")
self.freeBtnAnim=Util.GetGameObject(gameObject,"rzyBg/freeBtn/UI_effect_TanSuo_Box"):GetComponent("Animator")
self.redPoint=Util.GetGameObject(gameObject,"rzyBg/freeBtn/redPoint")
self.endTime = Util.GetGameObject(gameObject, "rzyBg/Image/endTime"):GetComponent("Text")
self.endTimeBg = Util.GetGameObject(gameObject, "rzyBg/Image")
self.oneKey = Util.GetGameObject(gameObject, "oneKey")
self.buyAllBtn = Util.GetGameObject(self.oneKey, "Button")
self.oriPrice = Util.GetGameObject(self.oneKey, "oriPrice"):GetComponent("Text")
self.nowPrice = Util.GetGameObject(self.oneKey, "nowPrice"):GetComponent("Text")
self.allSaoGuang = Util.GetGameObject(self.oneKey, "saoguang")
Util.SetGray(self.buyAllBtn,false)
self.buyAllBtn:GetComponent("Button").interactable = true
self.allSaoGuang:SetActive(true)
self.scrollItem = Util.GetGameObject(gameObject, "rzyBg/scrollItem")
self.tip3 = Util.GetGameObject(gameObject, "rzyBg/tip3")
self.lightList = {
Util.GetGameObject(self.freeBtnAnim.transform,"bg_ray"),
Util.GetGameObject(self.freeBtnAnim.transform,"yinying/ray 1"),
Util.GetGameObject(self.freeBtnAnim.transform,"yinying/ray 2"),
Util.GetGameObject(self.freeBtnAnim.transform,"yinying/ray 3"),
Util.GetGameObject(self.freeBtnAnim.transform,"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.scrollView2 = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollItem.transform,
self.itemPre2, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 35))
self.scrollView2.moveTween.MomentumAmount = 1
self.scrollView2.moveTween.Strength = 2
--成长礼包的滚动条
self.scrollView3 = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollItem.transform,
self.itemPre3, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 35))
self.scrollView3.moveTween.MomentumAmount = 1
self.scrollView3.moveTween.Strength = 2
end
function GiftView:BindEvent()
Util.AddClick(self.buyAllBtn,function ()
PayManager.Pay(1004, function(id)
FirstRechargeManager.RefreshAccumRechargeValue(1004)
PlayerPrefs.SetInt(PlayerManager.uid.."czlb", 0)
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.GrowthPackage)
timerList={}
self:RefreshGiftData()
end)
end)
end
local curBuyType = 0
function GiftView:OnShow(_sortingOrder, buyType)
rechargeNum= VipManager.GetChargedNum()--已经充值的金额
curBuyType = buyType
self:RefreshData(buyType,true,true)
end
function GiftView:OnSortingOrderChange(cursortingOrder)
for i, v in pairs(self.ItemList) do
for j = 1, #self.ItemList[i] do
self.ItemList[i][j]:SetEffectLayer(cursortingOrder)
end
end
Util.SetParticleSortLayer(self.allSaoGuang, self.sortingOrder + 1)
end
-- function GiftView.refresh()
-- LogYellow("收到了GameEvent.GrowGift.RechargeGift")
-- GiftView:RefreshData(curBuyType)
-- end
------日周月礼包------
-- 根据选择的页签刷新数据
function GiftView:RefreshData(buyType,isTop,isAni)
-- 当前选中的页签
self.buyType = buyType
self.titleBg.sprite = self.spLoader:LoadSprite(Title_BG_NAME[buyType])
CheckRedPointStatus(RedPointType.GrowthPackage)
-- 刷新商品数据
self:RefreshGiftData(isTop,isAni)
-- 刷新剩余时间
self:GetRemainTime()
-- 刷新一键购买显示
self:RefreshOneKeyShow()
end
-- 刷新一键购买显示
function GiftView:RefreshOneKeyShow()
-- 计算总价
local ori = 0
ori = ori + MoneyUtil.GetMoney(rechargeCommodityConfig[1001].Price)
ori = ori + MoneyUtil.GetMoney(rechargeCommodityConfig[1002].Price)
ori = ori + MoneyUtil.GetMoney(rechargeCommodityConfig[1003].Price)
-- 计算现价
local now = 0
now = now + MoneyUtil.GetMoney(rechargeCommodityConfig[1004].Price)
-- self.oriPrice.text = "原价:"..MoneyUtil.GetMoneyMark()..ori
-- self.nowPrice.text = "现价:"..MoneyUtil.GetMoneyMark()..now
self.oriPrice.text = string.format(Language[10582],ori)
self.nowPrice.text = string.format(Language[10644],now)
end
-- 刷新礼包的数据
function GiftView:RefreshGiftData(isTop,isAni)
self:isBought()
self.scrollView.gameObject:SetActive(false)
self.scrollView2.gameObject:SetActive(false)
self.scrollView3.gameObject:SetActive(false)--成长礼包
local shopData = {}
if self.buyType ~= DirectBuyType.FINDTREASURE_GIFT and self.buyType ~= SHOP_TYPE.VIP_GIFT then--充值+每日礼包界面
--这个界面 普通商品只有 GoodsTypeDef.DirectPurchaseGift
shopData = self:ResetShopData(OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift), self.buyType, DataType.Direct)
table.sort(shopData,function(a,b)
if a.sortId == b.sortId then
return a.data.goodsId < b.data.goodsId
else
return a.sortId > b.sortId
end
end)
local callBack = function(index, item)
self:RefreshShowData(item, shopData[index].data, self.buyType, shopData[index].DataType)
end
self.scrollView:SetData(shopData, callBack,not isTop,not isAni)
self.scrollView.gameObject:SetActive(true)
elseif self.buyType == DirectBuyType.FINDTREASURE_GIFT then--特权礼包界面
--两部分组成 寻宝特权在商品里 极速探索礼包在直购里
local topspeedData = self:ResetShopData(ShopManager.GetShopDataByType(SHOP_TYPE.FINDTREASURE_GIFT).storeItem, self.buyType, DataType.Shop)
if RECHARGEABLE then--(是否开启充值)
shopData = self:ResetShopData(OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift), self.buyType, DataType.Direct)
end
for i = 1, #topspeedData do
table.insert(shopData,topspeedData[i])
end
table.sort(shopData,function(a,b)
if a.sortId == b.sortId then
if a.DataType == b.DataType and a.DataType == DataType.Direct and b.DataType == DataType.Direct then
return rechargeCommodityConfig[a.data.goodsId].Sequence < rechargeCommodityConfig[b.data.goodsId].Sequence
else
return a.DataType > b.DataType
end
else
return a.sortId > b.sortId
end
end)
local callBack = function(index, item)
self:RefreshShowData(item, shopData[index].data, self.buyType, shopData[index].DataType)
end
self.scrollView2:SetData(shopData, callBack,not isTop,not isAni)
self:TimeCountDown()
self.scrollView2.gameObject:SetActive(true)
elseif self.buyType == SHOP_TYPE.VIP_GIFT then--成长礼包界面
--每次重新登录会显示红点
PlayerPrefs.SetInt(PlayerManager.uid.."czlb", 1)
shopData = self:ResetShopData(ShopManager.GetShopDataByType(SHOP_TYPE.VIP_GIFT).storeItem, self.buyType, DataType.Shop)
--如果未达到充值要求不显示某些档位商品
for i = 1, #shopData do
if rechargeNum < shopItemConfig[shopData[i].data.id].ShowRule[2] then
shopData[i] = nil
end
end
--(礼包类型-成长礼包,页面的类型-SHOP_TYPE.VIP_GIFT商品)
table.sort(shopData,function(a,b)
if a.sortId == b.sortId then
return a.data.id < b.data.id
end
end)
local callBack = function(index, item)
self:RefreshShowData(item, shopData[index].data, self.buyType, shopData[index].DataType)
end
self.scrollView3:SetData(shopData, callBack,not isTop,not isAni)
self.scrollView3.gameObject:SetActive(true)
end
self:RefreshFreeData()
end
-- 商店数据重组
function GiftView:ResetShopData(shopData, buyType, DataTypeIndex)
local newData = {}
local boughtNum = 0
local limitNum = 0
for i = 1, #shopData do
if DataTypeIndex == DataType.Shop then
boughtNum = ShopManager.GetShopItemHadBuyTimes(SHOP_TYPE.FINDTREASURE_GIFT, shopData[i].id)
limitNum = ShopManager.GetShopItemLimitBuyCount(shopData[i].id)
local curSortId = 0--临时一个数值 只用做排序用
if limitNum == -1 then
curSortId = 3
elseif limitNum - boughtNum > 0 then
curSortId = 2
end
newData[#newData + 1] = {data = shopData[i],DataType = DataTypeIndex,sortId = curSortId}
elseif DataTypeIndex == DataType.Direct then
--所有直购 进行筛选 类型一致的取出
if rechargeCommodityConfig[shopData[i].goodsId].ShowType == buyType then
boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, shopData[i].goodsId)
limitNum = rechargeCommodityConfig[ shopData[i].goodsId].Limit
local curSortId = 0--临时一个数值 只用做排序用
if limitNum == -1 then
curSortId = 2
elseif limitNum - boughtNum > 0 then
curSortId = 1
end
--DataTypeIndex 1 商品 2 直购商品
newData[#newData + 1] = {data = shopData[i],DataType = DataTypeIndex,sortId = curSortId}
end
end
end
return newData
end
--每种礼包的剩余时间
function GiftView:GetRemainTime()
local localSelf = self
local freshTime = 0--剩余时间
--成长礼包不显示时间
local isGrowthGift = self.buyType == SHOP_TYPE.VIP_GIFT
self.endTimeBg:SetActive(not isGrowthGift)--成长礼包 没有倒计时
self.oneKey:SetActive(not isGrowthGift)
if isGrowthGift then--特权商城界面+成长礼包
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
self.endTime.text= ""
return
end
--特权礼包计时器写入item刷新中了,计时器就停了
local isPrivilegeGift = self.buyType == DirectBuyType.FINDTREASURE_GIFT
if isPrivilegeGift then
self.endTimeBg:SetActive(not isPrivilegeGift)
self.oneKey:SetActive(not isPrivilegeGift)
self.endTime.text= ""
end
--每日礼包
local isDailyGift = self.buyType == DirectBuyType.DAILY_GIFT
if isDailyGift then
local datalist = OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift)
for i = 1, #datalist do
if rechargeCommodityConfig[datalist[i].goodsId].ShowType == self.buyType then
if freshTime <= 0 then
freshTime = datalist[i].endTime
end
end
end
end
if freshTime and freshTime > 0 then--时间已经耗尽
else
return
end
local UpDate = function()
if not localSelf.localTimer then
return
end
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]..self:TimeToHMS(showfreshTime)--时分秒
end
elseif showfreshTime == 0 then
-- 时间到刷一下数据
--Log("刷新时间到了")
self:RefreshGiftData()
elseif showfreshTime==-1 then --不刷新显示内容
self.endTime.text=""
end
end
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
UpDate()
end
--刷新每日免费礼包
function GiftView:RefreshFreeData()
local isDaily = self.buyType == DirectBuyType.DAILY_GIFT
self.freeBtn:SetActive(isDaily)
self.dayGiftIcon:SetActive(isDaily)
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
local costId, finalNum, oriCostNum = ShopManager.calculateBuyCost(SHOP_TYPE.FREE_GIFT, freeData[1].id, 1)
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.GrowthPackage)
Util.AddOnceClick(self.freeBtn,function()
if isCanBuy then
self:BuyAction(costId, finalNum, SHOP_TYPE.FREE_GIFT, freeData[1].id)
end
end)
end
--根据数字位数计算艺术字体后面的文字位置
function GiftView:SetTextPos(num1)
local x = (string.len(tostring(num1))-1)*18 - 60
return x
end
function GiftView:isBought()
local data = OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift)
for i = 1, #data do
if rechargeCommodityConfig[data[i].goodsId].ShowType == 14 then
if data[i].buyTimes >0 then
Util.SetGray(self.buyAllBtn,true)
self.buyAllBtn:GetComponent("Button").interactable = false
self.allSaoGuang:SetActive(false)
break
end
end
end
end
--刷新每一条的显示数据
function GiftView:RefreshShowData(item, data, buyType, DataTypeIndex)
--绑定组件
local localSelf = self
local name = Util.GetGameObject(item, "context/text"):GetComponent("Text")
local icon = Util.GetGameObject(item, "btnBuy/icon")
local price = Util.GetGameObject(item, "btnBuy/price"):GetComponent("Text")
local buyInfo = Util.GetGameObject(item, "buyInfo"):GetComponent("Text")
local btnBuy = Util.GetGameObject(item, "btnBuy")
local grid = Util.GetGameObject(item, "scrollView/grid")
local shadow=Util.GetGameObject(item,"shadow")
local tipImage=Util.GetGameObject(item,"tipImage")
local tipImageText=Util.GetGameObject(item,"tipImage/Text"):GetComponent("Text")
local redPoint = Util.GetGameObject(item,"btnBuy/redPoint")
-- 设置tip显示
self:SetTipShow(Util.GetGameObject(item,"tip"), data, buyType, DataTypeIndex)
-- 物品Item
local shows
local shopItemData
-- 购买数量与限购数量
local rechargeNum = VipManager.GetChargedNum()--已经充值的金额
local boughtNum = 0
local limitNum = 0
local costId, finalNum, oriCostNum
local isPrivilegeGift = buyType == DirectBuyType.FINDTREASURE_GIFT
local isGrowthGift = buyType == SHOP_TYPE.VIP_GIFT
self.tip3:SetActive(isGrowthGift)
--道具商品 和 直购商品 获取数据的地方不一致
if DataTypeIndex == DataType.Shop then
if isPrivilegeGift then--特权商城
shopItemData = shopItemConfig[data.id]
shows = shopItemData.Goods
name.text = GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.ItemConfig,shows[1][1]).Name)
boughtNum = ShopManager.GetShopItemHadBuyTimes(SHOP_TYPE.FINDTREASURE_GIFT, data.id)
limitNum = ShopManager.GetShopItemLimitBuyCount(data.id)
costId, finalNum, oriCostNum = ShopManager.calculateBuyCost(SHOP_TYPE.FINDTREASURE_GIFT, data.id, 1)
tipImage:SetActive(isPrivilegeGift)
if isPrivilegeGift then
tipImageText.text = Language[11356]
end
elseif isGrowthGift then--成长礼包!!!!!!!!
local num = Util.GetGameObject(item, "context/number/num"):GetComponent("Text")
local yuan = Util.GetGameObject(item, "context/number/yuan")
local progress = Util.GetGameObject(item, "context/progress"):GetComponent("Text")
local numTextGrid = Util.GetGameObject(item, "NumTextPre")
shopItemData = shopItemConfig[data.id]
shows = shopItemData.Goods--奖励数据
local str = shopItemData.BuyRule[2]--需要充值的金额数
CreatNumberPrefab(tostring(str),numTextGrid,2)
--设置艺术字体后面的文字位置
-- local x = self:SetTextPos(shopItemData.BuyRule[2])
-- yuan:GetComponent("RectTransform").anchoredPosition = Vector2.New(x, 0)
progress.text = ""..rechargeNum.."/"..shopItemData.BuyRule[2]..Language[11698]--资格进度条
boughtNum = ShopManager.GetShopItemHadBuyTimes(SHOP_TYPE.VIP_GIFT, data.id)
limitNum = ShopManager.GetShopItemLimitBuyCount(data.id)
costId, finalNum, oriCostNum = ShopManager.calculateBuyCost(SHOP_TYPE.VIP_GIFT, data.id, 1)
-- 根据充值状态修改按钮图片
local isCanBuy = rechargeNum >= shopItemConfig[data.id].BuyRule[2]
btnBuy:GetComponent("Image").sprite = self.spLoader:LoadSprite(isCanBuy and "Btn_hz_cheng_01" or "Btn_hz_lan_01")
tipImage:SetActive(isGrowthGift)
if isGrowthGift then
tipImageText.text = Language[11356]
end
end
else
shopItemData = rechargeCommodityConfig[data.goodsId]
shows = shopItemData.RewardShow
name.text = GetLanguageStrById(shopItemData.Name)
boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, data.goodsId)
limitNum = shopItemData.Limit
costId, finalNum, oriCostNum = nil, MoneyUtil.GetMoney(shopItemData.Price), nil
tipImage:SetActive(isPrivilegeGift)
if isPrivilegeGift then
if shopItemData.DailyUpdate == 7 then
tipImageText.text = Language[11699]
elseif shopItemData.DailyUpdate == 15 then
tipImageText.text = Language[11700]
elseif shopItemData.DailyUpdate == 30 then
tipImageText.text = Language[11357]
end
end
end
--滚动条复用重设itemview
if self.ItemList[item] then
for i = 1, 5 do
self.ItemList[item][i].gameObject:SetActive(false)
end
for i = 1, #shows do
if self.ItemList[item][i] then
self.ItemList[item][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,self.mainPanel.sortingOrder)
self.ItemList[item][i].gameObject:SetActive(true)
end
end
else
self.ItemList[item]={}
for i = 1, 5 do
self.ItemList[item][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform)
self.ItemList[item][i].gameObject:SetActive(false)
local obj= newObjToParent(shadow,self.ItemList[item][i].transform)
obj.transform:SetAsFirstSibling()
obj.transform:DOAnchorPos(Vector3(0,-3,0),0)
obj:GetComponent("RectTransform").transform.localScale=Vector3.one*1.1
obj.gameObject:SetActive(true)
end
for i = 1, #shows do
self.ItemList[item][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,self.mainPanel.sortingOrder)
self.ItemList[item][i].gameObject:SetActive(true)
end
end
-- 设置按钮状态
local isCanBuy = limitNum - boughtNum > 0
btnBuy:GetComponent("Button").interactable = isCanBuy
--btnBuy:SetActive(true)
Util.SetGray(btnBuy,not isCanBuy)
icon:GetComponent("Image").enabled=isCanBuy
btnBuy:SetActive(true)
if isCanBuy then
if DataTypeIndex == DataType.Shop then--商品类按钮上的文字位置(空格慎调整!!!)
icon:SetActive(true)
icon:GetComponent("Image").sprite = SetIcon(self.spLoader, shopItemData.Cost[1][1])
price.alignment="MiddleRight"
price.alignment = "MiddleLeft"
price.text = finalNum--..str
else--直购类按钮上的文字位置(空格慎调整!!!)
price.alignment = "MiddleCenter"
icon:SetActive(false)
price.text = string.format(MoneyUtil.GetMoneyUnitName(), finalNum)
end
buyInfo.text = Language[10580]..limitNum - boughtNum..Language[10048]
else
price.alignment="MiddleCenter"
price.text=Language[10514]
buyInfo.text = ""
--特权 直购 按钮消失
if DataTypeIndex == DataType.Direct and isPrivilegeGift then
-- btnBuy:SetActive(false)
buyInfo.text=""
end
end
--为特权商城加的倒计时
local refreshTime = Util.GetGameObject(item,"refreshTime")
if refreshTime then
refreshTime:SetActive(false)
if DataTypeIndex == DataType.Direct and isPrivilegeGift then
local freshTime = 0
local datalist = OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift)--当前所有礼包数据
for i = 1, #datalist do
if rechargeCommodityConfig[datalist[i].goodsId].Id == data.goodsId then
if freshTime <= 0 then
freshTime = datalist[i].endTime
table.insert(timerList,{pre=refreshTime:GetComponent("Text"),freshTime=freshTime})
end
end
refreshTime:GetComponent("Text").text=Language[10469]..self:SpecialTime(freshTime-GetTimeStamp())
end
refreshTime:SetActive(not isCanBuy)
end
end
-- 请求购买
Util.AddOnceClick(btnBuy, function()
if not isCanBuy then
PopupTipPanel.ShowTip(Language[10515])
else
--道具商品
if DataTypeIndex == DataType.Shop then
if buyType == SHOP_TYPE.VIP_GIFT then
if rechargeNum >= shopItemConfig[data.id].BuyRule[2] then--充值金额达到要求
self:BuyAction(costId, finalNum, SHOP_TYPE.VIP_GIFT, data.id)--成长礼包
else--充值金额未达到要求
PopupTipPanel.ShowTip(Language[11701])
end
elseif buyType == DirectBuyType.FINDTREASURE_GIFT then
self:BuyAction(costId, finalNum, SHOP_TYPE.FINDTREASURE_GIFT, data.id)--特权商城
end
CheckRedPointStatus(RedPointType.GrowthPackage)
else
--直购商品
PayManager.Pay( data.goodsId, function(id)
FirstRechargeManager.RefreshAccumRechargeValue(data.goodsId)
PlayerPrefs.SetInt(PlayerManager.uid.."czlb", 0)
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.GrowthPackage)
timerList={}
self:RefreshGiftData()
end)
end
end
end)
end
local offSetX = {
[0] = { icon = Vector3.New(15.3,8,0),txt = Vector3.New(83.4,0.5,0),ima = Vector3.New(0,0,0),txt1 = Vector3.New(-162,0.5,0),icon1 = Vector3.New(-219.6,8,0)},
[1] = { icon = Vector3.New(219.86,8,0),txt = Vector3.New(288.5,0.5,0),ima = Vector3.New(20.19,0,0),txt1 = Vector3.New(-162,0.5,0),icon1 = Vector3.New(-219.6,8,0)},
[2] = { icon = Vector3.New(30,8,0),txt = Vector3.New(86.4,0.5,0),ima = Vector3.New(30,0,0),txt1 = Vector3.New(-105.7,0.5,0),icon1 = Vector3.New(-155.7,8,0)}
}
function GiftView:SetTipShow(tipRoot, data, buyType, DataTypeIndex)
if buyType == DirectBuyType.DAILY_GIFT then
local tip1=Util.GetGameObject(tipRoot,"tip1"):GetComponent("Image")
local tip1Text1=Util.GetGameObject(tipRoot,"tip1/text1"):GetComponent("Text")
local tip1Text2=Util.GetGameObject(tipRoot,"tip1/text2"):GetComponent("Text")
local tip2=Util.GetGameObject(tipRoot,"tip2"):GetComponent("Image")
local tip2Text=Util.GetGameObject(tipRoot,"tip2/text"):GetComponent("Text")
--道具商品 和 直购商品 获取数据的地方不一致
if DataTypeIndex == DataType.Shop then
local shopItemData = shopItemConfig[data.id]
-- 设置立赠提示
tip1.gameObject:SetActive(shopItemData.Goods[1][1] == 16 )
tip2.gameObject:SetActive(shopItemData.Goods[1][1] ~= 16)
tip1Text1.text=shopItemData.Goods[1][2]
tip1Text2.text=shopItemData.Rebate
tip2Text.text=shopItemData.Rebate
else
local shopItemData = rechargeCommodityConfig[data.goodsId]
-- 设置立赠提示
tip1.gameObject:SetActive(shopItemData.RewardShow[1][1] == 16 )
tip2.gameObject:SetActive(shopItemData.RewardShow[1][1] ~= 16)
tip1Text1.text=shopItemData.RewardShow[1][2]
tip1Text2.text=shopItemData.Rebate
tip2Text.text=shopItemData.Rebate
end
if GetCurLanguage() == 0 then
tip1Text1.gameObject:GetComponent("RectTransform").localPosition = offSetX[0].txt1
Util.GetGameObject(tipRoot,"tip1/icon_1"):GetComponent("RectTransform").localPosition = offSetX[0].icon1
tip1Text2.gameObject:GetComponent("RectTransform").localPosition = offSetX[0].txt
Util.GetGameObject(tipRoot,"tip1/icon_2"):GetComponent("RectTransform").localPosition = offSetX[0].icon
Util.GetGameObject(tipRoot,"tip1/Image"):GetComponent("RectTransform").localPosition = offSetX[0].ima
elseif GetCurLanguage() == 1 then
tip1Text1.gameObject:GetComponent("RectTransform").localPosition = offSetX[1].txt1
Util.GetGameObject(tipRoot,"tip1/icon_1"):GetComponent("RectTransform").localPosition = offSetX[1].icon1
tip1Text2.gameObject:GetComponent("RectTransform").localPosition = offSetX[1].txt
Util.GetGameObject(tipRoot,"tip1/icon_2"):GetComponent("RectTransform").localPosition = offSetX[1].icon
Util.GetGameObject(tipRoot,"tip1/Image"):GetComponent("RectTransform").localPosition = offSetX[1].ima
else
tip1Text1.gameObject:GetComponent("RectTransform").localPosition = offSetX[2].txt1
Util.GetGameObject(tipRoot,"tip1/icon_1"):GetComponent("RectTransform").localPosition = offSetX[2].icon1
tip1Text2.gameObject:GetComponent("RectTransform").localPosition = offSetX[2].txt
Util.GetGameObject(tipRoot,"tip1/icon_2"):GetComponent("RectTransform").localPosition = offSetX[2].icon
Util.GetGameObject(tipRoot,"tip1/Image"):GetComponent("RectTransform").localPosition = offSetX[2].ima
end
elseif buyType == DirectBuyType.FINDTREASURE_GIFT then
local tip1 = Util.GetGameObject(tipRoot,"tip1")
local tip1_en = Util.GetGameObject(tipRoot,"tip1_en")
local tip2 = Util.GetGameObject(tipRoot,"tip2")
local tip2_en = Util.GetGameObject(tipRoot,"tip2_en")
local tip3 = Util.GetGameObject(tipRoot,"tip3")
local tip3_en = Util.GetGameObject(tipRoot,"tip3_en")
local tip4 = Util.GetGameObject(tipRoot,"tip4")
local tip4_en = Util.GetGameObject(tipRoot,"tip4_en")
local tip5 = Util.GetGameObject(tipRoot,"tip5")
local tip6 = Util.GetGameObject(tipRoot,"tip6")
tip1:SetActive(false)
tip1_en:SetActive(false)
tip2:SetActive(false)
tip2_en:SetActive(false)
tip3:SetActive(false)
tip3_en:SetActive(false)
tip4:SetActive(false)
tip4_en:SetActive(false)
tip5:SetActive(false)
tip6:SetActive(false)
if DataTypeIndex == DataType.Shop then
if data.id == 20091 then
if GetCurLanguage() ~= 0 then
tip1_en:SetActive(true)
else
tip1:SetActive(true)
end
elseif data.id == 20092 then
if GetCurLanguage() ~= 0 then
tip2_en:SetActive(true)
else
tip2:SetActive(true)
end
end
elseif DataTypeIndex == DataType.Direct then
if data.goodsId == 4002 then
if GetCurLanguage() ~= 0 then
tip3_en:SetActive(true)
else
tip3:SetActive(true)
end
elseif data.goodsId == 4001 then
if GetCurLanguage() ~= 0 then
tip4_en:SetActive(true)
else
tip4:SetActive(true)
end
elseif data.goodsId == 4003 then
tip5:SetActive(true)
elseif data.goodsId == 7105 then
tip6:SetActive(true)
end
end
end
end
--购买点击事件
function GiftView:BuyAction(costId, costNum, shopType, itemId)
local haveNum = BagManager.GetItemCountById(costId)
local costName = GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.ItemConfig, costId).Name)
--Log("需要消耗的道具ID" .. costId)
if haveNum < costNum then
NotEnoughPopup:Show(costId)
else
local isPopUp = RedPointManager.PlayerPrefsGetStr(PlayerManager.uid .. shopType)
local currentTime = os.date("%Y%m%d", PlayerManager.serverTime)
if (isPopUp ~= currentTime and costNum ~= 0) or (shopType == SHOP_TYPE.VIP_GIFT and isPopUp ~= currentTime and costNum ~= 0) then
local str = string.format(Language[11360], costNum, costName)
MsgPanel.ShowTwo(str, function()
end, function(isShow)
if (isShow) then
local currentTime = os.date("%Y%m%d", PlayerManager.serverTime)
RedPointManager.PlayerPrefsSetStr(PlayerManager.uid .. shopType, currentTime)
end
ShopManager.RequestBuyShopItem(shopType, itemId, 1, function()
self:RefreshGiftData()
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.GrowthPackage)
end) end, Language[10731], Language[10732],nil,true)
else
ShopManager.RequestBuyShopItem(shopType, itemId, 1, function()
self:RefreshGiftData()
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.GrowthPackage)
end)
end
end
end
function GiftView:OnHide()
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
if self.localTimerV2 then
self.localTimerV2:Stop()
self.localTimerV2 = nil
end
timerList = {}
end
function GiftView:OnDestroy()
self.spLoader:Destroy()
self.scrollView=nil
self.scrollView2=nil
self.scrollView3=nil
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
ClearRedPointObject(RedPointType.GrowthPackage)
end
---------------------
-----------本模块特殊使用-----------
function GiftView:TimeToHMS(t)
if not t or t < 0 then
return Language[11365]
end
local _sec = t % 60
local allMin = math.floor(t / 60)
local _min = allMin % 60
local _hour = math.floor(allMin / 60)
return string.format(Language[10551], _hour, _min, _sec), _hour, _min, _sec
end
--特权商城专属
function GiftView:SpecialTime(t)
if not t or t < 0 then
return Language[11702]
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[11702]
end
function GiftView:TimeCountDown()
if self.localTimerV2 then
self.localTimerV2:Stop()
self.localTimerV2 = nil
end
if RECHARGEABLE then--(是否开启充值)
self.localTimerV2 = Timer.New(function()
if timerList[1] then
local t1=timerList[1].freshTime-GetTimeStamp()
t1=t1-1
if t1 <= 0 then
self:RefreshData(curBuyType,false,false)
end
timerList[1].pre.text=Language[10469]..self:SpecialTime(t1)--self:SpecialTime
end
if timerList[2] then
local t2 = timerList[2].freshTime-GetTimeStamp()
t2=t2-1
if t2 <= 0 then
self:RefreshData(curBuyType,false,false)
end
timerList[2].pre.text=Language[10469]..self:SpecialTime(t2)
end
end,1,-1,true)
self.localTimerV2:Start()
end
end
------------------------------
return GiftView