ChatTextItemCtr.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. local ChatTextItemCtr = {}
  2. local TaskJumpCtr = require("Common/TaskJumpCtr")
  3. function ChatTextItemCtr:SetData(wnd, item, logicData, enterType, onClickOwner, onClickCB)
  4. item.chlWorld:SetActive(false)
  5. item.chlSystem:SetActive(logicData.isSystem and logicData.type ~= Enum.ChatSystemType.Guild)
  6. item.chlGuildSystem:SetActive(logicData.isSystem and logicData.type == Enum.ChatSystemType.Guild)
  7. --item.system:SetActive(enterType == Enum.ItemIEnterType.System)
  8. --item.player:SetActive(enterType ~= Enum.ItemIEnterType.System)
  9. item.easyPlayer:SetActive(not logicData.isSystem)
  10. item.vipIcon.image.enabled = false
  11. item.vipIcon.image.sprite = nil
  12. item.titleImg.image.enabled = false
  13. item.titleImg.image.sprite = nil
  14. item.text.symbolText.raycastTarget = false
  15. if item.text.symbolTextEvent then
  16. item.text.symbolTextEvent:RegisterClickEvent(nil, nil)
  17. end
  18. if enterType == Enum.ItemIEnterType.System then
  19. --公告类型 1通关 2获得伙伴 3宝箱 4稀有道具
  20. local paramName = ""
  21. if logicData.type == Enum.ChatSystemType.Loggedin then
  22. item.text.symbolText.text = I18N.T(logicData.nickname)
  23. --local content = I18N.T(logicData.nickname)
  24. --item.text.symbolText.text = "#h"..content.."{6}#h"
  25. --if item.text.symbolTextEvent then
  26. -- item.text.symbolTextEvent:RegisterClickEvent(wnd, wnd.SystemChatHyperClick)
  27. --end
  28. elseif logicData.type == Enum.ChatSystemType.PassMap then
  29. local levelData = ManagerContainer.CfgMgr:GetLevelDataById(logicData.paramIds[1])
  30. if levelData ~= nil then
  31. paramName = levelData.Name
  32. item.text.symbolText.text = I18N.SetLanguageValue("SystemMessageType1", CommonUtil.GetVaildNickName(logicData.nickname), I18N.T(paramName))
  33. end
  34. elseif logicData.type == Enum.ChatSystemType.Item then
  35. local itemData = ManagerContainer.CfgMgr:GetItemById(logicData.paramIds[1])
  36. paramName = string.format(Constant.ChatSystemColorArray[itemData.Quality], I18N.T(itemData.Name))
  37. local num = (logicData.paramIds[2] and logicData.paramIds[2] > 1) and "x"..logicData.paramIds[2] or ""
  38. local sourceType = logicData.paramIds[3]
  39. local sourceItemId = logicData.paramIds[4]
  40. if sourceType then
  41. if sourceType ~= Enum.DropSource.Gift then
  42. item.text.symbolText.text = I18N.SetLanguageValue("ChatNotice01", CommonUtil.GetVaildNickName(logicData.nickname), paramName, I18N.T("dropsource_"..sourceType))..num
  43. else
  44. if sourceItemId == 514 then
  45. --老旧卡包
  46. item.text.symbolText.text = I18N.SetLanguageValue("ChatNotice01", CommonUtil.GetVaildNickName(logicData.nickname), paramName, I18N.T("dropsource_"..sourceType.."_"..sourceItemId))..num
  47. end
  48. end
  49. end
  50. elseif logicData.type == Enum.ChatSystemType.WorldBoss then
  51. local worldBossName = ""
  52. if logicData.paramIds and logicData.paramIds[1] then
  53. local worldBossCfgData = ManagerContainer.DataMgr.WorldBossData:GetWorldBossDataById(logicData.paramIds[1],0)
  54. if nil == worldBossCfgData then
  55. worldBossCfgData = ManagerContainer.DataMgr.WorldBossData:GetWorldBossDataById(logicData.paramIds[1],1)
  56. end
  57. if worldBossCfgData then
  58. local npcCfgData = ManagerContainer.CfgMgr:GetNpcCfgById(worldBossCfgData.SummonId)
  59. if npcCfgData then
  60. worldBossName = I18N.SetLanguageValue(npcCfgData.Name)
  61. end
  62. end
  63. end
  64. local content = I18N.SetLanguageValue("SystemMessageType6", worldBossName, "{"..logicData.type.."}")
  65. item.text.symbolText.text = content --"#h"..content.."{"..logicData.type.."}#h"
  66. if item.text.symbolTextEvent then
  67. item.text.symbolText.raycastTarget = true
  68. item.text.symbolTextEvent:RegisterClickEvent(nil, function (hyperParam)
  69. local systemType = tonumber(hyperParam)
  70. if systemType == 6 then
  71. --世界BOSS
  72. TaskJumpCtr:JumpBuyCfgId(15)
  73. end
  74. end)
  75. end
  76. elseif logicData.type == Enum.ChatSystemType.ArenaWinStreak then
  77. item.text.symbolText.text = I18N.SetLanguageValue("ArenaNotice", CommonUtil.GetVaildNickName(logicData.nickname), unpack(logicData.paramIds))
  78. elseif logicData.type == Enum.ChatSystemType.TimeLimitDel then
  79. item.text.symbolText.text = I18N.SetLanguageValue("CompetitionTip2", logicData.nickname)
  80. elseif logicData.type == Enum.ChatSystemType.ItemExchange then
  81. local activityData = ManagerContainer.CfgMgr:GetActivityCfg(logicData.paramIds[1])
  82. local activityName = activityData and activityData.Name or ""
  83. local exchangeData = ManagerContainer.CfgMgr:GetActivitiesPetExchangeCfgById(logicData.paramIds[2])
  84. local itemCfgId = exchangeData and exchangeData.Reward and exchangeData.Reward[1][1] or 0
  85. local itemData = ManagerContainer.CfgMgr:GetItemById(itemCfgId)
  86. local itemName = itemData and itemData.Name or ""
  87. if itemData.ResType == Enum.ItemType.Card then
  88. local cardData = ManagerContainer.CfgMgr:GetCardDataById(itemCfgId)
  89. local lv = cardData.CardLevel
  90. item.text.symbolText.text = I18N.SetLanguageValue("ChangeTakeNotice1", CommonUtil.GetVaildNickName(logicData.nickname),activityName,lv,itemName)
  91. else
  92. item.text.symbolText.text = I18N.SetLanguageValue("ChangeTakeNotice", CommonUtil.GetVaildNickName(logicData.nickname),activityName,itemName)
  93. end
  94. elseif logicData.type == Enum.ChatSystemType.StarDivine then
  95. local data = ManagerContainer.CfgMgr:GetCompetitionDevineCfgById(logicData.paramIds[1] + 1)
  96. if data and data.BroadcastKey then
  97. item.text.symbolText.text = I18N.SetLanguageValue(data.BroadcastKey, CommonUtil.GetVaildNickName(logicData.nickname))
  98. end
  99. elseif logicData.type == Enum.ChatSystemType.GuildDemonBoss then
  100. if logicData.paramIds and logicData.paramIds[1] then
  101. item.text.symbolText.text = I18N.SetLanguageValue("GuildDemonBossNotice", logicData.nickname,logicData.paramIds[2])
  102. end
  103. elseif logicData.type == Enum.ChatSystemType.IdolGiftBroad then
  104. item.text.symbolText.text = I18N.SetLanguageValue("IdolGiftBroad", CommonUtil.GetVaildNickName(logicData.nickname))
  105. elseif logicData.type == Enum.ChatSystemType.Competition then
  106. local content = ""
  107. local score = logicData.paramIds[1] or 0
  108. if score < 101 then
  109. content = "CompetitionTip5"
  110. elseif score < 401 then
  111. content = "CompetitionTip6"
  112. elseif score < 501 then
  113. content = "CompetitionTip7"
  114. end
  115. item.text.symbolText.text = I18N.SetLanguageValue(content, CommonUtil.GetVaildNickName(logicData.nickname), score)
  116. elseif logicData.type == Enum.ChatSystemType.Guild then
  117. if logicData.paramIds then
  118. local type = logicData.paramIds[1]
  119. if type == 1 then
  120. item.text.symbolText.text = I18N.SetLanguageValue('Guildchat_003', CommonUtil.GetVaildNickName(logicData.nickname), CommonUtil.GetGuildPostStr(logicData.paramIds[2]))
  121. elseif type == 2 then
  122. item.text.symbolText.text = I18N.SetLanguageValue('Guildchat_001', CommonUtil.GetVaildNickName(logicData.nickname))
  123. elseif type == 3 then
  124. item.text.symbolText.text = I18N.SetLanguageValue('Guildchat_002', CommonUtil.GetVaildNickName(logicData.nickname), CommonUtil.GetGuildPostStr(logicData.paramIds[2]), "{".. logicData.paramIds[3] .."}")
  125. if item.text.symbolTextEvent then
  126. item.text.symbolText.raycastTarget = true
  127. item.text.symbolTextEvent:RegisterClickEvent(nil, function (hyperParam)
  128. TaskJumpCtr:JumpBuyCfgId(20, tonumber(hyperParam))
  129. end)
  130. end
  131. end
  132. end
  133. elseif logicData.type == Enum.ChatSystemType.TurnWheelPrize then
  134. if logicData.paramIds then
  135. local ItemId = logicData.paramIds[1]
  136. local ItemCount = logicData.paramIds[2]
  137. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(ItemId)
  138. if itemCfgData then
  139. local paramName = string.format(Constant.ChatSystemColorArray[itemCfgData.Quality], I18N.T(itemCfgData.Name))
  140. local num = (ItemCount and ItemCount > 1) and "x"..logicData.paramIds[2] or ""
  141. item.text.symbolText.text = I18N.SetLanguageValue("ChatNotice01", CommonUtil.GetVaildNickName(logicData.nickname), paramName , I18N.T("dropsource_dajiang"))..num
  142. end
  143. end
  144. elseif logicData.type == Enum.ChatSystemType.ActivityWheel then
  145. if logicData.paramIds then
  146. local actitivyId = logicData.paramIds[1]
  147. local ItemId = logicData.paramIds[2]
  148. local ItemCount = logicData.paramIds[3]
  149. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(ItemId)
  150. local ActivityName = ""
  151. if actitivyId then
  152. local cfgData = ManagerContainer.CfgMgr:GetActivityCfg(actitivyId)
  153. if cfgData then
  154. ActivityName = cfgData.Name
  155. end
  156. end
  157. if itemCfgData then
  158. local num = (ItemCount and ItemCount > 1) and "x"..logicData.paramIds[3] or ""
  159. item.text.symbolText.text = I18N.SetLanguageValue("ActivityRoulettel", CommonUtil.GetVaildNickName(logicData.nickname), ActivityName , I18N.T(itemCfgData.Name))..num
  160. end
  161. end
  162. elseif logicData.type == Enum.ChatSystemType.ActCollection then
  163. if logicData.paramIds then
  164. local actitivyId = logicData.paramIds[1]
  165. if actitivyId then
  166. local cfgData = ManagerContainer.CfgMgr:GetActivityCfg(actitivyId)
  167. if cfgData then
  168. if cfgData.Type == Enum.ActivityType.ACTIVITY_TYPE_FESTIVAL_REWARD then
  169. local actitivySubId = logicData.paramIds[2]
  170. local subCfgData = ManagerContainer.CfgMgr:GetActivitiesCollectionCfgById(actitivySubId)
  171. if subCfgData and subCfgData.ShowItem then
  172. local itemListStr = nil
  173. for i = 1, #subCfgData.ShowItem do
  174. local itemId = subCfgData.ShowItem[i]
  175. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(itemId)
  176. if itemCfgData then
  177. if itemListStr then
  178. itemListStr = itemListStr .. ',' .. I18N.T(itemCfgData.Name)
  179. else
  180. itemListStr = I18N.T(itemCfgData.Name)
  181. end
  182. end
  183. end
  184. if itemListStr then
  185. item.text.symbolText.text = I18N.SetLanguageValue("SetsWordActivity04", CommonUtil.GetVaildNickName(logicData.nickname), I18N.T(cfgData.Name), itemListStr)
  186. end
  187. end
  188. end
  189. end
  190. end
  191. end
  192. elseif logicData.type == Enum.ChatSystemType.GoddessLike then
  193. if logicData.paramIds then
  194. local actitivyId = logicData.paramIds[1]
  195. local ItemId = logicData.paramIds[2]
  196. local ItemCount = logicData.paramIds[3]
  197. local cfgData = ManagerContainer.CfgMgr:GetActivityCfg(actitivyId)
  198. local actName = cfgData and string.formatbykey(cfgData.Name) or ''
  199. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(ItemId)
  200. local itemName = nil
  201. if itemCfgData then
  202. itemName = string.format(Constant.ChatSystemColorArray[itemCfgData.Quality], I18N.T(itemCfgData.Name))
  203. else
  204. itemName = ''
  205. end
  206. item.text.symbolText.text = I18N.SetLanguageValue("GiftBroadcast", CommonUtil.GetVaildNickName(logicData.nickname), actName, tostring(ItemCount), itemName)
  207. end
  208. end
  209. else
  210. local fromData = logicData.fromData
  211. local content = logicData.message
  212. local context = CommonUtil.GetVaildNickName(fromData.nickname)
  213. item.nickname.text.text = context
  214. if fromData.sex ~= nil then
  215. CommonUtil.SetTextColor(item.nickname.text, fromData.sex == 1 and Constant.PinkColorText or Constant.BlueColorText)
  216. end
  217. local vipLv = fromData.vipLv
  218. local vipIcon = nil
  219. if vipLv and vipLv >= 0 then
  220. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  221. if vipCfg then
  222. vipIcon = vipCfg.SmallIcon
  223. end
  224. end
  225. local titleId = fromData.titleId
  226. local titleIcon = nil
  227. if titleId and titleId > 0 then
  228. local titleCfg = ManagerContainer.CfgMgr:GetDesignationCfgById(titleId)
  229. if titleCfg then
  230. titleIcon = titleCfg.ChatSource
  231. end
  232. end
  233. CommonUtil.LoadIcon(wnd, titleIcon, function (sprite)
  234. if sprite then
  235. item.titleImg.image.sprite = sprite
  236. item.titleImg.image.enabled = true
  237. end
  238. end, item)
  239. CommonUtil.LoadIcon(wnd, vipIcon, function (sprite)
  240. if sprite then
  241. item.vipIcon.image.sprite = sprite
  242. item.vipIcon.image.enabled = true
  243. end
  244. end, item, 'VipIcon')
  245. local msg = content.message
  246. if content.subType == Enum.ChatSubType.Expedition then
  247. local expedition = Enum.ChatSubType.Expedition..";"..fromData.uid
  248. local color = content.used and Constant.GrayColorSymbolText or Constant.DefaultColorSymbolText
  249. local color1 = content.used and Constant.GrayColorSymbolText or Constant.OrangeColorSymbolText
  250. msg = color..I18N.SetLanguageValue("ExpeditionHelp4", color1, "{"..expedition.."}")
  251. if item.text.symbolTextEvent then
  252. item.text.symbolText.raycastTarget = not content.used
  253. if not content.used then
  254. item.text.symbolTextEvent:RegisterClickEvent(nil, function (hyperParam)
  255. -- local curTime = ManagerContainer.LuaTimerMgr:GetTimeSecond()
  256. -- local isOneDay = ManagerContainer.LuaTimerMgr:TwoTimeSecondBetweenOneDay(content.sendTime, curTime)
  257. -- if not isOneDay then
  258. -- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeditionBailout")
  259. -- content.used = true
  260. -- return
  261. -- end
  262. local list = string.split(hyperParam, ";")
  263. local uid = ManagerContainer.DataMgr.UserData:GetUserId()
  264. if tostring(uid) == list[2] then
  265. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeditionHelpLog2")
  266. return
  267. end
  268. content.used = true
  269. local systemType = tonumber(list[1])
  270. if systemType == Enum.ChatSubType.Expedition then
  271. --远征求助
  272. local uid = int64.new(list[2])
  273. ManagerContainer.DataMgr.ExpeditionDataMgr:SendRescueFriendReq(uid, Enum.ExpeditionHelpSource.Guild, content.sendTime64)
  274. end
  275. end)
  276. end
  277. end
  278. end
  279. if logicData.type == Enum.ChatDataType.Guild then
  280. item.text.symbolText.text = string.formatbykey('GuildChatColor', StringUtil.FilterEmoji(msg))
  281. else
  282. item.text.symbolText.text = StringUtil.FilterEmoji(msg)
  283. end
  284. if onClickOwner and onClickCB then
  285. item.player.button.interactable = true
  286. wnd.uiBase:AddButtonUniqueEventListener(item.nameBg.button, onClickOwner, onClickCB, item.player, fromData)
  287. else
  288. item.player.button.interactable = true
  289. end
  290. end
  291. local parent = item.transform.parent
  292. if parent then
  293. local rectTrans = parent:GetComponent(Enum.TypeInfo.RectTransform)
  294. local width = rectTrans.rect.size.x
  295. item.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Horizontal, width);
  296. item.text.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Horizontal, width - 40);
  297. end
  298. item.text.contentSizeFitter:SetLayoutVertical()
  299. local size = item.text.rectTransform.sizeDelta
  300. item.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, 100);
  301. if size.y > 38 then
  302. local newY = item.rectTransform.sizeDelta.y + (size.y - 38)
  303. item.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, newY);
  304. end
  305. end
  306. return ChatTextItemCtr