PetBook.lua 4.1 KB

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