miduo_client/Assets/ManagedResources/~Lua/Modules/Popup/TrialRewardPopup.lua

193 lines
6.3 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.

----- 试练副本奖励弹窗 -----
require("Base/BasePanel")
local TrialRewardPopup = Inherit(BasePanel)
local this = TrialRewardPopup
local rewardConfig
local itemList={} --预设容器
local sortingOrder=0
local getFunc = {}
local pres = {}
local curType = 0
local scrollView = nil
function TrialRewardPopup:InitComponent()
this.panel=Util.GetGameObject(this.gameObject,"Panel")
this.backBtn=Util.GetGameObject(this.panel,"BackBtn")
this.scroll=Util.GetGameObject(this.panel,"Scroll")
pres[1]=Util.GetGameObject(this.panel,"Scroll/Pre")
pres[2]=Util.GetGameObject(this.panel,"Scroll/Pre3")
pres[4]=Util.GetGameObject(this.panel,"Scroll/Pre4")
scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,this.scroll.transform,pres[MonsterCampManager.preType], nil,
Vector2.New(this.scroll.transform.rect.width,this.scroll.transform.rect.height),1,1,Vector2.New(0,5))
scrollView.gameObject:GetComponent("RectTransform").anchoredPosition= Vector2.New(0,0)
scrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5)
scrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5)
scrollView.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5)
scrollView.moveTween.MomentumAmount = 1
scrollView.moveTween.Strength = 2
end
function TrialRewardPopup:BindEvent()
Util.AddClick(this.backBtn,function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
end
function TrialRewardPopup:AddListener()
end
function TrialRewardPopup:RemoveListener()
end
function TrialRewardPopup:OnSortingOrderChange()
sortingOrder = self.sortingOrder
end
function TrialRewardPopup:OnOpen(...)
local arg = {...}
rewardConfig = arg[1]
getFunc = arg[2]
curType = arg[3]
end
function TrialRewardPopup:OnShow()
this.RefreshPanel(true,true)
sortingOrder = self.sortingOrder
end
function TrialRewardPopup:OnClose()
end
function TrialRewardPopup:OnDestroy()
scrollView=nil
itemList = {}
end
--0 已经领取1 可领取2不能领取·
local sortIndex = {
[0] = 0,
[1] = 2,
[2] = 1,
}
--刷新
function this.RefreshPanel(isTop,isAni)
if curType ~= 4 then
table.sort(rewardConfig,function(a,b)
if sortIndex[a.state] == sortIndex[b.state] then
return a.Id < b.Id
end
return sortIndex[a.state] > sortIndex[b.state]
end)
scrollView:SetData(rewardConfig,function(index,root)
this.SetScrollPre(root,rewardConfig[index])
end,not isTop,not isAni)
else--踏碎凌霄-仅供展示
scrollView:SetData(rewardConfig,function(index,root)
this.SetScrollPre2(root,rewardConfig[index])
end,not isTop,not isAni)
end
end
--设置每条数据
function this.SetScrollPre(root,data)
local info=Util.GetGameObject(root,"Title/Info"):GetComponent("Text")
local grid=Util.GetGameObject(root,"Grid")
local goBtn=Util.GetGameObject(root,"GoBtn")
local getBtn=Util.GetGameObject(root,"GetBtn")
local mask=Util.GetGameObject(root,"mask")
local pregress = Util.GetGameObject(root,"getRewardProgress")
if pregress then
if curType == 2 then
pregress:GetComponent("Text").text = "("..(MonsterCampManager.monsterWave - 1).."/"..data.Id..")"
end
end
info.text=data.info --string.format( Language[11483],data.Count,MapTrialManager.GetKilCount(),data.Count)
--ResetItemView(root,grid.transform,itemList,#data.BoxReward,0.9,sortingOrder,false,data.BoxReward)
if not itemList[root] then
itemList[root] = {}
end
for k,v in ipairs(itemList[root]) do
v.gameObject:SetActive(false)
end
for i = 1 , #data.BoxReward do
if not itemList[root][i] then
itemList[root][i] = SubUIManager.Open(SubUIConfig.ItemView,grid.transform)
itemList[root][i].gameObject:SetActive(false)
end
itemList[root][i]:OnOpen(false, data.BoxReward[i], 0.9,false,false,false,sortingOrder)
itemList[root][i].gameObject:SetActive(true)
end
if data.state==0 then
-- goText.text="已领取"
mask:GetComponent("Image").sprite = Util.LoadSprite("s_slbz_yilingqu_zh")
mask:SetActive(true)
goBtn:SetActive(false)
getBtn:SetActive(false)
elseif data.state==1 then
-- goText.text="领取"
mask:SetActive(false)
goBtn:SetActive(false)
getBtn:SetActive(true)
elseif data.state==2 then
-- goText.text="前往"
mask:SetActive(false)
goBtn:SetActive(true)
getBtn:SetActive(false)
end
Util.AddOnceClick(goBtn,function()
this:ClosePanel()
end)
Util.AddOnceClick(getBtn,function()
if getFunc then
getFunc(data.Id,function()
mask:SetActive(true)
getBtn:SetActive(false)
this.ChangeState(data.Id)
this.RefreshPanel(false,false)
end)
end
end)
end
--设置每条数据
function this.SetScrollPre2(root,data)
local info=Util.GetGameObject(root,"Title/Info"):GetComponent("Text")
local grid=Util.GetGameObject(root,"Grid")
local mask=Util.GetGameObject(root,"mask")
info.text = string.format(Language[12309],data.otherData.Sort,data.otherData.Values[1][1])
if not itemList[root] then
itemList[root] = {}
end
for k,v in ipairs(itemList[root]) do
v.gameObject:SetActive(false)
end
for i = 1 , #data.otherData.Reward do
if not itemList[root][i] then
itemList[root][i] = SubUIManager.Open(SubUIConfig.ItemView,grid.transform)
itemList[root][i].gameObject:SetActive(false)
end
itemList[root][i]:OnOpen(false, data.otherData.Reward[i], 0.9,false,false,false,sortingOrder)
itemList[root][i].gameObject:SetActive(true)
end
mask:SetActive(true)
if data.state==0 then
mask:GetComponent("Image").sprite = Util.LoadSprite("g_ghhb_weidacheng_zh")
elseif data.state==1 then
mask:GetComponent("Image").sprite = Util.LoadSprite("g_ghhb_yidacheng_zh")
end
end
function this.ChangeState(id)
for k,v in ipairs(rewardConfig) do
if v.Id == id then
v.state = 0
return
end
end
end
return TrialRewardPopup