UIPetRootView.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. local UIPetRootView = require("UIPet/UIPetRootView_Generate")
  2. local PetMatsGridView = require("UIPet/PetMatsGridView")
  3. local RectOffset = UnityEngine.RectOffset
  4. local IconPetItemCtr = require("Common/IconPetItemCtr")
  5. local PetRootPage = {
  6. Pet = 1,
  7. Qiyue = 2,
  8. }
  9. local pageToggleData = {}
  10. local petMatsGridView
  11. local sameNatureTypeAdd = 0
  12. local qiyueFuncIsUnlock = true
  13. function UIPetRootView:OnAwake(data)
  14. self.controller = require("UIPet/UIPetRootCtr"):new()
  15. self.controller:Init(self)
  16. self.controller:SetData(data)
  17. end
  18. function UIPetRootView:AddEventListener()
  19. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.FILTER_NTF, self, self.RefreshCardDatasByFilter)
  20. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.QIYUE_PET_CHANGE_SUCCESS, self, self.RefreshSlotChangeNtf)
  21. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.QIYUE_TOGGLE_JUMP_TRIGGER, self, self.QiyueToggleJump)
  22. end
  23. function UIPetRootView:FillContent(data, uiBase)
  24. self.uiBase = uiBase
  25. local gameObject = self.uiBase:GetRoot()
  26. if gameObject ~= nil then
  27. self.gameObject = gameObject
  28. self.transform = gameObject.transform
  29. end
  30. self:InitGenerate(self.transform, data)
  31. self:Init()
  32. end
  33. function UIPetRootView:Init()
  34. ManagerContainer.RedPointMgr.PetRPCtr:RefreshTotalQiyueRPState()
  35. sameNatureTypeAdd = GlobalConfig.Instance:GetConfigIntValue(351)* 0.01
  36. if not petMatsGridView then
  37. petMatsGridView = PetMatsGridView:new()
  38. petMatsGridView:Init(Enum.ItemIEnterType.PetRoot, self, self.petScrollView.loopGridView)
  39. end
  40. self.contractScrollView.loopListView:InitListView(0, function(gridView, itemIndex, row, column)
  41. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  42. end, nil)
  43. self.contractScrollView.loopListView:SetListItemCount(6, true)
  44. end
  45. function UIPetRootView:RefreshCardDatasByFilter(uiId, data, isFilter)
  46. if uiId ~= self.uiData.id then return end
  47. self.controller:SetFilterData(data, isFilter)
  48. self:OnValueChangedToggle()
  49. end
  50. function UIPetRootView:OnValueChangedToggle()
  51. self.petScrollView:SetActive(pageToggleData.toggleDefaultIndex == PetRootPage.Pet)
  52. self.contract:SetActive(pageToggleData.toggleDefaultIndex == PetRootPage.Qiyue)
  53. self.btnFilter:SetActive(pageToggleData.toggleDefaultIndex == PetRootPage.Pet)
  54. self.btnDecompose:SetActive(pageToggleData.toggleDefaultIndex == PetRootPage.Pet)
  55. self.btnBattle:SetActive(pageToggleData.toggleDefaultIndex == PetRootPage.Pet)
  56. self.btnStamp:SetActive(pageToggleData.toggleDefaultIndex == PetRootPage.Pet)
  57. self.contractInfo:SetActive(pageToggleData.toggleDefaultIndex == PetRootPage.Qiyue)
  58. if pageToggleData.toggleDefaultIndex == PetRootPage.Pet then
  59. if petMatsGridView then
  60. petMatsGridView:Refresh(true)
  61. end
  62. self.btnFilter.check:SetActive(self.controller:GetIsFilter())
  63. elseif pageToggleData.toggleDefaultIndex == PetRootPage.Qiyue then
  64. self.controller:RefreshQiyueDatas()
  65. local loopGridView = self.contractScrollView.loopListView
  66. local realLength = self.controller:GetShowDataRealLength()
  67. --loopGridView:SetListItemCount(realLength, true)
  68. loopGridView:RefreshAllShownItem()
  69. end
  70. end
  71. function UIPetRootView:RefreshSlotChangeNtf()
  72. self.controller:HasEnoughPet()
  73. if ManagerContainer.DataMgr.PetDataMgr:IsQiyueSuccess() then
  74. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("PetContractState5")
  75. end
  76. self:OnValueChangedToggle()
  77. end
  78. function UIPetRootView:GetItemByRowColumn(gridView, itemIndex, row, column)
  79. local length = self.controller:GetShowDataRealLength()
  80. if (itemIndex < 0 or itemIndex >= length) then
  81. return nil
  82. end
  83. local heroData = self.controller:GetShowData(itemIndex)
  84. local item = nil
  85. if heroData then
  86. local unlockCount = self.controller:GetPetBattleUnlockCount()
  87. item = gridView:NewListViewItem("PetContractItem")
  88. item.gameObject.name = itemIndex
  89. local itemlua = CommonUtil.BindGridViewItem2Lua(self, "PetContractItem", item.gameObject)
  90. --pet qiyue detail show
  91. local jobIcon
  92. if heroData.id == 1 then
  93. local jobData = ManagerContainer.CfgMgr:GetJobDataById(heroData.configId)
  94. jobIcon = jobData.JobIcon
  95. else
  96. local heroCfgData = ManagerContainer.CfgMgr:GetPartnerDataById(heroData.configId)
  97. jobIcon = heroCfgData.JobIcon
  98. end
  99. CommonUtil.LoadIcon(self, jobIcon, function (sprite)
  100. itemlua.jobIcon.image.sprite = sprite
  101. end, itemlua, "jobIcon")
  102. local name
  103. if heroData.id == 1 then
  104. local nickName = ManagerContainer.DataMgr.UserData:GetUserNickname()
  105. local cfgData = ManagerContainer.CfgMgr:GetJobDataById(heroData.configId)
  106. if nickName == nil then
  107. name = CommonUtil.GetHeroJobAndNameByUid(heroData.id, heroData.configId)
  108. else
  109. if cfgData == nil then
  110. name = nickName
  111. else
  112. name = I18N.T(cfgData.JobName) .. nickName
  113. end
  114. end
  115. else
  116. name = CommonUtil.GetHeroJobAndNameByUid(heroData.id, heroData.configId)
  117. end
  118. itemlua.heroName.text.text = name
  119. local petId = heroData.battlePetId
  120. local petData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(petId)
  121. local slotList = heroData.petQiyueData.slotList
  122. local hasBattlePet = unlockCount >= (itemIndex + 1) and petId > 0
  123. itemlua.iconPetItem:SetActive(hasBattlePet)
  124. itemlua.petLock:SetActive(unlockCount < (itemIndex + 1))
  125. if hasBattlePet and petData then
  126. IconPetItemCtr:SetData(self,itemlua.iconPetItem, petData, Enum.ItemIEnterType.Bag)
  127. local petCfgData = ManagerContainer.CfgMgr:GetPetDataById(petData.cfgId)
  128. local natureId = petCfgData.NatureType
  129. local natureCfgData = ManagerContainer.CfgMgr:GetNatureDataById(natureId)
  130. local icon = natureCfgData.Icon
  131. CommonUtil.LoadIcon(self, icon, function (sprite)
  132. itemlua.extraBox.petQty.nature.image.sprite = sprite
  133. end, itemlua, "natureIcon")
  134. else
  135. CommonUtil.LoadIcon(self, Constant.Natural_Unknow_Icon, function (sprite)
  136. itemlua.extraBox.petQty.nature.image.sprite = sprite
  137. end, itemlua, "natureIcon")
  138. end
  139. local state = #slotList
  140. local noticed = false
  141. if not qiyueFuncIsUnlock then
  142. noticed = true
  143. itemlua.noticeText.uILocalizeScript:SetContent("")
  144. else
  145. if heroData.id > 1 and not heroData.owned then
  146. noticed = true
  147. itemlua.noticeText.uILocalizeScript:SetContent("PetContractState4")
  148. elseif unlockCount <= itemIndex then
  149. noticed = true
  150. itemlua.noticeText.uILocalizeScript:SetContent("PetContractState3")
  151. elseif petId == 0 then
  152. noticed = true
  153. itemlua.noticeText.uILocalizeScript:SetContent("PetContractState7")
  154. end
  155. end
  156. local count = 0
  157. local extAddPer = 0
  158. local natureType = petData and petData.natureType or 0
  159. if state > 0 and (heroData.id == 1 or heroData.owned) and unlockCount > 0 then
  160. local hasQiyuePet = false
  161. if petId > 0 then
  162. noticed = false
  163. end
  164. local costState, idx = self.controller:CalcUnlockSlot(slotList)
  165. for i = 1, 4 do
  166. local data = slotList[i]
  167. local slotItem = itemlua.contractBox["slot"..i]
  168. if slotItem then
  169. slotItem.btnLock:SetActive(data == nil)
  170. slotItem.iconPetItem:SetActive(data and data.petId > 0)
  171. local attrItem = itemlua.activatedBox["attrItem"..i]
  172. attrItem:SetActive(data and data.petId > 0)
  173. if data then
  174. if data.petId > 0 then
  175. hasQiyuePet = true
  176. local addPetData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(data.petId)
  177. if addPetData then
  178. if addPetData.natureType == natureType then
  179. count = count + 1
  180. end
  181. local addPetCfgData = ManagerContainer.CfgMgr:GetPetDataById(addPetData.cfgId)
  182. local totalAdd = 0
  183. if addPetCfgData then
  184. totalAdd = addPetCfgData.contract * 0.01 + (addPetData.natureType == natureType and sameNatureTypeAdd or 0) + addPetData.totalSkillUpCount * addPetCfgData.understand * 0.01
  185. end
  186. if attrItem then
  187. attrItem.text.uILocalizeScript:SetContent(addPetCfgData.Name)
  188. attrItem.number.text.text = totalAdd.."%"
  189. end
  190. end
  191. IconPetItemCtr:SetData(self,slotItem.iconPetItem, addPetData, Enum.ItemIEnterType.Bag)
  192. end
  193. slotItem.uIRedPointRP:SetActive(petId > 0 and self.controller:CanFreeQiyuePet() and data.petId == 0)
  194. else
  195. slotItem.uIRedPointRP:SetActive(costState and i == idx)
  196. end
  197. --slotItem.btnAdd.button.enabled = petId > 0
  198. self.uiBase:AddButtonUniqueEventListener(slotItem.btnAdd.button, self, self.OnSlotClick, itemIndex, heroData.id, i, data and data.petId or 0, petId)
  199. self.uiBase:AddButtonUniqueEventListener(slotItem.btnLock.button, self, self.OnSlotLockClick, itemIndex, heroData.id, idx)
  200. end
  201. end
  202. if not noticed and not hasQiyuePet then
  203. noticed = true
  204. itemlua.noticeText.uILocalizeScript:SetContent("PetContractState1")
  205. end
  206. else
  207. if not noticed and state == 0 then
  208. noticed = true
  209. itemlua.noticeText.uILocalizeScript:SetContent("PetContractState2")
  210. end
  211. local rpState = false
  212. for i = 1, 4 do
  213. local slotItem = itemlua.contractBox["slot"..i]
  214. local data = slotList[i]
  215. if slotItem then
  216. local costState = self.controller:CalcUnlockSlot(slotList)
  217. if not data and not rpState and costState and (heroData.id == 1 or heroData.owned) then
  218. rpState = true
  219. slotItem.uIRedPointRP:SetActive(true)
  220. else
  221. slotItem.uIRedPointRP:SetActive(false)
  222. end
  223. slotItem.btnLock:SetActive(true)
  224. slotItem.iconPetItem:SetActive(false)
  225. self.uiBase:AddButtonUniqueEventListener(slotItem.btnLock.button, self, self.OnSlotLockClick, itemIndex, heroData.id, 1)
  226. end
  227. end
  228. end
  229. itemlua.noticeBox:SetActive(state == 0 or noticed)
  230. itemlua.activatedBox:SetActive(state > 0 and not noticed)
  231. itemlua.btnRemoveAll:SetActive(state > 0 and not noticed)
  232. itemlua.extraBox.petQty.number.text.text = count .. "/4"
  233. itemlua.extraBox.petExtra.number.text.text = (count * sameNatureTypeAdd).."%"
  234. self.uiBase:AddButtonUniqueEventListener(itemlua.btnRemoveAll.button, self, self.OnRemoveAllClick, itemIndex, heroData.id)
  235. end
  236. return item
  237. end
  238. function UIPetRootView:OnSlotClick(button, params)
  239. self.curSelectedItemIdx = params[0]
  240. local heroId = params[1]
  241. local idx = params[2]
  242. local petId = params[3]
  243. local qiyuPetId = params[4]
  244. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPetContractTips, {heroId, idx, petId, qiyuPetId})
  245. end
  246. function UIPetRootView:OnSlotLockClick(button, params)
  247. self.curSelectedItemIdx = params[0]
  248. local heroId = params[1]
  249. local idx = params[2]
  250. local heroData = CommonUtil.GetHeroLogicDataByUid(heroId)
  251. local state,_,costId, count, cost = self.controller:CalcUnlockSlot(heroData.petQiyueData.slotList)
  252. if not state then
  253. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("PetContractUnlockTips")
  254. return
  255. end
  256. if not costId then return end
  257. local data = {"PetQiyueUnlock", {cost}, {heroId}, self, self.UnlockClickSure, nil, nil, {costId, count, cost}}
  258. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  259. end
  260. function UIPetRootView:OnRemoveAllClick(button, params)
  261. self.curSelectedItemIdx = params[0]
  262. local heroId = params[1]
  263. local data = {"PetQiyueRemoveAll", nil, {heroId}, self, self.OnRemoveAllSure}
  264. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  265. end
  266. function UIPetRootView:OnItemClick(button, params)
  267. local data = params[0]
  268. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPetLvUp, data.id, self.uiData.id)
  269. end
  270. function UIPetRootView:UnlockClickSure(params)
  271. local heroId = params[1]
  272. self.controller:SendQiyueUnlockReq(heroId)
  273. end
  274. function UIPetRootView:OnRemoveAllSure(params)
  275. local heroId = params[1]
  276. self.controller:HeroRemoveAllQiyueSlot(heroId)
  277. end
  278. function UIPetRootView:OnItemClick(button, params)
  279. local data = params[0]
  280. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPetLvUp, data.id, self.uiData.id)
  281. end
  282. function UIPetRootView:RemoveEventListener()
  283. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  284. end
  285. function UIPetRootView:AddUIEventListener()
  286. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  287. self.uiBase:AddButtonEventListener(self.btnFilter.button, self, self.OnFilterClick)
  288. self.uiBase:AddButtonEventListener(self.btnDecompose.button, self, self.OnDecomposeClick)
  289. self.uiBase:AddButtonEventListener(self.btnBattle.button, self, self.OnBattleClick)
  290. self.uiBase:AddButtonEventListener(self.btnStamp.button, self, self.OnStampClick)
  291. self.uiBase:AddButtonEventListener(self.btnContractAttr.button, self, self.OnContractClick)
  292. self.uiBase:AddButtonEventListener(self.btnInfo.button, self, self.OnClickPlayRuleBtn)
  293. CommonUtil.CreateToggleMouduleOnlyBtns(self, pageToggleData, self.toggleGroup, 1, self.OnValueChangedToggle)
  294. end
  295. function UIPetRootView:OnFilterClick()
  296. local data = {uiId = self.uiData.id, enter = Enum.ItemIEnterType.Pet, filterData = self.controller:GetFilterData()}
  297. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIFilter, data)
  298. end
  299. function UIPetRootView:OnContractClick()
  300. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPetContractAttribute)
  301. end
  302. function UIPetRootView:OnDecomposeClick()
  303. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPetDecompose, 1 , self.uiData.id)
  304. end
  305. function UIPetRootView:OnStampClick()
  306. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPetStamp, nil , self.uiData.id)
  307. end
  308. function UIPetRootView:OnBattleClick()
  309. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPetBattle, nil , self.uiData.id)
  310. end
  311. function UIPetRootView:OnClickPlayRuleBtn()
  312. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'PetContractText'})
  313. end
  314. function UIPetRootView:QiyueToggleJump()
  315. self.toggleContract.toggle.isOn = true
  316. end
  317. function UIPetRootView:GetFirstPetQiyueSlot()
  318. local loopListView = self.contractScrollView.loopListView
  319. local item = loopListView:GetShownItemByItemIndex(0)
  320. if not item then
  321. return
  322. end
  323. local itemlua = CommonUtil.BindGridViewItem2Lua(self, "PetContractItem", item.gameObject)
  324. if not itemlua then
  325. return
  326. end
  327. return itemlua
  328. end
  329. function UIPetRootView:PetContractToggleGuide(param, owner, ownerCB)
  330. local itemlua = self:GetFirstPetQiyueSlot()
  331. if not itemlua or not itemlua.gameObject then
  332. if owner and ownerCB then
  333. ownerCB(owner)
  334. end
  335. return
  336. end
  337. if owner and ownerCB then
  338. ownerCB(owner, itemlua.contractBox.slot1.btnLock)
  339. end
  340. end
  341. function UIPetRootView:OnHide()
  342. if petMatsGridView then
  343. petMatsGridView:OnHide()
  344. end
  345. end
  346. function UIPetRootView:OnShow(data)
  347. self.controller:SetData(data)
  348. ManagerContainer.RedPointMgr.PetRPCtr:RefreshTotalQiyueRPState()
  349. self:OnValueChangedToggle()
  350. end
  351. function UIPetRootView:OnClose()
  352. self.contractScrollView.loopListView:Dispose()
  353. pageToggleData = nil
  354. end
  355. function UIPetRootView:OnDispose()
  356. if petMatsGridView then
  357. petMatsGridView:OnDispose()
  358. petMatsGridView = nil
  359. end
  360. self.controller:OnDispose()
  361. self.defaultRectOffset = nil
  362. end
  363. return UIPetRootView