PetBook.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. local PetBook = class("PetBook")
  2. local BitUtil = require("BitUtil")
  3. local pageToggleData = {}
  4. function PetBook:ctor()
  5. end
  6. function PetBook:InitGo(host,uiGo)
  7. self.host = host
  8. self.viewLua = CommonUtil.BindGridViewItem2Lua(self.host, "BookItem", uiGo)
  9. self.controller = require("UICollect/PetBookCtr"):new()
  10. self.host.controller:SetPetBookCtr(self.controller)
  11. self:InitPanel()
  12. end
  13. function PetBook:InitPanel()
  14. self:InitGrid()
  15. self.viewLua.qtyCard:SetActive(false)
  16. self.viewLua.qtyPet:SetActive(true)
  17. self.viewLua.qtyCollection:SetActive(false)
  18. self.viewLua.btnMaterials:SetActive(false)
  19. self.viewLua.dscBox:SetActive(false)
  20. end
  21. function PetBook:Hide()
  22. self.viewLua.gameObject:SetActive(false)
  23. end
  24. function PetBook:Show()
  25. self.viewLua.gameObject:SetActive(true)
  26. end
  27. function PetBook:SelectToggle()
  28. CommonUtil.CreateToggleMouduleOnlyBtns(self.host, pageToggleData, self.viewLua.toggleGroup, Enum.CollectQualityType.ALL, self.host.OnValueChangedToggle)
  29. end
  30. function PetBook:InitGrid()
  31. self.viewLua.scrollView.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  32. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  33. end, nil)
  34. end
  35. function PetBook:GetItemByRowColumn(gridView, itemIndex, row, column)
  36. local item = gridView:NewListViewItem('PetCollect')
  37. local cfgData = self.controller:GetShowDataByIdx(itemIndex + 1)
  38. local state, curAdvLv, owned = ManagerContainer.DataMgr.PetDataMgr:GetPetCollectRewardState(cfgData.Id)
  39. local itemlua = CommonUtil.BindGridViewItem2Lua(self.host, "PetCollect", item.gameObject)
  40. CommonUtil.UpdateItemPrefab(self.host, itemlua, cfgData, nil, self, self.OnPetClick)
  41. if state and owned then
  42. self:RedPointRefresh(cfgData, curAdvLv, state, itemlua.uIRedPointRP)
  43. else
  44. itemlua.uIRedPointRP.gameObject:SetActive(false)
  45. end
  46. return item
  47. end
  48. function PetBook:RedPointRefresh(cfgData, advMaxLv, state, redPoint)
  49. if cfgData.PetReward then
  50. for i = 1,#cfgData.PetReward do
  51. local adv = cfgData.PetReward[i][1]
  52. if advMaxLv >= adv then
  53. local rewarded = BitUtil.RshiftNumBandOne(state, adv) == 1
  54. if not rewarded then
  55. redPoint.gameObject:SetActive(true)
  56. return
  57. end
  58. end
  59. end
  60. end
  61. end
  62. function PetBook:OnValueChangedToggle()
  63. local type = pageToggleData.toggleDefaultIndex
  64. self.controller:GetHandBookPetCfgDatasByType(type)
  65. local count = self.controller:GetCurCount(type)
  66. local length = self.controller:GetCurShowDatasLength()
  67. local maxCount = length
  68. self.viewLua.qtyPet.text.text.text = count.."/"..maxCount
  69. self.viewLua.qtyPet.iconAll:SetActive(type == Enum.CollectQualityType.ALL)
  70. self.viewLua.qtyPet.iconNormal:SetActive(type == Enum.CollectQualityType.NORMAL)
  71. self.viewLua.qtyPet.iconMini:SetActive(type == Enum.CollectQualityType.MINIBOSS)
  72. self.viewLua.qtyPet.iconMvp:SetActive(type == Enum.CollectQualityType.MVP)
  73. if length > 0 then
  74. --self.viewLua.scrollView.loopGridView:SetListItemCount(length, true)
  75. self.viewLua.scrollView.loopGridView:RefreshListByIndex(length)
  76. end
  77. end
  78. function PetBook:OnPetClick(button, params)
  79. local cfgId = params[0]
  80. local data = {type = Enum.CollectType.Pet, cfgId = cfgId}
  81. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UICollectTips, data)
  82. end
  83. function PetBook:AddEventListener()
  84. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.host.uiData.name, UIEventNames.PET_HANDBOOK_REWARD_REFRESH, function()
  85. self:OnValueChangedToggle()
  86. end)
  87. end
  88. function PetBook:RemoveEventListener()
  89. end
  90. function PetBook:AddUIEventListener()
  91. self.host.uiBase:AddButtonEventListener(self.viewLua.btnBack.button, self, self.OnBtnBackClick)
  92. end
  93. function PetBook:OnBtnBackClick()
  94. if self.host and self.host.BookBack then
  95. self.host:BookBack()
  96. end
  97. end
  98. function PetBook:Dispose()
  99. self.viewLua.scrollView.loopGridView:Dispose()
  100. self.controller:OnDispose()
  101. self.controller = nil
  102. self.host = nil
  103. self.viewLua:GenerateDestroy()
  104. self.viewLua = nil
  105. pageToggleData = {}
  106. end
  107. return PetBook