local UIFriendBase = UIViewClass() local EventSystem = require('Event/EventSystem') function UIFriendBase:OnOpened(context) self.isInit = false self:RegistSystemEvent(EventID.UI_OpenFriendPanel, self.SetContext) self:RegistSystemEvent(EventID.UI_UpdateChatRed, self.RefreshChatAndFriendRed) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.Mail, self.RefreshMailRed) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.Friend, self.RefreshChatAndFriendRed) -- 通用Toggle self.group_Toggles = self.group_LeftBtn.toggles_Group self.mainIndex = 0 self.togglesFuncDic = {} if not BattleDataGetter.IsNoBattleLevel() then --战斗内不显示仇人、邮件页签 UTL.Toggle.InitToggleGroupByIDS(self.group_Toggles, "txt", {Const_IDS.IDS_Friend_Friend}) self.togglesFuncDic[0] = CTL.Friend.MainIndex.Main self:RefreshChatAndFriendRed() else --主城内好友未开启,只显示邮件 if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Friend) then -- 判断一下邮件的GM开关是否开启 if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Mail) then UTL.Toggle.InitToggleGroupByIDS(self.group_Toggles, "txt", {Const_IDS.IDS_Mail}) self.togglesFuncDic[0] = CTL.Friend.MainIndex.Mail end else if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Mail) then UTL.Toggle.InitToggleGroupByIDS(self.group_Toggles, "txt", {Const_IDS.IDS_Friend_Friend, Const_IDS.IDS_Rival_FunctionName, Const_IDS.IDS_Mail}) self.togglesFuncDic[0] = CTL.Friend.MainIndex.Main self.togglesFuncDic[1] = CTL.Friend.MainIndex.Rival self.togglesFuncDic[2] = CTL.Friend.MainIndex.Mail else UTL.Toggle.InitToggleGroupByIDS(self.group_Toggles, "txt", {Const_IDS.IDS_Friend_Friend, Const_IDS.IDS_Rival_FunctionName}) self.togglesFuncDic[0] = CTL.Friend.MainIndex.Main self.togglesFuncDic[1] = CTL.Friend.MainIndex.Rival end self:RefreshChatAndFriendRed() self.mainIndex = context.MainIndex end self:RefreshMailRed() end UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) self:SetContext(context) end function UIFriendBase:SetContext(context) self.lastTabIndex = nil self.context = context local index = self.togglesFuncDic[self.mainIndex] if self.context.subContext and self.context.subContext[index] then self.context.subContext[index].SubIndex = self.context.SubIndex self.context.subContext[index].Acid = self.context.Acid self.context.subContext[index].EnterType = self.context.EnterType end self.group_Toggles:SelectIndex(self.mainIndex) self.isInit = true end --好友聊天红点,由于聊天消息和最近列表协议的时序不好确定,需要同时监听 function UIFriendBase:RefreshChatAndFriendRed() local recentRedNum = MDL.Friend.GetUnreadMsgNumByType(MDL.Friend.ListType.Recent) + CTL.SpecialTeam.GetSumGroupChatRedCount() + CTL.SpecialTeam.GetNoticeGroupChatRed() local friendRed = CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.Friend) self.group_Toggles:SetRedPoint(0, recentRedNum > 0 or (friendRed == nil and false or friendRed)) end -- 邮件红点 function UIFriendBase:RefreshMailRed() local mailIndex = nil for index, v in pairs(self.togglesFuncDic) do if v == CTL.Friend.MainIndex.Mail then mailIndex = index break end end if mailIndex == nil then return end local mailRed = CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.Mail) if mailRed == nil then self.group_Toggles:SetRedPoint(mailIndex, false) else self.group_Toggles:SetRedPoint(mailIndex, mailRed) end end function UIFriendBase:OnValueChanged(comp, index) if comp == self.group_Toggles then self:OnSwitchTab(index) end end function UIFriendBase:OnSwitchTab(index) if self.isInit then self.context.EnterType = 0 --好友内部切换页签,enterType需要置零 end if self.lastTabIndex == index then return end self.lastTabIndex = index self.subView:CloseAll() if self.context.subContext == nil then self.context.subContext = {} end index = self.togglesFuncDic[index] if index == CTL.Friend.MainIndex.Main then if self.context.subContext[index] == nil then self.context.subContext[index] = { SubIndex = self.context.SubIndex, Acid = self.context.Acid, EnterType = self.context.EnterType, } end self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIFriendMain), self.context.subContext[index]) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_Friend_Friend) elseif index == CTL.Friend.MainIndex.Rival then self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIRivalBase)) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_Rival_FunctionName) elseif index == CTL.Friend.MainIndex.Mail then if self.context.subContext[index] == nil then self.context.subContext[index] = { MailIndex = 0, } end CTL.Mail.OnOpenMail() self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIFriendMail), self.context.subContext[index]) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_Mail) end end function UIFriendBase:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIFriendBase:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView() elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() end end function UIFriendBase:OnClosed() MDL.Friend.ClearRecordSelectAcids() UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) --关闭好友界面,保存一次记录 CTL.Friend.WriteChatHistory() EventSystem.Dispatch(EventID.UIBattle_OnFriendBaseClose) end return UIFriendBase