UISummonShowView.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. local UISummonShowView = require("UISummon/UISummonShowView_Generate")
  2. local PetViewSystem = require('PetViewSystem')
  3. local PreviewSystem = require("PreviewSystem")
  4. local CardIconBigItemCtr = require("Common/CardIconBigItemCtr")
  5. function UISummonShowView:OnAwake(data)
  6. self.controller = require("UISummon/UISummonShowCtr"):new()
  7. self.controller:Init(self)
  8. self.controller:SetData(data)
  9. end
  10. function UISummonShowView:AddEventListener()
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  12. end
  13. function UISummonShowView: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 UISummonShowView:Init()
  24. self.loading = false
  25. self.isPageInEnd = false
  26. self:RefreshView()
  27. end
  28. function UISummonShowView:RemoveEventListener()
  29. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  30. end
  31. function UISummonShowView:AddUIEventListener()
  32. self.uiBase:AddButtonUniqueEventListener(self.skip.button, self, self.OnClickSkipBtn)
  33. self.uiBase:AddButtonUniqueEventListener(self.btnNext.button, self, self.OnClickNextBtn)
  34. end
  35. function UISummonShowView:OnHide()
  36. end
  37. function UISummonShowView:OnShow(data)
  38. self.controller:SetData(data)
  39. end
  40. function UISummonShowView:OnClose()
  41. end
  42. function UISummonShowView:OnDispose()
  43. self.loading = nil
  44. self.isPageInEnd = nil
  45. self.isAniming = nil
  46. if self.animTimer then
  47. self.animTimer:Stop()
  48. end
  49. self:DisposeShow()
  50. self.controller:OnDispose()
  51. end
  52. function UISummonShowView:OnPageInEnd()
  53. self.super.OnPageInEnd(self)
  54. self.isPageInEnd = true
  55. if not self.loading then
  56. self:LoadComplete()
  57. end
  58. end
  59. function UISummonShowView:OnClickSkipBtn()
  60. if not self.isPageInEnd then
  61. return
  62. end
  63. if self.loading or self.isAniming then
  64. if self.controller:GetCurMustShowComplete() then
  65. return
  66. end
  67. end
  68. if self.controller:CheckMustShow() then
  69. local showData = self.controller:GetShowData()
  70. if showData then
  71. self:RefreshView()
  72. return
  73. end
  74. end
  75. self:EnterResultView()
  76. end
  77. function UISummonShowView:OnClickNextBtn()
  78. if not self.isPageInEnd then
  79. return
  80. end
  81. if self.loading or self.isAniming then
  82. if self.controller:GetCurMustShowComplete() then
  83. return
  84. end
  85. end
  86. self.controller:ChangeNextData()
  87. local showData = self.controller:GetShowData()
  88. if showData then
  89. self:RefreshView()
  90. return
  91. end
  92. self:EnterResultView()
  93. end
  94. function UISummonShowView:RefreshView()
  95. self.loading = true
  96. self.itemShow.animator:Play('ItemShow', -1, 0)
  97. self.itemShow.animator:Update(0)
  98. self.itemShow.animator.enabled = false
  99. local showData = self.controller:GetShowData()
  100. if not showData then
  101. self:EnterResultView()
  102. return
  103. end
  104. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(showData.cfgId)
  105. if not itemCfgData then
  106. LogError('[wboy] itemCfg is not exist id : ' .. Inspect(showData))
  107. self:EnterResultView()
  108. return
  109. end
  110. -- 清理上一次显示的东西
  111. self:ClearLastShow()
  112. local isBlue = (not itemCfgData.Quality or itemCfgData.Quality <= 2)
  113. local isPink = (itemCfgData.Quality and itemCfgData.Quality == 3)
  114. local isYellow = (itemCfgData.Quality and itemCfgData.Quality >= 4)
  115. self.bGBlueBottom:SetActive(isBlue)
  116. self.bGBlue:SetActive(isBlue)
  117. self.bGPinkBottom:SetActive(isPink)
  118. self.bGPink:SetActive(isPink)
  119. self.bGYellowBottom:SetActive(isYellow)
  120. self.bGYellow:SetActive(isYellow)
  121. self.nameTxt.text.text = string.formatbykey(itemCfgData.Name)
  122. self.label:SetActive(false)
  123. self.labelNew:SetActive(showData.isNew)
  124. if showData.isNew then
  125. if not self.newRPGo then
  126. if not self.newRpSeqId then
  127. self.newRpSeqId = ManagerContainer.ResMgr:LuaLoadAssets(Enum.ResourceType.GameObject, Constants.UICommonPath, {'UINewRP'}, self, self.NewRPLoadComplete)
  128. if ManagerContainer.ResMgr:SeqIdEquals(self.newRpSeqId, 0) then
  129. self.newRpSeqId = nil
  130. self:NewRPLoadComplete()
  131. end
  132. end
  133. end
  134. end
  135. if itemCfgData.ResType == Enum.ItemType.Pet then
  136. if not self.petViewSystem then
  137. self.petViewSystem = PetViewSystem:new()
  138. end
  139. self.petViewSystem:RefreshView(Enum.RoleInEnvType.PetLvUp, showData.cfgId, showData.extGoesShowData, self, self.PetLoadComplete)
  140. elseif itemCfgData.ResType == Enum.ItemType.Card then
  141. if not self.cardItemLua then
  142. self.cardLoadSeqId = ManagerContainer.ResMgr:LuaLoadAssets(Enum.ResourceType.GameObject, Constants.UIItemDir, {'CardIconBigItem'}, self, self.CardLoadComplete)
  143. if ManagerContainer.ResMgr:SeqIdEquals(self.cardLoadSeqId, 0) then
  144. self.cardLoadSeqId = nil
  145. self:CardLoadComplete()
  146. end
  147. else
  148. self:CardLoadComplete()
  149. end
  150. elseif itemCfgData.ResType == Enum.ItemType.SkillEquip then
  151. local artifactCfgData = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(showData.cfgId)
  152. if not artifactCfgData then
  153. if self.artifactGo then
  154. ManagerContainer.ResMgr:RecycleGO(Constants.ModelPath, self.artifactPath, self.artifactGo)
  155. self.artifactPath = nil
  156. self.artifactGo = nil
  157. end
  158. elseif self.artifactPath ~= artifactCfgData.AvatarPrefab or not self.artifactGo then
  159. if self.artifactGo then
  160. ManagerContainer.ResMgr:RecycleGO(Constants.ModelPath, self.artifactPath, self.artifactGo)
  161. self.artifactPath = nil
  162. self.artifactGo = nil
  163. end
  164. self.artifactSeqId = ManagerContainer.ResMgr:LuaLoadAssets(Enum.ResourceType.GameObject, Constants.ModelPath, {artifactCfgData.AvatarPrefab}, self, self.ArtifactLoadComplete)
  165. if ManagerContainer.ResMgr:SeqIdEquals(self.artifactSeqId, 0) then
  166. self.artifactSeqId = nil
  167. self:ArtifactLoadComplete()
  168. end
  169. else
  170. self:ArtifactLoadComplete()
  171. end
  172. if artifactCfgData then
  173. self:ShowSkillEquipStar(artifactCfgData.ArtifactMaxLevel)
  174. end
  175. else
  176. if not self.iconItemLua then
  177. self.defaultLoadSeqId = ManagerContainer.ResMgr:LuaLoadAssets(Enum.ResourceType.GameObject, Constants.UIItemDir, {'IconItem'}, self, self.DefaultLoadComplete)
  178. if ManagerContainer.ResMgr:SeqIdEquals(self.defaultLoadSeqId, 0) then
  179. self.defaultLoadSeqId = nil
  180. self:DefaultLoadComplete()
  181. end
  182. else
  183. self:DefaultLoadComplete()
  184. end
  185. end
  186. end
  187. --神器星级显示
  188. function UISummonShowView:ClearSkillEquipStar()
  189. self:ShowSkillEquipStar()
  190. end
  191. function UISummonShowView:ShowSkillEquipStar(nStartCnt)
  192. if not nStartCnt or nStartCnt <=0 then
  193. self.starBox:SetActive(false)
  194. else
  195. self.starBox:SetActive(true)
  196. local tbStarGroup = {}
  197. if nStartCnt > 5 then
  198. nStartCnt = 5
  199. end
  200. tbStarGroup[1] = self.star1
  201. tbStarGroup[2] = self.star2
  202. tbStarGroup[3] = self.star3
  203. tbStarGroup[4] = self.star4
  204. tbStarGroup[5] = self.star5
  205. for i = 1,#tbStarGroup do
  206. local bIsShow = false
  207. bIsShow = nStartCnt >= i
  208. tbStarGroup[i]:SetActive(bIsShow)
  209. end
  210. end
  211. end
  212. function UISummonShowView:ClearLastShow()
  213. if self.previewSystem then
  214. self.previewSystem:RemoveAllGo()
  215. end
  216. self.rT:SetActive(false)
  217. self.item:SetActive(false)
  218. self.modelImg.rawImage.texture = nil
  219. if self.petViewSystem then
  220. self.petViewSystem:Recycle()
  221. end
  222. if self.artifactSeqId then
  223. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.artifactSeqId)
  224. self.artifactSeqId = nil
  225. end
  226. if self.cardLoadSeqId then
  227. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.cardLoadSeqId)
  228. self.cardLoadSeqId = nil
  229. end
  230. if self.defaultLoadSeqId then
  231. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.defaultLoadSeqId)
  232. self.defaultLoadSeqId = nil
  233. end
  234. if self.cardItemLua then
  235. self.cardItemLua:SetActive(false)
  236. end
  237. if self.iconItemLua then
  238. self.iconItemLua:SetActive(false)
  239. end
  240. self:ClearSkillEquipStar()
  241. end
  242. function UISummonShowView:DisposeShow()
  243. if self.previewSystem then
  244. self.previewSystem:Dispose()
  245. self.previewSystem = nil
  246. end
  247. if self.petViewSystem then
  248. self.petViewSystem:Dispose()
  249. self.petViewSystem = nil
  250. end
  251. self.modelImg.rawImage.texture = nil
  252. if self.newRpSeqId then
  253. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.newRpSeqId)
  254. self.newRpSeqId = nil
  255. end
  256. if self.newRPGo then
  257. ManagerContainer.ResMgr:RecycleGO(Constants.UICommonPath, 'UINewRP', self.newRPGo.gameObject)
  258. self.newRPGo = nil
  259. end
  260. if self.autoRotateContainer then
  261. UnityEngine.GameObject.Destroy(self.autoRotateContainer)
  262. end
  263. if self.artifactGo then
  264. ManagerContainer.ResMgr:RecycleGO(Constants.ModelPath, self.artifactPath, self.artifactGo)
  265. self.artifactPath = nil
  266. self.artifactGo = nil
  267. end
  268. if self.cardLoadSeqId then
  269. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.cardLoadSeqId)
  270. self.cardLoadSeqId = nil
  271. end
  272. if self.cardItemLua then
  273. ManagerContainer.ResMgr:RecycleGO(Constants.UIItemDir, 'CardIconBigItem', self.cardItemLua.gameObject)
  274. self.cardItemLua = nil
  275. end
  276. if self.defaultLoadSeqId then
  277. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.defaultLoadSeqId)
  278. self.defaultLoadSeqId = nil
  279. end
  280. if self.iconItemLua then
  281. ManagerContainer.ResMgr:RecycleGO(Constants.UIItemDir, 'IconItem', self.iconItemLua.gameObject)
  282. self.iconItemLua = nil
  283. end
  284. end
  285. function UISummonShowView:PetLoadComplete(modelGo)
  286. local showData = self.controller:GetShowData()
  287. local petCfgData = ManagerContainer.CfgMgr:GetPetDataById(showData.cfgId)
  288. local camPos = CommonUtil.TableToVector3(petCfgData.CamPos or {-0.116, 2.28, 3.89})
  289. local camRot = CommonUtil.TableToQuaternion(petCfgData.CamRot or {12.174, 177.372, 0.085})
  290. if not self.previewSystem then
  291. self.previewSystem = PreviewSystem:new("SummonPreviewSystem", 1024, 1024)
  292. end
  293. self.previewSystem:SetView(camPos, camRot)
  294. self.modelImg.rawImage.texture = self.previewSystem:GetRenderTexture()
  295. self.previewSystem:UpdateGo(modelGo)
  296. modelGo:SetActive(true)
  297. self.petViewSystem:RolePlayAni(modelGo, "s_click")
  298. if petCfgData then
  299. self.label:SetActive(true)
  300. self.mVP:SetActive(petCfgData.Quality == Enum.CardType.MVP)
  301. self.mini:SetActive(petCfgData.Quality == Enum.CardType.MINIBOSS)
  302. self.normal:SetActive(petCfgData.Quality == Enum.CardType.NORMAL)
  303. end
  304. self.rT:SetActive(true)
  305. self:LoadComplete()
  306. end
  307. function UISummonShowView:CardLoadComplete()
  308. self.cardLoadSeqId = nil
  309. if not self.cardItemLua then
  310. local cardItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIItemDir, 'CardIconBigItem')
  311. if cardItem then
  312. cardItem.transform:SetParent(self.item.transform)
  313. cardItem.transform.localPosition = Vector3.zero
  314. cardItem.transform.localRotation = Quaternion.identity
  315. cardItem.transform.localScale = Vector3.one
  316. self.cardItemLua = CommonUtil.BindGridViewItem2Lua(self, 'CardIconBigItem', cardItem.gameObject)
  317. end
  318. end
  319. if self.cardItemLua then
  320. self.cardItemLua:SetActive(true)
  321. local showData = self.controller:GetShowData()
  322. CardIconBigItemCtr:SetData(self, self.cardItemLua, showData)
  323. local cardData = ManagerContainer.CfgMgr:GetCardDataById(showData.cfgId)
  324. if cardData then
  325. self.label:SetActive(true)
  326. self.mVP:SetActive(cardData.CardType == Enum.CardType.MVP)
  327. self.mini:SetActive(cardData.CardType == Enum.CardType.MINIBOSS)
  328. self.normal:SetActive(cardData.CardType == Enum.CardType.NORMAL)
  329. end
  330. self.item:SetActive(true)
  331. end
  332. self:LoadComplete()
  333. end
  334. function UISummonShowView:ArtifactLoadComplete()
  335. local showData = self.controller:GetShowData()
  336. local artifactCfgData = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(showData.cfgId)
  337. if artifactCfgData then
  338. self.label:SetActive(true)
  339. self.mVP:SetActive(artifactCfgData.Quality == Enum.CardType.MVP)
  340. self.mini:SetActive(artifactCfgData.Quality == Enum.CardType.MINIBOSS)
  341. self.normal:SetActive(artifactCfgData.Quality == Enum.CardType.NORMAL)
  342. end
  343. self.artifactSeqId = nil
  344. if not self.autoRotateContainer then
  345. self.autoRotateContainer = UnityEngine.GameObject("AutoRotateContainer")
  346. local aroundSphereMove = self.autoRotateContainer:AddComponent(typeof(AroundSphereMove))
  347. aroundSphereMove.selfRotateSpeed = 50
  348. if ManagerContainer.LuaModelMgr and ManagerContainer.LuaModelMgr.ModelRoot then
  349. self.autoRotateContainer.transform:SetParent(ManagerContainer.LuaModelMgr.ModelRoot.transform)
  350. end
  351. end
  352. if not self.artifactGo then
  353. local artifactGo = ManagerContainer.ResMgr:GetGoFromPool(Constants.ModelPath, artifactCfgData.AvatarPrefab)
  354. if artifactGo then
  355. artifactGo.transform:SetParent(self.autoRotateContainer.transform)
  356. artifactGo.transform.localPosition = Vector3.zero
  357. artifactGo.transform.localRotation = Quaternion.identity
  358. artifactGo.transform.localScale = Vector3.one
  359. self.artifactGo = artifactGo
  360. self.artifactPath = artifactCfgData.AvatarPrefab
  361. end
  362. end
  363. if self.artifactGo then
  364. self.artifactGo:SetActive(true)
  365. end
  366. if not self.previewSystem then
  367. self.previewSystem = PreviewSystem:new("SummonPreviewSystem", 1024, 1024)
  368. end
  369. self.previewSystem:SetView(Vector3(0, 0, 1.435), Quaternion.Euler(0, 180, 0))
  370. self.modelImg.rawImage.texture = self.previewSystem:GetRenderTexture()
  371. self.previewSystem:UpdateGo(self.artifactGo)
  372. self.rT:SetActive(true)
  373. self:LoadComplete()
  374. end
  375. function UISummonShowView:DefaultLoadComplete()
  376. self.defaultLoadSeqId = nil
  377. if not self.iconItemLua then
  378. local iconItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIItemDir, 'IconItem')
  379. if iconItem then
  380. iconItem.transform:SetParent(self.item.transform)
  381. iconItem.transform.localPosition = Vector3.zero
  382. iconItem.transform.localRotation = Quaternion.identity
  383. iconItem.transform.localScale = Vector3.one
  384. self.iconItemLua = CommonUtil.BindGridViewItem2Lua(self, 'IconItem', iconItem.gameObject)
  385. end
  386. end
  387. if self.iconItemLua then
  388. self.iconItemLua:SetActive(true)
  389. local showData = self.controller:GetShowData()
  390. CommonUtil.UpdateItemPrefab(self, self.iconItemLua, showData, Enum.ItemIEnterType.Bag)
  391. self.item:SetActive(true)
  392. end
  393. self:LoadComplete()
  394. end
  395. function UISummonShowView:LoadComplete()
  396. self.loading = false
  397. if not self.isPageInEnd then return end
  398. self.itemShow.animator.enabled = true
  399. self.itemShow.animator:Play('ItemShow')
  400. self.particle.uIParticle:PlayCachedParticalSystem(true)
  401. self.isAniming = true
  402. if self.controller:GetCurMustShowComplete() then
  403. if not self.animTimer then
  404. self.animTimer = Timer.New(function()
  405. self.isAniming = false
  406. end, 1.3)
  407. else
  408. self.animTimer.time = 1.3
  409. self.animTimer.duration = 1.3
  410. end
  411. if not self.animTimer.running then
  412. self.animTimer:Start()
  413. end
  414. else
  415. if self.animTimer then
  416. if self.animTimer.running then
  417. self.animTimer:Stop()
  418. end
  419. end
  420. end
  421. end
  422. function UISummonShowView:NewRPLoadComplete()
  423. self.newRpSeqId = nil
  424. if not self.newRPGo then
  425. local newRPGo = ManagerContainer.ResMgr:GetGoFromPool(Constants.UICommonPath, 'UINewRP')
  426. if newRPGo then
  427. newRPGo.transform:SetParent(self.labelNew.transform)
  428. newRPGo.transform.localPosition = Vector3.zero
  429. newRPGo.transform.localRotation = Quaternion.identity
  430. newRPGo.transform.localScale = Vector3.one
  431. newRPGo:SetActive(true)
  432. self.newRPGo = newRPGo
  433. end
  434. end
  435. end
  436. function UISummonShowView:EnterResultView()
  437. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISummonResult, self.controller:GetData())
  438. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  439. end
  440. return UISummonShowView