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

165 lines
6.4 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 GMFreeRecharge = {}
self=GMFreeRecharge
local artConfig=ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
local rewardCom=ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
local sortingOrder = 0
local TabBox = require("Modules/Common/TabBox")
local _TabData={ [1] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "直充",img = "gm_shuachong_scGM_01_zh",id=7 },
[2] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "神充" ,img = "gm_shuachong_cjGM_01_zh",id=8 },
}
function GMFreeRecharge:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = GMFreeRecharge })
return b
end
local TabAdapter=nil
local SwitchView=nil
--初始化组件(用于子类重写)
function GMFreeRecharge:InitComponent()
self.spLoader = SpriteLoader.New()
self.titleImg=Util.GetGameObject(self.gameObject,"growPack/Content/Name"):GetComponent("Image")
self.coinNumTxt=Util.GetGameObject(self.gameObject,"growPack/Content/Num"):GetComponent("Text")
self.tipTxt=Util.GetGameObject(self.gameObject,"growPack/Content/Tip"):GetComponent("Text")
self.tabBox = Util.GetGameObject(self.gameObject, "TabBox")
self.progressImg=Util.GetGameObject(self.gameObject,"growPack/Content/Progress/Image"):GetComponent("Image")
self.progerssTxt=Util.GetGameObject(self.gameObject,"growPack/Content/Progress/Text"):GetComponent("Text")
self.itemPre=Util.GetGameObject(self.gameObject,"scrollbg/scrollroot/item")
self.grid=Util.GetGameObject(self.gameObject,"scrollbg/scrollroot")
local rootHight = self.grid.transform.rect.height
local width = self.grid.transform.rect.width
self.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.grid.transform,self.itemPre, nil, Vector2.New(width, rootHight), 1, 3, Vector2.New(50,10))
self.ScrollView.moveTween.MomentumAmount = 1
self.ScrollView.moveTween.Strength = 2
--self.ScrollView.elastic = false
TabAdapter=function(tab, index, status)
local tabLab = Util.GetGameObject(tab, "Text")
Util.GetGameObject(tab,"Image"):GetComponent("Image").sprite = self.spLoader:LoadSprite(_TabData[index][status])
tabLab:GetComponent("Text").text = _TabData[index].name
end
--切换视图
SwitchView=function(_index)
local list=ConfigManager.GetAllConfigsDataByKey(ConfigName.GMMaster,"Type",_TabData[_index].id)
if list then
LogError("3333333333333 list len=="..#list)
self.ScrollView:SetData(list, function (index, go)
self:SingleDataShow(go,list[index])
end,false)
else
LogError("222222222222222222")
end
end
self.TabCtrl = TabBox.New()
self.TabCtrl:SetTabAdapter(TabAdapter)
self.TabCtrl:SetChangeTabCallBack(SwitchView)
self.TabCtrl:Init(self.tabBox, _TabData, 1)
end
function GMFreeRecharge:SingleDataShow(item,data)
item.gameObject:SetActive(true)
local iconImg=Util.GetGameObject(item,"GameObject/icon"):GetComponent("Image")
local getImg=Util.GetGameObject(item,"GameObject/itemIcon"):GetComponent("Image")
local getTxt=Util.GetGameObject(item,"GameObject/itemNum"):GetComponent("Text")
local extraObj=Util.GetGameObject(item,"GameObject/first")
local extImg=Util.GetGameObject(item,"GameObject/first/Image"):GetComponent("Image")
local extTxt=Util.GetGameObject(item,"GameObject/first/Text"):GetComponent("Text")
local costObj=Util.GetGameObject(item,"GameObject/need")
local costImg=Util.GetGameObject(item,"GameObject/need/Image"):GetComponent("Image")
local costTxt=Util.GetGameObject(item,"GameObject/need/Text"):GetComponent("Text")
local nameTxt=Util.GetGameObject(item,"GameObject/price/Text"):GetComponent("Text")
local btn=Util.GetGameObject(item,"GameObject/price")
nameTxt.text=data.Name
local cost=data.Price
if cost[2] then
costObj:SetActive(true)
costImg.sprite=self.spLoader:LoadSprite(artConfig[itemConfig[cost[2][1]].ResourceID].Name)
costTxt.text=cost[2][2]
else
costObj:SetActive(false)
end
local rechargeConfig=ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig,data.PackID)
if rechargeConfig and rechargeConfig.RewardShow then
nameTxt.text=rechargeConfig.Name
local reward=rechargeConfig.RewardShow
getImg.sprite=self.spLoader:LoadSprite(artConfig[itemConfig[reward[1][1]].ResourceID].Name)
getTxt.text=PrintWanNum(reward[1][2])
if reward[2] then
extraObj:SetActive(true)
extImg.sprite=self.spLoader:LoadSprite(artConfig[itemConfig[reward[2][1]].ResourceID].Name)
extTxt.text=PrintWanNum(reward[2][2])
else
extraObj:SetActive(false)
end
end
Util.AddOnceClick(btn,function()
PayManager.Pay(data.PackID,function()
local num=BagManager.GetItemCountById(1367)
self.coinNumTxt.text="GM余额"..num
end)
end)
end
--绑定事件(用于子类重写)
function GMFreeRecharge:BindEvent()
end
--添加事件监听(用于子类重写)
function GMFreeRecharge:AddListener()
end
--移除事件监听(用于子类重写)
function GMFreeRecharge:RemoveListener()
end
--界面打开时调用(用于子类重写)
function GMFreeRecharge:OnOpen(_activityConfig,_index,parent)
self.actConfig = _activityConfig
self.pageIndex = _index
self.parent = parent
end
function GMFreeRecharge:OnSortingOrderChange()
end
-- 打开,重新打开时回调
function GMFreeRecharge:OnShow(_sortingOrder)
self.gameObject:SetActive(true)
sortingOrder = _sortingOrder
local num=BagManager.GetItemCountById(1367)
self.coinNumTxt.text="GM余额"..num
local useTime=PrivilegeManager.GetPrivilegeUsedTimes(PRIVILEGE_TYPE.GM_YI_YUAN_UP_TIME)
local maxNum=ActivityGiftManager.GetYiYuanUpMaxTime()
self.progressImg.fillAmount=useTime/maxNum
self.progerssTxt.text=useTime.."/"..maxNum
end
local gifts={}
local activityData={}
-- 妖晶数量显示
--界面关闭时调用(用于子类重写)
function GMFreeRecharge:OnClose()
self.gameObject:SetActive(false)
end
--界面销毁时调用(用于子类重写)
function GMFreeRecharge:OnDestroy()
self.spLoader:Destroy()
SubUIManager.Close(self.ScrollView)
end
return GMFreeRecharge