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

233 lines
8.6 KiB
Lua
Raw Normal View History

2021-03-30 10:48:34 +08:00

local GrowthGiftPage = {}
local sortingOrder = 0
2020-06-08 13:57:30 +08:00
local rewardNameConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)--读取奖励名称信息
local GlobalActivity = ConfigManager.GetConfig(ConfigName.GlobalActivity)
2021-03-30 10:48:34 +08:00
local actRewardConfig = ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)
local rechargeConfigs = ConfigManager.GetAllConfigsDataByKey(ConfigName.RechargeCommodityConfig,"Type",GoodsTypeDef.GrowthReward)
2020-06-08 13:57:30 +08:00
local giftList = {
[101] = 6,--表内没有礼包id101、102、103、104、105和ActivityId的对应关系
[102] = 7,
[103] = 8,--自定义本表建立对应关系
[104] = 9,
[105] = 16,
}
2021-03-30 10:48:34 +08:00
function GrowthGiftPage:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = GrowthGiftPage })
return b
2020-06-08 13:57:30 +08:00
end
2021-03-30 10:48:34 +08:00
--初始化组件(用于子类重写)
function GrowthGiftPage:InitComponent()
2020-06-08 13:57:30 +08:00
--定义头部文字和按钮
2021-03-30 10:48:34 +08:00
self.bg = Util.GetGameObject(self.gameObject, "rzyBg")
self.tip = Util.GetGameObject(self.gameObject, "rzyBg/bg/tip"):GetComponent("Text")
self.tip.text = "超值返利,累计可获<color=#FF6500>10000</color>妖晶"
self.btnInvest = Util.GetGameObject(self.gameObject, "rzyBg/bg/btnInvest")
self.btnInvestText = Util.GetGameObject(self.gameObject, "rzyBg/bg/btnInvest/Text"):GetComponent("Text")
2020-06-08 13:57:30 +08:00
--滚动条和预设
2021-03-30 10:48:34 +08:00
self.scrollItem = Util.GetGameObject(self.gameObject, "rzyBg/scrollItem")
self.itemPre = Util.GetGameObject(self.gameObject, "rzyBg/ItemPre")
2020-06-08 13:57:30 +08:00
--设置滚动条
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-09 13:31:21 +08:00
end
2021-03-30 10:48:34 +08:00
--绑定事件(用于子类重写)
2020-06-08 13:57:30 +08:00
function GrowthGiftPage:BindEvent()
2021-03-30 10:48:34 +08:00
Util.AddOnceClick(self.btnInvest,function()
self:OnBtnInvestClicked()
end)
2020-06-08 13:57:30 +08:00
end
2020-05-25 19:16:23 +08:00
2021-03-30 10:48:34 +08:00
--添加事件监听(用于子类重写)
function GrowthGiftPage:AddListener()
2020-05-09 13:31:21 +08:00
end
2021-03-30 10:48:34 +08:00
--移除事件监听(用于子类重写)
function GrowthGiftPage:RemoveListener()
2020-05-09 13:31:21 +08:00
end
2021-03-30 10:48:34 +08:00
--界面打开时调用(用于子类重写)
function GrowthGiftPage:OnOpen(_activityConfig,_index,parent)
self.actConfig = _activityConfig
self.pageIndex = _index
self.parent = parent
end
2020-06-08 13:57:30 +08:00
2021-03-30 10:48:34 +08:00
-- 打开,重新打开时回调
function GrowthGiftPage:OnShow(_sortingOrder)
self.gameObject:SetActive(true)
sortingOrder = _sortingOrder
self.curActiId = 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.curActiId = 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
2020-05-09 13:31:21 +08:00
end
2021-03-30 10:48:34 +08:00
end
self.curGiftsId = GlobalActivity[self.curActiId].CanBuyRechargeId[1]
self:RefreshData()
end
function GrowthGiftPage:RefreshData()
self:SetBtnInvestState()
self:RefreshGiftData(true)
end
--设置投资按钮初始状态
function GrowthGiftPage:SetBtnInvestState()
self.gift = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward, self.curGiftsId)
if self.gift and self.gift.buyTimes == 0 then
self.btnInvest:GetComponent("Button").enabled = true
local rechargeConfig = ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig, self.curGiftsId)
self.btnInvestText.text = string.format(MoneyUtil.GetMoneyUnitName(),MoneyUtil.GetMoney(rechargeConfig.Price))--"$98"
Util.SetGray(self.btnInvest, false)
else
self.btnInvest:GetComponent("Button").enabled = false
self.btnInvestText.text = "已购买"
Util.SetGray(self.btnInvest, true)
2020-05-09 13:31:21 +08:00
end
2021-03-30 10:48:34 +08:00
end
function GrowthGiftPage:RefreshGiftData(anim)
self.actiInfo = ActivityGiftManager.GetActivityInfoByType(self.curActiId)
table.sort(self.actiInfo.mission, function(a, b)
if a.state == 0 and b.state ~= 0 then
2020-05-25 19:16:23 +08:00
return true
end
2021-03-30 10:48:34 +08:00
if a.state ~= 0 and b.state == 0 then
2020-05-25 19:16:23 +08:00
return false
2020-05-09 13:31:21 +08:00
end
2021-03-30 10:48:34 +08:00
if a.state == b.state then
return a.missionId < b.missionId
2020-05-25 19:16:23 +08:00
end
2021-03-30 10:48:34 +08:00
return a.state < b.state
2020-05-09 13:31:21 +08:00
end)
2021-03-30 10:48:34 +08:00
if not self.missionPre then
self.missionPre = {}
2020-06-08 13:57:30 +08:00
end
2021-03-30 10:48:34 +08:00
for k,v in pairs(self.missionPre) do
v.gameObject:SetActive(false)
end
2021-03-30 10:48:34 +08:00
self.scrollView:SetData(self.actiInfo.mission, function(index, item)
self:RefreshShowData(item, self.actiInfo.mission[index])
end,not anim)
2020-06-08 13:57:30 +08:00
end
--刷新每一条item
function GrowthGiftPage:RefreshShowData(item, data)
2021-03-30 10:48:34 +08:00
if not self.missionPre[item] then
self.missionPre[item] = SubUIManager.Open(SubUIConfig[360],item.transform)
2020-06-08 13:57:30 +08:00
end
2021-03-30 10:48:34 +08:00
self.missionPre[item].gameObject:SetActive(true)
local shows = actRewardConfig[data.missionId].Reward
local title = rewardNameConfig[shows[1][1]].Name
local content = "达到"..actRewardConfig[data.missionId].Values[1][2].."级可领取"
local isCanGetReward = PlayerManager.level >= actRewardConfig[data.missionId].Values[1][2]
2020-06-08 13:57:30 +08:00
local goods = OperatingManager.GetHadBuyGoodsTypeId(GoodsTypeDef.GrowthReward)--已购买礼包ID
2021-03-30 10:48:34 +08:00
local state = data.state
--0 未领取(已达到条件) 1 已领取 -1 未达到等级 2可领取
if data.state == 0 then
if PlayerManager.level < actRewardConfig[data.missionId].Values[1][2] then
state = -1
elseif self.gift.buyTimes > 0 then
state = 2
2020-05-25 19:16:23 +08:00
end
2020-06-08 13:57:30 +08:00
else
2021-03-30 10:48:34 +08:00
state = data.state
2020-05-25 19:16:23 +08:00
end
2021-03-30 10:48:34 +08:00
self.missionPre[item]:OnShow(shows,title,content,state,function()
end,function()
if state == -1 then
PopupTipPanel.ShowTip("未达到等级要求~~~")
elseif state == 2 then
NetManager.GetActivityRewardRequest(data.missionId,self.curActiId, function(drop)
2020-06-08 13:57:30 +08:00
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1)
2021-03-30 10:48:34 +08:00
ActivityGiftManager.SetActivityInfo(self.curActiId, data.missionId, 1)
2020-06-08 13:57:30 +08:00
RedpotManager.CheckRedPointStatus(RedPointType.GrowthGift)
2021-03-30 10:48:34 +08:00
if self:CheckAllGet(self.curActiId,data.missionId) == 0 then
self:RefreshGiftData(false)
return
2020-06-08 13:57:30 +08:00
end
2021-03-30 10:48:34 +08:00
if(self.curActiId == 16)then--16是最后一个礼包的ActivityId
MsgPanel.ShowOne("恭喜!您已领取全部成长基金!")
2020-06-08 13:57:30 +08:00
else
2021-03-30 10:48:34 +08:00
MsgPanel.ShowOne("恭喜!您已激活更高等级成长基金,大量妖晶福利等您领取,快来激活吧!")
self:OnShow(sortingOrder)
2020-06-08 13:57:30 +08:00
end
end)
else
2021-03-30 10:48:34 +08:00
PopupTipPanel.ShowTip("请购买基金后领取")
2020-06-08 13:57:30 +08:00
end
2021-03-30 10:48:34 +08:00
end,function()
end,sortingOrder)
2020-05-09 13:31:21 +08:00
end
2021-03-30 10:48:34 +08:00
--检测是否全部已领取
function GrowthGiftPage:CheckAllGet(curActiId,missionId)
local aciInfo = ActivityGiftManager.GetActivityInfoByType(curActiId)
for i = 1, #aciInfo.mission do
if aciInfo.mission[i].state ~= 1 and aciInfo.mission[i].missionId ~= missionId then
return 0
2020-06-08 13:57:30 +08:00
end
end
2021-03-30 10:48:34 +08:00
return 1
2020-06-08 13:57:30 +08:00
end
2020-05-25 19:16:23 +08:00
2020-06-08 13:57:30 +08:00
--点击进行投资购买礼包
2020-05-09 13:31:21 +08:00
function GrowthGiftPage:OnBtnInvestClicked()
2021-03-30 10:48:34 +08:00
self.btnInvest:GetComponent("Button").enabled = false
2020-05-09 13:31:21 +08:00
self:RequestBuy()
end
function GrowthGiftPage:RequestBuy()
2021-03-30 10:48:34 +08:00
local giftGoodsInfo = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward, self.curGiftsId)
PayManager.Pay(giftGoodsInfo.goodsId, function(id)
self:RefreshStatus()
end)
2020-05-09 13:31:21 +08:00
end
function GrowthGiftPage:RefreshStatus()
2020-05-25 19:16:23 +08:00
-- 添加已经购买的物品
2021-03-30 10:48:34 +08:00
OperatingManager.SetHadBuyGoodsId({self.curGiftsId})
2020-05-25 19:16:23 +08:00
-- 增加充值金额
2021-03-30 10:48:34 +08:00
FirstRechargeManager.RefreshAccumRechargeValue(self.curGiftsId)
2020-05-25 19:16:23 +08:00
-- 检测红点状态
2020-05-09 13:31:21 +08:00
RedpotManager.CheckRedPointStatus(RedPointType.GrowthGift)
2020-05-25 19:16:23 +08:00
-- 刷新当前界面显示
2021-03-30 10:48:34 +08:00
self:RefreshData()
2020-05-09 13:31:21 +08:00
end
2021-03-30 10:48:34 +08:00
--界面关闭时调用(用于子类重写)
function GrowthGiftPage:OnClose()
self.gameObject:SetActive(false)
end
--界面销毁时调用(用于子类重写)
function GrowthGiftPage:OnDestroy()
for k,v in pairs(self.missionPre) do
SubUIManager.Close(v)
end
self.missionPre = {}
end
2020-06-08 13:57:30 +08:00
return GrowthGiftPage