local UICountryChangePosition = UIViewClass() function UICountryChangePosition:OnOpened(context) local acid = context.roleInfo.acid local jobId = MDL.Country.GetMyJobId() for i, v in DataSheetManager.CountryJob:GetEnumerator() do if MDL.Country.CanChangeJobById(jobId, v.ID) then self.loop_Position:AddData(v, 0) end end self:RegistSystemEvent(EventID.Country_OnCountrySetOfficial, self.OnCountrySetOfficial) self:InitDesc() UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_Guild_PlayerInfolistButton_ChangeJob) end function UICountryChangePosition:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() end end function UICountryChangePosition:InitDesc() local jobName = MDL.Country.GetJobColorName(self.context.roleInfo.CountryOfficial) self.lab_PlayerInfo.text = string.FormatByIdsId(Const_IDS.IDS_Country_ChangeOfficerIntro, self.context.roleInfo.name, jobName) end function UICountryChangePosition:OnCountrySetOfficial(changeInfo) local info = MDL.Country.GetOfficialInfo() local removeInfo = nil for i, v in ipairs(info.officialList) do if v.showInfo.acid == changeInfo.showInfo.acid then removeInfo = v table.remove(info.officialList, i) break end end table.insert(info.officialList, changeInfo) self.context.roleInfo.CountryOfficial = changeInfo.position self.loop_Position:RefreshCells() self:InitDesc() end function UICountryChangePosition:OnCellInit(scrollRect, index, cellTable, data) local countryID = MDL.Country.GetMyCountryId() UIUtils.SetLabelText(cellTable.txt_Position, Const_IDS[data.Title_Table[countryID].JobName]) cellTable.txt_Position.text = UIUtils.GetLocalizedTxt(Const_IDS[data.Title_Table[countryID].JobName]) UIUtils.SetActive(cellTable.Checkmark, data.ID == self.context.roleInfo.CountryOfficial) if data.ID == MDL.Country.CountryJob.CountryPopulace then UIUtils.SetLabelText(cellTable.txt_PositionNum, Const_IDS.IDS_Country_Nolimit) else local info = MDL.Country.GetOfficialInfo() local result = MDL.Country.GetCountryOfficial(info.officialList, data.ID) if #result == data.Num and data.ID ~= self.context.roleInfo.CountryOfficial then cellTable.txt_PositionNum.text = UTL.Color.FormatRedColor(#result).."/"..data.Num cellTable.toggle_Position:SetGray(true, true) else cellTable.txt_PositionNum.text = #result.."/"..data.Num cellTable.toggle_Position:SetGray(false) end end end function UICountryChangePosition:OnCellClicked(scrollRect, index, cellTable, target, data) if target == cellTable.toggle_Position then local info = MDL.Country.GetOfficialInfo() local result = MDL.Country.GetCountryOfficial(info.officialList, data.ID) if #result == data.Num then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Country_JobFull) else local roleInfo = self.context.roleInfo local jobName = MDL.Country.GetJobColorName(data.ID) local str = string.FormatByIdsId(Const_IDS.IDS_Country_AppointOfficerConfirm, CTL.CrossServer.GetServerShowStr(roleInfo.ShowServerId), roleInfo.name, jobName) local hasIndexs = {} for i = 1, data.Num do hasIndexs[i] = true end for i, v in ipairs(result) do hasIndexs[v.index + 1] = false end local firstIndex = 0 for i, v in ipairs(hasIndexs) do if v then firstIndex = i break end end UTL.MessageBox.ShowOKCancelBox("", str, function() MDL.Country.CountrySetOfficialReq(roleInfo.acid, data.ID, firstIndex - 1) end ) end end end return UICountryChangePosition