UIPetAttributeView.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. local UIPetAttributeView = require("UICommonTips/UIPetAttributeView_Generate")
  2. local AttrFilterList
  3. function UIPetAttributeView:OnAwake(data)
  4. self.controller = require("UICommonTips/UIPetAttributeCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIPetAttributeView:AddEventListener()
  9. end
  10. function UIPetAttributeView: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 UIPetAttributeView:Init()
  21. if not AttrFilterList then
  22. local val = GlobalConfig.Instance:GetConfigStrValue(230)
  23. if val ~= "" and val ~= nil then
  24. AttrFilterList = CommonUtil.DeserializeGlobalStrToTable(val)
  25. end
  26. end
  27. self:Refresh()
  28. end
  29. function UIPetAttributeView:Refresh()
  30. local type = self.controller:GetType()
  31. local cfgId = self.controller:GetCfgId()
  32. local id = self.controller:GetId()
  33. local actorData, petData
  34. if not cfgId then
  35. actorData = self.controller:GetPetActorData()
  36. if not actorData then
  37. return
  38. end
  39. petData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(id)
  40. cfgId = petData.cfgId
  41. end
  42. local petCfgData = ManagerContainer.CfgMgr:GetPetDataById(cfgId)
  43. if not petCfgData then
  44. return
  45. end
  46. local multiply = petCfgData.ConversionRate*0.0001
  47. local baseList1 = self.controller:GetBaseAttrList()
  48. local addList1 = self.controller:GetAddAttrList()
  49. local baseList = {}
  50. local addList = {}
  51. if not baseList1 and not addList1 then
  52. local relationAttrs = {}
  53. if petData.heroId == 0 then
  54. relationAttrs = self.controller:GetRelationAddAttrs()
  55. end
  56. local list = {}
  57. for k,v in pairs(Enum.HeroAttrType) do
  58. list[#list + 1] = v
  59. end
  60. table.sort(list, function (a,b)
  61. return a < b
  62. end)
  63. for _,v in pairs(list) do
  64. if not CommonUtil.EleInTable(tostring(v), AttrFilterList) then
  65. if v >= Enum.HeroAttrType.Life and v <= Enum.HeroAttrType.CastAcceleration then
  66. local num = SDataUtil.Add(actorData:GetFinalAttr(v), (relationAttrs[v] or 0))
  67. num = SDataUtil.InvConvert(SDataUtil.Multiply(num, multiply))
  68. num = math.floor(num)
  69. if SDataUtil.IsGreater(num, 0) then
  70. baseList[#baseList + 1] = {v, num, 0}
  71. end
  72. else
  73. if v >= Enum.HeroAttrType.Nature_None_Damage_Percent then
  74. local num = SDataUtil.Add(actorData:GetFinalAttr(v), (relationAttrs[v] and relationAttrs[v]*0.0001 or 0))
  75. num = SDataUtil.InvConvert(SDataUtil.Multiply(num, multiply))
  76. --num = math.floor(num)
  77. if SDataUtil.IsGreater(num, 0) then
  78. addList[#addList + 1] = {v, num, 0}
  79. end
  80. end
  81. end
  82. end
  83. end
  84. else
  85. for _,v in pairs(baseList1) do
  86. if not CommonUtil.EleInTable(tostring(v[1]), AttrFilterList) then
  87. local num = v[2]
  88. num = SDataUtil.InvConvert(SDataUtil.Multiply(num, multiply))
  89. num = math.floor(num)
  90. if SDataUtil.IsGreater(num, 0) then
  91. baseList[#baseList + 1] = {v[1], num, 0}
  92. end
  93. end
  94. end
  95. for _,v in pairs(addList1) do
  96. if not CommonUtil.EleInTable(tostring(v[1]), AttrFilterList) then
  97. local num = v[2]
  98. num = SDataUtil.InvConvert(SDataUtil.Multiply(num, multiply))
  99. --num = math.floor(num)
  100. if SDataUtil.IsGreater(num, 0) then
  101. addList[#addList + 1] = {v[1], num, 0}
  102. end
  103. end
  104. end
  105. end
  106. CommonUtil.LoopGridViewEleCreate(self, self.baseSView.loopVerticalScrollRect, self.baseSView.content.gridLayoutGroup, baseList, 0, function (itemLua, idx)
  107. CommonUtil.UpdateItemPrefab(self, itemLua, baseList[idx + 1])
  108. end)
  109. CommonUtil.LoopGridViewEleCreate(self, self.addSView.loopVerticalScrollRect, self.addSView.content.gridLayoutGroup, addList, 0, function (itemLua, idx)
  110. CommonUtil.UpdateItemPrefab(self, itemLua, addList[idx + 1])
  111. end)
  112. self.addSView:SetActive(#addList > 0)
  113. self.none:SetActive(#addList == 0)
  114. end
  115. function UIPetAttributeView:RemoveEventListener()
  116. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  117. end
  118. function UIPetAttributeView:AddUIEventListener()
  119. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  120. self.uiBase:AddButtonEventListener(self.AnyBtn.button, self, self.OnCloseClick)
  121. end
  122. function UIPetAttributeView:OnCloseClick()
  123. self:UIClose()
  124. end
  125. function UIPetAttributeView:OnHide()
  126. end
  127. function UIPetAttributeView:OnShow(data)
  128. self.controller:SetData(data)
  129. end
  130. function UIPetAttributeView:OnClose()
  131. end
  132. function UIPetAttributeView:OnDispose()
  133. self.baseSView.loopVerticalScrollRect:ClearCells()
  134. self.addSView.loopVerticalScrollRect:ClearCells()
  135. self.controller:OnDispose()
  136. end
  137. return UIPetAttributeView