KLUIChatView.lua 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ---@class KLUIChatView:UIKmlLuaPanelBase
  2. ---@field view KLUIChatViewView
  3. local KLUIChatView = class(UIKmlLuaPanelBase)
  4. local this = KLUIChatView
  5. ---创建时调用一次
  6. function this:Init()
  7. --GUI:Button_setTitleText(self.view.button_id,self.args.nameStr)
  8. if self.args.width and self.args.height then
  9. GUI:setContentSize(self.view.root,self.args.width,self.args.height)
  10. GUI:setContentSize(self.view.chat_view,self.args.width,self.args.height)
  11. --GUI:setContentSize(self.view.all_list_layout,self.args.width,self.args.height)
  12. end
  13. if self.args.x and self.args.y then
  14. GUI:setPositionX(self.view.root,self.args.x)
  15. GUI:setPositionY(self.view.root,self.args.y)
  16. end
  17. GUI:UIPanel_Open("dev/ui/Chat/Item/KLUIChatItem/KLUIChatItem",self.view.root,self,{},true,function (item)
  18. self.calculationUI = item
  19. GUI:setPositionX(self.calculationUI.view.root,2000)
  20. GUI:setPositionY(self.calculationUI.view.root,2000)
  21. end)
  22. GUI:DataListInitData(self.view.chat_data_list,function()
  23. return self:ChatDataListItemCountFunc()
  24. end,function(realIndex)
  25. return self:ChatDataListItemGetFunc(realIndex)
  26. end,function(realIndex, kmlcontrol)
  27. return self:ChatDataListItemInitFunc(realIndex, kmlcontrol)
  28. end, function(realIndex, kmlcontrol)
  29. return self:ChatDataListItemUpdateFunc(realIndex, kmlcontrol)
  30. end, function(realIndex, kmlcontrol)
  31. return self:ChatDataItemSizeGetFunc(realIndex, kmlcontrol)
  32. end)
  33. self.chat_all_item = {}
  34. end
  35. ---创建或者刷新界面数据时调用
  36. function this:Refresh()
  37. end
  38. function this:RefreshData(chat_list)
  39. self.chat_list = chat_list
  40. GUI:DataListUpdateData(self.view.chat_data_list)
  41. GUI:SetScrollView_scrollpos(self.view.chat_view,#self.chat_list-1)
  42. end
  43. ---注册UI事件和服务器消息
  44. function this:RegistEvents()
  45. --GUI:AddOnClickEvent(self.view.button_id,self,self.BtnOnClick)
  46. end
  47. function this:ChatDataListItemCountFunc()
  48. return #self.chat_list
  49. end
  50. function this:ChatDataListItemGetFunc(realIndex)
  51. local item = GUI:UIPanel_Open("dev/ui/Chat/Item/KLUIChatItem/KLUIChatItem",self.view.chat_data_list,self,{},true)
  52. self.chat_all_item[item.view.root] = item
  53. return item.view.root
  54. end
  55. function this:ChatDataListItemInitFunc(realIndex, kmlcontrol)
  56. end
  57. function this:ChatDataListItemUpdateFunc(realIndex, kmlcontrol)
  58. local data = self.chat_list[realIndex + 1]
  59. local mess = {message=data,itemIndex=realIndex + 1}
  60. self.chat_all_item[kmlcontrol]:RefreshItem(mess)
  61. end
  62. function this:ChatDataItemSizeGetFunc(realIndex)
  63. local data = self.chat_list[realIndex + 1]
  64. if not data.itemSize then
  65. local mess = {message=data,itemIndex=realIndex + 1}
  66. self.calculationUI:RefreshItem(mess)
  67. local xx,yy = GUI:getSizeDelta(self.calculationUI.view.root)
  68. data.itemSize = Vector2(xx, yy)
  69. end
  70. return data.itemSize
  71. end
  72. function this:Close()
  73. end
  74. return this