234 lines
9.1 KiB
Lua
234 lines
9.1 KiB
Lua
----- 公会十绝阵奖励弹窗 -----
|
||
require("Base/BasePanel")
|
||
local DeathPosRewardPopup = Inherit(BasePanel)
|
||
local guildWarRewardConfig = ConfigManager.GetConfig(ConfigName.GuildWarRewardConfig)
|
||
local this = DeathPosRewardPopup
|
||
local itemViewList = {}
|
||
local tempData = {}
|
||
local itemList = {} --优化itemView使用
|
||
function DeathPosRewardPopup: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.scroll, "Pre")
|
||
this.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform,
|
||
this.pre, nil, Vector2.New(this.scroll.transform.rect.width, this.scroll.transform.rect.height), 1, 3,
|
||
Vector2.New(10, 5)) --生成滚动条,设置属性
|
||
--设置滚动条
|
||
this.scrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, 0)
|
||
this.scrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5)
|
||
this.scrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5)
|
||
this.scrollView.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5)
|
||
this.scrollView.moveTween.MomentumAmount = 1
|
||
this.scrollView.moveTween.Strength = 2
|
||
|
||
this.empty = Util.GetGameObject(this.panel, "Empty")
|
||
this.timeTip = Util.GetGameObject(this.panel, "TimeTip"):GetComponent("Text")
|
||
this.Tip = Util.GetGameObject(this.panel, "Bg/Tip"):GetComponent("Text")
|
||
this.rewardScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,
|
||
this.scroll.transform,
|
||
Util.GetGameObject(self.gameObject, "Panel/Scroll/RewardShowPre"), nil,
|
||
Vector2.New(this.scroll.transform.rect.width, this.scroll.transform.rect.height), 1, 1,
|
||
Vector2.New(10, 10))
|
||
this.rewardScrollView.moveTween.MomentumAmount = 1
|
||
this.rewardScrollView.moveTween.Strength = 1
|
||
end
|
||
|
||
function DeathPosRewardPopup:BindEvent()
|
||
Util.AddClick(this.backBtn, function()
|
||
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
|
||
self:ClosePanel()
|
||
end)
|
||
end
|
||
|
||
function DeathPosRewardPopup:AddListener()
|
||
Game.GlobalEvent:AddEvent(GameEvent.Guild.RefreshDeathPosStatus, this.RefreshPanel)
|
||
Game.GlobalEvent:AddEvent(GameEvent.Guild.RefreshDeathPosReward, this.SetIndicationData)
|
||
end
|
||
|
||
function DeathPosRewardPopup:RemoveListener()
|
||
Game.GlobalEvent:RemoveEvent(GameEvent.Guild.RefreshDeathPosStatus, this.RefreshPanel)
|
||
Game.GlobalEvent:RemoveEvent(GameEvent.Guild.RefreshDeathPosReward, this.SetIndicationData)
|
||
end
|
||
|
||
function DeathPosRewardPopup:OnOpen(...)
|
||
this.SetIndicationData()
|
||
end
|
||
|
||
function DeathPosRewardPopup:OnShow()
|
||
if DeathPosManager.status == DeathPosStatus.Close then
|
||
this:ClosePanel()
|
||
return
|
||
end
|
||
if DeathPosManager.status == DeathPosStatus.Fight then
|
||
return
|
||
end
|
||
this.empty:SetActive(false)
|
||
this.timeTip.gameObject:SetActive(DeathPosManager.status == DeathPosStatus.Reward)
|
||
NetManager.GetAllDeathPathRewardInfoResponse(function(msg)
|
||
DeathPosManager.SetRewardData(msg.info)
|
||
this.RefreshPanel(DeathPosManager.GetRewardData(), false)
|
||
end)
|
||
end
|
||
|
||
function DeathPosRewardPopup:OnClose()
|
||
tempData = {}
|
||
CheckRedPointStatus(RedPointType.Guild_DeathPos)
|
||
end
|
||
|
||
function DeathPosRewardPopup:OnDestroy()
|
||
this.spLoader:Destroy()
|
||
this.scrollView = nil
|
||
this.rewardScrollView = nil
|
||
itemList = {}
|
||
end
|
||
|
||
--其他玩家点击领取奖励的indication推送
|
||
function this.SetIndicationData()
|
||
local data = DeathPosManager.GetDoRewardData()
|
||
this.RefreshPanel(data, true)
|
||
end
|
||
|
||
--刷新面板 isI 是否是Indication推送
|
||
function this.RefreshPanel(data, isI)
|
||
LogRed("刷新面板")
|
||
this.timeTip.text = DeathPosManager.rewardTimeTip
|
||
if isI then --indication推送 只翻牌单一数据
|
||
for i = 1, #tempData do
|
||
if tempData[i].position == data.position then
|
||
tempData[i] = data
|
||
end
|
||
end
|
||
else --上来主动获取数据
|
||
for i = 1, #data do
|
||
Log("uid " ..
|
||
data[i].uid ..
|
||
" itemId " ..
|
||
data[i].itemId ..
|
||
" itemCount " .. data[i].itemCount .. " position " .. data[i].position ..
|
||
" username " .. data[i].username)
|
||
local isHave = false
|
||
for j = 1, #data do
|
||
if data[j].position > 0 and data[j].position == i then
|
||
-- if not data[j] then
|
||
isHave = true
|
||
table.insert(tempData, data[j])
|
||
-- end
|
||
end
|
||
end
|
||
if not isHave then
|
||
table.insert(tempData, { uid = 0, username = "", position = i })
|
||
end
|
||
end
|
||
end
|
||
DeathPosManager.SetMyRewardData(tempData)
|
||
this.scrollView:SetData(tempData, function(index, root)
|
||
this.SetScrollPre(root, tempData[index], index)
|
||
end)
|
||
this.scrollView:SetIndex(1)
|
||
this.empty:SetActive(false)
|
||
if #tempData <= 0 then
|
||
this.Tip.text = "宝箱在十绝阵结束后产生,每个成员根据名次可获得不同宝箱!"
|
||
this.rewardScrollView.gameObject:SetActive(true)
|
||
_guildWarRewardConfig = {}
|
||
for _, configInfo in ConfigPairs(guildWarRewardConfig) do
|
||
table.insert(_guildWarRewardConfig, configInfo)
|
||
end
|
||
this.rewardScrollView:SetData(_guildWarRewardConfig, function(index, go)
|
||
this.ActivityRewardSingleShow(go, _guildWarRewardConfig[index], index)
|
||
end)
|
||
else
|
||
this.Tip.text = "十绝阵已经结束,每个成员可开启1次宝箱,试试手气吧!"
|
||
this.rewardScrollView.gameObject:SetActive(false)
|
||
end
|
||
end
|
||
|
||
--排名奖励
|
||
function this.ActivityRewardSingleShow(activityRewardGo, rewardData, index)
|
||
local sortNumTabs = {}
|
||
for i = 1, 4 do
|
||
sortNumTabs[i] = Util.GetGameObject(activityRewardGo, "SortNum/SortNum (" .. i .. ")")
|
||
sortNumTabs[i]:SetActive(i == rewardData.Section or (i == 4 and rewardData.Section > 4))
|
||
end
|
||
if not itemList[activityRewardGo.name] then
|
||
itemList[activityRewardGo.name] = {}
|
||
end
|
||
for i = 1, #itemList[activityRewardGo.name] do
|
||
itemList[activityRewardGo.name][i].gameObject:SetActive(false)
|
||
end
|
||
for i = 1, #rewardData.Reward do
|
||
if itemList[activityRewardGo.name][i] then
|
||
itemList[activityRewardGo.name][i]:OnOpen(false, rewardData.Reward[i], 0.75, false, false, false,
|
||
sorting)
|
||
else
|
||
itemList[activityRewardGo.name][i] = SubUIManager.Open(SubUIConfig.ItemView,
|
||
Util.GetGameObject(activityRewardGo, "Grid").transform)
|
||
itemList[activityRewardGo.name][i]:OnOpen(false, rewardData.Reward[i], 0.75, true, false, false,
|
||
sorting)
|
||
end
|
||
itemList[activityRewardGo.name][i].gameObject:SetActive(true)
|
||
end
|
||
end
|
||
|
||
--设置每个预设
|
||
function this.SetScrollPre(root, data, index)
|
||
local itemRoot = Util.GetGameObject(root, "Root")
|
||
local lock = Util.GetGameObject(itemRoot, "Lock")
|
||
local name = Util.GetGameObject(root, "Name"):GetComponent("Text")
|
||
local btn = Util.GetGameObject(root, "Bg")
|
||
|
||
if data.username ~= "" then
|
||
LogBlue("uid " ..
|
||
data.uid ..
|
||
" itemId " ..
|
||
data.itemId .. " itemCount " .. data.itemCount .. " position " ..
|
||
data.position .. " username " .. data.username)
|
||
else
|
||
LogBlue("uid " .. data.uid .. " position " .. data.position .. " username " .. data.username)
|
||
end
|
||
lock:SetActive(data.username == "")
|
||
if data.username == "" then
|
||
name.text = Language[11461]
|
||
else
|
||
name.text = data.uid == PlayerManager.uid and "<color=#FF8345>" .. data.username .. "</color>" or
|
||
"<color=#FFBB62>" .. data.username .. "</color>"
|
||
end
|
||
name.text = data.username == "" and Language[11462] or data.username
|
||
btn:GetComponent("Button").interactable = data.username == ""
|
||
|
||
Util.AddOnceClick(btn, function()
|
||
if DeathPosManager.GetIsGeted(tempData) then
|
||
PopupTipPanel.ShowTip(Language[11463])
|
||
return
|
||
end
|
||
if DeathPosManager.GetIsTakeIn() == false then
|
||
PopupTipPanel.ShowTip(Language[11464])
|
||
return
|
||
end
|
||
NetManager.DoRewardDeathPathRequest(index, function(msg)
|
||
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function()
|
||
-- this.RefreshPanel()
|
||
LogRed("msg.drop" .. #msg.drop)
|
||
end)
|
||
end)
|
||
end)
|
||
if data.username == "" then
|
||
if itemViewList[root] then
|
||
itemViewList[root].gameObject:SetActive(false)
|
||
end
|
||
return
|
||
end
|
||
|
||
if not itemViewList[root] then
|
||
itemViewList[root] = SubUIManager.Open(SubUIConfig.ItemView, itemRoot.transform)
|
||
end
|
||
itemViewList[root]:OnOpen(false, { data.itemId, data.itemCount }, 1.1, false, false, false)
|
||
itemViewList[root].gameObject:SetActive(true)
|
||
if data.username then
|
||
name.text = data.username
|
||
end
|
||
end
|
||
|
||
return DeathPosRewardPopup
|