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

1255 lines
62 KiB

  1. ChatItem = ChatItem or BaseClass(BaseItem)
  2. local ChatItem = ChatItem
  3. local Config = Config
  4. local co = co
  5. local RoleManager = RoleManager
  6. local ChatModel = ChatModel
  7. local lua_resM = lua_resM
  8. local GlobalTimerQuest = GlobalTimerQuest
  9. local GlobalEventSystem = GlobalEventSystem
  10. local SetSizeDeltaX = SetSizeDeltaX
  11. local SetInlineText = SetInlineText
  12. function ChatItem:__init(parent_wnd,prefab_asset,layer_name,delay_callback,not_delay)
  13. self.base_file = "chat"
  14. self.layout_file = "chatItem"
  15. -- self.use_local_view = true
  16. self.is_chat = true
  17. self.is_delay_callback = true
  18. if not_delay then
  19. self.is_delay_callback = false
  20. end
  21. self.mainRoleVo = RoleManager:getInstance():GetMainRoleVo()
  22. self.show_type = 1 -- 1系统样式 2横线时间样式 3 显示世界聊天剩余次数 4 非主玩家说话样式 5 主角说话
  23. self.height = 0
  24. -- self.use_local_view = true
  25. self.role_text_width = 360
  26. self.role_text_offset = co.TableXY(75, 0)
  27. self.player_chatBg_offset = co.TableXY(90, -50)
  28. self.main_role_chatBg_offset = co.TableXY(-92, -42)
  29. self.player_text_offset = co.TableXY(41+1, -0)--(28-8+2, -3) --有气泡的时候调整
  30. self.player_default_text_offset = co.TableXY(41+1, 0)--无气泡的时候调整
  31. self.main_role_text_offset = co.TableXY(-40-1, 0) ---31+10+2, -3-8) --有气泡的时候调整
  32. self.main_role_default_text_offset = co.TableXY(-40-1, 0) --无气泡的时候调整
  33. self.role_bg_add_size = co.TableXY(50, 39)
  34. self.dress_bubble_role_bg_add_size = co.TableXY(50, 39)
  35. self.role_bg_min_size = co.TableXY(20, 56)
  36. self.voice_text_offset = co.TableXY(3 + 38, 14.6 + 5)
  37. self.voice_bg_add_size = co.TableXY(50 , 10)
  38. self.dress_bubble_color = "#f0b30e" --有气泡时候字体颜色
  39. self.dress_bubble_color_value = Color(240 / 255, 179 / 255, 14 / 255, 1) --有气泡时候字体颜色
  40. self.default_bubble_color_value = Color(169 / 255, 193 / 255, 225 / 255, 1)
  41. -- self.voice_bg_min_size = Vector2(135,0)
  42. self.beach_scale = 0.8 --海滩的等比例缩小
  43. self.assist_award_item_list = {}--小助手的聊天物品item列表
  44. self.model = ChatModel:getInstance()
  45. self:Load()
  46. end
  47. function ChatItem:Load_callback()
  48. -- 尽量用这种方式加新节点
  49. self.nodes = {
  50. "playerCon/nameCon/player_military_rank_icon:obj:img", -- 跨服军衔
  51. "mainRoleCon/nameCon/mainrole_military_rank_icon:obj:img", -- 跨服军衔
  52. "playerCon/nameCon/playerCon_voteBtn:obj", -- 温泉聊天 投标按钮
  53. "playerCon/assistAwardCon:obj",--小助手聊天中的物品item容器
  54. }
  55. self:GetChildren(self.nodes)
  56. self.player_btnVoice = self:GetChild("playerCon/btnVoice").gameObject
  57. self.player_img_voice1 = self:GetChild("playerCon/btnVoice/image1").gameObject
  58. self.player_img_voice2 = self:GetChild("playerCon/btnVoice/image2").gameObject
  59. self.player_img_voice3 = self:GetChild("playerCon/btnVoice/image3").gameObject
  60. self.playerCon = self:GetChild("playerCon").gameObject
  61. self.btnGift = self:GetChild("playerCon/nameCon/btnGift").gameObject
  62. self.player_vipCon = self:GetChild("playerCon/nameCon/vipCon").gameObject
  63. self.mainRoleCon_btnVoice = self:GetChild("mainRoleCon/btnVoice").gameObject
  64. self.mainRoleCon_img_voice1 = self:GetChild("mainRoleCon/btnVoice/image1").gameObject
  65. self.mainRoleCon_img_voice2 = self:GetChild("mainRoleCon/btnVoice/image2").gameObject
  66. self.mainRoleCon_img_voice3 = self:GetChild("mainRoleCon/btnVoice/image3").gameObject
  67. self.mainRole_vipCon = self:GetChild("mainRoleCon/nameCon/vipCon").gameObject
  68. self.systemCon = self:GetChild("systemCon").gameObject
  69. self.lineCon = self:GetChild("lineCon").gameObject
  70. self.speakCon = self:GetChild("SpeakCon").gameObject
  71. self.mainRoleCon = self:GetChild("mainRoleCon").gameObject
  72. self.player_gm_dot = self:GetChild("playerCon/nameCon/GMDot").gameObject
  73. self.player_gm_img_go = self:GetChild("playerCon/nameCon/GMImg").gameObject
  74. self.mainRole_gm_dot = self:GetChild("mainRoleCon/nameCon/GMDot").gameObject
  75. self.mainRole_gm_img_go = self:GetChild("mainRoleCon/nameCon/GMImg").gameObject
  76. self.player_zdy_dot = self:GetChild("playerCon/nameCon/ZDYDot").gameObject
  77. self.player_zdy_img_go = self:GetChild("playerCon/nameCon/ZDYImg").gameObject
  78. self.mainRole_zdy_dot = self:GetChild("mainRoleCon/nameCon/ZDYDot").gameObject
  79. self.mainRole_zdy_img_go = self:GetChild("mainRoleCon/nameCon/ZDYImg").gameObject
  80. self.mainRole_voiceClick = self:GetChild("mainRoleCon/voiceClick").gameObject
  81. self.player_voiceClick = self:GetChild("playerCon/voiceClick").gameObject
  82. self.playerHeadCon = self:GetChild("playerCon/headCon")
  83. self.playerNameCon = self:GetChild("playerCon/nameCon/nameText")
  84. self.player_vipIcon = self:GetChild("playerCon/nameCon/vipCon/vipIcon")
  85. self.player_sexIcon = self:GetChild("playerCon/nameCon/sexIcon")
  86. self.player_chatBg = self:GetChild("playerCon/chatBg")
  87. self.playerGuildDescrb = self:GetChild("playerCon/guild_descrb")
  88. self.mainRoleHeadCon = self:GetChild("mainRoleCon/headCon")
  89. self.mainRoleGuildDescrb = self:GetChild("mainRoleCon/guild_descrb")
  90. self.mainRole_pos = self:GetChild("mainRoleCon/nameCon/posIcon")
  91. self.mainRole_vipIcon = self:GetChild("mainRoleCon/nameCon/vipCon/vipIcon")
  92. self.mainRole_sexIcon = self:GetChild("mainRoleCon/nameCon/sexIcon")
  93. self.mainRole_chatBg = self:GetChild("mainRoleCon/chatBg")
  94. self.system_bg = self:GetChild("systemCon/bg")
  95. self.system_beach_bg = self:GetChild("systemCon/bg_beach")
  96. self.system_contentText_tr = self:GetChild("systemCon/bg/contentText")
  97. self.system_beachText_tr = self:GetChild("systemCon/beachText")
  98. self.system_channelIcon_tr = self:GetChild("systemCon/channelIcon")
  99. self.player_contentText = self:GetChild("playerCon/contentText")
  100. self.mainRole_contentText = self:GetChild("mainRoleCon/contentText")
  101. self.mainRole_nameCon = self:GetChild("mainRoleCon/nameCon/nameText")
  102. self.mainRole_voiceClick_tr = self:GetChild("mainRoleCon/voiceClick")
  103. self.player_voiceClick_tr = self:GetChild("playerCon/voiceClick")
  104. self.mainRoleCon_tr = self:GetChild("mainRoleCon")
  105. self.playerCon_tr = self:GetChild("playerCon")
  106. self.lineCon_tr = self:GetChild("lineCon")
  107. self.system_img_bg = self:GetChild("systemCon/bg/bg")
  108. self.system_contentText2_tr = self:GetChild("systemCon/contentText") -- 系统消息用的文本 主要是对齐方式与不用
  109. self.player_chatBg_img = self:GetChild("playerCon/chatBg"):GetComponent("Image")
  110. self.mainRole_posIcon = self:GetChild("mainRoleCon/nameCon/posIcon"):GetComponent("Image")
  111. self.mainRole_chatBg_img = self:GetChild("mainRoleCon/chatBg"):GetComponent("Image")
  112. self.system_channelIcon = self:GetChild("systemCon/channelIcon"):GetComponent("Image")
  113. self.mainRole_headBoard_img = self:GetChild("mainRoleCon/mainRole_head_board"):GetComponent("Image")
  114. self.player_headBoard_img = self:GetChild("playerCon/player_head_board"):GetComponent("Image")
  115. self.player_rank_icon_img = self:GetChild("playerCon/nameCon/rank_txt_icon"):GetComponent("Image")
  116. self.mainRole_rank_icon_img = self:GetChild("mainRoleCon/nameCon/rank_txt_icon"):GetComponent("Image")
  117. self.player_voiceText = self:GetChild("playerCon/btnVoice/value"):GetComponent("Text")
  118. self.player_nameText = self:GetChild("playerCon/nameCon/nameText"):GetComponent("Text")
  119. self.player_contentText_t = self:GetChild("playerCon/contentText"):GetComponent("Text")
  120. self.player_addressText = self:GetChild("playerCon/addressText"):GetComponent("Text")
  121. self.mainRoleCon_voiceText = self:GetChild("mainRoleCon/btnVoice/value"):GetComponent("Text")
  122. self.mainRole_nameText = self:GetChild("mainRoleCon/nameCon/nameText"):GetComponent("Text")
  123. self.mainRole_contentText_t = self:GetChild("mainRoleCon/contentText"):GetComponent("Text")
  124. self.mainRole_addressText = self:GetChild("mainRoleCon/addressText"):GetComponent("Text")
  125. self.system_contentText = self:GetChild("systemCon/bg/contentText"):GetComponent("Text")
  126. self.system_contentText2 = self:GetChild("systemCon/contentText"):GetComponent("Text")
  127. self.system_beachText = self:GetChild("systemCon/beachText"):GetComponent("Text")
  128. self.line_timeText = self:GetChild("lineCon/timeText"):GetComponent("TextMeshProUGUI")
  129. self.chat_numText = self:GetChild("SpeakCon/amountText"):GetComponent("Text")
  130. self.playerGuild_txt = self:GetChild("playerCon/guild_descrb/text"):GetComponent("Text")
  131. self.mainRoleGuild_txt = self:GetChild("mainRoleCon/guild_descrb/text"):GetComponent("Text")
  132. -- self:GetChild("playerCon/contentText1").gameObject:SetActive(false)--先屏蔽
  133. local x = Config.ConfigChat.ChatItem.playerVoiceBtnPos.x
  134. local y = Config.ConfigChat.ChatItem.playerVoiceBtnPos.y
  135. self.player_btnVoice.transform.anchoredPosition = Vector2(x,y)
  136. x = Config.ConfigChat.ChatItem.mainRoleVoiceBtnPos.x
  137. y = Config.ConfigChat.ChatItem.mainRoleVoiceBtnPos.y
  138. self.mainRoleCon_btnVoice.transform.anchoredPosition = Vector2(x,y)
  139. -------------------------
  140. self.pos_x_systemCon, self.pos_y_systemCon = GetAnchoredPosition( self.systemCon.transform )
  141. -------------------------
  142. -- 调整消息间距
  143. SetAnchoredPositionX(self.mainRoleCon_tr, Config.ConfigChat.RIGHT_PLAYER_POSX)
  144. SetAnchoredPositionX(self.playerCon_tr, Config.ConfigChat.LEFT_PLAYER_POSX)
  145. -- self.mainRole_pos_pos = self.mainRole_pos.localPosition
  146. local function onPlayPlayerVoice( ... )
  147. if self.info and self.info.iType == ChatModel.MSG_TYPE.VOICE and self.info.voice_id then
  148. ChatVoiceManager:getInstance():SetVoiceVersion(self.info.voice_id, self.info.data_ver)
  149. local voice_vo = ChatVoiceManager:getInstance():GetVoice(self.info.voice_id)
  150. if voice_vo then
  151. ChatVoiceManager:getInstance():PlayVoice(self.info.voice_id)
  152. else
  153. ChatVoiceManager:getInstance():ClickPlay(self.info.voice_id)
  154. self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11004, self.info.voice_id, self.info.player_id, self.info.time)
  155. end
  156. end
  157. end
  158. AddClickEvent(self.player_btnVoice, onPlayPlayerVoice)
  159. AddClickEvent(self.player_voiceClick, onPlayPlayerVoice)
  160. local function onPlayMainRoleVoice()
  161. if self.info and self.info.iType == ChatModel.MSG_TYPE.VOICE and self.info.voice_id then
  162. ChatVoiceManager:getInstance():SetVoiceVersion(self.info.voice_id, self.info.data_ver)
  163. local voice_vo = ChatVoiceManager:getInstance():GetVoice(self.info.voice_id)
  164. if voice_vo then
  165. ChatVoiceManager:getInstance():PlayVoice(self.info.voice_id)
  166. else
  167. ChatVoiceManager:getInstance():ClickPlay(self.info.voice_id)
  168. self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11004, self.info.voice_id, self.info.player_id, self.info.time)
  169. end
  170. end
  171. end
  172. AddClickEvent(self.mainRoleCon_btnVoice, onPlayMainRoleVoice)
  173. AddClickEvent(self.mainRole_voiceClick, onPlayMainRoleVoice)
  174. -- 必须先设为false 不然表情会显示不出来
  175. self.mainRoleCon:SetActive(false)
  176. self.playerCon:SetActive(false)
  177. if self.need_refreshData then
  178. self:SetData(self.info,self.layout_height)
  179. self:SetItemSize(self.size_x,self.size_y)
  180. end
  181. if self.color_cache then
  182. self.color_cache = false
  183. self:SetLineTimeColor(self.line_color)
  184. end
  185. if self.set_line_size_cache then
  186. self.set_line_size_cache = false
  187. self:SetLineSize(self.line_width ,self.line_bg_width)
  188. end
  189. end
  190. --删除了上面的item 自己也要改变位置
  191. function ChatItem:ReLayout(off_height)
  192. if self.transform then
  193. self.transform.localPosition = Vector3(0, self.transform.localPosition.y + off_height, 0)
  194. end
  195. end
  196. function ChatItem:SetData(info, layout_height)
  197. self.info = info
  198. self.layout_height = layout_height
  199. if self.wait_set_local_y then
  200. self:SetLocalPositionY(self.wait_set_local_y)
  201. else
  202. self:SetAnchoredPosition(0,-layout_height,0)
  203. end
  204. if not self.is_loaded then
  205. self.need_refreshData = true
  206. return
  207. end
  208. if not self.transform then return end
  209. self.info = info
  210. -- self.transform.localPosition = Vector3(0, -layout_height, 0)
  211. self:SetVisible(true)
  212. self.height = 0
  213. --local channel_icon = self.info.channel_icon or self.info.channel
  214. -- local text_color = self.info.channel == ChatModel.CHANNEL_HORN and "#FF3A00" or "#323232"
  215. -- local icon = nil
  216. -- local color = nil
  217. -- if self.info.tip and self.info.tip ~= 0 then
  218. -- icon,color = self.model:GetTipWithShowType(self.info.tip)
  219. -- else
  220. -- icon = self.model:GetChannelIconWithChannel(self.info.channel)
  221. -- color = self.model:GetChannelColorWithChannel(self.info.channel)
  222. -- end
  223. --根据subtype(showtype)来控制chatitem的样式
  224. --在聊天栏部分颜色需要进行一次转换
  225. channel = self.info.showtype == nil and self.info.channel or self.info.showtype
  226. local chat_color_is_chat_view = channel and channel ~= ChatModel.CHANNEL_SYSTEM and channel ~= ChatModel.CHANNEL_GENERAL and channel ~= ChatModel.CHANNEL_HORN
  227. local text_color = "#f3fcff" --channel == ChatModel.CHANNEL_HORN and ColorUtil.YELLOW or ColorUtil.WHITE
  228. -- print("ChatItem:SetData 说了啥", self.info.msg)
  229. if self.info.msg then
  230. self.info.msg = Util.SetNonBreakSpaceText(self.info.msg)
  231. end
  232. local call_fun = function (param_list)
  233. self:CilckContentHandle(param_list)
  234. end
  235. if self.type_id and string.find(self.type_id,"beachChat") then
  236. if channel == ChatModel.CHANNEL_SYSTEM then
  237. SetAnchoredPosition( self.systemCon.transform, self.pos_x_systemCon+15, self.pos_y_systemCon+8 )
  238. else
  239. SetAnchoredPosition( self.systemCon.transform, self.pos_x_systemCon, self.pos_y_systemCon )
  240. end
  241. end
  242. -------------------------
  243. if channel == ChatModel.CHANNEL_SYSTEM then
  244. self.show_type = 1
  245. self.playerCon:SetActive(false)
  246. self.systemCon:SetActive(true)
  247. self.lineCon:SetActive(false)
  248. self.mainRoleCon:SetActive(false)
  249. self.speakCon:SetActive(false)
  250. -- local icon = nilf self.info.tip and self.info.tip ~= 0 then
  251. -- -- --增加飘字
  252. -- -- Message.show(self.info.msg)
  253. -- icon, text_color = self.model:GetTipWithShowType(self.info.tip)
  254. -- self.system_contentText.text = "<color="..text_color..">"..self.info.msg.."</color>"
  255. -- else
  256. -- print("=============>>> YiRan:ChatItem [start:295] self.info ------------------------------------------")
  257. -- PrintTable(self.info)
  258. -- print("=============>>> YiRan:ChatItem [end] ------------------------------------------")
  259. local icon = "chat_channel_20"
  260. --self.system_bg.gameObject:SetActive(false)
  261. self.system_img_bg.gameObject:SetActive(false)
  262. self.system_beach_bg.gameObject:SetActive(false)
  263. self.system_contentText.text = ""
  264. self.system_beachText.text = ""
  265. self.system_contentText2.text = ""
  266. local is_chuanwen = false
  267. if self.info.chuanwen_type and self.info.chuanwen_type == ChatModel.CHUANWEN_TYPE.UP_CHUANWEN then
  268. --如果是传闻类型
  269. icon = "chat_channel_20"
  270. is_chuanwen = true
  271. -- if self.info.tip and self.info.type == 1 then --这个字段用来加框
  272. --self.system_bg.gameObject:SetActive(true)
  273. self.system_img_bg.gameObject:SetActive(true)
  274. -- Message.show("self.info",self.info.msg)
  275. -- end
  276. else
  277. icon = self.model:GetChannelIconWithChannel(self.info.channel)
  278. end
  279. local fitHeight = 0
  280. local text_size = 0
  281. -------------------------
  282. if self.type_id and string.find(self.type_id,"beachChat") then
  283. --温泉要特殊表现
  284. local content_str = "<color=#a9c1e1>"..self.info.msg.."</color>"
  285. self.system_beachText.text = content_str
  286. SetInlineText(self.system_beachText, content_str,self.info.url,chat_color_is_chat_view)
  287. AddUnderLineAndClick(self, self.system_beachText_tr, call_fun)
  288. self.system_channelIcon_tr.gameObject:SetActive(false)
  289. fitHeight = 23 + self.system_beachText.preferredHeight
  290. text_size = Vector2(421.3, fitHeight)
  291. self.system_beachText_tr.sizeDelta = text_size
  292. self.system_beach_bg.gameObject:SetActive(true)
  293. self.system_bg.gameObject:SetActive(false)
  294. else
  295. -------------------------
  296. -- 传闻有特殊样式 不需要显示
  297. local content
  298. local content_tr
  299. self.system_contentText_tr.gameObject:SetActive(false)
  300. self.system_contentText2_tr.gameObject:SetActive(false)
  301. if is_chuanwen then
  302. content = self.system_contentText
  303. content_tr = self.system_contentText_tr
  304. self.system_channelIcon_tr.gameObject:SetActive(false)
  305. else
  306. content = self.system_contentText2
  307. content_tr = self.system_contentText2_tr
  308. self.system_channelIcon_tr.gameObject:SetActive(true)
  309. end
  310. content_tr.gameObject:SetActive(true)
  311. local content_str = "<color="..text_color..">"..self.info.msg.."</color>"
  312. content.color = self.default_bubble_color_value
  313. content.text = content_str
  314. lua_resM:setImageSprite(self, self.system_channelIcon, "mainUI_asset", icon) --设置图标
  315. SetInlineText(content, content_str,self.info.url, chat_color_is_chat_view)
  316. AddUnderLineAndClick(self, content_tr, call_fun)
  317. fitHeight = 19 + content.preferredHeight
  318. text_size = Vector2(421.3, fitHeight)
  319. content_tr.sizeDelta = text_size
  320. if is_chuanwen and content.preferredHeight > 20 then -- 超过一行的话 挪一下位置
  321. SetAnchoredPositionY(content_tr, 11.5)
  322. elseif is_chuanwen then
  323. SetAnchoredPositionY(content_tr, 21)
  324. end
  325. self.system_bg.gameObject:SetActive(true)
  326. end
  327. -------------------------
  328. fitHeight = fitHeight < Config.ConfigChat.Chuanwen_space and Config.ConfigChat.Chuanwen_space or fitHeight
  329. --终于找到= =。 巨坑这里, 文本高度的判断最终在chatview,chatview预制物体里自带了几个text框来找preferredHeight再扔回chatitem~~~!!!!
  330. --self.height = Config.ConfigChat.Sys_item_space + fitHeight -- 这个height不起效~~@@@!!!
  331. self.system_bg.sizeDelta = Vector2(512, fitHeight)
  332. self.height = 20
  333. elseif self.info.is_line then
  334. self.show_type = 2
  335. self.playerCon:SetActive(false)
  336. self.systemCon:SetActive(false)
  337. self.lineCon:SetActive(true)
  338. self.mainRoleCon:SetActive(false)
  339. self.speakCon:SetActive(false)
  340. self.line_timeText.text = TimeUtil:timeConversion(self.info.time, "mm-dd hh-MM")
  341. self.height = 30
  342. if channel == ChatModel.CHANNEL_CECRET then--重置,为了私聊好友界面的主角坐标设置
  343. self.lineCon_tr.anchoredPosition = Vector2(40,-13)
  344. else
  345. self.lineCon_tr.anchoredPosition = Vector2(-23,-13)
  346. end
  347. elseif self.info.show_num then
  348. self.show_type = 3
  349. self.playerCon:SetActive(false)
  350. self.systemCon:SetActive(false)
  351. self.lineCon:SetActive(false)
  352. self.mainRoleCon:SetActive(false)
  353. self.speakCon:SetActive(true)
  354. if self.info.chat_method == 0 then
  355. self.chat_numText.text = "您在世界聊天的次数剩余<color=#73AC44FF>" .. info.amount .. "</color>次"
  356. else
  357. self.chat_numText.text = "您使用世界发言凭证发言<color=#73AC44FF>1</color>次"
  358. end
  359. self.height = 30
  360. elseif self.info.player_id ~= RoleManager.Instance:GetMainRoleId() then
  361. self.show_type = 4
  362. self.playerCon:SetActive(true)
  363. self.systemCon:SetActive(false)
  364. self.lineCon:SetActive(false)
  365. self.mainRoleCon:SetActive(false)
  366. self.speakCon:SetActive(false)
  367. local function is_cs_chat( )
  368. return (self.info.ser_id ~= RoleManager.Instance:GetMainRoleServerId()) or self.model:IsCrossServerChannel( channel )
  369. end
  370. --local name_color = string.find(self.type_id or "","beachChat") and '#ffffff' or '#f3fcff'
  371. local name_color = '#ffffff'
  372. self.player_nameText.text = HtmlColorTxt( is_cs_chat() and GetCSLongName( self.info.name, self.info.ser_num ) or self.info.name ,name_color )
  373. self.player_addressText.text = "<color=#FFD797>(广东·深圳)</color>"
  374. self.player_gm_dot:SetActive(info.GM == 1)
  375. self.player_gm_img_go:SetActive(info.GM == 1)
  376. self.player_zdy_dot:SetActive(info.GM == 2)
  377. self.player_zdy_img_go:SetActive(info.GM == 2)
  378. --[[if string.find(self.info.msg,"<a@redenvelopes>") then --红包链接要加上红包图片
  379. if not self.img_player_red_packet then
  380. self.img_player_red_packet = UiFactory.createChild(self.playerCon.transform,UIType.Image,"Image")
  381. end
  382. self.img_player_red_packet:SetActive(true)
  383. lua_resM:setImageSprite(self, self.img_player_red_packet:GetComponent("Image"), "mainUI_asset", "mainui_red", true)
  384. self.img_player_red_packet.transform.anchoredPosition = Vector2(-90,-24)
  385. self.info.msg = "\n\n\n"..Trim(self.info.msg)
  386. AddClickEvent(self.img_player_red_packet, function()
  387. GlobalEventSystem:Fire(EventName.OPEN_GUILD_MAIN_VIEW,1,4)
  388. end)
  389. elseif self.img_player_red_packet then
  390. self.img_player_red_packet:SetActive(false)
  391. end]]
  392. --[[if string.find(self.info.msg,"<a@actredenvelopes>") then --活动红包链接要加上红包图片
  393. if not self.img_player_red_packet then
  394. self.img_player_red_packet = UiFactory.createChild(self.playerCon.transform,UIType.Image,"Image")
  395. end
  396. self.img_player_red_packet:SetActive(true)
  397. lua_resM:setImageSprite(self, self.img_player_red_packet:GetComponent("Image"), "mainUI_asset", "mainui_red", true)
  398. self.img_player_red_packet.transform.anchoredPosition = Vector2(-90,-24)
  399. self.info.msg = "\n\n\n"..Trim(self.info.msg)
  400. AddClickEvent(self.img_player_red_packet, function()
  401. local act = CustomActivityModel:getInstance():getActList(CustomActivityModel.CustomActBaseType.ACT_RED_BAG)
  402. if act ~= nil then
  403. GlobalEventSystem:Fire(EventName.OPEN_OPERATION_ACTIVITY_VIEW,act.base_type,act.sub_type)
  404. else
  405. Message.show("活动未开启")
  406. end
  407. end)
  408. elseif self.img_player_red_packet then
  409. self.img_player_red_packet:SetActive(false)
  410. end--]]
  411. --社团名字
  412. if self.mainRoleVo.level < Config.Modulesub["110@2"].open_lv then --等级不够不显示
  413. self.playerGuildDescrb.gameObject:SetActive(false)
  414. else
  415. self.playerGuildDescrb.gameObject:SetActive(true)
  416. local player_guild_name = ""
  417. self.playerGuild_txt.text = player_guild_name
  418. if info.guild_name and info.guild_name ~= "" then
  419. player_guild_name = info.guild_name
  420. elseif info.player_list and info.player_list[1].guild_name and info.player_list[1].guild_name ~= "" then
  421. player_guild_name = info.player_list[1].guild_name
  422. else
  423. self.playerGuildDescrb.gameObject:SetActive(false)
  424. end
  425. self.playerGuild_txt.text = player_guild_name
  426. --
  427. SetSizeDeltaX(self.playerGuildDescrb, self.playerGuild_txt.preferredWidth + 10)
  428. --
  429. end
  430. lua_resM:setImageSprite(self, self.player_chatBg_img, "chat_asset", "tyui_chat", false)-- "chat_asset", "chat_default_bg", false)--"common_asset", "tyui_qp1_1", false)--
  431. local player_dress_bubble = false
  432. if info.dress_list then
  433. for i, v in ipairs(info.dress_list) do
  434. --1气泡 2相框
  435. if v.dress_id ~= 0 then
  436. local icon_name = v.dress_id
  437. if v.dress_type == 2 then
  438. info.dress_board = icon_name
  439. -- if icon_name and icon_name~= 0 then
  440. -- lua_resM:setOutsideImageSprite(self, self.player_headBoard_img, GameResPath.GetChatDressIcon(icon_name), false)
  441. -- self.player_headBoard_img.gameObject:SetActive(true)
  442. -- else
  443. -- self.player_headBoard_img.gameObject:SetActive(false)
  444. -- end
  445. elseif v.dress_type == 1 then
  446. player_dress_bubble = Trim(icon_name)
  447. -- Message.show("icon_name:",icon_name)
  448. if icon_name and icon_name~= 0 then
  449. lua_resM:setOutsideImageSprite(self, self.player_chatBg_img, GameResPath.GetChatDressIcon(player_dress_bubble), false)
  450. end
  451. end
  452. end
  453. end
  454. else
  455. self.player_headBoard_img.gameObject:SetActive(false)
  456. end
  457. if main_role_dress_bubble ~= false and Config.ConfigChatTextColor[player_dress_bubble] then
  458. self.player_contentText_t.color = Config.ConfigChatTextColor[player_dress_bubble]
  459. else
  460. self.player_contentText_t.color = self.default_bubble_color_value
  461. end
  462. --添加超链接
  463. self.player_contentText.sizeDelta = Vector2(self.role_text_width, 0)
  464. self.assistAwardCon_obj:SetActive(false)
  465. if self.info.msg == "" then --语音信息有时候为空
  466. self.player_contentText_t.text = ""
  467. else
  468. --小助手部分聊天内容不存全部信息到cookies,改成代号转化前端配置
  469. if self.info.player_id == 1 then
  470. local assist_final_msg = ""
  471. if Config.AssistantChat.AssistChatCode[self.info.msg] then
  472. --如果是笑话,要随机选择一个
  473. if Config.AssistantChat.AssistChatCode[self.info.msg].is_joke then
  474. local random_num = math.random(1, TableSize(Config.AssistantChat.AssistChatCode[self.info.msg].joke_list))
  475. assist_final_msg = ChuanWenManager:FormatColorTag(Config.AssistantChat.AssistChatCode[self.info.msg].joke_list[random_num])
  476. else
  477. assist_final_msg = ChuanWenManager:FormatColorTag(Config.AssistantChat.AssistChatCode[self.info.msg].msg)
  478. end
  479. --展示物品
  480. if Config.AssistantChat.AssistChatCode[self.info.msg].show_goods_id then
  481. self.assistAwardCon_obj:SetActive(true)
  482. for k,v in pairs(self.assist_award_item_list) do
  483. v:SetVisible(false)
  484. end
  485. for i,v in ipairs(Config.AssistantChat.AssistChatCode[self.info.msg].show_goods_id) do
  486. local item = self.assist_award_item_list[i]
  487. if not item then
  488. item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.assistAwardCon)
  489. self.assist_award_item_list[i] = item
  490. end
  491. item:SetItemSize(62, 62)
  492. item:SetVisible(true)
  493. local goods_type_id = v
  494. item:SetData(goods_type_id)
  495. --如果需要对物品item单独进行坐标设置,这个值必传,否则就默认排列物品
  496. if Config.AssistantChat.AssistChatCode[self.info.msg].show_goods_pos then
  497. local pos_x = Config.AssistantChat.AssistChatCode[self.info.msg].show_goods_pos[i][1]
  498. local pos_y = Config.AssistantChat.AssistChatCode[self.info.msg].show_goods_pos[i][2]
  499. item:SetAnchoredPosition(pos_x,pos_y)
  500. else
  501. item:SetAnchoredPosition((62+20)*(i-1),-28)
  502. end
  503. end
  504. end
  505. else
  506. assist_final_msg = self.info.msg
  507. end
  508. SetInlineText(self.player_contentText_t, assist_final_msg,nil,chat_color_is_chat_view)
  509. else
  510. SetInlineText(self.player_contentText_t, self.info.msg,nil,chat_color_is_chat_view)
  511. end
  512. end
  513. -- SetInlineText(self.player_contentText_t, "<color="..text_color..">"..self.info.msg.."</color>")
  514. AddUnderLineAndClick(self, self.player_contentText, call_fun)
  515. if not self.playHeadItem then
  516. self.playHeadItem = HeadRoleItem.New(self.playerHeadCon)
  517. self.playHeadItem:SetItemSize(70,70)
  518. end
  519. local head_data = { --把info传进去好辨认是否外服 + 生成 operationview
  520. vo = {
  521. info = info,
  522. id = info.player_id,
  523. use_bg = 3,
  524. career = 0 ,
  525. server_id = info.ser_id,
  526. sex = info.sex,
  527. turn = info.turn,
  528. board = info.dress_board,
  529. picture_ver = info.picture_ver,
  530. picture = info.picture,
  531. profile_photo_id = info.profile_photo_id,
  532. dress_board_id = info.dress_board,
  533. },
  534. }-- level = info.level,
  535. self.playHeadItem:SetData(head_data)
  536. local long_click_call_back = function ()
  537. self.model:Fire(ChatModel.SELECT_OTHER_PLAYER, info.name)
  538. end
  539. self.playHeadItem:SetLongClickCall(long_click_call_back)
  540. local text_size = co.TableXY(math.min(self.role_text_width, self.player_contentText_t.preferredWidth), self.player_contentText_t.preferredHeight)
  541. self.player_contentText.sizeDelta = text_size--Vector2(self.role_text_width, text_size.y)
  542. --self.playerHeadCon.anchoredPosition = Vector2(-195,-text_size.y+22.5 -6.9)
  543. -- self.playerGuildDescrb.anchoredPosition = Vector2(-195,-text_size.y+22.5 -49.3)
  544. --对方
  545. local bg_size = player_dress_bubble and self.dress_bubble_role_bg_add_size or self.role_bg_add_size
  546. local text_offset = player_dress_bubble and self.player_text_offset or self.player_default_text_offset
  547. if player_dress_bubble and Config.ConfigChatDress.Pos[player_dress_bubble] then
  548. local addTable = Config.ConfigChatDress.Pos[player_dress_bubble]
  549. text_offset = co.AddXY(text_offset,co.TableXY(addTable.pos_x,addTable.pos_y)) --+ Vector2(addTable.pos_x,addTable.pos_y)
  550. bg_size = co.AddXY(bg_size,co.TableXY(addTable.size_x,addTable.size_y))
  551. end
  552. if info.iType == ChatModel.MSG_TYPE.VOICE then
  553. local voiceVo = ChatVoiceManager:getInstance():GetVoice(info.voice_id)
  554. if voiceVo then
  555. local leftTime = voiceVo:IsPlaying()
  556. if leftTime then
  557. self:PlayAnim(leftTime)
  558. else
  559. self:SetPlayState(3)
  560. end
  561. else
  562. self:SetPlayState(3)
  563. end
  564. self.player_voiceText.text = info.length.."''"
  565. self.player_btnVoice:SetActive(true)
  566. self.player_voiceClick:SetActive(true)
  567. local text_size_x = math.max(65,text_size.x) --最少要50
  568. self.player_chatBg.sizeDelta = Vector2(bg_size.x + text_size_x, bg_size.y + text_size.y + self.voice_bg_add_size.y)
  569. self.player_chatBg.anchoredPosition = Vector2(self.player_chatBg_offset.x, self.player_chatBg_offset.y)
  570. self.player_contentText.anchoredPosition = Vector3(self.role_text_offset.x + text_size_x/ 2 + text_offset.x, self.player_chatBg.localPosition.y - self.player_chatBg.sizeDelta.y + text_size.y / 2 + self.voice_text_offset.y)
  571. self.player_voiceClick_tr.sizeDelta = self.player_chatBg.sizeDelta
  572. self.player_voiceClick_tr.anchoredPosition = self.player_chatBg.anchoredPosition
  573. else
  574. self.player_btnVoice:SetActive(false)
  575. self.player_voiceClick:SetActive(false)
  576. self.player_chatBg.sizeDelta = Vector2(bg_size.x + text_size.x, math.max(bg_size.y + text_size.y, self.role_bg_min_size.y))
  577. -- self.player_chatBg.anchoredPosition = Vector2(90,-33)
  578. self.player_chatBg.anchoredPosition = Vector2(self.player_chatBg_offset.x, self.player_chatBg_offset.y)
  579. self.player_contentText.anchoredPosition = Vector3(self.role_text_offset.x + text_size.x / 2 + text_offset.x, self.player_chatBg.localPosition.y - self.player_chatBg.sizeDelta.y / 2 + self.role_text_offset.y + text_offset.y)
  580. end
  581. self.speakCon:SetActive(false)
  582. self.height = self.player_chatBg.sizeDelta.y + 30
  583. self.height = math.max(self.height, 95)
  584. local namepos = self.playerNameCon.localPosition
  585. -- 2021/3/13 ===策划说不要显示性别===
  586. -- if info.sex and info.sex == 1 then
  587. -- lua_resM:setImageSprite(self, self.player_sexIcon:GetComponent("Image"), "common_asset", "com_boy", true)
  588. -- else
  589. -- lua_resM:setImageSprite(self, self.player_sexIcon:GetComponent("Image"), "common_asset", "com_girl", true)
  590. -- end
  591. -- print("=============>>> YiRan:ChatItem [start:524]info ------------------------------------------")
  592. -- PrintTable(info)
  593. --print("=============>>> YiRan:ChatItem [end] ------------------------------------------")
  594. if not self.player_vip_item then
  595. self.player_vip_item = RoleVipItem.New(self.player_vipIcon)
  596. end
  597. --如果是Ai助手
  598. if self.info.player_id == 1 then
  599. lua_resM:setImageSprite(self,self.player_vipIcon:GetComponent("Image"), "sociality_asset", "sociality_asistant_icon",true)
  600. self.player_vip_item:SetData(0, 0)
  601. else
  602. -- 如果vip等级为零 则不空出vip的图标位置
  603. if (info.vip_flag and info.vip_flag == 0) or not info.vip_flag then
  604. self.player_vipCon:GetComponent("Text").text = ""
  605. else
  606. self.player_vipCon:GetComponent("Text").text = " "
  607. end
  608. -- 设置vip图标数据
  609. lua_resM:setImageSprite(self,self.player_vipIcon:GetComponent("Image"), "uiComponent_asset", "com_empty")
  610. self.player_vip_item:SetData(info.vip_flag, info.sup_vip_type)
  611. end
  612. --排行icon显示
  613. if (self.info.player_list and self.info.player_list[1] and self.info.player_list[1].is_overlord and self.info.player_list[1].is_overlord > 0) or (self.info.is_overlord and self.info.is_overlord > 0) then
  614. if self.info.is_overlord then
  615. lua_resM:setImageSprite(self,self.player_rank_icon_img, "chat_asset","chat_overlord"..self.info.is_overlord.."_pointfilter",true)
  616. else
  617. lua_resM:setImageSprite(self,self.player_rank_icon_img, "chat_asset","chat_overlord"..self.info.player_list[1].is_overlord.."_pointfilter",true)
  618. end
  619. self.player_rank_icon_img.gameObject:SetActive(true)
  620. else
  621. local res_rank_name = self:GetRankIconResName(self.info.player_id)
  622. if not res_rank_name then
  623. res_rank_name = self:GetRankIconResName2(self.info.lv_rank, self.info.combat_rank)
  624. end
  625. if res_rank_name then
  626. lua_resM:setImageSprite(self,self.player_rank_icon_img, "chat_asset",res_rank_name,true)
  627. self.player_rank_icon_img.gameObject:SetActive(true)
  628. else
  629. self.player_rank_icon_img.gameObject:SetActive(false)
  630. end
  631. end
  632. ------------------------
  633. -- 跨国团战 军衔
  634. local player_data = nil
  635. if self.info.player_list and self.info.player_list[1] then
  636. player_data = self.info.player_list[1]
  637. end
  638. if (player_data and player_data.military_ranks and player_data.military_ranks > 0) or
  639. (self.info.military_ranks and self.info.military_ranks > 0) then
  640. local m_rank = self.info.military_ranks and
  641. self.info.military_ranks or
  642. player_data.military_ranks
  643. lua_resM:setOutsideImageSprite(self, self.player_military_rank_icon_img,
  644. GameResPath.GetMilitaryImage("military_ranks_"..m_rank), true)
  645. self.player_military_rank_icon_obj:SetActive(true)
  646. else
  647. self.player_military_rank_icon_obj:SetActive(false)
  648. end
  649. -------------------------
  650. local is_beach_chat = self.type_id and string.find(self.type_id, "beachChat")
  651. self.playerCon_voteBtn_obj:SetActive(is_beach_chat ~= nil)
  652. if (not is_beach_chat) then
  653. SetLocalScale(self.playerCon_tr, 1,1,1)
  654. RemoveClickEvent(self.playerCon_voteBtn_obj)
  655. else
  656. SetLocalScale(self.playerCon_tr, self.beach_scale,self.beach_scale,self.beach_scale)
  657. -- 添加点击投票事件
  658. local function on_click_vote( ... )
  659. local beach_model = BeachModel:GetInstance()
  660. local cur_time = TimeUtil:getServerTimeMs()
  661. if beach_model.vote_clock and (beach_model.vote_clock > cur_time) then
  662. return
  663. end
  664. -------------------------
  665. local num = 0
  666. local data = beach_model:GetMyInfo( )
  667. if data then
  668. num = data.vote_times or 0
  669. end
  670. if num > 0 then
  671. local name_str = GetCSLongName( self.info.name, info.ser_id )
  672. beach_model:VoteToOher(name_str, self.info.player_id)
  673. else
  674. beach_model:Fire(BeachConst.OPEN_BUY_VOTE)
  675. end
  676. end
  677. AddClickEvent(self.playerCon_voteBtn_obj, on_click_vote)
  678. end
  679. elseif self.info.player_id == RoleManager.Instance:GetMainRoleId() then
  680. self.show_type = 5
  681. self.playerCon:SetActive(false)
  682. self.systemCon:SetActive(false)
  683. self.lineCon:SetActive(false)
  684. self.mainRoleCon:SetActive(true)
  685. self.speakCon:SetActive(false)
  686. local function is_cs_chat( )
  687. return (self.info.ser_id ~= RoleManager.Instance:GetMainRoleServerId()) or self.model:IsCrossServerChannel( channel )
  688. end
  689. --local name_color = string.find(self.type_id or "","beachChat") and '#ffffff' or '#ffffff'
  690. local name_color = '#ffffff'
  691. self.mainRole_nameText.text = HtmlColorTxt( is_cs_chat() and GetCSLongName( info.name, self.info.ser_num ) or info.name , name_color)
  692. self.mainRole_addressText.text = "<color=#FFD797>(广东·广州)</color>"
  693. self.mainRole_gm_dot:SetActive(info.GM == 1)
  694. self.mainRole_gm_img_go:SetActive(info.GM == 1)
  695. self.mainRole_zdy_dot:SetActive(info.GM == 2)
  696. self.mainRole_zdy_img_go:SetActive(info.GM == 2)
  697. if channel == ChatModel.CHANNEL_CECRET then--重置,为了私聊好友界面的主角坐标设置
  698. SetAnchoredPositionY(self.mainRoleCon_tr,-10)
  699. else
  700. SetAnchoredPositionY(self.mainRoleCon_tr,0)
  701. end
  702. --[[if string.find(self.info.msg,"<a@redenvelopes>") then --红包链接要加上红包图片
  703. if not self.img_mainrole_red_packet then
  704. self.img_mainrole_red_packet = UiFactory.createChild(self.mainRoleCon.transform,UIType.Image,"Image")
  705. end
  706. self.img_mainrole_red_packet:SetActive(true)
  707. lua_resM:setImageSprite(self, self.img_mainrole_red_packet:GetComponent("Image"), "mainUI_asset", "mainui_red", true)
  708. self.img_mainrole_red_packet.transform.anchoredPosition = Vector2(90,-20)
  709. self.info.msg = "\n\n\n"..Trim(self.info.msg)
  710. AddClickEvent(self.img_mainrole_red_packet, function()
  711. GlobalEventSystem:Fire(EventName.OPEN_GUILD_MAIN_VIEW,1,4)
  712. end)
  713. elseif self.img_mainrole_red_packet then
  714. self.img_mainrole_red_packet:SetActive(false)
  715. end]]
  716. --[[if string.find(self.info.msg,"<a@actredenvelopes>") then --活动红包链接要加上红包图片
  717. if not self.img_mainrole_red_packet then
  718. self.img_mainrole_red_packet = UiFactory.createChild(self.mainRoleCon.transform,UIType.Image,"Image")
  719. end
  720. self.img_mainrole_red_packet:SetActive(true)
  721. lua_resM:setImageSprite(self, self.img_mainrole_red_packet:GetComponent("Image"), "mainUI_asset", "mainui_red", true)
  722. self.img_mainrole_red_packet.transform.anchoredPosition = Vector2(90,-20)
  723. self.info.msg = "\n\n\n"..Trim(self.info.msg)
  724. AddClickEvent(self.img_mainrole_red_packet, function()
  725. local act = CustomActivityModel:getInstance():getActList(CustomActivityModel.CustomActBaseType.ACT_RED_BAG)
  726. if act ~= nil then
  727. GlobalEventSystem:Fire(EventName.OPEN_OPERATION_ACTIVITY_VIEW,act.base_type,act.sub_type)
  728. else
  729. Message.show("活动未开启")
  730. end
  731. end)
  732. elseif self.img_mainrole_red_packet then
  733. self.img_mainrole_red_packet:SetActive(false)
  734. end--]]
  735. if self.mainRoleVo.level < Config.Modulesub["110@2"].open_lv then --等级不够不显示
  736. self.mainRoleGuildDescrb.gameObject:SetActive(false)
  737. else
  738. --社团名字
  739. self.mainRoleGuildDescrb.gameObject:SetActive(true)
  740. local main_role_guild_name = ""
  741. self.playerGuild_txt.text = main_role_guild_name
  742. if info.guild_name and info.guild_name ~= "" then
  743. main_role_guild_name = info.guild_name
  744. elseif info.player_list and info.player_list[1].guild_name and info.player_list[1].guild_name ~= "" then
  745. main_role_guild_name = info.player_list[1].guild_name
  746. else -- 无社团
  747. self.mainRoleGuildDescrb.gameObject:SetActive(false)
  748. end
  749. self.mainRoleGuild_txt.text = main_role_guild_name
  750. end
  751. SetSizeDeltaX(self.mainRoleGuildDescrb, self.mainRoleGuild_txt.preferredWidth + 10)
  752. --
  753. --"common_asset", "tyui_qp1_1", false)-- "chat_asset", "chat_default_bg", false)--tyui_chat
  754. local main_role_dress_bubble = 425001--气泡类型
  755. if info.dress_list then
  756. for i, v in ipairs(info.dress_list) do
  757. --1气泡 2相框
  758. if v.dress_id ~= 0 then
  759. local icon_name = v.dress_id
  760. if v.dress_type == 2 then
  761. info.dress_board = icon_name
  762. -- if info.dress_board and info.dress_board ~= 0 then
  763. -- lua_resM:setOutsideImageSprite(self, self.mainRole_headBoard_img, GameResPath.GetChatDressIcon(info.dress_board), false)
  764. -- self.mainRole_headBoard_img.gameObject:SetActive(true)
  765. -- else
  766. -- self.mainRole_headBoard_img.gameObject:SetActive(false)
  767. -- end
  768. elseif v.dress_type == 1 then
  769. main_role_dress_bubble = Trim(icon_name)
  770. if main_role_dress_bubble and main_role_dress_bubble ~= 0 then
  771. lua_resM:setOutsideImageSprite(self, self.mainRole_chatBg_img, GameResPath.GetChatDressIcon(main_role_dress_bubble), false)
  772. end
  773. end
  774. end
  775. end
  776. end
  777. if main_role_dress_bubble ~= false and Config.ConfigChatTextColor[main_role_dress_bubble] then
  778. self.mainRole_contentText_t.color = Config.ConfigChatTextColor[main_role_dress_bubble]
  779. else
  780. self.mainRole_contentText_t.color = self.default_bubble_color_value
  781. end
  782. --添加超链接
  783. self.mainRole_contentText.sizeDelta = Vector2(self.role_text_width, 0)
  784. if self.info.msg == "" then --语音信息有时候为空
  785. self.mainRole_contentText_t.text = ""
  786. else
  787. SetInlineText(self.mainRole_contentText_t, self.info.msg,nil,chat_color_is_chat_view)
  788. end
  789. -- SetInlineText(self.mainRole_contentText_t, "<color="..text_color..">"..self.info.msg.."</color>")
  790. AddUnderLineAndClick(self, self.mainRole_contentText, call_fun)
  791. -- ===2021/3/13 策划说不要显示性别====
  792. -- if info.sex == 1 then
  793. -- lua_resM:setImageSprite(self, self.mainRole_sexIcon:GetComponent("Image"), "common_asset", "com_boy", true)
  794. -- else
  795. -- lua_resM:setImageSprite(self, self.mainRole_sexIcon:GetComponent("Image"), "common_asset", "com_girl", true)
  796. -- end
  797. if not self.mainRole_vip_item then
  798. self.mainRole_vip_item = RoleVipItem.New(self.mainRole_vipIcon)
  799. end
  800. self.mainRole_vip_item:SetData(info.vip_flag,info.sup_vip_type)
  801. ---
  802. --排行icon显示
  803. local player_data = nil
  804. if self.info.player_list and self.info.player_list[1] then
  805. player_data = self.info.player_list[1]
  806. end
  807. -- 战力第一/等级第一/霸主 等头衔显示
  808. if (player_data and player_data.is_overlord and player_data.is_overlord > 0) or
  809. (self.info.is_overlord and self.info.is_overlord > 0) then
  810. if self.info.is_overlord then
  811. lua_resM:setImageSprite(self,self.mainRole_rank_icon_img, "chat_asset","chat_overlord"..self.info.is_overlord.."_pointfilter",true)
  812. else
  813. lua_resM:setImageSprite(self,self.mainRole_rank_icon_img, "chat_asset","chat_overlord".. player_data.is_overlord.."_pointfilter",true)
  814. end
  815. self.mainRole_rank_icon_img.gameObject:SetActive(true)
  816. else
  817. local res_rank_name = self:GetRankIconResName(self.info.player_id)
  818. if res_rank_name then
  819. lua_resM:setImageSprite(self,self.mainRole_rank_icon_img, "chat_asset",res_rank_name,true)
  820. self.mainRole_rank_icon_img.gameObject:SetActive(true)
  821. else
  822. self.mainRole_rank_icon_img.gameObject:SetActive(false)
  823. end
  824. end
  825. -- 跨国团战 军衔
  826. if (player_data and player_data.military_ranks and player_data.military_ranks > 0) or
  827. (self.info.military_ranks and self.info.military_ranks > 0) then
  828. local m_rank = self.info.military_ranks and
  829. self.info.military_ranks or
  830. player_data.military_ranks
  831. lua_resM:setOutsideImageSprite(self, self.mainrole_military_rank_icon_img,
  832. GameResPath.GetMilitaryImage("military_ranks_"..m_rank), true)
  833. self.mainrole_military_rank_icon_obj:SetActive(true)
  834. else
  835. self.mainrole_military_rank_icon_obj:SetActive(false)
  836. end
  837. local is_beach_chat = self.type_id and string.find(self.type_id,"beachChat")
  838. if (not is_beach_chat) then
  839. SetLocalScale(self.mainRoleCon_tr, 1,1,1)
  840. else
  841. SetLocalScale(self.mainRoleCon_tr, self.beach_scale,self.beach_scale,self.beach_scale)
  842. end
  843. if not self.mainRoleHeadItem then
  844. self.mainRoleHeadItem = HeadRoleItem.New(self.mainRoleHeadCon)
  845. self.mainRoleHeadItem:SetItemSize(70,70)
  846. end
  847. local head_data = { --career = info.career
  848. vo = {
  849. id = info.player_id,
  850. use_bg = 3,
  851. career = 0,
  852. sex = info.sex,
  853. turn = info.turn,
  854. board = info.dress_board,
  855. picture_ver = info.picture_ver,
  856. picture = info.picture,
  857. profile_photo_id = info.profile_photo_id,
  858. dress_board_id = info.dress_board,
  859. },
  860. }--level = info.level,
  861. self.mainRoleHeadItem:SetData(head_data)
  862. local text_size = co.TableXY(math.min(self.role_text_width, self.mainRole_contentText_t.preferredWidth), self.mainRole_contentText_t.preferredHeight)
  863. self.mainRole_contentText.sizeDelta = text_size --Vector2(self.role_text_width, text_size.y)
  864. --self.mainRoleHeadCon.anchoredPosition = Vector2(195,text_size.y) -- 头像跟随气泡箭头位移
  865. -- self.mainRoleHeadCon.anchoredPosition = Vector2(195,-text_size.y+22.5)
  866. -- self.mainRoleGuildDescrb.anchoredPosition = Vector2(195,-text_size.y+22.5 -43.3)
  867. --主角
  868. local text_offset = main_role_dress_bubble and self.main_role_text_offset or self.main_role_default_text_offset
  869. local bg_add_size = main_role_dress_bubble and self.dress_bubble_role_bg_add_size or self.role_bg_add_size
  870. if main_role_dress_bubble and Config.ConfigChatDress.Pos[main_role_dress_bubble] then
  871. local addTable = Config.ConfigChatDress.Pos[main_role_dress_bubble]
  872. text_offset = co.AddXY(text_offset,co.TableXY(addTable.pos_x,addTable.pos_y)) --+ Vector2(addTable.pos_x,addTable.pos_y)
  873. bg_add_size = co.AddXY(bg_add_size,co.TableXY(addTable.size_x,addTable.size_y))
  874. end
  875. if info.iType == ChatModel.MSG_TYPE.VOICE then
  876. local voiceVo = ChatVoiceManager:getInstance():GetVoice(info.voice_id)
  877. if voiceVo then
  878. local leftTime = voiceVo:IsPlaying()
  879. if leftTime then
  880. self:PlayAnim(leftTime)
  881. else
  882. -- if not voiceVo.last_play_start_time then
  883. -- self.mainRole_voice_hot:SetActive(true)
  884. -- end
  885. self:SetPlayState(3)
  886. end
  887. else
  888. self:SetPlayState(3)
  889. end
  890. self.mainRoleCon_voiceText.text = info.length.."''"
  891. self.mainRoleCon_btnVoice:SetActive(true)
  892. self.mainRole_voiceClick:SetActive(true)
  893. local text_size_x = math.max(65,text_size.x) --最少要90
  894. self.mainRole_chatBg.sizeDelta = Vector2(bg_add_size.x + text_size_x, bg_add_size.y + text_size.y + self.voice_bg_add_size.y)
  895. self.mainRole_chatBg.anchoredPosition = Vector3(self.main_role_chatBg_offset.x, self.main_role_chatBg_offset.y)
  896. self.mainRole_contentText.anchoredPosition = Vector3(-self.role_text_offset.x - text_size_x / 2 + text_offset.x, self.mainRole_chatBg.localPosition.y - self.mainRole_chatBg.sizeDelta.y + text_size.y / 2 + self.voice_text_offset.y)
  897. self.mainRole_voiceClick_tr.anchoredPosition = self.mainRole_chatBg.anchoredPosition
  898. self.mainRole_voiceClick_tr.sizeDelta = self.mainRole_chatBg.sizeDelta
  899. else
  900. self.mainRoleCon_btnVoice:SetActive(false)
  901. self.mainRole_voiceClick:SetActive(false)
  902. self.mainRole_chatBg.sizeDelta = Vector2(bg_add_size.x + text_size.x, math.max(bg_add_size.y + text_size.y, self.role_bg_min_size.y))
  903. self.mainRole_chatBg.anchoredPosition = Vector3(self.main_role_chatBg_offset.x, self.main_role_chatBg_offset.y)
  904. self.mainRole_contentText.anchoredPosition = Vector3(-self.role_text_offset.x - text_size.x / 2 + text_offset.x, self.mainRole_chatBg.localPosition.y - self.mainRole_chatBg.sizeDelta.y / 2 + self.role_text_offset.y + text_offset.y)
  905. end
  906. self.height = self.mainRole_chatBg.sizeDelta.y + 30
  907. self.height = math.max(self.height, 95)
  908. end
  909. -----上面的height 都是独立的
  910. if SceneManager:getInstance():IsBeachScene() and channel == ChatModel.CHANNEL_NEAR then
  911. if self.info.player_id == RoleManager.Instance:GetMainRoleId() then
  912. self.btnGift:SetActive(false)
  913. else
  914. self.btnGift:SetActive(true)
  915. -- AddClickEvent(self.btnGift, function()
  916. -- BeachModel:getInstance():Fire(BeachModel.OPEN_GIFT_VIEW, {role_id = self.info.player_id, name = self.info.name})
  917. -- end)
  918. end
  919. else
  920. self.btnGift:SetActive(false)
  921. end
  922. self.bind_play_voice = GlobalEventSystem:Bind(ChatModel.PLAY_VOICE, function(voice_id, voice_clip)
  923. if self.info and self.info.voice_id == voice_id then
  924. if self.anim_play_voice then
  925. return
  926. end
  927. self:PlayAnim(voice_clip.length)
  928. end
  929. end)
  930. self.bind_stop_voice = self.model:Bind(ChatModel.STOP_VOICE_PLAY, function(voice_id)
  931. if self.info and self.info.voice_id == voice_id then
  932. if self.timer_cancel_anim then
  933. GlobalTimerQuest:CancelQuest(self.timer_cancel_anim)
  934. self.timer_cancel_anim = nil
  935. end
  936. if self.anim_play_voice then
  937. GlobalTimerQuest:CancelQuest(self.anim_play_voice)
  938. self.anim_play_voice = nil
  939. end
  940. self:SetPlayState(3)
  941. end
  942. end)
  943. self.height = self.height + 20
  944. -------------------------
  945. --用于其它地方用到了item计算高度
  946. local special_tag = self.info.msg or ""
  947. if channel ~= ChatModel.CHANNEL_SYSTEM and (not self.info.is_line) and (not self.info.show_num) then
  948. if self.type_id and string.find(self.type_id,"beachChat") then
  949. self.height = self.height * self.beach_scale
  950. end
  951. end
  952. self.model:Fire(ChatModel.CHANGE_HEIGHT,self.type_id,self.height,special_tag)
  953. --用于其它地方用到了item计算高度
  954. return self.height
  955. end
  956. function ChatItem:PlayAnim(leftTime)
  957. local playState = 0
  958. self:SetPlayState(1)
  959. self.anim_play_voice = GlobalTimerQuest:AddPeriodQuest(function()
  960. playState = (playState + 1) % 3
  961. self:SetPlayState(playState + 1)
  962. end, 0.5, -1)
  963. self.timer_cancel_anim = GlobalTimerQuest:AddPeriodQuest(function()
  964. GlobalTimerQuest:CancelQuest(self.anim_play_voice)
  965. self.anim_play_voice = nil
  966. self.timer_cancel_anim = nil
  967. self:SetPlayState(3)
  968. end, leftTime, 1)
  969. end
  970. function ChatItem:SetRegText(scmd)
  971. local text_size
  972. if self.info.player_id == RoleManager.Instance:GetMainRoleId() then
  973. self.mainRole_contentText.sizeDelta = Vector2(self.role_text_width, 0)
  974. self.mainRole_contentText_t.text = "<color=#323232>"..scmd.voice_text.."</color>"
  975. text_size = Vector2(math.min(self.role_text_width, self.mainRole_contentText_t.preferredWidth), self.mainRole_contentText_t.preferredHeight)
  976. self.mainRole_contentText.sizeDelta = text_size --Vector2(self.role_text_width, text_size.y)
  977. -- self.mainRole_chatBg.sizeDelta = Vector2(math.max(self.voice_bg_add_size.x + self.mainRoleCon_voiceText.preferredWidth, 40 + text_size.x),self.voice_bg_add_size.y + text_size.y + (text_size.y > 0 and 10 or 0))
  978. -- self.mainRole_contentText.anchoredPosition = Vector3(-118 - text_size.x / 2,self.mainRole_chatBg.localPosition.y - self.mainRole_chatBg.sizeDelta.y + text_size.y / 2 + 14.6)
  979. self.mainRole_chatBg.sizeDelta = Vector2(math.max(self.voice_bg_add_size.x + self.mainRoleCon_voiceText.preferredWidth, self.role_bg_add_size.x + text_size.x), self.voice_bg_add_size.y + text_size.y + (text_size.y > 0 and 10 or 10))
  980. self.mainRole_contentText.anchoredPosition = Vector3(-self.role_text_offset.x - text_size.x / 2, self.mainRole_chatBg.localPosition.y - self.mainRole_chatBg.sizeDelta.y + text_size.y / 2 + self.voice_text_offset.y)
  981. self.height = self.mainRole_chatBg.sizeDelta.y + 30
  982. self.height = math.max(self.height, 95)
  983. else
  984. self.mainRole_contentText.sizeDelta = Vector2(self.role_text_width, 0)
  985. self.player_contentText_t.text = "<color=#323232>"..scmd.voice_text.."</color>"
  986. text_size = Vector2(math.min(self.role_text_width, self.player_contentText_t.preferredWidth), self.player_contentText_t.preferredHeight)
  987. self.player_contentText.sizeDelta = text_size--Vector2(self.role_text_width, text_size.y)
  988. -- self.player_chatBg.sizeDelta = Vector2(math.max(self.voice_bg_add_size.x + self.player_voiceText.preferredWidth, 40 + text_size.x), self.voice_bg_add_size.y + text_size.y + (text_size.y > 0 and 10 or 0))
  989. self.player_chatBg.sizeDelta = Vector2(math.max(self.voice_bg_add_size.x + self.player_voiceText.preferredWidth, self.role_bg_add_size.x + text_size.x), self.voice_bg_add_size.y + text_size.y + (text_size.y > 0 and 10 or 10))
  990. self.player_contentText.anchoredPosition = Vector3(self.role_text_offset.x + text_size.x / 2, self.player_chatBg.localPosition.y - self.player_chatBg.sizeDelta.y + text_size.y / 2 + self.voice_text_offset.y)
  991. self.height = self.mainRole_chatBg.sizeDelta.y + 30
  992. self.height = math.max(self.height, 95)
  993. end
  994. return text_size.y
  995. end
  996. function ChatItem:GetHeight()
  997. return self.height
  998. end
  999. function ChatItem:IsLineItem()
  1000. return self.info and self.info.is_line
  1001. end
  1002. function ChatItem:SetLineSize(width, bgWidth)
  1003. self.line_width = width
  1004. self.line_bg_width = bgWidth
  1005. if self.is_loaded then
  1006. self.lineCon.transform.sizeDelta = Vector2(width or 560, 23)
  1007. -- self.lineImg.transform.sizeDelta = Vector2(bgWidth or 196, 22)
  1008. else
  1009. self.set_line_size_cache = true
  1010. end
  1011. end
  1012. function ChatItem:CilckContentHandle(param_list)
  1013. self.model.clicked_item = self
  1014. self.model.chick_hyperlink_mark = true
  1015. self.model:FireSpecialTab(param_list)
  1016. end
  1017. function ChatItem:SetVisible(state,force_hide)
  1018. BaseItem.SetVisible(self, state,force_hide)
  1019. if not state then
  1020. self:ClearAnimEvent()
  1021. end
  1022. end
  1023. function ChatItem:SetPlayState(state)
  1024. if not self.info then
  1025. return
  1026. end
  1027. local s1, s2, s3
  1028. if self.info.player_id == RoleManager.Instance:GetMainRoleId() then
  1029. s1 = self.mainRoleCon_img_voice1
  1030. s2 = self.mainRoleCon_img_voice2
  1031. s3 = self.mainRoleCon_img_voice3
  1032. else
  1033. s1 = self.player_img_voice1
  1034. s2 = self.player_img_voice2
  1035. s3 = self.player_img_voice3
  1036. end
  1037. if not IsNull(s1) and not IsNull(s2) and not IsNull(s3) then
  1038. s1:SetActive(state == 1)
  1039. s2:SetActive(state == 2)
  1040. s3:SetActive(state == 3)
  1041. end
  1042. end
  1043. function ChatItem:ClearAnimEvent()
  1044. if self.bind_play_voice then
  1045. GlobalEventSystem:UnBind(self.bind_play_voice)
  1046. self.bind_play_voice = nil
  1047. end
  1048. if self.anim_play_voice then
  1049. GlobalTimerQuest:CancelQuest(self.anim_play_voice)
  1050. self.anim_play_voice = nil
  1051. end
  1052. if self.timer_cancel_anim then
  1053. GlobalTimerQuest:CancelQuest(self.timer_cancel_anim)
  1054. self.timer_cancel_anim = nil
  1055. end
  1056. if self.bind_stop_voice then
  1057. self.model:UnBind(self.bind_stop_voice)
  1058. self.bind_stop_voice = nil
  1059. end
  1060. end
  1061. function ChatItem:__delete()
  1062. self:ClearAnimEvent()
  1063. if self.mainRoleHeadItem then
  1064. self.mainRoleHeadItem:DeleteMe()
  1065. self.mainRoleHeadItem = nil
  1066. end
  1067. if self.playHeadItem then
  1068. self.playHeadItem:DeleteMe()
  1069. self.playHeadItem = nil
  1070. end
  1071. if self.player_vip_item then
  1072. self.player_vip_item:DeleteMe()
  1073. self.player_vip_item = nil
  1074. end
  1075. if self.mainRole_vip_item then
  1076. self.mainRole_vip_item:DeleteMe()
  1077. self.mainRole_vip_item = nil
  1078. end
  1079. for k,v in pairs(self.assist_award_item_list) do
  1080. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem,v)
  1081. end
  1082. self.assist_award_item_list = {}
  1083. end
  1084. function ChatItem:SetLineTimeColor(color)
  1085. self.line_color = color
  1086. if self.is_loaded then
  1087. -- self.line_timeText.color = Color(221 / 255, 223 / 255, 231 / 255, 1)--ColorUtil:GetGoodsColor(color)
  1088. else
  1089. self.color_cache = true
  1090. end
  1091. end
  1092. function ChatItem:ResetText( )
  1093. self.player_contentText_t.text = ""
  1094. self.mainRole_contentText_t.text = ""
  1095. self.system_contentText.text = ""
  1096. end
  1097. function ChatItem:GetRankIconResName( playId )
  1098. local fight_rank_num = nil
  1099. local level_rank_num = nil
  1100. local rankList = RankModel:getInstance():GetRankChatList()
  1101. if not rankList or not rankList.fight_list then return end
  1102. for k,v in pairs(rankList.fight_list) do
  1103. if playId == v.player_id then
  1104. fight_rank_num = v.rank
  1105. end
  1106. end
  1107. for k,v in pairs(rankList.level_list) do
  1108. if playId == v.player_id then
  1109. level_rank_num = v.rank
  1110. end
  1111. end
  1112. local res_rank_name = nil
  1113. if fight_rank_num and fight_rank_num < 4 then
  1114. res_rank_name = "chat_fight_rank"..fight_rank_num.."_pointfilter"
  1115. elseif level_rank_num and level_rank_num < 4 then
  1116. res_rank_name = "chat_level_rank"..level_rank_num.."_pointfilter"
  1117. elseif fight_rank_num and fight_rank_num >= 4 and fight_rank_num <= 10 then
  1118. res_rank_name = "chat_fight_rank4_pointfilter"
  1119. elseif level_rank_num and level_rank_num >= 4 and level_rank_num <= 10 then
  1120. res_level_name = "chat_level_rank4_pointfilter"
  1121. else
  1122. res_rank_name = nil
  1123. end
  1124. return res_rank_name
  1125. end
  1126. -- 跨服频道 根据后端传的玩家原本服务器排名来拿
  1127. function ChatItem:GetRankIconResName2( level_rank_num, fight_rank_num )
  1128. local res_rank_name = nil
  1129. if fight_rank_num and fight_rank_num < 4 and fight_rank_num ~= 0 then
  1130. res_rank_name = "chat_fight_rank"..fight_rank_num.."_pointfilter"
  1131. elseif level_rank_num and level_rank_num < 4 and level_rank_num ~= 0 then
  1132. res_rank_name = "chat_level_rank"..level_rank_num.."_pointfilter"
  1133. elseif fight_rank_num and fight_rank_num >= 4 and fight_rank_num <= 10 and fight_rank_num ~= 0 then
  1134. res_rank_name = "chat_fight_rank4_pointfilter"
  1135. elseif level_rank_num and level_rank_num >= 4 and level_rank_num <= 10 and level_rank_num ~= 0 then
  1136. res_level_name = "chat_level_rank4_pointfilter"
  1137. else
  1138. res_rank_name = nil
  1139. end
  1140. return res_rank_name
  1141. end
  1142. function ChatItem:SetItemSize(x,y)
  1143. self.size_x = self.size_x or x
  1144. self.size_y = self.size_y or y
  1145. if self.transform then
  1146. self.size_x = x or self.transform.sizeDelta.x
  1147. self.size_y = y or self.transform.sizeDelta.y
  1148. self.transform.sizeDelta = Vector3(self.size_x,self.size_y,0)
  1149. end
  1150. end
  1151. function ChatItem:SetLocalPositionY(pos)
  1152. --快速创建多个的时候pos都是0会挤在一起,所以需要创建的时候及时存储相应位置,ReLayoutScroll的时候再次定义位置
  1153. self.wait_set_local_y = nil
  1154. if pos and self.transform and self.transform.localPosition then
  1155. self.transform.localPosition = Vector3(0,pos,0)
  1156. else
  1157. self.wait_set_local_y = pos
  1158. end
  1159. end
  1160. function ChatItem:SetTypeId( type_id )
  1161. self.type_id = type_id
  1162. end