miduo_client/Assets/ManagedResources/~Lua/Modules/Guild/DeathPos/DeathPosRankPopup.lua

161 lines
5.5 KiB
Lua
Raw Normal View History

2020-05-09 13:31:21 +08:00
----- 公会十绝阵排行弹窗 -----
require("Base/BasePanel")
local DeathPosRankPopup = Inherit(BasePanel)
local this = DeathPosRankPopup
--标签按钮
local TabBox = require("Modules/Common/TabBox")
local _TabImgData = {select = "r_tongyong_xiaanniu_01", default = "r_tongyong_xiaanniu_02",}
local _TabFontColor = { default = Color.New(130 / 255, 128 / 255, 120 / 255, 1),
select = Color.New(243 / 255, 235 / 255, 202 / 255, 1) }
local _TabData = {
[1]= {txt = "公会排行"},
[2]= {txt = "个人排行"},
}
function DeathPosRankPopup:InitComponent()
this.panel=Util.GetGameObject(this.gameObject,"Panel")
this.backBtn=Util.GetGameObject(this.panel,"BackBtn")
this.tabbox = Util.GetGameObject(this.panel, "TabBox")
this.rankScroll=Util.GetGameObject(this.panel,"Scroll/Root")
this.rankPre=Util.GetGameObject(this.panel,"Scroll/Root/Pre")
this.scrollView=SubUIManager.Open(SubUIConfig.ScrollCycleView,this.rankScroll.transform,this.rankPre, nil,
Vector2.New(this.rankScroll.transform.rect.width,this.rankScroll.transform.rect.height),1,1,Vector2.New(0,10))
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.mRRank=Util.GetGameObject(this.panel,"Scroll/MyInfo")
this.mRSortNum=Util.GetGameObject(this.panel,"Scroll/MyInfo/SortNum")
this.mRName=Util.GetGameObject(this.panel,"Scroll/MyInfo/Grid/Name"):GetComponent("Text")
this.mRNum=Util.GetGameObject(this.panel,"Scroll/MyInfo/Grid/Num"):GetComponent("Text")
this.mRHurt=Util.GetGameObject(this.panel,"Scroll/MyInfo/Hurt"):GetComponent("Text")
end
function DeathPosRankPopup:BindEvent()
Util.AddClick(this.backBtn,function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
end
function DeathPosRankPopup:AddListener()
end
function DeathPosRankPopup:RemoveListener()
end
function DeathPosRankPopup:OnOpen(...)
end
function DeathPosRankPopup:OnShow()
this.TabCtrl = TabBox.New()
this.TabCtrl:SetTabAdapter(this.TabAdapter)
this.TabCtrl:SetChangeTabCallBack(this.OnTabChange)
this.TabCtrl:Init(this.tabbox, _TabData)
end
function DeathPosRankPopup:OnClose()
end
function DeathPosRankPopup:OnDestroy()
this.scrollView=nil
end
-- tab按钮自定义显示设置
function this.TabAdapter(tab, index, status)
local img = Util.GetGameObject(tab, "Image")
local txt = Util.GetGameObject(tab, "Text")
img:GetComponent("Image").sprite = Util.LoadSprite(_TabImgData[status])
txt:GetComponent("Text").text = _TabData[index].txt
txt:GetComponent("Text").color = _TabFontColor[status]
end
-- tab改变回调事件
function this.OnTabChange(index, lastIndex)
this.RefreshRank(index)
end
--刷新排行榜 index当前排行类型索引
function this.RefreshRank(index)
local curRankType=18 --默认公会排行
if index==1 then
curRankType=18 --公会排行
elseif index==2 then
curRankType=17 --个人排行
end
NetManager.RequestRankInfo(curRankType,function(msg)
this.scrollView:SetData(msg.ranks,function(index,root)
this.SetScrollPre(root,msg.ranks[index],curRankType)
end)
this.scrollView:SetIndex(1)
--当我的排名没数据时
this.mRSortNum:SetActive(msg.myRankInfo.rank~=-1)
this.mRNum.gameObject:SetActive(msg.myRankInfo.rank~=-1)
if msg.myRankInfo.rank==-1 then
this.mRName.text="未上榜"
this.mRHurt.text=""
return
end
this.SetMyRank(msg.myRankInfo,curRankType)
end)
end
--设置每条数据
function this.SetScrollPre(root,data,curRankType)
local name=Util.GetGameObject(root,"Grid/Name"):GetComponent("Text")
local num=Util.GetGameObject(root,"Grid/Num"):GetComponent("Text")
local hurt=Util.GetGameObject(root,"Hurt"):GetComponent("Text")
this.SetRankingNum(root,data.rankInfo.rank)
num.gameObject:SetActive(curRankType==18)
if curRankType==18 then
name.text=data.guildName--公会名称
num.text=data.rankInfo.param2 -- param2 挑战人数
elseif curRankType==17 then
name.text=data.userName
end
hurt.text= data.rankInfo.param1
end
--设置我的名次
function this.SetMyRank(data,curRankType)
local guildData = MyGuildManager.GetMyGuildInfo()
this.SetRankingNum(this.mRRank,data.rank)
this.mRNum.gameObject:SetActive(curRankType==18)
if curRankType==18 then
this.mRName.text=guildData.name
this.mRNum.text= data.param2 --param2 人数
elseif curRankType==17 then
this.mRName.text=PlayerManager.nickName
end
this.mRHurt.text=data.param1 --param1 伤害
end
--设置名次
function this.SetRankingNum(root,rank)
local sortNumTabs={}
for i = 1, 4 do
sortNumTabs[i]=Util.GetGameObject(root,"SortNum/SortNum ("..i..")")
sortNumTabs[i]:SetActive(false)
end
if rank < 4 then
sortNumTabs[rank]:SetActive(true)
else
sortNumTabs[4]:SetActive(true)
Util.GetGameObject(sortNumTabs[4], "TitleText"):GetComponent("Text").text = rank
end
end
return DeathPosRankPopup