PetMatsGridCtr.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. local PetMatsGridCtr = class("PetMatsGridCtr")
  2. function PetMatsGridCtr:ctor()
  3. self.root = nil
  4. end
  5. function PetMatsGridCtr:InitRoot(root, enterType)
  6. self.enterType = enterType
  7. self.root = root
  8. if self.root.SetChildController then
  9. self.root:SetChildController(self)
  10. end
  11. end
  12. function PetMatsGridCtr:RefreshShowDataType()
  13. if self.enterType >= Enum.ItemIEnterType.PetRoot and self.enterType <= Enum.ItemIEnterType.PetQiyueMat then
  14. self.showDatas = self:RefreshPetDatas()
  15. elseif self.enterType == Enum.ItemIEnterType.SkillEquip then
  16. self.showDatas = self:RefreshSkillEquipDatas()
  17. end
  18. if self.root.SetShowDatas then
  19. self.root:SetShowDatas(self.showDatas)
  20. end
  21. local showDataLength = 0
  22. if self.showDatas then
  23. showDataLength = #self.showDatas
  24. if self.row and self.minColumn then
  25. local curColumn = Mathf.Ceil(showDataLength / self.row) + 2
  26. if curColumn < self.minColumn then
  27. curColumn = self.minColumn
  28. end
  29. showDataLength = curColumn * self.row
  30. end
  31. end
  32. self.showDataLength = showDataLength
  33. end
  34. function PetMatsGridCtr:SetGridRowColumn(row, minColumn)
  35. self.row = row
  36. self.minColumn = minColumn
  37. end
  38. function PetMatsGridCtr:GetShowDataLength()
  39. return self.showDataLength or 0
  40. end
  41. function PetMatsGridCtr:GetRealShowDataLength()
  42. return self.showDatas and #self.showDatas or 0
  43. end
  44. function PetMatsGridCtr:GetShowDatas()
  45. return self.showDatas
  46. end
  47. function PetMatsGridCtr:GetShowData(itemIndex)
  48. return self.showDatas and self.showDatas[itemIndex + 1] or nil
  49. end
  50. function PetMatsGridCtr:RefreshPetDatas()
  51. return self.root:RefreshPetDatas()
  52. end
  53. function PetMatsGridCtr:RefreshSkillEquipDatas()
  54. return self.root:RefreshSkillEquipDatas()
  55. end
  56. function PetMatsGridCtr:GetPetDataById(id)
  57. for k,v in pairs(self.showDatas) do
  58. if v.id == id then
  59. return v, k
  60. end
  61. end
  62. return nil, nil
  63. end
  64. function PetMatsGridCtr:Dispose()
  65. if self.showDatas then
  66. for _,v in pairs(self.showDatas) do
  67. v.selected = 0
  68. v.canUse = false
  69. v.isUsed = false
  70. end
  71. end
  72. self.showDatas = nil
  73. self.root = nil
  74. end
  75. return PetMatsGridCtr