miduo_client/Assets/ManagedResources/~Lua/Modules/NewShenZun/ActivityChongRank.lua

375 lines
14 KiB
Lua

require("Base/BasePanel")
ActivityChongRank = Inherit(BasePanel)
local TabBox = require("Modules/Common/TabBox")
local this=ActivityChongRank
local infoConfig=ConfigManager.GetConfig(ConfigName.ChongRankInfo)
local rankConfig=ConfigManager.GetConfig(ConfigName.ChongRank)
local curConfig=nil
local type=0
local btnType=0
local rankType=0
local ownRank=0
local isFirst=false
local _TabData={ [1] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "排行榜"},
[2] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "排名奖励"},
}
function this:InitComponent()
this.spLoader = SpriteLoader.New()
this.backBtn=Util.GetGameObject(self.gameObject, "bg/btn_close")
this.titleImg=Util.GetGameObject(self.gameObject, "bg/name"):GetComponent("Image")
this.leftTimeTxt=Util.GetGameObject(self.gameObject, "bg/Image/timebg"):GetComponent("Text")
this.grid=Util.GetGameObject(self.gameObject, "bg/tabScroll/grid")
this.btnItem=Util.GetGameObject(self.gameObject, "bg/tabBtnPre")
this.rewardItem=Util.GetGameObject(self.gameObject, "bg/Rank")
this.rankItem=Util.GetGameObject(self.gameObject, "bg/Rank2")
this.selectObj=Util.GetGameObject(self.gameObject, "bg/tabSelectBtn")
this.infoTxt=Util.GetGameObject(self.gameObject, "bg/title/infoTxt"):GetComponent("Text")
this.rewardGrid=Util.GetGameObject(self.gameObject, "bg/rewardGrid")
this.rankGrid=Util.GetGameObject(self.gameObject, "bg/rankGrid")
this.selectTxt=Util.GetGameObject(self.gameObject, "bg/tabSelectBtn/Text"):GetComponent("Text")
this.tabBox=Util.GetGameObject(self.gameObject, "bg/TabBox")
this.btn_help=Util.GetGameObject(self.gameObject, "bg/btn_help")
local rootHight = this.rewardGrid.transform.rect.height
local width = this.rewardGrid.transform.rect.width
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.rewardGrid.transform,this.rewardItem, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0,0))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 2
this.ScrollView.elastic = false
--local rootHight2 = this.rankGrid.transform.rect.height
--local width2 = this.rankGrid.transform.rect.width
this.rankScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.rankGrid.transform,this.rankItem, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0,0))
this.rankScrollView.moveTween.MomentumAmount = 1
this.rankScrollView.moveTween.Strength = 2
this.rankScrollView.elastic = false
this.actData = CommonActPageManager.GetData(ActivityTypeDef.KaiFuChongBang)
this.btnList={}
for _, configInfo in ConfigPairs(infoConfig) do
local tabBtn = newObjToParent(this.btnItem, this.grid)
Util.GetGameObject(tabBtn, "Text"):GetComponent("Text").text=configInfo.RankName
local openTime=this.actData.startTime+configInfo.OpenTime
local closeTime=this.actData.startTime+configInfo.CloseTime
if GetTimeStamp()>=openTime and GetTimeStamp()<=closeTime then --活动未开启
curConfig=configInfo
isFirst=true
end
table.insert(this.btnList,tabBtn)
Util.AddClick(tabBtn,function ()
btnType=_
this.TabBtnOnClick(configInfo,tabBtn)
end)
end
--显示货币
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
this.itemList = {}
end
local qaId=0
function this:OnShow()
PlayerPrefs.SetInt(PlayerManager.uid.."kaifuchongbang",1)
end
function this.TabBtnOnClick(config,btn)
this.selectObj.transform:SetParent(btn.transform)
this.selectObj.transform.localScale = Vector3.one
this.selectObj.transform.localPosition = Vector3.zero
this.selectTxt.text=config.RankName
qaId=config.QAConfig
--设置时间
if this.timer then
this.timer:Stop()
this.timer = nil
end
local time=0
local openTime=this.actData.startTime+config.OpenTime
local closeTime=this.actData.startTime+config.CloseTime
local state=0
if openTime>GetTimeStamp() then --活动未开启
time =openTime - GetTimeStamp()
state=1
elseif closeTime>GetTimeStamp() then --活动进行中
time=closeTime-GetTimeStamp()
state=2
elseif closeTime<GetTimeStamp() then
time=0
state=3
end
if state==1 then
this.leftTimeTxt.text = string.format("活动开始倒计时:".."%s",TimeToFelaxible(time))
elseif state==2 then
this.leftTimeTxt.text = string.format(Language[10512].."%s",TimeToFelaxible(time))
elseif state==3 then
this.leftTimeTxt.text = "活动已结束"
end
if time~=0 then
this.timer = Timer.New(function ()
time = time - 1
if state==1 then
this.leftTimeTxt.text = string.format("活动开始倒计时:".."%s",TimeToFelaxible(time))
elseif state==2 then
this.leftTimeTxt.text = string.format(Language[10512].."%s",TimeToFelaxible(time))
elseif state==3 then
this.leftTimeTxt.text = "活动已结束"
end
if time <= 0 and state~=3 then
--this:OnClose()
state=3
this.ChangeWindow(config)
end
end,1,-1,true)
this.timer:Start()
end
this.ChangeWindow(config)
end
function this.ChangeWindow(config)
this.titleImg.sprite=this.spLoader:LoadSprite(config.Icon)
curConfig=config
RankingManager.InitData(config.RankType,function()
rankType=config.RankType
LogError("ranktype=="..rankType)
local ranks,myRank = RankingManager.GetRankingInfo()
ownRank=myRank.rank
LogError("ranks len======="..#ranks)
--this.SetRoleRank(ranks,myRank,true,true)
if type==1 then
this.rewardGrid:SetActive(false)
this.rankGrid:SetActive(true)
this.infoTxt.text="玩家信息"
-- RankingManager.InitData(config.RankType,function()
-- rankType=config.RankType
-- LogError("ranktype=="..rankType)
-- local ranks,myRank = RankingManager.GetRankingInfo()
-- ownRank=myRank.rank
-- LogError("ranks len======="..#ranks)
this.SetRoleRank(ranks,myRank,true,true)
-- end,0,1)
elseif type==2 then
local list={}
this.rewardGrid:SetActive(true)
this.rankGrid:SetActive(false)
this.infoTxt.text="奖励"
for _, configInfo in ConfigPairs(rankConfig) do
if configInfo.ChongRankInfoID==config.Id then
table.insert(list,configInfo)
end
end
this.ScrollView:SetData(list, function (index, go)
this.UpdateRewardInfo(go,list[index])
end,false)
end
end,0,1)
end
function this:BindEvent()
Util.AddClick(this.backBtn,function ()
self:ClosePanel()
end)
Util.AddClick(this.btn_help,function ()
UIManager.OpenPanel(UIName.HelpPopup,qaId,this.btn_help.transform.localPosition.x,this.btn_help.transform.localPosition.y)
end)
this.TabCtrl = TabBox.New()
this.TabCtrl:SetTabAdapter(this.TabAdapter)
this.TabCtrl:SetChangeTabCallBack(this.SwitchView)
this.TabCtrl:Init(this.tabBox, _TabData)
end
-- tab节点显示自定义
function this.TabAdapter(tab, index, status)
local tabLab = Util.GetGameObject(tab, "Text")
Util.GetGameObject(tab,"Image"):GetComponent("Image").sprite = this.spLoader:LoadSprite(_TabData[index][status])
tabLab:GetComponent("Text").text = _TabData[index].name
--tabLab:GetComponent("Text").color = _TabFontColor[status]
end
--切换视图
function this.SwitchView(index)
type=index
if curConfig==nil then
curConfig=infoConfig[1]
this.TabBtnOnClick(curConfig,this.btnList[1])
return
end
if isFirst then
this.TabBtnOnClick(curConfig,this.btnList[curConfig.Id])
return
end
this.ChangeWindow(curConfig)
end
function this.UpdateRewardInfo(go,data)
local sortNumTabs = {}
for i = 1, 4 do
sortNumTabs[i] = Util.GetGameObject(go, "sortNum/sortNum ("..i..")")
sortNumTabs[i]:SetActive(false)
end
local reward = Util.GetGameObject(go,"reward")
local sort4Text = Util.GetGameObject(sortNumTabs[4],"rankNumberText"):GetComponent("Text")
local hintObj=Util.GetGameObject(go,"hint")
if ownRank and ownRank>=data.MinRank and ownRank<=data.MaxRank then
hintObj:SetActive(true)
else
hintObj:SetActive(false)
end
if data.MinRank == data.MaxRank then
if data.MaxRank < 4 then
sortNumTabs[data.MinRank]:SetActive(true)
else
sortNumTabs[4]:SetActive(true)
sort4Text.text = data.MaxRank
end
else
sortNumTabs[4]:SetActive(true)
if data.MaxRank < 0 then
sort4Text.text = data.MinRank .."+"
else
sort4Text.text = data.MinRank .."-".. data.MaxRank
end
end
if not this.itemList[go] then
this.itemList[go] = {}
end
for i = 1, #data.RankingReward do
if not this.itemList[go][i] then
this.itemList[go][i] = SubUIManager.Open(SubUIConfig.ItemView,reward.transform)
end
this.itemList[go][i]:OnOpen(false, data.RankingReward[i], 0.8,false,false,false,this.sortingOrder)
end
end
-- 设置玩家排行
function this.SetRoleRank(ranks,myRankInfo, isTop, isAnim )
--if #ranks == 0 or not ranks then Log(Language[10267]) return end
local rankFunc = function (index, item)
this.UpdateRankInfo(item, ranks[index], myRankInfo.rank)
if index==#ranks then
RankingManager.RequestNextWarPowerPageData(function()
local ranks,myRank = RankingManager.GetRankingInfo()
--this.SetPlayerRankInfo(ranks,myRank)
this.SetRoleRank(ranks,myRank)
end)
end
end
-- -- 重置排行列表
this.rankScrollView:SetData(ranks, rankFunc, not isTop, not isAnim )
end
local _PlayerHeadList = {}
function this.UpdateRankInfo(go,data)
local sortNumTabs = {}
for i = 1, 4 do
sortNumTabs[i] = Util.GetGameObject(go, "sortNum/sortNum ("..i..")")
sortNumTabs[i]:SetActive(false)
end
local sort4Text = Util.GetGameObject(sortNumTabs[4],"rankNumberText"):GetComponent("Text")
if data.rankInfo.rank<4 then
sort4Text.gameObject:SetActive(false)
sortNumTabs[data.rankInfo.rank]:SetActive(true)
else
sort4Text.gameObject:SetActive(true)
sortNumTabs[4]:SetActive(true)
sort4Text.text=data.rankInfo.rank
end
local head=Util.GetGameObject(go, "head")
local nameTxt=Util.GetGameObject(go, "nameTxt"):GetComponent("Text")
local warPower = Util.GetGameObject(go,"warPower")
local infoTxt = Util.GetGameObject(go,"numTxt"):GetComponent("Text")
local starImg = Util.GetGameObject(go,"starImg")
local selfObj=Util.GetGameObject(go,"slefBG")
selfObj:SetActive(data.rankInfo.rank==ownRank)
warPower:SetActive(false)
infoTxt.gameObject:SetActive(false)
starImg:SetActive(false)
nameTxt.text=data.userName
if not _PlayerHeadList[go] then
_PlayerHeadList[go] = SubUIManager.Open(SubUIConfig.PlayerHeadView, head.transform)
end
_PlayerHeadList[go]:Reset()
_PlayerHeadList[go]:SetHead(data.head)
_PlayerHeadList[go]:SetFrame(data.headFrame)
_PlayerHeadList[go]:SetLevel(data.level)
_PlayerHeadList[go]:SetScale(Vector3.one*0.7)
_PlayerHeadList[go]:SetLayer(this.sortingOrder)
_PlayerHeadList[go]:SetEffectScale(0.75)
if rankType==RANK_TYPE.FORCE_CURR_RANK then --战力排行
warPower:SetActive(true)
Util.GetGameObject(go,"warPower/Text"):SetActive(true)
Util.GetGameObject(go,"warPower/Text"):GetComponent("Text").text = data.rankInfo.param1
elseif rankType==RANK_TYPE.FIGHT_LEVEL_RANK then --关卡排行
infoTxt.gameObject:SetActive(true)
infoTxt.text=GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.MainLevelConfig,data.rankInfo.param1).Name)
elseif rankType==RANK_TYPE.MONSTER_RANK then --心魔试炼
infoTxt.gameObject:SetActive(true)
infoTxt.text=Language[11689].. data.rankInfo.param1
elseif rankType==RANK_TYPE.FIGHTLEVEL_STAR or rankType==RANK_TYPE.UpStar then --山河社稷图 升星排行
starImg:SetActive(true)
infoTxt.gameObject:SetActive(true)
infoTxt.text= data.rankInfo.param1
elseif rankType==RANK_TYPE.EquipRank then
infoTxt.gameObject:SetActive(true)
infoTxt.text="装备:"..data.rankInfo.param1
elseif rankType==RANK_TYPE.SoulSign then
infoTxt.gameObject:SetActive(true)
infoTxt.text="魂印:"..data.rankInfo.param1
end
Util.AddOnceClick(go,function()
UIManager.OpenPanel(UIName.PlayerInfoPopup, data.uid,PLAYER_INFO_VIEW_TYPE.MIND_DEMON)
end)
end
function this:OnOpen(data)
--this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.ShenZun})
end
--添加事件监听(用于子类重写)
function this:AddListener()
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
end
function this.UpdateTopInfo()
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
if self.timer then
self.timer:Stop()
self.timer = nil
end
CheckRedPointStatus(RedPointType.KaiFuChongBang)
end
function this:OnDestroy()
this.spLoader:Destroy()
if self.timer then
self.timer:Stop()
self.timer = nil
end
curConfig=nil
SubUIManager.Close(this.ScrollView)
SubUIManager.Close(this.rankScrollView)
end
return this