miduo_client/Assets/ManagedResources/~Lua/Modules/Recharge/View/RechargeViewNew.lua

266 lines
12 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.

local RechargeViewNew = {}
local growData = {}
function RechargeViewNew:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = RechargeViewNew })
return b
end
--添加事件监听(用于子类重写)
function RechargeViewNew:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.MoneyPay.OnPayResultSuccess,self.SetGrowGift,self)
end
--移除事件监听(用于子类重写)
function RechargeViewNew:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.MoneyPay.OnPayResultSuccess,self.SetGrowGift,self)
end
function RechargeViewNew:InitComponent()
self.spLoader = SpriteLoader.New()
self.shopViewRoot = Util.GetGameObject(self.gameObject, "root")
if not self.shopView then
self.shopView = SubUIManager.Open(SubUIConfig.ShopView, self.shopViewRoot.transform)
-- 修改商品栏的位置
self.shopView:SetItemContentPosition(Vector3.New(0, 710, 0))
end
-- 显示特权信息
--===================成长礼包================
self.grow = Util.GetGameObject(self.gameObject,"growPack/Content")
self.tip = Util.GetGameObject(self.grow,"Tip"):GetComponent("Text")
self.icon = Util.GetGameObject(self.grow,"Icon"):GetComponent("Image")
self.Level = Util.GetGameObject(self.grow,"Icon/Level"):GetComponent("Text")
self.name = Util.GetGameObject(self.grow,"Name"):GetComponent("Image")
self.name.sprite=self.spLoader:LoadSprite("gm_mingwang_title")
self.progress = Util.GetGameObject(self.grow,"Progress/Image")
self.value = Util.GetGameObject(self.grow,"Progress/Text"):GetComponent("Text")
self.reward = Util.GetGameObject(self.grow,"Reward")
self.btnLeft = Util.GetGameObject(self.grow,"btnLeft")
self.btnRight = Util.GetGameObject(self.grow,"btnRight")
self.btnGet = Util.GetGameObject(self.grow,"btnGet")
self.price = Util.GetGameObject(self.btnGet,"cost/Text"):GetComponent("Text")
self.cost = Util.GetGameObject(self.btnGet,"cost")
self.btnText = Util.GetGameObject(self.btnGet,"Text")
self.btnRed = Util.GetGameObject(self.btnGet,"red")
self.leftRed = Util.GetGameObject(self.btnLeft,"Red")
self.rightRed = Util.GetGameObject(self.btnRight,"Red")
self.endTimeBg = Util.GetGameObject(self.gameObject,"growPack/Time")
self.endTimeBg.gameObject:SetActive(false)
self.ItemList = {}
end
function RechargeViewNew:BindEvent()
end
--界面打开时调用(用于子类重写)
function RechargeViewNew:OnOpen(_activityConfig,_index,parent)
self.actConfig = _activityConfig
self.pageIndex = _index
self.parent = parent
end
function RechargeViewNew:OnSortingOrderChange()
end
function RechargeViewNew:OnShow(_sortingOrder)
self.gameObject:SetActive(true)
self.sortingOrder = _sortingOrder
self.shopView:ShowShop(SHOP_TYPE.SOUL_STONE_SHOP, self.sortingOrder)
self:SetGrowGift()
end
--==============================成长礼包部分==========================(rechargeViewNew和EveryDayGiftNew中有完全相同的部分复制过去)
function RechargeViewNew:SetGrowGift()
growData = DynamicActivityManager.GetGiftDataByType({{2,95}})
local rechargeNum =BagManager.GetItemCountById(1351) --VipManager.GetChargedNum()--已经充值的金额
table.sort(growData,function (a,b)
return a.data.shopItemData.BuyRule[2] < b.data.shopItemData.BuyRule[2]
end)
--计算当前声望等级
if DynamicActivityManager.curLevel == 0 or DynamicActivityManager.curLevel == 1 then
for i = 1, #growData do
if rechargeNum < DynamicActivityManager.GetMingWangLv(growData[i].data.shopItemData.BuyRule[2]) then
if rechargeNum ~= 0 then
DynamicActivityManager.curLevel = i
if DynamicActivityManager.Index == 0 then
DynamicActivityManager.Index = DynamicActivityManager.curLevel
end
break
else
DynamicActivityManager.curLevel = 1
DynamicActivityManager.Index = 1
end
end
end
end
--如果所有都没有,说明超范围了
if DynamicActivityManager.curLevel == 0 then
DynamicActivityManager.curLevel = #growData
if DynamicActivityManager.Index == 0 then
DynamicActivityManager.Index = DynamicActivityManager.curLevel
end
end
Log("当前声望Level:"..tostring(DynamicActivityManager.curLevel).." Index:"..tostring(DynamicActivityManager.Index))
--如果有当前声望数据,就显示,没有就显示上一档位
--local data = not not growData[DynamicActivityManager.Index] and growData[DynamicActivityManager.Index] or growData[DynamicActivityManager.Index-1]
local data=growData[DynamicActivityManager.Index]
if data==nil then
return
end
self:RefreshReward(data)
Util.AddOnceClick(self.btnLeft,function ()
if growData[DynamicActivityManager.Index - 1] then
DynamicActivityManager.Index = DynamicActivityManager.Index - 1
self:RefreshReward(growData[DynamicActivityManager.Index])
end
end)
Util.AddOnceClick(self.btnRight,function ()
if growData[DynamicActivityManager.Index + 1] then
DynamicActivityManager.Index = DynamicActivityManager.Index + 1
self:RefreshReward(growData[DynamicActivityManager.Index])
end
end)
end
--刷新奖励、按钮显示
function RechargeViewNew:RefreshReward(Data)
local rechargeNum =BagManager.GetItemCountById(1351) --VipManager.GetChargedNum()--已经充值的金额
self.btnLeft:SetActive(not not growData[DynamicActivityManager.Index - 1])--左按钮显示
self.btnRight:SetActive(not not growData[DynamicActivityManager.Index + 1])--右按钮显示
-- LogPink(DynamicActivityManager.Index.." 金额:"..tostring(Data.data.shopItemData.BuyRule[2]).." 限购:"..tostring(Data.data.limitNum).." 已购:"..tostring(Data.data.boughtNum).." rechargeNum:"..tostring(rechargeNum))
local text = 1
local num = 0
if DynamicActivityManager.Index < 2 then
num = growData[1].data.shopItemData.BuyRule[2]
elseif DynamicActivityManager.Index + 1 > #growData then
text = #growData
num = growData[#growData].data.shopItemData.BuyRule[2]
else
text = DynamicActivityManager.Index
num = growData[DynamicActivityManager.Index].data.shopItemData.BuyRule[2]
end
num=DynamicActivityManager.GetMingWangLv(num)
local aaa=growData[DynamicActivityManager.curLevel].data.shopItemData.BuyRule[2]
if DynamicActivityManager.curLevel <= 2 then
--self.tip.text = string.format("再获得%s积分升至名望1",num - rechargeNum)
elseif DynamicActivityManager.curLevel + 1 >= #growData and rechargeNum >= DynamicActivityManager.GetMingWangLv(aaa) then
--self.tip.text = ""
else
--self.tip.text = string.format("再获得%s积分升至名望%s",DynamicActivityManager.GetMingWangLv(aaa) - rechargeNum,DynamicActivityManager.curLevel+1)
end
self.tip.text="每充值1元可以获得10点名望经验"
local size = rechargeNum/num
size = size > 1 and 1 or size
self.icon.sprite = self.spLoader:LoadSprite("UI_hz_huizhang")
self.Level.text=text
self.progress:GetComponent("RectTransform").sizeDelta = Vector3.New(483*size,12,0)
self.value.text = string.format("%s/%s",rechargeNum,num)
self.price.text = Data.data.price
self.btnRed:SetActive(false)
local needNum=DynamicActivityManager.GetMingWangLv(Data.data.shopItemData.BuyRule[2]-1)
if Data.data.limitNum - Data.data.boughtNum > 0 then
self.btnText:SetActive(false)
self.cost:SetActive(true)
self.btnGet:GetComponent("Button").interactable = true
Util.SetGray(self.btnGet, false)
if rechargeNum >= needNum then
self.btnGet:GetComponent("Image").sprite = self.spLoader:LoadSprite("Btn_hz_cheng_01")
if BagManager.GetTotalItemNum(Data.data.costId) >= Data.data.price then
self.btnRed:SetActive(true)
end
else
self.btnGet:GetComponent("Image").sprite = self.spLoader:LoadSprite("Btn_hz_cheng_01")
end
else
self.btnText:SetActive(true)
self.cost:SetActive(false)
self.btnGet:GetComponent("Button").interactable = false
Util.SetGray(self.btnGet, true)
end
Util.AddOnceClick(self.btnGet,function ()
-- LogGreen(tostring(Data.data.limitNum).." "..tostring(Data.data.boughtNum))
if Data.data.limitNum - Data.data.boughtNum > 0 then
-- LogYellow(tostring(rechargeNum).." "..tostring(Data.data.shopItemData.BuyRule[2]))
if rechargeNum >= needNum then
-- LogPink(tostring(BagManager.GetItemCountById(Data.data.costId)).." "..tostring(Data.data.shopItemData.BuyRule[2]))
if BagManager.GetItemCountById(Data.data.costId) >= Data.data.price then
-- LogBlue(tostring(Data.data.shopItemData.buyType).." "..tostring(Data.data.shopData.id))
ShopManager.RequestBuyShopItem(Data.buyType, Data.data.shopData.id, 1, function()
self:SetGrowGift()
CheckRedPointStatus(RedPointType.DailyGift)
CheckRedPointStatus(RedPointType.GrowthPackage)
end)
else
NotEnoughPopup:Show(Data.data.costId)
end
else
PopupTipPanel.ShowTip(string.format("名望等级不足,请升至%s级后才可购买",DynamicActivityManager.Index))
end
end
end)
if not self.ItemList then
self.ItemList = {}
end
for i = 1, #self.ItemList do
self.ItemList[i].gameObject:SetActive(false)
end
for i = 1, #Data.data.shows do
if not self.ItemList[i] then
self.ItemList[i] = SubUIManager.Open(SubUIConfig.ItemView,self.reward.transform)
end
self.ItemList[i]:OnOpen(false, {Data.data.shows[i][1],Data.data.shows[i][2],Data.data.shows[i][3]}, 0.9,false,false,false,self.sortingOrder)
self.ItemList[i].gameObject:SetActive(true)
end
--左右按钮红点检测
if growData[DynamicActivityManager.Index - 1] then
for i = DynamicActivityManager.Index - 1, 1,-1 do
local curData = growData[i]
if curData.data.limitNum - curData.data.boughtNum > 0 and
BagManager.GetTotalItemNum(curData.data.costId) >= curData.data.price and
rechargeNum >=DynamicActivityManager.GetMingWangLv(curData.data.shopItemData.BuyRule[2]-1) then
self.leftRed:SetActive(true)
break
else
self.leftRed:SetActive(false)
end
end
end
if growData[DynamicActivityManager.Index + 1] then
for i = DynamicActivityManager.Index + 1, 20 do
local curData = growData[i]
if curData and curData.data.limitNum - curData.data.boughtNum > 0 and
BagManager.GetTotalItemNum(curData.data.costId) >= curData.data.price and
rechargeNum >= DynamicActivityManager.GetMingWangLv(curData.data.shopItemData.BuyRule[2]-1) then
self.rightRed:SetActive(true)
break
else
self.rightRed:SetActive(false)
end
end
end
end
function RechargeViewNew:OnClose()
self.gameObject:SetActive(false)
end
function RechargeViewNew:OnDestroy()
self.spLoader:Destroy()
if self.shopView then
SubUIManager.Close(self.shopView)
self.shopView = nil
end
end
return RechargeViewNew