local UICommandTheWorldHonorRollPanel = UIViewClass() local MaxShowCount = 3 --region 生命周期方法 function UICommandTheWorldHonorRollPanel:OnCreated() self.playerComponents = { [1] = {obj = self.Hero_Num1,txtName = self.txt_Num1,txtRank = self.txt_Num1Rank,btnBox = self.btn_Box1,stateBox = self.state_Box1,effect = self.effect_Available1}, [2] = {obj = self.Hero_Num2,txtName = self.txt_Num2,txtRank = self.txt_Num2Rank,btnBox = self.btn_Box2,stateBox = self.state_Box2,effect = self.effect_Available2}, [3] = {obj = self.Hero_Num3,txtName = self.txt_Num3,txtRank = self.txt_Num3Rank,btnBox = self.btn_Box3,stateBox = self.state_Box3,effect = self.effect_Available3}, } end function UICommandTheWorldHonorRollPanel:OnOpened(context) UIManager.ActiveUIModle(false, "UICommandTheWorldHonorRollPanel") self:RegistSystemEvent(EventID.UI_CommandTheWorld_RefreshHonorRollPanel, self.InitData) --刷新荣耀榜界面 self:RegistSystemEvent(EventID.UI_CommandTheWorld_RefreshHonorRollReward, self.RefreshGetRewardState) --单刷领取显示 self:RegistSystemEvent(EventID.UI_CommandTheWorld_EndAndCloseActivity,self.EndAndCloseActivity) --关闭活动 --标题 UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title,Const_IDS.IDS_BattlefieldMuster_Title) UIUtils.SetLabel(self.lab_Title,string.FormatByIdsId(Const_IDS.IDS_BattlefieldMuster_HonorRanking,"S."..tostring(MDL.Login.GetServerShowId()))) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info,false) --活动时间 local startTime= MDL.CommandTheWorld.GetActivityBeginTime() local startTimeMonth,startTimeDay,startTimeHourMinute = UTL.Time.FormatTimeSimple(startTime) local endTime = MDL.CommandTheWorld.GetActivityEndTime() local endTimeMonth,endTimeDay,endTimeHourMinute = UTL.Time.FormatTimeSimple(endTime) if GameAppInfo.IsVietnamPackage() then UIUtils.SetLabel(self.txt_Time, os.date(UTL.Time.FormatDateEnum.MDHM, startTime).."-"..os.date(UTL.Time.FormatDateEnum.MDHM, endTime)) else UIUtils.SetLabel(self.txt_Time,string.FormatByIdsId(Const_IDS.IDS_BattlefieldMuster_Time,tostring(startTimeMonth),tostring(startTimeDay),tostring(startTimeHourMinute),tostring(endTimeMonth),tostring(endTimeDay),tostring(endTimeHourMinute))) end self:InitData() end function UICommandTheWorldHonorRollPanel:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UICommandTheWorldHonorRollPanel:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Shop then --活动店铺 if not CTL.CommandTheWorld.IsActivityEnd() then if not self:CheckCanClick() then return end UIManager.OpenView(Const_UI_Lua.UIEnum.UICommandTheWorldWindow,{popWindowType = CTL.CommandTheWorld.PopWindowType.Store}) else self:CloseView(true) end elseif comp == self.btn_Rank then --排行奖励 if not self:CheckCanClick() then return end self:OnClickRankReward() elseif comp == self.btn_Box1 then --领取奖励 if not self:CheckCanClick() then return end self:OnClickBox(1) elseif comp == self.btn_Box2 then --领取奖励 if not self:CheckCanClick() then return end self:OnClickBox(2) elseif comp == self.btn_Box3 then --领取奖励 if not self:CheckCanClick() then return end self:OnClickBox(3) end end --荣誉榜没开启时,提示 function UICommandTheWorldHonorRollPanel:CheckCanClick() if CTL.CommandTheWorld.IsBeforeHonourOpen() then CTL.Tips.AddTipsMsg(Const_IDS.IDS_BattlefieldMuster_InSettlement) return false end return true end function UICommandTheWorldHonorRollPanel:OnClosed() self:ResetHeroShow() UIManager.ActiveUIModle(true, "UICommandTheWorldHonorRollPanel") UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) end --endregion function UICommandTheWorldHonorRollPanel:InitData() --结算等待阶段,显示结算中提示 if CTL.CommandTheWorld.IsBalanceWait() then UIUtils.SetLabelText(self.txt_Tip,Const_IDS.IDS_BattlefieldMuster_InSettlement) UIUtils.SetActive(self.img_Tips,true) else UIUtils.SetActive(self.img_Tips,false) end --先隐藏展示 for i = 1, MaxShowCount do UIUtils.SetActive(self.playerComponents[i].obj,false) end self.rankIndexArray = {} --显示战区荣誉榜 local rankData = MDL.CommandTheWorld.GetHonorRankData() if rankData and IsServerDataNotNil(rankData.honorRecordInfos) then self.localServerRankData = self:SetRankData(rankData.honorRecordInfos) --本服进入战区榜的玩家榜单数据 --显示提示 if #self.localServerRankData >=1 then self.state_Info:SetState(1) else self.state_Info:SetState(0) end --显示进入榜中的玩家形象和信息 if #self.localServerRankData >0 then self.heroList = {} self.HeroShow:EnterTeamMemberShow() for i,v in ipairs(self.localServerRankData) do if i <= MaxShowCount then UIUtils.SetActive(self.playerComponents[i].obj,true) UIUtils.SetLabel(self.playerComponents[i].txtName,v.showInfo.name) UIUtils.SetLabel(self.playerComponents[i].txtRank,string.FormatByIdsId(Const_IDS.IDS_BattlefieldMuster_WarZoneRank,v.rankIndex)) self.rankIndexArray[i] = v.rankIndex self.playerComponents[i].stateBox:SetState(v.hasClaimed and 1 or 0) if v.hasClaimed then self.playerComponents[i].effect:StopUIEffect() else self.playerComponents[i].effect:PlayUIEffect() end self:RefreshHeroShowInfo(v.showInfo,i) end end self.HasLoadHero = true self:ReSetHeroPos() self:SetSceneBg() end else self:OnlyShowScene() self.state_Info:SetState(0) end end --因为原组件逻辑从左到右是012,而这里的需求从左至右是213,所以需要转换 function UICommandTheWorldHonorRollPanel:GetHeroShowIndex(index) if index == 1 then return 1 elseif index ==2 then return 0 else return 2 end end function UICommandTheWorldHonorRollPanel:OnlyShowScene() self.HeroShow:EnterTeamMemberShow() self:SetSceneBg() end function UICommandTheWorldHonorRollPanel:SetSceneBg() --先换一下背景,方法很绕,因为C#没提供接口 local trans= self.HeroShow:GetHeroModelTransform(1) self.blackPlaneTrans = trans.parent.parent:Find("BlackPlane") UIUtils.SetActive(self.blackPlaneTrans,false) self.blackPlaneTrans2 = trans.parent.parent:Find("BlackPlane2") UIUtils.SetActive(self.blackPlaneTrans2,true) --设置新背景大小,保持一样的分辨率 self.blackPlaneTrans2:SetLocalScale(self.blackPlaneTrans:GetLocalScale()) --需要整体左移一下 self.oldHeroParentPosX,self.oldHeroParentPosY,self.oldHeroParentPosZ = trans.parent:GetLocalPosition() trans.parent:SetLocalPosition(0.62,self.oldHeroParentPosY,self.oldHeroParentPosZ) end function UICommandTheWorldHonorRollPanel:ResetHeroShow() if self.blackPlaneTrans and self.blackPlaneTrans2 then UIUtils.SetActive(self.blackPlaneTrans2,false) UIUtils.SetActive(self.blackPlaneTrans,true) end if self.oldHeroParentPosX then local trans= self.HeroShow:GetHeroModelTransform(1) trans.parent:SetLocalPosition(self.oldHeroParentPosX,self.oldHeroParentPosY,self.oldHeroParentPosZ) end end --显示展示的模型 function UICommandTheWorldHonorRollPanel:RefreshHeroShowInfo(showInfo,index) if IsServerDataNotNil(showInfo) then --主将重复加载 会有问题,也没必要重复加载了 if not self.HasLoadHero then self.HeroShow:LoadTeamMemberModel(UTL.UIRender.LoadCommandTheWorldHonorHero(showInfo, index)) local transOld = self.HeroShow:GetHeroModelTransform(index - 1) local hero = transOld:GetChild(0) table.insert(self.heroList,hero) end else self.HeroShow:DisposeTeamMemberModel(index - 1) end end --需要对英雄的位置重新摆放 function UICommandTheWorldHonorRollPanel:ReSetHeroPos() if #self.heroList > 0 then for i = 1, #self.heroList do local transNew= self.HeroShow:GetHeroModelTransform(self:GetHeroShowIndex(i)) local hero = self.heroList[i] hero:SetParent(transNew) hero:SetLocalPosition(0,0,0) end end end --刷新领取奖励的状态 function UICommandTheWorldHonorRollPanel:RefreshGetRewardState() local rankData = MDL.CommandTheWorld.GetHonorRankData() if rankData then self.localServerRankData = self:SetRankData(rankData.honorRecordInfos) --本服进入战区榜的玩家榜单数据 if #self.localServerRankData > 0 then for i,v in ipairs(self.localServerRankData) do if i <= MaxShowCount then self.playerComponents[i].stateBox:SetState(v.hasClaimed and 1 or 0) if v.hasClaimed then self.playerComponents[i].effect:StopUIEffect() else self.playerComponents[i].effect:PlayUIEffect() end end end end end end function UICommandTheWorldHonorRollPanel:SetRankData(honorRecordInfos) local localServerRankData = {} if #honorRecordInfos > 0 then for i,v in ipairs(honorRecordInfos) do table.insert(localServerRankData,v) end table.sort(localServerRankData,self.SortRankData) end return localServerRankData end function UICommandTheWorldHonorRollPanel.SortRankData(a,b) return a.rankIndex < b.rankIndex end --点击排行奖励 function UICommandTheWorldHonorRollPanel:OnClickRankReward() UIManager.OpenView(Const_UI_Lua.UIEnum.UICommandTheWorldWindow,{popWindowType = CTL.CommandTheWorld.PopWindowType.Rank}) end --领取荣誉榜奖励 function UICommandTheWorldHonorRollPanel:OnClickBox(index) --先检测是否领取过,如果领过无反馈 for i,v in ipairs(self.localServerRankData) do if i == index then if v.hasClaimed then return end end end CTL.Sound.PlayGameSound("UI_click_03") --没领取过,发请求 MDL.CommandTheWorld.ClaimCommandWorldHonorTreasureReq(self.rankIndexArray[index]) end function UICommandTheWorldHonorRollPanel:EndAndCloseActivity() self:CloseView(true) end return UICommandTheWorldHonorRollPanel