miduo_client/Assets/ManagedResources/~Lua/Modules/UpGradePackage/UpGradePackagePanel.lua

296 lines
11 KiB
Lua
Raw Normal View History

2020-08-25 15:46:38 +08:00
require("Base/BasePanel")
2020-06-13 11:47:13 +08:00
local UpGradePackagePanel = Inherit(BasePanel)
local this = UpGradePackagePanel
local RechargeConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)--整表数据
2020-06-18 20:39:29 +08:00
local upgradeConfig = ConfigManager.GetAllConfigsDataByKey(ConfigName.RechargeCommodityConfig,"ShowType",21)--五档奖励数据
2020-10-13 17:21:27 +08:00
local fightLevelConfig = ConfigManager.GetConfig(ConfigName.MainLevelConfig)
2020-06-13 11:47:13 +08:00
local rechargeNum = 0
2020-06-18 20:39:29 +08:00
local cursortingOrder = 0
local curGiftList = {}
local curGiftId = nil
local curEndTime = 0
local curIndex
2020-08-19 22:03:47 +08:00
local curType
2020-06-18 20:39:29 +08:00
local fun--回调
2020-08-19 22:03:47 +08:00
local rechargeData
local activityType = {
2021-03-02 16:53:12 +08:00
[1] = {name = Language[11935],timePos = Vector3.New(0,-255.6,0),comp = "bg1",showType = 21},
[2] = {name = Language[11936],timePos = Vector3.New(0,-567,0),comp = "bg2",showType = 8},
[3] = {name = Language[11935],timePos = Vector3.New(0,-255.6,0),comp = "bg1",showType = 25},
[4] = {name = Language[11935],timePos = Vector3.New(0,-255.6,0),comp = "bg1",showType = 26},
2020-08-19 22:03:47 +08:00
}
2020-06-13 11:47:13 +08:00
--初始化组件(用于子类重写)
function this:InitComponent()
this.btnClose = Util.GetGameObject(self.gameObject,"show/btnBack")
this.btnBuy = Util.GetGameObject(self.gameObject,"show/Button")
this.grid = Util.GetGameObject(self.gameObject,"show/rewards/Grid")
this.endTime = Util.GetGameObject(self.gameObject,"show/endTime"):GetComponent("Text")
2020-08-19 22:11:48 +08:00
this.price = Util.GetGameObject(self.gameObject,"show/Button/Text"):GetComponent("Text")
this.oriPrice = Util.GetGameObject(self.gameObject,"show/price/Text1"):GetComponent("Text")
2020-06-28 17:52:29 +08:00
this.arrowsLeft = Util.GetGameObject(self.gameObject,"show/arrows/left")
this.arrowsRight = Util.GetGameObject(self.gameObject,"show/arrows/right")
2020-08-19 22:03:47 +08:00
this.UI_effect_DailyRechargePanel_particle = Util.GetGameObject(self.gameObject, "bg1/UI_effect_DailyRechargePanel_particle")
this.times = Util.GetGameObject(self.gameObject,"show/timesLeft"):GetComponent("Text")
this.tip = Util.GetGameObject(self.gameObject,"show/tip"):GetComponent("Text")
2020-06-13 11:47:13 +08:00
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.btnClose,function()
self:ClosePanel()
end)
Util.AddClick(this.btnBuy,function()
PayManager.Pay(curGiftId, function(id)
FirstRechargeManager.RefreshAccumRechargeValue(curGiftId)
CheckRedPointStatus(RedPointType.GrowthPackage)--成长礼包的红点检测
rechargeData.dynamicBuyTimes = rechargeData.dynamicBuyTimes - 1
--判断可购买次数是否为零,是剔除礼包信息
-- for i = 1, #curGiftList do
if rechargeData.dynamicBuyTimes < 1 then
OperatingManager.SetHadBuyGoodsId({curGiftId})
OperatingManager.RemoveItemInfoByType(GoodsTypeDef.DirectPurchaseGift, curGiftId)
2020-06-18 20:39:29 +08:00
end
-- end
this:Refresh()
end)
2020-06-18 20:39:29 +08:00
end)
Util.AddClick(this.arrowsLeft,function()
2020-08-19 22:03:47 +08:00
curIndex = curIndex - 1
if curGiftList[curType][curIndex] then
else
2020-10-13 17:21:27 +08:00
while(curType >= 0) do
2020-10-22 03:24:22 +08:00
if not activityType[curType] then
2020-10-22 02:57:40 +08:00
curType = LengthOfTable(activityType)
else
2020-10-22 03:24:22 +08:00
curType = curType - 1
2020-08-19 22:03:47 +08:00
end
2020-10-22 02:57:40 +08:00
if curGiftList[curType] and #curGiftList[curType] > 0 then
curIndex = #curGiftList[curType]
break
end
end
2020-08-19 22:03:47 +08:00
end
OperatingManager.upGradePackagePanelType = curType
OperatingManager.upGradePackagePanelIndex = curIndex
this:Refresh()
2020-06-18 20:39:29 +08:00
end)
Util.AddClick(this.arrowsRight,function()
2020-08-19 22:03:47 +08:00
curIndex = curIndex + 1
if curGiftList[curType][curIndex] then
else
2020-10-22 03:24:22 +08:00
while(curType <= LengthOfTable(activityType) + 1) do
if not activityType[curType] then
2020-10-22 02:57:40 +08:00
curType = 1
else
2020-10-22 03:24:22 +08:00
curType = curType + 1
2020-10-22 02:57:40 +08:00
end
if curGiftList[curType] and #curGiftList[curType] > 0 then
2020-08-19 22:03:47 +08:00
curIndex = 1
2020-10-22 02:57:40 +08:00
break
2020-08-19 22:03:47 +08:00
end
end
end
OperatingManager.upGradePackagePanelType = curType
OperatingManager.upGradePackagePanelIndex = curIndex
this:Refresh()
2020-06-13 11:47:13 +08:00
end)
end
--添加事件监听(用于子类重写)
function this:AddListener()
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
end
2020-06-18 20:39:29 +08:00
function this:OnSortingOrderChange()
Util.AddParticleSortLayer( self.UI_effect_DailyRechargePanel_particle, self.sortingOrder - cursortingOrder)
cursortingOrder = self.sortingOrder
end
2020-06-13 11:47:13 +08:00
--界面打开时调用(用于子类重写)
2020-06-18 20:39:29 +08:00
function this:OnOpen(_fun)
fun = _fun
2020-10-19 18:54:50 +08:00
-- 音效
SoundManager.PlaySound(SoundConfig.Sound_mrhl)
2020-06-18 20:39:29 +08:00
end
2020-06-13 11:47:13 +08:00
2020-06-18 20:39:29 +08:00
--获取(自己拼凑)礼包数据
function this:GetInfoList()
local infoList = OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift)--拿取所有类型5礼包信息(包含需要的礼包)
2020-08-19 22:03:47 +08:00
local num = 0
for k,v in pairs(activityType) do
curGiftList[k] = {}
local infoList2 = ConfigManager.GetAllConfigsDataByKey(ConfigName.RechargeCommodityConfig,"ShowType",v.showType)
for index, value in pairs(infoList) do
for i = 1, #infoList2 do
if infoList2[i].Id == value.goodsId and value.dynamicBuyTimes > 0 then
table.insert(curGiftList[k],value)
num = num + 1
end
2020-06-18 20:39:29 +08:00
end
end
end
2020-08-19 22:03:47 +08:00
return num
2020-06-13 11:47:13 +08:00
end
2020-08-19 22:03:47 +08:00
function this:OnShow()
this:Refresh()
2020-06-13 11:47:13 +08:00
end
2020-08-19 22:03:47 +08:00
function this:SetCurTypeAndIndex()
curType = OperatingManager.upGradePackagePanelType and OperatingManager.upGradePackagePanelType or 1
curIndex = OperatingManager.upGradePackagePanelIndex and OperatingManager.upGradePackagePanelIndex or 0
if curGiftList[curType] and #curGiftList[curType] > 0 and curGiftList[curType][curIndex] then
2020-08-19 22:03:47 +08:00
elseif curGiftList[curType] and #curGiftList[curType] > 0 and (not curGiftList[curType][curIndex]) then
2020-09-27 18:27:20 +08:00
curIndex = #curGiftList[curType]
2020-08-19 22:03:47 +08:00
return curGiftList[curType][curIndex]
else
for k,v in pairs(curGiftList) do
2020-10-13 17:21:27 +08:00
if v and #v > 0 then
2020-08-19 22:03:47 +08:00
curType = k
curIndex = #curGiftList[curType]
2020-08-19 22:03:47 +08:00
return curGiftList[curType][curIndex]
end
end
end
return curGiftList[curType][curIndex]
end
function this:Refresh()
2020-10-13 17:21:27 +08:00
2020-08-19 22:03:47 +08:00
local num = self:GetInfoList()
if num < 1 then
2020-08-24 10:22:27 +08:00
this:ClosePanel()
2020-08-19 22:03:47 +08:00
return
end
rechargeData = this:SetCurTypeAndIndex()
for k,v in pairs(activityType) do
Util.GetGameObject(self.gameObject,v.comp):SetActive(false)
end
Util.GetGameObject(self.gameObject,activityType[curType].comp):SetActive(true)
2020-06-18 20:39:29 +08:00
local level = 0
if (PlayerManager.level)%10 == 8 then
level = PlayerManager.level
else
level = (math.floor(PlayerManager.level/10)-1)*10+8
end
2020-08-19 22:03:47 +08:00
rechargeNum= VipManager.GetChargedNum()
2020-10-13 17:21:27 +08:00
if curType == 1 then
2021-03-02 16:53:12 +08:00
this.tip.text = Language[11937]..level..Language[12174] or ""
2020-10-13 17:21:27 +08:00
elseif curType == 3 then
2020-10-13 18:39:55 +08:00
local specialConfig = ConfigManager.GetConfigData(ConfigName.SpecialConfig,93).Value
2020-10-13 17:21:27 +08:00
local num = tonumber(specialConfig)
2020-10-19 21:54:01 +08:00
local value = fightLevelConfig[FightPointPassManager.lastPassFightId].SortId
2021-01-26 17:08:39 +08:00
local value2 = GetLanguageStrById(ConfigManager.GetConfigDataByKey(ConfigName.MainLevelConfig,"SortId",math.floor(value/num)*num).Name)
2021-03-02 16:53:12 +08:00
this.tip.text =Language[11939]..value2..Language[11940]
2020-10-13 17:21:27 +08:00
elseif curType == 4 then
2020-10-13 18:39:55 +08:00
local specialConfig = ConfigManager.GetConfigData(ConfigName.SpecialConfig,92).Value
2020-10-13 17:21:27 +08:00
local str = string.split(specialConfig,"|")
local nums = string.split(str[1],"#")
local canGet = false
local value = MonsterCampManager.monsterWave
2020-10-19 18:54:50 +08:00
local value2 = 0
if value <= tonumber(nums[#nums]) then
local temp = tonumber(nums[#nums]) - tonumber(nums[#nums-1])
2020-10-13 17:21:27 +08:00
value2 = math.floor(value/temp) * temp
else
2020-10-19 18:54:50 +08:00
value2 = math.floor((value - tonumber(nums[#nums]))/tonumber(str[2]))* tonumber(str[2]) + tonumber(nums[#nums])
2020-10-13 17:21:27 +08:00
end
2021-03-02 16:53:12 +08:00
this.tip.text =Language[11941]..value2..Language[11942]
2020-10-13 17:21:27 +08:00
else
this.tip.text = ""
end
-- this.tip.text = curType == 1 and "恭喜您等级提升至"..level.."级,我们为您准备了超值礼包,助您提升战力!!!" or ""
2020-10-13 17:21:27 +08:00
2020-08-19 22:03:47 +08:00
this.arrowsLeft:SetActive(num > 1)
this.arrowsRight:SetActive(num > 1)
curGiftId = rechargeData.goodsId
curEndTime = rechargeData.endTime
2021-03-02 16:53:12 +08:00
this.endTime.text = Language[10573]..TimeToHMS(curEndTime-GetTimeStamp())
2020-08-19 22:03:47 +08:00
this.endTime.gameObject:GetComponent("RectTransform").localPosition = activityType[curType].timePos
this:SetGfitShow(rechargeData)
this:SetTime(rechargeData)
2020-06-13 11:47:13 +08:00
end
--设置奖励
local _ItemViewList = {}
2020-08-19 22:03:47 +08:00
function this:SetGfitShow(rechargeData)
2020-08-22 19:40:14 +08:00
for k,v in pairs(_ItemViewList) do
v.gameObject:SetActive(false)
end
2020-06-18 20:39:29 +08:00
for i=1, #RechargeConfig[curGiftId].RewardShow do
2020-06-13 11:47:13 +08:00
if not _ItemViewList[i] then
local view = SubUIManager.Open(SubUIConfig.ItemView,this.grid.transform)
_ItemViewList[i] = view
end
2020-08-19 22:03:47 +08:00
_ItemViewList[i]:OnOpen(false,RechargeConfig[curGiftId].RewardShow[i],0.95,false)
2020-06-13 11:47:13 +08:00
_ItemViewList[i].gameObject:SetActive(true)
end
2021-03-02 16:53:12 +08:00
this.times.text = Language[10580]..rechargeData.dynamicBuyTimes..Language[10048]
this.price.text = string.format(MoneyUtil.GetMoneyUnitName(), MoneyUtil.GetMoney(RechargeConfig[curGiftId].Price))--..MoneyUtil.GetMoneyUnitName()
if activityType[curType].Rebate and activityType[curType].Rebate ~= 0 then
this.oriPrice.transform.parent.gameObject:SetActive(true)
this.oriPrice = string.format(MoneyUtil.GetMoneyUnitName(), activityType[curType].Rebate)
else
this.oriPrice.transform.parent.gameObject:SetActive(false)
end
2020-06-13 11:47:13 +08:00
end
2020-08-19 22:03:47 +08:00
--设置剩余时间,取剩余时间最短的礼包
2020-06-13 11:47:13 +08:00
function this:SetTime()
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
self.localTimer = Timer.New(function()
2020-06-18 20:39:29 +08:00
-- curEndTime= curEndTime-1
--时间到了之后
if curEndTime-GetTimeStamp() < 0 then
OperatingManager.RemoveItemInfoByType(GoodsTypeDef.DirectPurchaseGift, curGiftId)
2020-08-19 22:03:47 +08:00
this:Refresh()
2020-06-13 11:47:13 +08:00
end
2021-03-02 16:53:12 +08:00
this.endTime.text = Language[10573]..TimeToHMS(curEndTime-GetTimeStamp())
2020-06-13 11:47:13 +08:00
end,1,-1,true)
self.localTimer:Start()
end
function this:Hide()
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
2020-06-18 20:39:29 +08:00
if fun then
fun()
fun = nil
end
2020-06-13 11:47:13 +08:00
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
2020-06-18 20:39:29 +08:00
cursortingOrder = 0
_ItemViewList = {}
if self.localTimer then
self.localTimer:Stop()
self.localTimer = nil
end
2020-06-13 11:47:13 +08:00
end
2020-06-23 18:36:24 +08:00
return UpGradePackagePanel