UILuckyEggResultView.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. ---@diagnostic disable: undefined-field
  2. local UILuckyEggResultView = require("UILuckyEgg/UILuckyEggResultView_Generate")
  3. local MultiTypeAssetLoadSystem = require('MultiTypeAssetLoadSystem')
  4. local OnePoss = Vector3.zero
  5. local FivePoss = {
  6. Vector3(-240, 90), Vector3(0, 90), Vector3(240, 90), Vector3(-120, -120), Vector3(120, -120)
  7. }
  8. function UILuckyEggResultView:OnAwake(data)
  9. self.controller = require("UILuckyEgg/UILuckyEggResultCtr"):new()
  10. self.controller:Init(self)
  11. self.controller:SetData(data)
  12. end
  13. function UILuckyEggResultView:AddEventListener()
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ITEM_CHANGE, self, self.OnItemChanged)
  15. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.DIAMOND_CHANGED, self, self.OnDiamondChanged)
  16. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.LUCKYEGG_DATA_CHANGED, self, self.OnLuckyEggDataChanged)
  17. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_CLOSE_COMPELETED, self, self.OnUICloseCompleted)
  18. end
  19. function UILuckyEggResultView:FillContent(data, uiBase)
  20. self.uiBase = uiBase
  21. local gameObject = self.uiBase:GetRoot()
  22. if gameObject ~= nil then
  23. self.gameObject = gameObject
  24. self.transform = gameObject.transform
  25. end
  26. self:InitGenerate(self.transform, data)
  27. self:Init()
  28. end
  29. function UILuckyEggResultView:Init()
  30. self.controller:InitData()
  31. self.isPageInEnd = false
  32. self.animing = nil
  33. self.needAnim = nil
  34. if not self.loadSystem then
  35. self.loadSystem = MultiTypeAssetLoadSystem:new()
  36. self.loadSystem:SetCompleteCB(self, self.LoadedAssets)
  37. end
  38. self.loadSystem:Cancel()
  39. self.currency:SetActive(false)
  40. self:RefreshTopCurrency()
  41. self:RefreshCostCurrency()
  42. self:PreLoadAssets()
  43. end
  44. function UILuckyEggResultView:RemoveEventListener()
  45. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  46. end
  47. function UILuckyEggResultView:AddUIEventListener()
  48. self.uiBase:AddButtonUniqueEventListener(self.btnConfirm.button, self, self.OnClickConfirmBtn)
  49. self.uiBase:AddButtonUniqueEventListener(self.btnOne.button, self, self.OnClickLuckyEggBtn, 1)
  50. self.uiBase:AddButtonUniqueEventListener(self.btnTen.button, self, self.OnClickLuckyEggBtn, 2)
  51. end
  52. function UILuckyEggResultView:OnHide()
  53. end
  54. function UILuckyEggResultView:OnShow(data)
  55. if data then
  56. self.controller:SetData(data)
  57. end
  58. end
  59. function UILuckyEggResultView:OnClose()
  60. end
  61. function UILuckyEggResultView:OnDispose()
  62. self.isPageInEnd = nil
  63. if self.loadSystem then
  64. self.loadSystem:Dispose()
  65. self.loadSystem = nil
  66. end
  67. DG.Tweening.DOTween.Kill(self.extraRewardItem.rewardSlider.slider)
  68. if self.sliderAnimTimer then
  69. self.sliderAnimTimer:Stop()
  70. self.sliderAnimTimer = nil
  71. end
  72. if self.fxTimer then
  73. self.fxTimer:Stop()
  74. self.fxTimer = nil
  75. end
  76. if self.extraRewardTimer then
  77. self.extraRewardTimer:Stop()
  78. self.extraRewardTimer = nil
  79. end
  80. self.animing = nil
  81. self.needAnim = nil
  82. self:DisposeIconItems()
  83. self:DisposeIconLightPurples()
  84. self:DisposeIconLightGolds()
  85. self:DisposeIconLightReds()
  86. self:DisposeRedPoints()
  87. self:DisposeCurrency()
  88. self.controller:OnDispose()
  89. end
  90. function UILuckyEggResultView:OnPageInEnd()
  91. self.super.OnPageInEnd(self)
  92. self.isPageInEnd = true
  93. self:StartRewardAnim()
  94. end
  95. function UILuckyEggResultView:OnItemChanged()
  96. self:RefreshTopCurrency()
  97. self:RefreshCostCurrency()
  98. end
  99. function UILuckyEggResultView:OnDiamondChanged()
  100. self:RefreshTopCurrency()
  101. self:RefreshCostCurrency()
  102. end
  103. function UILuckyEggResultView:OnLuckyEggDataChanged()
  104. if not self.isPageInEnd or self.animing then return end
  105. if not ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UILuckyEggResult) then
  106. return
  107. end
  108. if not ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UILuckyEggAnim) then
  109. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggAnim)
  110. else
  111. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.LUCKYEGG_AGAIN_DATA_CHANGED)
  112. self:UIClose()
  113. end
  114. end
  115. function UILuckyEggResultView:OnUICloseCompleted(owner)
  116. if owner.uiData.id ~= Enum.UIPageName.UIRuneShopBT then return end
  117. if ManagerContainer.LuaUIMgr:PageInHideStack(self.uiBase) then
  118. ManagerContainer.LuaUIMgr:Show(Enum.UIPageName.UILuckyEggResult)
  119. end
  120. end
  121. function UILuckyEggResultView:OnClickCurrencyBuyBtn(_, params)
  122. if not self.isPageInEnd or self.animing then return end
  123. local cfgId = params[0]
  124. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  125. if not itemCfgData then return end
  126. if itemCfgData.ResType == Enum.ItemType.Diamond then
  127. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UILuckyEggAnim) then
  128. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold}, Enum.UIPageName.UILuckyEggAnim)
  129. ManagerContainer.LuaUIMgr:Hide(Enum.UIPageName.UILuckyEggResult)
  130. else
  131. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold})
  132. self:UIClose()
  133. end
  134. end
  135. end
  136. function UILuckyEggResultView:OnClickConfirmBtn()
  137. if not self.isPageInEnd or self.animing then return end
  138. self:UIClose()
  139. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UILuckyEggAnim)
  140. end
  141. function UILuckyEggResultView:SureBuy(idx)
  142. local errorCode, LuckyEggNum, remainLuckyEggNum, vaildCosts = self.controller:GetSendLuckyEggReqErrorCode(idx)
  143. if errorCode == 0 then
  144. errorCode = self.controller:SendLuckyEggReq(LuckyEggNum)
  145. if errorCode ~= 0 then
  146. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  147. end
  148. elseif errorCode == 1 then
  149. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  150. elseif errorCode == 2 then
  151. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  152. elseif errorCode == 3 then
  153. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  154. elseif errorCode == 4 then
  155. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  156. else
  157. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  158. end
  159. end
  160. function UILuckyEggResultView:SureJumpBuy(idx)
  161. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UILuckyEggAnim) then
  162. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold}, Enum.UIPageName.UILuckyEggAnim)
  163. ManagerContainer.LuaUIMgr:Hide(Enum.UIPageName.UILuckyEggResult)
  164. else
  165. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold})
  166. self:UIClose()
  167. end
  168. end
  169. function UILuckyEggResultView:OnClickLuckyEggBtn(_, params)
  170. if not self.isPageInEnd or self.animing then return end
  171. local idx = params[0]
  172. local errorCode, LuckyEggNum, remainLuckyEggNum, vaildCosts = self.controller:GetSendLuckyEggReqErrorCode(idx)
  173. if errorCode == 0 then
  174. local len = #vaildCosts
  175. if len > 1 then
  176. local vaildCost = vaildCosts[len]
  177. local cfgId = vaildCost[1]
  178. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  179. if itemCfgData.ResType == Enum.ItemType.Diamond and vaildCost[4] < LuckyEggNum then
  180. local paramData = {}
  181. local vaildCost2 = vaildCosts[1]
  182. local cfgId2 = vaildCost2[1]
  183. local itemCfgData2 = ManagerContainer.CfgMgr:GetItemById(cfgId2)
  184. paramData[1] = itemCfgData2 and string.formatbykey(itemCfgData2.Name) or ''
  185. paramData[2] = string.formatbykey('Supplementary', tostring(vaildCost[3] * vaildCost[4]), itemCfgData and string.formatbykey(itemCfgData.Name) or '', tostring(vaildCost[4]), paramData[1])
  186. local data = {"LuckyEggNoItemTip", paramData, idx, self, self.SureBuy}
  187. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  188. else
  189. errorCode = self.controller:SendLuckyEggReq(LuckyEggNum)
  190. if errorCode ~= 0 then
  191. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  192. end
  193. end
  194. else
  195. errorCode = self.controller:SendLuckyEggReq(LuckyEggNum)
  196. if errorCode ~= 0 then
  197. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  198. end
  199. end
  200. elseif errorCode == 1 then
  201. local len = #vaildCosts
  202. if len >= 1 then
  203. local vaildCost = vaildCosts[len]
  204. if Constant.OpenPay then
  205. local cfgId = vaildCost[1]
  206. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  207. if itemCfgData.ResType == Enum.ItemType.Diamond then
  208. local data = {"NoDiamondTip", nil, idx, self, self.SureJumpBuy}
  209. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  210. return
  211. elseif itemCfgData.ResType == Enum.ItemType.ROCoin then
  212. local data = {"NoRoDiamondTip", nil, idx, self, self.SureJumpBuy}
  213. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  214. return
  215. end
  216. end
  217. end
  218. local vaildCost = vaildCosts[1]
  219. local cfgId = vaildCost[1]
  220. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  221. ManagerContainer.LuaUIMgr:ErrorNoticeDisplayWithParam('InsufficientQuantity', itemCfgData and string.formatbykey(itemCfgData.Name) or '', '')
  222. elseif errorCode == 2 then
  223. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  224. elseif errorCode == 3 then
  225. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  226. elseif errorCode == 4 then
  227. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  228. else
  229. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  230. end
  231. end
  232. function UILuckyEggResultView:OnClickIconItem(_, params)
  233. if not self.isPageInEnd or self.animing then return end
  234. local data = params[0]
  235. ManagerContainer.LuaUIMgr:OpenTips(data)
  236. end
  237. function UILuckyEggResultView:PreLoadAssets()
  238. self.loadSystem:Cancel()
  239. local rewards = self.controller:GetRewards()
  240. local hasNew, hasRed, hasGold, hasPurple, hasExtra
  241. for i = 1, #rewards do
  242. local reward = rewards[i]
  243. local quality1, quality2 = self.controller:GetShowQuality(reward.cfgId)
  244. if quality1 == 3 then
  245. hasRed = true
  246. elseif quality1 == 2 then
  247. hasGold = true
  248. elseif quality1 == 1 then
  249. hasPurple = true
  250. end
  251. end
  252. if self.controller:IsHasExtra() then
  253. self.bG.animator:Play('ExtraKeep')
  254. local lastPrecent = self.controller:GetLastLuckyEggPercent()
  255. self.extraRewardItem.rewardSlider.slider.value = lastPrecent
  256. local LuckyEggNum = self.controller:GetLuckyEggNum()
  257. local validPercent = CommonUtil.GetPreciseDecimal(lastPrecent * 100)
  258. if validPercent <= 0 and LuckyEggNum > 0 then
  259. validPercent = 1
  260. end
  261. self.extraRewardItem.percentTxt.text.text = tostring(validPercent) .. '%'
  262. local extraReward = self.controller:GetExtraReward()
  263. if extraReward then
  264. local quality1, quality2 = self.controller:GetShowQuality(extraReward.cfgId)
  265. if quality1 == 3 then
  266. hasRed = true
  267. elseif quality1 == 2 then
  268. hasGold = true
  269. elseif quality1 == 1 then
  270. hasPurple = true
  271. end
  272. hasExtra = true
  273. end
  274. else
  275. self.bG.animator:Play('NoExtraKeep')
  276. end
  277. self.loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, Constants.UIItemDir, 'IconItem')
  278. if hasRed then
  279. self.loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, Constants.UIPath, 'UISummon/IconLightRed')
  280. end
  281. if hasGold then
  282. self.loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, Constants.UIPath, 'UISummon/IconLightGold')
  283. end
  284. if hasPurple then
  285. self.loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, Constants.UIPath, 'UISummon/IconLightPurple')
  286. end
  287. if hasNew then
  288. self.loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, Constants.UICommonPath, 'UINewRP')
  289. end
  290. if hasExtra then
  291. self.loadSystem:AddLoadAsset(Enum.ResourceType.GameObject, Constants.UIEffectPath, 'FX_UI_MVP_01')
  292. end
  293. self.loadSystem:Begin()
  294. end
  295. function UILuckyEggResultView:LoadedAssets()
  296. local rewards = self.controller:GetRewards()
  297. local rewardNum = #rewards
  298. if rewardNum > 5 then
  299. rewardNum = 5
  300. end
  301. self.iconItemIdx = 0
  302. if not self.rewardIconItems then
  303. self.rewardIconItems = {}
  304. end
  305. self.lightRedIdx = 0
  306. if not self.rewardLightReds then
  307. self.rewardLightReds = {}
  308. end
  309. self.lightGoldIdx = 0
  310. if not self.rewardLightGolds then
  311. self.rewardLightGolds = {}
  312. end
  313. self.lightPurpleIdx = 0
  314. if not self.rewardLightPurples then
  315. self.rewardLightPurples = {}
  316. end
  317. self.newRPIdx = 0
  318. if not self.newRPGos then
  319. self.newRPGos = {}
  320. end
  321. if rewardNum == 1 then
  322. self:AddReward(rewards[1], OnePoss, self)
  323. else
  324. for i = 1, rewardNum do
  325. self:AddReward(rewards[i], FivePoss[i], self)
  326. end
  327. end
  328. if self.controller:IsHasExtra() then
  329. self.bG.animator:Play('ExtraKeep')
  330. local lastPrecent = self.controller:GetLastLuckyEggPercent()
  331. self.extraRewardItem.rewardSlider.slider.value = lastPrecent
  332. local LuckyEggNum = self.controller:GetLuckyEggNum()
  333. local validPercent = CommonUtil.GetPreciseDecimal(lastPrecent * 100)
  334. if validPercent <= 0 and LuckyEggNum > 0 then
  335. validPercent = 1
  336. end
  337. self.extraRewardItem.percentTxt.text.text = tostring(validPercent) .. '%'
  338. local extraReward = self.controller:GetExtraReward()
  339. if extraReward then
  340. self:AddReward(extraReward, Vector3.zero, self.extraAnim)
  341. end
  342. self.needAnim = true
  343. self:StartRewardAnim()
  344. else
  345. self.needAnim = false
  346. self.bG.animator:Play('NoExtraKeep')
  347. end
  348. for i = self.iconItemIdx + 1, #self.rewardIconItems do
  349. if self.rewardIconItems[i] then
  350. self.rewardIconItems:SetActive(false)
  351. end
  352. end
  353. for i = self.lightRedIdx + 1, #self.rewardLightReds do
  354. if self.rewardLightReds[i] then
  355. self.rewardLightReds:SetActive(false)
  356. end
  357. end
  358. for i = self.lightGoldIdx + 1, #self.rewardLightGolds do
  359. if self.rewardLightGolds[i] then
  360. self.rewardLightGolds:SetActive(false)
  361. end
  362. end
  363. for i = self.lightPurpleIdx + 1, #self.rewardLightPurples do
  364. if self.rewardLightPurples[i] then
  365. self.rewardLightPurples:SetActive(false)
  366. end
  367. end
  368. for i = self.newRPIdx + 1, #self.newRPGos do
  369. if self.newRPGos[i] then
  370. self.newRPGos:SetActive(false)
  371. end
  372. end
  373. end
  374. function UILuckyEggResultView:AddReward(reward, pos, parent)
  375. local idx = self.iconItemIdx + 1
  376. local iconItem = self.rewardIconItems[idx]
  377. if not iconItem then
  378. local iconItemGo = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIItemDir, 'IconItem')
  379. if iconItemGo then
  380. iconItem = CommonUtil.BindGridViewItem2Lua(self, 'IconItem', iconItemGo)
  381. self.rewardIconItems[idx] = iconItem
  382. end
  383. end
  384. if iconItem then
  385. iconItem.transform:SetParent(parent.iconParent.transform)
  386. iconItem.transform.localPosition = pos
  387. iconItem.transform.localRotation = Quaternion.identity
  388. iconItem.transform.localScale = Vector3.one
  389. CommonUtil.UpdateItemPrefab(self, iconItem, reward, Enum.ItemIEnterType.Egg, self, self.OnClickIconItem)
  390. iconItem:SetActive(true)
  391. self.iconItemIdx = idx
  392. end
  393. local quality1, quality2 = self.controller:GetShowQuality(reward.cfgId)
  394. if quality1 == 3 then
  395. self.lightRedIdx = self:AddLight(self.rewardLightReds, self.lightRedIdx, parent, pos, quality2, 'UISummon/IconLightRed')
  396. elseif quality1 == 2 then
  397. self.lightGoldIdx = self:AddLight(self.rewardLightGolds, self.lightGoldIdx, parent, pos, quality2, 'UISummon/IconLightGold')
  398. elseif quality1 == 1 then
  399. self.lightPurpleIdx = self:AddLight(self.rewardLightPurples, self.lightPurpleIdx, parent, pos, quality2, 'UISummon/IconLightPurple')
  400. end
  401. if reward.isNew then
  402. self:AddNew(parent, pos)
  403. end
  404. end
  405. function UILuckyEggResultView:AddLight(lights, lastLightIdx, parent, pos, isCircle, prefabName)
  406. local lightIdx = lastLightIdx + 1
  407. local light = lights[lightIdx]
  408. if not light then
  409. local lightGo = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, prefabName)
  410. if lightGo then
  411. light = CommonUtil.BindGridViewItem2Lua(self, 'IconLight', lightGo)
  412. lights[lightIdx] = light
  413. end
  414. end
  415. if light then
  416. light.transform:SetParent(parent.iconLightParent.transform)
  417. light.transform.localPosition = pos
  418. light.transform.localRotation = Quaternion.identity
  419. light.transform.localScale = Vector3.one
  420. light.lightCircle:SetActive(isCircle)
  421. light:SetActive(true)
  422. else
  423. lightIdx = lastLightIdx
  424. end
  425. return lightIdx
  426. end
  427. function UILuckyEggResultView:AddNew(parent, pos)
  428. local newRPIdx = self.newRPIdx + 1
  429. local newRPGo = self.newRPGos[newRPIdx]
  430. if not newRPGo then
  431. newRPGo = ManagerContainer.ResMgr:GetGoFromPool(Constants.UICommonPath, 'UINewRP')
  432. self.newRPGos[newRPIdx] = newRPGo
  433. end
  434. if newRPGo then
  435. newRPGo.transform:SetParent(parent.iconIsNewParent.transform)
  436. newRPGo.transform.localPosition = pos + Vector3(80, 80, 0)
  437. newRPGo.transform.localRotation = Quaternion.identity
  438. newRPGo.transform.localScale = Vector3.one
  439. newRPGo:SetActive(true)
  440. self.newRPIdx = newRPIdx
  441. end
  442. end
  443. function UILuckyEggResultView:StartRewardAnim()
  444. if not self.isPageInEnd then return end
  445. if not self.controller:IsHasExtra() then return end
  446. if not self.needAnim then return end
  447. self.needAnim = false
  448. local lastPrecent = self.controller:GetLastLuckyEggPercent()
  449. local curPrecent = self.controller:GetLuckyEggPercent()
  450. self.extraRewardItem.rewardSlider.slider.value = lastPrecent
  451. local function OnUpdate()
  452. local LuckyEggNum = self.controller:GetLuckyEggNum()
  453. local percent = self.extraRewardItem.rewardSlider.slider.value
  454. local validPercent = CommonUtil.GetPreciseDecimal(percent * 100)
  455. if validPercent <= 0 and LuckyEggNum > 0 then
  456. validPercent = 1
  457. end
  458. self.extraRewardItem.percentTxt.text.text = tostring(validPercent) .. '%'
  459. end
  460. OnUpdate()
  461. local time = (curPrecent - lastPrecent) * 10
  462. self.extraRewardItem.rewardSlider.slider:DOValue(curPrecent, time):OnUpdate(OnUpdate):OnComplete(OnUpdate)
  463. self.animing = true
  464. if not self.sliderAnimTimer then
  465. self.sliderAnimTimer = Timer.New(slot(self.ShowFx, self), time)
  466. else
  467. self.sliderAnimTimer.time = time
  468. self.sliderAnimTimer.duration = time
  469. end
  470. if not self.sliderAnimTimer.running then
  471. self.sliderAnimTimer:Start()
  472. end
  473. end
  474. function UILuckyEggResultView:ShowFx()
  475. local extraReward = self.controller:GetExtraReward()
  476. if not extraReward then
  477. self:ShowExtraReward()
  478. return
  479. end
  480. if not self.extraFxGo then
  481. self:ShowExtraReward()
  482. return
  483. end
  484. if not self.fxTimer then
  485. self.fxTimer = Timer.New(slot(self.ShowExtraReward, self), 1)
  486. else
  487. self.fxTimer.time = 1
  488. self.fxTimer.duration = 1
  489. end
  490. if not self.fxTimer.running then
  491. self.fxTimer:Start()
  492. end
  493. self.extraFxGo:SetActive(true)
  494. end
  495. function UILuckyEggResultView:ShowExtraReward()
  496. if self.extraFxGo then
  497. self.extraFxGo:SetActive(false)
  498. end
  499. local extraReward = self.controller:GetExtraReward()
  500. if not extraReward then
  501. self.animing = false
  502. return
  503. end
  504. self.bG.animator:Play('ExtraShow')
  505. if not self.extraRewardTimer then
  506. self.extraRewardTimer = Timer.New(function()
  507. self.animing = false
  508. end, 1)
  509. else
  510. self.extraRewardTimer.time = 1
  511. self.extraRewardTimer.duration = 1
  512. end
  513. if not self.extraRewardTimer.running then
  514. self.extraRewardTimer:Start()
  515. end
  516. end
  517. function UILuckyEggResultView:DisposeIconItems()
  518. if not self.rewardIconItems then return end
  519. for _, iconItem in pairs(self.rewardIconItems) do
  520. -- 常用,所以回收到对象池
  521. ManagerContainer.ResMgr:RecycleGO(Constants.UIItemDir, 'IconItem', iconItem.gameObject)
  522. end
  523. self.iconItemIdx = nil
  524. self.rewardIconItems = nil
  525. end
  526. function UILuckyEggResultView:DisposeIconLightPurples()
  527. if not self.rewardLightPurples then return end
  528. for _, lightPurple in pairs(self.rewardLightPurples) do
  529. CommonUtil.DestroyGO(lightPurple.gameObject)
  530. end
  531. self.lightPurpleIdx = nil
  532. self.rewardLightPurples = nil
  533. end
  534. function UILuckyEggResultView:DisposeIconLightGolds()
  535. if not self.rewardLightGolds then return end
  536. for _, lightGold in pairs(self.rewardLightGolds) do
  537. CommonUtil.DestroyGO(lightGold.gameObject)
  538. end
  539. self.lightGoldIdx = nil
  540. self.rewardLightGolds = nil
  541. end
  542. function UILuckyEggResultView:DisposeIconLightReds()
  543. if not self.rewardLightReds then return end
  544. for _, lightRed in pairs(self.rewardLightReds) do
  545. CommonUtil.DestroyGO(lightRed.gameObject)
  546. end
  547. self.lightRedIdx = nil
  548. self.rewardLightReds = nil
  549. end
  550. function UILuckyEggResultView:DisposeRedPoints()
  551. if not self.newRPGos then return end
  552. for _, newRPGo in pairs(self.newRPGos) do
  553. -- 常用,所以回收到对象池
  554. ManagerContainer.ResMgr:RecycleGO(Constants.UICommonPath, 'UINewRP', newRPGo.gameObject)
  555. end
  556. self.newRPIdx = nil
  557. self.newRPGos = nil
  558. end
  559. function UILuckyEggResultView:RefreshTopCurrency()
  560. local cfg = self.controller:GetCfgData()
  561. local costs = cfg.Cost
  562. local num = costs and #costs or 0
  563. local length = 0
  564. if not self.currencys then
  565. self.currencys = {}
  566. else
  567. length = #self.currencys
  568. end
  569. local currency = nil
  570. local parent = self.currency.transform.parent
  571. for i = 1, num do
  572. if i <= length then
  573. currency = self.currencys[i]
  574. else
  575. currency = CommonUtil.Instantiate(self.currency.gameObject, parent)
  576. if tolua.getpeer(currency) == nil then
  577. tolua.setpeer(currency, {})
  578. end
  579. local icon = currency.transform:Find('Icon').gameObject
  580. if tolua.getpeer(icon) == nil then
  581. tolua.setpeer(icon, {})
  582. end
  583. icon.image = icon:GetComponent(Enum.TypeInfo.Image)
  584. currency.icon = icon
  585. local number = currency.transform:Find('Number').gameObject
  586. if tolua.getpeer(number) == nil then
  587. tolua.setpeer(number, {})
  588. end
  589. number.text = number:GetComponent(Enum.TypeInfo.Text)
  590. currency.number = number
  591. local btnBuy = currency.transform:Find('BtnBuy').gameObject
  592. if tolua.getpeer(btnBuy) == nil then
  593. tolua.setpeer(btnBuy, {})
  594. end
  595. btnBuy.button = btnBuy:GetComponent(Enum.TypeInfo.Button)
  596. currency.btnBuy = btnBuy
  597. self.currencys[i] = currency
  598. end
  599. currency:SetActive(true)
  600. currency.icon.image.enabled = false
  601. currency.icon.image.sprite = nil
  602. local cfgId = tonumber(costs[i][1])
  603. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  604. if itemCfgData then
  605. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function(sprite)
  606. if sprite then
  607. currency.icon.image.sprite = sprite
  608. currency.icon.image.enabled = true
  609. end
  610. end)
  611. if itemCfgData.ResType == Enum.ItemType.Diamond then
  612. currency.btnBuy:SetActive(Constant.OpenPay)
  613. self.uiBase:AddButtonUniqueEventListener(currency.btnBuy.button, self, self.OnClickCurrencyBuyBtn, cfgId)
  614. else
  615. currency.btnBuy:SetActive(false)
  616. currency.btnBuy.button.onClick:RemoveAllListeners()
  617. end
  618. else
  619. currency.btnBuy:SetActive(false)
  620. currency.btnBuy.button.onClick:RemoveAllListeners()
  621. end
  622. currency.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(cfgId))
  623. end
  624. for i = num + 1, length do
  625. currency = self.currencys[i]
  626. currency:SetActive(false)
  627. currency.btnBuy:SetActive(false)
  628. currency.btnBuy.button.onClick:RemoveAllListeners()
  629. end
  630. end
  631. function UILuckyEggResultView:DisposeCurrency()
  632. if not self.currencys then return end
  633. for _, currency in pairs(self.currencys) do
  634. CommonUtil.DestroyGO(currency)
  635. if tolua.getpeer(currency.btnBuy) ~= nil then
  636. tolua.setpeer(currency.btnBuy, nil)
  637. end
  638. if tolua.getpeer(currency.number) ~= nil then
  639. tolua.setpeer(currency.number, nil)
  640. end
  641. if tolua.getpeer(currency.icon) ~= nil then
  642. tolua.setpeer(currency.icon, nil)
  643. end
  644. if tolua.getpeer(currency) ~= nil then
  645. tolua.setpeer(currency, nil)
  646. end
  647. end
  648. self.currencys = nil
  649. end
  650. function UILuckyEggResultView:RefreshCostCurrency()
  651. local cfg = self.controller:GetCfgData()
  652. local method = cfg.Method
  653. local costs = cfg.Cost
  654. local costCfgId, costNum
  655. local cost = nil
  656. if costs then
  657. local costLength = #costs
  658. for i = 1, costLength do
  659. cost = costs[i]
  660. if self.controller:GetOwnResCountByItemId(cost[1]) > 0 or i == costLength then
  661. costCfgId = tonumber(cost[1])
  662. costNum = tonumber(cost[2])
  663. break
  664. end
  665. end
  666. end
  667. self.currencyOne.icon.image.enabled = false
  668. self.currencyOne.icon.image.sprite = nil
  669. self.currencyTen.icon.image.enabled = false
  670. self.currencyTen.icon.image.sprite = nil
  671. if not costCfgId or not costNum or not method then
  672. self.one:SetActive(false)
  673. self.ten:SetActive(false)
  674. else
  675. local method1 = method[1]
  676. local method2 = method[2]
  677. local curMethod = self.controller:GetLuckyEggNum()
  678. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(costCfgId)
  679. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function(sprite)
  680. if sprite then
  681. self.currencyOne.icon.image.sprite = sprite
  682. self.currencyOne.icon.image.enabled = true
  683. self.currencyTen.icon.image.sprite = sprite
  684. self.currencyTen.icon.image.enabled = true
  685. end
  686. end)
  687. if method1 == curMethod then
  688. self.currencyOne.number.text.text = tostring(tonumber(method1) * costNum)
  689. self.one:SetActive(true)
  690. else
  691. self.one:SetActive(false)
  692. end
  693. if method2 == curMethod then
  694. self.currencyTen.number.text.text = tostring(tonumber(method2) * costNum)
  695. self.ten:SetActive(true)
  696. else
  697. self.ten:SetActive(false)
  698. end
  699. end
  700. end
  701. return UILuckyEggResultView