local UIAchievementShare = UIViewClass() local EventSystem = require('Event/EventSystem') local chat_pb = require("Proto/chat_pb") local chatTimeLimit = 0.5 --私聊时间限制 local TitleStr = "【%s】" ------------------------------- 系统函数 ---------------------------- function UIAchievementShare:OnOpened(context) if not context then return end UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_Achievement_Share_Title) self.content = UIUtils.GetLocalizedTxt(Const_IDS["IDS_Achievement_Share_SendItem"]) self.achievementId = context.configData.ID self.ChatTimeStamp = UTL.Time.GetServerTimestamp() self.searchTxt = nil self:UpdateFriendList() end function UIAchievementShare:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_AchieventLevel then CTL.Character.SetPortraitAndFrame(cellTable.UIHeroHead150, data.portraitId, data.frameId, data.level, data.acid) UIUtils.SetLabel(cellTable.txt_Name, data.name) UIUtils.SetActive(cellTable.group_Online, data.isOnline) UIUtils.SetActive(cellTable.group_Offline, not data.isOnline) end end function UIAchievementShare:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_AchieventLevel then if target == cellTable.btn_Share then self:ShareAchievementItem(data.acid, true) end end end function UIAchievementShare:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIAchievementShare:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Search then self:UpdateFriendList() elseif comp == self.btn_World then self:ShareAchievementItem(MDL.ChannelChat.ChannelCfgId.World) elseif comp == self.btn_Team then if CTL.Team.IsInTeam() then self:ShareAchievementItem(MDL.ChannelChat.ChannelCfgId.Team) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Achievement_Share_NoTeam"]) end elseif comp == self.btn_Guild then if MDL.Guild.IsHasGuild() then self:ShareAchievementItem(MDL.ChannelChat.ChannelCfgId.Legion) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Achievement_Share_NoGuild"]) end elseif comp == self.btn_Now then self:ShareAchievementItem(MDL.ChannelChat.ChannelCfgId.Current) end end ---------------------------------------------------------------------- function UIAchievementShare:ShareAchievementItem(channelID, isSendPrivate) if not isSendPrivate then if MDL.ChannelChat.CanSendMsg() then local channelName = UIUtils.GetLocalizedTxt(Const_IDS["IDS_CHAT_Name_1_World"]) if channelID == MDL.ChannelChat.ChannelCfgId.Team then channelName = UIUtils.GetLocalizedTxt(Const_IDS["IDS_CHAT_Name_3_Team"]) elseif channelID == MDL.ChannelChat.ChannelCfgId.Legion then channelName = UIUtils.GetLocalizedTxt(Const_IDS["IDS_CHAT_Name_2_Guild"]) elseif channelID == MDL.ChannelChat.ChannelCfgId.Current then channelName = UIUtils.GetLocalizedTxt(Const_IDS["IDS_CHAT_Name_5_Current"]) end local errorCode, leftTime = CTL.ChannelChat.CheckCanSendTextMsg(self.content, MDL.ChannelChat.GetChannelIdByCfgID(channelID), chat_pb.Room) if errorCode == CTL.ChannelChat.ErrorCode.Success then MDL.ChannelChat.SendAchievementMsg(MDL.ChannelChat.GetChannelIdByCfgID(channelID), chat_pb.Room, self.content, BattleDataGetter.GetPlayerName(), self.achievementId, "IDS_Achievement_Share_SendItem") CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS["IDS_Achievement_Share_Tip_Chat"], channelName)) self:CloseView() else CTL.ChannelChat.ProcessError(errorCode,leftTime) end end else if MDL.ChannelChat.CanSendPrivateMsg() and (UTL.Time.GetServerTimestamp() - self.ChatTimeStamp >= chatTimeLimit) then MDL.ChannelChat.SendAchievementMsg(channelID, chat_pb.Personal, self.content, BattleDataGetter.GetPlayerName(), self.achievementId, "IDS_Achievement_Share_SendItem") self.ChatTimeStamp = UTL.Time.GetServerTimestamp() CTL.Tips.AddTipsMsg(Const_IDS["IDS_Achievement_Share_Tip_Friend"]) self:CloseView() end end end function UIAchievementShare:UpdateFriendList() if self.searchTxt == nil or self.obj_InputField.text ~= self.searchTxt then self.loop_AchieventLevel:ClearCells() local friends = MDL.Friend.GetSortedList(MDL.Friend.ListType.Friend) self.hasFriend = #friends > 0 if friends and self.hasFriend then for _, v in ipairs (friends) do if not string.isNilOrEmpty(self.obj_InputField.text) then if v.name == self.obj_InputField.text then self.loop_AchieventLevel:AddData(v, 0) end else self.loop_AchieventLevel:AddData(v, 0) end end end UIUtils.SetActive(self.group_Empty, self.loop_AchieventLevel.Count == 0) UIUtils.SetLabelText(self.lab_Noresult, self.hasFriend and Const_IDS["IDS_Achievement_Share_NoResult"] or Const_IDS["IDS_Achievement_Share_NoFriend"]) self.searchTxt = self.obj_InputField.text end end return UIAchievementShare