ChatTextItemCtr.lua 18 KB

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