local UIOfficialPositionMain = UIViewClass() local GRAY_COLOR = "fefefe" local GRAY_FONT_COLOR = "3C3C3C" local YELLOW_COLOR = "e8d588" local LOW_TITLE_COLOR = "aeb0b6" function UIOfficialPositionMain:OnOpened(context) self.profitInfoList ={} self.DownLevelInfo = {} --降品信息:文本、时间 self.examTimeTab = {} self.hasInit = false self:RegistSystemEvent(EventID.UI_RefreshOfficialPositionInfo, self.UpdateInfo) self:RegistSystemEvent(EventID.UI_UpdateOfficialPositionApplyInfo, self.UpdateExamInfo) self:RegistSystemEvent(EventID.UI_Solofight_RankSelfIndex_Refresh, self.UpdateRankSelfIndex) self:UpdateInfo() self:SelectHighest() self.hasInit = true end function UIOfficialPositionMain:SelectHighest() local selectIndex = 0 for i, v in DataSheetManager.OfficialPosition:GetEnumerator() do if v.ID == self.nextTitle then selectIndex = i - 1 break end end if selectIndex <= 1 then self.loopScroll_Icon:MoveBegin() elseif selectIndex >= self.loopScroll_Icon.Count - 3 then self.loopScroll_Icon:MoveEnd() else self.loopScroll_Icon:MoveIndex(selectIndex - 2) end self.loopScroll_Icon:SelectIndex(selectIndex, false) end function UIOfficialPositionMain:UpdateInfo() local titleInfo = MDL.OfficialPosition.GetOfficialInfo() local highestTitle = titleInfo.HighestTitle --历史最高官职 self.curTitle = titleInfo.CurTitle --当前官职 self.nextTitle = math.max(self.curTitle + 1, highestTitle) --居中显示的官职(历史最高或者下一个官职) local _, nextTitleData = DataSheetManager.OfficialPosition:TryGetDataByID(self.nextTitle) if nextTitleData == nil then --已达到最高阶 self.nextTitle = self.curTitle end for i, v in DataSheetManager.OfficialPosition:GetEnumerator() do if self.hasInit == true then self.loopScroll_Icon:UpdateIndex(i - 1, v) else self.loopScroll_Icon:AddData(v, 0) end end if self.selectCell and self.selectCellData then --可能降品后,选中不了原来最高的品阶 if self.selectCellData.ID <= self.nextTitle then self:SelectTitleCell(self.selectCell, self.selectCellData) else self:SelectHighest() end end --是否显示演武对决榜单按钮 if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.SoloFight) then UIUtils.SetActive(self.btn_Rank,true) MDL.SoloFight.SoloFightRankDetailsReq() else UIUtils.SetActive(self.btn_Rank,false) end end --阶段3 or 4,等报名信息返回再加载数据(报名阶段 or 已晋升阶段) function UIOfficialPositionMain:UpdateExamInfo() if self.selectCellData then self.loopScroll_FinishDetail:ClearCells() local pvpData = DataSheetManager.OfficialPositionPromotion:GetDataByGradeID(self.selectCellData.GradeID) --报名时间 local registerTime = UTL.Time.GetBeginAndEndTime(pvpData.Unlock_Table, YELLOW_COLOR) local content_1 = UTL.Color.FormatTextByColor(LOW_TITLE_COLOR,UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_RegistrationTime)) .. registerTime self.loopScroll_FinishDetail:AddData(content_1, 2) --考试时间 table.clearArray(self.examTimeTab) for _, v in pairs(pvpData.Unlock_Table) do table.insert(self.examTimeTab, v.ExaminationTime) end local examTime = UTL.Time.GetBeginAndEndTime(self.examTimeTab, YELLOW_COLOR) local content_2 = UTL.Color.FormatTextByColor(LOW_TITLE_COLOR,UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_ExaminationTime)) .. examTime self.loopScroll_FinishDetail:AddData(content_2, 2) --战队等级 local content_3 = UTL.Color.FormatTextByColor(LOW_TITLE_COLOR,UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_TeamLv)) local triggerData = DataSheetManager.TriggerID:GetDataByID(pvpData.TriggerID) local needLv = tonumber(triggerData.Unlock_Table[1].UnlockConditionParamA) local curLv = MDL.Player.GetRoleInfo() if curLv >= needLv then content_3 = content_3 .. UTL.Color.FormatGreenColor(string.FormatByIdsId(Const_IDS.IDS_OfficialPosition_Lv, needLv)) else content_3 = content_3 .. UTL.Color.FormatRedColor(string.FormatByIdsId(Const_IDS.IDS_OfficialPosition_Lv, needLv)) end self.loopScroll_FinishDetail:AddData(content_3, 2) --通关条件 self.loopScroll_FinishDetail:AddData(triggerData.Unlock_Table[2], 0) --报考人数 local content_4 = UTL.Color.FormatTextByColor(LOW_TITLE_COLOR,UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_ApplicantsNum)) local maxNum = pvpData.ApplicantsNum local curNum = MDL.OfficialPosition.ExamInfoList and #MDL.OfficialPosition.ExamInfoList or 0 if curNum >= maxNum then content_4 = content_4 .. UTL.Color.FormatRedColor(string.format("%s/%s", curNum, maxNum)) else content_4 = content_4 .. string.format("%s/%s", curNum, maxNum) end self.loopScroll_FinishDetail:AddData(content_4, 0) --考试方式 local content_5 = string.FormatByIdsId(Const_IDS.IDS_OfficialPosition_ExaminationMethod, pvpData.PromotionsNum) --考试方式 self.loopScroll_FinishDetail:AddData(content_5, 2) --是否已晋升 if self.curTitle >= self.selectCellData.ID then self.group_Btn:SetState(2) else --自己是否有报名 local hasApply = MDL.OfficialPosition.GetHasApply() if hasApply then self.group_Btn:SetState(1) else if MDL.Unlock.IsTriggerIdComplete(pvpData.TriggerID) == false then if CTL.OfficialPosition.NextTitleIsHighestTitle() then self.group_Btn:SetState(0) self.btn_GoPromotion:SetGray(true) UIUtils.SetLabel(self.txt_GoPromotion, UTL.Color.FormatTextByColor(GRAY_FONT_COLOR, UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_SignUp))) else self.group_Btn:SetState(4) end else if CTL.OfficialPosition.NextTitleIsHighestTitle() then self.group_Btn:SetState(0) self.btn_GoPromotion:SetGray(false) UIUtils.SetLabelText(self.txt_GoPromotion, Const_IDS.IDS_OfficialPosition_SignUp) else self.group_Btn:SetState(3) end end end end end end function UIOfficialPositionMain:UpdateRankSelfIndex(index) if self.selectCellData then self.loopScroll_FinishDetail:ClearCells() local rankIndex = index local pvpData = DataSheetManager.OfficialPositionPromotion:GetDataByGradeID(self.selectCellData.GradeID) --降品时间 local timeFormat = UTL.Color.FormatRedColor(" ({0}:{1}:{2})") local degradationTime = UTL.Time.GetBeginAndEndTime(pvpData.DegradationTime, YELLOW_COLOR) self.DownLevelInfo.Content = UTL.Color.FormatTextByColor(LOW_TITLE_COLOR, UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_TimeOfProductDegradation)) .. degradationTime .. timeFormat local leftTime = 0 for _, v in ipairs(pvpData.DegradationTime) do local offsetTime = UTL.Time.GetServerIntervalNextTimeByTimeId(v) if leftTime == 0 then leftTime = offsetTime else if leftTime > offsetTime then leftTime = offsetTime end end end --降品倒计时 self.DownLevelInfo.Time = leftTime self.loopScroll_FinishDetail:AddData(self.DownLevelInfo, 2) --降品条件 local content_2 if pvpData.DegradationNum == 0 then --全员降品 content_2 = UTL.Color.FormatTextByColor(LOW_TITLE_COLOR,UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_ConditionOfQualityReduction1)) .. UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_Everyone) else content_2 = UTL.Color.FormatTextByColor(LOW_TITLE_COLOR,UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_ConditionOfQualityReduction1)) .. string.FormatByIdsId(Const_IDS.IDS_OfficialPosition_ConditionOfQualityReduction2, UTL.Color.FormatTextByColor(YELLOW_COLOR,pvpData.DegradationNum)) end self.loopScroll_FinishDetail:AddData(content_2, 2) self.DownLevelInfo.Content = UTL.Color.FormatTextByColor(LOW_TITLE_COLOR,UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_CurrentRanking1)) .. string.FormatByIdsId(Const_IDS.IDS_OfficialPosition_CurrentRanking2, UTL.Color.FormatTextByColor(YELLOW_COLOR,rankIndex)) self.DownLevelInfo.Flag = rankIndex > pvpData.DegradationNum self.loopScroll_FinishDetail:AddData(self.DownLevelInfo, 1) end end function UIOfficialPositionMain:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loopScroll_Icon then UIUtils.SetImageByAssetBundle(cellTable.img_Icon, data.OfficialHat) UTL.Color.SetQualityImageByType(cellTable.img_Bg, data.QualityColor, UTL.Color.QualityType.OfficialPositionQuality) UIUtils.SetActive(cellTable.img_BgRenZhi, data.ID == self.curTitle) if self.nextTitle >= data.ID then UIUtils.SetGray(cellTable.img_Bg, false) UIUtils.SetGray(cellTable.img_Icon, false) UIUtils.SetLabel(cellTable.txt_Pinjie, UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[data.Name1]), data.QualityColor)) else --不可点击 UIUtils.SetGray(cellTable.img_Bg, true) UIUtils.SetGray(cellTable.img_Icon, true) UIUtils.SetLabel(cellTable.txt_Pinjie, UTL.Color.FormatTextByColor(GRAY_COLOR, UIUtils.GetLocalizedTxt(Const_IDS[data.Name1]))) end if self.selectIndex == index then UIUtils.SetActive(cellTable.img_IconSelect, true) else UIUtils.SetActive(cellTable.img_IconSelect, false) end elseif scrollRect == self.loopScroll_FinishDetail then local type = self.selectCellData.Type if type == 1 then local titleInfo = MDL.OfficialPosition.GetOfficialInfo() local isFinish = (titleInfo and titleInfo.FinishDetail) and titleInfo.FinishDetail[data.UnlockCondition] or false if self.curTitle >= self.selectCellData.ID or isFinish then UIUtils.SetLabel(cellTable.txt_Attr01, MDL.Unlock.GetDesByTriggerID(data, true)) cellTable.state:SetState(2) --完成 else UIUtils.SetLabel(cellTable.txt_Attr01, MDL.Unlock.GetDesByTriggerID(data, false)) --是否显示前往按钮 if data.ItemSourceID ~= 0 then cellTable.state:SetState(0) else cellTable.state:SetState(3) end end elseif type == 2 then --推荐战力 local recommendFight = data.Recommend local fightStr = CTL.LevelSelect.GetSubjugateGsText(data.SubjugateDataPVE, recommendFight) local monsterData = DataSheetManager.MonsterData:GetDataByID(data.MonsterlID) local txt = string.FormatByIdsId(Const_IDS.IDS_OfficialPosition_PVE, UIUtils.GetLocalizedTxt(Const_IDS[monsterData.MonsterNameIDS]), fightStr) UIUtils.SetLabel(cellTable.txt_Attr01, txt) if self.curTitle >= self.selectCellData.ID then cellTable.state:SetState(2) --完成 else cellTable.state:SetState(3) end elseif type == 3 then self:SetType3CellData(cellTable, data, index) elseif type == 4 then local pvpData = DataSheetManager.OfficialPositionPromotion:GetDataByGradeID(self.selectCellData.GradeID) if self.selectCellData.ID == self.curTitle and pvpData.DegradationNum ~= -1 then if index == 0 then cellTable.txt_Attr03:ResetAndBeginCustomTimer(false, UTL.Time.GetTimeFormatTimeZone(data.Time), 0, data.Content, 1) elseif index == 2 then UIUtils.SetLabel(cellTable.txt_Attr02, data.Content) UIUtils.SetActive(cellTable.img_Down, data.Flag) else cellTable.txt_Attr03:EndTimer() cellTable.txt_Attr03:SetCDLabel(data) end else self:SetType3CellData(cellTable, data, index) end end end end function UIOfficialPositionMain:SetType3CellData(cellTable, data, index) if index == 3 then local isUnlock = MDL.Unlock.IsTriggerComplete(data.UnlockCondition, nil, data.UnlockConditionParamA) UIUtils.SetLabel(cellTable.txt_Attr01, MDL.Unlock.GetDesByTriggerID(data, isUnlock)) --是否显示前往按钮 if isUnlock then cellTable.state:SetState(3) else if data.ItemSourceID ~= 0 then cellTable.state:SetState(0) else cellTable.state:SetState(3) end end elseif index == 4 then --第3个cell带按钮 UIUtils.SetLabel(cellTable.txt_Attr01, data) cellTable.state:SetState(1) else cellTable.txt_Attr03:EndTimer() cellTable.txt_Attr03:SetCDLabel(data) end end function UIOfficialPositionMain:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loopScroll_Icon then --点击无反馈 if self.nextTitle < data.ID then return end if self.selectIndex == index and self.hasInit == true then return end self.selectIndex = index self:SelectTitleCell(cellTable, data) elseif scrollRect == self.loopScroll_FinishDetail then if target == cellTable.btn_Go then CTL.ItemSources.ExecuteSourceFunctionById(data.ItemSourceID) elseif target == cellTable.btn_Chakan then --查看报名情况 CTL.OfficialPosition.OpenApplyList(self.selectCellData.ID) end end end function UIOfficialPositionMain:SelectTitleCell(cellTable, cellData) if self.selectCell ~= nil then UIUtils.SetActive(self.selectCell.img_IconSelect, false) end self.selectCell = cellTable self.selectCellData = cellData UIUtils.SetActive(cellTable.img_IconSelect, true) UIUtils.SetImageByAssetBundle(self.img_Icon, cellData.OfficialHat) --称号显示 UTL.Color.SetTitleFrame(cellData.TitleFrame, self.lab_ChenghaoName, self.img_Chenghao) if GameAppInfo.IsVietnamPackage() then self.lab_ChenghaoName.text = CTL.OfficialPosition.GetTitleFullTxtMainVN(cellData) else self.lab_ChenghaoName.text = CTL.OfficialPosition.GetTitleFullTxt(cellData) end --显示属性 local attrData = DataSheetManager.OfficialPositionAttr:GetDataByAttrRepeatID(cellData.OfficialPositionAttr) for i = 1, #attrData.Attr_Table do UTL.Attr.SetAttrItem(self.group_Attr[i], attrData.Attr_Table[i].AttrType, UTL.Color.FormatGreenColor("+" .. attrData.Attr_Table[i].AttrNum), false) end --道具奖励 local rewardConfig = DataSheetManager.OfficialRankingReward:GetDataByID(cellData.Reward) local itemDatas = rewardConfig.Item_Table self.highestTitle = MDL.OfficialPosition.GetOfficialInfo().HighestTitle for i, itemData in ipairs(itemDatas) do local contentItem = self.group_Item[i] if not contentItem then contentItem = self:InstantiateCollection(self.group_Item, self.templateItem.gameObject) if GameAppInfo.IsVersionGreaterThan16000() then self:InitUITemplate(contentItem.baseItem, contentItem.gameObject) end end UIUtils.SetActive(contentItem.gameObject, true) UIUtils.SetActive(contentItem.group_Get, self.highestTitle >= cellData.ID) UTL.Item.SetItemCell(contentItem.baseItem, itemData.ItemID, itemData.ItemNum) end for i = #itemDatas + 1, #self.group_Item do UIUtils.SetActive(self.group_Item[i].gameObject, false) end --收益 CTL.OfficialPosition.UpdateProfitList(cellData.GradeID, self.profitInfoList) self:UpdateProfit(self.profitInfoList, cellData.QualityColor) --Info UIUtils.SetLabelText(self.lab_BaseAttr,Const_IDS.IDS_OfficialPosition_PromotionConditions) self.btn_GoPromotion:SetRedPoint(false) local type = cellData.Type if type == 1 then self.loopScroll_FinishDetail:ClearCells() local guideData = DataSheetManager.OfficialPositionGuide:GetDataByGradeID(cellData.GradeID) local triggerData = DataSheetManager.TriggerID:GetDataByID(guideData.TriggerID) for _, v in ipairs(triggerData.Unlock_Table) do self.loopScroll_FinishDetail:AddData(v, 0) end if self.curTitle >= cellData.ID then self.group_Btn:SetState(2) else self.group_Btn:SetState(0) local isFinish = CTL.OfficialPosition.IsNextTitleUnlock() if isFinish then self.btn_GoPromotion:SetGray(false) UIUtils.SetLabelText(self.txt_GoPromotion, Const_IDS.IDS_OfficialPosition_GoPromotion) self.btn_GoPromotion:SetRedPoint(true) else self.btn_GoPromotion:SetGray(true) UIUtils.SetLabel(self.txt_GoPromotion, UTL.Color.FormatTextByColor(GRAY_FONT_COLOR, UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPosition_GoPromotion))) end end elseif type == 2 then self.loopScroll_FinishDetail:ClearCells() local pveData = DataSheetManager.OfficialPositionPVE:GetDataByGradeID(cellData.GradeID) self.loopScroll_FinishDetail:AddData(pveData, 0) if self.curTitle >= cellData.ID then self.group_Btn:SetState(2) else self.group_Btn:SetState(0) self.btn_GoPromotion:SetGray(false) UIUtils.SetLabelText(self.txt_GoPromotion, Const_IDS.IDS_OfficialPosition_GoPromotion) local hasEnoughPower = CTL.OfficialPosition.GetHasEnoughPower(cellData) self.btn_GoPromotion:SetRedPoint(hasEnoughPower) end elseif type == 3 then --报名人数需要请求服务器,统一在协议返回后处理显示 MDL.OfficialPosition.GetExamInfoReq(cellData.ID) else local pvpData = DataSheetManager.OfficialPositionPromotion:GetDataByGradeID(cellData.GradeID) --已晋升 if cellData.ID == self.curTitle and pvpData.DegradationNum ~= -1 then --当前名次(降品标识),需要请求服务器 MDL.SoloFight.SoloRankSelfInfosReq() --演武校场入口 self.group_Btn:SetState(0) self.btn_GoPromotion:SetGray(false) UIUtils.SetLabelText(self.txt_GoPromotion, Const_IDS.IDS_OfficialPosition_GoPvp) UIUtils.SetLabelText(self.lab_BaseAttr, Const_IDS.IDS_OfficialPosition_RulesOfQualityReduction) else --显示晋升条件,跟类型3一致 MDL.OfficialPosition.GetExamInfoReq(cellData.ID) end end UIUtils.SetActive(self.btn_PromotionList, type >= 3) end function UIOfficialPositionMain:OnButtonClicked(comp) if comp == self.btn_GoPromotion then local data = self.selectCellData if data then if data.Type <= 2 then --晋升 CTL.OfficialPosition.GoToPromotionOrExam(data) UIManager.CloseView(Const_UI_Lua.UIEnum.UIOfficialPositionBase) UIManager.RecoverView() else if self.curTitle >= self.selectCellData.ID then --演武校场 CTL.SoloFight.OpenSoloFightView() else --报名 local ret, reason = CTL.OfficialPosition.CheckCanExam(data.GradeID) if ret == false then CTL.Sound.PlayGameSound("UI_invalid") if reason then CTL.Tips.AddTipsMsg(reason) end else CTL.OfficialPosition.SetCurrentOfficialPositionOfExam(data.ID) CTL.OfficialPosition.GoToPromotionOrExam(data) UIManager.CloseView(Const_UI_Lua.UIEnum.UIOfficialPositionBase) UIManager.RecoverView() end end end end elseif comp == self.btn_Reward then CTL.OfficialPosition.ShowProfitPreview() elseif comp == self.rect_CloseTips then UIUtils.SetActive(self.rect_CloseTips, false) UIUtils.SetActive(self.group_Tip, false) elseif comp == self.btn_PromotionList then CTL.OfficialPosition.OpenRankLast() elseif comp == self.btn_Rank then --打开演武对决榜单 CTL.OfficialPosition.OpenSoloRank() else for i = 1, #self.group_Profits do if comp == self.group_Profits[i].rect_btn then self:OnClickProfitTips(i) return end end for i, v in ipairs(self.group_Item) do if comp == v.baseItem.event_Click then local rewardConfig = DataSheetManager.OfficialRankingReward:GetDataByID(self.selectCellData.Reward) local itemDatas = rewardConfig.Item_Table UTL.ItemTips.ShowCommonTipsById(itemDatas[i].ItemID) return end end end end function UIOfficialPositionMain:OnClickProfitTips(i) UIUtils.SetActive(self.rect_CloseTips, true) UIUtils.SetActive(self.group_Tip, true) local info = self.profitInfoList[i] self.txt_Tip.text = string.FormatByIdsId(Const_IDS[info.IDS], info.Parm) end function UIOfficialPositionMain:UpdateProfit(infoList, quality) for i, v in ipairs(self.group_Profits) do if i > #infoList then UIUtils.SetActive(v.gameObject, false) else UIUtils.SetActive(v.gameObject, true) local info = infoList[i] UIUtils.SetImageByAssetBundle(v.img_Icon, info.Icon) UTL.Color.SetQualityImageByType(v.img_qua, quality, UTL.Color.QualityType.OfficialProfitQuality) end end end function UIOfficialPositionMain:OnClosed() self.selectCell = nil self.selectCellData = nil end return UIOfficialPositionMain