PrivateChatItemCtr.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. local PrivateChatItem = {}
  2. local regexPattern = "%[e%d+%]"
  3. local function GetEmojiCfg(num)
  4. local s = tostring(num + 1)
  5. local emojis = ManagerContainer.CfgMgr:GetEmojiCfg()
  6. local result
  7. for k,v in pairs(emojis) do
  8. local find = string.find(s, tostring(k))
  9. if find == 1 then
  10. result = v
  11. end
  12. end
  13. return result
  14. end
  15. function PrivateChatItem:SetData(wnd, item, logicData)
  16. local chat = logicData[2]
  17. local lastChat = logicData[1]
  18. local fromData = chat.fromData
  19. local userUid = ManagerContainer.DataMgr.UserData:GetUserId()
  20. local isLeft = fromData.uid ~= tostring(userUid)
  21. item.chatBubbleLftItem:SetActive(isLeft)
  22. item.chatBubbleRgtItem:SetActive(not isLeft)
  23. if isLeft then
  24. item.chatBubbleLftItem.bg:SetActive(chat.message.subType == Enum.ChatSubType.None)
  25. item.chatBubbleLftItem.helpBg:SetActive(chat.message.subType == Enum.ChatSubType.Expedition)
  26. else
  27. item.chatBubbleRgtItem.bg:SetActive(chat.message.subType == Enum.ChatSubType.None)
  28. item.chatBubbleRgtItem.helpBg:SetActive(chat.message.subType == Enum.ChatSubType.Expedition)
  29. end
  30. local chatItem = isLeft and item.chatBubbleLftItem or item.chatBubbleRgtItem
  31. local height = 0
  32. local timeOut = false
  33. if lastChat ~= nil then
  34. local lastTime = lastChat.message.sendTime
  35. local nowTime = chat.message.sendTime
  36. local seconds = nowTime - lastTime
  37. local mtTenM = seconds/ManagerContainer.LuaTimerMgr.OneMinuteSeconds >= 10
  38. if mtTenM then
  39. seconds = ManagerContainer.LuaTimerMgr:GetTimeSecond() - nowTime
  40. local days = seconds/ManagerContainer.LuaTimerMgr.OneDaySeconds
  41. if days < 1 then
  42. local str = ManagerContainer.LuaTimerMgr:ParseTimeStamp2Format(nowTime, "%H:%M")
  43. item.chatTimeStampItem.text.text.text = str
  44. elseif days < 2 then
  45. item.chatTimeStampItem.text.text.text = I18N.T("PrivateChatDate1")
  46. elseif days < 3 then
  47. item.chatTimeStampItem.text.text.text = I18N.T("PrivateChatDate2")
  48. else
  49. item.chatTimeStampItem.text.text.text = I18N.T("PrivateChatDate3")
  50. end
  51. end
  52. item.chatTimeStampItem:SetActive(mtTenM)
  53. if mtTenM then
  54. height = item.chatTimeStampItem.rectTransform.sizeDelta.y
  55. timeOut = true
  56. end
  57. else
  58. item.chatTimeStampItem:SetActive(false)
  59. end
  60. --chatItem.text.rectTransform.sizeDelta = Vector2(0,10)
  61. if chat.message.subType == Enum.ChatSubType.None then
  62. local content = StringUtil.FilterEmoji(chat.message.message)
  63. chatItem.text.symbolText.text = content
  64. local length = StringUtil.GetTextLeng(chatItem.text.symbolText, content) + 10
  65. local emojis = ManagerContainer.CfgMgr:GetEmojiCfg()
  66. for k, v in string.gmatch(content, regexPattern) do
  67. local num = tonumber(string.match(k, '%d+'))
  68. if num < #emojis then
  69. length = length + 41
  70. end
  71. end
  72. length = math.min(length, 606)
  73. --local height = math.floor(length/606) + 1
  74. --textHeight = textHeight + height*39
  75. chatItem.text.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Horizontal, length);
  76. --chatItem.text.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, textHeight);
  77. chatItem.text.contentSizeFitter:SetLayoutVertical()
  78. local textHeight = chatItem.text.rectTransform.sizeDelta.y
  79. local bgWidth = length + 48
  80. local bgHeight = textHeight + 24 + 10
  81. chatItem.bg.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Horizontal, bgWidth);
  82. chatItem.bg.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, bgHeight);
  83. chatItem.rectTransform.anchoredPosition3D = Vector3.zero
  84. if timeOut then
  85. local rectPosition = chatItem.rectTransform.anchoredPosition3D
  86. chatItem.rectTransform.anchoredPosition3D = Vector3(rectPosition.x, -height, rectPosition.z)
  87. end
  88. height = height + bgHeight
  89. item.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, height);
  90. elseif chat.message.subType == Enum.ChatSubType.Expedition then
  91. local color = chat.message.used and Constant.GrayColorSymbolText or Constant.DefaultColorSymbolText
  92. chatItem.helpText.symbolText.text = color..I18N.SetLanguageValue("ExpeditionHelp1", fromData.nickname)
  93. if chatItem.helpText1.symbolTextEvent then
  94. local content = Enum.ChatSubType.Expedition..";"..fromData.uid
  95. local color = chat.message.used and Constant.GrayColorSymbolText or Constant.RedColorSymbolText
  96. chatItem.helpText1.symbolText.text = color..I18N.SetLanguageValue("ExpeditionHelp2", "{"..content.."}")
  97. chatItem.helpText1.symbolText.raycastTarget = not chat.message.used
  98. if not chat.message.used then
  99. chatItem.helpText1.symbolTextEvent:RegisterClickEvent(nil, function (hyperParam)
  100. local curTime = ManagerContainer.LuaTimerMgr:GetTimeSecond()
  101. local isOneDay = ManagerContainer.LuaTimerMgr:TwoTimeSecondBetweenOneDay(chat.message.sendTime, curTime)
  102. if not isOneDay then
  103. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeditionBailout")
  104. chat.message.used = true
  105. return
  106. end
  107. local list = string.split(hyperParam, ";")
  108. local uid = ManagerContainer.DataMgr.UserData:GetUserId()
  109. if tostring(uid) == list[2] then
  110. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeditionHelpLog2")
  111. return
  112. end
  113. chat.message.used = true
  114. local systemType = tonumber(list[1])
  115. if systemType == Enum.ChatSubType.Expedition then
  116. --远征求助
  117. local uid = int64.new(list[2])
  118. ManagerContainer.DataMgr.ExpeditionDataMgr:SendRescueFriendReq(uid, Enum.ExpeditionHelpSource.Private, chat.message.sendTime64)
  119. end
  120. end)
  121. end
  122. end
  123. height = height + chatItem.helpBg.rectTransform.sizeDelta.y
  124. item.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, height);
  125. end
  126. end
  127. return PrivateChatItem