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

229 lines
8.5 KiB
Lua
Raw Normal View History

2022-09-20 17:04:48 +08:00
require("Base/BasePanel")
GMChangePanel = Inherit(BasePanel)
local this= GMChangePanel
local GMInfo=ConfigManager.GetConfig(ConfigName.GMInfo)
local GMMaster=ConfigManager.GetConfig(ConfigName.GMMaster)
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
local rechargeCommodityConfig=ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
2022-10-27 15:32:13 +08:00
local icons={"gm_shuachong_scGM_02_zh","gm_shuachong_cjGM_02_zh","gm_shuachong_sjGM_02_zh","gm_shuachong_wsGM_02_zh"}
2022-09-20 17:04:48 +08:00
local sortingOrder = 0
--初始化组件(用于子类重写)
function GMChangePanel:InitComponent()
this.spLoader = SpriteLoader.New()
--定义头部文字和按钮
this.curTxt=Util.GetGameObject(self.gameObject, "layout/top/value1"):GetComponent("Text")
this.addTxt=Util.GetGameObject(self.gameObject, "layout/top/value2"):GetComponent("Text")
this.btn_add=Util.GetGameObject(self.gameObject, "layout/top/btn_chong")
2022-09-23 15:24:10 +08:00
this.gmIcon=Util.GetGameObject(self.gameObject, "layout/top/Image"):GetComponent("Image")
2022-09-20 17:04:48 +08:00
this.btn_up=Util.GetGameObject(self.gameObject, "layout/top/btn_up")
2022-09-23 15:24:10 +08:00
this.progress=Util.GetGameObject(self.gameObject, "layout/top/progress")
2022-09-20 17:04:48 +08:00
this.progressTxt=Util.GetGameObject(self.gameObject, "layout/top/progress/value"):GetComponent("Text")
this.progressBar=Util.GetGameObject(self.gameObject, "layout/top/progress/progressBar"):GetComponent("Image")
this.progressBar.fillAmount=0
--滚动条和预设
--self.scrollItem = Util.GetGameObject(self.gameObject, "rzyBg/scrollItem")
this.itemPre = Util.GetGameObject(self.gameObject, "layout/tabBtnPre")
this.grid = Util.GetGameObject(self.gameObject, "layout/tabScroll/grid")
this.btn_close=Util.GetGameObject(self.gameObject, "layout/backBtn")
this.selectBtn=Util.GetGameObject(self.gameObject, "layout/tabSelectBtn")
this.selectBtnText=Util.GetGameObject(self.gameObject, "layout/tabSelectBtn/Text"):GetComponent("Text")
this.shopItemPre=Util.GetGameObject(self.gameObject, "layout/shopItemPre")
this.scroll=Util.GetGameObject(self.gameObject, "layout/scroll")
this.hint=Util.GetGameObject(self.gameObject, "layout/hint"):GetComponent("Text")
2022-09-23 15:24:10 +08:00
this.info=Util.GetGameObject(self.gameObject, "layout/top/Text (1)"):GetComponent("Text")
2022-09-20 17:04:48 +08:00
--设置滚动条
local rootHight = this.scroll.transform.rect.height
local width = this.scroll.transform.rect.width
this.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform,
this.shopItemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 5),false)
this.scrollView.moveTween.MomentumAmount = 1
this.scrollView.moveTween.Strength = 2
local isFirst=true
for k, v in ConfigPairs(GMInfo) do
if v.IsOpen==1 then
local tabBtn = newObjToParent(this.itemPre,this.grid)
Util.GetGameObject(tabBtn, "Text"):GetComponent("Text").text=v.Name
Util.AddClick(tabBtn,function ()
this.TabBtnOnClick(tabBtn,v)
end)
if isFirst then
this.TabBtnOnClick(tabBtn,v)
isFirst=false
end
end
end
end
--绑定事件(用于子类重写)
function GMChangePanel:BindEvent()
Util.AddClick(this.btn_close, function()
self:ClosePanel()
end)
Util.AddClick(this.btn_add, function()
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup,1342)
end)
Util.AddClick(this.btn_up, function()
2022-11-04 17:18:11 +08:00
UIManager.OpenPanel(UIName.GMShuaChongTeQuan)
2022-09-20 17:04:48 +08:00
end)
end
--添加事件监听(用于子类重写)
function GMChangePanel:AddListener()
end
--移除事件监听(用于子类重写)
function GMChangePanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function GMChangePanel:OnOpen(activityId)
this:ShowTopInfo()
end
2022-09-23 15:24:10 +08:00
function GMChangePanel:OnFocus()
this:ShowTopInfo()
end
2022-09-20 17:04:48 +08:00
function GMChangePanel:ShowTopInfo()
local num=BagManager.GetItemCountById(1367)
2022-09-23 15:24:10 +08:00
this.info.text="使用1元直充卡可增加余额今日还可存入"
local allTimes = PrivilegeManager.GetPrivilegeNumber(PRIVILEGE_TYPE.GM_YI_YUAN_UP_TIME)
local useTime=PrivilegeManager.GetPrivilegeUsedTimes(PRIVILEGE_TYPE.GM_YI_YUAN_UP_TIME)
local leftTimes = PrivilegeManager.GetPrivilegeRemainValue(PRIVILEGE_TYPE.GM_YI_YUAN_UP_TIME)
LogError("allTimes=="..allTimes.." leftTimes=="..leftTimes.." useTime"..useTime)
2022-09-20 17:04:48 +08:00
this.curTxt.text=num..""
2022-09-23 15:24:10 +08:00
local maxnum=100
local missions=ActivityGiftManager.GetActivityInfoByType(ActivityTypeDef.shuaChongTeQuan).mission
local index=1
if missions then
for i = 1, #missions do
if missions[i].state~=0 then
index=i
end
end
end
this.gmIcon.sprite=this.spLoader:LoadSprite(icons[index])
local privile=ConfigManager.GetConfigData(ConfigName.PrivilegeTypeConfig,2101)
if privile then
2022-10-27 15:32:13 +08:00
maxnum=privile.Condition[index][2]
2022-09-23 15:24:10 +08:00
if maxnum~=-1 then
this.progress:SetActive(true)
this.addTxt.text=maxnum-useTime..""
this.progressBar.fillAmount=useTime/maxnum
this.progressTxt.text=useTime.."/"..maxnum
else
this.progress:SetActive(false)
this.addTxt.text="不限"
end
end
2022-09-20 17:04:48 +08:00
end
function this.TabBtnOnClick(btn,config)
--local _level=_privilegeLv>0 and _privilegeLv or 1
--local clickBtn=this.tabGrid.transform:GetChild(_level-1)
this.selectBtn.transform:SetParent(btn.gameObject.transform)
this.selectBtn.transform.localScale = Vector3.one
this.selectBtn.transform.localPosition = Vector3.zero
this.selectBtnText.text=config.Name
--this.UpdateLayout(_level)
local dataList={}
local aa=config.Unlock[1]
LogError("aa[1]==="..aa[1].." aa[2]==="..aa[2])
local isOpen,tip=CheckGMIsOpen(aa[1],aa[2])
if isOpen then
this.hint.gameObject:SetActive(false)
this.scroll:SetActive(true)
for k, v in ConfigPairs(GMMaster) do
if v.Type==config.Type then
table.insert(dataList,v)
end
end
this.scrollView:SetData(dataList,function(index, rewardItem)
this:SingleTask(rewardItem, dataList[index])
end,not false,not false)
else
this.hint.gameObject:SetActive(true)
this.hint.text=tip
this.scroll:SetActive(false)
end
end
function GMChangePanel:SingleTask(go,data)
local name=Util.GetGameObject(go, "name"):GetComponent("Text")
local num=Util.GetGameObject(go, "num"):GetComponent("Text")
local itemDes=Util.GetGameObject(go, "item"):GetComponent("Text")
local btn=Util.GetGameObject(go, "btn")
local btnTxt=Util.GetGameObject(go, "btn/Text"):GetComponent("Text")
local recharge=rechargeCommodityConfig[data.PackID]
name.text=recharge.Name
LogError("type=="..recharge.Type.." id=="..recharge.Id)
local leftBuyTime=OperatingManager.GetLeftBuyTime(recharge.Type,recharge.Id)
num.text="("..leftBuyTime.."/"..recharge.Limit..")"
local des=""
for i = 1, #data.Price do
if itemConfig[data.Price[i][1]] then
des=des.." "..itemConfig[data.Price[i][1]].Name.." *"..data.Price[i][2]
end
end
itemDes.text=des
Util.SetGray(btn,leftBuyTime<=0)
btn:GetComponent("Button").interactable = leftBuyTime>0
Util.AddClick(btn, function()
local sureFunc=function()
NetManager.SendGmBuyGoodRequest(data.PackID,function()
if data.Jump~=0 then
self:ClosePanel()
JumpManager.GoJump(data.Jump)
return
end
local leftBuyTime=OperatingManager.GetLeftBuyTime(recharge.Type,recharge.Id)
num.text="("..leftBuyTime.."/"..recharge.Limit..")"
Util.SetGray(btn,leftBuyTime<=0)
btn:GetComponent("Button").interactable = leftBuyTime>0
this:ShowTopInfo()
end)
end
local args={}
args[1]="是否兑换?"
args[2]="兑换"
args[3]="取消"
args[4]=sureFunc
UIManager.OpenPanel(UIName.GMCommonConfirmPanel,args)
end)
end
function GMChangePanel:OnSortingOrderChange()
end
-- 打开,重新打开时回调
function GMChangePanel:OnShow(_sortingOrder)
end
--界面关闭时调用(用于子类重写)
function GMChangePanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function GMChangePanel:OnDestroy()
this.spLoader:Destroy()
end
return GMChangePanel