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

307 lines
11 KiB
Lua

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)
local icons={"gm_shuachong_scGM_02_zh","gm_shuachong_cjGM_02_zh","gm_shuachong_sjGM_02_zh","gm_shuachong_wsGM_02_zh"}
local sortingOrder = 0
local isFirst=true
local curBtn=nil
local curConfig=nil
--初始化组件(用于子类重写)
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")
this.gmIcon=Util.GetGameObject(self.gameObject, "layout/top/Image"):GetComponent("Image")
this.btn_up=Util.GetGameObject(self.gameObject, "layout/top/btn_up")
this.progress=Util.GetGameObject(self.gameObject, "layout/top/progress")
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")
this.info=Util.GetGameObject(self.gameObject, "layout/top/Text (1)"):GetComponent("Text")
--设置滚动条
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
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)
curBtn=tabBtn
curConfig=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()
UIManager.OpenPanel(UIName.GMShuaChongTeQuan)
end)
end
--添加事件监听(用于子类重写)
function GMChangePanel:AddListener()
end
--移除事件监听(用于子类重写)
function GMChangePanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function GMChangePanel:OnOpen(activityId)
this:ShowTopInfo()
end
function GMChangePanel:OnFocus()
this:ShowTopInfo()
end
function GMChangePanel:ShowTopInfo()
local num=BagManager.GetItemCountById(1367)
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)
this.curTxt.text=num..""
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
maxnum=privile.Condition[index][2]
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
end
function this.TabBtnOnClick(btn,config)
curBtn=btn
curConfig=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]
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],isOpen,tip)
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,isOpen,tip)
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 priceTxt=Util.GetGameObject(go, "price"):GetComponent("Text")
local limitTxt=Util.GetGameObject(go, "limit"):GetComponent("Text")
local recharge=rechargeCommodityConfig[data.PackID]
local scale=1
btn:SetActive(true)
limitTxt.gameObject:SetActive(false)
priceTxt.gameObject:SetActive(true)
if data.PackID~=0 and recharge then
name.text=recharge.Name
priceTxt.gameObject:SetActive(isOpen)
limitTxt.gameObject:SetActive(not isOpen)
btn:SetActive(isOpen)
limitTxt.text=tip
--LogError("type=="..recharge.Type.." id=="..recharge.Id)
local leftBuyTime=OperatingManager.GetLeftBuyTime(recharge.Type,recharge.Id)
if leftBuyTime==-1 then
num.text=""
else
num.text="("..leftBuyTime.."/"..recharge.Limit..")"
end
btn:GetComponent("Button").interactable = leftBuyTime==-1 or leftBuyTime>0
Util.SetGray(btn,leftBuyTime==0)
if data.Type==7 or data.Type==8 then
btnTxt.text="前往"
else
btnTxt.text="兑换"
end
if isOpen and leftBuyTime>0 then
priceTxt.gameObject:SetActive(true)
else
priceTxt.gameObject:SetActive(false)
end
priceTxt.text=data.Price[1][2]..""
else
name.text=data.Name
priceTxt.gameObject:SetActive(false)
btn:GetComponent("Button").interactable = true
Util.SetGray(btn,false)
if data.Id==45 then
scale = BattleManager.GetTimeScale()
scale = math.floor(scale*10 + 0.5)/10
if scale == BATTLE_TIME_SCALE_ONE then
btnTxt.text="一键破解"
else
btnTxt.text="暂停"
end
else
btnTxt.text="前往"
end
end
--LogError("data.id=="..data.Id.." data.name=="..data.Type)
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
des=data.DisplayReward
itemDes.text=des
Util.AddOnceClick(btn, function()
if data.PackID==0 then
if data.Id==45 then
scale = BattleManager.GetTimeScale()
scale = math.floor(scale*10 + 0.5)/10
--LogError("scale========="..scale)
if scale == BATTLE_TIME_SCALE_ONE then
BattleManager.SetTimeScale(BATTLE_TIME_SCALE_TWO)
btnTxt.text="暂停"
else
BattleManager.SetTimeScale(BATTLE_TIME_SCALE_ONE)
btnTxt.text="一键破解"
end
scale = BattleManager.GetTimeScale()
scale = math.floor(scale*10 + 0.5)/10
else
JumpManager.GoJump(data.Jump)
end
return
else
if data.Type==7 or data.Type==8 then
JumpManager.GoJump(data.Jump)
return
end
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)
if leftBuyTime==-1 then
num.text=""
else
num.text="("..leftBuyTime.."/"..recharge.Limit..")"
end
Util.SetGray(btn,leftBuyTime==0)
btn:GetComponent("Button").interactable = leftBuyTime==-1 or leftBuyTime>0
this:ShowTopInfo()
end)
end
local args={}
args[1]="是否兑换?"
args[2]="兑换"
args[3]="取消"
args[4]=sureFunc
UIManager.OpenPanel(UIName.GMCommonConfirmPanel,args)
end
end)
end
function GMChangePanel:OnSortingOrderChange()
end
-- 打开,重新打开时回调
function GMChangePanel:OnShow(_sortingOrder)
this:ShowTopInfo()
this.TabBtnOnClick(curBtn,curConfig)
end
--界面关闭时调用(用于子类重写)
function GMChangePanel:OnClose()
isFirst=true
end
--界面销毁时调用(用于子类重写)
function GMChangePanel:OnDestroy()
this.spLoader:Destroy()
end
return GMChangePanel