源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1086 lines
40 KiB

SocialityFriendView = SocialityFriendView or BaseClass(BaseItem)
function SocialityFriendView:__init()
self.base_file = "sociality"
self.layout_file = "SocialityFriendView"
self.model = SocialityModel:getInstance()
self.chatModel = ChatModel:getInstance()
self.scrollView_original_y = 0 --滚动面板最初的y值
self.curr_channel = ChatModel.CHANNEL_CECRET --当前频道
self.chating_key_id = 0 --当前正在私聊的玩家id 0表示没有正在私聊的玩家
self.all_chatItem_list = {} --总的聊天显示列表
self.cache_chatItem_list = {} --缓存聊天显示列表
self.cur_index = 0--TabBtn的index
self.cur_sub_index = 0--TabSubBtn的index
self.second_index = 0 --选中的一项,用于刷新的时候选回之前的一项
self.curr_channel_height = 0 --当前频道界面的高度 用于布局
self.chatItem_prefab = nil
self.event_list = {}
self.send_limit = 50
self:SetSendFormat(Config.ConfigChat.friendChannel)
self.open_index = 1--Config.ConfigSocial.RelativeType.friend --默认打开界面时展示的标签
self.is_reset_open_index = false
self.model.friend_tab_index = 2--打开界面时候,默认展示“联系人”界面
self.recent_cur_index = 0
self.recent_cur_sub_index = 0
--更新社交列表 提前绑定事件
local function onUpdate( need_sel_last )
if self.is_loaded then
self.is_need_update_sociality_view = false
self.need_sel_last = need_sel_last
self:UpdateView(false, need_sel_last)
else
self.is_need_update_sociality_view = true
end
end
self.list_event_id = self.model:Bind(SocialityModel.UPDATE_SOCIALITY_VIEW, onUpdate) --更新社交列表
--从外部调用事件私聊其他人时,不等协议全部返回才刷新界面
if not self.model.only_show_recent_view then
self.model:Fire(SocialityModel.REQUEST_SOCIAL_LIST)
else
self.model.only_rqeuest_data = true--只请求数据,不在协议返回后立即刷新界面
self.model:Fire(SocialityModel.REQUEST_SOCIAL_LIST)
end
self:Load()
end
function SocialityFriendView:Load_callback()
self.input_con,
self.voiceBtn,
self.faceBtn,
self.sendBtn,
self.chatCon,
self.tipCon,
self.chatBg,
self.contactsBtn,--联系人按钮
self.recentlyBtn,--最近联系列表
self.sendBtnBlock,--发送按钮的挡板
self.recentlyRed,
self.firstLabel,
self.oneKeyGetBtn,
self.oneKeySendBtn,
self.oneKeyGetRed,
self.oneKeySendRed
= GetChildGameObjects(self.transform,
{
"chatCon/bottom_con/TextInput",
"chatCon/bottom_con/voiceBtn",
"chatCon/bottom_con/faceBtn",
"chatCon/bottom_con/sendBtn",
"chatCon",
"tipCon",
"chatMsgBg",
"topBarCon/contactsBtn",
"topBarCon/recentlyBtn",
"chatCon/bottom_con/sendBtnBlock",
"topBarCon/recentlyBtn/recentlyRed",
"first_label",
"oneKeyGetBtn",
"oneKeySendBtn",
"oneKeyGetBtn/oneKeyGetRed",
"oneKeySendBtn/oneKeySendRed",
})
self.bottom_con,
self.scroll_content,
self.tabCon,
self.friendMsgCon,
self.assistantChatCon--小助手聊天三分栏
= GetChildTransforms(self.transform,
{
"chatCon/bottom_con",
"chatCon/ScrollView/Viewport/Content",
"tabCon",
"friendMsgCon",
"assistantChatCon",
})
self.sendBtn_text = self:GetChild("chatCon/bottom_con/sendBtn/Text"):GetComponent("TextMeshProUGUI")
self.tipLabel = self:GetChild("tipCon/tipLabel"):GetComponent("TextMeshProUGUI")
self.recentTabTxt = self:GetChild("topBarCon/recentlyBtn/Text"):GetComponent("TextMeshProUGUI")
self.contactsStr = self:GetChild("topBarCon/contactsBtn/Text"):GetComponent("TextMeshProUGUI")
self.sendText = self:GetChild("chatCon/bottom_con/sendBtn/Text"):GetComponent("TextMeshProUGUI")
self.contactsImg,--联系人按钮背景图
self.recentlyImg,--最近按钮背景图
self.friendListBg,
self.chatMsgBg,
self.chatBottomBg
= GetChildImages(self.transform,
{
"topBarCon/contactsBtn",
"topBarCon/recentlyBtn",
"friendListBg",
"chatMsgBg",
"chatMsgBg/chatBottomBg",
})
self.input_text = self:GetChild("chatCon/bottom_con/TextInput"):GetComponent("InputField")
self.ScrollView = self:GetChild("chatCon/ScrollView"):GetComponent("RectTransform")
self.girlIcon = self:GetChild("tipCon/girlIcon"):GetComponent("RawImage")
self.empty_talk_bg = self:GetChild("tipCon/Image"):GetComponent("RawImage")
self.scrollView_original_y = self.ScrollView.anchoredPosition.y
self.input_text.characterLimit = self.send_limit
self.chatCon:SetActive(false)
self.chatBg:SetActive(false)
self.tipCon:SetActive(false)
self.firstLabel:SetActive(false)
-- self.transform.localPosition = Vector3.zero
lua_resM:setOutsideImageSprite(self, self.friendListBg, GameResPath.GetSocialityImage("sociality_friend_list_bg"))
lua_resM:setOutsideImageSprite(self, self.chatMsgBg, GameResPath.GetSocialityImage("sociality_chat_bg"))
lua_resM:setOutsideImageSprite(self, self.chatBottomBg, GameResPath.GetSocialityImage("sociality_chat_bottom"))
lua_resM:setOutsideRawImage(self, self.girlIcon, GameResPath.GetRoleBg("team_empty_bg_267_589"), false)
lua_resM:setOutsideRawImage(self, self.empty_talk_bg, GameResPath.GetViewBigBg("com_empty_bg1"))
self.sendBtnBlock:SetActive(false)
self:InitEvent()
if self.friend_msg_view == nil then
self.friend_msg_view = SocialityFriendMsg.New(self.friendMsgCon)
end
self.friend_msg_view:SetVisible(false)
if self.assistan_chat_bar == nil then
self.assistan_chat_bar = SocialityAssistanChatBar.New(self.assistantChatCon)
end
self.assistan_chat_bar:SetVisible(false)
self:LoadChatItemPrefab()
if self.is_need_update_sociality_view then
self:UpdateView(false, self.need_sel_last)
end
end
function SocialityFriendView:LoadChatItemPrefab()
local function call_back(objs)
if self._use_delete_method then
return
end
self.chatItem_prefab = objs[0]
-- self:UpdateView(true)
-- self:UpdateView(false, self.need_sel_last)
--正常打开好友界面时等协议返回再updateview,从外部私聊时,先updateview
if self.model.only_show_recent_view then
self:UpdateView()
else
self:UpdateView(false,false,true)
end
self.model.only_show_recent_view = false
end
lua_resM:loadPrefabs(self, "chat", {"chatItem"}, call_back)
end
function SocialityFriendView:InitEvent( )
local function onClickBtnHandler(target)
if target == self.faceBtn then
GlobalEventSystem:Fire(EventName.OPEN_INDIVIDUATION_VIEW,self.chatModel.curr_individuation_bar_index,-192,-270, true, self.chating_key_id,true)
elseif target == self.sendBtn then
GlobalEventSystem:Fire(EventName.CLOSE_INDIVIDUATION_VIEW)
self:SendMsg()
elseif target == self.posBtn then
-- 仇人不能聊天
local is_enemy = self.model:IsRelaviveType(self.chating_key_id, Config.ConfigSocial.RelativeType.enemy)
if is_enemy then
Message.show("仇人不能聊天")
self.input_text.text = ""
return
end
local use_index = self.model.friend_tab_index == 1 and self.recent_cur_index or self.cur_index
local use_sub_index = self.model.friend_tab_index == 1 and self.recent_cur_sub_index or self.cur_sub_index
local vo = self.model:GetInfoByIndex(use_index, use_sub_index)
-- if vo and vo.online_flag~=1 then
-- Message.show("对方不在线")
-- return
-- end
--跳跃中不能发坐标,障碍点也不能发
if Scene.Instance.main_role:IsInState(PoseState.JUMP) or Scene.Instance.main_role:IsInState(PoseState.FLY) then return end
--发送坐标 用超链接的方法
local role = Scene.Instance:GetMainRole()
if not role then return end
local scene_id = SceneManager:getInstance():GetSceneId()
local line = MapModel:getInstance():GetServerLine()
local x = role.logic_pos.x
local y = role.logic_pos.y
if not SceneManager:getInstance():IsBlockXY(x , y) then
local scene_name = SceneManager:getInstance():GetSceneInfo(scene_id).name
local content = string.format("<a@pos@%s@%s@%s@%s><color=%s><u>%s,%d,%d</u></color></a>", scene_id, line, role.real_pos.x, role.real_pos.y, "#2cf89a", scene_name, x, y)
local tmpArgs = ChatModel:getInstance():GetAllArgsText(content)
content = ChatModel:getInstance():GetHyperlinkText(content)
ChatModel:getInstance():Fire(ChatModel.SEND_MSG,self.curr_channel,content,self.chating_key_id,tmpArgs,ChatModel.CHAT_COMMON_TYPE.COMMON)
end
elseif target == self.contactsBtn then--联系人按钮
--切换到联系人页签时,会加载到上次在联系人界面时候的历史位置(打开socialityview时默认加载第一个位置)
if self.model.friend_tab_index ==2 then return end--已经是当前页签时候就不再刷新界面了
self.model.friend_tab_index = 2
self.model.special_flag_change_tab = true--特殊标记:切换页签时防止好友列表遍历setselected时选中其他好友
self:UpdateView()
self.model:Fire(SocialityModel.REFRESH_SUB_BTN_RED)
elseif target == self.recentlyBtn then--最近联系按钮
if self.model.friend_tab_index ==1 then return end--已经是当前页签时候就不再刷新界面了
self.model.friend_tab_index = 1
self.model.special_flag_change_tab = true--特殊标记:切换页签时防止好友列表遍历setselected时选中其他好友
self.model.only_request_recent_flag = true--标识:只请求最近联系人列表
self.model:Fire(SocialityModel.REQUEST_CCMD_EVENT, 14000, 5)--请求最近联系人
elseif target == self.oneKeyGetBtn then--一键领取票券
local id_list = self.model:GetCanGetTicketFriendIdList()
if #id_list == 0 then
Message.show("暂无交易券可领")
else
self.model:Fire(SocialityModel.REQUEST_CCMD_EVENT, 14023)
end
elseif target == self.oneKeySendBtn then--一键赠送票券
local id_list,special_flag = self.model:GetCanSendTicketFriendIdList()
if special_flag then
Message.show("已达到赠送次数限制")
else
if #id_list == 0 then
Message.show("暂无好友可赠送")
else
self.model:Fire(SocialityModel.REQUEST_CCMD_EVENT, 14022, id_list)
end
end
end
end
AddClickEvent(self.faceBtn,onClickBtnHandler,2)
AddClickEvent(self.sendBtn,onClickBtnHandler,2)
AddClickEvent(self.applyBtn,onClickBtnHandler,2)
AddClickEvent(self.addBtn,onClickBtnHandler,2)
AddClickEvent(self.flowerBtn,onClickBtnHandler,LuaSoundManager.SOUND_UI.NONE)
AddClickEvent(self.contactsBtn,onClickBtnHandler,2)
AddClickEvent(self.recentlyBtn,onClickBtnHandler,2)
AddClickEvent(self.oneKeyGetBtn,onClickBtnHandler,2)
AddClickEvent(self.oneKeySendBtn,onClickBtnHandler,2)
local function onUpdateRecentView()
self:UpdateView()
self.model:Fire(SocialityModel.REFRESH_SUB_BTN_RED)
end
self:BindEvent(self.model,SocialityModel.UPDATE_SOCIALITY_RECENT_VIEW,onUpdateRecentView)
local function onSelectFaceItemHandler(item)
if item then
local face_str = "<#f_"..(item.index - 1)..">"
if #self.input_text.text + #face_str <= self.input_text.characterLimit and self.input_text.characterLimit ~= 0 then
self.input_text.text = self.input_text.text .. face_str
end
end
end
self.select_faceItem_id = self.chatModel:Bind(ChatModel.SELECT_FACE_ITEM,onSelectFaceItemHandler)
local function onSelectTextFaceItemHandler(item)
if item then
if self.chatModel.clicked_role_item == nil then
self.input_text.text = string.gsub(item.vo.one,"#N",RoleManager.Instance:GetMainRoleVo().name)
else
self.input_text.text = string.gsub(item.vo.two,"#n",self.chatModel.clicked_role_item.info.name)
self.input_text.text = string.gsub(self.input_text.text,"#N",RoleManager.Instance:GetMainRoleVo().name)
end
end
end
self.select_textFaceItem_id = self.chatModel:Bind(ChatModel.SELECT_TEXT_FACE_ITEM,onSelectTextFaceItemHandler)
local function onSelectHistoryTextItemHandler(str)
self.input_text.text = str
end
table.insert(self.event_list, self.chatModel:Bind(ChatModel.SELECT_HISTORY_TEXT_ITEM, onSelectHistoryTextItemHandler))
local function onClickPosBtnHandler(content, show_str)
self.click_pos_content = content
self.click_pos_show_str = show_str
self.input_text.text = show_str
end
table.insert(self.event_list, self.chatModel:Bind(ChatModel.CLICK_POS_BTN, onClickPosBtnHandler))
local function onSelectGoodItemHandler(goodVo)
-- if goodVo then
-- local content = nil
-- if goodVo.type == GoodsModel.TYPE.EQUIP then
-- content = string.format("<a@goods4@%s@%s@%s></a>", goodVo.type_id, goodVo.goods_id, RoleManager.Instance:GetMainRoleId())
-- else
-- content = string.format("<a@goods4@%s></a>", goodVo.type_id)
-- end
-- local args = string.format("{goods,%s,%s}", goodVo.type_id, goodVo.goods_id)
-- local str = "<" .. Trim(goodVo.goods_name) .. ">"
-- if goodVo.type == 11 and (goodVo.subtype == 10 or goodVo.subtype == 11) then
-- local type_id, _name, icon = EquipModel:getInstance():GetIdentifyGoodsNameAndIcon(goodVo.type_id, RoleManager.Instance.mainRoleInfo.career, goodVo.color, true)
-- str = "<" .. _name .. ">"
-- end
-- self:ReplaceInputTextMark(str)
-- self.chatModel:AddArgs(str, {args, content})
-- -- self.model.curr_chat_args = "{goods,"..goodVo.type_id..","..goodVo.goods_id.."}"
-- end
if goodVo then
local content = nil
local em_power_lv = 0
if goodVo.type == GoodsModel.TYPE.EQUIP then
content = string.format("<a@goods2@%s@%s@%s></a>", RoleManager.Instance:GetMainRoleId(),goodVo.goods_id, goodVo.type_id)
if goodVo then
for i,v in pairs(goodVo.other_data) do
if v.type == GoodsModel.GoodsInfoType.EquipEmpower then
em_power_lv = tonumber(v.info)
break
end
end
if em_power_lv == 0 and EquipModel:getInstance():IsWearEquip(goodVo.goods_id) then--如果是已穿戴
local equip_cfg = EquipModel:getInstance():GetEquipmentCfg(goodVo.type_id)
if equip_cfg and equip_cfg.series ~= 99 then
local server_info = EquipModel:getInstance():GetRedEquipInfo(equip_cfg.series,equip_cfg.equip_type)
em_power_lv = server_info and server_info.lv or 0
end
end
if em_power_lv > 0 then
content = string.format("<a@goods2@%s@%s@%s@%s></a>", RoleManager.Instance:GetMainRoleId(),goodVo.goods_id, goodVo.type_id,em_power_lv)
end
end
else
content = string.format("<a@goods4@%s></a>", goodVo.type_id)
end
local args = string.format("{goods,%s,%s}", goodVo.type_id, goodVo.goods_id)
local str = "<" .. Trim(goodVo.goods_name) .. ">"
if goodVo.type == 11 and (goodVo.subtype == 10 or goodVo.subtype == 11) then
local type_id, _name, icon = EquipModel:getInstance():GetIdentifyGoodsNameAndIcon(goodVo.type_id, RoleManager.Instance.mainRoleInfo.career, goodVo.color, true)
str = "<" .. _name .. ">"
end
self:ReplaceInputTextMark(str)
self.chatModel:AddArgs(str, {args, content})
-- self.model.curr_chat_args = "{goods,"..goodVo.type_id..","..goodVo.goods_id.."}"
end
end
self.select_goodItem_id = self.chatModel:Bind(ChatModel.SELECT_GOOD_ITEM, onSelectGoodItemHandler)
local function onSendMsg( str )
self.input_text.text = str
self:SendMsg()
end
self.send_event_id = self.chatModel:Bind(ChatModel.SEND_MSG_IN_VIEW, onSendMsg)
local function onAddMsgHandler(info)
if info and info.channel and info.channel == self.curr_channel then
self:AddMsgItem(info,true)
self.firstLabel:SetActive(false)
-- --保存聊天记录
-- CookieWrapper.Instance:WriteChatHistroy()
end
end
self.add_msg_id = self.chatModel:Bind(ChatModel.ADD_NEW_MSG,onAddMsgHandler)
GlobalEventSystem:Fire(EventName.ADD_RECORD_BTN,self.voiceBtn,{channel = ChatModel.CHANNEL_CECRET, rect = {x = 401,y = 33, w = 397, h = 58}, dis = 60})
local function onBoardCast( scmd )
local offset = 0
local curr_channel_list = self.all_chatItem_list[self.chatModel.curr_channel]
if not curr_channel_list then return end
for k,v in pairs(curr_channel_list) do
if offset ~= 0 then
v:ReLayout(offset)
else
if v.info.voice_id == scmd.auto_id then
offset = -v:SetRegText(scmd)
end
end
end
self.curr_channel_height = self.curr_channel_height + offset
end
self.bind_update_reg_text = self.chatModel:Bind(ChatModel.BROADCAST_VOICE_TEXT, onBoardCast)
-- local function onUpdate( need_sel_last )
-- if self.is_loaded then
-- self.is_need_update_sociality_view = false
-- self.need_sel_last = need_sel_last
-- self:UpdateView(false, need_sel_last)
-- else
-- self.is_need_update_sociality_view = true
-- end
-- end
-- self.list_event_id = self.model:Bind(SocialityModel.UPDATE_SOCIALITY_VIEW, onUpdate) --更新社交列表
local onRed = function ( )
-- self:RefreshRed()--主界面的申请、送花红点
self:RefreshRed()
end
self.social_event_id = GlobalEventSystem:Bind(EventName.REFRESH_SOCIAL_RED_DOT, onRed)
-- local onSelect = function ( )
-- --需要打开私聊对象
-- if ChatModel:getInstance().need_chat_key then
-- local index, sub_index = self.model:GetIndexByChatKey(ChatModel:getInstance().need_chat_key)
-- if index and sub_index then
-- self.verTabBar:SetSelectTab(index, sub_index, true)
-- end
-- ChatModel:getInstance().need_chat_key = nil
-- end
-- end
-- self.sel_event_id = GlobalEventSystem:Bind(EventName.SOCIAL_CHAT_SEL, onSelect)
--打开聊天界面上方的好友信息栏
local function UpdateFriendMsgView( data )
if not data then return end
if self.friend_msg_view then
local is_black = self.model:IsRelaviveType(data.role_id, Config.ConfigSocial.RelativeType.black)
if is_black then
self.friend_msg_view:SetVisible(false)
else
self.friend_msg_view:SetVisible(true)
end
self.friend_msg_view:SetData(data)
end
end
self.friend_msg_event_id = self.model:Bind(SocialityModel.OPEN_FRIEND_MSG_VIEW, UpdateFriendMsgView)
local function onUpdateSendTime()
self:UpdateSendTime()
end
self:BindEvent(ChatModel:getInstance(),ChatModel.UPDATE_SEND_TIME,onUpdateSendTime)
local function onUpdateScrollViewSize(is_one_way)
if is_one_way then
self.ScrollView.anchoredPosition = Vector3(self.ScrollView.anchoredPosition.x,305,self.ScrollView.anchoredPosition.z)
self.ScrollView.sizeDelta = Vector2(650,450)
else
self.ScrollView.anchoredPosition = Vector3(self.ScrollView.anchoredPosition.x,self.scrollView_original_y,self.ScrollView.anchoredPosition.z)
self.ScrollView.sizeDelta = Vector2(650,500)
end
end
self:BindEvent(self.model,SocialityModel.UPDATE_ONE_WAY_SCROLL_VIEW_SIZE,onUpdateScrollViewSize)
end
function SocialityFriendView:SetVisible( bool )
BaseItem.SetVisible(self, bool)
if bool and self.is_loaded then
GlobalEventSystem:Fire(EventName.ADD_RECORD_BTN,self.voiceBtn,{channel = ChatModel.CHANNEL_CECRET, rect = {x = 401,y = 33, w = 397, h = 58}, dis = 60})
end
end
function SocialityFriendView:RefreshRed( )
self:RefreshTopBarRed()
self:RefreshOneKeyTicketRed()
end
--根据“最近”、“联系人”页签来获取tabdata
function SocialityFriendView:GetFriendListDataByTabIndex()
local contactsAb = self.model.friend_tab_index == 1 and "uiComponent_asset" or "sociality_asset"
local contactsStr = self.model.friend_tab_index == 1 and "com_empty" or "sociality_tab_on"
local recentlyAb = self.model.friend_tab_index == 1 and "sociality_asset" or "uiComponent_asset"
local recentlyStr = self.model.friend_tab_index == 1 and "sociality_tab_on" or "com_empty"
lua_resM:setImageSprite(self, self.contactsImg, contactsAb, contactsStr)
lua_resM:setImageSprite(self, self.recentlyImg, recentlyAb, recentlyStr)
self.contactsStr.text = self.model.friend_tab_index == 2 and "<color=#ffffff>联系人</color>" or "<color=#9eb3cf>联系人</color>"
self.recentTabTxt.text = self.model.friend_tab_index == 2 and "<color=#9eb3cf>最近</color>" or "<color=#ffffff>最近</color>"
local contactsMat = self.model.friend_tab_index == 2 and ShaderTools.TMPSharedMaterialType.HKYTW7OutlineBlueTab or ShaderTools.TMPSharedMaterialType.HKYTW7FFDefault
local recentTabMat = self.model.friend_tab_index == 2 and ShaderTools.TMPSharedMaterialType.HKYTW7FFDefault or ShaderTools.TMPSharedMaterialType.HKYTW7OutlineBlueTab
SetTMPSharedMaterial(self.contactsStr, contactsMat)
SetTMPSharedMaterial(self.recentTabTxt, recentTabMat)
if self.model.friend_tab_index == 1 then
self.tab_data = self.model:GetRecentFriendTabData()
else
self.tab_data = self.model:GetFriendTabData()
end
end
function SocialityFriendView:UpdateView( show, need_sel_last,do_not_reset_chat_key)
self.need_cecret_chat = ChatModel:getInstance().need_chat_key
--先判断一次是不是有人私聊,如果有,界面打开时需要切换到最近页签
if self.need_cecret_chat then
self.model.friend_tab_index = 1
end
--判断页签,并使用相应的下标
local use_index = self.model.friend_tab_index == 1 and self.recent_cur_index or self.cur_index
local use_sub_index = self.model.friend_tab_index == 1 and self.recent_cur_sub_index or self.cur_sub_index
if self.model.friend_tab_index == 1 then
need_sel_last = false
end
self:GetFriendListDataByTabIndex()--根据页签获取到相应的好友列表数据
self:ReLayoutScroll()
--创建好友列表TabBar
if not self.verTabBar then
self.verTabBar = SocialityTabBar.New(self.tabCon)
end
local call_back = function (index, sub_index)
self:SwitchView(index, sub_index)
end
local call_back2 = function (index)
self.second_index = index
end
self.verTabBar:SetTabBars(self.tab_data, call_back, false, call_back2)
self.model.special_flag_change_tab = false
self.model.special_flag_online_changed = false
if show then return end --只是展示列表 不要往下执行, 等协议返回再执行
if self.need_cecret_chat then--需要打开私聊对象
local index, sub_index
if self.model.friend_tab_index == 1 then
index, sub_index = self.model:GetRecentListIndex(self.need_cecret_chat)
else
index, sub_index = self.model:GetIndexByChatKey(self.need_cecret_chat)
end
if index and sub_index then
self.verTabBar:SetSelectTab(index, sub_index, true)
end
--预加载的updateview不要重置私聊id
if not do_not_reset_chat_key then
ChatModel:getInstance().need_chat_key = nil
self.need_cecret_chat = nil
end
if self.model.has_private_chat then
self.model.has_private_chat = false
-- if MsgManager:getInstance():IsMsgTypeShow(Config.ConfigMainIcon.TipType.private_chat) then
-- MsgManager:getInstance():Remove(Config.ConfigMainIcon.TipType.private_chat)
-- end --WQ:暂时不需要主界面的私聊图标
end
return
elseif need_sel_last and use_index~=0 then
-- self.verTabBar:SetNewData(use_index)
local index, sub_index = self.model:GetIndexByChatKey(self.chating_key_id)
if index and sub_index then
self.verTabBar:SetSelectTab(index, sub_index, true)
end
return
else
if use_index == 0 and use_sub_index == 0 then --历史记录为(0,0)时直接打开(1,1)位置
self.verTabBar:SetSelectTab(1, 1, true)
use_index = 1--强行打开指定位置后,临时下标变量use_index等也要手动变化,因为当前函数后面还将用到
use_sub_index = 1
elseif use_index ~= 0 and use_sub_index ~= 0 then --当历史记录存在时,直接打开历史位置
self.verTabBar:SetSelectTab(use_index, use_sub_index, true)
elseif self.second_index~=0 then
self.verTabBar:SetSelectTab(self.second_index, 1, true)
elseif self.open_index then
self.verTabBar:SetSelectTab(self.open_index,1,true)
self.open_index = nil
self.is_reset_open_index = true
else
self.firstLabel:SetActive(false)
self.chatCon:SetActive(false)
self.chatBg:SetActive(false)
self.friend_msg_view:SetVisible(false)
self.tipCon:SetActive(true)
end
end
if self.is_reset_open_index then return end
-- if use_index == 0 then
-- self.verTabBar:SetNewData(self.second_index)
-- else
-- self.verTabBar:SetNewData(use_index)
-- end
self.is_reset_open_index = false
end
function SocialityFriendView:__delete( )
GlobalEventSystem:Fire(EventName.CLOSE_INDIVIDUATION_VIEW)
GlobalEventSystem:Fire(EventName.REMOVE_RECORD_BTN,self.voiceBtn)
if self.select_faceItem_id then
self.chatModel:UnBind(self.select_faceItem_id)
self.select_faceItem_id = nil
end
if self.select_textFaceItem_id then
self.chatModel:UnBind(self.select_textFaceItem_id)
self.select_textFaceItem_id = nil
end
if self.send_event_id then
self.chatModel:UnBind(self.send_event_id)
self.send_event_id = nil
end
if self.list_event_id then
self.model:UnBind(self.list_event_id)
self.list_event_id = nil
end
if self.add_msg_id then
self.chatModel:UnBind(self.add_msg_id)
self.add_msg_id = nil
end
if self.social_event_id then
GlobalEventSystem:UnBind(self.social_event_id)
self.social_event_id = nil
end
for channel,list in pairs(self.all_chatItem_list) do
for i,item in pairs(list) do
item:DeleteMe()
item = nil
end
list = nil
end
if self.verTabBar then
self.verTabBar:DestroyBtnList()
self.verTabBar:DeleteMe()
self.verTabBar = nil
end
for i,item in pairs(self.cache_chatItem_list) do
item:DeleteMe()
item = nil
end
for i, v in ipairs(self.event_list) do
self.chatModel:UnBind(v)
v = nil
end
self.event_list = nil
if self.friend_msg_event_id then
self.model:UnBind(self.friend_msg_event_id)
self.friend_msg_event_id = nil
end
if self.friend_msg_view then
self.friend_msg_view:DeleteMe()
self.friend_msg_view = nil
end
if self.assistan_chat_bar then
self.assistan_chat_bar:DeleteMe()
self.assistan_chat_bar = nil
end
if self.send_timer_id then
GlobalTimerQuest:CancelQuest(self.send_timer_id)
self.send_timer_id = nil
end
self.cache_chatItem_list = {}
self.all_chatItem_list = {}
self.chating_key_id = 0
self.chatModel.chating_key_id = 0
self.chatItem_prefab = nil
if self.delay_show_assist_msg then
TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_assist_msg)
self.delay_show_assist_msg = nil
end
--保存聊天记录
CookieWrapper.Instance:WriteChatHistroy()
end
function SocialityFriendView:SendMsg()
local use_index = self.model.friend_tab_index == 1 and self.recent_cur_index or self.cur_index
local use_sub_index = self.model.friend_tab_index == 1 and self.recent_cur_sub_index or self.cur_sub_index
-- 黑名单不能聊天
local is_black = self.model:IsRelaviveType(self.chating_key_id, Config.ConfigSocial.RelativeType.black)
if is_black then
Message.show("不能向黑名单发送消息")
self.input_text.text = ""
return
end
--对方是否在线(WQ暂时先不要离线禁止私聊的逻辑)
-- local vo = self.model:GetInfoByIndex(use_index, use_sub_index)
-- if vo and vo.online_flag~=1 then
-- Message.show("对方不在线")
-- self.input_text.text = ""
-- return
-- end
if self.chatModel:CheckCurrentTimeCanSend(channel,self.send_interval) then
local content = self.input_text.text
local _, title_filter = LanguageFilter.FilterMsg(content)
if title_filter == false then
Message.show("内容有敏感词")
return
end
if not CheatModel:getInstance():CheckCommand(content) then
return
end
if self.input_text.text == "@##@" then
GlobalEventSystem:Fire(EventName.OPEN_CHEAT_INPUT_VIEW) --秘籍
return
elseif self.input_text.text == "@testclient" then
GlobalEventSystem:Fire(EventName.OPEN_CHEAT_CLIENT_VIEW) --客户端秘籍
return
end
if content and content ~= "" then
if self.click_pos_content then
if Trim(self.click_pos_show_str) == Trim(content) then
content = self.click_pos_content
self.click_pos_content = false
end
end
local tmpArgs = self.chatModel:GetAllArgsText(content)
content = self.chatModel:GetHyperlinkText(content)
self.chatModel:Fire(ChatModel.SEND_MSG,self.curr_channel,content,self.chating_key_id,tmpArgs,ChatModel.CHAT_COMMON_TYPE.COMMON)
self.input_text.text = ""
self.chatModel.chat_args_dic = {}
--判断私聊是否可以完成羁绊日常任务
local mate_daily_need_chat_role_list = MateModel:GetInstance():GetMateDailyTaskNeedChatData()
if mate_daily_need_chat_role_list and mate_daily_need_chat_role_list[self.chating_key_id] then
MateModel:GetInstance():Fire(MateConst.PROTO_CCMD_EVENT,14956,1,self.chating_key_id)
mate_daily_need_chat_role_list[self.chating_key_id] = nil
end
end
else
if self.input_text.text ~= "" then
Message.show("发送频率过快,请销后再试...")
end
end
end
--设置发送的格式
function SocialityFriendView:SetSendFormat(info)
self.send_interval = info.send_interval
self.send_limit = info.send_limit
end
function SocialityFriendView:ReplaceInputTextMark(str)
--替换规则是"(<.->)"
local text = self.input_text.text
local old_args = self.chatModel:IsHasArgs(text)
if (string.find(text,"(<.->)") and old_args) then
old_args = LanguageFilter.ConvPartten(old_args)
self.input_text.text = string.gsub(text,old_args,str)
else
self.input_text.text = text .. str
end
return str
end
--重新布局滚动条大小 以及位置
function SocialityFriendView:ReLayoutScroll()
local is_one_way = self.model:IsRelaviveType(self.chating_key_id,Config.ConfigSocial.RelativeType.oneWay)
if is_one_way then
self.ScrollView.anchoredPosition = Vector3(self.ScrollView.anchoredPosition.x,305,self.ScrollView.anchoredPosition.z)
self.ScrollView.sizeDelta = Vector2(650,450)
else
self.ScrollView.anchoredPosition = Vector3(self.ScrollView.anchoredPosition.x,self.scrollView_original_y,self.ScrollView.anchoredPosition.z)
self.ScrollView.sizeDelta = Vector2(650,500)
end
self.scroll_content.sizeDelta = Vector2(702,self.curr_channel_height+10)
local off_h = self.scroll_content.sizeDelta.y - self.ScrollView.sizeDelta.y
off_h = off_h < 0 and 0 or off_h
self.scroll_content.localPosition = Vector3(0,off_h,0)
end
--添加一个聊天信息 autoLayout是否自动布局
function SocialityFriendView:AddMsgItem(info,autoLayout)
-- self.firstLabel:SetActive(false)
if self.curr_channel ~= info.channel or info.key_id~=self.chating_key_id then return end
if self.pre_renderer_chatItem and not self.pre_renderer_chatItem:IsLineItem() then
local time_off = info.time - self.pre_renderer_chatItem.info.time
if time_off >= ChatModel.SHOW_LINE_TIME then --说话间隔大于该时间 就要添加横线时间
self.pre_renderer_chatItem = nil
local lineInfo = self.chatModel:PackChatInfo(self.curr_channel,info.time,info.key_id)
self:AddMsgItem(lineInfo,true)
end
end
local curr_channel_list = nil
curr_channel_list = self.all_chatItem_list[self.curr_channel] -- 取出当前频道的消息列表
if curr_channel_list == nil then --如果没有就创建一个空表出来
curr_channel_list = {}
self.all_chatItem_list[self.curr_channel] = curr_channel_list
end
--超过长度放入缓存列表
if #curr_channel_list >= ChatModel.MAX_LEN_LIST[self.curr_channel] then
local item = table.remove(curr_channel_list,1)
item:SetVisible(false)
table.insert(self.cache_chatItem_list,item)
local item_height = item:GetHeight()
for i = 1, #curr_channel_list do
item = curr_channel_list[i]
item:ReLayout(item_height)
end
self.curr_channel_height = self.curr_channel_height - item_height
end
--检查缓存
local new_item
if #self.cache_chatItem_list > 0 then
new_item = table.remove(self.cache_chatItem_list,1)
else
new_item = ChatItem.New(self.scroll_content, self.chatItem_prefab, nil, nil, true)
end
self.curr_channel_height = self.curr_channel_height + new_item:SetData(info,self.curr_channel_height) or 0
table.insert(curr_channel_list,new_item)
if new_item:IsLineItem() then
new_item:SetLineTimeColor(ColorType.WHITE)
new_item:SetLineSize(560, 192)
end
if autoLayout then
self:ReLayoutScroll()
end
self.pre_renderer_chatItem = new_item
new_item.transform.sizeDelta = Vector2(575, new_item.height)
end
function SocialityFriendView:UpdateSendTime()
local time = self:SetSendTimeText()
if time > 0 then
if self.send_timer_id then
GlobalTimerQuest:CancelQuest(self.send_timer_id)
self.send_timer_id = nil
end
local function onSendTimerPlaying()
self:SetSendTimeText()
end
self.send_timer_id = GlobalTimerQuest:AddPeriodQuest(onSendTimerPlaying,1,-1)
end
end
function SocialityFriendView:SetSendTimeText()
if self._use_delete_method then return end
-- local time = self.chatModel:GetPassTimeFromSend(ChatModel.CHANNEL_CECRET,Config.ConfigChat.channel_level[4].send_interval)
local time = self.chatModel:GetPassTimeFromSend(ChatModel.CHANNEL_CECRET,3)
if time > 0 then
local str = math.ceil(time) .. "s"
self.sendText.text = str
self.sendBtnBlock:SetActive(true)
else
self:CancelSendTimer()
self.sendText.text = "发送"
self.sendBtnBlock:SetActive(false)
end
return time
end
function SocialityFriendView:CancelSendTimer( )
if self.send_timer_id then
GlobalTimerQuest:CancelQuest(self.send_timer_id)
self.send_timer_id = nil
end
end
function SocialityFriendView:SwitchView(index, sub_index)
-------- 先处理和小助手聊天的情况
local is_assistant = (self.model.friend_tab_index == 1 and index == 1 and sub_index == 1) or (self.model.friend_tab_index == 2 and index == 1 and sub_index == 1)
if is_assistant then
self.friend_msg_view:HideBtnCon(false)
self.assistan_chat_bar:SetVisible(true)
self.bottom_con.gameObject:SetActive(false)
self.chatBottomBg.gameObject:SetActive(false)
else
self.friend_msg_view:HideBtnCon(true)
self.assistan_chat_bar:SetVisible(false)
self.bottom_con.gameObject:SetActive(true)
self.chatBottomBg.gameObject:SetActive(true)
end
--------
local vo = self.model:GetInfoByIndex(index, sub_index) -- 拿到好友信息
if vo then
self.chating_key_id = vo.role_id
self.chatModel.chating_key_id = vo.role_id
if self.model.friend_tab_index == 2 then
self.cur_index = index
self.cur_sub_index = sub_index
else
self.recent_cur_index = index
self.recent_cur_sub_index = sub_index
end
local use_index = self.model.friend_tab_index == 1 and self.recent_cur_index or self.cur_index
local use_sub_index = self.model.friend_tab_index == 1 and self.recent_cur_sub_index or self.cur_sub_index
if index==3 then
self.chatCon:SetActive(false)
self.chatBg:SetActive(false)
self.friend_msg_view:SetVisible(false)
self.tipCon:SetActive(true)
self.tipLabel.text = "无法向黑名单玩家发消息哦!"
else
self.chatCon:SetActive(true)
self.chatBg:SetActive(true)
self.tipCon:SetActive(false)
self.tipLabel.text = "点击左侧列表好友即可聊天!"
end
self.curr_channel_height = 0
--先显示界面再加载 非黑名单的情况下
if index~=3 then
self.chatCon:SetActive(true)
self.chatBg:SetActive(true)
self.tipCon:SetActive(false)
end
--好友首次聊天显示防骗信息(除去小助手)
if (index == 1 or index == 2)
and vo.last_chat_time==0
and not is_assistant
and self.model:IsRelaviveType(vo.role_id,Config.ConfigSocial.RelativeType.friend) then
self.firstLabel:SetActive(true)
else
self.firstLabel:SetActive(false)
end
local pre_channel_list = self.all_chatItem_list[self.curr_channel]
if pre_channel_list then
for i,item in pairs(pre_channel_list) do
item:SetVisible(false)
if not TableContains(self.cache_chatItem_list,item) then
table.insert(self.cache_chatItem_list,item)
end
end
end
--测试用,用于删除和指定玩家的聊天缓存
-- CookieWrapper.Instance:DeleteChatHistroyFile(1)
local list = CookieWrapper.Instance:GetChatHistroy(self.chating_key_id,true)--根据id获取聊天缓存
if list and list[tostring(self.chating_key_id)] then
for k,v in pairs(list[tostring(self.chating_key_id)]) do
--获取新头像信息
if v.key_id then
if v.player_id==RoleManager.Instance.mainRoleInfo.role_id then
v.turn = RoleManager.Instance.mainRoleInfo.turn
v.sex = RoleManager.Instance.mainRoleInfo.sex
v.career = RoleManager.Instance.mainRoleInfo.career
v.picture_ver = RoleManager.Instance.mainRoleInfo.picture_ver
v.picture = RoleManager.Instance.mainRoleInfo.picture
v.profile_photo_id = RoleManager.Instance.mainRoleInfo.profile_photo_id
else
local vo = SocialityModel:getInstance():GetVoByOnlyId(v.key_id)
if vo then
v.picture_ver = vo.picture_ver
v.picture = vo.picture
v.profile_photo_id = vo.profile_photo_id
v.board = vo.board
v.turn = vo.turn
v.sex = vo.sex
v.career = vo.career
end
end
end
end
end
self.chatModel.all_chat_list[ChatModel.CHANNEL_CECRET] = list
local curr_channel_list = list[tostring(self.chating_key_id)]
--设置好友信息栏的展示
self.model:Fire(SocialityModel.OPEN_FRIEND_MSG_VIEW,vo)
--判断有没有小助手的私聊信息,如果有的话,打开界面后要延时展示消息
local has_assist_info = false
local chat_priate_info = ChatModel:getInstance():GetPriateChatInfo() or {}
for k,v in pairs(chat_priate_info) do
if v == 1 then
has_assist_info = true
end
end
--设置聊天记录
self.pre_renderer_chatItem = nil
local need_hide_first_label = false
if curr_channel_list then
self.all_chatItem_list[self.curr_channel] = {}
if #curr_channel_list > 0 then
need_hide_first_label = true
end
if is_assistant and has_assist_info then
for i = 1,#curr_channel_list-1 do
self:AddMsgItem(curr_channel_list[i],false)
end
else
for i = 1,#curr_channel_list do
self:AddMsgItem(curr_channel_list[i],false)
end
end
end
if need_hide_first_label then
self.firstLabel:SetActive(false)
end
self:ReLayoutScroll()--滚动到聊天栏最后的位置
if self.model.temp_chat_msg_content then
self.input_text.text = self.model.temp_chat_msg_content
self.model.temp_chat_msg_content = nil
end
if self.delay_show_assist_msg then
TimerQuest.CancelQuest(GlobalTimerQuest, self.delay_show_assist_msg)
self.delay_show_assist_msg = nil
end
if is_assistant and has_assist_info then
local function delay_method( )
self:AddMsgItem(curr_channel_list[#curr_channel_list],false)
self:ReLayoutScroll()--滚动到聊天栏最后的位置
end
self.delay_show_assist_msg = setTimeout(delay_method, 0.5)
end
else
self.chating_key_id = 0
self.chatModel.chating_key_id = 0
self.cur_index = 0
self.cur_sub_index = 0
self.curr_channel_height = 0
self.firstLabel:SetActive(false)
self.chatCon:SetActive(false)
self.chatBg:SetActive(false)
self.friend_msg_view:SetVisible(false)
self.tipCon:SetActive(true)
self.tipLabel.text = "点击左侧列表好友即可聊天!"
end
--清除红点
self.chatModel:ClearChannelMessageNum(self.curr_channel, self.chating_key_id)
self.chatModel:Fire(ChatModel.SHOW_TAB_RED_POINT,self.chatModel.all_chat_list_count)
end
--刷新“最近”页签的红点,当有其他玩家(非当前聊天时)消息过来时,刷新红点
function SocialityFriendView:RefreshTopBarRed( ... )
self.info,self.vo = MainUIModel:getInstance():IsShowChatFriendRed()
if self.vo then
self.recentlyRed:SetActive(self.info)
end
local chat_priate_info = ChatModel:getInstance():GetPriateChatInfo() or {}
local recent_red = {}
self.recentlyRed:SetActive(TableSize(chat_priate_info) > 0)
end
function SocialityFriendView:RefreshOneKeyTicketRed( )
local can_send_list = self.model:GetCanSendTicketFriendIdList()
local can_get_list = self.model:GetCanGetTicketFriendIdList()
local sendRed = #can_send_list ~= 0
local getRed = #can_get_list ~= 0
self.oneKeySendRed:SetActive(sendRed)
self.oneKeyGetRed:SetActive(getRed)
end