UIRoleInfoPopView.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. local UIRoleInfoPopView = require("UIRoleMain/UIRoleInfoPopView_Generate")
  2. function UIRoleInfoPopView:OnAwake(data)
  3. self.controller = require("UIRoleMain/UIRoleInfoPopCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UIRoleInfoPopView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  9. end
  10. function UIRoleInfoPopView:FillContent(data, uiBase)
  11. self.uiBase = uiBase
  12. local gameObject = self.uiBase:GetRoot()
  13. if gameObject ~= nil then
  14. self.gameObject = gameObject
  15. self.transform = gameObject.transform
  16. end
  17. self:InitGenerate(self.transform, data)
  18. self:Init()
  19. end
  20. function UIRoleInfoPopView:Init()
  21. self.controller:InitData()
  22. self.scrollView.loopListView:InitListView(0, function(loopListView, idx)
  23. return self:GetItemByIndex(loopListView, idx)
  24. end)
  25. self:RefreshView(true)
  26. self.scrollView.loopListView.ScrollRect.enabled = false
  27. end
  28. function UIRoleInfoPopView:RemoveEventListener()
  29. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  30. end
  31. function UIRoleInfoPopView:AddUIEventListener()
  32. self.uiBase:AddButtonEventListener(self.btnClose.button, self, self.OnClickCancelBtn)
  33. self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnClickCancelBtn)
  34. end
  35. function UIRoleInfoPopView:OnHide()
  36. end
  37. function UIRoleInfoPopView:OnShow(data)
  38. if data then
  39. self.controller:SetData(data)
  40. self.controller:InitData()
  41. self:RefreshView(true)
  42. end
  43. end
  44. function UIRoleInfoPopView:OnClose()
  45. end
  46. function UIRoleInfoPopView:OnDispose()
  47. self.scrollView.loopListView:Dispose()
  48. self.controller:OnDispose()
  49. end
  50. function UIRoleInfoPopView:OnPageInEnd()
  51. self.super.OnPageInEnd(self)
  52. self.scrollView.loopListView.ScrollRect.enabled = true
  53. end
  54. function UIRoleInfoPopView:OnClickCancelBtn()
  55. self:UIClose()
  56. end
  57. function UIRoleInfoPopView:RefreshView(resetPos)
  58. self.textTitle.text.text = string.formatbykey(self.controller:GetTitleName())
  59. self.scrollView.loopListView:SetListItemCount(self.controller:GetDataLength(), resetPos or false)
  60. self.scrollView.loopListView:RefreshAllShownItem()
  61. end
  62. function UIRoleInfoPopView:GetItemByIndex(loopListView, idx)
  63. local data = self.controller:GetDataByIdx(idx + 1)
  64. if not data then return nil end
  65. local title = data[2]
  66. local des = data[3]
  67. if not title or not des then
  68. return nil
  69. end
  70. local iconName = data[4]
  71. local item = loopListView:NewListViewItem('InfoDscItem')
  72. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'InfoDscItem', item.gameObject)
  73. if itemLua then
  74. itemLua.textName.text.text = string.formatbykey(title)
  75. itemLua.textDsc.text.text = string.formatbykey(des)
  76. if iconName and iconName ~= '' then
  77. itemLua.icon:SetActive(true)
  78. itemLua.icon.image.sprite = nil
  79. itemLua.icon.image.enabled = false
  80. CommonUtil.LoadIcon(self, iconName, function(sprite)
  81. if sprite then
  82. itemLua.icon.image.sprite = sprite
  83. itemLua.icon.image.enabled = true
  84. end
  85. end)
  86. else
  87. itemLua.icon:SetActive(false)
  88. end
  89. end
  90. ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform)
  91. return item
  92. end
  93. return UIRoleInfoPopView