KLUIChatItem.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. ---@class KLUIChatItem:UIKmlLuaPanelBase
  2. ---@field view KLUIChatItemView
  3. local KLUIChatItem = class(UIKmlLuaPanelBase)
  4. local this = KLUIChatItem
  5. ---创建时调用一次
  6. function this:Init()
  7. end
  8. ---创建或者刷新界面数据时调用
  9. function this:Refresh()
  10. end
  11. function this:RefreshItem(data)
  12. if not SL:MeData_Check() then
  13. return
  14. end
  15. self.message = data.message
  16. self.itemIndex = data.itemIndex
  17. --self.data.sendName
  18. local is_union_system = false
  19. if self.message.channel == EChatChannelType.UNION and (not self.message.senderId or self.message.senderId == 0) then
  20. is_union_system = true
  21. end
  22. if not self.message.career then
  23. self.message.career = 0
  24. end
  25. if not self.message.sendName then
  26. self.message.sendName = ""
  27. end
  28. local is_me = false
  29. if self.message.senderId == SL:GetMetaValue(EMetaVarGetKey.UID) then
  30. is_me = true
  31. end
  32. local career = self.message.career
  33. local careerStr
  34. local channel = self.message.channel
  35. if channel == EChatChannelType.PERSONAL then
  36. local isFriend = false
  37. if is_me then
  38. isFriend = SL:CheckIsFriend(self.message.receiverId)
  39. else
  40. isFriend = SL:CheckIsFriend(self.message.senderId)
  41. end
  42. if isFriend then
  43. channel = EChatChannelType.FRIEND
  44. end
  45. end
  46. local typeStr = SL:ChatInfo_GetChatTypeStr(channel)
  47. local typeTitleStr = self:GetTypeTitle(typeStr,channel)
  48. local str = typeTitleStr
  49. if channel ~= EChatChannelType.SYSTEM and not is_union_system then
  50. local career = self.message.career
  51. careerStr = "1"..career
  52. str = typeTitleStr.. self.message.sendName
  53. end
  54. if is_me and channel ~= EChatChannelType.SYSTEM then
  55. GUI:setAnchorPoint(self.view.icon_root,2,1)
  56. GUI:setAnchorPoint(self.view.name,2,1)
  57. GUI:setAnchorPoint(self.view.qipao,2,1)
  58. GUI:setPositionX(self.view.name,-75)
  59. GUI:setPositionX(self.view.qipao,-70)
  60. GUI:Image_loadTexture(self.view.qipao,"img_chat_pao2","Atlas/KLChatPanel.spriteatlas")
  61. GUI:setAnchorPoint(self.view.richT,2,0)
  62. GUI:setPositionX(self.view.richT,-13)
  63. else
  64. GUI:setAnchorPoint(self.view.icon_root,1,1)
  65. GUI:setAnchorPoint(self.view.name,1,1)
  66. GUI:setAnchorPoint(self.view.qipao,1,1)
  67. GUI:setPositionX(self.view.name,75)
  68. GUI:setPositionX(self.view.qipao,70)
  69. GUI:Image_loadTexture(self.view.qipao,"img_chat_pao","Atlas/KLChatPanel.spriteatlas")
  70. GUI:setAnchorPoint(self.view.richT,1,0)
  71. GUI:setPositionX(self.view.richT,13)
  72. end
  73. GUI:Text_setString(self.view.name,str)
  74. if channel == EChatChannelType.SYSTEM or is_union_system then
  75. GUI:setVisible(self.view.icon_root,false)
  76. GUI:setPositionX(self.view.name,10)
  77. GUI:setPositionX(self.view.qipao,12)
  78. else
  79. GUI:Image_loadTexture(self.view.icon,careerStr,"Atlas/MUIcon.spriteatlas")
  80. GUI:setVisible(self.view.icon_root,true)
  81. end
  82. if not self.message.chatiteminfo and self.message.itemList and #self.message.itemList >0 then
  83. local chatiteminfo = ""
  84. for i, v in ipairs(self.message.itemList) do
  85. local item = SL:GetConfig("cfg_item", v.cfgId)
  86. local name_color = "#d2d2d2"
  87. if item.type == EItemType.Equip then
  88. -- local grade = SL:GetEquipValue(EMetaVarGetKey.EQUIP_GRADE, "", v.cfgId)
  89. -- local colorid = SL:GetConfigMultiKeys('cfg_equip_quality', grade, 'id').nameColor
  90. -- name_color = SL:GetConfigMultiKeys('cfg_color', colorid, 'id').color
  91. --不读品质了,全部走配置
  92. local colorid = SL:GetConfig('cfg_item', v.cfgId).color
  93. name_color = SL:GetConfig('cfg_color', colorid).color
  94. else
  95. local colorid = SL:GetConfig('cfg_item', v.cfgId).color
  96. name_color = SL:GetConfig('cfg_color', colorid).color
  97. end
  98. local oneStr = ""
  99. if i ~= 1 then
  100. oneStr = "|"
  101. end
  102. oneStr = oneStr .. v.id .. "*" .. v.cfgId .. "*" .. name_color
  103. chatiteminfo = chatiteminfo .. oneStr
  104. SL:ChatInfo_AddChaItemInfo(v)
  105. end
  106. self.message.chatiteminfo = chatiteminfo
  107. end
  108. -- SL:LogError(self.message.message)
  109. -- SL:LogTable(self.message.chatiteminfo)
  110. GUI:RichText_setchatiteminfo(self.view.richT,self.message.chatiteminfo)
  111. GUI:Text_setString(self.view.richT,self.message.message)
  112. local playerid = ""
  113. if self.message.senderId and self.message.senderId~=0 then
  114. playerid = tostring(self.message.senderId)
  115. end
  116. GUI:RichText_setchatplayerid(self.view.richT,playerid)
  117. end
  118. ---注册UI事件和服务器消息
  119. function this:RegistEvents()
  120. GUI:AddOnClickEvent(self.view.icon,self,self.OnclickIcon)
  121. end
  122. function this:GetTypeTitle(typeStr,channel)
  123. if channel == EChatChannelType.SYSTEM then
  124. return "<color=#4cc5feff>[".. typeStr.."]</color>"
  125. elseif channel == EChatChannelType.WORLD then
  126. return "<color=#B3C5E3>[".. typeStr.."]</color>"
  127. elseif channel == EChatChannelType.NEARBY then
  128. return "<color=#00ff00ff>[".. typeStr.."]</color>"
  129. elseif channel == EChatChannelType.UNION then
  130. return "<color=#ffc000ff>[".. typeStr.."]</color>"
  131. elseif channel == EChatChannelType.TEAM then
  132. return "<color=#d916d9ff>[".. typeStr.."]</color>"
  133. elseif channel == EChatChannelType.FRIEND then
  134. return "<color=#4cc5feff>[".. typeStr.."]</color>"
  135. elseif channel == EChatChannelType.PERSONAL then
  136. return "<color=#28e529ff>[".. typeStr.."]</color>"
  137. elseif channel == EChatChannelType.RECRUIT then
  138. return "[".. typeStr.."]"
  139. end
  140. return "[".. typeStr.."]"
  141. end
  142. function this:OnclickIcon()
  143. local id = self.message.senderId
  144. if id == SL:GetMetaValue(EMetaVarGetKey.UID) then
  145. return
  146. end
  147. local _x,_y,_z = GUI:GetWorldPosition(self.view.icon_root)
  148. _x = math.floor(_x * 100) / 100
  149. _y = math.floor(_y * 100) / 100
  150. _z = math.floor(_z * 100) / 100
  151. if _y < 359.1 then
  152. _y = 359.1
  153. end
  154. GUI:UIPanel_Open("dev/ui/FriendSys/Panel/KLFriendOperate/KLFriendOperatePanel", _, _, {rid = id,pos={x=_x+4.9,y=_y-2.3,z=_z},name = self.message.sendName,isHideMainUI=true})
  155. end
  156. function this:Close()
  157. end
  158. return this