282 lines
11 KiB
Lua
282 lines
11 KiB
Lua
local GrowthGiftPage = quick_class("GrowthGiftPage")
|
||
local curGiftsId--当前礼包Id
|
||
local actRewardConfig = ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)--读取礼包任务信息
|
||
local rewardNameConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)--读取奖励名称信息
|
||
local GlobalActivity = ConfigManager.GetConfig(ConfigName.GlobalActivity)
|
||
|
||
local giftList = {
|
||
[101] = 6,--表内没有礼包id(101、102、103、104、105)和ActivityId的对应关系,
|
||
[102] = 7,
|
||
[103] = 8,--自定义本表建立对应关系
|
||
[104] = 9,
|
||
[105] = 16,
|
||
}
|
||
|
||
function GrowthGiftPage:ctor(mainPanel, gameObject)
|
||
self.mainPanel = mainPanel
|
||
self.gameObject = gameObject
|
||
self:InitComponent(gameObject)
|
||
self:BindEvent()
|
||
self.ItemList = {}
|
||
end
|
||
|
||
function GrowthGiftPage:InitComponent(gameObject)
|
||
--定义头部文字和按钮
|
||
self.bg = Util.GetGameObject(gameObject, "rzyBg")
|
||
self.tip = Util.GetGameObject(gameObject, "rzyBg/bg/tip"):GetComponent("Text")
|
||
self.tip.text = Language[11464]
|
||
self.btnInvest = Util.GetGameObject(gameObject, "rzyBg/bg/btnInvest")
|
||
self.btnInvest:GetComponent("Button").onClick:AddListener(
|
||
function()
|
||
self:OnBtnInvestClicked()
|
||
end
|
||
)
|
||
self.btnInvestText = Util.GetGameObject(gameObject, "rzyBg/bg/btnInvest/Text"):GetComponent("Text")
|
||
--滚动条和预设
|
||
self.scrollItem = Util.GetGameObject(gameObject, "rzyBg/scrollItem")
|
||
self.itemPre = Util.GetGameObject(gameObject, "rzyBg/ItemPre")
|
||
--设置滚动条
|
||
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, 0))
|
||
self.scrollView.moveTween.MomentumAmount = 1
|
||
self.scrollView.moveTween.Strength = 2
|
||
|
||
end
|
||
|
||
function GrowthGiftPage:BindEvent()
|
||
end
|
||
|
||
function GrowthGiftPage:OnShow()
|
||
self.gameObject:SetActive(true)
|
||
self:RefreshData()
|
||
end
|
||
|
||
function GrowthGiftPage:RefreshData()
|
||
self:SetBtnInvestState()
|
||
self:RefreshGiftData()
|
||
end
|
||
|
||
function GrowthGiftPage:RefreshGiftData()
|
||
|
||
local list = {}
|
||
--判断是否已经有了List
|
||
if self.taskList then
|
||
table.walk(self.taskList,function(taskItem)
|
||
taskItem.cloneObj:SetActive(false)
|
||
end)
|
||
end
|
||
for _, configInfo in ConfigPairs(actRewardConfig) do
|
||
if configInfo.ActivityId == giftList[curGiftsId] then
|
||
table.insert(list, configInfo)
|
||
end
|
||
end
|
||
--按照领取状态排序
|
||
table.sort(list, function(a, b)
|
||
local state_a = ActivityGiftManager.GetActivityInfo(a.ActivityId, a.Id).state
|
||
local state_b = ActivityGiftManager.GetActivityInfo(b.ActivityId, b.Id).state
|
||
if state_a == 0 and state_b ~= 0 then
|
||
return true
|
||
end
|
||
if state_a ~= 0 and state_b == 0 then
|
||
return false
|
||
end
|
||
if state_a == state_b then
|
||
return a.Id < b.Id
|
||
end
|
||
return state_a < state_b
|
||
end)
|
||
|
||
local callBack = function(index, item)
|
||
self:RefreshShowData(item, list[index])
|
||
end
|
||
self.scrollView:SetData(list, callBack)
|
||
end
|
||
|
||
--刷新每一条item
|
||
function GrowthGiftPage:RefreshShowData(item, data)
|
||
|
||
local GrowthRewardId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.GrowthReward)--当前礼包奖励的活动类型(6\7\8\9\16)(成长礼包的不同档位奖励ActivityId不同,虽然同为成长基金)
|
||
local singleRewardData = ActivityGiftManager.GetActivityInfo(GrowthRewardId, data.Id)--获取活动数据 self.context.Id
|
||
local havaBought = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward, GlobalActivity[GrowthRewardId].CanBuyRechargeId)--当前礼包ID(101\102\103\104\105)
|
||
local openStatus = ActivityGiftManager.GetActivityOpenStatus(ActivityTypeDef.GrowthReward)
|
||
--item
|
||
local shadow = Util.GetGameObject(item, "shadow")
|
||
local grid = Util.GetGameObject(item, "scrollView/grid")
|
||
local name = Util.GetGameObject(item, "contents/name"):GetComponent("Text")
|
||
local condition = Util.GetGameObject(item, "contents/condition"):GetComponent("Text")
|
||
--按钮
|
||
local btnGet = Util.GetGameObject(item, "btnGet")
|
||
local btnGo = Util.GetGameObject(item, "btnGo")
|
||
local btnFinish = Util.GetGameObject(item, "btnFinish")
|
||
local redPoint=Util.GetGameObject(item,"btnGet/redPoint")
|
||
|
||
-- 物品Item
|
||
local shows = actRewardConfig[data.Id].Reward
|
||
name.text = rewardNameConfig[shows[1][1]].Name
|
||
condition.text = Language[11465]..actRewardConfig[data.Id].Values[1][2]..Language[11466]
|
||
--任务领取状态
|
||
local state = singleRewardData.state
|
||
local isCanGetReward = PlayerManager.level >= actRewardConfig[data.Id].Values[1][2]
|
||
|
||
--设置滚动条
|
||
if self.ItemList[item] then--如果已经存在在list中
|
||
self.ItemList[item]:OnOpen(false, {shows[1][1],shows[1][2]}, 0.9,false,false,false,self.mainPanel.sortingOrder)
|
||
self.ItemList[item].gameObject:SetActive(true)
|
||
else--如果List中不存在
|
||
self.ItemList[item]={}
|
||
self.ItemList[item] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform)
|
||
self.ItemList[item].gameObject:SetActive(false)
|
||
local obj= newObjToParent(shadow,self.ItemList[item].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)
|
||
|
||
self.ItemList[item]:OnOpen(false, {shows[1][1],shows[1][2]}, 0.9,false,false,false,self.mainPanel.sortingOrder)
|
||
self.ItemList[item].gameObject:SetActive(true)
|
||
end
|
||
|
||
local goods = OperatingManager.GetHadBuyGoodsTypeId(GoodsTypeDef.GrowthReward)--已购买礼包ID
|
||
|
||
--设置按钮状态
|
||
if isCanGetReward then
|
||
if state == 0 then
|
||
btnGet:SetActive(true)
|
||
btnFinish:SetActive(false)
|
||
redPoint:SetActive(goods == curGiftsId)
|
||
Util.SetGray(btnGet,false)
|
||
elseif state == 1 then
|
||
btnGet:SetActive(false)
|
||
btnFinish:SetActive(true)
|
||
redPoint:SetActive(goods == curGiftsId)
|
||
Util.SetGray(btnGet,false)
|
||
end
|
||
else
|
||
btnGet:SetActive(true)
|
||
btnFinish:SetActive(false)
|
||
redPoint:SetActive(false)
|
||
Util.SetGray(btnGet,true)
|
||
end
|
||
|
||
-- LogRed("GrowthRewardId:"..GrowthRewardId)--不同档位奖励对应的ActivityId
|
||
-- LogBlue("singleRewardData ID:"..singleRewardData.missionId)
|
||
-- LogGreen("havaBought iD"..havaBought.goodsId)--goodsId
|
||
|
||
Util.AddOnceClick(btnGet,function()
|
||
if not openStatus or (havaBought and havaBought.buyTimes < 1) then
|
||
PopupTipPanel.ShowTip(Language[11467])
|
||
return
|
||
end
|
||
|
||
if isCanGetReward then
|
||
NetManager.GetActivityRewardRequest(singleRewardData.missionId,GrowthRewardId, function(drop)
|
||
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1)
|
||
ActivityGiftManager.SetActivityInfo(actRewardConfig[data.Id].ActivityId, singleRewardData.missionId, 1)
|
||
btnGet:SetActive(false)
|
||
redPoint:SetActive(false)
|
||
btnFinish:SetActive(true)
|
||
state = 1
|
||
RedpotManager.CheckRedPointStatus(RedPointType.GrowthGift)
|
||
|
||
--检测奖励是否全部领完
|
||
local t = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig, "ActivityId", GrowthRewardId)
|
||
for i = 1, #t do
|
||
local info = ActivityGiftManager.GetActivityInfo(GrowthRewardId, t[i].Id)
|
||
if info.state ~= 1 then
|
||
-- Game.GlobalEvent:DispatchEvent(GameEvent.GrowGift.GetAllGift)
|
||
self:RefreshGiftData()
|
||
return
|
||
end
|
||
end
|
||
if(GrowthRewardId == 16)then--16是最后一个礼包的ActivityId
|
||
MsgPanel.ShowOne(Language[11468])
|
||
else
|
||
MsgPanel.ShowOne(Language[11469])
|
||
end
|
||
self:RefreshData()
|
||
end)
|
||
else
|
||
PopupTipPanel.ShowTip(Language[11470])
|
||
end
|
||
|
||
end)
|
||
|
||
end
|
||
|
||
function GrowthGiftPage:OnHide()
|
||
self.gameObject:SetActive(false)
|
||
end
|
||
|
||
function GrowthGiftPage:OnDestroy()
|
||
end
|
||
|
||
--更改特效层级
|
||
function GrowthGiftPage: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
|
||
end
|
||
|
||
--设置投资按钮初始状态
|
||
function GrowthGiftPage:SetBtnInvestState()
|
||
local packageInfo = OperatingManager.IsGrowthGiftGoodsAvailable(GoodsTypeDef.GrowthReward)--packageInfo:当前成长基金礼包ID(ID:101、102、103、104、105)
|
||
if packageInfo and packageInfo.buyTimes == 0 then
|
||
self.btnInvest:GetComponent("Button").enabled = true
|
||
local rechargeConfig = ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig, packageInfo.goodsId)
|
||
self.btnInvestText.text = string.format(MoneyUtil.GetMoneyUnitName(),MoneyUtil.GetMoney(rechargeConfig.Price))--"$98"
|
||
Util.SetGray(self.btnInvest, false)
|
||
curGiftsId = packageInfo.goodsId
|
||
else
|
||
self.btnInvest:GetComponent("Button").enabled = false
|
||
self.btnInvestText.text = Language[10526]
|
||
Util.SetGray(self.btnInvest, true)
|
||
curGiftsId = OperatingManager.GetHadBuyGoodsTypeId(GoodsTypeDef.GrowthReward)
|
||
end
|
||
end
|
||
--点击进行投资购买礼包
|
||
function GrowthGiftPage:OnBtnInvestClicked()
|
||
local status = OperatingManager.IsRechargeable(GoodsTypeDef.GrowthReward)
|
||
if not status then
|
||
self.btnInvest:GetComponent("Button").enabled = false
|
||
Util.SetGray(self.btnInvest, true)
|
||
return
|
||
end
|
||
self.btnInvest:GetComponent("Button").enabled = true
|
||
Util.SetGray(self.btnInvest, false)
|
||
self:RequestBuy()
|
||
end
|
||
function GrowthGiftPage:RequestBuy()
|
||
local giftGoodsInfo = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward, curGiftsId)
|
||
if AppConst.isSDKLogin then
|
||
PayManager.Pay({Id = giftGoodsInfo.goodsId})
|
||
else
|
||
NetManager.RequestBuyGiftGoods(giftGoodsInfo.goodsId,function(respond)
|
||
-- PopupTipPanel.ShowTip("奖励已发送到邮件,请前往领取")
|
||
-- FirstRechargeManager.RefreshAccumRechargeValue( giftGoodsInfo.goodsId)
|
||
lastGiftId = curGiftsId
|
||
self:RefreshStatus()
|
||
end)
|
||
end
|
||
end
|
||
|
||
function GrowthGiftPage:RefreshStatus()
|
||
local giftGoodsInfo = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward, curGiftsId)
|
||
-- 设置活动开启状态
|
||
ActivityGiftManager.SetActivityOpenStatus(ActivityTypeDef.GrowthReward)
|
||
-- 添加已经购买的物品
|
||
OperatingManager.SetHadBuyGoodsId({curGiftsId})
|
||
-- 增加充值金额
|
||
FirstRechargeManager.RefreshAccumRechargeValue(curGiftsId)
|
||
-- 检测红点状态
|
||
RedpotManager.CheckRedPointStatus(RedPointType.GrowthGift)
|
||
-- 从可购买物品列表中删除
|
||
OperatingManager.RemoveItemInfoByType(GoodsTypeDef.GrowthReward, curGiftsId)
|
||
-- 刷新当前界面显示
|
||
self:RefreshData()
|
||
end
|
||
|
||
return GrowthGiftPage |