UILuckyEggShowView.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. local UILuckyEggShowView = require("UILuckyEgg/UILuckyEggShowView_Generate")
  2. local PetViewSystem = require('PetViewSystem')
  3. local PreviewSystem = require("PreviewSystem")
  4. local CardIconBigItemCtr = require("Common/CardIconBigItemCtr")
  5. function UILuckyEggShowView:OnAwake(data)
  6. self.controller = require("UILuckyEgg/UILuckyEggShowCtr"):new()
  7. self.controller:Init(self)
  8. self.controller:SetData(data)
  9. end
  10. function UILuckyEggShowView:AddEventListener()
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  12. end
  13. function UILuckyEggShowView: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 UILuckyEggShowView:Init()
  24. self.loading = false
  25. self.isPageInEnd = false
  26. self:RefreshView()
  27. end
  28. function UILuckyEggShowView:RemoveEventListener()
  29. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  30. end
  31. function UILuckyEggShowView: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 UILuckyEggShowView:OnHide()
  36. end
  37. function UILuckyEggShowView:OnShow(data)
  38. self.controller:SetData(data)
  39. end
  40. function UILuckyEggShowView:OnClose()
  41. end
  42. function UILuckyEggShowView: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 UILuckyEggShowView: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 UILuckyEggShowView: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 UILuckyEggShowView: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 UILuckyEggShowView: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. -- else
  141. -- if itemCfgData.ResType == Enum.ItemType.Card then
  142. -- if not self.cardItemLua then
  143. -- self.cardLoadSeqId = ManagerContainer.ResMgr:LuaLoadAssets(Enum.ResourceType.GameObject, Constants.UIItemDir, {'CardIconBigItem'}, self, self.CardLoadComplete)
  144. -- if ManagerContainer.ResMgr:SeqIdEquals(self.cardLoadSeqId, 0) then
  145. -- self.cardLoadSeqId = nil
  146. -- self:CardLoadComplete()
  147. -- end
  148. -- else
  149. -- self:CardLoadComplete()
  150. -- end
  151. -- else
  152. -- if itemCfgData.ResType == Enum.ItemType.SkillEquip then
  153. -- local artifactCfgData = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(showData.cfgId)
  154. -- if not artifactCfgData then
  155. -- if self.artifactGo then
  156. -- ManagerContainer.ResMgr:RecycleGO(Constants.ModelPath, self.artifactPath, self.artifactGo)
  157. -- self.artifactPath = nil
  158. -- self.artifactGo = nil
  159. -- end
  160. -- elseif self.artifactPath ~= artifactCfgData.AvatarPrefab or not self.artifactGo then
  161. -- if self.artifactGo then
  162. -- ManagerContainer.ResMgr:RecycleGO(Constants.ModelPath, self.artifactPath, self.artifactGo)
  163. -- self.artifactPath = nil
  164. -- self.artifactGo = nil
  165. -- end
  166. -- self.artifactSeqId = ManagerContainer.ResMgr:LuaLoadAssets(Enum.ResourceType.GameObject, Constants.ModelPath, {artifactCfgData.AvatarPrefab}, self, self.ArtifactLoadComplete)
  167. -- if ManagerContainer.ResMgr:SeqIdEquals(self.artifactSeqId, 0) then
  168. -- self.artifactSeqId = nil
  169. -- self:ArtifactLoadComplete()
  170. -- end
  171. -- else
  172. -- self:ArtifactLoadComplete()
  173. -- end
  174. -- if artifactCfgData then
  175. -- self:ShowSkillEquipStar(artifactCfgData.ArtifactMaxLevel)
  176. -- end
  177. -- end
  178. if not self.iconItemLua then
  179. self.defaultLoadSeqId = ManagerContainer.ResMgr:LuaLoadAssets(Enum.ResourceType.GameObject, Constants.UIItemDir, {'IconItem'}, self, self.DefaultLoadComplete)
  180. if ManagerContainer.ResMgr:SeqIdEquals(self.defaultLoadSeqId, 0) then
  181. self.defaultLoadSeqId = nil
  182. self:DefaultLoadComplete()
  183. end
  184. else
  185. self:DefaultLoadComplete()
  186. end
  187. end
  188. --神器星级显示
  189. function UILuckyEggShowView:ClearSkillEquipStar()
  190. self:ShowSkillEquipStar()
  191. end
  192. function UILuckyEggShowView:ShowSkillEquipStar(nStartCnt)
  193. if not nStartCnt or nStartCnt <=0 then
  194. -- self.starBox:SetActive(false)
  195. else
  196. -- self.starBox:SetActive(true)
  197. -- local tbStarGroup = {}
  198. -- if nStartCnt > 5 then
  199. -- nStartCnt = 5
  200. -- end
  201. -- tbStarGroup[1] = self.star1
  202. -- tbStarGroup[2] = self.star2
  203. -- tbStarGroup[3] = self.star3
  204. -- tbStarGroup[4] = self.star4
  205. -- tbStarGroup[5] = self.star5
  206. -- for i = 1,#tbStarGroup do
  207. -- local bIsShow = false
  208. -- bIsShow = nStartCnt >= i
  209. -- tbStarGroup[i]:SetActive(bIsShow)
  210. -- end
  211. end
  212. end
  213. function UILuckyEggShowView:ClearLastShow()
  214. if self.previewSystem then
  215. self.previewSystem:RemoveAllGo()
  216. end
  217. self.rT:SetActive(false)
  218. self.item:SetActive(false)
  219. self.modelImg.rawImage.texture = nil
  220. if self.petViewSystem then
  221. self.petViewSystem:Recycle()
  222. end
  223. if self.artifactSeqId then
  224. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.artifactSeqId)
  225. self.artifactSeqId = nil
  226. end
  227. if self.cardLoadSeqId then
  228. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.cardLoadSeqId)
  229. self.cardLoadSeqId = nil
  230. end
  231. if self.defaultLoadSeqId then
  232. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.defaultLoadSeqId)
  233. self.defaultLoadSeqId = nil
  234. end
  235. if self.cardItemLua then
  236. self.cardItemLua:SetActive(false)
  237. end
  238. if self.iconItemLua then
  239. self.iconItemLua:SetActive(false)
  240. end
  241. self:ClearSkillEquipStar()
  242. end
  243. function UILuckyEggShowView:DisposeShow()
  244. if self.previewSystem then
  245. self.previewSystem:Dispose()
  246. self.previewSystem = nil
  247. end
  248. if self.petViewSystem then
  249. self.petViewSystem:Dispose()
  250. self.petViewSystem = nil
  251. end
  252. self.modelImg.rawImage.texture = nil
  253. if self.newRpSeqId then
  254. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.newRpSeqId)
  255. self.newRpSeqId = nil
  256. end
  257. if self.newRPGo then
  258. ManagerContainer.ResMgr:RecycleGO(Constants.UICommonPath, 'UINewRP', self.newRPGo.gameObject)
  259. self.newRPGo = nil
  260. end
  261. if self.autoRotateContainer then
  262. UnityEngine.GameObject.Destroy(self.autoRotateContainer)
  263. end
  264. if self.artifactGo then
  265. ManagerContainer.ResMgr:RecycleGO(Constants.ModelPath, self.artifactPath, self.artifactGo)
  266. self.artifactPath = nil
  267. self.artifactGo = nil
  268. end
  269. if self.cardLoadSeqId then
  270. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.cardLoadSeqId)
  271. self.cardLoadSeqId = nil
  272. end
  273. if self.cardItemLua then
  274. ManagerContainer.ResMgr:RecycleGO(Constants.UIItemDir, 'CardIconBigItem', self.cardItemLua.gameObject)
  275. self.cardItemLua = nil
  276. end
  277. if self.defaultLoadSeqId then
  278. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.defaultLoadSeqId)
  279. self.defaultLoadSeqId = nil
  280. end
  281. if self.iconItemLua then
  282. ManagerContainer.ResMgr:RecycleGO(Constants.UIItemDir, 'IconItem', self.iconItemLua.gameObject)
  283. self.iconItemLua = nil
  284. end
  285. end
  286. function UILuckyEggShowView:PetLoadComplete(modelGo)
  287. local showData = self.controller:GetShowData()
  288. local petCfgData = ManagerContainer.CfgMgr:GetPetDataById(showData.cfgId)
  289. local camPos = CommonUtil.TableToVector3(petCfgData.CamPos or {-0.116, 2.28, 3.89})
  290. local camRot = CommonUtil.TableToQuaternion(petCfgData.CamRot or {12.174, 177.372, 0.085})
  291. if not self.previewSystem then
  292. self.previewSystem = PreviewSystem:new("LuckyEggPreviewSystem", 1024, 1024)
  293. end
  294. self.previewSystem:SetView(camPos, camRot)
  295. self.modelImg.rawImage.texture = self.previewSystem:GetRenderTexture()
  296. self.previewSystem:UpdateGo(modelGo)
  297. modelGo:SetActive(true)
  298. self.petViewSystem:RolePlayAni(modelGo, "s_click")
  299. if petCfgData then
  300. self.label:SetActive(true)
  301. self.mVP:SetActive(petCfgData.Quality == Enum.CardType.MVP)
  302. self.mini:SetActive(petCfgData.Quality == Enum.CardType.MINIBOSS)
  303. self.normal:SetActive(petCfgData.Quality == Enum.CardType.NORMAL)
  304. end
  305. self.rT:SetActive(true)
  306. self:LoadComplete()
  307. end
  308. function UILuckyEggShowView:CardLoadComplete()
  309. self.cardLoadSeqId = nil
  310. if not self.cardItemLua then
  311. local cardItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIItemDir, 'CardIconBigItem')
  312. if cardItem then
  313. cardItem.transform:SetParent(self.item.transform)
  314. cardItem.transform.localPosition = Vector3.zero
  315. cardItem.transform.localRotation = Quaternion.identity
  316. cardItem.transform.localScale = Vector3.one
  317. self.cardItemLua = CommonUtil.BindGridViewItem2Lua(self, 'CardIconBigItem', cardItem.gameObject)
  318. end
  319. end
  320. if self.cardItemLua then
  321. self.cardItemLua:SetActive(true)
  322. local showData = self.controller:GetShowData()
  323. CardIconBigItemCtr:SetData(self, self.cardItemLua, showData)
  324. local cardData = ManagerContainer.CfgMgr:GetCardDataById(showData.cfgId)
  325. if cardData then
  326. self.label:SetActive(true)
  327. self.mVP:SetActive(cardData.CardType == Enum.CardType.MVP)
  328. self.mini:SetActive(cardData.CardType == Enum.CardType.MINIBOSS)
  329. self.normal:SetActive(cardData.CardType == Enum.CardType.NORMAL)
  330. end
  331. self.item:SetActive(true)
  332. end
  333. self:LoadComplete()
  334. end
  335. function UILuckyEggShowView:ArtifactLoadComplete()
  336. local showData = self.controller:GetShowData()
  337. local artifactCfgData = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(showData.cfgId)
  338. if artifactCfgData then
  339. self.label:SetActive(true)
  340. self.mVP:SetActive(artifactCfgData.Quality == Enum.CardType.MVP)
  341. self.mini:SetActive(artifactCfgData.Quality == Enum.CardType.MINIBOSS)
  342. self.normal:SetActive(artifactCfgData.Quality == Enum.CardType.NORMAL)
  343. end
  344. self.artifactSeqId = nil
  345. if not self.autoRotateContainer then
  346. self.autoRotateContainer = UnityEngine.GameObject("AutoRotateContainer")
  347. local aroundSphereMove = self.autoRotateContainer:AddComponent(typeof(AroundSphereMove))
  348. aroundSphereMove.selfRotateSpeed = 50
  349. if ManagerContainer.LuaModelMgr and ManagerContainer.LuaModelMgr.ModelRoot then
  350. self.autoRotateContainer.transform:SetParent(ManagerContainer.LuaModelMgr.ModelRoot.transform)
  351. end
  352. end
  353. if not self.artifactGo then
  354. local artifactGo = ManagerContainer.ResMgr:GetGoFromPool(Constants.ModelPath, artifactCfgData.AvatarPrefab)
  355. if artifactGo then
  356. artifactGo.transform:SetParent(self.autoRotateContainer.transform)
  357. artifactGo.transform.localPosition = Vector3.zero
  358. artifactGo.transform.localRotation = Quaternion.identity
  359. artifactGo.transform.localScale = Vector3.one
  360. self.artifactGo = artifactGo
  361. self.artifactPath = artifactCfgData.AvatarPrefab
  362. end
  363. end
  364. if self.artifactGo then
  365. self.artifactGo:SetActive(true)
  366. end
  367. if not self.previewSystem then
  368. self.previewSystem = PreviewSystem:new("LuckyEggPreviewSystem", 1024, 1024)
  369. end
  370. self.previewSystem:SetView(Vector3(0, 0, 1.435), Quaternion.Euler(0, 180, 0))
  371. self.modelImg.rawImage.texture = self.previewSystem:GetRenderTexture()
  372. self.previewSystem:UpdateGo(self.artifactGo)
  373. self.rT:SetActive(true)
  374. self:LoadComplete()
  375. end
  376. function UILuckyEggShowView:DefaultLoadComplete()
  377. self.defaultLoadSeqId = nil
  378. if not self.iconItemLua then
  379. local iconItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIItemDir, 'IconItem')
  380. if iconItem then
  381. iconItem.transform:SetParent(self.item.transform)
  382. iconItem.transform.localPosition = Vector3.zero
  383. iconItem.transform.localRotation = Quaternion.identity
  384. iconItem.transform.localScale = Vector3.one
  385. self.iconItemLua = CommonUtil.BindGridViewItem2Lua(self, 'IconItem', iconItem.gameObject)
  386. end
  387. end
  388. if self.iconItemLua then
  389. self.iconItemLua:SetActive(true)
  390. local showData = self.controller:GetShowData()
  391. CommonUtil.UpdateItemPrefab(self, self.iconItemLua, showData, Enum.ItemIEnterType.Bag)
  392. self.item:SetActive(true)
  393. end
  394. self:LoadComplete()
  395. end
  396. function UILuckyEggShowView:LoadComplete()
  397. self.loading = false
  398. if not self.isPageInEnd then return end
  399. self.itemShow.animator.enabled = true
  400. self.itemShow.animator:Play('ItemShow')
  401. self.particle.uIParticle:PlayCachedParticalSystem(true)
  402. self.isAniming = true
  403. if self.controller:GetCurMustShowComplete() then
  404. if not self.animTimer then
  405. self.animTimer = Timer.New(function()
  406. self.isAniming = false
  407. end, 1.3)
  408. else
  409. self.animTimer.time = 1.3
  410. self.animTimer.duration = 1.3
  411. end
  412. if not self.animTimer.running then
  413. self.animTimer:Start()
  414. end
  415. else
  416. if self.animTimer then
  417. if self.animTimer.running then
  418. self.animTimer:Stop()
  419. end
  420. end
  421. end
  422. end
  423. function UILuckyEggShowView:NewRPLoadComplete()
  424. self.newRpSeqId = nil
  425. if not self.newRPGo then
  426. local newRPGo = ManagerContainer.ResMgr:GetGoFromPool(Constants.UICommonPath, 'UINewRP')
  427. if newRPGo then
  428. newRPGo.transform:SetParent(self.labelNew.transform)
  429. newRPGo.transform.localPosition = Vector3.zero
  430. newRPGo.transform.localRotation = Quaternion.identity
  431. newRPGo.transform.localScale = Vector3.one
  432. newRPGo:SetActive(true)
  433. self.newRPGo = newRPGo
  434. end
  435. end
  436. end
  437. function UILuckyEggShowView:EnterResultView()
  438. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggResult, self.controller:GetData())
  439. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  440. end
  441. return UILuckyEggShowView