UIPetMatsView.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. local UIPetMatsView = require("UIPet/UIPetMatsView_Generate")
  2. local PetMatsGridView = require("UIPet/PetMatsGridView")
  3. local petMatsGridView
  4. function UIPetMatsView:OnAwake(data)
  5. self.controller = require("UIPet/UIPetMatsCtr"):new()
  6. self.controller:Init(self)
  7. self.controller:SetData(data)
  8. end
  9. function UIPetMatsView:AddEventListener()
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_PAGE_IN_END_NTF, self, self.OnUIPageInEndNtf)
  12. end
  13. function UIPetMatsView:FillContent(data, uiBase)
  14. self.uiBase = uiBase
  15. local gameObject = self.uiBase:GetRoot()
  16. if gameObject ~= nil then
  17. self.gameObject = gameObject
  18. self.transform = gameObject.transform
  19. end
  20. self:InitGenerate(self.transform, data)
  21. self:Init()
  22. end
  23. function UIPetMatsView:Init()
  24. local fromUIId = self.controller:GetFromUIId()
  25. if fromUIId == Enum.UIPageName.UIPetLvUp then
  26. self.textTitle.uILocalizeScript:SetContent("TitleChooseMet")
  27. self.mats.text.uILocalizeScript:SetContent("DscChooseSillUpMet")
  28. elseif fromUIId == Enum.UIPageName.UIPetRelations then
  29. self.textTitle.uILocalizeScript:SetContent("TitlePetRelations")
  30. self.mats.text.uILocalizeScript:SetContent("DscPetChooseSupport")
  31. elseif fromUIId == Enum.UIPageName.UIPetMySupport then
  32. self.textTitle.uILocalizeScript:SetContent("TitleChooseSupport")
  33. self.mats.text.uILocalizeScript:SetContent("DscChooseSupport")
  34. end
  35. end
  36. function UIPetMatsView:OnUIPageInEndNtf()
  37. if not petMatsGridView then
  38. petMatsGridView = PetMatsGridView:new()
  39. petMatsGridView:Init(self.controller:GetEnterType(), self, self.mats.loopGridView)
  40. end
  41. self:Refresh()
  42. end
  43. function UIPetMatsView:Refresh(resetPos)
  44. if petMatsGridView then
  45. petMatsGridView:Refresh(resetPos)
  46. end
  47. local selectedData, idx = self.controller:GetCurSelectedIdx()
  48. if selectedData then
  49. self.lastSelectedData = selectedData
  50. self.lastSelectedItemlua = petMatsGridView:GetShowItemByIdx(idx)
  51. end
  52. end
  53. function UIPetMatsView:OnItemClick(button, params)
  54. local data = params[0]
  55. local fromUIId = self.controller:GetFromUIId()
  56. if fromUIId == Enum.UIPageName.UIPetLvUp then
  57. if data.isBattle then
  58. return
  59. end
  60. elseif fromUIId == Enum.UIPageName.UIPetRelations then
  61. if not data.canUse then
  62. return
  63. end
  64. elseif fromUIId == Enum.UIPageName.UIPetMySupport then
  65. if data.isUsed then
  66. return
  67. end
  68. end
  69. self.selectedIdx = data.idx
  70. self.curSelectedData = data
  71. if not self.lastSelectedData or self.lastSelectedData ~= self.curSelectedData then
  72. if data and data.isRelevant and fromUIId == Enum.UIPageName.UIPetLvUp then
  73. local data = {"PetCostNotify8", nil, nil, self, self.PetClickSure}
  74. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  75. return
  76. end
  77. if data and (data.level > 1 or self.controller:WasSkillUp(data)) and self.controller:GetEnterType() == Enum.ItemIEnterType.PetMats then
  78. local data = {"PetCostNotify4", nil, nil, self, self.PetClickSure}
  79. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  80. return
  81. end
  82. end
  83. self:PetClickSure()
  84. end
  85. function UIPetMatsView:PetClickSure()
  86. if self.selectedIdx then
  87. local sameItem = false
  88. if self.curSelectedData and self.lastSelectedData and self.curSelectedData.idx == self.lastSelectedData.idx then
  89. sameItem = true
  90. self.controller:SetSelectedData(nil)
  91. self.curSelectedData.selected = 0
  92. else
  93. self.controller:SetSelectedData(self.selectedIdx)
  94. self.curSelectedData.selected = 1
  95. if self.lastSelectedData then
  96. self.lastSelectedData.selected = 0
  97. if petMatsGridView then
  98. local luaitem = petMatsGridView:GetShowItemByIdx(self.lastSelectedData.idx)
  99. if luaitem then
  100. luaitem.selected:SetActive(false)
  101. end
  102. end
  103. end
  104. end
  105. if petMatsGridView then
  106. local luaitem = petMatsGridView:GetShowItemByIdx(self.selectedIdx)
  107. if luaitem then
  108. luaitem.selected:SetActive(self.curSelectedData.selected > 0)
  109. end
  110. end
  111. self.lastSelectedData = (sameItem and {nil} or {self.curSelectedData})[1]
  112. self.selectedIdx = nil
  113. end
  114. end
  115. function UIPetMatsView:RemoveEventListener()
  116. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  117. end
  118. function UIPetMatsView:AddUIEventListener()
  119. self.uiBase:AddButtonEventListener(self.AnyBtn.button, self, self.OnCloseClick)
  120. self.uiBase:AddButtonEventListener(self.btnCancel.button, self, self.OnCancelClick)
  121. self.uiBase:AddButtonEventListener(self.btnSure.button, self, self.OnSureClick)
  122. end
  123. function UIPetMatsView:OnCloseClick()
  124. self:UIClose()
  125. end
  126. function UIPetMatsView:OnCancelClick()
  127. self.controller:SetSelectedData(nil)
  128. self:OnCloseClick()
  129. end
  130. function UIPetMatsView:OnSureClick()
  131. self:OnCloseClick()
  132. local fromUIId = self.controller:GetFromUIId()
  133. if fromUIId == Enum.UIPageName.UIPetLvUp then
  134. local id = self.controller:GetCurSelectedIdByIdx()
  135. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.PET_SKILLUP_REFRESH_NTF, id)
  136. elseif fromUIId == Enum.UIPageName.UIPetRelations then
  137. local relationCfgId = self.controller:GetRelationCfgId()
  138. local data = self.controller:GetCurSelectedDataByIdx()
  139. if not relationCfgId or not data then
  140. return
  141. end
  142. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.PET_RELATION_CHANGE_NTF, {relationCfgId = relationCfgId, petData = data})
  143. elseif fromUIId == Enum.UIPageName.UIPetMySupport then
  144. local id = self.controller:GetCurSelectedIdByIdx()
  145. local idx = self.controller:GetSupportIdx()
  146. if not id or not idx then
  147. return
  148. end
  149. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.PET_MY_SUPPORT_CHANGE_NTF, {id, idx})
  150. end
  151. end
  152. function UIPetMatsView:OnHide()
  153. if petMatsGridView then
  154. petMatsGridView:OnHide()
  155. end
  156. end
  157. function UIPetMatsView:OnShow(data)
  158. self.controller:SetData(data)
  159. end
  160. function UIPetMatsView:OnClose()
  161. end
  162. function UIPetMatsView:OnDispose()
  163. if petMatsGridView then
  164. petMatsGridView:OnDispose()
  165. petMatsGridView = nil
  166. end
  167. self.lastSelectedItemlua = nil
  168. self.lastSelectedData = nil
  169. self.selectedIdx = nil
  170. self.curSelectedData = nil
  171. self.curSelectedItemlua = nil
  172. self.controller:OnDispose()
  173. end
  174. return UIPetMatsView