UILuckyEggView.lua 20 KB

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