UILuckyEggView.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. local UILuckyEggView = require("UILuckyEgg/UILuckyEggView_Generate")
  2. function UILuckyEggView:OnAwake(data)
  3. self.controller = require("UILuckyEgg/UILuckyEggCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UILuckyEggView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ITEM_CHANGE, self, self.OnItemChanged)
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.DIAMOND_CHANGED, self, self.OnDiamondChanged)
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.LUCKYEGG_DATA_CHANGED, self, self.OnSmashDataChanged)
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.LUCKYEGG_RANK_DATA_CHANGED, self, self.OnSmashRankDataChanged)
  12. end
  13. function UILuckyEggView: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 UILuckyEggView:Init()
  24. -- 清除红点信息
  25. self.controller:ReadyData()
  26. self.dot:SetActive(false)
  27. self.window.animator:Play('UIShow')
  28. self.currency:SetActive(false)
  29. local initParam = SuperScrollView.LoopListViewInitParam()
  30. initParam.mSmoothDumpRate = 0.05
  31. initParam.mSnapVecThreshold = 9999
  32. self.scrollView.loopListView.OffsetSnapCenterPercent = 0.4
  33. self.scrollView.loopListView.ItemSnapEnable = true
  34. self.scrollView.loopListView:InitListView(-1, function(loopListView, idx)
  35. return self:GetItemByIndex(loopListView, idx)
  36. end, nil, initParam)
  37. self.scrollView.loopListView:MovePanelToItemIndex(self.controller:GetListIdx(), 0)
  38. self:RefreshView()
  39. end
  40. function UILuckyEggView:RemoveEventListener()
  41. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  42. self.scrollView.loopListView.mOnSnapItemFinished = nil
  43. end
  44. function UILuckyEggView:AddUIEventListener()
  45. self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn)
  46. self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
  47. self.uiBase:AddToggleEventListener(self.goldenEggToggle.toggle,self,self.OnClickTab,1)
  48. self.uiBase:AddToggleEventListener(self.variegationEggToggle.toggle,self,self.OnClickTab,2)
  49. self.uiBase:AddButtonUniqueEventListener(self.btnPlayRule.button, self, self.OnClickPlayRuleBtn)
  50. self.uiBase:AddButtonUniqueEventListener(self.btnOne.button, self, self.OnClickLuckyEggBtn, 1)
  51. self.uiBase:AddButtonUniqueEventListener(self.btnTen.button, self, self.OnClickLuckyEggBtn, 2)
  52. self.uiBase:AddButtonUniqueEventListener(self.btnArrowL.button, self, self.OnClickArrowBtn, false)
  53. self.uiBase:AddButtonUniqueEventListener(self.btnArrowR.button, self, self.OnClickArrowBtn, true)
  54. self.scrollView.loopListView.mOnBeginDragAction = function()
  55. return self:OnBeginDragAction()
  56. end
  57. self.scrollView.loopListView.mOnSnapItemFinished = function(loopListView, loopListViewItem)
  58. return self:OnSnapItemFinished(loopListView, loopListViewItem)
  59. end
  60. --滚动文字
  61. local OnChangeText = function (TextObj)
  62. self:ChangeLogText(TextObj)
  63. end
  64. self.NextTextIndex = 0
  65. if self.viewport.uiLoopAutoMove then
  66. self.viewport.uiLoopAutoMove:SetChangeInfoCb(OnChangeText)
  67. end
  68. self.controller:SendLuckyEggRecordReq()
  69. end
  70. function UILuckyEggView:OnClickTab(tog,idex)
  71. if tog.isOn then
  72. -- local cfg = self.controller:GetCfgByIdx(idex)
  73. local curSelect = self.controller:GetSelectIdx()
  74. if curSelect ~= idex then
  75. self:OnClickArrowBtn(nil,{[0]=curSelect < idex})
  76. end
  77. end
  78. end
  79. --添加文字
  80. function UILuckyEggView:ChangeLogText(TextObj)
  81. self.NextTextIndex = self.NextTextIndex >= 10 and 1 or self.NextTextIndex + 1
  82. local str = ""
  83. local rank_list = self.controller:GetActivityData()
  84. --LogError("============ rank_list = "..Inspect(rank_list));
  85. local package = rank_list[self.NextTextIndex]
  86. --LogError("============ NextTextIndex = "..self.NextTextIndex);
  87. if package then
  88. --LogError("============ package = "..Inspect(package));
  89. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(package.itemId)
  90. local name = nil
  91. if package.nickName and package.nickName ~= "" then
  92. name = package.nickName
  93. else
  94. name = ManagerContainer.DataMgr.UserData:GetUserNickname()
  95. end
  96. str = ManagerContainer.CfgMgr:GetLanguageValueByKey("BTSmashEggsTips1", name,itemCfgData.Name)
  97. end
  98. --LogError("============ Str = "..str);
  99. TextObj.text = str
  100. end
  101. function UILuckyEggView:OnHide()
  102. end
  103. function UILuckyEggView:OnShow(data)
  104. if data then
  105. self.controller:SetData(data)
  106. end
  107. self.scrollView.loopListView:RefreshAllShownItem()
  108. self:RefreshLuckyEggBtn()
  109. self:RefreshTopCurrency()
  110. self:RefreshCostCurrency()
  111. self:ResetEggLoopText()
  112. end
  113. function UILuckyEggView:OnDispose()
  114. self:DisposeCurrency()
  115. self:DisposeDot()
  116. self.scrollView.loopListView:Dispose()
  117. self.controller:OnDispose()
  118. end
  119. function UILuckyEggView:OnItemChanged()
  120. self:RefreshTopCurrency()
  121. self:RefreshCostCurrency()
  122. end
  123. function UILuckyEggView:OnDiamondChanged()
  124. self:RefreshTopCurrency()
  125. self:RefreshCostCurrency()
  126. end
  127. function UILuckyEggView:OnSmashDataChanged()
  128. if not ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UILuckyEgg) then
  129. return
  130. end
  131. if not ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UILuckyEggAnim) then
  132. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggAnim, nil, self.uiData.id)
  133. end
  134. end
  135. function UILuckyEggView:OnSmashRankDataChanged()
  136. self.NextTextIndex = 0
  137. self:ResetEggLoopText()
  138. end
  139. function UILuckyEggView:OnClickCloseBtn()
  140. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  141. end
  142. function UILuckyEggView:OnClickPlayRuleBtn()
  143. local actId = self.controller:GetActivityId()
  144. if actId then
  145. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'LuckyEggPlayExplain_'..actId})
  146. else
  147. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'LuckyEggPlayExplain'})
  148. end
  149. end
  150. local resType = Enum.RuneShopSubType.Gold
  151. function UILuckyEggView:OnClickCurrencyBuyBtn(_, params)
  152. local cfgId = params[0]
  153. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  154. if not itemCfgData then return end
  155. local type
  156. if itemCfgData.ResType == Enum.ItemType.Diamond or itemCfgData.ResType == Enum.ItemType.ROCoin then
  157. resType = Enum.RuneShopSubType.Gold
  158. end
  159. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, resType}, self.uiData.id)
  160. end
  161. function UILuckyEggView:SureBuy(idx)
  162. local errorCode, luckyEggNum, remainLuckyEggNum, vaildCosts = self.controller:GetSendLuckyEggReqErrorCode(idx)
  163. if errorCode == 0 then
  164. errorCode = self.controller:SendLuckyEggReq(luckyEggNum)
  165. if errorCode ~= 0 then
  166. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  167. end
  168. elseif errorCode == 1 then
  169. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  170. elseif errorCode == 2 then
  171. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  172. elseif errorCode == 3 then
  173. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  174. elseif errorCode == 4 then
  175. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  176. else
  177. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  178. end
  179. end
  180. function UILuckyEggView:SureJumpBuy(idx)
  181. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold}, self.uiData.id)
  182. end
  183. --- 发送砸蛋请求
  184. ---@param params Cfg.Method
  185. function UILuckyEggView:OnClickLuckyEggBtn(_, params)
  186. local idx = params[0]
  187. local errorCode, luckyEggNum, remainLuckyEggNum, vaildCosts = self.controller:GetSendLuckyEggReqErrorCode(idx)
  188. if errorCode == 0 then
  189. local len = #vaildCosts
  190. if len > 1 then
  191. local vaildCost = vaildCosts[len]
  192. local cfgId = vaildCost[1]
  193. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  194. if itemCfgData.ResType == Enum.ItemType.Diamond and vaildCost[4] < luckyEggNum then
  195. local paramData = {}
  196. local vaildCost2 = vaildCosts[1]
  197. local cfgId2 = vaildCost2[1]
  198. local itemCfgData2 = ManagerContainer.CfgMgr:GetItemById(cfgId2)
  199. paramData[1] = itemCfgData2 and string.formatbykey(itemCfgData2.Name) or ''
  200. paramData[2] = string.formatbykey('Supplementary', tostring(vaildCost[3] * vaildCost[4]), itemCfgData and string.formatbykey(itemCfgData.Name) or '', tostring(vaildCost[4]), paramData[1])
  201. local data = {"LuckyEggNoItemTip", paramData, idx, self, self.SureBuy}
  202. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  203. else
  204. errorCode = self.controller:SendLuckyEggReq(luckyEggNum)
  205. if errorCode ~= 0 then
  206. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  207. end
  208. end
  209. else
  210. errorCode = self.controller:SendLuckyEggReq(luckyEggNum)
  211. if errorCode ~= 0 then
  212. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  213. end
  214. end
  215. elseif errorCode == 1 then
  216. local len = #vaildCosts
  217. if len >= 1 then
  218. local vaildCost = vaildCosts[len]
  219. if Constant.OpenPay then
  220. local cfgId = vaildCost[1]
  221. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  222. local showStr = nil
  223. if itemCfgData.ResType == Enum.ItemType.Diamond then
  224. showStr = "NoDiamondTip"
  225. elseif itemCfgData.ResType == Enum.ItemType.ROCoin then
  226. showStr = "NoRoDiamondTip"
  227. end
  228. -- 提示框[1] 提示框的类型
  229. local data = {showStr, nil, idx, self, self.SureJumpBuy}
  230. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  231. return
  232. end
  233. end
  234. elseif errorCode == 2 then
  235. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  236. elseif errorCode == 3 then
  237. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  238. elseif errorCode == 4 then
  239. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  240. else
  241. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  242. end
  243. end
  244. function UILuckyEggView:OnClickArrowBtn(_, params)
  245. local isRight = params[0]
  246. local listIdx = self.controller:GetListIdx()
  247. if isRight then
  248. listIdx = listIdx + 1
  249. else
  250. listIdx = listIdx - 1
  251. end
  252. self.scrollView.loopListView:SetSnapTargetItemIndex(listIdx)
  253. self.window.animator:Play('UIRemove')
  254. end
  255. function UILuckyEggView:OnClickDetailsBtn(btn, params)
  256. local showList = params[0]
  257. table.sort(showList,function(a,b)
  258. local cfgA = ManagerContainer.CfgMgr:GetItemById(a[1])
  259. local cfgB = ManagerContainer.CfgMgr:GetItemById(b[1])
  260. if cfgA and cfgB then
  261. if cfgA.Quality == cfgB.Quality then
  262. if cfgA.ResType == Enum.ItemType.SkillEquip or cfgB.ResType == Enum.ItemType.SkillEquip then
  263. local artifactA = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(cfgA.Id)
  264. local artifactB = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(cfgB.Id)
  265. if artifactA and artifactB then
  266. if artifactA.ArtifactMaxLevel == artifactB.ArtifactMaxLevel then
  267. return cfgA.Id > cfgB.Id
  268. else
  269. return artifactA.ArtifactMaxLevel > artifactB.ArtifactMaxLevel
  270. end
  271. end
  272. else
  273. return cfgA.Id > cfgB.Id
  274. end
  275. else
  276. return cfgA.Quality > cfgB.Quality
  277. end
  278. end
  279. end)
  280. local show = {
  281. rewards = showList,
  282. title = "LuckyEggExtraRewards",
  283. type = Enum.ArtifactType.egg
  284. }
  285. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIArtifactRewardsList,show)
  286. end
  287. function UILuckyEggView:OnBeginDragAction()
  288. self.window.animator:Play('UIRemove')
  289. end
  290. function UILuckyEggView:OnSnapItemFinished(loopListView, loopListViewItem)
  291. self.window.animator:Play('UIShow')
  292. if not self.controller:SetListIdx(loopListViewItem.ItemIndex) then
  293. return
  294. end
  295. self:RefreshView()
  296. self:ResetEggLoopText()
  297. self.controller:SendLuckyEggRecordReq()
  298. end
  299. function UILuckyEggView:GetItemByIndex(loopListView, listIdx)
  300. local idx = self.controller:GetSelectIdxByListIdx(listIdx)
  301. local cfg = self.controller:GetCfgByIdx(idx)
  302. if not cfg then return nil end
  303. local item = loopListView:NewListViewItem('UILuckyEggItem')
  304. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'UILuckyEggItem', item.gameObject)
  305. if itemLua then
  306. itemLua.egg.image.enabled = false
  307. itemLua.egg.image.sprite = nil
  308. CommonUtil.LoadIcon(self, cfg.ShowImg, function(sprite)
  309. if sprite then
  310. itemLua.egg.image.sprite = sprite
  311. itemLua.egg.image.enabled = true
  312. end
  313. end, itemLua, 'BannerIconAsync')
  314. local reward_show = cfg.ClientShow
  315. if reward_show and #reward_show > 0 then
  316. self.uiBase:AddButtonUniqueEventListener(itemLua.btnMvpPreview.button, self, self.OnClickDetailsBtn, reward_show)
  317. end
  318. if not cfg.Total or cfg.Total <= 0 then
  319. itemLua.extraBox:SetActive(false)
  320. else
  321. itemLua.extraBox:SetActive(true)
  322. local luckyEggNum = self.controller:GetLuckyEggNumByIdx(idx)
  323. local percent = luckyEggNum % cfg.Total
  324. local per = percent/ cfg.Total
  325. itemLua.extraRewardItem.rewardSlider.slider.value = per
  326. local validPercent = CommonUtil.GetPreciseDecimal(per * 100)
  327. if validPercent <= 0 and luckyEggNum > 0 then
  328. validPercent = 1
  329. end
  330. itemLua.extraRewardItem.percentTxt.text.text = tostring(validPercent) .. '%'
  331. end
  332. end
  333. item.CachedRectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Horizontal, loopListView.ViewPortWidth)
  334. return item
  335. end
  336. function UILuckyEggView:RefreshView()
  337. self:RefreshTopCurrency()
  338. self:RefreshLuckyEggBtn()
  339. self:RefreshCostCurrency()
  340. local selectIdx = self.controller:GetSelectIdx()
  341. local length = self.controller:GetCfgLength()
  342. local cfg = self.controller:GetCfgByIdx(selectIdx)
  343. --LogError("length = "..length)
  344. if length <= 1 then
  345. self.btnArrowL:SetActive(false)
  346. self.btnArrowR:SetActive(false)
  347. else
  348. self.btnArrowL:SetActive(true)
  349. self.btnArrowR:SetActive(true)
  350. end
  351. if cfg and cfg.Type == 5 and self.controller:GetCfgLength_cfg() == 1 then
  352. self.goldenEggToggle:SetActive(false)
  353. self.variegationEggToggle:SetActive(true)
  354. else
  355. self.goldenEggToggle:SetActive(true)
  356. self.variegationEggToggle:SetActive(false)
  357. end
  358. if not self.dots then self.dots = {} end
  359. local num = #self.dots
  360. local dot = nil
  361. local parent = self.dotToggleGroup.transform
  362. for i = 1, length do
  363. if i <= num then
  364. dot = self.dots[i]
  365. else
  366. dot = CommonUtil.Instantiate(self.dot.gameObject, parent)
  367. if tolua.getpeer(dot) == nil then
  368. tolua.setpeer(dot, {})
  369. end
  370. dot.toggle = dot:GetComponent(Enum.TypeInfo.Toggle)
  371. self.dots[i] = dot
  372. end
  373. dot:SetActive(true)
  374. dot.toggle.isOn = (i == selectIdx)
  375. end
  376. for i = length + 1, num do
  377. dot = self.dots[i]
  378. dot:SetActive(false)
  379. end
  380. end
  381. function UILuckyEggView:RefreshLuckyEggBtn()
  382. --- 检测
  383. self.controller:CheckTotalRecharge()
  384. local selectIdx = self.controller:GetSelectIdx()
  385. local cfg = self.controller:GetCfgByIdx(selectIdx)
  386. if cfg == nil then
  387. return
  388. end
  389. if cfg.UnLock and cfg.UnLock > 0 then
  390. local result, val, content = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(cfg.UnLock)
  391. if not result then
  392. self.leftAnim:SetActive(false)
  393. self.rightAnim:SetActive(false)
  394. return
  395. end
  396. end
  397. self.leftAnim:SetActive(true)
  398. self.rightAnim:SetActive(true)
  399. local egg_active = self.controller:GetEggActiveByPay()
  400. self.variegationEggToggle.gameObject:SetActive(egg_active)
  401. if cfg.Type == 4 then
  402. self.goldenEggToggle.toggle.graphic:CrossFadeAlpha(1.0,0.1,true)
  403. self.variegationEggToggle.toggle.graphic:CrossFadeAlpha(0.1,0.1,true)
  404. elseif cfg.Type == 5 then
  405. self.variegationEggToggle.toggle.graphic:CrossFadeAlpha(1.0,0.1,true)
  406. self.goldenEggToggle.toggle.graphic:CrossFadeAlpha(0.1,0.1,true)
  407. end
  408. end
  409. function UILuckyEggView:RefreshTopCurrency()
  410. local selectIdx = self.controller:GetSelectIdx()
  411. local cfg = self.controller:GetCfgByIdx(selectIdx)
  412. if cfg == nil then
  413. return
  414. end
  415. local costs = cfg.Cost
  416. local num = costs and #costs or 0
  417. local length = 0
  418. if not self.currencys then
  419. self.currencys = {}
  420. else
  421. length = #self.currencys
  422. end
  423. local parent = self.currency.transform.parent
  424. for i = 1, num do
  425. local currency = nil
  426. if i <= length then
  427. currency = self.currencys[i]
  428. else
  429. currency = CommonUtil.Instantiate(self.currency.gameObject, parent)
  430. if tolua.getpeer(currency) == nil then
  431. tolua.setpeer(currency, {})
  432. end
  433. local icon = currency.transform:Find('Icon').gameObject
  434. if tolua.getpeer(icon) == nil then
  435. tolua.setpeer(icon, {})
  436. end
  437. icon.image = icon:GetComponent(Enum.TypeInfo.Image)
  438. currency.icon = icon
  439. local number = currency.transform:Find('Number').gameObject
  440. if tolua.getpeer(number) == nil then
  441. tolua.setpeer(number, {})
  442. end
  443. number.text = number:GetComponent(Enum.TypeInfo.Text)
  444. currency.number = number
  445. local btnBuy = currency.transform:Find('BtnBuy').gameObject
  446. if tolua.getpeer(btnBuy) == nil then
  447. tolua.setpeer(btnBuy, {})
  448. end
  449. btnBuy.button = btnBuy:GetComponent(Enum.TypeInfo.Button)
  450. currency.btnBuy = btnBuy
  451. self.currencys[i] = currency
  452. end
  453. currency:SetActive(true)
  454. currency.icon.image.enabled = false
  455. currency.icon.image.sprite = nil
  456. local cfgId = tonumber(costs[i][1])
  457. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  458. if itemCfgData then
  459. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function(sprite)
  460. if sprite then
  461. currency.icon.image.sprite = sprite
  462. currency.icon.image.enabled = true
  463. end
  464. end)
  465. if itemCfgData.ResType == Enum.ItemType.ROCoin or itemCfgData.ResType == Enum.ItemType.Diamond then
  466. currency.btnBuy:SetActive(Constant.OpenPay)
  467. self.uiBase:AddButtonUniqueEventListener(currency.btnBuy.button, self, self.OnClickCurrencyBuyBtn, cfgId)
  468. else
  469. currency.btnBuy:SetActive(false)
  470. currency.btnBuy.button.onClick:RemoveAllListeners()
  471. end
  472. else
  473. currency.btnBuy:SetActive(false)
  474. currency.btnBuy.button.onClick:RemoveAllListeners()
  475. end
  476. currency.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(cfgId))
  477. end
  478. for i = num + 1, length do
  479. local currency = self.currencys[i]
  480. currency:SetActive(false)
  481. currency.btnBuy:SetActive(false)
  482. currency.btnBuy.button.onClick:RemoveAllListeners()
  483. end
  484. end
  485. function UILuckyEggView:RefreshCostCurrency()
  486. local selectIdx = self.controller:GetSelectIdx()
  487. local cfg = self.controller:GetCfgByIdx(selectIdx)
  488. if cfg == nil then
  489. return
  490. end
  491. local method = cfg.Method
  492. local costs = cfg.Cost
  493. local costCfgId, costNum
  494. local cost = nil
  495. if costs then
  496. local costLength = #costs
  497. for i = 1, costLength do
  498. cost = costs[i]
  499. if self.controller:GetOwnResCountByItemId(cost[1]) > 0 or i == costLength then
  500. costCfgId = tonumber(cost[1])
  501. costNum = tonumber(cost[2])
  502. break
  503. end
  504. end
  505. end
  506. self.currencyOne.icon.image.enabled = false
  507. self.currencyOne.icon.image.sprite = nil
  508. self.currencyTen.icon.image.enabled = false
  509. self.currencyTen.icon.image.sprite = nil
  510. if not costCfgId or not costNum or not method then
  511. self.leftAnim:SetActive(false)
  512. self.rightAnim:SetActive(false)
  513. else
  514. local method1 = method[1]
  515. local method2 = method[2]
  516. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(costCfgId)
  517. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function(sprite)
  518. if sprite then
  519. self.currencyOne.icon.image.sprite = sprite
  520. self.currencyOne.icon.image.enabled = true
  521. self.currencyTen.icon.image.sprite = sprite
  522. self.currencyTen.icon.image.enabled = true
  523. end
  524. end)
  525. if method1 then
  526. self.currencyOne.number.text.text = tostring(tonumber(method1) * costNum)
  527. self.leftAnim:SetActive(true)
  528. else
  529. self.leftAnim:SetActive(false)
  530. end
  531. if method2 then
  532. self.currencyTen.number.text.text = tostring(tonumber(method2) * costNum)
  533. self.rightAnim:SetActive(true)
  534. else
  535. self.rightAnim:SetActive(false)
  536. end
  537. end
  538. end
  539. function UILuckyEggView:ResetEggLoopText()
  540. if self.viewport and self.viewport.uiLoopAutoMove then
  541. self.NextTextIndex = 0
  542. self.viewport.uiLoopAutoMove:Reset()
  543. self.viewport.uiLoopAutoMove:RunMove()
  544. end
  545. end
  546. function UILuckyEggView:DisposeCurrency()
  547. if not self.currencys then return end
  548. for _, currency in pairs(self.currencys) do
  549. CommonUtil.DestroyGO(currency)
  550. if tolua.getpeer(currency.btnBuy) ~= nil then
  551. tolua.setpeer(currency.btnBuy, nil)
  552. end
  553. if tolua.getpeer(currency.number) ~= nil then
  554. tolua.setpeer(currency.number, nil)
  555. end
  556. if tolua.getpeer(currency.icon) ~= nil then
  557. tolua.setpeer(currency.icon, nil)
  558. end
  559. if tolua.getpeer(currency) ~= nil then
  560. tolua.setpeer(currency, nil)
  561. end
  562. end
  563. self.currencys = nil
  564. end
  565. function UILuckyEggView:OnClose()
  566. end
  567. function UILuckyEggView:DisposeDot()
  568. if not self.dots then return end
  569. for _, dot in pairs(self.dots) do
  570. CommonUtil.DestroyGO(dot)
  571. dot.toggle = nil
  572. if tolua.getpeer(dot) ~= nil then
  573. tolua.setpeer(dot, nil)
  574. end
  575. end
  576. self.dots = nil
  577. end
  578. return UILuckyEggView