KLUIChatSmallItem.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ---@class KLUIChatSmallItem:UIKmlLuaPanelBase
  2. ---@field view KLUIChatSmallItemView
  3. local KLUIChatSmallItem = class(UIKmlLuaPanelBase)
  4. local this = KLUIChatSmallItem
  5. ---创建时调用一次
  6. function this:Init()
  7. end
  8. ---创建或者刷新界面数据时调用
  9. function this:Refresh()
  10. end
  11. function this:RefreshItem(data)
  12. self.message = data.message
  13. self.itemIndex = data.itemIndex
  14. local is_me = false
  15. if self.message.senderId == SL:GetMetaValue(EMetaVarGetKey.UID) then
  16. is_me = true
  17. end
  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 channel = self.message.channel
  29. if channel == EChatChannelType.PERSONAL then
  30. local isFriend = false
  31. if is_me then
  32. isFriend = SL:CheckIsFriend(self.message.receiverId)
  33. else
  34. isFriend = SL:CheckIsFriend(self.message.senderId)
  35. end
  36. if isFriend then
  37. channel = EChatChannelType.FRIEND
  38. end
  39. end
  40. local typeStr = SL:ChatInfo_GetChatTypeStr(channel)
  41. local typeTitleStr = self:GetTypeTitle(typeStr,channel)
  42. local sendName
  43. if channel == EChatChannelType.SYSTEM then
  44. sendName = ""
  45. elseif is_union_system then
  46. sendName = ""
  47. else
  48. sendName = self.message.sendName
  49. end
  50. local str = typeTitleStr .. sendName ..":" ..self.message.message
  51. if not self.message.chatiteminfo and self.message.itemList and #self.message.itemList >0 then
  52. local chatiteminfo = ""
  53. for i, v in ipairs(self.message.itemList) do
  54. local item = SL:GetConfig("cfg_item", v.cfgId)
  55. local name_color = "#d2d2d2"
  56. if item.type == EItemType.Equip then
  57. local grade = SL:GetEquipValue(EMetaVarGetKey.EQUIP_GRADE, "", v.cfgId)
  58. --不读品质了,全部走配置
  59. local colorid = SL:GetConfig('cfg_item', v.cfgId).color
  60. name_color = SL:GetConfig('cfg_color', colorid).color
  61. else
  62. local colorid = SL:GetConfig('cfg_item', v.cfgId).color
  63. name_color = SL:GetConfig('cfg_color', colorid).color
  64. end
  65. local oneStr = ""
  66. if i ~= 1 then
  67. oneStr = "|"
  68. end
  69. oneStr = oneStr .. v.id .. "*" .. v.cfgId .. "*" .. name_color
  70. chatiteminfo = chatiteminfo .. oneStr
  71. SL:ChatInfo_AddChaItemInfo(v)
  72. end
  73. self.message.chatiteminfo = chatiteminfo
  74. end
  75. GUI:RichText_setchatiteminfo(self.view.richSmall,self.message.chatiteminfo)
  76. if not str then
  77. str = ""
  78. end
  79. GUI:Text_setString(self.view.richSmall,str)
  80. if self.message and self.message.itemSizeSmall then
  81. GUI:setContentSize(self.view.samll_one_bg, 360,self.message.itemSizeSmall.y+10)
  82. end
  83. end
  84. ---注册UI事件和服务器消息
  85. function this:RegistEvents()
  86. --GUI:AddOnClickEvent(self.view.button_id,self,self.BtnOnClick)
  87. GUI:AddOnClickEvent(self.view.root, self, self.OpenChatPanel)
  88. end
  89. function this:OpenChatPanel()
  90. SL:OpenChatUI()
  91. end
  92. function this:Close()
  93. end
  94. function this:GetTypeTitle(typeStr,channel)
  95. if channel == EChatChannelType.SYSTEM then
  96. return "<color=#4cc5feff>[".. typeStr.."]</color>"
  97. elseif channel == EChatChannelType.WORLD then
  98. return "<color=#B3C5E3>[".. typeStr.."]</color>"
  99. elseif channel == EChatChannelType.NEARBY then
  100. return "<color=#00ff00ff>[".. typeStr.."]</color>"
  101. elseif channel == EChatChannelType.UNION then
  102. return "<color=#ffc000ff>[".. typeStr.."]</color>"
  103. elseif channel == EChatChannelType.TEAM then
  104. return "<color=#d916d9ff>[".. typeStr.."]</color>"
  105. elseif channel == EChatChannelType.FRIEND then
  106. return "<color=#4cc5feff>[".. typeStr.."]</color>"
  107. elseif channel == EChatChannelType.PERSONAL then
  108. return "<color=#28e529ff>[".. typeStr.."]</color>"
  109. elseif channel == EChatChannelType.RECRUIT then
  110. return "[".. typeStr.."]"
  111. end
  112. return "[".. typeStr.."]"
  113. end
  114. return this