UISummonResultView.lua 24 KB

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