miduo_client/Assets/ManagedResources/~Lua/Modules/Vip/VipPanel.lua

562 lines
20 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.

--[[
* @ClassName OperatingPanel
* @Description 等级特权面板
* @Date 2019/5/27 11:14
* @Author MagicianJoker, fengliudianshao@outlook.com
* @Copyright Copyright (c) 2019, MagicianJoker
--]]
---@class VipPanel
local VipPanel = quick_class("VipPanel", BasePanel)
local this = VipPanel
local orginLayer
local maxVipLevel = 15
local curChooseLevel = 0
-- 当前选中的礼包内容
local giftData = {}
-- 避免多次点击按钮
local btnBg = {
[1] = "r_hero_button_001", -- 未激活, 已领取
[2] = "t_tequan_lingqu", -- 领取
}
-- 按钮选中的颜色
local btnColor = {
[1] = {nameColor = "#dca074FF", descColor = "#b6815bFF", img = "r_tequan_te_anniu01"}, -- 未选中
[2] = {nameColor = "#930f0fFF", descColor = "#60271bFF", img = "r_tequan_te_anniu02"}, -- 选中
}
-- 上一个选择的按钮
local lastChoose = 0
local vipLevelConfig = ConfigManager.GetConfig(ConfigName.VipLevelConfig)
function VipPanel:InitComponent()
this.spLoader = SpriteLoader.New()
orginLayer = 0
maxVipLevel = VipManager.GetMaxVipLevel()
--self.bg = Util.GetGameObject(self.transform, "bg")
--if Screen.width / Screen.height < 1080 / 1920 then
-- screenAdapte(self.bg)
--end
self.BtnBack = Util.GetGameObject(self.transform, "btnBack")
this.helpBtn = Util.GetGameObject(self.gameObject, "frame/helpBtn")
this.helpPosition=this.helpBtn:GetComponent("RectTransform").localPosition
--topPart
self.topPart = Util.GetGameObject(self.transform, "frame/topPart")
self.effect = Util.GetGameObject(self.topPart, "UI_Effect_VipPanel")
effectAdapte(self.effect)
-- 充值信息
self.chargeTip = Util.GetGameObject(self.topPart, "VipInfoPart/textGrid")
self.moneyNeed = Util.GetGameObject(self.topPart, "VipInfoPart/textGrid/num"):GetComponent("Text")
self.vipNextLevel = Util.GetGameObject(self.topPart, "VipInfoPart/textGrid/end"):GetComponent("Text")
self.moneyIcon = Util.GetGameObject(self.topPart, "VipInfoPart/textGrid/icon/Image"):GetComponent("Image")
self.rewardInfo = Util.GetGameObject(self.topPart, "VipInfoPart/reward/Text"):GetComponent("Image")
self.vipCurLevel = Util.GetGameObject(self.topPart, "VipInfoPart/vipIcon/num"):GetComponent("Text")
-- 充值进度信息
self.progressValue = Util.GetGameObject(self.topPart, "VipInfoPart/Slider/fill"):GetComponent("Image")
self.progressText = Util.GetGameObject(self.topPart, "VipInfoPart/Slider/value"):GetComponent("Text")
-- 购买月卡
self.monthRewardList = {}
self.monthRewardGrid = Util.GetGameObject(self.topPart, "dailyGift/grid")
self.dailyReward = {}
for i = 1, 2 do
self.dailyReward[i] = SubUIManager.Open(SubUIConfig.ItemView, self.monthRewardGrid.transform)
self.dailyReward[i].gameObject:SetActive(false)
end
self.btnGetReward = Util.GetGameObject(self.topPart, "dailyGift/btnGet")
self.btnText = Util.GetGameObject(self.btnGetReward, "Text"):GetComponent("Text")
-- 领取按钮红点
self.redReward = Util.GetGameObject(self.btnGetReward, "redPoint")
--midPart
self.midPart = Util.GetGameObject(self.gameObject, "frame/midPart/privilegeRoot")
self.moneyNeedTotal = Util.GetGameObject(self.midPart, "chargeTip/num"):GetComponent("Text")
self.moneyIconTotal = Util.GetGameObject(self.midPart, "chargeTip/icon/Image"):GetComponent("Image")
self.btnMidPart = Util.GetGameObject(self.gameObject, "frame/midPart")
-- 增益描述
self.privilegeTitle = Util.GetGameObject(self.midPart, "imgTitle/title"):GetComponent("Text")
self.privilegeContent = Util.GetGameObject(self.midPart, "privilegeList/viewPort/content")
self.privilegeItem = Util.GetGameObject(self.privilegeContent, "itemPro")
self.privilegeItem.gameObject:SetActive(false)
self.privilegeList = {}
-- 当前等级的特权礼包
self.giftGrid = Util.GetGameObject(self.midPart, "gfitContent/Scroll/grid")
self.vipGfitList = {}
-- 缓存6项
for i = 1, 6 do
self.vipGfitList[i] = SubUIManager.Open(SubUIConfig.ItemView, self.giftGrid.transform)
self.vipGfitList[i].gameObject:SetActive(false)
end
self.giftText = Util.GetGameObject(self.midPart, "gfitContent/orginPrice/price"):GetComponent("Text")
self.giftIcon = Util.GetGameObject(self.midPart, "gfitContent/orginPrice/icon"):GetComponent("Image")
self.discountLine = Util.GetGameObject(self.midPart, "gfitContent/orginPrice/line")
self.btnGiftBuy = Util.GetGameObject(self.midPart, "gfitContent/btnBuy")
self.buyIcon = Util.GetGameObject(self.midPart, "gfitContent/icon"):GetComponent("Image")
self.buyText = Util.GetGameObject(self.midPart, "gfitContent/Text"):GetComponent("Text")
-- 那一排的滑动按钮
self.levelBtnList = {}
self.btnRedPointList = {}
self.btnGrid = Util.GetGameObject(self.midPart, "btnScroll/grid")
self.btnPre = Util.GetGameObject(self.midPart, "btnScroll/btnVipInfo")
for i = 1, maxVipLevel + 1 do
self.levelBtnList[i] = newObjToParent(self.btnPre, self.btnGrid)
self.btnRedPointList[i] = Util.GetGameObject(self.levelBtnList[i], "redPoint")
end
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.transform)
end
function VipPanel:BindEvent()
----帮助按钮
Util.AddClick(this.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.VIP, this.helpPosition.x,this.helpPosition.y)
end)
Util.AddClick(self.BtnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
for i = 1, maxVipLevel + 1 do
Util.AddClick(self.levelBtnList[i], function ()
self:RefreshPanelStatus(i - 1)
-- 刷新按钮红点状态
if VipManager.GetBuyBtnRedState(i - 1) == 0 and self.vipLevel >= i - 1 then
VipManager.SetBuyBtnRed(i - 1, 1)
CheckRedPointStatus(RedPointType.VIP_SHOP_DETAIL)
CheckRedPointStatus(RedPointType.VipPrivilege)
end
self:SetBtnRedState(i-1)
end)
end
--点击中间部分设置为目前VIP等级的增益描述
-- Util.AddClick(self.btnMidPart, function ()
-- if curChooseLevel ~= self.vipLevel then
-- self:RefreshPanelStatus(self.vipLevel)
-- end
-- end)
Util.AddClick(self.btnGetReward, function ()
self:BtnRewardClick()
end)
Util.AddClick(self.btnGiftBuy, function ()
self:BuyVipGift()
end)
end
--待功能扩展(试图打开某个状态)
function VipPanel:OnOpen()
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main })
end
function VipPanel:OnSortingOrderChange()
Util.AddParticleSortLayer(self.effect, self.sortingOrder - orginLayer)
orginLayer = self.sortingOrder
end
function VipPanel:OnShow()
---- 临时使用活动的充值数量
self.chargedNum = VipManager.GetChargedNum()
self.vipLevel = VipManager.GetVipLevel()
Log("当前Vip等级" .. self.vipLevel)
self.nextLevel = self.vipLevel + 1
self.nextLevel = self.nextLevel > maxVipLevel and maxVipLevel or self.nextLevel
-- 设置充值信息
self:SetChargeInfo()
--豪华礼包奖励信息
self:MonthGift()
-- 滑动的特权按钮
self:SetBtnListState()
self:InitAllRedBtn()
-- 设置增益描述
lastChoose = self.vipLevel
self:RefreshPanelStatus(self.vipLevel)
end
-- 刷新系统界面
function VipPanel:RefreshPanelStatus(curLevel)
if lastChoose ~= curLevel then -- 重置
local bg = self.levelBtnList[lastChoose + 1]:GetComponent("Image")
local name = Util.GetGameObject(self.levelBtnList[lastChoose + 1], "level"):GetComponent("Text")
local desc = Util.GetGameObject(self.levelBtnList[lastChoose + 1], "info"):GetComponent("Text")
bg.sprite = this.spLoader:LoadSprite(btnColor[1].img)
local nameText = Language[11944] .. lastChoose
local descTex = VipManager.GetFirstNameByLevel(lastChoose)
name.text = string.format("<color=%s>%s</color>", btnColor[1].nameColor, nameText)
desc.text = string.format("<color=%s>%s</color>", btnColor[1].descColor, descTex)
end
curChooseLevel = curLevel
lastChoose = curChooseLevel
local bg1 = self.levelBtnList[curChooseLevel + 1]:GetComponent("Image")
local nameText1 = Language[11944] .. curChooseLevel
local descTex1 = VipManager.GetFirstNameByLevel(curChooseLevel)
local name1 = Util.GetGameObject(self.levelBtnList[curChooseLevel + 1], "level"):GetComponent("Text")
local desc1 = Util.GetGameObject(self.levelBtnList[curChooseLevel + 1], "info"):GetComponent("Text")
bg1.sprite = this.spLoader:LoadSprite(btnColor[2].img)
name1.text = string.format("<color=%s>%s</color>", btnColor[2].nameColor, nameText1)
desc1.text = string.format("<color=%s>%s</color>", btnColor[2].descColor, descTex1)
self.privilegeTitle.text = string.format(Language[11945], curLevel)
self.moneyNeedTotal.text = VipManager.CurLevelMoneyNeed(curLevel)
self.moneyIconTotal.sprite = SetIcon(this.spLoader, 15)
local VipLvConfig = vipLevelConfig[curLevel]
assert(VipLvConfig, string.format("ConfigName.VipLevelConfig not find VipLevel:%s", curLevel))
self:SetVipPrivileges(curLevel)
-- 刷新礼包内容
self:RefreshVipGift(curLevel)
end
-- 初始化刷新所有按钮红点状态
function VipPanel:InitAllRedBtn()
for i = 1, maxVipLevel + 1 do
VipPanel:SetBtnRedState(i - 1)
end
end
function VipPanel:SetBtnRedState(level)
local isShow = false
isShow = VipManager.GetBtnListRed(level)
self.btnRedPointList[level + 1]:SetActive(isShow)
end
----------------------------- 特权信息显示 --------------------------------------
function VipPanel:SetChargeInfo()
local maxLevelNeed = VipManager.CurLevelMoneyNeed(maxVipLevel)
local need, nextLevelNeed = VipManager.GetNextLevelNeed()
self.moneyNeed.text = need
--self.chargeTip:SetActive(self.chargedNum < maxLevelNeed)
self.vipNextLevel.text = self.nextLevel
self.moneyIcon.sprite = SetIcon(this.spLoader, 15)
self.rewardInfo.sprite = this.spLoader:LoadSprite(VIP_LEVEL_REWARD[self.nextLevel])
self.rewardInfo:SetNativeSize()
self.vipCurLevel.text = self.vipLevel
self.progressValue.fillAmount = self.chargedNum / nextLevelNeed
self.progressText.text = self.chargedNum .. "/" .. nextLevelNeed
self:RefreshBtnState()
end
function VipPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Vip.OnVipDailyRewardStatusChanged, self.OnVipDailyRewardStatusChanged, self)
end
function VipPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Vip.OnVipDailyRewardStatusChanged, self.OnVipDailyRewardStatusChanged, self)
end
-- 点击领取按钮
function VipPanel:BtnRewardClick()
-- 豪华月卡的激活状态
local isActive = MonthCardManager.GetMonthCardIsOpen(MONTH_CARD_TYPE.LUXURYMONTHCARD)--VipManager.GetMonthCardOpenState()
local getState = VipManager.GetRewardState()
if not isActive then
JumpManager.GoJump(36004)
else
if getState < 1 then
-- 发送领取请求
NetManager.GetVipDailyReward(function(respond)
VipManager.SetRewardVipLevel(self.vipLevel)
UIManager.OpenPanel(UIName.RewardItemPopup, respond.drop, 1, function ()
self:RefreshBtnState()
CheckRedPointStatus(RedPointType.VIP_SHOP_DETAIL)
CheckRedPointStatus(RedPointType.VipPrivilege)
end)
end)
else
-- 设置为不可领取
PopupTipPanel.ShowTip(Language[11946])
end
end
end
-- 设置领取按钮显示状态
function VipPanel:RefreshBtnState()
local isActive = MonthCardManager.GetMonthCardIsOpen(MONTH_CARD_TYPE.LUXURYMONTHCARD)--VipManager.GetMonthCardOpenState()
Log("豪华月卡是否激活 -- " .. tostring(isActive))
local getState = VipManager.GetRewardState()
local str = ""
if not isActive then
str = Language[11947]
else
if getState < 1 then
str = Language[11948]
else
str = Language[10101]
end
end
-- 设置红点
self.redReward:SetActive(isActive and getState < 1)
self.btnText.text = str
end
-- 5点刷新数据
function VipPanel:OnVipDailyRewardStatusChanged()
self:RefreshBtnState()
self:MonthGift()
self:InitAllRedBtn()
end
----------------------------- 豪华月卡每日礼包显示 --------------------------------
function VipPanel:MonthGift()
local level = 0
local getState = VipManager.GetRewardState()
local isLevelUp = self:IsLevelUped()
--Log("升级结果 -- " .. tostring(isLevelUp))
--Log("getState" .. getState)
if isLevelUp and getState > 0 then -- 升级过又领取了奖励
level = VipManager.GetRewardVipLevel()
else
level = VipManager.GetVipLevel()
end
Log("显示等级 " .. level .. "的礼包内容")
local rewardData = vipLevelConfig[level].VipBoxDailyReward
if not rewardData then Log(Language[11949]) return end
for i = 1, 2 do
this.dailyReward[i].gameObject:SetActive(i <= #rewardData)
if rewardData[i] then
this.dailyReward[i]:OnOpen(false, {rewardData[i][1],rewardData[i][2]}, 0.9)
end
end
end
function VipPanel:SetBtnListState()
for i = 1, maxVipLevel + 1 do
local btn = self.levelBtnList[i]
Util.GetGameObject(btn, "level"):GetComponent("Text").text = Language[11944] .. i - 1
Util.GetGameObject(btn, "info"):GetComponent("Text").text = VipManager.GetFirstNameByLevel(i - 1)
end
end
------------------------------- 特权增益 --------------------------------------
--特权增益描述
function VipPanel:SetVipPrivileges(curVipLevel)
if self.priThread then
coroutine.stop(self.priThread)
self.priThread = nil
end
table.walk(self.privilegeList, function(privilegeItem)
privilegeItem:SetActive(false)
end)
local curVipData = PrivilegeManager.GetTipsByVipLv(curVipLevel)
local tempNumber = 0
self.priThread = coroutine.start(function()
for _, privilegeInfo in ipairs(curVipData) do
if privilegeInfo.value == "" or privilegeInfo.value > 0 then
tempNumber = tempNumber + 1
local item = self:GetPrivilegeItem(tempNumber)
item:SetActive(false)
-- local str = "<size=45><color=#7bb15bFF> </color></size>"
-- str = string.format("<size=45><color=#7bb15bFF>%s</color></size>", privilegeInfo.value)
if privilegeInfo.id==1 then --特权关卡挂机加成百分比
Util.GetGameObject(item, "title"):GetComponent("Text").text = privilegeInfo.content ..Language[11950]..(privilegeInfo.value*100-100).."%"
else
Util.GetGameObject(item, "title"):GetComponent("Text").text = privilegeInfo.content .. privilegeInfo.value
end
PlayUIAnim(Util.GetGameObject(item, "content"))
coroutine.wait(0.03)
--加成为0就别丢人现眼了
if privilegeInfo.id==1 and (privilegeInfo.value*100-100)==0 then
item:SetActive(false)
else
item:SetActive(true)
end
end
end
end)
end
function VipPanel:GetPrivilegeItem(index)
if self.privilegeList[index] then
return self.privilegeList[index]
else
local newItem = newObjToParent(self.privilegeItem, self.privilegeContent)
table.insert(self.privilegeList, newItem)
return newItem
end
end
-----------------------------------------------------------------------
--------------------------特权礼包购买 ----------------------------------
function VipPanel:RefreshVipGift(curLevel)
local shopData = VipManager.vipShopData[curLevel + 1]
if not shopData then
Log("未能找到Vip等级为 " .. curLevel .. "的商店数据")
return
end
local curGoodData = shopData.Goods
for i = 1, 6 do
self.vipGfitList[i].gameObject:SetActive(i <= #curGoodData)
if curGoodData[i] then
self.vipGfitList[i]:OnOpen(false, {curGoodData[i][1],curGoodData[i][2]}, 0.75)
end
end
giftData = {}
-- 设置购买按钮状态
local itemId = shopData.Id
local costId, finalCost, orignalCost = ShopManager.calculateBuyCost(SHOP_TYPE.VIP_GIFT, itemId, 1)
self.giftText.text = orignalCost
self.giftIcon.sprite = SetIcon(this.spLoader, costId)
self.buyIcon.sprite = SetIcon(this.spLoader, costId)
giftData.shopType = SHOP_TYPE.VIP_GIFT
giftData.shopItemId = itemId
giftData.num = 1
giftData.costId = costId
giftData.costNum = finalCost
VipPanel:FreshBuyBtnState(giftData.costNum)
end
--购买礼包处理
function VipPanel:BuyVipGift()
-- 你有资格买吗
if curChooseLevel > self.vipLevel then
PopupTipPanel.ShowTip(Language[11951] .. curChooseLevel .. Language[11952])
return
end
-- 商品的剩余购买次数
local leftNum = ShopManager.GetShopItemRemainBuyTimes(giftData.shopType, giftData.shopItemId)
if leftNum < 1 and leftNum ~= -1 then
PopupTipPanel.ShowTip(Language[11953])
return
end
-- 钱钱是不是不够,找麻麻要吧
local haveNum = BagManager.GetItemCountById(giftData.costId)
if haveNum < giftData.costNum then
UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = UpViewRechargeType.DemonCrystal })
return
end
ShopManager.RequestBuyShopItem(giftData.shopType, giftData.shopItemId, 1, function ()
VipPanel:FreshBuyBtnState(giftData.costNum)
end)
end
-- 刷新购买按钮显示状态
function VipPanel:FreshBuyBtnState(costNum)
-- 检测剩余购买次数
local leftNum = ShopManager.GetShopItemRemainBuyTimes(giftData.shopType, giftData.shopItemId)
local canBuy = false
if leftNum < 1 and leftNum ~= -1 then
self.buyText.text = Language[11954]
canBuy = false
Util.SetGray(self.btnGiftBuy, true)
else
self.buyText.text = costNum
canBuy = true
Util.SetGray(self.btnGiftBuy, false)
end
end
-- 判断出去面板后,是否升过级
function VipPanel:IsLevelUped()
local isUp = false
-- 今日领取奖励时的等级
local rewardLevel = VipManager.GetRewardVipLevel()
if rewardLevel > 0 and rewardLevel ~= self.vipLevel then
isUp = true
else
isUp = false
end
return isUp
end
--------------------------------------------------------------------
--跳转显示新手提示圈
function this.ShowGuideGo()
JumpManager.ShowGuide(UIName.VipPanel, this.taskItemList[1].dealBtn)
end
function VipPanel:OnClose()
if self.priThread then
coroutine.stop(self.priThread)
self.priThread = nil
end
if self.taskThread then
coroutine.stop(self.taskThread)
self.taskThread = nil
end
-- 目前的选择
local bg = self.levelBtnList[curChooseLevel + 1]:GetComponent("Image")
local name = Util.GetGameObject(self.levelBtnList[curChooseLevel + 1], "level"):GetComponent("Text")
local desc = Util.GetGameObject(self.levelBtnList[curChooseLevel + 1], "info"):GetComponent("Text")
bg.sprite = this.spLoader:LoadSprite(btnColor[1].img)
local namaText = Language[11944] .. curChooseLevel + 1
local descTex = VipManager.GetFirstNameByLevel(curChooseLevel)
name.text = string.format("<color=%s>%s</color>", btnColor[1].nameColor, namaText)
desc.text = string.format("<color=%s>%s</color>", btnColor[1].descColor, descTex)
end
function VipPanel:OnDestroy()
this.spLoader:Destroy()
SubUIManager.Close(this.UpView)
end
return VipPanel
return VipPanel