UIPetRootCtr.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. local UIPetRootCtr = class("UIPetRootCtr", require("UICtrBase"))
  2. local qiyueSlotUnlockCost
  3. local lockIds = {42,43,44,45,46,47}
  4. function UIPetRootCtr:Init(view)
  5. self.view = view
  6. end
  7. function UIPetRootCtr:SetData(data)
  8. if self.filterData == nil then
  9. self.filterData = {}
  10. self.filterData.raritySelections = {}
  11. self.filterData.attrSelections = {}
  12. self.filterData.typeSelections = {}
  13. self.isFilter = false
  14. end
  15. local val = GlobalConfig.Instance:GetConfigStrValue(350)
  16. if val ~= "" and val ~= nil then
  17. qiyueSlotUnlockCost = CommonUtil.DeserializeGlobalStrToTable(val)
  18. end
  19. self:RefreshCurPetBattleLock()
  20. self.asyncIdx = 0
  21. if data == nil then return end
  22. self.data = data
  23. end
  24. function UIPetRootCtr:GetShowDataRealLength()
  25. return self.showDatas and #self.showDatas or 0
  26. end
  27. function UIPetRootCtr:GetShowData(itemIndex)
  28. return self.showDatas and self.showDatas[itemIndex + 1] or nil
  29. end
  30. function UIPetRootCtr:RefreshCurPetBattleLock()
  31. self.unlockCount = 0
  32. for i = 1,#lockIds do
  33. local unLockState, val, content = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(lockIds[i])
  34. if unLockState then
  35. self.unlockCount = self.unlockCount + 1
  36. else
  37. self.curLockContent = content
  38. break
  39. end
  40. end
  41. end
  42. function UIPetRootCtr:GetPetBattleUnlockCount()
  43. return self.unlockCount
  44. end
  45. function UIPetRootCtr:CalcUnlockSlot(slotList)
  46. local state = false
  47. local idx = #slotList + 1
  48. local cost = qiyueSlotUnlockCost[idx]
  49. if not cost then
  50. return false
  51. end
  52. local costId = tonumber(cost[1])
  53. local costNum = tonumber(cost[2])
  54. local count = CommonUtil.GetOwnResCountByItemId(costId)
  55. return count >= costNum, idx, costId, count, costNum
  56. end
  57. function UIPetRootCtr:RefreshQiyueDatas()
  58. self:HasEnoughPet()
  59. if self.showDatas then return end
  60. self.showDatas = {}
  61. for i = 1, 6 do
  62. local data = CommonUtil.GetHeroLogicDataByUid(i)
  63. self.showDatas[#self.showDatas + 1] = data
  64. end
  65. CommonUtil.ArraySortSelections(self.showDatas, {Enum.TableSortRule.Up, Enum.TableSortRule.Down, Enum.TableSortRule.Down}, "id", "isBattle", "owned")
  66. end
  67. function UIPetRootCtr:RefreshPetDatas()
  68. local petDatasSource = ManagerContainer.DataMgr.PetDataMgr:GetPetDatas()
  69. --策划要求战力加入排序
  70. for _,v in pairs(petDatasSource) do
  71. v.totalFightPower = ManagerContainer.DataMgr.PetDataMgr:GetTotalFightPower(v.id)
  72. end
  73. local petDatas
  74. petDatas = CommonUtil.ArrayFilterSelections(petDatasSource, Enum.FilterType.AND, {"quality", "Attribute", "natureType"}, {self.filterData.raritySelections, self.filterData.attrSelections, self.filterData.typeSelections})
  75. if petDatas ~= nil then
  76. CommonUtil.ArraySortSelections(petDatas, Enum.TableSortRule.Down, "isBattle", "isRelevant", "isSupport", "quality", "level", "totalFightPower", "cfgId", "id")
  77. end
  78. if petDatas == nil then
  79. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("NoCardTips3")
  80. end
  81. return petDatas
  82. end
  83. function UIPetRootCtr:SetFilterData(data, isFilter)
  84. self.filterData = data
  85. self.isFilter = isFilter
  86. end
  87. function UIPetRootCtr:GetFilterData()
  88. return self.filterData
  89. end
  90. function UIPetRootCtr:GetIsFilter()
  91. return self.isFilter
  92. end
  93. function UIPetRootCtr:HasEnoughPet()
  94. self.hasFreePet = false
  95. local petDatas = ManagerContainer.DataMgr.PetDataMgr:GetPetDatas()
  96. for i = 1, #petDatas do
  97. if not petDatas[i].isBattle and petDatas[i].qiyueHeroId == 0 then
  98. self.hasFreePet = true
  99. return
  100. end
  101. end
  102. end
  103. function UIPetRootCtr:HeroRemoveAllQiyueSlot(heroId)
  104. ManagerContainer.DataMgr.PetDataMgr:SendQiyueSlotOutReq(heroId, 0)
  105. end
  106. function UIPetRootCtr:SendQiyueUnlockReq(heroId)
  107. ManagerContainer.DataMgr.PetDataMgr:SendQiyueUnlockReq(heroId)
  108. end
  109. function UIPetRootCtr:CanFreeQiyuePet()
  110. return self.hasFreePet
  111. end
  112. function UIPetRootCtr:SetQueryPetId(id)
  113. self.queryPetId = id
  114. end
  115. function UIPetRootCtr:GetQueryPetId()
  116. return self.queryPetId
  117. end
  118. function UIPetRootCtr:GetAsyncIdx()
  119. self.asyncIdx = self.asyncIdx + 1
  120. return self.asyncIdx
  121. end
  122. function UIPetRootCtr:GetData()
  123. return self.data
  124. end
  125. function UIPetRootCtr:OnDispose()
  126. self.filterData = nil
  127. self.isFilter = nil
  128. self.showDatas = nil
  129. self.data = nil
  130. self.view = nil
  131. end
  132. return UIPetRootCtr