miduo_client/Assets/ManagedResources/~Lua/Modules/Explore/ExploreRewardPopup.lua

151 lines
5.0 KiB
Lua

require("Base/BasePanel")
local ExploreRewardPopup = Inherit(BasePanel)
local this = ExploreRewardPopup
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local _ProductList = {}
local _ItemList = {}
local _RewardList = {}
local _ExtraRewardList = {}
--初始化组件(用于子类重写)
function ExploreRewardPopup:InitComponent()
this.spLoader = SpriteLoader.New()
this.btnBack = Util.GetGameObject(this.transform, "mask")
this.rewardPre = Util.GetGameObject(this.transform, "showMopUp/reward")
this.itemRoot = Util.GetGameObject(this.transform, "showMopUp/scroller")
this.itemList = {}
end
--绑定事件(用于子类重写)
function ExploreRewardPopup:BindEvent()
Util.AddClick(this.btnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
this:ClosePanel()
end)
end
--添加事件监听(用于子类重写)
function ExploreRewardPopup:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Explore.UpdateFormation,this.OnShow)
end
--移除事件监听(用于子类重写)
function ExploreRewardPopup:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Explore.UpdateFormation,this.OnShow)
end
--界面打开时调用(用于子类重写)
function ExploreRewardPopup:OnOpen(mapId)
this.mapId = mapId
end
--
local orginLayer = -1
function this:OnSortingOrderChange()
-- Util.AddParticleSortLayer(this.privilegeEffect, this.sortingOrder - orginLayer)
orginLayer = this.sortingOrder
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function ExploreRewardPopup:OnShow()
this.data = ExploreManager.GetFormationDataByMapId(this.mapId)
if not this.data or #this.data < 1 then
this:ClosePanel()
return
end
local ishave = false
for k,v in ipairs(this.data) do
if #v.dropReward > 0 then
ishave = true
break
end
end
if not ishave then
PopupTipPanel.ShowTip("尚未获得探索奖励!")
this:ClosePanel()
return
end
for i = 1,math.max(#this.data,#this.itemList) do
if not this.data[i] then
this.itemList[i].go.gameObject:SetActive(false)
else
if not this.itemList[i] then
this.itemList[i] = {}
this.itemList[i].reward = {}
this.itemList[i].go = newObjToParent(this.rewardPre,this.itemRoot)
this.itemList[i].name = Util.GetGameObject(this.itemList[i].go, "name"):GetComponent("Text")
this.itemList[i].time = Util.GetGameObject(this.itemList[i].go, "time"):GetComponent("Text")
this.itemList[i].exploring = Util.GetGameObject(this.itemList[i].go, "exploring")
this.itemList[i].grid = Util.GetGameObject(this.itemList[i].go, "grid")
end
this:Refresh(this.itemList[i],this.data[i])
end
end
this:TimeCountDown()
end
function this:Refresh(_item,_data)
if _data.state == 0 then
_item.go.gameObject:SetActive(false)
else
_item.go.gameObject:SetActive(true)
end
_item.data = _data
_item.name.text = string.format("队伍%s",_data.index)
for i = 1,math.max(#_item.reward,#_data.dropReward) do
if not _data.dropReward[i] then
_item.reward[i].gameObject:SetActive(false)
else
if not _item.reward[i] then
_item.reward[i] = SubUIManager.Open(SubUIConfig.ItemView,_item.grid.transform)
end
_item.reward[i].gameObject:SetActive(true)
_item.reward[i]:OnOpen(false, {_data.dropReward[i].key,_data.dropReward[i].val},0.73,false,false,false,orginLayer)
end
end
Util.AddOnceClick(_item.exploring,function()
if _data.state > 0 then
NetManager.ExplorerMapRewardRequest(0,_data.formationId,function(drop)
UIManager.OpenPanel(UIName.RewardItemPopup,drop,1,function()
end)
end)
end
end)
end
function this:TimeCountDown()
if this.timer then
this.timer:Stop()
this.timer = nil
end
local s = function()
for i = 1,#this.itemList do
if this.itemList[i].data and this.itemList[i].data.state > 0 then
local time = this.itemList[i].data.exploreTime - GetTimeStamp()
if time < 0 then
this.itemList[i].data.state = 0
this.itemList[i].data.exploreTime = 0
this:Refresh(this.itemList[i],this.itemList[i].data)
else
this.itemList[i].time.text = string.format("%s后结束",TimeStampToDateStr3new(time))
end
end
end
end
s()
this.timer = Timer.New(s,1,-1,true)
this.timer:Start()
end
--界面关闭时调用(用于子类重写)
function ExploreRewardPopup:OnClose()
end
--界面销毁时调用(用于子类重写)
function ExploreRewardPopup:OnDestroy()
this.spLoader:Destroy()
this.itemList = {}
end
return ExploreRewardPopup