源战役客户端
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.

1910 lines
80 KiB

  1. ChatView = ChatView or BaseClass(BaseView)
  2. local ChatView = ChatView
  3. local ChatModel = ChatModel
  4. local GlobalEventSystem = GlobalEventSystem
  5. local GlobalTimerQuest = GlobalTimerQuest
  6. local GuildModel = GuildModel
  7. local MainUIModel = MainUIModel
  8. local RoleManager = RoleManager
  9. local lua_resM = lua_resM
  10. local table_insert = table.insert
  11. local table_remove = table.remove
  12. local AddClickEvent = AddClickEvent
  13. function ChatView:__init()
  14. self.base_file = "chat"
  15. self.layout_file = "chatView"
  16. self.layer_name = "UI"
  17. -- self.use_local_view = true
  18. self.open_wnd_anim = 0
  19. self.model = ChatModel:getInstance()
  20. self.change_scene_close = true
  21. self.append_to_ctl_queue = true
  22. self.is_moving = false
  23. self.is_set_zdepth = true
  24. self.curr_bar_index = 1
  25. self.destroy_imm = false
  26. self.tabbar_list = {}
  27. self.tabbar_prefab = nil
  28. self.chatItem_prefab = nil
  29. -- self.close_mode = CloseMode.CloseVisible
  30. self.event_list = {}
  31. self.need_instance_data_list = {} --隐藏还没有创键的item数据
  32. self.all_chat_data_list = {} --记录每个频道每个item的位置
  33. self.all_chat_item_list = {} --所以聊天信息item
  34. self.need_add_line_list = {}
  35. self.need_add_msg = {} --消息缓存 需要设置完坐标后重新计算
  36. self.is_talk_to_text = true --是否文本聊天 非语音聊天模式
  37. self.front_item_data_list = {}
  38. self.back_item_data_list = {}
  39. self.cur_item_data_list = {}
  40. self.send_interval = 0 -- 发送时间间隔
  41. self.send_limit = 50 -- 发送文字限制
  42. self.all_chatItem_list = {} --总的聊天显示列表
  43. self.cache_chatItem_list = {} --缓存聊天显示列表
  44. self.pre_content_pos_y = 0--刷新一对一聊天记录前的位置
  45. self.curr_channel_height = 0 --当前频道界面的高度 用于布局
  46. self.pre_renderer_chatItem = nil -- 上一个渲染的chatitem 跟当前需要渲染的chatitem对比用于判断是否需要显示横线时间
  47. self.chating_name = "" --当前正在私聊的玩家名字
  48. self.scrollView_original_y = 0 --滚动面板最初的y值
  49. self.pre_channel_list = {} --当前频道 聊天显示列表
  50. self.not_read_count = 0 --未读消息
  51. self.scroll_content_drag = false --拖拽的标志
  52. self.scroll_posy_in_lock = 0 --锁定时当前content的pos y
  53. self.cache_not_read_list = {}
  54. self.horn_id = 38050001
  55. self.cross_horn_id = 38050002
  56. self.pre_cache_item_list = {} --缓存多添加的item
  57. --self:AddPreLoadList("chat", {"ChatItem"})
  58. self.click_pos_content = false --用来记录位置的字符串
  59. self.input_text_onValueChanged_addListener_off = false --
  60. self.is_hide_skill_black_bg = true
  61. self.limit_btn_list = {} -- 缓存限制频道的ITem
  62. self.load_callback = function ()
  63. self:LoadSuccess()
  64. self:InitEvent()
  65. self:LoadTabbarPrefab()
  66. end
  67. self.open_callback = function ()
  68. self.view_is_close = false
  69. if SceneManager:getInstance():IsGuildScene() then
  70. --答题场景请求题目信息
  71. -- GuildModel:getInstance():Fire(GuildModel.REQUEST_CCMD_EVENT, 40217)
  72. self:SetCurrTabbarIndex(ChatModel.CHANNEL_GUILD)
  73. end
  74. self:SwitchBar()
  75. local function onCompleted()
  76. self.is_moving = false
  77. end
  78. self.is_moving = true
  79. self.model:Fire(ChatModel.UPDATE_SEND_TIME)
  80. self.transform.anchoredPosition = Vector2(-SrcScreenWidth / 2, 0)
  81. TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POS, Vector2(ClientConfig.iphone_x_offset_left, 0), 0.1, onCompleted)
  82. self.temp_state = MainUIModel:getInstance().state_right_bottom:isInstate()
  83. GlobalEventSystem:Fire(EventName.HIDE_MAIN_CHAT_VIEW, true, MainUIModel.MAIN_MODE)
  84. -- GlobalEventSystem:Fire(EventName.HIDE_RIGHT_BOTTOM_VIEW, true, MainUIModel.MAIN_MODE, true)
  85. self:ShowIndividualRedPoint()
  86. self.input_text.text = self.model.say_cache
  87. self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11011, ChatModel.CHANNEL_CROSS)
  88. -- self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11011, ChatModel.CHANNEL_COUNTRY)
  89. self:SetDressBackground()
  90. end
  91. self.ReOpen_callback = function ()
  92. self:SetDressBackground() -- 装扮界面关闭会主动跳回来
  93. end
  94. self.close_callback = function ()
  95. self:HideCurChannelItem()
  96. self.need_add_msg = {}
  97. self.view_is_close = true
  98. self.is_moving = false
  99. local recordView = MainUIController.Instance.RecordViw
  100. GlobalEventSystem:Fire(EventName.CLOSE_INDIVIDUATION_VIEW)
  101. if recordView then
  102. recordView:OnClose()
  103. end
  104. GlobalEventSystem:Fire(EventName.HIDE_MAIN_CHAT_VIEW, false, MainUIModel.MAIN_MODE)
  105. if SceneManager:getInstance():IsStarFightScene() then
  106. GlobalEventSystem:Fire(EventName.HIDE_RIGHT_BOTTOM_VIEW, self.temp_state, MainUIModel.MAIN_MODE, true)
  107. else
  108. GlobalEventSystem:Fire(EventName.HIDE_RIGHT_BOTTOM_VIEW, false, MainUIModel.MAIN_MODE, true)
  109. end
  110. self.model.say_cache = self.input_text.text
  111. GlobalEventSystem:Fire(EventName.CLOSE_CHAT_BAG_VIEW)
  112. GlobalEventSystem:Fire(EventName.MAIN_VOICE_BIND)
  113. end
  114. self.destroy_callback = function ()
  115. self:Clear()
  116. end
  117. ----测试 后续调进配置里 这个无用!!
  118. self.role_text_width = 307+100
  119. self.dress_bubble_role_bg_add_size = co.TableXY(41+100, 40)
  120. self.role_bg_add_size = co.TableXY(60+100, 25)
  121. self.voice_bg_add_size = co.TableXY(30 + 53+100, 40)
  122. self.role_bg_min_size = co.TableXY(5+100, 56)
  123. self.main_role_text_offset = co.TableXY(-31+100, -3) --有气泡的时候调整
  124. self.main_role_default_text_offset = co.TableXY(-28+100, 0) --无气泡的时候调整
  125. end
  126. function ChatView:Clear()
  127. self.is_initialized = false
  128. self.has_init_item = false
  129. self.is_first_open = false
  130. self:CancelAddMsgTimer()
  131. self:CancelGetHeightQuest()
  132. self.model:SeletedChatViewTabbar(nil)
  133. self.pre_renderer_chatItem = nil
  134. self.curr_channel_height = 0
  135. self.pre_content_pos_y = 0
  136. self.tabbar_prefab = nil
  137. self.chatItem_prefab = nil
  138. for channel, list in pairs(self.all_chatItem_list) do
  139. for i, item in pairs(list) do
  140. item:DeleteMe()
  141. end
  142. end
  143. self.all_chatItem_list = {}
  144. for i, v in ipairs(self.pre_channel_list) do
  145. if v then
  146. v:DeleteMe()
  147. v = nil
  148. end
  149. end
  150. self.pre_channel_list = {}
  151. for i, item in pairs(self.cache_chatItem_list) do
  152. item:DeleteMe()
  153. end
  154. self.cache_chatItem_list = {}
  155. for _, v in pairs(self.all_chat_item_list) do
  156. v:DeleteMe()
  157. end
  158. self.all_chat_item_list = {}
  159. for i, item in pairs(self.tabbar_list) do
  160. item:DeleteMe()
  161. end
  162. self.tabbar_list = {}
  163. if self.selected_item_bind_id then
  164. self.model:UnBind(self.selected_item_bind_id)
  165. self.selected_item_bind_id = nil
  166. end
  167. if self.refresh_event_id then
  168. self.model:UnBind(self.refresh_event_id)
  169. self.refresh_event_id = nil
  170. end
  171. if self.send_event_id then
  172. self.model:UnBind(self.send_event_id)
  173. self.send_event_id = nil
  174. end
  175. if self.select_faceItem_id then
  176. self.model:UnBind(self.select_faceItem_id)
  177. self.select_faceItem_id = nil
  178. end
  179. if self.select_textFaceItem_id then
  180. self.model:UnBind(self.select_textFaceItem_id)
  181. self.select_textFaceItem_id = nil
  182. end
  183. if self.horn_event_id then
  184. self.model:UnBind(self.horn_event_id)
  185. self.horn_event_id = nil
  186. end
  187. if self.select_goodItem_id then
  188. self.model:UnBind(self.select_goodItem_id)
  189. self.select_goodItem_id = nil
  190. end
  191. if self.select_coord_id then
  192. self.model:UnBind(self.select_coord_id)
  193. self.select_coord_id = nil
  194. end
  195. if self.add_msg_id then
  196. self.model:UnBind(self.add_msg_id)
  197. self.add_msg_id = nil
  198. end
  199. if self.show_tab_red_point_id then
  200. self.model:UnBind(self.show_tab_red_point_id)
  201. self.show_tab_red_point_id = nil
  202. end
  203. if self.title_promote_id then
  204. self.model:UnBind(self.title_promote_id)
  205. self.title_promote_id = nil
  206. end
  207. if self.update_time_id then
  208. self.model:UnBind(self.update_time_id)
  209. self.update_time_id = nil
  210. end
  211. self:CancelSendTimer()
  212. if self.bind_update_reg_text then
  213. self.model:UnBind(self.bind_update_reg_text)
  214. self.bind_update_reg_text = nil
  215. end
  216. if self.vip_event_id then
  217. RoleManager:getInstance():GetMainRoleVo():UnBind(self.vip_event_id)
  218. self.vip_event_id = nil
  219. end
  220. if self.question_event_id then
  221. GuildModel:getInstance():UnBind(self.question_event_id)
  222. self.question_event_id = nil
  223. end
  224. if self.select_bag_id then
  225. self.model:UnBind(self.select_bag_id)
  226. self.select_bag_id = nil
  227. end
  228. GlobalEventSystem:Fire(EventName.REMOVE_RECORD_BTN, self.voiceBtn)
  229. -- self:CancelQueTimer()
  230. if self.show_individual_redPoint_id then
  231. GlobalEventSystem:UnBind(self.show_individual_redPoint_id)
  232. self.show_individual_redPoint_id = nil
  233. end
  234. if self.orientation_change_id then
  235. GlobalEventSystem:UnBind(self.orientation_change_id)
  236. self.orientation_change_id = nil
  237. end
  238. for i, v in ipairs(self.pre_channel_list) do
  239. if v then
  240. v:DeleteMe()
  241. v = nil
  242. end
  243. end
  244. for i, v in ipairs(self.pre_cache_item_list) do
  245. if v then
  246. v:DeleteMe()
  247. v = nil
  248. end
  249. end
  250. for i, v in ipairs(self.event_list) do
  251. self.model:UnBind(v)
  252. v = nil
  253. end
  254. if self.bind_guild_id then
  255. RoleManager:getInstance():GetMainRoleVo():UnBind(self.bind_guild_id)
  256. self.bind_guild_id = nil
  257. end
  258. if self.notice_event_id then
  259. self.model:UnBind(self.notice_event_id)
  260. self.notice_event_id = nil
  261. end
  262. if self.change_limit_way_id then
  263. self.model:UnBind(self.change_limit_way_id)
  264. self.change_limit_way_id = nil
  265. end
  266. for k,v in pairs(self.limit_btn_list) do
  267. v:DeleteMe()
  268. v = nil
  269. end
  270. self.limit_btn_list = {}
  271. end
  272. function ChatView:CancelSendTimer()
  273. if self.send_timer_id then
  274. GlobalTimerQuest:CancelQuest(self.send_timer_id)
  275. self.send_timer_id = nil
  276. end
  277. end
  278. function ChatView:LoadTabbarPrefab()
  279. local function call_back(objs)
  280. if self._use_delete_method then
  281. return
  282. end
  283. self.tabbar_prefab = objs[0]
  284. self.chatItem_prefab = objs[1]
  285. self:RefeshTabbar()
  286. end
  287. lua_resM:loadPrefabs(self, "chat", {"chatBarBtn", "chatItem"}, call_back)
  288. end
  289. function ChatView:LoadSuccess()
  290. self.transform.sizeDelta = Vector2(ScreenWidth, ScreenHeight)
  291. self.bg = self:GetChild("bg")
  292. self.content_bg = self:GetChild("content_bg")
  293. self.tabbar_con = self:GetChild("tabbar_con")
  294. self.bottom_img = self:GetChild("bottom_img")
  295. self.bottom_con = self:GetChild("bottom_con")
  296. self.bottom_con2 = self:GetChild("bottom_con2")
  297. self.standard_point = self:GetChild("standard_point")
  298. self.scroll_content = self:GetChild("ScrollView/Viewport/Content")
  299. self.static_system_text_tr = self:GetChild("static/systemCon/contentText")
  300. self.static_player_text_tr = self:GetChild("static/playerCon/contentText")
  301. self.static_mainRole_text_tr = self:GetChild("static/mainRoleCon/contentText")
  302. self.shieldContent_tr = self:GetChild("shieldChannelCon/ScrollView/Viewport/Content")
  303. self.hasHorn = self:GetChild("content_bg/hornCon/hasHorn"):GetComponent("Text")
  304. self.curHorn = self:GetChild("content_bg/hornCon/curHorn"):GetComponent("Text")
  305. self.crossChatTime = self:GetChild("content_bg/crossChatCon/curHorn"):GetComponent("Text")
  306. self.has_cross_horn = self:GetChild("content_bg/crossChatCon/hasHorn"):GetComponent("Text")
  307. self.not_read_text = self:GetChild("bottomTipCon/notReadCon/not_read_text"):GetComponent("Text")
  308. self.sendBtn_text = self:GetChild("bottom_con/sendBtn/Text"):GetComponent("TextMeshProUGUI")
  309. self.bottom_con2_text = self:GetChild("bottom_con2/Text"):GetComponent("Text")
  310. self.static_system_text = self:GetChild("static/systemCon/contentText"):GetComponent("Text")
  311. self.static_player_text = self:GetChild("static/playerCon/contentText"):GetComponent("Text")
  312. self.static_mainRole_text = self:GetChild("static/mainRoleCon/contentText"):GetComponent("Text")
  313. self.shieldBtntext = self:GetChild("shieldChannelCon/shieldTxtBtn/text"):GetComponent("Text")
  314. -- self.lock_state_text.text = "未锁定"
  315. self.hornAddBtn = self:GetChild("content_bg/hornCon/addBtn").gameObject
  316. self.crossChatCon = self:GetChild("content_bg/crossChatCon").gameObject
  317. self.crossChatAddBtn = self:GetChild("content_bg/crossChatCon/addBtn").gameObject
  318. self.notReadCon = self:GetChild("bottomTipCon/notReadCon").gameObject
  319. self.hornCon = self:GetChild("content_bg/hornCon").gameObject
  320. self.noGuildCon = self:GetChild("noGuildCon").gameObject
  321. self.addGuildBtn = self:GetChild("noGuildCon/addGuildBtn").gameObject
  322. self.input_con = self:GetChild("bottom_con/TextInput").gameObject
  323. self.voiceBtn = self:GetChild("bottom_con/border/voiceBtn").gameObject
  324. self.faceBtn = self:GetChild("bottom_con/border/faceBtn").gameObject
  325. self.sendBtn = self:GetChild("bottom_con/sendBtn").gameObject
  326. self.ScrollViewCon = self:GetChild("ScrollView").gameObject
  327. self.closeBtn = self:GetChild("bg/closeBtn").gameObject
  328. self.shieldBtn = self:GetChild("shieldBtn").gameObject
  329. self.shieldImg = self:GetChild("shieldBtn/Image").gameObject
  330. self.alpha_btn = self:GetChild("AlphaBtn").gameObject
  331. self.individualBtn = self:GetChild("individualBtn").gameObject
  332. self.individual_RedPoint = self:GetChild("individualBtn/redPoint").gameObject
  333. self.goTeamBtn = self:GetChild("bottomTipCon/goTeamBtn").gameObject
  334. self.lockBtn = self:GetChild("LockBtn").gameObject
  335. self.shieldTxtBtn = self:GetChild("shieldChannelCon/shieldTxtBtn").gameObject
  336. self.shieldChannelCon = self:GetChild("shieldChannelCon").gameObject
  337. self.shieldChannelScrv = self:GetChild("shieldChannelCon/ScrollView").gameObject
  338. self.limitBtn_true_obj = self:GetChild("shieldChannelCon/shieldTxtBtn/limitBtn_true").gameObject
  339. self.voiceImg = self:GetChild("bottom_con/border/voiceBtn"):GetComponent("Image")
  340. self.lock_img = self:GetChild("LockBtn"):GetComponent("Image")
  341. self.bg_img = self:GetChild("bg/bg_img"):GetComponent("Image")
  342. --lua_resM:setOutsideImageSprite(self,self.noGuild_img,GameResPath.GetCommonImage("com_girl3"),false)
  343. self.input_text = self:GetChild("bottom_con/TextInput"):GetComponent("InputField")
  344. self.ScrollView = self:GetChild("ScrollView"):GetComponent("RectTransform")
  345. self.scrollView_original_y = self.ScrollView.anchoredPosition.y
  346. self.scroll_rect = self:GetChild("ScrollView"):GetComponent("ScrollRect")
  347. self.bg_rawImge = self:GetChild("bg"):GetComponent("Image")
  348. -- self.lock_toggle = self:GetChild("Toggle"):GetComponent("Toggle")
  349. lua_resM:setOutsideImageSprite(self,self.bg_rawImge,GameResPath.GetChatBg("chat_view_bg"),false)
  350. end
  351. function ChatView:RefeshTabbar()
  352. local vo = nil
  353. local item = nil
  354. for i = 1, #Config.ConfigChat.channel_level do
  355. vo = Config.ConfigChat.channel_level[i]
  356. if (vo.channel ~= ChatModel.CHANNEL_CROSS and
  357. vo.channel ~= ChatModel.CHANNEL_REPLY and
  358. vo.channel ~= ChatModel.CHANNEL_COUNTRY ) or -- 非跨服/本国/答题
  359. ------------------------------------------------
  360. (vo.channel == ChatModel.CHANNEL_CROSS and -- 大跨服(要满足条件)
  361. -- RoleManager.Instance.mainRoleInfo.level >= vo.level and
  362. vo.open_day and ServerTimeModel:getInstance():GetOpenServerDay() >= vo.open_day ) or
  363. -----------------------------------------------------
  364. (vo.channel == ChatModel.CHANNEL_COUNTRY and -- 本国(要满足条件)
  365. RoleManager.Instance.mainRoleInfo.level >= vo.level and
  366. vo.open_day and ServerTimeModel:getInstance():GetOpenServerDay() >= vo.open_day )
  367. then
  368. item = self.tabbar_list[i]
  369. if item == nil then
  370. item = ChatBarBtn.New(self.tabbar_con, self.tabbar_prefab)
  371. self.tabbar_list[i] = item
  372. end
  373. item:SetData(i, vo.channel, vo)
  374. end
  375. end
  376. self:SwitchBar()
  377. end
  378. function ChatView:InitEvent()
  379. local function onOrientationChange()
  380. self.transform.anchoredPosition = Vector2(ClientConfig.iphone_x_offset_left, 0)
  381. end
  382. self.orientation_change_id = GlobalEventSystem:Bind(EventName.ORIENTATION_DID_CHANGE, onOrientationChange)
  383. local function onClickBtnHandler(target)
  384. if target == self.alpha_btn then
  385. if self.model.curr_bar_index == ChatModel.CHANNEL_GUILD then
  386. self.model:SetGuildChannelRedDot(false)
  387. end
  388. self:Close()
  389. elseif target == self.faceBtn then
  390. GlobalEventSystem:Fire(EventName.OPEN_INDIVIDUATION_VIEW, self.model.curr_individuation_bar_index, -1, 60.5)
  391. if self.is_show_shield then
  392. self:SetShieldBtnState()
  393. end
  394. elseif target == self.sendBtn then
  395. local content = self.input_text.text
  396. local tmpArgs = self.model:GetAllArgsText(content)
  397. content = self.model:GetHyperlinkText(content)
  398. -- if self.model.curr_channel == ChatModel.CHANNEL_CROSS then
  399. -- if string.find(content, "<a@goods4@") then
  400. -- Message.show("跨服频道无法发送背包物品","fault")
  401. -- return
  402. -- elseif string.find(content, "<a@pos@") then
  403. -- Message.show("跨服频道无法发送坐标","fault")
  404. -- return
  405. -- end
  406. -- end
  407. GlobalEventSystem:Fire(EventName.CLOSE_CHAT_BAG_VIEW)
  408. GlobalEventSystem:Fire(EventName.CLOSE_INDIVIDUATION_VIEW)
  409. self:SendMsg()
  410. elseif target == self.individualBtn then
  411. if RoleManager.Instance.mainRoleInfo.level >= Config.Modulesub["112@1"].open_lv then
  412. OpenFun.Open(112,1)
  413. else
  414. Message.show(Config.Modulesub["112@1"].open_lv.."级开启聊天装扮功能","fault")
  415. end
  416. elseif target == self.closeBtn then
  417. self:Close()
  418. elseif target == self.shieldBtn then
  419. local key = GameSettingManager.blockChannel[self.model.curr_channel]
  420. local isShield = GameSettingManager:getInstance():GetBlockProperty(key)
  421. GameSettingManager:getInstance():SetBlockProperty(key, not isShield)
  422. self:RefreshShieldBtn()
  423. Message.show(isShield and "开启语音自动播放" or "屏蔽语音自动播放")
  424. elseif target == self.lockBtn then
  425. local rect_height = self.scroll_rect.transform.sizeDelta.y
  426. local content_height = self.scroll_content.sizeDelta.y
  427. if content_height < rect_height + 80 then
  428. self.is_lock = false
  429. -- self.lock_state_text.text = "未锁定"
  430. lua_resM:setImageSprite(self,self.lock_img,"chat_asset","icon_chat_unlocked")
  431. return
  432. end
  433. self.is_lock = not self.is_lock
  434. -- self.lock_state_text.text = self.is_lock and "锁定" or "未锁定"
  435. if self.is_lock then
  436. self.scroll_posy_in_lock = self.scroll_content.localPosition.y
  437. lua_resM:setImageSprite(self,self.lock_img,"chat_asset","icon_chat_locking")
  438. else
  439. lua_resM:setImageSprite(self,self.lock_img,"chat_asset","icon_chat_unlocked")
  440. end
  441. elseif target == self.hornAddBtn then
  442. GlobalEventSystem:Fire(EventName.OPEN_ASSIGN_BUY_VIEW, self.horn_id)
  443. -- GlobalEventSystem:Fire(EventName.OPEN_QUICK_BUY_VIEW,self.horn_id,1,ShopType.Binding)
  444. --GlobalEventSystem:Fire(EventName.OPEN_SHOP_VIEW, 2, self.horn_id)
  445. elseif target == self.crossChatAddBtn then
  446. GlobalEventSystem:Fire(EventName.OPEN_ASSIGN_BUY_VIEW, self.cross_horn_id)
  447. -- GlobalEventSystem:Fire(EventName.OPEN_QUICK_BUY_VIEW,self.horn_id,1,ShopType.Binding)
  448. --GlobalEventSystem:Fire(EventName.OPEN_SHOP_VIEW, 2, self.horn_id)
  449. elseif target == self.addGuildBtn then
  450. -- GlobalEventSystem:Fire(EventName.OPEN_GUILD_APPLY_VIEW)
  451. OpenFun.Open(400, 0)
  452. self:Close()
  453. elseif target == self.goTeamBtn then
  454. GlobalEventSystem:Fire(EventName.OPEN_TEAM_LIST_VIEW)
  455. self:Close()
  456. elseif target == self.notReadCon then
  457. self:ReLayoutScroll(true)
  458. self:ShowNotReadMsgNum(0, true)
  459. elseif target == self.shieldTxtBtn then
  460. self:SetShieldBtnState()
  461. end
  462. end
  463. AddClickEvent(self.faceBtn, onClickBtnHandler, LuaSoundManager.SOUND_UI.NONE)
  464. AddClickEvent(self.sendBtn, onClickBtnHandler)
  465. AddClickEvent(self.alpha_btn, onClickBtnHandler)
  466. AddClickEvent(self.individualBtn, onClickBtnHandler, LuaSoundManager.SOUND_UI.NONE)
  467. AddClickEvent(self.closeBtn, onClickBtnHandler)
  468. AddClickEvent(self.shieldBtn, onClickBtnHandler)
  469. -- AddClickEvent(self.lock_toggle.gameObject, onClickBtnHandler)
  470. AddClickEvent(self.lockBtn, onClickBtnHandler)
  471. AddClickEvent(self.hornAddBtn, onClickBtnHandler)
  472. AddClickEvent(self.crossChatAddBtn, onClickBtnHandler)
  473. AddClickEvent(self.addGuildBtn, onClickBtnHandler, LuaSoundManager.SOUND_UI.NONE)
  474. AddClickEvent(self.goTeamBtn, onClickBtnHandler, LuaSoundManager.SOUND_UI.NONE)
  475. AddClickEvent(self.notReadCon, onClickBtnHandler)
  476. AddClickEvent(self.shieldTxtBtn, onClickBtnHandler)
  477. local function onDragBeginHandler(target,x,y)
  478. self.drag_start_pos_y = self.scroll_content.anchoredPosition.y
  479. self.scroll_content_drag = true
  480. self.scroll_content_drag2 = true
  481. end
  482. AddDragBeginEvent(self.scroll_rect.gameObject, onDragBeginHandler)
  483. -- AddDragBeginEvent(self.hornScrollCon, onDragBeginHandler)
  484. local function onDraEndgHandler(target,x,y)
  485. self.scroll_content_drag = false
  486. end
  487. AddDragEndEvent(self.scroll_rect.gameObject, onDraEndgHandler)
  488. -- AddDragEndEvent(self.hornScrollCon, onDraEndgHandler)
  489. local function onValueChanged()
  490. if not self.scroll_content_drag2 and not self.scroll_content_drag then
  491. return
  492. end
  493. local rect_height = self.scroll_rect.transform.sizeDelta.y --ScrollView 的高度
  494. local content_height = self.scroll_content.sizeDelta.y --Contenet的高度
  495. local pos_y = self.scroll_content.localPosition.y
  496. if pos_y <= -10 or pos_y + rect_height > content_height + 10 then
  497. return
  498. end
  499. self:CalcuInHideItem()
  500. self:CheckItemCanHide()
  501. self:CheckFrontItemShow()
  502. self:CheckBackItemShow()
  503. self.is_lock = content_height - pos_y >= rect_height + 90
  504. -- self.lock_state_text.text = self.is_lock and "锁定" or "未锁定"
  505. if self.is_lock then
  506. self.scroll_posy_in_lock = self.scroll_content.localPosition.pos_y
  507. lua_resM:setImageSprite(self, self.lock_img, "chat_asset", "icon_chat_locking")
  508. else
  509. lua_resM:setImageSprite(self, self.lock_img, "chat_asset", "icon_chat_unlocked")
  510. end
  511. if #self.cache_not_read_list > 0 then
  512. local new_item_height = self.cache_not_read_list[1]
  513. if new_item_height and (pos_y + self.ScrollView.sizeDelta.y) - new_item_height >= 0 then
  514. table_remove(self.cache_not_read_list, 1)
  515. self:ShowNotReadMsgNum(-1)
  516. end
  517. end
  518. if content_height - pos_y <= 20 then --锁定
  519. self.scroll_content_drag2 = false
  520. end
  521. end
  522. self.scroll_rect.onValueChanged:AddListener(onValueChanged)
  523. -- self.horn_scroll_rect.onValueChanged:AddListener(onValueChanged)
  524. GlobalEventSystem:Fire(EventName.ADD_RECORD_BTN, self.voiceBtn, {channel = -1, rect = {x = -302, y = 0, w = 57, h = 57}, dis = 300})
  525. local function vip_change()
  526. self:RefeshTabbar()
  527. end
  528. self.vip_event_id = RoleManager:getInstance():GetMainRoleVo():BindOne("vip_flag", vip_change)
  529. local function onUpdateSendTime()
  530. self:UpdateSendTime()
  531. end
  532. self.update_time_id = self.model:Bind(ChatModel.UPDATE_SEND_TIME, onUpdateSendTime)
  533. local function onSelecteItemHandler(item)
  534. self:SetCurrTabbarIndex(item.channel)
  535. self:SwitchBar()
  536. GlobalEventSystem:Fire(EventName.ADD_RECORD_BTN, self.voiceBtn, {channel = item.channel, rect = {x = -302, y = 0, w = 57, h = 57}, dis = 300})
  537. end
  538. self.selected_item_bind_id = self.model:Bind(ChatModel.SELECT_CHAT_VIEW_TARBAR, onSelecteItemHandler)
  539. local function onRefresh()
  540. self:SwitchBar()
  541. end
  542. self.refresh_event_id = self.model:Bind(ChatModel.REFRESH_VIEW, onRefresh)
  543. local function onSelectFaceItemHandler(item)
  544. if item and not self.model.horn_view_is_open then
  545. local face_str = "<#f_" .. (item.index - 1) .. ">"
  546. if #self.input_text.text + #face_str <= self.input_text.characterLimit and self.input_text.characterLimit ~= 0 then
  547. self.input_text.text = self.input_text.text .. face_str
  548. else
  549. Message.show(string.format("最多可输入%d个字符", self.send_limit),"fault")
  550. end
  551. end
  552. end
  553. self.select_faceItem_id = self.model:Bind(ChatModel.SELECT_FACE_ITEM, onSelectFaceItemHandler)
  554. local function onSelectTextFaceItemHandler(item)
  555. if item and not self.model.horn_view_is_open then
  556. if self.model.clicked_role_item == nil then
  557. self.input_text.text = string.gsub(item.vo.one, "#N", RoleManager.Instance:GetMainRoleVo().name)
  558. else
  559. self.input_text.text = string.gsub(item.vo.two, "#n", self.model.clicked_role_item.info.name)
  560. self.input_text.text = string.gsub(self.input_text.text, "#N", RoleManager.Instance:GetMainRoleVo().name)
  561. end
  562. end
  563. end
  564. self.select_textFaceItem_id = self.model:Bind(ChatModel.SELECT_TEXT_FACE_ITEM, onSelectTextFaceItemHandler)
  565. local function onSelectHistoryTextItemHandler(str)
  566. self.input_text.text = str
  567. end
  568. table_insert(self.event_list, self.model:Bind(ChatModel.SELECT_HISTORY_TEXT_ITEM, onSelectHistoryTextItemHandler))
  569. local function onClickPosBtnHandler(content, show_str)
  570. self.click_pos_content = content
  571. self.click_pos_show_str = show_str
  572. self.input_text.text = show_str
  573. end
  574. table_insert(self.event_list, self.model:Bind(ChatModel.CLICK_POS_BTN, onClickPosBtnHandler))
  575. local function onSelectCoordHandler(findVo)
  576. if findVo then
  577. local scene_name = SceneManager.Instance:GetSceneName()
  578. local str = "<" .. scene_name .. "(" .. findVo.x .. "," .. findVo.y .. ")>"
  579. self:ReplaceInputTextMark(str)
  580. local content = string.format("<a@scene2@%s@%s@%s></a>", findVo.sceneId, findVo.x, findVo.y)
  581. local key, argStr = self.model:GetSpecFindStr()
  582. if key ~= "" then content = string.gsub(content, "scene2", key) end
  583. if argStr ~= "" then content = string.gsub(content, "></a>", argStr.."></a>") end
  584. self.model:AddArgs(str, {"", content})
  585. end
  586. end
  587. self.select_coord_id = self.model:Bind(ChatModel.SELECT_COORD_ITEM, onSelectCoordHandler)
  588. local function onSelectGoodItemHandler(goodVo)
  589. if goodVo then
  590. local content = nil
  591. local em_power_lv = 0
  592. if goodVo.type == GoodsModel.TYPE.EQUIP then
  593. content = string.format("<a@goods2@%s@%s@%s></a>", RoleManager.Instance:GetMainRoleId(),goodVo.goods_id, goodVo.type_id)
  594. if goodVo then
  595. for i,v in pairs(goodVo.other_data) do
  596. if v.type == GoodsModel.GoodsInfoType.EquipEmpower then
  597. em_power_lv = tonumber(v.info)
  598. break
  599. end
  600. end
  601. if em_power_lv == 0 and EquipModel:getInstance():IsWearEquip(goodVo.goods_id) then--如果是已穿戴
  602. local equip_cfg = EquipModel:getInstance():GetEquipmentCfg(goodVo.type_id)
  603. if equip_cfg and equip_cfg.series ~= 99 then
  604. local server_info = EquipModel:getInstance():GetRedEquipInfo(equip_cfg.series,equip_cfg.equip_type)
  605. em_power_lv = server_info and server_info.lv or 0
  606. end
  607. end
  608. if em_power_lv > 0 then
  609. content = string.format("<a@goods2@%s@%s@%s@%s></a>", RoleManager.Instance:GetMainRoleId(),goodVo.goods_id, goodVo.type_id,em_power_lv)
  610. end
  611. end
  612. else
  613. content = string.format("<a@goods4@%s></a>", goodVo.type_id)
  614. end
  615. local args = string.format("{goods,%s,%s}", goodVo.type_id, goodVo.goods_id)
  616. local str = "<" .. Trim(goodVo.goods_name) .. ">"
  617. if goodVo.type == 11 and (goodVo.subtype == 10 or goodVo.subtype == 11) then
  618. local type_id, _name, icon = EquipModel:getInstance():GetIdentifyGoodsNameAndIcon(goodVo.type_id, RoleManager.Instance.mainRoleInfo.career, goodVo.color, true)
  619. str = "<" .. _name .. ">"
  620. end
  621. self:ReplaceInputTextMark(str)
  622. self.model:AddArgs(str, {args, content})
  623. -- self.model.curr_chat_args = "{goods,"..goodVo.type_id..","..goodVo.goods_id.."}"
  624. end
  625. end
  626. self.select_goodItem_id = self.model:Bind(ChatModel.SELECT_GOOD_ITEM, onSelectGoodItemHandler)
  627. local function onSelectOtherPlayerHandler(name)
  628. local player_name = name or ""
  629. local str = "<" .. "@" .. player_name ..">"
  630. self:ReplaceInputTextMark(str)
  631. local content = string.format("<a@playername@%s></a>", player_name)
  632. local args = string.format("{playername,%s}", player_name)
  633. self.model:AddArgs(str, {"", content})
  634. end
  635. self:BindEvent(self.model, ChatModel.SELECT_OTHER_PLAYER, onSelectOtherPlayerHandler)
  636. local function onAddMsgHandler(info)
  637. self:AddMsgItem(info, true,nil,nil,nil,nil,true)
  638. end
  639. self.add_msg_id = self.model:Bind(ChatModel.ADD_NEW_MSG, onAddMsgHandler)
  640. local function onShowTabRedPointHandler(all_chat_list_count)
  641. local item = nil
  642. for i, v in ipairs(self.tabbar_list) do
  643. item = v
  644. if all_chat_list_count[item.info.channel] ~= nil and
  645. all_chat_list_count[item.info.channel] > 0 and
  646. ( item.info.channel == ChatModel.CHANNEL_INVITE or
  647. item.info.channel == ChatModel.CHANNEL_GUILD ) then
  648. item:ShowRedPoint()
  649. else
  650. item:HideRedPoint()
  651. if item.info.channel == ChatModel.CHANNEL_GUILD then -- 外部社团按钮红点
  652. self.model:SetGuildChannelRedDot(false)
  653. end
  654. end
  655. end
  656. end
  657. self.show_tab_red_point_id = self.model:Bind(ChatModel.SHOW_TAB_RED_POINT, onShowTabRedPointHandler)
  658. self.bind_update_reg_text = self.model:Bind(ChatModel.BROADCAST_VOICE_TEXT, function(scmd)
  659. local offset = 0
  660. local curr_channel_list = self.all_chatItem_list[self.model.curr_channel]
  661. if not curr_channel_list then return end
  662. for k, v in pairs(curr_channel_list) do
  663. if offset ~= 0 then
  664. v:ReLayout(offset)
  665. else
  666. if v.info.voice_id == scmd.auto_id then
  667. offset = -v:SetRegText(scmd)
  668. end
  669. end
  670. end
  671. self.curr_channel_height = self.curr_channel_height + offset
  672. end)
  673. local function onSendMsg(str)
  674. self.input_text.text = str
  675. self:SendMsg()
  676. end
  677. self.send_event_id = self.model:Bind(ChatModel.SEND_MSG_IN_VIEW, onSendMsg)
  678. self.input_text.onValueChanged:AddListener(function()
  679. local is_code_cheat = string.find(self.input_text.text,"@RunCode:")
  680. self:SetCharacterLimit(is_code_cheat and 9999 or false)--秘籍需要解除字符数限制
  681. -------------------------
  682. local len = utf8len(self.input_text.text)
  683. if len > self.send_limit and (not is_code_cheat) then
  684. self.input_text.text = self.legal_text_str or ""
  685. self.tip_time = self.tip_time or 0
  686. if Status.NowTime - self.tip_time > 0.1 then
  687. Message.show(string.format("最多可输入%d个字符", self.send_limit),"fault")
  688. self.tip_time = Status.NowTime
  689. end
  690. return
  691. end
  692. self.legal_text_str = self.input_text.text
  693. end)
  694. local function onSel(bool)
  695. -- self.bag_select_bg:SetActive(bool)
  696. -- self.ScrollViewCon:SetActive(not bool)
  697. end
  698. self.select_bag_id = self.model:Bind(ChatModel.SHOW_BAG_SELECT_BG, onSel)
  699. local function show_individual_redPoint()
  700. self:ShowIndividualRedPoint()
  701. end
  702. self.show_individual_redPoint_id = GlobalEventSystem:Bind(EventName.REFRESH_CHATDRESS_RED_DOT, show_individual_redPoint)
  703. local function update_cross_horn(count)
  704. if self.model.curr_channel ~= ChatModel.CHANNEL_CROSS and
  705. self.model.curr_channel ~= ChatModel.CHANNEL_COUNTRY then
  706. return
  707. end
  708. local str = self.model.crossChatTime > 9999999 and "无限" or self.model.crossChatTime
  709. self.crossChatTime.text = "剩余发言次数:"..str
  710. end
  711. table_insert(self.event_list, self.model:Bind(ChatModel.CROSS_HORN_HAS_CHANGE, update_cross_horn))
  712. local function update_horn()
  713. if self.model.curr_channel == ChatModel.CHANNEL_HORN then
  714. self:SetHornNum()
  715. elseif self.model.curr_channel == ChatModel.CHANNEL_CROSS then -- 跨服聊天次数限制
  716. self.model:Fire(ChatModel.REQUEST_CCMD_EVENT,11011,ChatModel.CHANNEL_CROSS)
  717. self:SetCrossHornNum()
  718. elseif self.model.curr_channel == ChatModel.CHANNEL_CROSS then -- 本服聊天次数限制
  719. self.model:Fire(ChatModel.REQUEST_CCMD_EVENT,11011,ChatModel.CHANNEL_COUNTRY)
  720. self:SetCrossHornNum()
  721. end
  722. end
  723. table_insert(self.event_list, self.model:Bind(ChatModel.HORN_HAS_CHANGE, update_horn))
  724. local function onUpdateHorn()
  725. if self.model.curr_channel ~= ChatModel.CHANNEL_HORN then
  726. return
  727. end
  728. self:SetCurHorn()
  729. end
  730. self.horn_event_id = self.model:Bind(ChatModel.UPDATE_HORNTV_NUM, onUpdateHorn)
  731. local function onGuildChange()
  732. if not RoleManager.Instance:GetMainRoleVo().guild_id then
  733. self.model.all_chat_list[ChatModel.CHANNEL_GUILD] = nil
  734. end
  735. if self.model.curr_channel == ChatModel.CHANNEL_GUILD then
  736. self:SetCurrTabbarIndex(ChatModel.CHANNEL_GUILD)
  737. self:SwitchBar()
  738. self.noGuildCon:SetActive(not RoleManager.Instance:GetMainRoleVo().guild_id or RoleManager.Instance:GetMainRoleVo().guild_id == 0)
  739. end
  740. end
  741. self.bind_guild_id = RoleManager:getInstance():GetMainRoleVo():BindOne("guild_id", onGuildChange)
  742. local function onRefreshNotice(notice_id)
  743. self:DelNoticeChatItem(notice_id)
  744. end
  745. self.notice_event_id = self.model:Bind(ChatModel.DEL_NOTICE_CHAT_ITEM, onRefreshNotice)
  746. local function changeIimitWay( index ) --占时没用到,在选择屏蔽打钩后调取
  747. -- self.co:SetActive(false)
  748. -- self.limit_way.up_img:SetActive(true)
  749. self.shieldChannelScrv:SetActive(false)
  750. local color = ColorUtil:GetColor(index)
  751. self.shieldBtntext.text = string.format("<color=%s>%s</color>",color,ChatModel.LIMIY_WAY_NAME[index])
  752. end
  753. self.change_limit_way_id = self.model:Bind(ChatModel.CHANGE_LIMIT_WAY, changeIimitWay)
  754. end
  755. function ChatView:SendMsg()
  756. local channel = self.model.curr_bar_index
  757. if self.model:CheckCurrentTimeCanSend(channel, self.send_interval) then
  758. local content = self.input_text.text
  759. if not CheatModel:getInstance():CheckCommand(content) then
  760. return
  761. end
  762. -------------------------
  763. --[[ if self.input_text.text == "@##@" then
  764. GlobalEventSystem:Fire(EventName.OPEN_CHEAT_INPUT_VIEW) --秘籍
  765. return
  766. elseif self.input_text.text == "@testclient" then
  767. GlobalEventSystem:Fire(EventName.OPEN_CHEAT_CLIENT_VIEW) --客户端秘籍
  768. return
  769. elseif self.input_text.text == "@##P@" then
  770. local cfg, scmd = {subtype = ChatModel.CHANNEL_SYSTEM}, {}
  771. for i = 1, 10 do
  772. GlobalEventSystem:Fire(EventName.SHOW_CHUANWEN, "测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试"..i, cfg, scmd)
  773. end
  774. return
  775. end]]
  776. -------------------------
  777. --[[ if RoleManager.Instance:GetMainRoleVo().GM == 0 then
  778. local is_show_word = false
  779. local fun,tbl
  780. for k, v in pairs(Config.Goods) do ---如果是发送物品的物品名字被屏蔽就跳过
  781. fun = loadstring(v)
  782. tbl = fun()
  783. local pass_name = "<"..Trim(tbl.goods_name)..">"
  784. if Trim(content) == pass_name then
  785. is_show_word = true
  786. break
  787. end
  788. end
  789. if is_show_word == false then
  790. local _, title_filter = LanguageFilter.FilterMsg(content)
  791. if title_filter == false then
  792. Message.show("内容有敏感词")
  793. return
  794. end
  795. end
  796. end]]
  797. if content and content ~= "" then
  798. if self.click_pos_content then
  799. if Trim(self.click_pos_show_str) == Trim(content) then
  800. content = self.click_pos_content
  801. self.click_pos_content = false
  802. end
  803. end
  804. local tmpArgs = self.model:GetAllArgsText(content)
  805. content = self.model:GetHyperlinkText(content)
  806. self.model:Fire(ChatModel.SEND_MSG, self.model.curr_bar_index, content, self.chating_key_id, tmpArgs)
  807. self.input_text.text = ""
  808. self.model.chat_args_dic = {}
  809. end
  810. else
  811. if self.input_text.text ~= "" then
  812. Message.show("发送频率过快,请销后再试...","fault")
  813. end
  814. end
  815. end
  816. function ChatView:SetSendTimeText()
  817. if self._use_delete_method then return end
  818. local channel = self.model.curr_bar_index
  819. local time = self.model:GetPassTimeFromSend(channel, self.send_interval)
  820. if time > 0 then
  821. local str = math.ceil(time) .. "s"
  822. self.sendBtn_text.text = str
  823. else
  824. self:CancelSendTimer()
  825. self.sendBtn_text.text = "发送"
  826. end
  827. return time
  828. end
  829. function ChatView:UpdateSendTime()
  830. local time = self:SetSendTimeText()
  831. if time > 0 then
  832. self:CancelSendTimer()
  833. local function onSendTimerPlaying()
  834. self:SetSendTimeText()
  835. end
  836. self.send_timer_id = GlobalTimerQuest:AddPeriodQuest(onSendTimerPlaying, 1, -1)
  837. end
  838. end
  839. --添加一个聊天信息 autoLayout是否自动布局 record 是不是要记录这个item为最后创建的item not_from_model --是不是新消息
  840. function ChatView:AddMsgItem(info, autoLayout, custom_height, not_from_model, custom_line, is_delay_callback,new_msg)
  841. if self.view_is_close then return end
  842. local curr_channel = self.model.curr_bar_index
  843. if info.channel == ChatModel.CHANNEL_HORN then
  844. 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
  845. return
  846. end
  847. else
  848. if info.channel ~= self.model.curr_channel and self.model.curr_channel ~= ChatModel.CHANNEL_GENERAL then
  849. return
  850. end
  851. end
  852. --if curr_channel ~= info.channel and info.channel ~= ChatModel.CHANNEL_HORN then return end
  853. -- if info.channel == ChatModel.CHANNEL_HORN and curr_channel ~= ChatModel.CHANNEL_WORLD then return end
  854. if info.channel == ChatModel.CHANNEL_NONE then return end
  855. if info.channel == ChatModel.CHANNEL_CECRET then return end
  856. -- 没社团时不显示社团活动消息
  857. if info.channel == ChatModel.CHANNEL_GUILD and (not RoleManager.Instance:GetMainRoleVo().guild_id or RoleManager.Instance:GetMainRoleVo().guild_id == 0) then return end
  858. if self.is_init_operate and not not_from_model then
  859. table_insert(self.need_add_msg, {info = info, autoLayout = autoLayoutm, custom_height = custom_height})
  860. return
  861. end
  862. if not custom_line then
  863. 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
  864. local time_off = info.time - self.pre_renderer_chatItem.info.time
  865. if time_off >= ChatModel.SHOW_LINE_TIME then --说话间隔大于该时间 就要添加横线时间
  866. self.pre_renderer_chatItem = nil
  867. local lineInfo = self.model:PackChatInfo(curr_channel, info.time, info.key_id)
  868. -- self:AddMsgItem(lineInfo, false)
  869. self:AddMsgItem(lineInfo, not not_from_model, custom_height, not_from_model)
  870. end
  871. end
  872. end
  873. local curr_channel_list = self.all_chatItem_list[curr_channel]
  874. if curr_channel_list == nil then
  875. curr_channel_list = {}
  876. self.all_chatItem_list[curr_channel] = curr_channel_list
  877. end
  878. local new_item
  879. if #self.cache_chatItem_list > 0 then
  880. new_item = table_remove(self.cache_chatItem_list, 1)
  881. else
  882. new_item = ChatItem.New(self.scroll_content, self.chatItem_prefab, self.layer_name,is_delay_callback,self.is_initialized)--, self.chatItem_prefab)
  883. end
  884. local function do_next(new_item_height)
  885. if #curr_channel_list < ChatModel.MAX_LEN_LIST[curr_channel] then
  886. table_insert(curr_channel_list, new_item)
  887. else
  888. table_insert(self.pre_channel_list, new_item)
  889. end
  890. if autoLayout then
  891. self:ReLayoutScroll()
  892. end
  893. if new_item:IsLineItem() then
  894. new_item:SetLineTimeColor(ColorType.WHITE)
  895. new_item:SetLineSize()
  896. end
  897. if self.is_init_operate and not self.pre_renderer_chatItem and not new_item:IsLineItem() then
  898. self.pre_renderer_chatItem = new_item
  899. end
  900. if not self.is_init_operate and not new_item:IsLineItem() then
  901. self.pre_renderer_chatItem = new_item
  902. end
  903. --未读消息处理
  904. if self.is_lock and new_msg then
  905. if (not info.player_id or info.player_id ~= RoleManager.Instance:GetMainRoleId()) and not info.is_line then
  906. self:ShowNotReadMsgNum(1)
  907. table_insert(self.cache_not_read_list,new_item_height)
  908. end
  909. else
  910. self:ShowNotReadMsgNum(0, true)
  911. end
  912. end
  913. if custom_height then
  914. new_item:SetData(info, custom_height)
  915. self:SetCurItemData({height = custom_height,item = new_item,info = info})
  916. do_next(custom_height)
  917. else
  918. local function call_back(height)
  919. new_item:SetData(info, self.curr_channel_height)
  920. self:SetCurItemData({height = custom_height,item = new_item,info = info})
  921. self.curr_channel_height = self.curr_channel_height + height
  922. do_next(self.curr_channel_height)
  923. end
  924. self:GetItemHeight(info, call_back)
  925. end
  926. self.scroll_rect.enabled = true
  927. end
  928. --增或减就行了
  929. function ChatView:ShowNotReadMsgNum(add_num, is_reset)
  930. if is_reset then
  931. -- self.notReadCon:SetActive(false) -- 未读消息框取消显示
  932. self.cache_not_read_list = {}
  933. self.not_read_count = 0
  934. self.not_read_text.text = ""
  935. return
  936. end
  937. self.not_read_count = self.not_read_count and self.not_read_count + add_num or 0
  938. if self.not_read_count <= 0 then
  939. self:ShowNotReadMsgNum(0, true)
  940. return
  941. end
  942. -- self.notReadCon:SetActive(true)-- 未读消息框取消显示
  943. self.not_read_text.text = "您有"..self.not_read_count.."条消息未读"
  944. end
  945. --改变交流类型 文本或者语音
  946. function ChatView:ChangeTalkType()
  947. if self.is_talk_to_text then
  948. lua_resM:setImageSprite(self, self.voiceImg, "chat_asset", "chat_ui_2")
  949. self.input_con:SetActive(true)
  950. self.sendBtn:SetActive(true)
  951. else
  952. lua_resM:setImageSprite(self, self.voiceImg, "chat_asset", "chat_ui_3")
  953. self.input_con:SetActive(false)
  954. self.sendBtn:SetActive(false)
  955. end
  956. end
  957. function ChatView:Open(channel)
  958. MainUIModel:getInstance().main_voice_channel = self.model.curr_channel == 0 and ChatModel.CHANNEL_WORLD or self.model.curr_channel
  959. self:SetCurrTabbarIndex(channel)
  960. BaseView.Open(self)
  961. end
  962. function ChatView:SetCurrTabbarIndex(channel)
  963. self.model.pre_bar_index = self.model.curr_bar_index
  964. self.model.curr_bar_index = channel or self.model.curr_bar_index
  965. end
  966. function ChatView:Close()
  967. self.model.curr_channel = 0
  968. if self.is_moving == false then
  969. local function onCompleted()
  970. --保存聊天记录
  971. CookieWrapper.Instance:WriteChatHistroy()
  972. CookieWrapper.Instance.chat_histroy_id = nil
  973. self.is_moving = false
  974. self.model.clicked_role_item = nil
  975. BaseView.Close(self)
  976. end
  977. self.is_moving = true
  978. TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POS, Vector2(-SrcScreenWidth / 2, 0), 0.1, onCompleted)
  979. end
  980. end
  981. function ChatView:ShowChannelObj(curr_channel)
  982. if curr_channel == ChatModel.CHANNEL_HORN then
  983. self.hornCon:SetActive(true)
  984. self.crossChatCon:SetActive(false)
  985. self.noGuildCon:SetActive(false)
  986. self.goTeamBtn:SetActive(false)
  987. elseif curr_channel == ChatModel.CHANNEL_CROSS or
  988. curr_channel == ChatModel.CHANNEL_COUNTRY then
  989. self.hornCon:SetActive(false)
  990. self.crossChatCon:SetActive(true)
  991. self.noGuildCon:SetActive(false)
  992. self.goTeamBtn:SetActive(false)
  993. else
  994. self.hornCon:SetActive(false)
  995. self.crossChatCon:SetActive(false)
  996. self.noGuildCon:SetActive(false)
  997. self.goTeamBtn:SetActive(false)
  998. end
  999. end
  1000. function ChatView:SwitchBar()
  1001. -- print('Cat:ChatView.lua[1050] SwitchBar()')
  1002. self:ResetLockState()
  1003. self:CancelGetHeightQuest()
  1004. self:CancelAddMsgTimer()
  1005. GlobalEventSystem:Fire(EventName.CLOSE_INDIVIDUATION_VIEW)
  1006. local curr_channel = self.model.curr_bar_index
  1007. local tabbar_item
  1008. for k, v in pairs(self.tabbar_list) do
  1009. if v.channel == self.model.curr_bar_index then
  1010. tabbar_item = v
  1011. end
  1012. end
  1013. if tabbar_item then
  1014. self:SetSendFormat(tabbar_item.info)
  1015. self:InitModelInfo(self.model.curr_bar_index)
  1016. self.model:SeletedChatViewTabbar(tabbar_item, true)
  1017. self.model:Fire(ChatModel.SHOW_TAB_RED_POINT, self.model.all_chat_list_count)
  1018. self:UpdateSendTime()
  1019. local pre_channel = self.model.pre_bar_index
  1020. local pre_channel_list = self.all_chatItem_list[pre_channel]
  1021. if pre_channel_list then
  1022. for i, item in pairs(pre_channel_list) do
  1023. table_insert(self.cache_chatItem_list, item)
  1024. end
  1025. end
  1026. self.all_chatItem_list[pre_channel] = {}
  1027. -- print(TableSize(self.pre_channel_list))
  1028. if self.pre_channel_list then
  1029. for i, item in pairs(self.pre_channel_list) do
  1030. table_insert(self.cache_chatItem_list, item)
  1031. end
  1032. end
  1033. self.pre_channel_list = {}
  1034. local vo = nil
  1035. local item = nil
  1036. self.curr_channel_height = 0
  1037. self.pre_renderer_chatItem = nil
  1038. local len = 0
  1039. self:ShowChannelObj(curr_channel)
  1040. local vo = RoleManager.Instance:GetMainRoleVo()
  1041. local mainRole_level = vo.level
  1042. local guild_id = vo.guild_id
  1043. -- self.shieldChannelCon:SetActive(false)
  1044. if curr_channel == ChatModel.CHANNEL_INVITE then
  1045. self.bottom_con.gameObject:SetActive(false)
  1046. self.bottom_con2.gameObject:SetActive(true)
  1047. self.bottom_con2_text.text = "请切换其他频道聊天"
  1048. else
  1049. if mainRole_level >= tabbar_item.info.level or PlatformMgr:getInstance():IsIflyRecord() then
  1050. if curr_channel == ChatModel.CHANNEL_SYSTEM then
  1051. self.bottom_con.gameObject:SetActive(false)
  1052. self.bottom_con2.gameObject:SetActive(true)
  1053. self.bottom_con2_text.text = "请切换其他频道聊天"
  1054. elseif curr_channel == ChatModel.CHANNEL_GENERAL then
  1055. self.bottom_con.gameObject:SetActive(false)
  1056. self.bottom_con2.gameObject:SetActive(true)
  1057. self.bottom_con2_text.text = "请切换其他频道聊天"
  1058. -- self.shieldChannelCon:SetActive(true)
  1059. self.shieldChannelScrv:SetActive(false)
  1060. elseif curr_channel == ChatModel.CHANNEL_TEAM and not TeamModel:getInstance().in_team then
  1061. self.bottom_con.gameObject:SetActive(false)
  1062. self.bottom_con2.gameObject:SetActive(true)
  1063. self.bottom_con2_text.text = "您当前未加入队伍"
  1064. self.goTeamBtn:SetActive(true)
  1065. elseif curr_channel == ChatModel.CHANNEL_GUILD then
  1066. if guild_id == 0 then
  1067. self.bottom_con.gameObject:SetActive(false)
  1068. self.bottom_con2.gameObject:SetActive(true)
  1069. self.bottom_con2_text.text = "您当前未加入社团"
  1070. else
  1071. self.bottom_con.gameObject:SetActive(true)
  1072. self.bottom_con2.gameObject:SetActive(false)
  1073. self.bottom_con2_text.text = ""
  1074. end
  1075. self.noGuildCon:SetActive(guild_id == 0)
  1076. --[[ elseif curr_channel == ChatModel.CHANNEL_HORN then
  1077. local channel = self.model:GetChannelWithId(curr_channel)
  1078. if RoleManager.Instance.mainRoleInfo.level >= channel.level then
  1079. -- GlobalEventSystem:Fire(EventName.OPEN_HORN_VIEW)
  1080. self.bottom_con.gameObject:SetActive(true)
  1081. self.bottom_con2.gameObject:SetActive(false)
  1082. self.bottom_con2_text.text = ""
  1083. self:SetHornNum()
  1084. self:SetCurHorn()
  1085. else
  1086. self.bottom_con.gameObject:SetActive(false)
  1087. self.bottom_con2.gameObject:SetActive(true)
  1088. self.bottom_con2_text.text = string.format("%d级后可发送喇叭", channel.level)
  1089. -- Message.show(string.format("%d级后可发送喇叭", channel.level))
  1090. end]]
  1091. elseif curr_channel == ChatModel.CHANNEL_CROSS then
  1092. local channel = self.model:GetChannelWithId(curr_channel)
  1093. if RoleManager.Instance.mainRoleInfo.level >= channel.level then
  1094. -- GlobalEventSystem:Fire(EventName.OPEN_HORN_VIEW)
  1095. self.bottom_con.gameObject:SetActive(true)
  1096. self.bottom_con2.gameObject:SetActive(false)
  1097. self.bottom_con2_text.text = ""
  1098. local str = self.model.crossChatTime > 9999999 and "无限" or self.model.crossChatTime
  1099. self.crossChatTime.text = "剩余发言次数:"..str
  1100. self:SetCrossHornNum()
  1101. else
  1102. self.bottom_con.gameObject:SetActive(false)
  1103. self.bottom_con2.gameObject:SetActive(true)
  1104. self.bottom_con2_text.text = string.format("%d级后可开启", channel.level)
  1105. -- Message.show(string.format("%d级后可发送喇叭", channel.level))
  1106. end
  1107. elseif curr_channel == ChatModel.CHANNEL_COUNTRY then
  1108. local channel = self.model:GetChannelWithId(curr_channel)
  1109. if RoleManager.Instance.mainRoleInfo.level >= channel.level then
  1110. self.bottom_con.gameObject:SetActive(true)
  1111. self.bottom_con2.gameObject:SetActive(false)
  1112. self.bottom_con2_text.text = ""
  1113. -- local str = self.model.crossChatTime > 9999999 and "无限" or self.model.crossChatTime
  1114. -- self.crossChatTime.text = "剩余发言次数:"..str
  1115. -- self:SetCrossHornNum()
  1116. else
  1117. self.bottom_con.gameObject:SetActive(false)
  1118. self.bottom_con2.gameObject:SetActive(true)
  1119. self.bottom_con2_text.text = string.format("%d级后可开启", channel.level)
  1120. end
  1121. elseif curr_channel == ChatModel.CHANNEL_WORLD then
  1122. if RoleManager.Instance.mainRoleInfo.level >= Config.Moduleid[110].open_lv then
  1123. self.bottom_con.gameObject:SetActive(true)
  1124. self.bottom_con2.gameObject:SetActive(false)
  1125. else
  1126. self.bottom_con.gameObject:SetActive(false)
  1127. self.bottom_con2.gameObject:SetActive(true)
  1128. self.bottom_con2_text.text = string.format("%d级开启世界频道", Config.Moduleid[110].open_lv)
  1129. end
  1130. -- self.shieldChannelCon:SetActive(true)
  1131. self.shieldChannelScrv:SetActive(false)
  1132. else
  1133. self.bottom_con.gameObject:SetActive(true)
  1134. self.bottom_con2.gameObject:SetActive(false)
  1135. end
  1136. else
  1137. self.bottom_con.gameObject:SetActive(false)
  1138. self.bottom_con2.gameObject:SetActive(true)
  1139. local cfg = ChatModel:getInstance():GetChannelWithId(curr_channel)
  1140. self.bottom_con2_text.text = cfg.tip
  1141. end
  1142. end
  1143. -- self.bottom_con2_text.rectTransform.anchoredPosition = Vector3(240 - self.bottom_con2_text.preferredWidth / 2, 20, 0)
  1144. -- self.bottom_con2_image.rectTransform.anchoredPosition = Vector3(-self.bottom_con2_text.preferredWidth / 2, 0, 0)
  1145. self.model:SetChannelGennealList(curr_channel) -- 加入综合频道
  1146. local curr_channel_list = self.model.all_chat_list[curr_channel] --筛出当前频道的聊天数据
  1147. if curr_channel_list then
  1148. self.scroll_rect.enabled = #curr_channel_list > 0
  1149. local item_list = self.all_chatItem_list[curr_channel] or {}
  1150. for _, item in pairs(item_list) do
  1151. item:ResetText()
  1152. table_insert(self.cache_chatItem_list, item)
  1153. end
  1154. self.all_chatItem_list[curr_channel] = {}
  1155. self:SetFirstOpenViewInitItem(curr_channel_list)
  1156. else
  1157. self:HideCurChannelItem()
  1158. self:ReLayoutScroll()
  1159. end
  1160. end
  1161. self:ShowNotReadMsgNum(0, true)
  1162. end
  1163. function ChatView:CheckNeedInstanceData()
  1164. if #self.need_add_msg > 0 then
  1165. local list = self.need_add_msg
  1166. self.need_add_msg = {}
  1167. for i, v in ipairs(list) do
  1168. self:AddMsgItem(v.info, v.autoLayout, v.custom_height)
  1169. end
  1170. self.is_init_operate = false
  1171. self:CheckNeedInstanceData()
  1172. end
  1173. self:HideAllItem()
  1174. end
  1175. function ChatView:HideAllItem( )
  1176. for _, item in pairs(self.cache_chatItem_list) do
  1177. item:SetVisible(false)
  1178. end
  1179. end
  1180. function ChatView:RefreshShieldBtn()
  1181. --判断是否显示屏蔽语音按钮
  1182. if GameSettingManager.blockChannel[self.model.curr_channel] then
  1183. self.shieldBtn:SetActive(true)
  1184. local key = GameSettingManager.blockChannel[self.model.curr_channel]
  1185. local isShield = GameSettingManager:getInstance():GetBlockProperty(key)
  1186. if isShield then
  1187. lua_resM:setImageSprite(self, self.shieldImg, "chat_asset", "chat_shield_2", true)
  1188. else
  1189. lua_resM:setImageSprite(self, self.shieldImg, "chat_asset", "chat_shield_1", true)
  1190. end
  1191. else
  1192. self.shieldBtn:SetActive(false)
  1193. end
  1194. end
  1195. --重新布局滚动条大小 以及位置
  1196. function ChatView:ReLayoutScroll(force)
  1197. if self.model.curr_bar_index == ChatModel.CHANNEL_CROSS or
  1198. self.model.curr_bar_index == ChatModel.CHANNEL_HORN or
  1199. self.model.curr_bar_index == ChatModel.CHANNEL_COUNTRY then
  1200. -- self.ScrollView.sizeDelta = Vector2(576, ScreenHeight - 164) --适配屏幕高度,勿改
  1201. -- self.ScrollView.anchoredPosition = Vector3(138, -67, self.ScrollView.anchoredPosition.z)
  1202. -- self.ScrollView.anchoredPosition = Vector2(self.ScrollView.anchoredPosition.x, -68)
  1203. self.ScrollView.sizeDelta = Vector2(516.5, ScreenHeight - 74) --适配屏幕高度,勿改
  1204. self.ScrollView.anchoredPosition = Vector3(123, -2.9, self.ScrollView.anchoredPosition.z)
  1205. elseif self.model.curr_bar_index == ChatModel.CHANNEL_GENERAL then
  1206. self.ScrollView.sizeDelta = Vector2(516.5, ScreenHeight - 74) --适配屏幕高度,勿改
  1207. self.ScrollView.anchoredPosition = Vector3(125, -2.9, self.ScrollView.anchoredPosition.z)
  1208. -- self.ScrollView.anchoredPosition = Vector2(121, -24.5)
  1209. else
  1210. self.ScrollView.sizeDelta = Vector2(516.5, ScreenHeight - 74) --适配屏幕高度,勿改
  1211. self.ScrollView.anchoredPosition = Vector3(123, -2.9, self.ScrollView.anchoredPosition.z)
  1212. end
  1213. self.scroll_content.sizeDelta = Vector2(490, self.curr_channel_height)
  1214. local off_h = self.scroll_content.sizeDelta.y - self.ScrollView.sizeDelta.y
  1215. off_h = off_h < 0 and 0 or off_h
  1216. self.last_scroll_content_posy = off_h
  1217. if self.is_lock and not force then
  1218. return
  1219. end
  1220. if not self.is_lock or force then
  1221. self.scroll_content.localPosition = Vector3(0, off_h, 0)
  1222. end
  1223. end
  1224. --设置发送的格式
  1225. function ChatView:SetSendFormat(info)
  1226. self.send_interval = info.send_interval
  1227. self.send_limit = info.send_limit
  1228. self:SetCharacterLimit(self.send_limit)
  1229. end
  1230. function ChatView:SetCharacterLimit( send_limit )
  1231. send_limit = send_limit or self.send_limit
  1232. self.input_text.characterLimit = send_limit + 1 --多一位触发onvaluechange
  1233. end
  1234. function ChatView:InitModelInfo(index)
  1235. local curr_channel = index
  1236. self.model.curr_channel = curr_channel
  1237. self.model:ClearChannelMessageNum(curr_channel)
  1238. end
  1239. function ChatView:ReplaceInputTextMark(str)
  1240. self.input_text_onValueChanged_addListener_off = true
  1241. --替换规则是"(<.->)"
  1242. local text = self.input_text.text
  1243. local old_args = self.model:IsHasArgs(text)
  1244. if (string.find(text, "(<.->)") and old_args) then
  1245. old_args = LanguageFilter.ConvPartten(old_args)
  1246. local newStr = string.gsub(text, old_args, str)
  1247. if utf8len(newStr) > self.send_limit then
  1248. Message.show(string.format("最多可输入%d个字符", self.send_limit),"fault")
  1249. else
  1250. self.input_text.text = newStr
  1251. end
  1252. else
  1253. local newStr = text .. str
  1254. if utf8len(newStr) > self.send_limit then
  1255. Message.show(string.format("最多可输入%d个字符", self.send_limit),"fault")
  1256. else
  1257. self.input_text.text = newStr
  1258. end
  1259. end
  1260. self.input_text_onValueChanged_addListener_off = false
  1261. return str
  1262. end
  1263. -- 显示装扮红点
  1264. function ChatView:ShowIndividualRedPoint()
  1265. local bool = ChatDressModel:getInstance():ShowChatDressRedPoint()
  1266. self.individual_RedPoint:SetActive(bool)
  1267. end
  1268. --设置喇叭的数量
  1269. function ChatView:SetHornNum()
  1270. local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.horn_id)
  1271. local cur_own = GoodsModel:getInstance():GetTypeGoodsNum(self.horn_id)
  1272. local str = "您拥有的喇叭:"
  1273. if basic then
  1274. if cur_own == 0 then
  1275. self.hasHorn.text = str.."<color=#de4141>" .. cur_own .. "</color>"
  1276. else
  1277. self.hasHorn.text = str.."<color=#73AC44FF>" .. cur_own .. "</color>"
  1278. end
  1279. else
  1280. self.hasHorn.text = str.."<color=#de4141>0</color>"
  1281. end
  1282. end
  1283. --设置跨服喇叭的数量
  1284. function ChatView:SetCrossHornNum()
  1285. local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.cross_horn_id)
  1286. local cur_own = GoodsModel:getInstance():GetTypeGoodsNum(self.cross_horn_id)
  1287. local str = "您拥有的喇叭:"
  1288. if basic then
  1289. if cur_own == 0 then
  1290. self.has_cross_horn.text = str.."<color=#de4141>" .. cur_own .. "</color>"
  1291. else
  1292. self.has_cross_horn.text = str.."<color=#73AC44FF>" .. cur_own .. "</color>"
  1293. end
  1294. else
  1295. self.has_cross_horn.text = str.."<color=#de4141>0</color>"
  1296. end
  1297. end
  1298. function ChatView:GetHornNum()
  1299. return GoodsModel:getInstance():GetTypeGoodsNum(self.horn_id)
  1300. end
  1301. --设置喇叭排队数量
  1302. function ChatView:SetCurHorn()
  1303. if self.model.curr_channel ~= ChatModel.CHANNEL_HORN then
  1304. return
  1305. end
  1306. local num = self.model:GetDelayHornNum()
  1307. if self.curHorn then
  1308. self.curHorn.text = string.format("当前排队喇叭:%d", num)
  1309. end
  1310. end
  1311. function ChatView:DelNoticeChatItem(notice_id)
  1312. local index_tb = {}
  1313. for k, v in pairs(self.all_chatItem_list[ChatModel.CHANNEL_SYSTEM]) do
  1314. if v.info and v.info.notice_id == notice_id then
  1315. table_insert(index_tb, k)
  1316. end
  1317. end
  1318. local del = 0
  1319. local num = 0
  1320. for k, v in ipairs(index_tb) do
  1321. del = v - num
  1322. local item = table_remove(self.all_chatItem_list[ChatModel.CHANNEL_SYSTEM], del)
  1323. self.curr_channel_height = self.curr_channel_height - item:GetHeight()
  1324. item:DeleteMe()
  1325. num = num + 1
  1326. end
  1327. self:ReLayoutScroll()
  1328. local pre_item
  1329. local cur_item
  1330. for i = 1, #self.all_chatItem_list[ChatModel.CHANNEL_SYSTEM] do
  1331. cur_item = self.all_chatItem_list[ChatModel.CHANNEL_SYSTEM][i]
  1332. if i == 1 then
  1333. cur_item.transform.anchoredPosition = Vector2(0, 0)
  1334. else
  1335. pre_item = self.all_chatItem_list[ChatModel.CHANNEL_SYSTEM][i - 1]
  1336. cur_item.transform.anchoredPosition = Vector2(0, pre_item.transform.anchoredPosition.y - pre_item:GetHeight())
  1337. end
  1338. end
  1339. end
  1340. function ChatView:CancelAddMsgTimer( )
  1341. if self.msg_timer_id then
  1342. GlobalTimerQuest:CancelQuest(self.msg_timer_id)
  1343. self.msg_timer_id = nil
  1344. end
  1345. end
  1346. function ChatView:GetItemHeight(info, call_back)
  1347. local base_add = 40 -- 距离顶部的高度
  1348. local channel = info.showtype == nil and info.channel or info.showtype
  1349. --print('Msh:ChatView.lua[1470] data', data)
  1350. --PrintTable(info)
  1351. if channel == ChatModel.CHANNEL_SYSTEM then
  1352. local function temp_call(height,info)
  1353. -- 区别普通消息 和 传闻喇叭消息
  1354. if (not info.chuanwen_type) or info.chuanwen_type == ChatModel.CHUANWEN_TYPE.NORMAL then -- 系统消息
  1355. height = height
  1356. else -- 传闻
  1357. --print('Msh:ChatView.lua[1476] data', info.chuanwen_type)
  1358. --PrintTable(info)
  1359. local min_height = Config.ConfigChat.Chuanwen_space
  1360. height = height < min_height and min_height or height
  1361. end
  1362. call_back(Config.ConfigChat.Sys_item_space + height )--高度在这边设置
  1363. end
  1364. self.static_system_text_tr.sizeDelta = Vector2(421.3,self.static_system_text_tr.sizeDelta.y) --- 一样适应问题宽度的最终计算在这边
  1365. self:GetTextHeight(self.static_system_text, self.static_system_text_tr, info.msg, temp_call,info) -- 最后这个info只是为了确认是否传闻加底用04/15
  1366. elseif info.is_line or info.show_num then
  1367. call_back(30 + base_add)
  1368. elseif info.player_id ~= RoleManager.Instance:GetMainRoleId() then
  1369. local player_dress_bubble = Config.ConfigChatDress.DefaultBubble
  1370. if info.dress_list then
  1371. for i, v in ipairs(info.dress_list) do
  1372. --1气泡 2相框
  1373. if v.dress_id ~= 0 then
  1374. local icon_name = v.dress_id
  1375. if v.dress_type == 1 then
  1376. player_dress_bubble = Trim(icon_name)
  1377. end
  1378. end
  1379. end
  1380. end
  1381. local function temp_call(height)
  1382. local text_size_y = height
  1383. local bg_size = player_dress_bubble and self.dress_bubble_role_bg_add_size or self.role_bg_add_size
  1384. local bg_size_y = 0
  1385. if player_dress_bubble and Config.ConfigChatDress.Pos[player_dress_bubble] then
  1386. local addTable = Config.ConfigChatDress.Pos[player_dress_bubble]
  1387. bg_size = co.AddXY(bg_size, co.TableXY(addTable.size_x,addTable.size_y))
  1388. end
  1389. if info.iType == ChatModel.MSG_TYPE.VOICE then
  1390. bg_size_y = bg_size.y + text_size_y + self.voice_bg_add_size.y
  1391. else
  1392. bg_size_y = math.max(bg_size.y + text_size_y, self.role_bg_min_size.y)
  1393. end
  1394. call_back(math.max(bg_size_y + 30 +10, 95) + base_add-23)
  1395. end
  1396. self:GetTextHeight(self.static_player_text, self.static_player_text_tr, info.msg, temp_call)
  1397. elseif info.player_id == RoleManager.Instance:GetMainRoleId() then
  1398. local main_role_dress_bubble = Config.ConfigChatDress.DefaultBubble--有没有气泡
  1399. if info.dress_list then
  1400. for i, v in ipairs(info.dress_list) do
  1401. --1气泡 2相框
  1402. if v.dress_id ~= 0 then
  1403. local icon_name = v.dress_id
  1404. if v.dress_type == 1 then
  1405. main_role_dress_bubble = Trim(icon_name)
  1406. end
  1407. end
  1408. end
  1409. end
  1410. local function temp_call(height)
  1411. local text_size = co.TableXY(math.min(self.role_text_width, self.static_mainRole_text.preferredWidth), self.static_mainRole_text.preferredHeight)
  1412. --主角
  1413. local bg_size = main_role_dress_bubble and self.dress_bubble_role_bg_add_size or self.role_bg_add_size
  1414. if main_role_dress_bubble and Config.ConfigChatDress.Pos[main_role_dress_bubble] then
  1415. local addTable = Config.ConfigChatDress.Pos[main_role_dress_bubble]
  1416. bg_size = co.AddXY(bg_size, co.TableXY(addTable.size_x,addTable.size_y))
  1417. end
  1418. local bg_size_y = 0
  1419. if info.iType == ChatModel.MSG_TYPE.VOICE then
  1420. bg_size_y = bg_size.y + text_size.y + self.voice_bg_add_size.y
  1421. else
  1422. bg_size_y = math.max(bg_size.y + text_size.y, self.role_bg_min_size.y)
  1423. end
  1424. call_back(math.max(bg_size_y + 30 +10, 95) + base_add-23)
  1425. end
  1426. self:GetTextHeight(self.static_mainRole_text, self.static_mainRole_text_tr, info.msg, temp_call)
  1427. else
  1428. call_back(base_add)
  1429. end
  1430. end
  1431. function ChatView:GetTextHeight(text_component,text_transform, msg, call_back,info)
  1432. local height = 0
  1433. self:CancelGetHeightQuest()
  1434. if text_component then
  1435. text_component.text = ""
  1436. text_transform.sizeDelta = Vector2(text_transform.sizeDelta.x, 10)
  1437. SetInlineText(text_component,msg)
  1438. -- text_component.text = msg
  1439. height = text_component.preferredHeight
  1440. call_back(height,info)
  1441. -- local function timer_func()
  1442. -- height = text_component.preferredHeight
  1443. -- call_back(height)
  1444. -- end
  1445. -- self.get_height_timer = GlobalTimerQuest:AddDelayQuest(timer_func, 0.02)
  1446. else
  1447. call_back(height,info)
  1448. end
  1449. end
  1450. function ChatView:CancelGetHeightQuest()
  1451. if self.get_height_timer then
  1452. GlobalTimerQuest:CancelQuest(self.get_height_timer)
  1453. self.get_height_timer = nil
  1454. end
  1455. end
  1456. --第一次打开界面做的处理 -- list的初建
  1457. function ChatView:SetFirstOpenViewInitItem(curr_channel_list)
  1458. local msg_len = #curr_channel_list
  1459. local need_add_list = {}
  1460. local content_height = 0
  1461. local len_count = 1
  1462. local pos_y = 0
  1463. if msg_len <= 0 then
  1464. return
  1465. end
  1466. self.is_init_operate = true --正在设置坐标中
  1467. self.has_init_item = true
  1468. local last_time = TimeUtil:getClientTimeMs( )
  1469. local function calContentSize() -- 一直调自己到len_count == msg_len
  1470. local vo = curr_channel_list[len_count]
  1471. if vo then
  1472. need_add_list[len_count] = {height = content_height, info = vo}
  1473. local function call_back(height)
  1474. content_height = content_height + height
  1475. if len_count == msg_len then -- 全部计算好了
  1476. self.curr_channel_height = content_height
  1477. self:ReLayoutScroll(true)
  1478. pos_y = self.scroll_content.sizeDelta.y - self.ScrollView.sizeDelta.y --
  1479. local over_count = self.is_initialized and msg_len or 5 -- 这里做个阈值
  1480. if not self.is_initialized then
  1481. self.is_initialized = true --表示已经分帧加载过了
  1482. end
  1483. if msg_len >= over_count then
  1484. local cur_index = msg_len --创建到第几个了 倒序创建
  1485. self:CancelAddMsgTimer()
  1486. for i = 1, over_count do
  1487. self:AddMsgItem(need_add_list[cur_index].info, false, need_add_list[cur_index].height, true, false, false)
  1488. cur_index = cur_index - 1
  1489. end
  1490. if cur_index > 0 then
  1491. local function time_func()
  1492. if not self.last_frame then
  1493. self.last_frame = Time.frameCount
  1494. end
  1495. if Time.frameCount - self.last_frame >= 1 then
  1496. self.last_frame = Time.frameCount
  1497. local data = need_add_list[cur_index]
  1498. if not data then
  1499. self:DoAfferFirstInit()
  1500. else
  1501. self:AddMsgItem(need_add_list[cur_index].info, false, need_add_list[cur_index].height, true, false, true)
  1502. cur_index = cur_index - 1
  1503. if need_add_list[cur_index] and need_add_list[cur_index].height - pos_y < -200 then
  1504. for i = cur_index, 1, -1 do
  1505. self.need_instance_data_list[i] = need_add_list[i]
  1506. end
  1507. self:DoAfferFirstInit()
  1508. end
  1509. end
  1510. end
  1511. end
  1512. self.msg_timer_id = GlobalTimerQuest:AddPeriodQuest(time_func, 0.01)--AddDelayQuest
  1513. else
  1514. self:DoAfferFirstInit()
  1515. end
  1516. else
  1517. for i = #need_add_list, 1, -1 do
  1518. self:AddMsgItem(need_add_list[i].info, false, need_add_list[i].height, true, false, true)
  1519. end
  1520. self:DoAfferFirstInit()
  1521. end
  1522. else
  1523. len_count = len_count + 1
  1524. local next_vo = curr_channel_list[len_count] --检查下一个是不是时间线
  1525. local is_line = self:CheckIsLine(next_vo)
  1526. if is_line then
  1527. local curr_channel = self.model.curr_bar_index
  1528. local lineInfo = self.model:PackChatInfo(curr_channel, next_vo.time, next_vo.key_id)
  1529. table_insert(self.need_add_line_list,{height = content_height,info = lineInfo})
  1530. content_height = content_height + 50
  1531. end
  1532. calContentSize()
  1533. end
  1534. end
  1535. self.pre_vo = vo
  1536. self:GetItemHeight(vo, call_back)
  1537. end
  1538. end
  1539. calContentSize()
  1540. end
  1541. function ChatView:CreateTimeLine( )
  1542. for i=1, #self.need_add_line_list do
  1543. local data = self.need_add_line_list[i]
  1544. if data then
  1545. self:AddMsgItem(data.info,false,data.height,true,true,true)
  1546. end
  1547. end
  1548. self.need_add_line_list = {}
  1549. end
  1550. function ChatView:CheckIsLine(vo)
  1551. local is_line = false
  1552. if not vo then return false end
  1553. 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
  1554. is_line = true
  1555. vo.is_line_flag = true
  1556. end
  1557. return is_line
  1558. end
  1559. function ChatView:Create( ... )
  1560. -- body
  1561. end
  1562. --计算显示那些没有创出来的item
  1563. function ChatView:CalcuInHideItem()
  1564. local len = #self.need_instance_data_list
  1565. if len > 0 then
  1566. local data = self.need_instance_data_list[len]
  1567. if data then
  1568. local height = data.height + 100
  1569. if self.scroll_content.localPosition.y <= height then
  1570. table_remove(self.need_instance_data_list, len)
  1571. self:AddMsgItem(data.info, false, data.height)
  1572. end
  1573. end
  1574. end
  1575. end
  1576. --切换页签的时候重置数据
  1577. function ChatView:ResetLockState()
  1578. self.scroll_content_drag = false
  1579. self.scroll_content_drag2 = false
  1580. self.is_lock = false
  1581. self.scroll_rect.enabled = false
  1582. self.need_instance_data_list = {}
  1583. self.front_item_data_list = {}
  1584. self.back_item_data_list = {}
  1585. self.cur_item_data_list = {}
  1586. lua_resM:setImageSprite(self, self.lock_img, "chat_asset", "icon_chat_unlocked")
  1587. end
  1588. function ChatView:HideCurChannelItem( )
  1589. local list = self.all_chatItem_list[self.model.curr_bar_index]
  1590. if list then
  1591. for _,item in pairs(list) do
  1592. item:SetVisible(false)
  1593. end
  1594. end
  1595. for _,item in pairs(self.cache_chatItem_list) do
  1596. item:SetVisible(false)
  1597. end
  1598. end
  1599. function ChatView:DoAfferFirstInit( )
  1600. self.is_init_operate = false
  1601. self:CancelAddMsgTimer()
  1602. self:CreateTimeLine()
  1603. self:CheckNeedInstanceData()
  1604. self:SortByItemHeight()
  1605. end
  1606. function ChatView:SortByItemHeight( )
  1607. table.sort(self.cur_item_data_list,function ( a,b )
  1608. return a.height < b.height
  1609. end)
  1610. end
  1611. function ChatView:CheckItemCanHide( )
  1612. if not self.last_check_hide_time then
  1613. self.last_check_hide_time = Status.NowTime
  1614. end
  1615. if Status.NowTime - self.last_check_hide_time < 0.01 then
  1616. return
  1617. end
  1618. self.last_check_hide_time = Status.NowTime
  1619. if self.drag_start_pos_y and #self.cur_item_data_list > 0 then
  1620. local pos_y = self.scroll_content.anchoredPosition.y
  1621. if pos_y <= 0 or pos_y >= self.scroll_content.sizeDelta.y then
  1622. return
  1623. end
  1624. if pos_y > self.drag_start_pos_y then --向上滑动
  1625. local data = self.cur_item_data_list[1]
  1626. if data and data.height and data.info and data.item and pos_y - data.height > 150 then --向上超过150了 隐藏起来
  1627. data.item:SetVisible(false)
  1628. table_remove(self.cur_item_data_list,1)
  1629. table_insert(self.front_item_data_list,data)
  1630. end
  1631. else
  1632. local last_index = #self.cur_item_data_list
  1633. local data = self.cur_item_data_list[last_index]
  1634. if data and data.height and data.info and data.item and data.height - pos_y - self.ScrollView.sizeDelta.y > 150 then --向下超过150了 隐藏起来
  1635. data.item:SetVisible(false)
  1636. table_remove(self.cur_item_data_list,last_index)
  1637. table_insert(self.back_item_data_list,1,data)
  1638. end
  1639. end
  1640. end
  1641. end
  1642. function ChatView:CheckFrontItemShow( )
  1643. if not self.last_check_front_show_time then
  1644. self.last_check_front_show_time = Status.NowTime
  1645. end
  1646. if Status.NowTime - self.last_check_front_show_time < 0.01 then
  1647. return
  1648. end
  1649. local pos_y = self.scroll_content.anchoredPosition.y
  1650. if pos_y <= 0 or pos_y >= self.scroll_content.sizeDelta.y then
  1651. return
  1652. end
  1653. self.last_check_front_show_time = Status.NowTime
  1654. local last_index = #self.front_item_data_list
  1655. local data = self.front_item_data_list[last_index]
  1656. if data and data.height and data.item and pos_y - data.height <= 150 then
  1657. data.item:SetVisible(true)
  1658. table_remove(self.front_item_data_list,last_index)
  1659. table_insert(self.cur_item_data_list,1,data)
  1660. end
  1661. end
  1662. function ChatView:CheckBackItemShow( )
  1663. if not self.last_check_back_show_time then
  1664. self.last_check_back_show_time = Status.NowTime
  1665. end
  1666. if Status.NowTime - self.last_check_back_show_time < 0.01 then
  1667. return
  1668. end
  1669. local pos_y = self.scroll_content.anchoredPosition.y
  1670. if pos_y <= 0 or pos_y >= self.scroll_content.sizeDelta.y then
  1671. return
  1672. end
  1673. self.last_check_back_show_time = Status.NowTime
  1674. local data = self.back_item_data_list[1]
  1675. 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
  1676. data.item:SetVisible(true)
  1677. table_remove(self.back_item_data_list,1)
  1678. table_insert(self.cur_item_data_list,data)
  1679. end
  1680. end
  1681. function ChatView:SetCurItemData( data )
  1682. for i=#self.cur_item_data_list,1,-1 do
  1683. local last_data = self.cur_item_data_list[i]
  1684. local per_data = self.cur_item_data_list[i-1]
  1685. if not per_data then
  1686. if last_data.height < data.height then
  1687. table_insert(self.cur_item_data_list,data)
  1688. else
  1689. table_insert(self.cur_item_data_list,i,data)
  1690. end
  1691. elseif last_data and per_data then
  1692. if last_data.height > data.height and per_data.height < data.height then
  1693. table_insert(self.cur_item_data_list,i-1,data)
  1694. elseif last_data.height < data.height and per_data.height < data.height then
  1695. table_insert(self.cur_item_data_list,data)
  1696. end
  1697. end
  1698. end
  1699. end
  1700. function ChatView:InitLimitWaySelectView( )
  1701. for i= 1,#self.model.LIMIY_WAY_NAME do
  1702. local item = self.limit_btn_list[i]
  1703. if not item then
  1704. item = ChatChannelToggleItem.New(self.shieldContent_tr)
  1705. self.limit_btn_list[i] = item
  1706. end
  1707. local color ="#ffffff"
  1708. local str = string.format("<color=%s>%s</color>",color,ChatModel.LIMIY_WAY_NAME[i], i == #self.model.LIMIY_WAY_NAME)
  1709. item:SetData(str,i)
  1710. end
  1711. -- local color = ColorUtil:GetColor(self.model.limit_way)
  1712. -- self.shieldBtntext.text = string.format("<color=%s>%s</color>",color,ChatModel.LIMIY_WAY_NAME[self.model.limit_way])
  1713. -- local clear_item = ChatSelectLimnitItem.New(self.limit_way.select_con)
  1714. -- table_insert(self.limit_btn_list,clear_item)
  1715. -- clear_item:SetData(-1)
  1716. end
  1717. function ChatView:SetDressBackground( )
  1718. -- Message.show("SetDressBackground")
  1719. local use_dress_list = ChatDressModel:getInstance().use_dress_list or {}
  1720. if use_dress_list == {} then return end
  1721. local bg_dress_id = use_dress_list[ChatDressSubType.BACKGROUND]
  1722. if bg_dress_id and bg_dress_id ~= 0 then
  1723. lua_resM:setOutsideImageSprite(self, self.bg_img, GameResPath.GetChatDressIcon(bg_dress_id), false)
  1724. end
  1725. end
  1726. function ChatView:SetShieldBtnState( )
  1727. local state = not self.shieldChannelScrv.activeSelf
  1728. self.is_show_shield = state
  1729. self.shieldChannelScrv:SetActive(state)
  1730. self.limitBtn_true_obj:SetActive(state)
  1731. if state then
  1732. self:InitLimitWaySelectView()
  1733. end
  1734. end