local UIGuildAlliesAlign = UIViewClass() local AlignStrategyID = 3 local NormalID = 1 ------------------------- 系统函数 -------------------------------- function UIGuildAlliesAlign:OnCreated() self:RegistSystemEvent(EventID.UI_GuildAlliesAlign_Refresh, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_Guild_GuildInfoRefresh, self.RefreshAllyInfo) UIUtils.SetLabelText(self.UICommonPopUpTab.txt_Title, Const_IDS["IDS_GuildAllies_Align"]) self.curGuildAllies = nil self.allySuccessRatio = 0 self.selectIndex = 1 self.selectGuildId = nil self.curAllyIndex = 0 self.isGuildsPanelOpen = false self:ResetSelectTarget() end function UIGuildAlliesAlign:OnOpened(context) self.curGuildAllies = context self:RefreshPanel() end function UIGuildAlliesAlign:OnUpdateFun(deltaTime, timeSinceUpdate) self:RefreshInfo() end function UIGuildAlliesAlign:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUpTab.btn_Close) end function UIGuildAlliesAlign:OnButtonClicked(comp) local targetData = MDL.GuildAllies.GetGuildAllyMemberByPos(self.selectIndex) if comp == self.UICommonPopUpTab.btn_Close then self:CloseView() elseif comp == self.ReactionSwitch then UIUtils.SetActive(self.group_Rank, false) self.isGuildsPanelOpen = not self.isGuildsPanelOpen elseif comp == self.group_Target.btn_Change then UIUtils.SetActive(self.group_Rank, not self.isGuildsPanelOpen) if not self.isGuildsPanelOpen then self.loop_Align_Rank:MoveIndex(self.selectIndex - 1) end self.isGuildsPanelOpen = not self.isGuildsPanelOpen elseif comp == self.btn_Align then if not CTL.GuildAllies.HasPermissionByTitle() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Guild_CommonFail4"]) return end --当要结盟的排名低于自己当前排名时提示 if not self:CheckTargetRank() then return end local guildAllies = DataSheetManager.GuildAlliesData:GetDataByID(MDL.GuildAllies.GetCurShowPowerID()) local isFirst = self.selectIndex == 1 and guildAllies.BigAllies == 1 --拥有首席盟友后,不能和其他人再成为首席盟友 if isFirst and CTL.GuildAllies.CheckHasFirstSeat() then return end local myGuildInfo = MDL.Guild.GetMyGuildInfo() local strategyCfg = DataSheetManager.GuildAlliesStrategy:GetDataByID_sortID(AlignStrategyID, NormalID) local isCD, cdStr = CTL.GuildAllies.GetAllyOprCDTimeState(self.curGuildAllies.allyOprCDTimeStamp) local isProtect, protectCDStr, protectStr = CTL.GuildAllies.GetAllyProtectTimeState(targetData.allyTime) if self.curGuildAllies.remainAllyOprCount <= 0 then CTL.Tips.AddTipsMsg(Const_IDS["IDS_GuildAllies_AlignDailyTimeLimit"], UIUtils.GetLocalizedTxt(Const_IDS[self.curGuildAllies.AlliesName])) return elseif myGuildInfo and myGuildInfo.goldIngot < strategyCfg.Cost_Table[1].CostItemNum then CTL.Sound.PlayGameSound("UI_invalid") local itemData = DataSheetManager.ItemData:GetDataByID(strategyCfg.Cost_Table[1].CostItemID) CTL.Tips.AddTipsMsg(Const_IDS["IDS_Guild_CommonFail1"], UIUtils.GetLocalizedTxt(Const_IDS[itemData.Name])) return elseif isCD then CTL.Tips.AddTipsMsg(cdStr) return elseif MDL.GuildAllies.GetCurAllyCount() >= CTL.GuildAllies.GetCurUnlockAllyPosCount() and not MDL.GuildAllies.IsMyAllyByPowerId(self.curGuildAllies.ID) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_GuildAllies_AlliesNumLimit"]) return elseif isProtect then CTL.Tips.AddTipsMsg(Const_IDS["IDS_GuildAllies_ProtectTimeTip"], protectStr) return end self.selectGuildId = targetData.guildId MDL.GuildAllies.RequestGuildAlliesAlly(self.curGuildAllies.ID, targetData.guildId, targetData.allyIndex, math.floor(self.allySuccessRatio * 100)) end end --检查目标排名,目标排名低于本势力排名时提示 function UIGuildAlliesAlign:CheckTargetRank() if self.selectIndex > MDL.GuildAllies.GetMyGuildMemberIndex() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_GuildAllies_TargerLowerRank"]) return false end return true end function UIGuildAlliesAlign:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Align_Rank then local targetData = MDL.GuildAllies.GetGuildAllyMemberByPos(self.selectIndex) CTL.GuildAllies.SetAllyPosImage(cellTable.img_Medal, data.allyIndex) UIUtils.SetLabel(cellTable.txt_FriendshipData, data.friendliness) CTL.GuildAllies.SetRankImage(cellTable.img_AllyQualityFrame, data.allyIndex) -- 保护中 local isProtect, cdStr = CTL.GuildAllies.GetAllyProtectTimeState(data.allyTime) if isProtect then UIUtils.SetLabel(cellTable.txt_TipInfo, cdStr) else UIUtils.SetLabelText(cellTable.txt_TipInfo, Const_IDS["IDS_GuildAllies_Target"]) end UIUtils.SetActive(cellTable.btn_LowRankDiscord, targetData.guildId ~= data.guildId and not isProtect) if CTL.GuildAllies.IsRobotGuild(data.guildId) then UIUtils.SetLabelText(cellTable.txt_GuildName, Const_IDS[data.guildName]) UIUtils.SetActive(cellTable.group_GuildInitiate, false) else UIUtils.SetActive(cellTable.group_GuildInitiate, true) UIUtils.SetLabel(cellTable.txt_GuildName, data.guildName) UIUtils.SetLabel(cellTable.txt_GuildInitiate, data.emblemContent) local _, guildEmblemCfg = DataSheetManager.GuildEmblem:TryGetDataByID(targetData.emblemFrame) if guildEmblemCfg then UTL.Item.SetAtlasSprite(cellTable.img_GuildIcon, "UI_Guild", guildEmblemCfg.Image) end end if self.curGuildAllies.State_Table[data.allyIndex] then UIUtils.SetActive(cellTable.group_Buff_1.gameObject, true) UIUtils.SetActive(cellTable.group_Buff_2.gameObject, true) UIUtils.SetActive(cellTable.group_Buff_Empty, false) CTL.GuildAllies.SetTextBuff(self.curGuildAllies.State_Table[data.allyIndex].StateAttr, cellTable.group_Buff_1.img_BuffIcon, cellTable.group_Buff_1.txt_BuffName, cellTable.group_Buff_1.txt_BuffNumber, cellTable.group_Buff_2.img_BuffIcon, cellTable.group_Buff_2.txt_BuffName, cellTable.group_Buff_2.txt_BuffNumber) else UIUtils.SetActive(cellTable.group_Buff_1.gameObject, false) UIUtils.SetActive(cellTable.group_Buff_2.gameObject, false) UIUtils.SetActive(cellTable.group_Buff_Empty, true) end end end function UIGuildAlliesAlign:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Align_Rank then if target == cellTable.btn_LowRankDiscord then local oldIndex = (self.curAllyIndex > 0 and self.selectIndex > self.curAllyIndex) and self.selectIndex - 2 or self.selectIndex - 1 self.selectIndex = (self.curAllyIndex > 0 and index + 1 >= self.curAllyIndex) and index + 2 or index + 1 --当要结盟的排名低于自己当前排名时提示 if not self:CheckTargetRank() then return end self.loop_Align_Rank:UpdateIndex(oldIndex) self.loop_Align_Rank:UpdateIndex((self.curAllyIndex > 0 and self.selectIndex > self.curAllyIndex) and self.selectIndex - 2 or self.selectIndex - 1) UIUtils.SetActive(self.group_Rank, false) self.isGuildsPanelOpen = not self.isGuildsPanelOpen self:RefreshTarget() end end end ------------------------------------------------------------------- function UIGuildAlliesAlign:RefreshPanel() UIUtils.SetLabel(self.txt_Number, self.curGuildAllies.friendliness) -- 选中目标 self:ResetSelectTarget() self:RefreshTarget() self:RefreshAllyInfo() self.loop_Align_Rank:ClearCells() local members = MDL.GuildAllies.GetGuildAllyMembers() local myMember = MDL.GuildAllies.GetMyGuildMember() for i, v in ipairs (MDL.GuildAllies.GetGuildAllyMembers()) do if v.allyIndex == 0 then break end if myMember and v.guildId ~= myMember.guildId then self.loop_Align_Rank:AddData(v, 0) else self.curAllyIndex = i end end UIUtils.SetActive(self.group_Rank, self.isGuildsPanelOpen) self:RefreshInfo(true) end function UIGuildAlliesAlign:RefreshAllyInfo() local strategyCfg = DataSheetManager.GuildAlliesStrategy:GetDataByID_sortID(AlignStrategyID, NormalID) CTL.GuildAllies.SetTextFriendlinessBenefit(self.txt_FriendshipNumber, strategyCfg) CTL.GuildAllies.SetTextFriendlinessLose(self.txt_LoseNumber, strategyCfg) CTL.GuildAllies.SetTextGuildMoneyForAlignPanel(self.txt_Money, strategyCfg.Cost_Table[1].CostItemID, strategyCfg.Cost_Table[1].CostItemNum) UTL.Item.ItemIconWithoutBg(self.img_MoneyIcon, strategyCfg.Cost_Table[1].CostItemID) end function UIGuildAlliesAlign:RefreshTarget() local targetData = MDL.GuildAllies.GetGuildAllyMemberByPos(self.selectIndex) local groupTarget = self.group_Target CTL.GuildAllies.SetAllyPosImage(groupTarget.img_medal, self.selectIndex) CTL.GuildAllies.SetAllyPosText(groupTarget.txt_GuildNum, self.selectIndex) CTL.GuildAllies.SetRankImage(groupTarget.img_GuildQualityFrame, self.selectIndex) UIUtils.SetLabel(groupTarget.txt_FriendshipData, targetData.friendliness) --大诸侯1号位显示首席 local guildAllies = DataSheetManager.GuildAlliesData:GetDataByID(MDL.GuildAllies.GetCurShowPowerID()) local isFirst = self.selectIndex == 1 and guildAllies.BigAllies == 1 UIUtils.SetActive(groupTarget.img_Chief,isFirst) if CTL.GuildAllies.IsRobotGuild(targetData.guildId) then UIUtils.SetLabelText(groupTarget.txt_GuildName, Const_IDS[targetData.guildName]) UIUtils.SetActive(groupTarget.group_GuildInitiate, false) else UIUtils.SetActive(groupTarget.group_GuildInitiate, true) UIUtils.SetLabel(groupTarget.txt_GuildName, targetData.guildName) UIUtils.SetLabel(groupTarget.txt_GuildInitiate, targetData.emblemContent) UTL.Item.SetAtlasSprite(groupTarget.img_GuildIcon, "UI_Guild", DataSheetManager.GuildEmblem:GetDataByID(targetData.emblemFrame).Image) end if self.curGuildAllies.State_Table[targetData.allyIndex] then UIUtils.SetActive(groupTarget.group_Buff_1.gameObject, true) UIUtils.SetActive(groupTarget.group_Buff_2.gameObject, true) UIUtils.SetActive(groupTarget.group_Buff_Empty, false) CTL.GuildAllies.SetTextBuff(self.curGuildAllies.State_Table[targetData.allyIndex].StateAttr, groupTarget.group_Buff_1.img_BuffIcon, groupTarget.group_Buff_1.txt_BuffName, groupTarget.group_Buff_1.txt_BuffNumber, groupTarget.group_Buff_2.img_BuffIcon, groupTarget.group_Buff_2.txt_BuffName, groupTarget.group_Buff_2.txt_BuffNumber) else UIUtils.SetActive(groupTarget.group_Buff_1.gameObject, false) UIUtils.SetActive(groupTarget.group_Buff_2.gameObject, false) UIUtils.SetActive(groupTarget.group_Buff_Empty, true) end self:RefreshSuccessfulRatio() end function UIGuildAlliesAlign:RefreshSuccessfulRatio() local myMember = MDL.GuildAllies.GetMyGuildMember() local myFriendliness = myMember and myMember.friendliness or 0 local targetData = MDL.GuildAllies.GetGuildAllyMemberByPos(self.selectIndex) local targetFriendliness = targetData.friendliness self.allySuccessRatio = CTL.GuildAllies.CalculateAlliesSuccessRatio(myFriendliness, targetFriendliness) UIUtils.SetLabel(self.txt_SuccessRate, string.FormatByIdsId(Const_IDS["IDS_GuildAllies_AlignSuccessRate"], math.floor(self.allySuccessRatio * 100))) end function UIGuildAlliesAlign:RefreshInfo(isStartUpdate) local isStartTimer = false local isCD, cdStr = CTL.GuildAllies.GetAllyOprCDTimeState(self.curGuildAllies.allyOprCDTimeStamp) if not isCD then UIUtils.SetLabel(self.txt_TipInfo, string.FormatByIdsId(Const_IDS["IDS_GuildAllies_DailyAlignNum"], self.curGuildAllies.remainAllyOprCount)) else UIUtils.SetLabel(self.txt_TipInfo, cdStr) isStartTimer = true end local myMember = MDL.GuildAllies.GetMyGuildMember() for i, v in ipairs (MDL.GuildAllies.GetGuildAllyMembers()) do if v.allyIndex == 0 then break end if myMember and v.guildId ~= myMember.guildId then local isProtect, cdStr = CTL.GuildAllies.GetAllyProtectTimeState(v.allyTime) if isProtect then self.loop_Align_Rank:RefreshCells() isStartTimer = true break end end end if isStartTimer then if isStartUpdate then self:StartRepeatFunc(self.OnUpdateFun, 1) end else self:StopRepeatFunc(self.OnUpdateFun) end end function UIGuildAlliesAlign:ResetSelectTarget() if self.selectGuildId then for i, v in ipairs (MDL.GuildAllies.GetGuildAllyMembers()) do if v.allyIndex == 0 then break end if v.guildId == self.selectGuildId then self.selectIndex = i self.selectGuildId = nil break end end if self.selectGuildId then self.selectGuildId = nil self:InitSelectTarget() end else self:InitSelectTarget() end end function UIGuildAlliesAlign:InitSelectTarget() self.selectIndex = 1 local target = MDL.GuildAllies.GetGuildAllyMemberByPos(self.selectIndex) local myMember = MDL.GuildAllies.GetMyGuildMember() if myMember and myMember.guildId == target.guildId then self.selectIndex = 2 end end return UIGuildAlliesAlign