UIPetStampListView.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. local UIPetStampListView = require("UIPet/UIPetStampListView_Generate")
  2. local IconItemCtr = require("Common/IconItemCtr")
  3. local EquipListItemCtr = require("Common/EquipListItemCtr")
  4. function UIPetStampListView:OnAwake(data)
  5. self.controller = require("UIPet/UIPetStampListCtr"):new()
  6. self.controller:Init(self)
  7. self.controller:SetData(data)
  8. end
  9. function UIPetStampListView:AddEventListener()
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  11. end
  12. function UIPetStampListView:FillContent(data, uiBase)
  13. self.uiBase = uiBase
  14. local gameObject = self.uiBase:GetRoot()
  15. if gameObject ~= nil then
  16. self.gameObject = gameObject
  17. self.transform = gameObject.transform
  18. end
  19. self:InitGenerate(self.transform, data)
  20. self:Init()
  21. end
  22. function UIPetStampListView:Init()
  23. self:InitGrid()
  24. self:Refresh()
  25. end
  26. function UIPetStampListView:InitGrid()
  27. self.scrollView.loopListView:InitListView(0, function(gridView, itemIndex, row, column)
  28. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  29. end, nil)
  30. end
  31. function UIPetStampListView:Refresh()
  32. self:RefreshTop()
  33. end
  34. function UIPetStampListView:OnPageInEnd()
  35. self:RefreshStampList()
  36. self.super.OnPageInEnd(self)
  37. end
  38. function UIPetStampListView:RefreshTop()
  39. local equipedStampData = self.controller:GetStampData()
  40. self.equipBlank:SetActive(equipedStampData == nil)
  41. self.equipListEquippedItem:SetActive(equipedStampData ~= nil)
  42. if equipedStampData then
  43. IconItemCtr:SetData(self, self.iconItem, equipedStampData, Enum.ItemIEnterType.PetStamp)
  44. local cfgData = ManagerContainer.CfgMgr:GetPetEquipCfgDataById(equipedStampData.cfgId)
  45. if not cfgData then
  46. return
  47. end
  48. local stampLvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(equipedStampData.lv, equipedStampData.cfgId)
  49. if not stampLvCfgData then
  50. return
  51. end
  52. self.topItem.textName.uILocalizeScript:SetContent(cfgData.Name)
  53. local baseAttrs = clone(stampLvCfgData.Nature)
  54. table.sort(baseAttrs, function (a,b)
  55. return a[1] < b[1]
  56. end)
  57. local idx = 0
  58. for i = 1, #baseAttrs do
  59. idx = idx + 1
  60. CommonUtil.BatchCreateItemsLoopWithMould(self, self.equipBaseAttrItem, self.topItem.grid.transform, baseAttrs[i], i)
  61. end
  62. end
  63. end
  64. function UIPetStampListView:RefreshStampList()
  65. local stampList = self.controller:GetAllTypeStampDatas()
  66. local length = #stampList
  67. self.scrollView.loopListView:SetListItemCount(length, true)
  68. --self.scrollView.loopListView:RefreshAllShownItem()
  69. end
  70. function UIPetStampListView:GetItemByRowColumn(gridView, itemIndex, row, column)
  71. local showData = self.controller:GetShowDataByIdx(itemIndex)
  72. if not showData then
  73. return
  74. end
  75. local item = gridView:NewListViewItem("EquipListItem")
  76. local itemlua = CommonUtil.BindGridViewItem2Lua(self, "EquipListItem", item.gameObject)
  77. local equipLua = itemlua.iconItem
  78. IconItemCtr:SetData(self, equipLua, showData, Enum.ItemIEnterType.PetStamp)
  79. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(showData.cfgId)
  80. itemlua.textName.text.text = I18N.T(itemCfgData.Name)
  81. local stampLvCfgData = ManagerContainer.CfgMgr:GetPetEquipExpCfgDataByLvAndCfgId(showData.lv, showData.cfgId)
  82. if not stampLvCfgData then
  83. return
  84. end
  85. local baseAttrs = clone(stampLvCfgData.Nature)
  86. table.sort(baseAttrs, function (a,b)
  87. return a[1] < b[1]
  88. end)
  89. local idx = 0
  90. for i = 1, #baseAttrs do
  91. idx = idx + 1
  92. CommonUtil.BatchCreateItemsLoopWithMould(self, itemlua.equipBaseAttrItem, itemlua.grid.transform, baseAttrs[i], i)
  93. end
  94. itemlua.btnChange:SetActive(true)
  95. itemlua.btnDown:SetActive(false)
  96. self.uiBase:AddButtonUniqueEventListener(itemlua.btnChange.button, self, self.SendStampChange, showData.id)
  97. itemlua.contentSizeFitter:SetLayoutVertical()
  98. local minHeight = itemlua.layoutElement.minHeight
  99. if #baseAttrs > 2 then
  100. local addtional = #baseAttrs - 2
  101. itemlua.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, minHeight + addtional * 50);
  102. else
  103. itemlua.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, minHeight);
  104. end
  105. return item
  106. end
  107. function UIPetStampListView:RemoveEventListener()
  108. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  109. end
  110. function UIPetStampListView:AddUIEventListener()
  111. self.uiBase:AddButtonEventListener(self.btnClose.button, self, self.OnCloseClick)
  112. self.uiBase:AddButtonEventListener(self.AnyBtn.button, self, self.OnCloseClick)
  113. self.uiBase:AddButtonEventListener(self.btnDown.button, self, self.OnDownClick)
  114. end
  115. function UIPetStampListView:OnCloseClick()
  116. self:UIClose()
  117. end
  118. function UIPetStampListView:OnDownClick()
  119. self.controller:SendDownStamp()
  120. self:UIClose()
  121. end
  122. function UIPetStampListView:SendStampChange(button, params)
  123. local id = params[0]
  124. self.controller:SendChangeStamp(id)
  125. self:UIClose()
  126. end
  127. function UIPetStampListView:OnHide()
  128. end
  129. function UIPetStampListView:OnShow(data)
  130. self.controller:SetData(data)
  131. end
  132. function UIPetStampListView:OnClose()
  133. self.scrollView.loopListView:Dispose()
  134. end
  135. function UIPetStampListView:OnDispose()
  136. self.controller:OnDispose()
  137. end
  138. return UIPetStampListView