239 lines
8.0 KiB
Lua
239 lines
8.0 KiB
Lua
----- 通用奖励领取弹窗 -----
|
||
require("Base/BasePanel")
|
||
local GeneralRewardPopup = Inherit(BasePanel)
|
||
local this = GeneralRewardPopup
|
||
local trialKillConfig=ConfigManager.GetConfig(ConfigName.TrialKillConfig)
|
||
local GodSacrificeConfig=ConfigManager.GetConfig(ConfigName.GodSacrificeConfig)
|
||
local ActivityRewardConfig = ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)
|
||
local itemList={} --预设容器
|
||
|
||
local curRewardType = 1
|
||
local ActivityType = nil
|
||
|
||
local ActInfo = {}
|
||
local ActReward = {}
|
||
local func
|
||
|
||
local sortingOrder=0
|
||
function GeneralRewardPopup:InitComponent()
|
||
this.spLoader = SpriteLoader.New()
|
||
this.panel=Util.GetGameObject(this.gameObject,"Panel")
|
||
this.backBtn=Util.GetGameObject(this.panel,"BackBtn")
|
||
|
||
this.scroll=Util.GetGameObject(this.panel,"Scroll")
|
||
this.pre=Util.GetGameObject(this.panel,"Scroll/Pre")
|
||
this.pre2=Util.GetGameObject(this.panel,"Scroll/Pre2")
|
||
this.scrollView1=SubUIManager.Open(SubUIConfig.ScrollCycleView,this.scroll.transform,this.pre, nil,
|
||
Vector2.New(this.scroll.transform.rect.width,this.scroll.transform.rect.height),1,1,Vector2.New(0,10))
|
||
this.scrollView1.gameObject:GetComponent("RectTransform").anchoredPosition= Vector2.New(0,0)
|
||
this.scrollView1.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5)
|
||
this.scrollView1.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5)
|
||
this.scrollView1.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5)
|
||
this.scrollView1.moveTween.MomentumAmount = 1
|
||
this.scrollView1.moveTween.Strength = 2
|
||
|
||
this.scrollView2=SubUIManager.Open(SubUIConfig.ScrollCycleView,this.scroll.transform,this.pre2, nil,
|
||
Vector2.New(this.scroll.transform.rect.width,this.scroll.transform.rect.height),1,1,Vector2.New(0,10))
|
||
this.scrollView2.gameObject:GetComponent("RectTransform").anchoredPosition= Vector2.New(0,0)
|
||
this.scrollView2.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5)
|
||
this.scrollView2.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5)
|
||
this.scrollView2.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5)
|
||
this.scrollView2.moveTween.MomentumAmount = 1
|
||
this.scrollView2.moveTween.Strength = 2
|
||
|
||
end
|
||
|
||
function GeneralRewardPopup:BindEvent()
|
||
Util.AddClick(this.backBtn,function()
|
||
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
|
||
DynamicActivityManager.SheJiCheckRedPoint()
|
||
self:ClosePanel()
|
||
end)
|
||
end
|
||
|
||
function GeneralRewardPopup:AddListener()
|
||
end
|
||
|
||
function GeneralRewardPopup:RemoveListener()
|
||
end
|
||
|
||
function GeneralRewardPopup:OnSortingOrderChange()
|
||
sortingOrder = self.sortingOrder
|
||
end
|
||
|
||
--rewardType==1 是一般奖励,配在ActivityRewardConfig中的,234567是配在特殊表里的
|
||
function GeneralRewardPopup:OnOpen(rewardType,activityType,activityId,_func)
|
||
curRewardType = rewardType
|
||
if rewardType == 1 then
|
||
ActivityType = activityType
|
||
ActInfo = ActivityGiftManager.GetActivityTypeInfo(activityType)--活动数据
|
||
ActReward = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig,"ActivityId",activityId)
|
||
elseif rewardType == 2 then
|
||
-- body
|
||
end
|
||
if _func then
|
||
func = _func
|
||
end
|
||
end
|
||
|
||
function GeneralRewardPopup:OnShow()
|
||
this.RefreshPanel(false,false)
|
||
end
|
||
|
||
function GeneralRewardPopup:OnClose()
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.DynamicTask.OnGetReward)
|
||
if func then
|
||
func()
|
||
func = nil
|
||
end
|
||
end
|
||
|
||
function GeneralRewardPopup:OnDestroy()
|
||
this.spLoader:Destroy()
|
||
this.scrollView=nil
|
||
itemList = {}
|
||
end
|
||
|
||
|
||
--刷新
|
||
function this.RefreshPanel(isTop,isAnim)
|
||
local d={}
|
||
|
||
if curRewardType == 1 then
|
||
d = ActReward
|
||
this.scrollView2:SetData(d,function(index,root)
|
||
this.SetScrollPre2(root,d[index])
|
||
end,isTop,isAnim)
|
||
this.scrollView2:SetIndex(1)
|
||
|
||
elseif curRewardType == 2 then
|
||
for _, configInfo in ConfigPairs(trialKillConfig) do
|
||
table.insert(d, configInfo)
|
||
end
|
||
this.scrollView1:SetData(d,function(index,root)
|
||
this.SetScrollPre1(root,d[index])
|
||
end,isTop,isAnim)
|
||
this.scrollView1:SetIndex(1)
|
||
end
|
||
end
|
||
|
||
function this.GetState(missionId)
|
||
for i = 1,#ActInfo.mission do
|
||
if ActInfo.mission[i].missionId == missionId then
|
||
return ActInfo.mission[i].state
|
||
end
|
||
end
|
||
return 0
|
||
end
|
||
|
||
--设置每条数据
|
||
function this.SetScrollPre2(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")
|
||
|
||
info.text = GetLanguageStrById(data.ContentsShow)
|
||
ResetItemView(root,grid.transform,itemList,#data.Reward,0.9,sortingOrder,false,data.Reward)
|
||
|
||
--按钮状态
|
||
local s = this.GetState(data.Id)
|
||
|
||
--社稷大典需要根据贡献等级重构state
|
||
if ActivityType == ActivityTypeDef.Celebration then
|
||
local level = DynamicActivityManager.curLevel
|
||
if s == 0 then
|
||
if data.Sort <= level then
|
||
s = 1
|
||
else
|
||
s = 2
|
||
end
|
||
else
|
||
s = 0
|
||
end
|
||
end
|
||
|
||
goBtn:GetComponent("Button").interactable=s~=0
|
||
if s==0 then
|
||
-- goText.text="已领取"
|
||
mask:GetComponent("Image").sprite = this.spLoader:LoadSprite("s_slbz_yilingqu_zh")
|
||
mask:SetActive(true)
|
||
goBtn:SetActive(false)
|
||
getBtn:SetActive(false)
|
||
elseif s==1 then
|
||
-- goText.text="领取"
|
||
mask:SetActive(false)
|
||
goBtn:SetActive(false)
|
||
getBtn:SetActive(true)
|
||
elseif s==2 then
|
||
-- goText.text="前往"
|
||
mask:SetActive(false)
|
||
goBtn:SetActive(true)
|
||
getBtn:SetActive(false)
|
||
end
|
||
|
||
Util.AddOnceClick(goBtn,function()
|
||
PopupTipPanel.ShowTip(Language[11482])
|
||
end)
|
||
Util.AddOnceClick(getBtn,function()
|
||
NetManager.GetActivityRewardRequest(data.Id, ActInfo.activityId, function(_drop)
|
||
UIManager.OpenPanel(UIName.RewardItemPopup, _drop, 1,function()
|
||
this.RefreshPanel(false,true)
|
||
CheckRedPointStatus(RedPointType.Celebration)
|
||
end)
|
||
end)
|
||
end)
|
||
end
|
||
|
||
|
||
--设置每条数据
|
||
function this.SetScrollPre1(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")
|
||
|
||
info.text=string.format( Language[11483],data.Count,MapTrialManager.GetKilCount(),data.Count)
|
||
ResetItemView(root,grid.transform,itemList,#data.BoxReward,0.9,sortingOrder,false,data.BoxReward)
|
||
|
||
--按钮状态
|
||
local s=MapTrialManager.GetTrialRewardState(data.Id)
|
||
goBtn:GetComponent("Button").interactable=s~=0
|
||
if s==0 then
|
||
-- goText.text="已领取"
|
||
mask:SetActive(true)
|
||
goBtn:SetActive(false)
|
||
getBtn:SetActive(false)
|
||
elseif s==1 then
|
||
-- goText.text="领取"
|
||
mask:SetActive(false)
|
||
goBtn:SetActive(false)
|
||
getBtn:SetActive(true)
|
||
elseif s==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()
|
||
NetManager.RequestLevelReward(data.Id, function(msg)
|
||
MapTrialManager.SetTrialRewardInfo(data.Id) --本地记录已领奖励信息
|
||
UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function()
|
||
mask:SetActive(true)
|
||
getBtn:SetActive(false)
|
||
this.RefreshPanel(false,true)
|
||
CheckRedPointStatus(RedPointType.TrialReward)
|
||
CheckRedPointStatus(RedPointType.Trial)
|
||
end)
|
||
end)
|
||
end)
|
||
end
|
||
|
||
|
||
return GeneralRewardPopup |