UIPetContractTipsCtr.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. local UIPetContractTipsCtr = class("UIPetContractTipsCtr", require("UICtrBase"))
  2. local PetMatsGridView = require("UIPet/PetMatsGridView")
  3. local RectOffset = UnityEngine.RectOffset
  4. function UIPetContractTipsCtr:Init(view)
  5. self.view = view
  6. end
  7. function UIPetContractTipsCtr:SetData(data)
  8. self.asyncIdx = 0
  9. if data == nil then return end
  10. self.data = data
  11. local petData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(self:GetSelectedPetId())
  12. self:SetSelectedData(petData)
  13. end
  14. function UIPetContractTipsCtr:GetAsyncIdx()
  15. self.asyncIdx = self.asyncIdx + 1
  16. return self.asyncIdx
  17. end
  18. function UIPetContractTipsCtr:GetData()
  19. return self.data
  20. end
  21. function UIPetContractTipsCtr:GetHeroId()
  22. return self.data[1]
  23. end
  24. function UIPetContractTipsCtr:GetSlotIdx()
  25. return self.data[2]
  26. end
  27. function UIPetContractTipsCtr:GetSelectedPetId()
  28. return self.data[3]
  29. end
  30. function UIPetContractTipsCtr:GetQiyuePetId()
  31. return self.data[4]
  32. end
  33. function UIPetContractTipsCtr:SetChildController(ctr)
  34. self.childCtr = ctr
  35. end
  36. function UIPetContractTipsCtr:SetSelectedData(data)
  37. local lastData = self.selectedData
  38. if self.selectedData == data then
  39. if data then
  40. data.selected = 0
  41. end
  42. self.selectedData = nil
  43. else
  44. self.selectedData = data
  45. if data then
  46. data.selected = 1
  47. end
  48. end
  49. if lastData then
  50. lastData.selected = 0
  51. end
  52. return lastData
  53. end
  54. function UIPetContractTipsCtr:GetSelectedData()
  55. return self.selectedData
  56. end
  57. function UIPetContractTipsCtr:RefreshPetDatas()
  58. local petDatasSource = ManagerContainer.DataMgr.PetDataMgr:GetPetDatas()
  59. --策划要求战力加入排序
  60. for _,v in pairs(petDatasSource) do
  61. v.totalFightPower = ManagerContainer.DataMgr.PetDataMgr:GetTotalFightPower(v.id)
  62. end
  63. local petDatas
  64. petDatas = CommonUtil.ArrayFilterSelections(petDatasSource, Enum.FilterType.AND, {"isBattle"}, {false})
  65. if petDatas ~= nil then
  66. if self.selectedData then
  67. self.selectedData.selected = 1
  68. end
  69. --CommonUtil.ArraySortSelections(petDatas, Enum.TableSortRule.Down, "isBattle", "isRelevant", "isSupport", "quality", "totalFightPower", "cfgId", "id")
  70. CommonUtil.ArraySortListSelections(petDatas, {Enum.TableSortRule.Up, Enum.TableSortRule.Down, Enum.TableSortRule.Down, Enum.TableSortRule.Down}, {"qiyueHeroId", "quality", "totalSkillUpCount", "level"})
  71. end
  72. if petDatas == nil then
  73. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("NoCardTips3")
  74. end
  75. return petDatas
  76. end
  77. function UIPetContractTipsCtr:SendSlotChangeReq(petId)
  78. local heroId = self:GetHeroId()
  79. local idx = self:GetSlotIdx()
  80. if self.selectedData then
  81. if self.selectedData.id ~= self:GetSelectedPetId() then
  82. ManagerContainer.DataMgr.PetDataMgr:SendQiyueSlotInReq(heroId, idx, self.selectedData.id)
  83. end
  84. else
  85. ManagerContainer.DataMgr.PetDataMgr:SendQiyueSlotOutReq(heroId, idx)
  86. end
  87. end
  88. function UIPetContractTipsCtr:GetPetDataIdxInShowDatas(id)
  89. if self.childCtr then
  90. return self.childCtr:GetPetDataById(id)
  91. end
  92. return nil
  93. end
  94. function UIPetContractTipsCtr:OnDispose()
  95. self.selectedData = nil
  96. self.childCtr = nil
  97. self.data = nil
  98. self.view = nil
  99. end
  100. return UIPetContractTipsCtr