ChatView = ChatView or BaseClass(BaseView)
|
|
local ChatView = ChatView
|
|
|
|
local ChatModel = ChatModel
|
|
local GlobalEventSystem = GlobalEventSystem
|
|
local GlobalTimerQuest = GlobalTimerQuest
|
|
local GuildModel = GuildModel
|
|
local MainUIModel = MainUIModel
|
|
local RoleManager = RoleManager
|
|
local lua_resM = lua_resM
|
|
|
|
local table_insert = table.insert
|
|
local table_remove = table.remove
|
|
local AddClickEvent = AddClickEvent
|
|
|
|
function ChatView:__init()
|
|
self.base_file = "chat"
|
|
self.layout_file = "chatView"
|
|
self.layer_name = "UI"
|
|
-- self.use_local_view = true
|
|
self.open_wnd_anim = 0
|
|
self.model = ChatModel:getInstance()
|
|
self.change_scene_close = true
|
|
self.append_to_ctl_queue = true
|
|
self.is_moving = false
|
|
self.is_set_zdepth = true
|
|
self.curr_bar_index = 1
|
|
self.destroy_imm = false
|
|
self.tabbar_list = {}
|
|
self.tabbar_prefab = nil
|
|
self.chatItem_prefab = nil
|
|
-- self.close_mode = CloseMode.CloseVisible
|
|
self.event_list = {}
|
|
self.need_instance_data_list = {} --隐藏还没有创键的item数据
|
|
self.all_chat_data_list = {} --记录每个频道每个item的位置
|
|
self.all_chat_item_list = {} --所以聊天信息item
|
|
self.need_add_line_list = {}
|
|
self.need_add_msg = {} --消息缓存 需要设置完坐标后重新计算
|
|
self.is_talk_to_text = true --是否文本聊天 非语音聊天模式
|
|
|
|
|
|
self.front_item_data_list = {}
|
|
self.back_item_data_list = {}
|
|
self.cur_item_data_list = {}
|
|
|
|
self.send_interval = 0 -- 发送时间间隔
|
|
self.send_limit = 50 -- 发送文字限制
|
|
|
|
self.all_chatItem_list = {} --总的聊天显示列表
|
|
self.cache_chatItem_list = {} --缓存聊天显示列表
|
|
|
|
self.pre_content_pos_y = 0--刷新一对一聊天记录前的位置
|
|
self.curr_channel_height = 0 --当前频道界面的高度 用于布局
|
|
self.pre_renderer_chatItem = nil -- 上一个渲染的chatitem 跟当前需要渲染的chatitem对比用于判断是否需要显示横线时间
|
|
|
|
self.chating_name = "" --当前正在私聊的玩家名字
|
|
self.scrollView_original_y = 0 --滚动面板最初的y值
|
|
|
|
self.pre_channel_list = {} --当前频道 聊天显示列表
|
|
|
|
self.not_read_count = 0 --未读消息
|
|
self.scroll_content_drag = false --拖拽的标志
|
|
|
|
self.scroll_posy_in_lock = 0 --锁定时当前content的pos y
|
|
self.cache_not_read_list = {}
|
|
self.horn_id = 38050001
|
|
self.cross_horn_id = 38050002
|
|
self.pre_cache_item_list = {} --缓存多添加的item
|
|
--self:AddPreLoadList("chat", {"ChatItem"})
|
|
self.click_pos_content = false --用来记录位置的字符串
|
|
self.input_text_onValueChanged_addListener_off = false --
|
|
self.is_hide_skill_black_bg = true
|
|
|
|
self.limit_btn_list = {} -- 缓存限制频道的ITem
|
|
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
self:InitEvent()
|
|
self:LoadTabbarPrefab()
|
|
end
|
|
self.open_callback = function ()
|
|
self.view_is_close = false
|
|
if SceneManager:getInstance():IsGuildScene() then
|
|
--答题场景请求题目信息
|
|
-- GuildModel:getInstance():Fire(GuildModel.REQUEST_CCMD_EVENT, 40217)
|
|
self:SetCurrTabbarIndex(ChatModel.CHANNEL_GUILD)
|
|
end
|
|
self:SwitchBar()
|
|
local function onCompleted()
|
|
self.is_moving = false
|
|
end
|
|
self.is_moving = true
|
|
self.model:Fire(ChatModel.UPDATE_SEND_TIME)
|
|
self.transform.anchoredPosition = Vector2(-SrcScreenWidth / 2, 0)
|
|
TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POS, Vector2(ClientConfig.iphone_x_offset_left, 0), 0.1, onCompleted)
|
|
|
|
self.temp_state = MainUIModel:getInstance().state_right_bottom:isInstate()
|
|
|
|
GlobalEventSystem:Fire(EventName.HIDE_MAIN_CHAT_VIEW, true, MainUIModel.MAIN_MODE)
|
|
-- GlobalEventSystem:Fire(EventName.HIDE_RIGHT_BOTTOM_VIEW, true, MainUIModel.MAIN_MODE, true)
|
|
|
|
self:ShowIndividualRedPoint()
|
|
self.input_text.text = self.model.say_cache
|
|
self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11011, ChatModel.CHANNEL_CROSS)
|
|
-- self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11011, ChatModel.CHANNEL_COUNTRY)
|
|
|
|
self:SetDressBackground()
|
|
end
|
|
|
|
self.ReOpen_callback = function ()
|
|
self:SetDressBackground() -- 装扮界面关闭会主动跳回来
|
|
end
|
|
|
|
self.close_callback = function ()
|
|
self:HideCurChannelItem()
|
|
self.need_add_msg = {}
|
|
self.view_is_close = true
|
|
self.is_moving = false
|
|
local recordView = MainUIController.Instance.RecordViw
|
|
GlobalEventSystem:Fire(EventName.CLOSE_INDIVIDUATION_VIEW)
|
|
if recordView then
|
|
recordView:OnClose()
|
|
end
|
|
GlobalEventSystem:Fire(EventName.HIDE_MAIN_CHAT_VIEW, false, MainUIModel.MAIN_MODE)
|
|
if SceneManager:getInstance():IsStarFightScene() then
|
|
GlobalEventSystem:Fire(EventName.HIDE_RIGHT_BOTTOM_VIEW, self.temp_state, MainUIModel.MAIN_MODE, true)
|
|
else
|
|
GlobalEventSystem:Fire(EventName.HIDE_RIGHT_BOTTOM_VIEW, false, MainUIModel.MAIN_MODE, true)
|
|
end
|
|
self.model.say_cache = self.input_text.text
|
|
GlobalEventSystem:Fire(EventName.CLOSE_CHAT_BAG_VIEW)
|
|
GlobalEventSystem:Fire(EventName.MAIN_VOICE_BIND)
|
|
end
|
|
self.destroy_callback = function ()
|
|
self:Clear()
|
|
end
|
|
----测试 后续调进配置里 这个无用!!
|
|
self.role_text_width = 307+100
|
|
self.dress_bubble_role_bg_add_size = co.TableXY(41+100, 40)
|
|
self.role_bg_add_size = co.TableXY(60+100, 25)
|
|
self.voice_bg_add_size = co.TableXY(30 + 53+100, 40)
|
|
self.role_bg_min_size = co.TableXY(5+100, 56)
|
|
self.main_role_text_offset = co.TableXY(-31+100, -3) --有气泡的时候调整
|
|
self.main_role_default_text_offset = co.TableXY(-28+100, 0) --无气泡的时候调整
|
|
end
|
|
|
|
function ChatView:Clear()
|
|
self.is_initialized = false
|
|
self.has_init_item = false
|
|
self.is_first_open = false
|
|
self:CancelAddMsgTimer()
|
|
self:CancelGetHeightQuest()
|
|
self.model:SeletedChatViewTabbar(nil)
|
|
self.pre_renderer_chatItem = nil
|
|
self.curr_channel_height = 0
|
|
self.pre_content_pos_y = 0
|
|
self.tabbar_prefab = nil
|
|
self.chatItem_prefab = nil
|
|
for channel, list in pairs(self.all_chatItem_list) do
|
|
for i, item in pairs(list) do
|
|
item:DeleteMe()
|
|
end
|
|
end
|
|
self.all_chatItem_list = {}
|
|
|
|
for i, v in ipairs(self.pre_channel_list) do
|
|
if v then
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
end
|
|
self.pre_channel_list = {}
|
|
|
|
for i, item in pairs(self.cache_chatItem_list) do
|
|
item:DeleteMe()
|
|
end
|
|
self.cache_chatItem_list = {}
|
|
|
|
for _, v in pairs(self.all_chat_item_list) do
|
|
v:DeleteMe()
|
|
end
|
|
self.all_chat_item_list = {}
|
|
|
|
for i, item in pairs(self.tabbar_list) do
|
|
item:DeleteMe()
|
|
end
|
|
self.tabbar_list = {}
|
|
|
|
if self.selected_item_bind_id then
|
|
self.model:UnBind(self.selected_item_bind_id)
|
|
self.selected_item_bind_id = nil
|
|
end
|
|
|
|
if self.refresh_event_id then
|
|
self.model:UnBind(self.refresh_event_id)
|
|
self.refresh_event_id = nil
|
|
end
|
|
|
|
if self.send_event_id then
|
|
self.model:UnBind(self.send_event_id)
|
|
self.send_event_id = nil
|
|
end
|
|
if self.select_faceItem_id then
|
|
self.model:UnBind(self.select_faceItem_id)
|
|
self.select_faceItem_id = nil
|
|
end
|
|
if self.select_textFaceItem_id then
|
|
self.model:UnBind(self.select_textFaceItem_id)
|
|
self.select_textFaceItem_id = nil
|
|
end
|
|
|
|
if self.horn_event_id then
|
|
self.model:UnBind(self.horn_event_id)
|
|
self.horn_event_id = nil
|
|
end
|
|
|
|
if self.select_goodItem_id then
|
|
self.model:UnBind(self.select_goodItem_id)
|
|
self.select_goodItem_id = nil
|
|
end
|
|
|
|
if self.select_coord_id then
|
|
self.model:UnBind(self.select_coord_id)
|
|
self.select_coord_id = nil
|
|
end
|
|
|
|
if self.add_msg_id then
|
|
self.model:UnBind(self.add_msg_id)
|
|
self.add_msg_id = nil
|
|
end
|
|
|
|
if self.show_tab_red_point_id then
|
|
self.model:UnBind(self.show_tab_red_point_id)
|
|
self.show_tab_red_point_id = nil
|
|
end
|
|
|
|
if self.title_promote_id then
|
|
self.model:UnBind(self.title_promote_id)
|
|
self.title_promote_id = nil
|
|
end
|
|
|
|
if self.update_time_id then
|
|
self.model:UnBind(self.update_time_id)
|
|
self.update_time_id = nil
|
|
end
|
|
|
|
self:CancelSendTimer()
|
|
|
|
if self.bind_update_reg_text then
|
|
self.model:UnBind(self.bind_update_reg_text)
|
|
self.bind_update_reg_text = nil
|
|
end
|
|
|
|
if self.vip_event_id then
|
|
RoleManager:getInstance():GetMainRoleVo():UnBind(self.vip_event_id)
|
|
self.vip_event_id = nil
|
|
end
|
|
|
|
if self.question_event_id then
|
|
GuildModel:getInstance():UnBind(self.question_event_id)
|
|
self.question_event_id = nil
|
|
end
|
|
|
|
if self.select_bag_id then
|
|
self.model:UnBind(self.select_bag_id)
|
|
self.select_bag_id = nil
|
|
end
|
|
|
|
GlobalEventSystem:Fire(EventName.REMOVE_RECORD_BTN, self.voiceBtn)
|
|
-- self:CancelQueTimer()
|
|
|
|
if self.show_individual_redPoint_id then
|
|
GlobalEventSystem:UnBind(self.show_individual_redPoint_id)
|
|
self.show_individual_redPoint_id = nil
|
|
end
|
|
|
|
if self.orientation_change_id then
|
|
GlobalEventSystem:UnBind(self.orientation_change_id)
|
|
self.orientation_change_id = nil
|
|
end
|
|
for i, v in ipairs(self.pre_channel_list) do
|
|
if v then
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
end
|
|
|
|
for i, v in ipairs(self.pre_cache_item_list) do
|
|
if v then
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
end
|
|
for i, v in ipairs(self.event_list) do
|
|
self.model:UnBind(v)
|
|
v = nil
|
|
end
|
|
|
|
if self.bind_guild_id then
|
|
RoleManager:getInstance():GetMainRoleVo():UnBind(self.bind_guild_id)
|
|
self.bind_guild_id = nil
|
|
end
|
|
|
|
if self.notice_event_id then
|
|
self.model:UnBind(self.notice_event_id)
|
|
self.notice_event_id = nil
|
|
end
|
|
|
|
if self.change_limit_way_id then
|
|
self.model:UnBind(self.change_limit_way_id)
|
|
self.change_limit_way_id = nil
|
|
end
|
|
|
|
|
|
for k,v in pairs(self.limit_btn_list) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
self.limit_btn_list = {}
|
|
|
|
end
|
|
|
|
function ChatView:CancelSendTimer()
|
|
if self.send_timer_id then
|
|
GlobalTimerQuest:CancelQuest(self.send_timer_id)
|
|
self.send_timer_id = nil
|
|
end
|
|
end
|
|
|
|
function ChatView:LoadTabbarPrefab()
|
|
local function call_back(objs)
|
|
if self._use_delete_method then
|
|
return
|
|
end
|
|
self.tabbar_prefab = objs[0]
|
|
self.chatItem_prefab = objs[1]
|
|
self:RefeshTabbar()
|
|
end
|
|
lua_resM:loadPrefabs(self, "chat", {"chatBarBtn", "chatItem"}, call_back)
|
|
end
|
|
|
|
function ChatView:LoadSuccess()
|
|
self.transform.sizeDelta = Vector2(ScreenWidth, ScreenHeight)
|
|
self.bg = self:GetChild("bg")
|
|
self.content_bg = self:GetChild("content_bg")
|
|
self.tabbar_con = self:GetChild("tabbar_con")
|
|
self.bottom_img = self:GetChild("bottom_img")
|
|
self.bottom_con = self:GetChild("bottom_con")
|
|
self.bottom_con2 = self:GetChild("bottom_con2")
|
|
self.standard_point = self:GetChild("standard_point")
|
|
self.scroll_content = self:GetChild("ScrollView/Viewport/Content")
|
|
self.static_system_text_tr = self:GetChild("static/systemCon/contentText")
|
|
self.static_player_text_tr = self:GetChild("static/playerCon/contentText")
|
|
self.static_mainRole_text_tr = self:GetChild("static/mainRoleCon/contentText")
|
|
self.shieldContent_tr = self:GetChild("shieldChannelCon/ScrollView/Viewport/Content")
|
|
|
|
self.hasHorn = self:GetChild("content_bg/hornCon/hasHorn"):GetComponent("Text")
|
|
self.curHorn = self:GetChild("content_bg/hornCon/curHorn"):GetComponent("Text")
|
|
self.crossChatTime = self:GetChild("content_bg/crossChatCon/curHorn"):GetComponent("Text")
|
|
self.has_cross_horn = self:GetChild("content_bg/crossChatCon/hasHorn"):GetComponent("Text")
|
|
|
|
self.not_read_text = self:GetChild("bottomTipCon/notReadCon/not_read_text"):GetComponent("Text")
|
|
self.sendBtn_text = self:GetChild("bottom_con/sendBtn/Text"):GetComponent("TextMeshProUGUI")
|
|
self.bottom_con2_text = self:GetChild("bottom_con2/Text"):GetComponent("Text")
|
|
|
|
self.static_system_text = self:GetChild("static/systemCon/contentText"):GetComponent("Text")
|
|
self.static_player_text = self:GetChild("static/playerCon/contentText"):GetComponent("Text")
|
|
self.static_mainRole_text = self:GetChild("static/mainRoleCon/contentText"):GetComponent("Text")
|
|
self.shieldBtntext = self:GetChild("shieldChannelCon/shieldTxtBtn/text"):GetComponent("Text")
|
|
|
|
-- self.lock_state_text.text = "未锁定"
|
|
self.hornAddBtn = self:GetChild("content_bg/hornCon/addBtn").gameObject
|
|
self.crossChatCon = self:GetChild("content_bg/crossChatCon").gameObject
|
|
self.crossChatAddBtn = self:GetChild("content_bg/crossChatCon/addBtn").gameObject
|
|
self.notReadCon = self:GetChild("bottomTipCon/notReadCon").gameObject
|
|
self.hornCon = self:GetChild("content_bg/hornCon").gameObject
|
|
self.noGuildCon = self:GetChild("noGuildCon").gameObject
|
|
self.addGuildBtn = self:GetChild("noGuildCon/addGuildBtn").gameObject
|
|
self.input_con = self:GetChild("bottom_con/TextInput").gameObject
|
|
self.voiceBtn = self:GetChild("bottom_con/border/voiceBtn").gameObject
|
|
self.faceBtn = self:GetChild("bottom_con/border/faceBtn").gameObject
|
|
self.sendBtn = self:GetChild("bottom_con/sendBtn").gameObject
|
|
self.ScrollViewCon = self:GetChild("ScrollView").gameObject
|
|
self.closeBtn = self:GetChild("bg/closeBtn").gameObject
|
|
self.shieldBtn = self:GetChild("shieldBtn").gameObject
|
|
self.shieldImg = self:GetChild("shieldBtn/Image").gameObject
|
|
self.alpha_btn = self:GetChild("AlphaBtn").gameObject
|
|
self.individualBtn = self:GetChild("individualBtn").gameObject
|
|
self.individual_RedPoint = self:GetChild("individualBtn/redPoint").gameObject
|
|
self.goTeamBtn = self:GetChild("bottomTipCon/goTeamBtn").gameObject
|
|
self.lockBtn = self:GetChild("LockBtn").gameObject
|
|
self.shieldTxtBtn = self:GetChild("shieldChannelCon/shieldTxtBtn").gameObject
|
|
self.shieldChannelCon = self:GetChild("shieldChannelCon").gameObject
|
|
self.shieldChannelScrv = self:GetChild("shieldChannelCon/ScrollView").gameObject
|
|
self.limitBtn_true_obj = self:GetChild("shieldChannelCon/shieldTxtBtn/limitBtn_true").gameObject
|
|
|
|
self.voiceImg = self:GetChild("bottom_con/border/voiceBtn"):GetComponent("Image")
|
|
self.lock_img = self:GetChild("LockBtn"):GetComponent("Image")
|
|
self.bg_img = self:GetChild("bg/bg_img"):GetComponent("Image")
|
|
--lua_resM:setOutsideImageSprite(self,self.noGuild_img,GameResPath.GetCommonImage("com_girl3"),false)
|
|
self.input_text = self:GetChild("bottom_con/TextInput"):GetComponent("InputField")
|
|
self.ScrollView = self:GetChild("ScrollView"):GetComponent("RectTransform")
|
|
self.scrollView_original_y = self.ScrollView.anchoredPosition.y
|
|
self.scroll_rect = self:GetChild("ScrollView"):GetComponent("ScrollRect")
|
|
self.bg_rawImge = self:GetChild("bg"):GetComponent("Image")
|
|
-- self.lock_toggle = self:GetChild("Toggle"):GetComponent("Toggle")
|
|
|
|
lua_resM:setOutsideImageSprite(self,self.bg_rawImge,GameResPath.GetChatBg("chat_view_bg"),false)
|
|
end
|
|
|
|
function ChatView:RefeshTabbar()
|
|
local vo = nil
|
|
local item = nil
|
|
for i = 1, #Config.ConfigChat.channel_level do
|
|
vo = Config.ConfigChat.channel_level[i]
|
|
if (vo.channel ~= ChatModel.CHANNEL_CROSS and
|
|
vo.channel ~= ChatModel.CHANNEL_REPLY and
|
|
vo.channel ~= ChatModel.CHANNEL_COUNTRY ) or -- 非跨服/本国/答题
|
|
------------------------------------------------
|
|
(vo.channel == ChatModel.CHANNEL_CROSS and -- 大跨服(要满足条件)
|
|
-- RoleManager.Instance.mainRoleInfo.level >= vo.level and
|
|
vo.open_day and ServerTimeModel:getInstance():GetOpenServerDay() >= vo.open_day ) or
|
|
-----------------------------------------------------
|
|
(vo.channel == ChatModel.CHANNEL_COUNTRY and -- 本国(要满足条件)
|
|
RoleManager.Instance.mainRoleInfo.level >= vo.level and
|
|
vo.open_day and ServerTimeModel:getInstance():GetOpenServerDay() >= vo.open_day )
|
|
then
|
|
|
|
item = self.tabbar_list[i]
|
|
if item == nil then
|
|
item = ChatBarBtn.New(self.tabbar_con, self.tabbar_prefab)
|
|
self.tabbar_list[i] = item
|
|
end
|
|
item:SetData(i, vo.channel, vo)
|
|
end
|
|
end
|
|
self:SwitchBar()
|
|
end
|
|
|
|
function ChatView:InitEvent()
|
|
local function onOrientationChange()
|
|
self.transform.anchoredPosition = Vector2(ClientConfig.iphone_x_offset_left, 0)
|
|
end
|
|
self.orientation_change_id = GlobalEventSystem:Bind(EventName.ORIENTATION_DID_CHANGE, onOrientationChange)
|
|
|
|
local function onClickBtnHandler(target)
|
|
if target == self.alpha_btn then
|
|
if self.model.curr_bar_index == ChatModel.CHANNEL_GUILD then
|
|
self.model:SetGuildChannelRedDot(false)
|
|
end
|
|
self:Close()
|
|
elseif target == self.faceBtn then
|
|
GlobalEventSystem:Fire(EventName.OPEN_INDIVIDUATION_VIEW, self.model.curr_individuation_bar_index, -1, 60.5)
|
|
if self.is_show_shield then
|
|
self:SetShieldBtnState()
|
|
end
|
|
elseif target == self.sendBtn then
|
|
local content = self.input_text.text
|
|
local tmpArgs = self.model:GetAllArgsText(content)
|
|
content = self.model:GetHyperlinkText(content)
|
|
-- if self.model.curr_channel == ChatModel.CHANNEL_CROSS then
|
|
-- if string.find(content, "<a@goods4@") then
|
|
-- Message.show("跨服频道无法发送背包物品","fault")
|
|
-- return
|
|
-- elseif string.find(content, "<a@pos@") then
|
|
-- Message.show("跨服频道无法发送坐标","fault")
|
|
-- return
|
|
-- end
|
|
-- end
|
|
GlobalEventSystem:Fire(EventName.CLOSE_CHAT_BAG_VIEW)
|
|
GlobalEventSystem:Fire(EventName.CLOSE_INDIVIDUATION_VIEW)
|
|
self:SendMsg()
|
|
elseif target == self.individualBtn then
|
|
if RoleManager.Instance.mainRoleInfo.level >= Config.Modulesub["112@1"].open_lv then
|
|
OpenFun.Open(112,1)
|
|
else
|
|
Message.show(Config.Modulesub["112@1"].open_lv.."级开启聊天装扮功能","fault")
|
|
end
|
|
elseif target == self.closeBtn then
|
|
self:Close()
|
|
elseif target == self.shieldBtn then
|
|
local key = GameSettingManager.blockChannel[self.model.curr_channel]
|
|
local isShield = GameSettingManager:getInstance():GetBlockProperty(key)
|
|
GameSettingManager:getInstance():SetBlockProperty(key, not isShield)
|
|
self:RefreshShieldBtn()
|
|
Message.show(isShield and "开启语音自动播放" or "屏蔽语音自动播放")
|
|
elseif target == self.lockBtn then
|
|
local rect_height = self.scroll_rect.transform.sizeDelta.y
|
|
local content_height = self.scroll_content.sizeDelta.y
|
|
if content_height < rect_height + 80 then
|
|
self.is_lock = false
|
|
-- self.lock_state_text.text = "未锁定"
|
|
lua_resM:setImageSprite(self,self.lock_img,"chat_asset","icon_chat_unlocked")
|
|
return
|
|
end
|
|
self.is_lock = not self.is_lock
|
|
|
|
-- self.lock_state_text.text = self.is_lock and "锁定" or "未锁定"
|
|
if self.is_lock then
|
|
self.scroll_posy_in_lock = self.scroll_content.localPosition.y
|
|
lua_resM:setImageSprite(self,self.lock_img,"chat_asset","icon_chat_locking")
|
|
else
|
|
lua_resM:setImageSprite(self,self.lock_img,"chat_asset","icon_chat_unlocked")
|
|
end
|
|
elseif target == self.hornAddBtn then
|
|
GlobalEventSystem:Fire(EventName.OPEN_ASSIGN_BUY_VIEW, self.horn_id)
|
|
-- GlobalEventSystem:Fire(EventName.OPEN_QUICK_BUY_VIEW,self.horn_id,1,ShopType.Binding)
|
|
--GlobalEventSystem:Fire(EventName.OPEN_SHOP_VIEW, 2, self.horn_id)
|
|
elseif target == self.crossChatAddBtn then
|
|
GlobalEventSystem:Fire(EventName.OPEN_ASSIGN_BUY_VIEW, self.cross_horn_id)
|
|
-- GlobalEventSystem:Fire(EventName.OPEN_QUICK_BUY_VIEW,self.horn_id,1,ShopType.Binding)
|
|
--GlobalEventSystem:Fire(EventName.OPEN_SHOP_VIEW, 2, self.horn_id)
|
|
elseif target == self.addGuildBtn then
|
|
-- GlobalEventSystem:Fire(EventName.OPEN_GUILD_APPLY_VIEW)
|
|
OpenFun.Open(400, 0)
|
|
self:Close()
|
|
elseif target == self.goTeamBtn then
|
|
GlobalEventSystem:Fire(EventName.OPEN_TEAM_LIST_VIEW)
|
|
self:Close()
|
|
elseif target == self.notReadCon then
|
|
self:ReLayoutScroll(true)
|
|
self:ShowNotReadMsgNum(0, true)
|
|
elseif target == self.shieldTxtBtn then
|
|
self:SetShieldBtnState()
|
|
end
|
|
end
|
|
AddClickEvent(self.faceBtn, onClickBtnHandler, LuaSoundManager.SOUND_UI.NONE)
|
|
AddClickEvent(self.sendBtn, onClickBtnHandler)
|
|
AddClickEvent(self.alpha_btn, onClickBtnHandler)
|
|
AddClickEvent(self.individualBtn, onClickBtnHandler, LuaSoundManager.SOUND_UI.NONE)
|
|
AddClickEvent(self.closeBtn, onClickBtnHandler)
|
|
AddClickEvent(self.shieldBtn, onClickBtnHandler)
|
|
-- AddClickEvent(self.lock_toggle.gameObject, onClickBtnHandler)
|
|
AddClickEvent(self.lockBtn, onClickBtnHandler)
|
|
AddClickEvent(self.hornAddBtn, onClickBtnHandler)
|
|
AddClickEvent(self.crossChatAddBtn, onClickBtnHandler)
|
|
AddClickEvent(self.addGuildBtn, onClickBtnHandler, LuaSoundManager.SOUND_UI.NONE)
|
|
AddClickEvent(self.goTeamBtn, onClickBtnHandler, LuaSoundManager.SOUND_UI.NONE)
|
|
AddClickEvent(self.notReadCon, onClickBtnHandler)
|
|
AddClickEvent(self.shieldTxtBtn, onClickBtnHandler)
|
|
local function onDragBeginHandler(target,x,y)
|
|
self.drag_start_pos_y = self.scroll_content.anchoredPosition.y
|
|
self.scroll_content_drag = true
|
|
self.scroll_content_drag2 = true
|
|
end
|
|
AddDragBeginEvent(self.scroll_rect.gameObject, onDragBeginHandler)
|
|
-- AddDragBeginEvent(self.hornScrollCon, onDragBeginHandler)
|
|
|
|
local function onDraEndgHandler(target,x,y)
|
|
self.scroll_content_drag = false
|
|
end
|
|
AddDragEndEvent(self.scroll_rect.gameObject, onDraEndgHandler)
|
|
-- AddDragEndEvent(self.hornScrollCon, onDraEndgHandler)
|
|
local function onValueChanged()
|
|
if not self.scroll_content_drag2 and not self.scroll_content_drag then
|
|
return
|
|
end
|
|
local rect_height = self.scroll_rect.transform.sizeDelta.y --ScrollView 的高度
|
|
local content_height = self.scroll_content.sizeDelta.y --Contenet的高度
|
|
local pos_y = self.scroll_content.localPosition.y
|
|
if pos_y <= -10 or pos_y + rect_height > content_height + 10 then
|
|
return
|
|
end
|
|
self:CalcuInHideItem()
|
|
self:CheckItemCanHide()
|
|
self:CheckFrontItemShow()
|
|
self:CheckBackItemShow()
|
|
|
|
self.is_lock = content_height - pos_y >= rect_height + 90
|
|
-- self.lock_state_text.text = self.is_lock and "锁定" or "未锁定"
|
|
if self.is_lock then
|
|
self.scroll_posy_in_lock = self.scroll_content.localPosition.pos_y
|
|
lua_resM:setImageSprite(self, self.lock_img, "chat_asset", "icon_chat_locking")
|
|
else
|
|
lua_resM:setImageSprite(self, self.lock_img, "chat_asset", "icon_chat_unlocked")
|
|
end
|
|
if #self.cache_not_read_list > 0 then
|
|
local new_item_height = self.cache_not_read_list[1]
|
|
if new_item_height and (pos_y + self.ScrollView.sizeDelta.y) - new_item_height >= 0 then
|
|
table_remove(self.cache_not_read_list, 1)
|
|
self:ShowNotReadMsgNum(-1)
|
|
end
|
|
end
|
|
if content_height - pos_y <= 20 then --锁定
|
|
self.scroll_content_drag2 = false
|
|
end
|
|
end
|
|
self.scroll_rect.onValueChanged:AddListener(onValueChanged)
|
|
-- self.horn_scroll_rect.onValueChanged:AddListener(onValueChanged)
|
|
GlobalEventSystem:Fire(EventName.ADD_RECORD_BTN, self.voiceBtn, {channel = -1, rect = {x = -302, y = 0, w = 57, h = 57}, dis = 300})
|
|
|
|
local function vip_change()
|
|
self:RefeshTabbar()
|
|
end
|
|
|
|
self.vip_event_id = RoleManager:getInstance():GetMainRoleVo():BindOne("vip_flag", vip_change)
|
|
|
|
local function onUpdateSendTime()
|
|
self:UpdateSendTime()
|
|
end
|
|
self.update_time_id = self.model:Bind(ChatModel.UPDATE_SEND_TIME, onUpdateSendTime)
|
|
|
|
local function onSelecteItemHandler(item)
|
|
self:SetCurrTabbarIndex(item.channel)
|
|
self:SwitchBar()
|
|
GlobalEventSystem:Fire(EventName.ADD_RECORD_BTN, self.voiceBtn, {channel = item.channel, rect = {x = -302, y = 0, w = 57, h = 57}, dis = 300})
|
|
end
|
|
self.selected_item_bind_id = self.model:Bind(ChatModel.SELECT_CHAT_VIEW_TARBAR, onSelecteItemHandler)
|
|
|
|
local function onRefresh()
|
|
self:SwitchBar()
|
|
end
|
|
self.refresh_event_id = self.model:Bind(ChatModel.REFRESH_VIEW, onRefresh)
|
|
|
|
local function onSelectFaceItemHandler(item)
|
|
if item and not self.model.horn_view_is_open 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
|
|
else
|
|
Message.show(string.format("最多可输入%d个字符", self.send_limit),"fault")
|
|
end
|
|
end
|
|
end
|
|
self.select_faceItem_id = self.model:Bind(ChatModel.SELECT_FACE_ITEM, onSelectFaceItemHandler)
|
|
|
|
local function onSelectTextFaceItemHandler(item)
|
|
if item and not self.model.horn_view_is_open then
|
|
if self.model.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.model.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.model:Bind(ChatModel.SELECT_TEXT_FACE_ITEM, onSelectTextFaceItemHandler)
|
|
|
|
local function onSelectHistoryTextItemHandler(str)
|
|
self.input_text.text = str
|
|
end
|
|
table_insert(self.event_list, self.model: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.model:Bind(ChatModel.CLICK_POS_BTN, onClickPosBtnHandler))
|
|
|
|
local function onSelectCoordHandler(findVo)
|
|
if findVo then
|
|
local scene_name = SceneManager.Instance:GetSceneName()
|
|
local str = "<" .. scene_name .. "(" .. findVo.x .. "," .. findVo.y .. ")>"
|
|
self:ReplaceInputTextMark(str)
|
|
local content = string.format("<a@scene2@%s@%s@%s></a>", findVo.sceneId, findVo.x, findVo.y)
|
|
local key, argStr = self.model:GetSpecFindStr()
|
|
if key ~= "" then content = string.gsub(content, "scene2", key) end
|
|
if argStr ~= "" then content = string.gsub(content, "></a>", argStr.."></a>") end
|
|
self.model:AddArgs(str, {"", content})
|
|
end
|
|
end
|
|
self.select_coord_id = self.model:Bind(ChatModel.SELECT_COORD_ITEM, onSelectCoordHandler)
|
|
|
|
local function onSelectGoodItemHandler(goodVo)
|
|
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.model:AddArgs(str, {args, content})
|
|
-- self.model.curr_chat_args = "{goods,"..goodVo.type_id..","..goodVo.goods_id.."}"
|
|
end
|
|
end
|
|
self.select_goodItem_id = self.model:Bind(ChatModel.SELECT_GOOD_ITEM, onSelectGoodItemHandler)
|
|
|
|
local function onSelectOtherPlayerHandler(name)
|
|
local player_name = name or ""
|
|
local str = "<" .. "@" .. player_name ..">"
|
|
self:ReplaceInputTextMark(str)
|
|
local content = string.format("<a@playername@%s></a>", player_name)
|
|
local args = string.format("{playername,%s}", player_name)
|
|
self.model:AddArgs(str, {"", content})
|
|
end
|
|
self:BindEvent(self.model, ChatModel.SELECT_OTHER_PLAYER, onSelectOtherPlayerHandler)
|
|
|
|
local function onAddMsgHandler(info)
|
|
self:AddMsgItem(info, true,nil,nil,nil,nil,true)
|
|
end
|
|
self.add_msg_id = self.model:Bind(ChatModel.ADD_NEW_MSG, onAddMsgHandler)
|
|
|
|
local function onShowTabRedPointHandler(all_chat_list_count)
|
|
local item = nil
|
|
for i, v in ipairs(self.tabbar_list) do
|
|
item = v
|
|
if all_chat_list_count[item.info.channel] ~= nil and
|
|
all_chat_list_count[item.info.channel] > 0 and
|
|
( item.info.channel == ChatModel.CHANNEL_INVITE or
|
|
item.info.channel == ChatModel.CHANNEL_GUILD ) then
|
|
item:ShowRedPoint()
|
|
else
|
|
item:HideRedPoint()
|
|
if item.info.channel == ChatModel.CHANNEL_GUILD then -- 外部社团按钮红点
|
|
self.model:SetGuildChannelRedDot(false)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
self.show_tab_red_point_id = self.model:Bind(ChatModel.SHOW_TAB_RED_POINT, onShowTabRedPointHandler)
|
|
|
|
self.bind_update_reg_text = self.model:Bind(ChatModel.BROADCAST_VOICE_TEXT, function(scmd)
|
|
local offset = 0
|
|
local curr_channel_list = self.all_chatItem_list[self.model.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)
|
|
|
|
local function onSendMsg(str)
|
|
self.input_text.text = str
|
|
self:SendMsg()
|
|
end
|
|
self.send_event_id = self.model:Bind(ChatModel.SEND_MSG_IN_VIEW, onSendMsg)
|
|
|
|
self.input_text.onValueChanged:AddListener(function()
|
|
local is_code_cheat = string.find(self.input_text.text,"@RunCode:")
|
|
self:SetCharacterLimit(is_code_cheat and 9999 or false)--秘籍需要解除字符数限制
|
|
-------------------------
|
|
local len = utf8len(self.input_text.text)
|
|
if len > self.send_limit and (not is_code_cheat) then
|
|
self.input_text.text = self.legal_text_str or ""
|
|
self.tip_time = self.tip_time or 0
|
|
if Status.NowTime - self.tip_time > 0.1 then
|
|
Message.show(string.format("最多可输入%d个字符", self.send_limit),"fault")
|
|
self.tip_time = Status.NowTime
|
|
end
|
|
return
|
|
end
|
|
self.legal_text_str = self.input_text.text
|
|
end)
|
|
|
|
local function onSel(bool)
|
|
-- self.bag_select_bg:SetActive(bool)
|
|
-- self.ScrollViewCon:SetActive(not bool)
|
|
end
|
|
self.select_bag_id = self.model:Bind(ChatModel.SHOW_BAG_SELECT_BG, onSel)
|
|
|
|
local function show_individual_redPoint()
|
|
self:ShowIndividualRedPoint()
|
|
end
|
|
self.show_individual_redPoint_id = GlobalEventSystem:Bind(EventName.REFRESH_CHATDRESS_RED_DOT, show_individual_redPoint)
|
|
|
|
local function update_cross_horn(count)
|
|
|
|
if self.model.curr_channel ~= ChatModel.CHANNEL_CROSS and
|
|
self.model.curr_channel ~= ChatModel.CHANNEL_COUNTRY then
|
|
return
|
|
end
|
|
local str = self.model.crossChatTime > 9999999 and "无限" or self.model.crossChatTime
|
|
self.crossChatTime.text = "剩余发言次数:"..str
|
|
end
|
|
table_insert(self.event_list, self.model:Bind(ChatModel.CROSS_HORN_HAS_CHANGE, update_cross_horn))
|
|
|
|
local function update_horn()
|
|
if self.model.curr_channel == ChatModel.CHANNEL_HORN then
|
|
self:SetHornNum()
|
|
elseif self.model.curr_channel == ChatModel.CHANNEL_CROSS then -- 跨服聊天次数限制
|
|
self.model:Fire(ChatModel.REQUEST_CCMD_EVENT,11011,ChatModel.CHANNEL_CROSS)
|
|
self:SetCrossHornNum()
|
|
elseif self.model.curr_channel == ChatModel.CHANNEL_CROSS then -- 本服聊天次数限制
|
|
self.model:Fire(ChatModel.REQUEST_CCMD_EVENT,11011,ChatModel.CHANNEL_COUNTRY)
|
|
self:SetCrossHornNum()
|
|
end
|
|
end
|
|
table_insert(self.event_list, self.model:Bind(ChatModel.HORN_HAS_CHANGE, update_horn))
|
|
|
|
local function onUpdateHorn()
|
|
if self.model.curr_channel ~= ChatModel.CHANNEL_HORN then
|
|
return
|
|
end
|
|
self:SetCurHorn()
|
|
end
|
|
self.horn_event_id = self.model:Bind(ChatModel.UPDATE_HORNTV_NUM, onUpdateHorn)
|
|
local function onGuildChange()
|
|
if not RoleManager.Instance:GetMainRoleVo().guild_id then
|
|
self.model.all_chat_list[ChatModel.CHANNEL_GUILD] = nil
|
|
end
|
|
if self.model.curr_channel == ChatModel.CHANNEL_GUILD then
|
|
self:SetCurrTabbarIndex(ChatModel.CHANNEL_GUILD)
|
|
self:SwitchBar()
|
|
self.noGuildCon:SetActive(not RoleManager.Instance:GetMainRoleVo().guild_id or RoleManager.Instance:GetMainRoleVo().guild_id == 0)
|
|
|
|
end
|
|
end
|
|
self.bind_guild_id = RoleManager:getInstance():GetMainRoleVo():BindOne("guild_id", onGuildChange)
|
|
|
|
|
|
local function onRefreshNotice(notice_id)
|
|
|
|
self:DelNoticeChatItem(notice_id)
|
|
end
|
|
self.notice_event_id = self.model:Bind(ChatModel.DEL_NOTICE_CHAT_ITEM, onRefreshNotice)
|
|
|
|
local function changeIimitWay( index ) --占时没用到,在选择屏蔽打钩后调取
|
|
-- self.co:SetActive(false)
|
|
-- self.limit_way.up_img:SetActive(true)
|
|
|
|
self.shieldChannelScrv:SetActive(false)
|
|
local color = ColorUtil:GetColor(index)
|
|
self.shieldBtntext.text = string.format("<color=%s>%s</color>",color,ChatModel.LIMIY_WAY_NAME[index])
|
|
end
|
|
self.change_limit_way_id = self.model:Bind(ChatModel.CHANGE_LIMIT_WAY, changeIimitWay)
|
|
|
|
end
|
|
|
|
function ChatView:SendMsg()
|
|
local channel = self.model.curr_bar_index
|
|
|
|
if self.model:CheckCurrentTimeCanSend(channel, self.send_interval) then
|
|
local content = self.input_text.text
|
|
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
|
|
elseif self.input_text.text == "@##P@" then
|
|
local cfg, scmd = {subtype = ChatModel.CHANNEL_SYSTEM}, {}
|
|
for i = 1, 10 do
|
|
GlobalEventSystem:Fire(EventName.SHOW_CHUANWEN, "测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试"..i, cfg, scmd)
|
|
end
|
|
return
|
|
end]]
|
|
-------------------------
|
|
|
|
--[[ if RoleManager.Instance:GetMainRoleVo().GM == 0 then
|
|
local is_show_word = false
|
|
local fun,tbl
|
|
for k, v in pairs(Config.Goods) do ---如果是发送物品的物品名字被屏蔽就跳过
|
|
fun = loadstring(v)
|
|
tbl = fun()
|
|
local pass_name = "<"..Trim(tbl.goods_name)..">"
|
|
if Trim(content) == pass_name then
|
|
is_show_word = true
|
|
break
|
|
end
|
|
end
|
|
if is_show_word == false then
|
|
local _, title_filter = LanguageFilter.FilterMsg(content)
|
|
if title_filter == false then
|
|
Message.show("内容有敏感词")
|
|
return
|
|
end
|
|
end
|
|
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.model:GetAllArgsText(content)
|
|
content = self.model:GetHyperlinkText(content)
|
|
self.model:Fire(ChatModel.SEND_MSG, self.model.curr_bar_index, content, self.chating_key_id, tmpArgs)
|
|
self.input_text.text = ""
|
|
self.model.chat_args_dic = {}
|
|
end
|
|
else
|
|
if self.input_text.text ~= "" then
|
|
Message.show("发送频率过快,请销后再试...","fault")
|
|
end
|
|
end
|
|
end
|
|
|
|
function ChatView:SetSendTimeText()
|
|
if self._use_delete_method then return end
|
|
local channel = self.model.curr_bar_index
|
|
local time = self.model:GetPassTimeFromSend(channel, self.send_interval)
|
|
if time > 0 then
|
|
local str = math.ceil(time) .. "s"
|
|
self.sendBtn_text.text = str
|
|
else
|
|
self:CancelSendTimer()
|
|
self.sendBtn_text.text = "发送"
|
|
end
|
|
return time
|
|
end
|
|
|
|
function ChatView:UpdateSendTime()
|
|
local time = self:SetSendTimeText()
|
|
if time > 0 then
|
|
self:CancelSendTimer()
|
|
local function onSendTimerPlaying()
|
|
self:SetSendTimeText()
|
|
end
|
|
self.send_timer_id = GlobalTimerQuest:AddPeriodQuest(onSendTimerPlaying, 1, -1)
|
|
end
|
|
end
|
|
|
|
--添加一个聊天信息 autoLayout是否自动布局 record 是不是要记录这个item为最后创建的item not_from_model --是不是新消息
|
|
function ChatView:AddMsgItem(info, autoLayout, custom_height, not_from_model, custom_line, is_delay_callback,new_msg)
|
|
|
|
if self.view_is_close then return end
|
|
local curr_channel = self.model.curr_bar_index
|
|
if info.channel == ChatModel.CHANNEL_HORN then
|
|
if self.model.curr_channel ~= ChatModel.CHANNEL_WORLD and self.model.curr_channel ~= ChatModel.CHANNEL_HORN and self.model.curr_channel ~= ChatModel.CHANNEL_GENERAL then
|
|
return
|
|
end
|
|
else
|
|
if info.channel ~= self.model.curr_channel and self.model.curr_channel ~= ChatModel.CHANNEL_GENERAL then
|
|
return
|
|
end
|
|
end
|
|
|
|
--if curr_channel ~= info.channel and info.channel ~= ChatModel.CHANNEL_HORN then return end
|
|
-- if info.channel == ChatModel.CHANNEL_HORN and curr_channel ~= ChatModel.CHANNEL_WORLD then return end
|
|
if info.channel == ChatModel.CHANNEL_NONE then return end
|
|
if info.channel == ChatModel.CHANNEL_CECRET then return end
|
|
-- 没社团时不显示社团活动消息
|
|
if info.channel == ChatModel.CHANNEL_GUILD and (not RoleManager.Instance:GetMainRoleVo().guild_id or RoleManager.Instance:GetMainRoleVo().guild_id == 0) then return end
|
|
|
|
if self.is_init_operate and not not_from_model then
|
|
table_insert(self.need_add_msg, {info = info, autoLayout = autoLayoutm, custom_height = custom_height})
|
|
return
|
|
end
|
|
if not custom_line then
|
|
if self.pre_renderer_chatItem and self.pre_renderer_chatItem.info and not self.pre_renderer_chatItem:IsLineItem() and curr_channel ~= ChatModel.CHANNEL_SYSTEM 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.model:PackChatInfo(curr_channel, info.time, info.key_id)
|
|
-- self:AddMsgItem(lineInfo, false)
|
|
self:AddMsgItem(lineInfo, not not_from_model, custom_height, not_from_model)
|
|
end
|
|
end
|
|
end
|
|
|
|
local curr_channel_list = self.all_chatItem_list[curr_channel]
|
|
|
|
if curr_channel_list == nil then
|
|
curr_channel_list = {}
|
|
self.all_chatItem_list[curr_channel] = curr_channel_list
|
|
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, self.layer_name,is_delay_callback,self.is_initialized)--, self.chatItem_prefab)
|
|
end
|
|
local function do_next(new_item_height)
|
|
if #curr_channel_list < ChatModel.MAX_LEN_LIST[curr_channel] then
|
|
table_insert(curr_channel_list, new_item)
|
|
else
|
|
table_insert(self.pre_channel_list, new_item)
|
|
end
|
|
if autoLayout then
|
|
self:ReLayoutScroll()
|
|
end
|
|
if new_item:IsLineItem() then
|
|
new_item:SetLineTimeColor(ColorType.WHITE)
|
|
new_item:SetLineSize()
|
|
end
|
|
if self.is_init_operate and not self.pre_renderer_chatItem and not new_item:IsLineItem() then
|
|
self.pre_renderer_chatItem = new_item
|
|
end
|
|
if not self.is_init_operate and not new_item:IsLineItem() then
|
|
self.pre_renderer_chatItem = new_item
|
|
end
|
|
|
|
--未读消息处理
|
|
if self.is_lock and new_msg then
|
|
if (not info.player_id or info.player_id ~= RoleManager.Instance:GetMainRoleId()) and not info.is_line then
|
|
self:ShowNotReadMsgNum(1)
|
|
table_insert(self.cache_not_read_list,new_item_height)
|
|
end
|
|
else
|
|
self:ShowNotReadMsgNum(0, true)
|
|
end
|
|
end
|
|
if custom_height then
|
|
new_item:SetData(info, custom_height)
|
|
self:SetCurItemData({height = custom_height,item = new_item,info = info})
|
|
do_next(custom_height)
|
|
else
|
|
local function call_back(height)
|
|
new_item:SetData(info, self.curr_channel_height)
|
|
self:SetCurItemData({height = custom_height,item = new_item,info = info})
|
|
self.curr_channel_height = self.curr_channel_height + height
|
|
do_next(self.curr_channel_height)
|
|
end
|
|
self:GetItemHeight(info, call_back)
|
|
end
|
|
|
|
self.scroll_rect.enabled = true
|
|
end
|
|
|
|
--增或减就行了
|
|
function ChatView:ShowNotReadMsgNum(add_num, is_reset)
|
|
if is_reset then
|
|
-- self.notReadCon:SetActive(false) -- 未读消息框取消显示
|
|
self.cache_not_read_list = {}
|
|
self.not_read_count = 0
|
|
self.not_read_text.text = ""
|
|
return
|
|
end
|
|
self.not_read_count = self.not_read_count and self.not_read_count + add_num or 0
|
|
if self.not_read_count <= 0 then
|
|
self:ShowNotReadMsgNum(0, true)
|
|
return
|
|
end
|
|
-- self.notReadCon:SetActive(true)-- 未读消息框取消显示
|
|
self.not_read_text.text = "您有"..self.not_read_count.."条消息未读"
|
|
end
|
|
|
|
--改变交流类型 文本或者语音
|
|
function ChatView:ChangeTalkType()
|
|
if self.is_talk_to_text then
|
|
lua_resM:setImageSprite(self, self.voiceImg, "chat_asset", "chat_ui_2")
|
|
self.input_con:SetActive(true)
|
|
self.sendBtn:SetActive(true)
|
|
else
|
|
lua_resM:setImageSprite(self, self.voiceImg, "chat_asset", "chat_ui_3")
|
|
self.input_con:SetActive(false)
|
|
self.sendBtn:SetActive(false)
|
|
end
|
|
end
|
|
|
|
function ChatView:Open(channel)
|
|
MainUIModel:getInstance().main_voice_channel = self.model.curr_channel == 0 and ChatModel.CHANNEL_WORLD or self.model.curr_channel
|
|
self:SetCurrTabbarIndex(channel)
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function ChatView:SetCurrTabbarIndex(channel)
|
|
self.model.pre_bar_index = self.model.curr_bar_index
|
|
self.model.curr_bar_index = channel or self.model.curr_bar_index
|
|
end
|
|
|
|
function ChatView:Close()
|
|
self.model.curr_channel = 0
|
|
if self.is_moving == false then
|
|
local function onCompleted()
|
|
--保存聊天记录
|
|
CookieWrapper.Instance:WriteChatHistroy()
|
|
CookieWrapper.Instance.chat_histroy_id = nil
|
|
self.is_moving = false
|
|
self.model.clicked_role_item = nil
|
|
BaseView.Close(self)
|
|
end
|
|
self.is_moving = true
|
|
TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POS, Vector2(-SrcScreenWidth / 2, 0), 0.1, onCompleted)
|
|
end
|
|
end
|
|
|
|
function ChatView:ShowChannelObj(curr_channel)
|
|
if curr_channel == ChatModel.CHANNEL_HORN then
|
|
self.hornCon:SetActive(true)
|
|
self.crossChatCon:SetActive(false)
|
|
self.noGuildCon:SetActive(false)
|
|
self.goTeamBtn:SetActive(false)
|
|
elseif curr_channel == ChatModel.CHANNEL_CROSS or
|
|
curr_channel == ChatModel.CHANNEL_COUNTRY then
|
|
self.hornCon:SetActive(false)
|
|
self.crossChatCon:SetActive(true)
|
|
self.noGuildCon:SetActive(false)
|
|
self.goTeamBtn:SetActive(false)
|
|
else
|
|
self.hornCon:SetActive(false)
|
|
self.crossChatCon:SetActive(false)
|
|
self.noGuildCon:SetActive(false)
|
|
self.goTeamBtn:SetActive(false)
|
|
end
|
|
end
|
|
|
|
function ChatView:SwitchBar()
|
|
-- print('Cat:ChatView.lua[1050] SwitchBar()')
|
|
self:ResetLockState()
|
|
self:CancelGetHeightQuest()
|
|
self:CancelAddMsgTimer()
|
|
GlobalEventSystem:Fire(EventName.CLOSE_INDIVIDUATION_VIEW)
|
|
|
|
local curr_channel = self.model.curr_bar_index
|
|
local tabbar_item
|
|
for k, v in pairs(self.tabbar_list) do
|
|
if v.channel == self.model.curr_bar_index then
|
|
tabbar_item = v
|
|
end
|
|
end
|
|
if tabbar_item then
|
|
self:SetSendFormat(tabbar_item.info)
|
|
self:InitModelInfo(self.model.curr_bar_index)
|
|
self.model:SeletedChatViewTabbar(tabbar_item, true)
|
|
self.model:Fire(ChatModel.SHOW_TAB_RED_POINT, self.model.all_chat_list_count)
|
|
self:UpdateSendTime()
|
|
local pre_channel = self.model.pre_bar_index
|
|
local pre_channel_list = self.all_chatItem_list[pre_channel]
|
|
|
|
if pre_channel_list then
|
|
for i, item in pairs(pre_channel_list) do
|
|
table_insert(self.cache_chatItem_list, item)
|
|
end
|
|
end
|
|
self.all_chatItem_list[pre_channel] = {}
|
|
-- print(TableSize(self.pre_channel_list))
|
|
if self.pre_channel_list then
|
|
for i, item in pairs(self.pre_channel_list) do
|
|
table_insert(self.cache_chatItem_list, item)
|
|
end
|
|
end
|
|
self.pre_channel_list = {}
|
|
|
|
local vo = nil
|
|
local item = nil
|
|
self.curr_channel_height = 0
|
|
self.pre_renderer_chatItem = nil
|
|
local len = 0
|
|
self:ShowChannelObj(curr_channel)
|
|
local vo = RoleManager.Instance:GetMainRoleVo()
|
|
local mainRole_level = vo.level
|
|
local guild_id = vo.guild_id
|
|
-- self.shieldChannelCon:SetActive(false)
|
|
if curr_channel == ChatModel.CHANNEL_INVITE then
|
|
self.bottom_con.gameObject:SetActive(false)
|
|
self.bottom_con2.gameObject:SetActive(true)
|
|
self.bottom_con2_text.text = "请切换其他频道聊天"
|
|
|
|
else
|
|
if mainRole_level >= tabbar_item.info.level or PlatformMgr:getInstance():IsIflyRecord() then
|
|
if curr_channel == ChatModel.CHANNEL_SYSTEM then
|
|
self.bottom_con.gameObject:SetActive(false)
|
|
self.bottom_con2.gameObject:SetActive(true)
|
|
self.bottom_con2_text.text = "请切换其他频道聊天"
|
|
elseif curr_channel == ChatModel.CHANNEL_GENERAL then
|
|
self.bottom_con.gameObject:SetActive(false)
|
|
self.bottom_con2.gameObject:SetActive(true)
|
|
self.bottom_con2_text.text = "请切换其他频道聊天"
|
|
-- self.shieldChannelCon:SetActive(true)
|
|
self.shieldChannelScrv:SetActive(false)
|
|
|
|
elseif curr_channel == ChatModel.CHANNEL_TEAM and not TeamModel:getInstance().in_team then
|
|
self.bottom_con.gameObject:SetActive(false)
|
|
self.bottom_con2.gameObject:SetActive(true)
|
|
self.bottom_con2_text.text = "您当前未加入队伍"
|
|
self.goTeamBtn:SetActive(true)
|
|
elseif curr_channel == ChatModel.CHANNEL_GUILD then
|
|
if guild_id == 0 then
|
|
self.bottom_con.gameObject:SetActive(false)
|
|
self.bottom_con2.gameObject:SetActive(true)
|
|
self.bottom_con2_text.text = "您当前未加入社团"
|
|
else
|
|
self.bottom_con.gameObject:SetActive(true)
|
|
self.bottom_con2.gameObject:SetActive(false)
|
|
self.bottom_con2_text.text = ""
|
|
end
|
|
self.noGuildCon:SetActive(guild_id == 0)
|
|
--[[ elseif curr_channel == ChatModel.CHANNEL_HORN then
|
|
local channel = self.model:GetChannelWithId(curr_channel)
|
|
if RoleManager.Instance.mainRoleInfo.level >= channel.level then
|
|
-- GlobalEventSystem:Fire(EventName.OPEN_HORN_VIEW)
|
|
self.bottom_con.gameObject:SetActive(true)
|
|
self.bottom_con2.gameObject:SetActive(false)
|
|
self.bottom_con2_text.text = ""
|
|
self:SetHornNum()
|
|
self:SetCurHorn()
|
|
else
|
|
self.bottom_con.gameObject:SetActive(false)
|
|
self.bottom_con2.gameObject:SetActive(true)
|
|
self.bottom_con2_text.text = string.format("%d级后可发送喇叭", channel.level)
|
|
-- Message.show(string.format("%d级后可发送喇叭", channel.level))
|
|
end]]
|
|
elseif curr_channel == ChatModel.CHANNEL_CROSS then
|
|
local channel = self.model:GetChannelWithId(curr_channel)
|
|
if RoleManager.Instance.mainRoleInfo.level >= channel.level then
|
|
-- GlobalEventSystem:Fire(EventName.OPEN_HORN_VIEW)
|
|
self.bottom_con.gameObject:SetActive(true)
|
|
self.bottom_con2.gameObject:SetActive(false)
|
|
self.bottom_con2_text.text = ""
|
|
local str = self.model.crossChatTime > 9999999 and "无限" or self.model.crossChatTime
|
|
self.crossChatTime.text = "剩余发言次数:"..str
|
|
self:SetCrossHornNum()
|
|
else
|
|
self.bottom_con.gameObject:SetActive(false)
|
|
self.bottom_con2.gameObject:SetActive(true)
|
|
self.bottom_con2_text.text = string.format("%d级后可开启", channel.level)
|
|
-- Message.show(string.format("%d级后可发送喇叭", channel.level))
|
|
end
|
|
elseif curr_channel == ChatModel.CHANNEL_COUNTRY then
|
|
local channel = self.model:GetChannelWithId(curr_channel)
|
|
if RoleManager.Instance.mainRoleInfo.level >= channel.level then
|
|
self.bottom_con.gameObject:SetActive(true)
|
|
self.bottom_con2.gameObject:SetActive(false)
|
|
self.bottom_con2_text.text = ""
|
|
-- local str = self.model.crossChatTime > 9999999 and "无限" or self.model.crossChatTime
|
|
-- self.crossChatTime.text = "剩余发言次数:"..str
|
|
-- self:SetCrossHornNum()
|
|
else
|
|
self.bottom_con.gameObject:SetActive(false)
|
|
self.bottom_con2.gameObject:SetActive(true)
|
|
self.bottom_con2_text.text = string.format("%d级后可开启", channel.level)
|
|
end
|
|
elseif curr_channel == ChatModel.CHANNEL_WORLD then
|
|
if RoleManager.Instance.mainRoleInfo.level >= Config.Moduleid[110].open_lv then
|
|
self.bottom_con.gameObject:SetActive(true)
|
|
self.bottom_con2.gameObject:SetActive(false)
|
|
else
|
|
self.bottom_con.gameObject:SetActive(false)
|
|
self.bottom_con2.gameObject:SetActive(true)
|
|
self.bottom_con2_text.text = string.format("%d级开启世界频道", Config.Moduleid[110].open_lv)
|
|
end
|
|
-- self.shieldChannelCon:SetActive(true)
|
|
self.shieldChannelScrv:SetActive(false)
|
|
else
|
|
self.bottom_con.gameObject:SetActive(true)
|
|
self.bottom_con2.gameObject:SetActive(false)
|
|
end
|
|
else
|
|
self.bottom_con.gameObject:SetActive(false)
|
|
self.bottom_con2.gameObject:SetActive(true)
|
|
local cfg = ChatModel:getInstance():GetChannelWithId(curr_channel)
|
|
self.bottom_con2_text.text = cfg.tip
|
|
end
|
|
end
|
|
-- self.bottom_con2_text.rectTransform.anchoredPosition = Vector3(240 - self.bottom_con2_text.preferredWidth / 2, 20, 0)
|
|
-- self.bottom_con2_image.rectTransform.anchoredPosition = Vector3(-self.bottom_con2_text.preferredWidth / 2, 0, 0)
|
|
|
|
|
|
self.model:SetChannelGennealList(curr_channel) -- 加入综合频道
|
|
local curr_channel_list = self.model.all_chat_list[curr_channel] --筛出当前频道的聊天数据
|
|
if curr_channel_list then
|
|
self.scroll_rect.enabled = #curr_channel_list > 0
|
|
local item_list = self.all_chatItem_list[curr_channel] or {}
|
|
for _, item in pairs(item_list) do
|
|
item:ResetText()
|
|
table_insert(self.cache_chatItem_list, item)
|
|
end
|
|
self.all_chatItem_list[curr_channel] = {}
|
|
self:SetFirstOpenViewInitItem(curr_channel_list)
|
|
else
|
|
self:HideCurChannelItem()
|
|
self:ReLayoutScroll()
|
|
end
|
|
|
|
end
|
|
self:ShowNotReadMsgNum(0, true)
|
|
end
|
|
|
|
function ChatView:CheckNeedInstanceData()
|
|
if #self.need_add_msg > 0 then
|
|
local list = self.need_add_msg
|
|
self.need_add_msg = {}
|
|
for i, v in ipairs(list) do
|
|
self:AddMsgItem(v.info, v.autoLayout, v.custom_height)
|
|
end
|
|
self.is_init_operate = false
|
|
self:CheckNeedInstanceData()
|
|
end
|
|
self:HideAllItem()
|
|
end
|
|
|
|
function ChatView:HideAllItem( )
|
|
for _, item in pairs(self.cache_chatItem_list) do
|
|
item:SetVisible(false)
|
|
end
|
|
end
|
|
|
|
function ChatView:RefreshShieldBtn()
|
|
--判断是否显示屏蔽语音按钮
|
|
if GameSettingManager.blockChannel[self.model.curr_channel] then
|
|
self.shieldBtn:SetActive(true)
|
|
local key = GameSettingManager.blockChannel[self.model.curr_channel]
|
|
local isShield = GameSettingManager:getInstance():GetBlockProperty(key)
|
|
if isShield then
|
|
lua_resM:setImageSprite(self, self.shieldImg, "chat_asset", "chat_shield_2", true)
|
|
else
|
|
lua_resM:setImageSprite(self, self.shieldImg, "chat_asset", "chat_shield_1", true)
|
|
end
|
|
else
|
|
self.shieldBtn:SetActive(false)
|
|
end
|
|
end
|
|
|
|
--重新布局滚动条大小 以及位置
|
|
function ChatView:ReLayoutScroll(force)
|
|
|
|
if self.model.curr_bar_index == ChatModel.CHANNEL_CROSS or
|
|
self.model.curr_bar_index == ChatModel.CHANNEL_HORN or
|
|
self.model.curr_bar_index == ChatModel.CHANNEL_COUNTRY then
|
|
-- self.ScrollView.sizeDelta = Vector2(576, ScreenHeight - 164) --适配屏幕高度,勿改
|
|
-- self.ScrollView.anchoredPosition = Vector3(138, -67, self.ScrollView.anchoredPosition.z)
|
|
-- self.ScrollView.anchoredPosition = Vector2(self.ScrollView.anchoredPosition.x, -68)
|
|
self.ScrollView.sizeDelta = Vector2(516.5, ScreenHeight - 74) --适配屏幕高度,勿改
|
|
self.ScrollView.anchoredPosition = Vector3(123, -2.9, self.ScrollView.anchoredPosition.z)
|
|
elseif self.model.curr_bar_index == ChatModel.CHANNEL_GENERAL then
|
|
self.ScrollView.sizeDelta = Vector2(516.5, ScreenHeight - 74) --适配屏幕高度,勿改
|
|
self.ScrollView.anchoredPosition = Vector3(125, -2.9, self.ScrollView.anchoredPosition.z)
|
|
-- self.ScrollView.anchoredPosition = Vector2(121, -24.5)
|
|
else
|
|
self.ScrollView.sizeDelta = Vector2(516.5, ScreenHeight - 74) --适配屏幕高度,勿改
|
|
self.ScrollView.anchoredPosition = Vector3(123, -2.9, self.ScrollView.anchoredPosition.z)
|
|
end
|
|
|
|
self.scroll_content.sizeDelta = Vector2(490, self.curr_channel_height)
|
|
local off_h = self.scroll_content.sizeDelta.y - self.ScrollView.sizeDelta.y
|
|
off_h = off_h < 0 and 0 or off_h
|
|
self.last_scroll_content_posy = off_h
|
|
if self.is_lock and not force then
|
|
return
|
|
end
|
|
if not self.is_lock or force then
|
|
self.scroll_content.localPosition = Vector3(0, off_h, 0)
|
|
end
|
|
end
|
|
|
|
--设置发送的格式
|
|
function ChatView:SetSendFormat(info)
|
|
self.send_interval = info.send_interval
|
|
self.send_limit = info.send_limit
|
|
self:SetCharacterLimit(self.send_limit)
|
|
end
|
|
|
|
function ChatView:SetCharacterLimit( send_limit )
|
|
send_limit = send_limit or self.send_limit
|
|
self.input_text.characterLimit = send_limit + 1 --多一位触发onvaluechange
|
|
end
|
|
|
|
function ChatView:InitModelInfo(index)
|
|
local curr_channel = index
|
|
self.model.curr_channel = curr_channel
|
|
self.model:ClearChannelMessageNum(curr_channel)
|
|
end
|
|
|
|
function ChatView:ReplaceInputTextMark(str)
|
|
self.input_text_onValueChanged_addListener_off = true
|
|
--替换规则是"(<.->)"
|
|
local text = self.input_text.text
|
|
local old_args = self.model:IsHasArgs(text)
|
|
if (string.find(text, "(<.->)") and old_args) then
|
|
old_args = LanguageFilter.ConvPartten(old_args)
|
|
local newStr = string.gsub(text, old_args, str)
|
|
if utf8len(newStr) > self.send_limit then
|
|
Message.show(string.format("最多可输入%d个字符", self.send_limit),"fault")
|
|
else
|
|
self.input_text.text = newStr
|
|
end
|
|
else
|
|
local newStr = text .. str
|
|
if utf8len(newStr) > self.send_limit then
|
|
Message.show(string.format("最多可输入%d个字符", self.send_limit),"fault")
|
|
else
|
|
self.input_text.text = newStr
|
|
end
|
|
end
|
|
self.input_text_onValueChanged_addListener_off = false
|
|
return str
|
|
end
|
|
|
|
-- 显示装扮红点
|
|
function ChatView:ShowIndividualRedPoint()
|
|
local bool = ChatDressModel:getInstance():ShowChatDressRedPoint()
|
|
self.individual_RedPoint:SetActive(bool)
|
|
end
|
|
|
|
--设置喇叭的数量
|
|
function ChatView:SetHornNum()
|
|
local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.horn_id)
|
|
local cur_own = GoodsModel:getInstance():GetTypeGoodsNum(self.horn_id)
|
|
local str = "您拥有的喇叭:"
|
|
if basic then
|
|
if cur_own == 0 then
|
|
self.hasHorn.text = str.."<color=#de4141>" .. cur_own .. "</color>"
|
|
else
|
|
self.hasHorn.text = str.."<color=#73AC44FF>" .. cur_own .. "</color>"
|
|
end
|
|
else
|
|
self.hasHorn.text = str.."<color=#de4141>0</color>"
|
|
end
|
|
end
|
|
|
|
--设置跨服喇叭的数量
|
|
function ChatView:SetCrossHornNum()
|
|
local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.cross_horn_id)
|
|
local cur_own = GoodsModel:getInstance():GetTypeGoodsNum(self.cross_horn_id)
|
|
local str = "您拥有的喇叭:"
|
|
if basic then
|
|
if cur_own == 0 then
|
|
self.has_cross_horn.text = str.."<color=#de4141>" .. cur_own .. "</color>"
|
|
else
|
|
self.has_cross_horn.text = str.."<color=#73AC44FF>" .. cur_own .. "</color>"
|
|
end
|
|
else
|
|
self.has_cross_horn.text = str.."<color=#de4141>0</color>"
|
|
end
|
|
end
|
|
|
|
function ChatView:GetHornNum()
|
|
return GoodsModel:getInstance():GetTypeGoodsNum(self.horn_id)
|
|
end
|
|
|
|
--设置喇叭排队数量
|
|
function ChatView:SetCurHorn()
|
|
if self.model.curr_channel ~= ChatModel.CHANNEL_HORN then
|
|
return
|
|
end
|
|
local num = self.model:GetDelayHornNum()
|
|
if self.curHorn then
|
|
self.curHorn.text = string.format("当前排队喇叭:%d", num)
|
|
end
|
|
|
|
end
|
|
|
|
function ChatView:DelNoticeChatItem(notice_id)
|
|
|
|
local index_tb = {}
|
|
for k, v in pairs(self.all_chatItem_list[ChatModel.CHANNEL_SYSTEM]) do
|
|
if v.info and v.info.notice_id == notice_id then
|
|
table_insert(index_tb, k)
|
|
end
|
|
end
|
|
local del = 0
|
|
local num = 0
|
|
for k, v in ipairs(index_tb) do
|
|
del = v - num
|
|
local item = table_remove(self.all_chatItem_list[ChatModel.CHANNEL_SYSTEM], del)
|
|
self.curr_channel_height = self.curr_channel_height - item:GetHeight()
|
|
item:DeleteMe()
|
|
num = num + 1
|
|
end
|
|
self:ReLayoutScroll()
|
|
local pre_item
|
|
local cur_item
|
|
for i = 1, #self.all_chatItem_list[ChatModel.CHANNEL_SYSTEM] do
|
|
cur_item = self.all_chatItem_list[ChatModel.CHANNEL_SYSTEM][i]
|
|
if i == 1 then
|
|
cur_item.transform.anchoredPosition = Vector2(0, 0)
|
|
else
|
|
pre_item = self.all_chatItem_list[ChatModel.CHANNEL_SYSTEM][i - 1]
|
|
cur_item.transform.anchoredPosition = Vector2(0, pre_item.transform.anchoredPosition.y - pre_item:GetHeight())
|
|
end
|
|
end
|
|
end
|
|
|
|
function ChatView:CancelAddMsgTimer( )
|
|
if self.msg_timer_id then
|
|
GlobalTimerQuest:CancelQuest(self.msg_timer_id)
|
|
self.msg_timer_id = nil
|
|
end
|
|
end
|
|
|
|
function ChatView:GetItemHeight(info, call_back)
|
|
local base_add = 40 -- 距离顶部的高度
|
|
local channel = info.showtype == nil and info.channel or info.showtype
|
|
--print('Msh:ChatView.lua[1470] data', data)
|
|
--PrintTable(info)
|
|
if channel == ChatModel.CHANNEL_SYSTEM then
|
|
local function temp_call(height,info)
|
|
-- 区别普通消息 和 传闻喇叭消息
|
|
if (not info.chuanwen_type) or info.chuanwen_type == ChatModel.CHUANWEN_TYPE.NORMAL then -- 系统消息
|
|
height = height
|
|
else -- 传闻
|
|
--print('Msh:ChatView.lua[1476] data', info.chuanwen_type)
|
|
--PrintTable(info)
|
|
local min_height = Config.ConfigChat.Chuanwen_space
|
|
height = height < min_height and min_height or height
|
|
end
|
|
call_back(Config.ConfigChat.Sys_item_space + height )--高度在这边设置
|
|
end
|
|
self.static_system_text_tr.sizeDelta = Vector2(421.3,self.static_system_text_tr.sizeDelta.y) --- 一样适应问题宽度的最终计算在这边
|
|
self:GetTextHeight(self.static_system_text, self.static_system_text_tr, info.msg, temp_call,info) -- 最后这个info只是为了确认是否传闻加底用04/15
|
|
|
|
elseif info.is_line or info.show_num then
|
|
call_back(30 + base_add)
|
|
elseif info.player_id ~= RoleManager.Instance:GetMainRoleId() then
|
|
local player_dress_bubble = Config.ConfigChatDress.DefaultBubble
|
|
if info.dress_list then
|
|
for i, v in ipairs(info.dress_list) do
|
|
--1气泡 2相框
|
|
if v.dress_id ~= 0 then
|
|
local icon_name = v.dress_id
|
|
if v.dress_type == 1 then
|
|
player_dress_bubble = Trim(icon_name)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
local function temp_call(height)
|
|
local text_size_y = height
|
|
local bg_size = player_dress_bubble and self.dress_bubble_role_bg_add_size or self.role_bg_add_size
|
|
local bg_size_y = 0
|
|
if player_dress_bubble and Config.ConfigChatDress.Pos[player_dress_bubble] then
|
|
local addTable = Config.ConfigChatDress.Pos[player_dress_bubble]
|
|
bg_size = co.AddXY(bg_size, co.TableXY(addTable.size_x,addTable.size_y))
|
|
end
|
|
|
|
if info.iType == ChatModel.MSG_TYPE.VOICE then
|
|
bg_size_y = bg_size.y + text_size_y + self.voice_bg_add_size.y
|
|
else
|
|
bg_size_y = math.max(bg_size.y + text_size_y, self.role_bg_min_size.y)
|
|
end
|
|
call_back(math.max(bg_size_y + 30 +10, 95) + base_add-23)
|
|
end
|
|
self:GetTextHeight(self.static_player_text, self.static_player_text_tr, info.msg, temp_call)
|
|
|
|
elseif info.player_id == RoleManager.Instance:GetMainRoleId() then
|
|
|
|
local main_role_dress_bubble = Config.ConfigChatDress.DefaultBubble--有没有气泡
|
|
if info.dress_list then
|
|
for i, v in ipairs(info.dress_list) do
|
|
--1气泡 2相框
|
|
if v.dress_id ~= 0 then
|
|
local icon_name = v.dress_id
|
|
if v.dress_type == 1 then
|
|
main_role_dress_bubble = Trim(icon_name)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
local function temp_call(height)
|
|
local text_size = co.TableXY(math.min(self.role_text_width, self.static_mainRole_text.preferredWidth), self.static_mainRole_text.preferredHeight)
|
|
|
|
--主角
|
|
local bg_size = main_role_dress_bubble and self.dress_bubble_role_bg_add_size or self.role_bg_add_size
|
|
if main_role_dress_bubble and Config.ConfigChatDress.Pos[main_role_dress_bubble] then
|
|
local addTable = Config.ConfigChatDress.Pos[main_role_dress_bubble]
|
|
bg_size = co.AddXY(bg_size, co.TableXY(addTable.size_x,addTable.size_y))
|
|
end
|
|
local bg_size_y = 0
|
|
if info.iType == ChatModel.MSG_TYPE.VOICE then
|
|
bg_size_y = bg_size.y + text_size.y + self.voice_bg_add_size.y
|
|
else
|
|
bg_size_y = math.max(bg_size.y + text_size.y, self.role_bg_min_size.y)
|
|
end
|
|
call_back(math.max(bg_size_y + 30 +10, 95) + base_add-23)
|
|
end
|
|
self:GetTextHeight(self.static_mainRole_text, self.static_mainRole_text_tr, info.msg, temp_call)
|
|
|
|
else
|
|
call_back(base_add)
|
|
end
|
|
end
|
|
|
|
function ChatView:GetTextHeight(text_component,text_transform, msg, call_back,info)
|
|
local height = 0
|
|
self:CancelGetHeightQuest()
|
|
if text_component then
|
|
text_component.text = ""
|
|
text_transform.sizeDelta = Vector2(text_transform.sizeDelta.x, 10)
|
|
SetInlineText(text_component,msg)
|
|
-- text_component.text = msg
|
|
height = text_component.preferredHeight
|
|
call_back(height,info)
|
|
-- local function timer_func()
|
|
-- height = text_component.preferredHeight
|
|
-- call_back(height)
|
|
-- end
|
|
-- self.get_height_timer = GlobalTimerQuest:AddDelayQuest(timer_func, 0.02)
|
|
else
|
|
call_back(height,info)
|
|
end
|
|
end
|
|
|
|
function ChatView:CancelGetHeightQuest()
|
|
if self.get_height_timer then
|
|
GlobalTimerQuest:CancelQuest(self.get_height_timer)
|
|
self.get_height_timer = nil
|
|
end
|
|
end
|
|
|
|
--第一次打开界面做的处理 -- list的初建
|
|
function ChatView:SetFirstOpenViewInitItem(curr_channel_list)
|
|
local msg_len = #curr_channel_list
|
|
local need_add_list = {}
|
|
local content_height = 0
|
|
local len_count = 1
|
|
local pos_y = 0
|
|
if msg_len <= 0 then
|
|
return
|
|
end
|
|
self.is_init_operate = true --正在设置坐标中
|
|
self.has_init_item = true
|
|
local last_time = TimeUtil:getClientTimeMs( )
|
|
local function calContentSize() -- 一直调自己到len_count == msg_len
|
|
local vo = curr_channel_list[len_count]
|
|
if vo then
|
|
need_add_list[len_count] = {height = content_height, info = vo}
|
|
local function call_back(height)
|
|
content_height = content_height + height
|
|
if len_count == msg_len then -- 全部计算好了
|
|
self.curr_channel_height = content_height
|
|
self:ReLayoutScroll(true)
|
|
pos_y = self.scroll_content.sizeDelta.y - self.ScrollView.sizeDelta.y --
|
|
local over_count = self.is_initialized and msg_len or 5 -- 这里做个阈值
|
|
if not self.is_initialized then
|
|
self.is_initialized = true --表示已经分帧加载过了
|
|
end
|
|
if msg_len >= over_count then
|
|
local cur_index = msg_len --创建到第几个了 倒序创建
|
|
self:CancelAddMsgTimer()
|
|
for i = 1, over_count do
|
|
self:AddMsgItem(need_add_list[cur_index].info, false, need_add_list[cur_index].height, true, false, false)
|
|
cur_index = cur_index - 1
|
|
end
|
|
if cur_index > 0 then
|
|
local function time_func()
|
|
if not self.last_frame then
|
|
self.last_frame = Time.frameCount
|
|
end
|
|
if Time.frameCount - self.last_frame >= 1 then
|
|
self.last_frame = Time.frameCount
|
|
local data = need_add_list[cur_index]
|
|
|
|
if not data then
|
|
self:DoAfferFirstInit()
|
|
else
|
|
self:AddMsgItem(need_add_list[cur_index].info, false, need_add_list[cur_index].height, true, false, true)
|
|
cur_index = cur_index - 1
|
|
if need_add_list[cur_index] and need_add_list[cur_index].height - pos_y < -200 then
|
|
for i = cur_index, 1, -1 do
|
|
self.need_instance_data_list[i] = need_add_list[i]
|
|
end
|
|
self:DoAfferFirstInit()
|
|
end
|
|
end
|
|
end
|
|
end
|
|
self.msg_timer_id = GlobalTimerQuest:AddPeriodQuest(time_func, 0.01)--AddDelayQuest
|
|
else
|
|
self:DoAfferFirstInit()
|
|
end
|
|
else
|
|
for i = #need_add_list, 1, -1 do
|
|
self:AddMsgItem(need_add_list[i].info, false, need_add_list[i].height, true, false, true)
|
|
end
|
|
self:DoAfferFirstInit()
|
|
end
|
|
else
|
|
len_count = len_count + 1
|
|
local next_vo = curr_channel_list[len_count] --检查下一个是不是时间线
|
|
local is_line = self:CheckIsLine(next_vo)
|
|
if is_line then
|
|
local curr_channel = self.model.curr_bar_index
|
|
local lineInfo = self.model:PackChatInfo(curr_channel, next_vo.time, next_vo.key_id)
|
|
table_insert(self.need_add_line_list,{height = content_height,info = lineInfo})
|
|
content_height = content_height + 50
|
|
end
|
|
calContentSize()
|
|
end
|
|
end
|
|
self.pre_vo = vo
|
|
self:GetItemHeight(vo, call_back)
|
|
end
|
|
end
|
|
calContentSize()
|
|
|
|
end
|
|
|
|
function ChatView:CreateTimeLine( )
|
|
for i=1, #self.need_add_line_list do
|
|
local data = self.need_add_line_list[i]
|
|
if data then
|
|
self:AddMsgItem(data.info,false,data.height,true,true,true)
|
|
end
|
|
end
|
|
self.need_add_line_list = {}
|
|
end
|
|
|
|
function ChatView:CheckIsLine(vo)
|
|
local is_line = false
|
|
if not vo then return false end
|
|
if self.pre_vo and not self.pre_vo.is_line_flag and self.model.curr_bar_index ~= ChatModel.CHANNEL_SYSTEM and vo.time - self.pre_vo.time >= ChatModel.SHOW_LINE_TIME then
|
|
is_line = true
|
|
vo.is_line_flag = true
|
|
end
|
|
return is_line
|
|
end
|
|
|
|
function ChatView:Create( ... )
|
|
-- body
|
|
end
|
|
|
|
--计算显示那些没有创出来的item
|
|
function ChatView:CalcuInHideItem()
|
|
local len = #self.need_instance_data_list
|
|
if len > 0 then
|
|
local data = self.need_instance_data_list[len]
|
|
if data then
|
|
local height = data.height + 100
|
|
if self.scroll_content.localPosition.y <= height then
|
|
table_remove(self.need_instance_data_list, len)
|
|
self:AddMsgItem(data.info, false, data.height)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
--切换页签的时候重置数据
|
|
function ChatView:ResetLockState()
|
|
self.scroll_content_drag = false
|
|
self.scroll_content_drag2 = false
|
|
self.is_lock = false
|
|
self.scroll_rect.enabled = false
|
|
self.need_instance_data_list = {}
|
|
self.front_item_data_list = {}
|
|
self.back_item_data_list = {}
|
|
self.cur_item_data_list = {}
|
|
lua_resM:setImageSprite(self, self.lock_img, "chat_asset", "icon_chat_unlocked")
|
|
end
|
|
|
|
function ChatView:HideCurChannelItem( )
|
|
local list = self.all_chatItem_list[self.model.curr_bar_index]
|
|
if list then
|
|
for _,item in pairs(list) do
|
|
item:SetVisible(false)
|
|
end
|
|
end
|
|
for _,item in pairs(self.cache_chatItem_list) do
|
|
item:SetVisible(false)
|
|
end
|
|
end
|
|
|
|
|
|
function ChatView:DoAfferFirstInit( )
|
|
self.is_init_operate = false
|
|
self:CancelAddMsgTimer()
|
|
self:CreateTimeLine()
|
|
self:CheckNeedInstanceData()
|
|
self:SortByItemHeight()
|
|
end
|
|
|
|
function ChatView:SortByItemHeight( )
|
|
table.sort(self.cur_item_data_list,function ( a,b )
|
|
return a.height < b.height
|
|
end)
|
|
end
|
|
|
|
function ChatView:CheckItemCanHide( )
|
|
if not self.last_check_hide_time then
|
|
self.last_check_hide_time = Status.NowTime
|
|
end
|
|
if Status.NowTime - self.last_check_hide_time < 0.01 then
|
|
return
|
|
end
|
|
self.last_check_hide_time = Status.NowTime
|
|
if self.drag_start_pos_y and #self.cur_item_data_list > 0 then
|
|
local pos_y = self.scroll_content.anchoredPosition.y
|
|
if pos_y <= 0 or pos_y >= self.scroll_content.sizeDelta.y then
|
|
return
|
|
end
|
|
if pos_y > self.drag_start_pos_y then --向上滑动
|
|
local data = self.cur_item_data_list[1]
|
|
if data and data.height and data.info and data.item and pos_y - data.height > 150 then --向上超过150了 隐藏起来
|
|
data.item:SetVisible(false)
|
|
table_remove(self.cur_item_data_list,1)
|
|
table_insert(self.front_item_data_list,data)
|
|
end
|
|
else
|
|
local last_index = #self.cur_item_data_list
|
|
local data = self.cur_item_data_list[last_index]
|
|
if data and data.height and data.info and data.item and data.height - pos_y - self.ScrollView.sizeDelta.y > 150 then --向下超过150了 隐藏起来
|
|
data.item:SetVisible(false)
|
|
table_remove(self.cur_item_data_list,last_index)
|
|
table_insert(self.back_item_data_list,1,data)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function ChatView:CheckFrontItemShow( )
|
|
if not self.last_check_front_show_time then
|
|
self.last_check_front_show_time = Status.NowTime
|
|
end
|
|
if Status.NowTime - self.last_check_front_show_time < 0.01 then
|
|
return
|
|
end
|
|
local pos_y = self.scroll_content.anchoredPosition.y
|
|
if pos_y <= 0 or pos_y >= self.scroll_content.sizeDelta.y then
|
|
return
|
|
end
|
|
self.last_check_front_show_time = Status.NowTime
|
|
local last_index = #self.front_item_data_list
|
|
local data = self.front_item_data_list[last_index]
|
|
if data and data.height and data.item and pos_y - data.height <= 150 then
|
|
data.item:SetVisible(true)
|
|
table_remove(self.front_item_data_list,last_index)
|
|
table_insert(self.cur_item_data_list,1,data)
|
|
end
|
|
end
|
|
|
|
function ChatView:CheckBackItemShow( )
|
|
if not self.last_check_back_show_time then
|
|
self.last_check_back_show_time = Status.NowTime
|
|
end
|
|
if Status.NowTime - self.last_check_back_show_time < 0.01 then
|
|
return
|
|
end
|
|
local pos_y = self.scroll_content.anchoredPosition.y
|
|
if pos_y <= 0 or pos_y >= self.scroll_content.sizeDelta.y then
|
|
return
|
|
end
|
|
self.last_check_back_show_time = Status.NowTime
|
|
local data = self.back_item_data_list[1]
|
|
if data and data.height and data.item and (pos_y + self.ScrollView.sizeDelta.y) - data.height >= -10 then --data.height - pos_y - self.ScrollView.sizeDelta.y <= 150 then
|
|
data.item:SetVisible(true)
|
|
table_remove(self.back_item_data_list,1)
|
|
table_insert(self.cur_item_data_list,data)
|
|
end
|
|
end
|
|
|
|
function ChatView:SetCurItemData( data )
|
|
for i=#self.cur_item_data_list,1,-1 do
|
|
local last_data = self.cur_item_data_list[i]
|
|
local per_data = self.cur_item_data_list[i-1]
|
|
if not per_data then
|
|
if last_data.height < data.height then
|
|
table_insert(self.cur_item_data_list,data)
|
|
else
|
|
table_insert(self.cur_item_data_list,i,data)
|
|
end
|
|
elseif last_data and per_data then
|
|
if last_data.height > data.height and per_data.height < data.height then
|
|
table_insert(self.cur_item_data_list,i-1,data)
|
|
elseif last_data.height < data.height and per_data.height < data.height then
|
|
table_insert(self.cur_item_data_list,data)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function ChatView:InitLimitWaySelectView( )
|
|
|
|
for i= 1,#self.model.LIMIY_WAY_NAME do
|
|
local item = self.limit_btn_list[i]
|
|
if not item then
|
|
item = ChatChannelToggleItem.New(self.shieldContent_tr)
|
|
self.limit_btn_list[i] = item
|
|
end
|
|
local color ="#ffffff"
|
|
local str = string.format("<color=%s>%s</color>",color,ChatModel.LIMIY_WAY_NAME[i], i == #self.model.LIMIY_WAY_NAME)
|
|
item:SetData(str,i)
|
|
end
|
|
-- local color = ColorUtil:GetColor(self.model.limit_way)
|
|
-- self.shieldBtntext.text = string.format("<color=%s>%s</color>",color,ChatModel.LIMIY_WAY_NAME[self.model.limit_way])
|
|
-- local clear_item = ChatSelectLimnitItem.New(self.limit_way.select_con)
|
|
-- table_insert(self.limit_btn_list,clear_item)
|
|
-- clear_item:SetData(-1)
|
|
end
|
|
|
|
function ChatView:SetDressBackground( )
|
|
-- Message.show("SetDressBackground")
|
|
local use_dress_list = ChatDressModel:getInstance().use_dress_list or {}
|
|
if use_dress_list == {} then return end
|
|
local bg_dress_id = use_dress_list[ChatDressSubType.BACKGROUND]
|
|
if bg_dress_id and bg_dress_id ~= 0 then
|
|
lua_resM:setOutsideImageSprite(self, self.bg_img, GameResPath.GetChatDressIcon(bg_dress_id), false)
|
|
end
|
|
|
|
end
|
|
|
|
function ChatView:SetShieldBtnState( )
|
|
local state = not self.shieldChannelScrv.activeSelf
|
|
self.is_show_shield = state
|
|
self.shieldChannelScrv:SetActive(state)
|
|
self.limitBtn_true_obj:SetActive(state)
|
|
if state then
|
|
self:InitLimitWaySelectView()
|
|
end
|
|
end
|