miduo_client/Assets/ManagedResources/~Lua/Modules/Operating/GrowthGiftPage.lua

281 lines
11 KiB
Lua
Raw Normal View History

2020-06-23 18:36:24 +08:00
local GrowthGiftPage = quick_class("GrowthGiftPage")
2020-06-08 13:57:30 +08:00
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,--表内没有礼包id101、102、103、104、105和ActivityId的对应关系
[102] = 7,
[103] = 8,--自定义本表建立对应关系
[104] = 9,
[105] = 16,
}
2020-05-09 13:31:21 +08:00
function GrowthGiftPage:ctor(mainPanel, gameObject)
self.mainPanel = mainPanel
self.gameObject = gameObject
2020-06-08 13:57:30 +08:00
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")
2020-06-23 18:36:24 +08:00
self.tip.text = Language[11464]
2020-06-08 13:57:30 +08:00
self.btnInvest = Util.GetGameObject(gameObject, "rzyBg/bg/btnInvest")
2020-05-25 19:16:23 +08:00
self.btnInvest:GetComponent("Button").onClick:AddListener(
function()
self:OnBtnInvestClicked()
end
)
2020-06-08 13:57:30 +08:00
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
2020-05-25 19:16:23 +08:00
2020-05-09 13:31:21 +08:00
end
2020-06-08 13:57:30 +08:00
function GrowthGiftPage:BindEvent()
end
2020-05-25 19:16:23 +08:00
2020-06-08 13:57:30 +08:00
function GrowthGiftPage:OnShow()
self.gameObject:SetActive(true)
self:RefreshData()
2020-05-09 13:31:21 +08:00
end
2020-06-08 13:57:30 +08:00
function GrowthGiftPage:RefreshData()
self:SetBtnInvestState()
self:RefreshGiftData()
2020-05-09 13:31:21 +08:00
end
2020-06-08 13:57:30 +08:00
function GrowthGiftPage:RefreshGiftData()
local list = {}
--判断是否已经有了List
2020-05-25 19:16:23 +08:00
if self.taskList then
table.walk(self.taskList,function(taskItem)
taskItem.cloneObj:SetActive(false)
end)
2020-05-09 13:31:21 +08:00
end
for _, configInfo in ConfigPairs(actRewardConfig) do
2020-06-08 13:57:30 +08:00
if configInfo.ActivityId == giftList[curGiftsId] then
2020-05-25 19:16:23 +08:00
table.insert(list, configInfo)
2020-05-09 13:31:21 +08:00
end
end
2020-06-08 13:57:30 +08:00
--按照领取状态排序
2020-05-25 19:16:23 +08:00
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
2020-05-09 13:31:21 +08:00
end
2020-05-25 19:16:23 +08:00
if state_a == state_b then
return a.Id < b.Id
end
return state_a < state_b
2020-05-09 13:31:21 +08:00
end)
2020-06-08 13:57:30 +08:00
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(GrowthRewardId)
--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
2020-06-23 18:36:24 +08:00
condition.text = Language[11465]..actRewardConfig[data.Id].Values[1][2]..Language[11466]
2020-06-08 13:57:30 +08:00
--任务领取状态
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)
2020-05-25 19:16:23 +08:00
end
2020-06-08 13:57:30 +08:00
else
btnGet:SetActive(true)
btnFinish:SetActive(false)
redPoint:SetActive(false)
Util.SetGray(btnGet,true)
2020-05-25 19:16:23 +08:00
end
2020-06-08 13:57:30 +08:00
-- 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
2020-06-23 18:36:24 +08:00
PopupTipPanel.ShowTip(Language[11467])
2020-06-08 13:57:30 +08:00
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
2020-06-23 18:36:24 +08:00
MsgPanel.ShowOne(Language[11468])
2020-06-08 13:57:30 +08:00
else
2020-06-23 18:36:24 +08:00
MsgPanel.ShowOne(Language[11469])
2020-06-08 13:57:30 +08:00
end
self:RefreshData()
end)
else
2020-06-23 18:36:24 +08:00
PopupTipPanel.ShowTip(Language[11470])
2020-06-08 13:57:30 +08:00
end
end)
2020-05-09 13:31:21 +08:00
end
2020-06-08 13:57:30 +08:00
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
2020-05-25 19:16:23 +08:00
2020-06-08 13:57:30 +08:00
--设置投资按钮初始状态
function GrowthGiftPage:SetBtnInvestState()
local packageInfo = OperatingManager.IsGrowthGiftGoodsAvailable(GoodsTypeDef.GrowthReward)--packageInfo:当前成长基金礼包IDID101、102、103、104、105
if packageInfo and packageInfo.buyTimes == 0 then
self.btnInvest:GetComponent("Button").enabled = true
2020-06-23 18:36:24 +08:00
self.btnInvestText.text = Language[11471]
2020-06-08 13:57:30 +08:00
Util.SetGray(self.btnInvest, false)
curGiftsId = packageInfo.goodsId
else
self.btnInvest:GetComponent("Button").enabled = false
2020-06-23 18:36:24 +08:00
self.btnInvestText.text = Language[10526]
2020-06-08 13:57:30 +08:00
Util.SetGray(self.btnInvest, true)
curGiftsId = OperatingManager.GetHadBuyGoodsTypeId(GoodsTypeDef.GrowthReward)
end
end
--点击进行投资购买礼包
2020-05-09 13:31:21 +08:00
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()
2020-05-25 19:16:23 +08:00
local giftGoodsInfo = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward, curGiftsId)
2020-05-09 13:31:21 +08:00
if AppConst.isSDK then
2020-05-25 19:16:23 +08:00
PayManager.Pay({Id = giftGoodsInfo.goodsId})
2020-05-09 13:31:21 +08:00
else
2020-06-08 13:57:30 +08:00
NetManager.RequestBuyGiftGoods(giftGoodsInfo.goodsId,function(respond)
-- PopupTipPanel.ShowTip("奖励已发送到邮件,请前往领取")
-- FirstRechargeManager.RefreshAccumRechargeValue( giftGoodsInfo.goodsId)
lastGiftId = curGiftsId
self:RefreshStatus()
end)
2020-05-09 13:31:21 +08:00
end
end
function GrowthGiftPage:RefreshStatus()
2020-05-25 19:16:23 +08:00
local giftGoodsInfo = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward, curGiftsId)
-- 设置活动开启状态
2020-05-09 13:31:21 +08:00
ActivityGiftManager.SetActivityOpenStatus(ActivityTypeDef.GrowthReward)
2020-05-25 19:16:23 +08:00
-- 添加已经购买的物品
OperatingManager.SetHadBuyGoodsId({curGiftsId})
-- 增加充值金额
FirstRechargeManager.RefreshAccumRechargeValue(curGiftsId)
-- 检测红点状态
2020-05-09 13:31:21 +08:00
RedpotManager.CheckRedPointStatus(RedPointType.GrowthGift)
2020-05-25 19:16:23 +08:00
-- 从可购买物品列表中删除
OperatingManager.RemoveItemInfoByType(GoodsTypeDef.GrowthReward, curGiftsId)
-- 刷新当前界面显示
2020-06-08 13:57:30 +08:00
self:RefreshData()
2020-05-09 13:31:21 +08:00
end
2020-06-08 13:57:30 +08:00
return GrowthGiftPage