local UIGuildChangePositionPanel = UIViewClass() function UIGuildChangePositionPanel:OnOpened(context) self:RegistSystemEvent(EventID.UI_Guild_GuildInfoRefresh, self.ShowInfo) self:ShowInfo() UIUtils.SetLabelText(self.UICommonPopUp.txt_Title,Const_IDS.IDS_GuildChangeJob_PageTitle) end function UIGuildChangePositionPanel:ShowInfo() local target = nil self.members = {} local index = 1 for _, v in MDL.Guild.GetGuildMembersIterator(true) do table.insert(self.members, index, v) if v.roleInfo.acid == self.context.acid then target = v end index = index + 1 end for i = #self.members, index, -1 do table.remove(self.members, i) end self.target = target UIUtils.SetActive(self.group_IdentityGodless, target.roleInfo.sex ~= 1) self.event_Identity1:SetGray(false) self.event_Identity2:SetGray(false) self.Checkmark1.gameObject:SetActive(false) self.Checkmark1.gameObject:SetActive(false) self.lab_PlayerInfo.text = string.FormatByIdsId(Const_IDS.IDS_GuildChangeJob_Label1,target.roleInfo.name,MDL.Guild.GetMemberJobDesc(target)) self:SetIdentityStr(MDL.Guild.IdentityEnum.Warlord,self.txt_IdentityNum,self.event_Identity1) self:SetIdentityStr(MDL.Guild.IdentityEnum.Goddess,self.txt_IdentityGodlessNum,self.event_Identity2) self.Checkmark1.gameObject:SetActive(false) self.Checkmark2.gameObject:SetActive(false) for i,v in ipairs(target.identity) do if v == MDL.Guild.IdentityEnum.Warlord then self.Checkmark1.gameObject:SetActive(true) self.event_Identity1:SetGray(false) elseif v == MDL.Guild.IdentityEnum.Goddess then self.Checkmark2.gameObject:SetActive(true) self.event_Identity2:SetGray(false) end end self:InitToggles() for k,v in pairs(MDL.Guild.JobEnum) do if v ~=MDL.Guild.JobEnum.Leader then self:SetToggles(v) end end UIUtils.SetLabelText(self.txt_FightGod,Const_IDS.IDS_Guild_Warlord) UIUtils.SetLabelText(self.txt_Godless,Const_IDS.IDS_Guild_Goddess) end function UIGuildChangePositionPanel:InitToggles() self.jobKeyToToggle = {} self.jobKeyToToggle[MDL.Guild.JobEnum.RenshiElder] = self.toggles[1] self.jobKeyToToggle[MDL.Guild.JobEnum.NeishiElder] = self.toggles[2] self.jobKeyToToggle[MDL.Guild.JobEnum.JunshiElder] = self.toggles[3] self.jobKeyToToggle[MDL.Guild.JobEnum.Elite] = self.toggles[4] self.jobKeyToToggle[MDL.Guild.JobEnum.Common] = self.toggles[5] end function UIGuildChangePositionPanel:SetToggles(jobId) local count = 0 local isIn = false for i,v in ipairs(self.members) do if v.jobTitle == jobId then count = count + 1 end if v.jobTitle == jobId and self.context.acid == v.roleInfo.acid then isIn = true end end self.jobKeyToToggle[jobId].Checkmark.gameObject:SetActive(isIn) local jobData = DataSheetManager.GuildJob:GetDataByID(jobId) if MDL.Guild.JobEnum.Common == jobId then self.jobKeyToToggle[jobId].txt_PositionNum.text = count.."/"..self:GetMemberCount() else self.jobKeyToToggle[jobId].txt_PositionNum.text = count.."/"..jobData.Num end if isIn then self.jobKeyToToggle[jobId].Background:SetState(0) self.jobKeyToToggle[jobId].toggle_Position.interactable = false self.jobKeyToToggle[jobId].toggle_Position:SetGray(false) self.jobKeyToToggle[jobId].toggle_Position:SetGray(true, false) elseif count == jobData.Num then self.jobKeyToToggle[jobId].isMax = true self.jobKeyToToggle[jobId].Background:SetState(1) self.jobKeyToToggle[jobId].toggle_Position.interactable = true self.jobKeyToToggle[jobId].toggle_Position:SetGray(true, true) else self.jobKeyToToggle[jobId].isMax = false self.jobKeyToToggle[jobId].Background:SetState(0) self.jobKeyToToggle[jobId].toggle_Position.interactable = true self.jobKeyToToggle[jobId].toggle_Position:SetGray(false) end UIUtils.SetLabelText(self.jobKeyToToggle[jobId].txt_Position, Const_IDS[jobData.JobName]) end function UIGuildChangePositionPanel:SetIdentityStr(identity, label, toggle) local count = 0 for i,v in ipairs(self.members) do for _,id in ipairs(v.identity) do if id == identity then count = count + 1 end end end if count == 1 then if self.target.identity[1] ~= identity then toggle:SetGray(true,true) label.text = UTL.Color.FormatRedColor(count.."/"..1) else label.text = count.."/"..1 end else label.text = count.."/"..1 end end function UIGuildChangePositionPanel:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIGuildChangePositionPanel:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.event_Identity1 then self:AppointIdentity(MDL.Guild.IdentityEnum.Warlord) elseif comp == self.event_Identity2 then self:AppointIdentity(MDL.Guild.IdentityEnum.Goddess) else self:ClickToggles(comp) end end function UIGuildChangePositionPanel:AppointIdentity(identityId) if not MDL.Guild.JobHasPermission(MDL.Guild.GetMyGuildInfo().jobTitle,MDL.Guild.AuthorityEnum.GuildAppoint2) then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_OnlyLead) return end if self.target == nil or self.target.roleInfo == nil then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_1320_InfoCode_Guild_TargetNotInGuild) return end local exist = false for i,v in ipairs(self.target.identity) do if v == identityId then exist = true end end if exist then local name = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.GuildStatus:GetDataByID(identityId).JobName]) local str =string.FormatByIdsId(Const_IDS.IDS_GuildLeaderDismissConfirm_Label, self.target.roleInfo.name, name) UTL.MessageBox.ShowOKCancelBox(nil, str, function () MDL.Guild.GuildAppointIdentityReq(self.context.acid,identityId,true) end, nil) else for i,v in ipairs(self.members) do for _,id in ipairs(v.identity) do if id == identityId then exist = true end end end if exist then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_GuildJob_TargetJobMax) else local name = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.GuildStatus:GetDataByID(identityId).JobName]) local str =string.FormatByIdsId(Const_IDS.IDS_GuildChangeJobConfirm_Label, self.target.roleInfo.name, name) UTL.MessageBox.ShowOKCancelBox(nil, str, function () MDL.Guild.GuildAppointIdentityReq(self.context.acid,identityId) end, nil) end end end function UIGuildChangePositionPanel:ClickToggles( comp ) for i,v in ipairs(self.toggles) do if v.toggle_Position == comp then if i == 1 then self:ChangeJob(MDL.Guild.JobEnum.RenshiElder) elseif i == 2 then self:ChangeJob(MDL.Guild.JobEnum.NeishiElder) elseif i == 3 then self:ChangeJob(MDL.Guild.JobEnum.JunshiElder) elseif i == 4 then self:ChangeJob(MDL.Guild.JobEnum.Elite) elseif i == 5 then self:ChangeJob(MDL.Guild.JobEnum.Common) end end end end function UIGuildChangePositionPanel:ChangeJob(jobId) local jobData = DataSheetManager.GuildJob:GetDataByID(jobId) local myJobData = DataSheetManager.GuildJob:GetDataByID(MDL.Guild.GetMyGuildInfo().jobTitle) if self.jobKeyToToggle[jobId].isMax then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_GuildJob_TargetJobMax) elseif myJobData.Level == jobData.Level then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_OnlyLead) elseif self.target == nil or self.target.roleInfo == nil then CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_1320_InfoCode_Guild_TargetNotInGuild) else local str =string.FormatByIdsId(Const_IDS.IDS_GuildChangeJobConfirm_Label,self.target.roleInfo.name, UIUtils.GetLocalizedTxt(Const_IDS[jobData.JobName])) UTL.MessageBox.ShowOKCancelBox(nil, str, function () MDL.Guild.GuildAppointJobReq(self.context.acid,jobId) end, nil) end end function UIGuildChangePositionPanel:GetMemberCount() local count = 0 for i,v in ipairs(self.members) do if v.jobTitle ~= MDL.Guild.JobEnum.Common then count = count + 1 end end -- for _,d in DataSheetManager.GuildJob:GetEnumerator() do -- if d.ID ~= MDL.Guild.JobEnum.Common then -- count = count - d.Num -- end -- end return MDL.Guild.GetMaxMemberCount() - count end return UIGuildChangePositionPanel