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

151 lines
5.0 KiB
Lua
Raw Normal View History

2021-12-23 13:09:34 +08:00
require("Base/BasePanel")
2021-12-24 00:33:33 +08:00
local ExploreRewardPopup = Inherit(BasePanel)
local this = ExploreRewardPopup
2021-12-23 13:09:34 +08:00
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local _ProductList = {}
local _ItemList = {}
local _RewardList = {}
local _ExtraRewardList = {}
--初始化组件(用于子类重写)
2021-12-24 00:33:33 +08:00
function ExploreRewardPopup:InitComponent()
2021-12-23 13:09:34 +08:00
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
--绑定事件(用于子类重写)
2021-12-24 00:33:33 +08:00
function ExploreRewardPopup:BindEvent()
2021-12-23 13:09:34 +08:00
Util.AddClick(this.btnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
this:ClosePanel()
end)
end
--添加事件监听(用于子类重写)
2021-12-24 00:33:33 +08:00
function ExploreRewardPopup:AddListener()
2021-12-28 14:50:45 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Explore.UpdateFormation,this.OnShow)
2021-12-23 13:09:34 +08:00
end
--移除事件监听(用于子类重写)
2021-12-24 00:33:33 +08:00
function ExploreRewardPopup:RemoveListener()
2021-12-28 14:50:45 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.Explore.UpdateFormation,this.OnShow)
2021-12-23 13:09:34 +08:00
end
--界面打开时调用(用于子类重写)
2021-12-24 00:33:33 +08:00
function ExploreRewardPopup:OnOpen(mapId)
2021-12-23 13:09:34 +08:00
this.mapId = mapId
end
--
local orginLayer = -1
function this:OnSortingOrderChange()
-- Util.AddParticleSortLayer(this.privilegeEffect, this.sortingOrder - orginLayer)
orginLayer = this.sortingOrder
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
2021-12-24 00:33:33 +08:00
function ExploreRewardPopup:OnShow()
2021-12-23 13:09:34 +08:00
this.data = ExploreManager.GetFormationDataByMapId(this.mapId)
2021-12-28 14:50:45 +08:00
if not this.data or #this.data < 1 then
this:ClosePanel()
return
end
2021-12-24 09:37:31 +08:00
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("尚未获得探索奖励!")
2021-12-31 16:11:51 +08:00
this:ClosePanel()
2021-12-24 09:37:31 +08:00
return
end
2021-12-23 13:09:34 +08:00
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)
2021-12-23 17:23:02 +08:00
for i = 1,math.max(#_item.reward,#_data.dropReward) do
2021-12-23 13:09:34 +08:00
if not _data.dropReward[i] then
2021-12-23 17:23:02 +08:00
_item.reward[i].gameObject:SetActive(false)
2021-12-23 13:09:34 +08:00
else
2021-12-23 17:23:02 +08:00
if not _item.reward[i] then
_item.reward[i] = SubUIManager.Open(SubUIConfig.ItemView,_item.grid.transform)
2021-12-23 13:09:34 +08:00
end
2021-12-23 17:23:02 +08:00
_item.reward[i].gameObject:SetActive(true)
2021-12-28 17:52:28 +08:00
_item.reward[i]:OnOpen(false, {_data.dropReward[i].key,_data.dropReward[i].val},0.73,false,false,false,orginLayer)
2021-12-23 13:09:34 +08:00
end
end
Util.AddOnceClick(_item.exploring,function()
2021-12-28 14:50:45 +08:00
if _data.state > 0 then
NetManager.ExplorerMapRewardRequest(0,_data.formationId,function(drop)
UIManager.OpenPanel(UIName.RewardItemPopup,drop,1,function()
end)
end)
end
2021-12-23 13:09:34 +08:00
end)
end
function this:TimeCountDown()
if this.timer then
this.timer:Stop()
this.timer = nil
end
2021-12-28 14:50:45 +08:00
local s = function()
2021-12-23 13:09:34 +08:00
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
2021-12-28 14:50:45 +08:00
this.itemList[i].time.text = string.format("%s后结束",TimeStampToDateStr3new(time))
2021-12-23 13:09:34 +08:00
end
end
end
2021-12-28 14:50:45 +08:00
end
s()
this.timer = Timer.New(s,1,-1,true)
2021-12-23 13:09:34 +08:00
this.timer:Start()
end
--界面关闭时调用(用于子类重写)
2021-12-24 00:33:33 +08:00
function ExploreRewardPopup:OnClose()
2021-12-23 13:09:34 +08:00
end
--界面销毁时调用(用于子类重写)
2021-12-24 00:33:33 +08:00
function ExploreRewardPopup:OnDestroy()
2021-12-23 13:09:34 +08:00
this.spLoader:Destroy()
this.itemList = {}
end
2021-12-24 00:33:33 +08:00
return ExploreRewardPopup