UIRuneShopBTView.lua 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. local UIRuneShopBTView = require("UIRuneShop/UIRuneShopBTView_Generate")
  2. local ConditionJudge = require("Common/ConditionJudge")
  3. local FirstBuyBgIconPath = 'ShopIcons/txt_club_first'
  4. local ExtraBuyBgIconPath = 'ShopIcons/txt_club_free_extra_cn'
  5. function UIRuneShopBTView:OnAwake(data)
  6. self.controller = require("UIRuneShop/UIRuneShopBTCtr"):new()
  7. self.controller:Init(self)
  8. self.controller:SetData(data)
  9. end
  10. function UIRuneShopBTView:AddEventListener()
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ROCOIN_CHANGED, self, self.OnRoCoinChanged)
  12. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.COIN_CHANGED, self, self.OnCoinChanged)
  13. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.DIAMOND_CHANGED, self, self.OnDiamondChanged)
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VIP_LV_CHANGED, self, self.OnVipLvChanged)
  15. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.RUNE_SHOP_DATA_CHANGED, self, self.OnRuneShopDataChanged)
  16. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.RED_POINT_MGR_NOTICE, self, self.OnRPNotify)
  17. end
  18. function UIRuneShopBTView: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 UIRuneShopBTView:Init()
  29. self.controller:InitData()
  30. self.privilegeCardItem.privilegeScrollView.loopListView:InitListView(0, function (loopListView, itemIdx)
  31. return self:GetItemByIndexPrivilege(loopListView, itemIdx)
  32. end, nil, nil)
  33. self.privilegeCardItem.rewardScrollView.loopGridView:InitGridView(0, function (loopGridView, itemIdx, row, column)
  34. return self:GetItemByRowColumnPrivilege(loopGridView, itemIdx, row, column)
  35. end, nil, nil)
  36. self.giftsBox.scrollView.loopGridView:InitGridView(0, function(loopGridView, itemIdx, row, column)
  37. return self:GetItemByRowColumnGifts(loopGridView, itemIdx, row, column)
  38. end, nil, nil)
  39. self.rOPassport.scrollView.loopListView:InitListView(0, function(loopListView, itemIdx)
  40. return self:GetItemByIndexROPass(loopListView, itemIdx)
  41. end)
  42. self.limitedBox.scrollView.loopGridView:InitGridView(0, function(loopGridView, itemIdx, row, column)
  43. return self:GetItemByRowColumnLimited(loopGridView, itemIdx, row, column)
  44. end, nil, nil)
  45. self:RefreshRoCoinView()
  46. self:RefreshCoinView()
  47. self:RefreshGoldView()
  48. self:RefreshVipView()
  49. self:RefreshToggleGroupView()
  50. self:RefreshShopView(true)
  51. end
  52. function UIRuneShopBTView:RemoveEventListener()
  53. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  54. end
  55. function UIRuneShopBTView:AddUIEventListener()
  56. self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
  57. self.uiBase:AddButtonUniqueEventListener(self.btnVIP.button, self, self.OnClickVipBtn)
  58. self.uiBase:AddToggleUniqueEventListener(self.privilegeCardToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.SpecialPrivilege)
  59. self.uiBase:AddToggleUniqueEventListener(self.weekToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.MonthCard)
  60. self.uiBase:AddToggleUniqueEventListener(self.passportToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.PassCheck)
  61. self.uiBase:AddToggleUniqueEventListener(self.giftsToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.Gifts)
  62. self.uiBase:AddToggleUniqueEventListener(self.limitedToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.LimitTime)
  63. self.uiBase:AddButtonUniqueEventListener(self.dailyBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Daily)
  64. self.uiBase:AddButtonUniqueEventListener(self.weekBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Week)
  65. self.uiBase:AddButtonUniqueEventListener(self.roCoinBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.ROCoin)
  66. self.uiBase:AddButtonUniqueEventListener(self.goldBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Gold)
  67. self.uiBase:AddButtonUniqueEventListener(self.monthBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Month)
  68. end
  69. function UIRuneShopBTView:OnHide()
  70. end
  71. function UIRuneShopBTView:OnShow(data)
  72. if data then
  73. self.controller:SetData(data)
  74. self.controller:InitData()
  75. end
  76. self:RefreshCoinView()
  77. self:RefreshGoldView()
  78. self:RefreshVipView()
  79. self:RefreshToggleGroupView()
  80. self:RefreshShopView(true)
  81. end
  82. function UIRuneShopBTView:OnClose()
  83. end
  84. function UIRuneShopBTView:OnDispose()
  85. self.privilegeUnlockDess = nil
  86. self.privilegeRewards = nil
  87. self.roPassUnlockDess = nil
  88. self:DisposeRefreshTimer()
  89. self.privilegeCardItem.privilegeScrollView.loopListView:Dispose()
  90. self.privilegeCardItem.rewardScrollView.loopGridView:Dispose()
  91. self.giftsBox.scrollView.loopGridView:Dispose()
  92. self.rOPassport.scrollView.loopListView:Dispose()
  93. self.limitedBox.scrollView.loopGridView:Dispose()
  94. self.controller:OnDispose()
  95. end
  96. function UIRuneShopBTView:OnClickCloseBtn()
  97. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  98. end
  99. function UIRuneShopBTView:OnClickVipBtn()
  100. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIVip)
  101. end
  102. function UIRuneShopBTView:OnClickOneToggle(tog, params, b)
  103. if not b then return end
  104. local shopType = params[0]
  105. if self.controller:ChangeShopType(shopType) then
  106. self:RefreshShopView(true)
  107. end
  108. end
  109. function UIRuneShopBTView:OnClickShopSubBtn(btn, params)
  110. local shopSubType = params[0]
  111. if self.controller:ChangeShopSubType(shopSubType) then
  112. self:RefreshGiftsView(true)
  113. end
  114. end
  115. function UIRuneShopBTView:OnClickMonthCardPrice(_, params)
  116. local id = params[0]
  117. local errorCodeKey = self.controller:SendPay(id)
  118. if not errorCodeKey then
  119. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey)
  120. end
  121. end
  122. function UIRuneShopBTView:OnClickRoPassBuy(_, params)
  123. local id = params[0]
  124. local errorCodeKey = self.controller:SendPay(id)
  125. if not errorCodeKey then
  126. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey)
  127. end
  128. end
  129. function UIRuneShopBTView:OnClickShopGoodsItem(_, params)
  130. local data = params[0]
  131. if not data then return end
  132. if data:IsSoldout() then return end
  133. local id = data:GetId()
  134. local runeShopType = self.controller:GetShopType()
  135. local runeShopSubType = self.controller:GetShopSubType()
  136. if runeShopType == Enum.RuneShopType.Gifts then
  137. if runeShopSubType == Enum.RuneShopSubType.Gold then
  138. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopGoldBuyTips, {runeShopType, runeShopSubType, id})
  139. return
  140. end
  141. end
  142. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBuyTips, {runeShopType, runeShopSubType, id})
  143. end
  144. function UIRuneShopBTView:OnClickGiftItem(button, params)
  145. local id = params[0]
  146. local runeShopType = self.controller:GetShopType()
  147. local runeShopSubType = self.controller:GetShopSubType()
  148. if runeShopType == Enum.RuneShopType.Gifts then
  149. if runeShopSubType == Enum.RuneShopSubType.Gold then
  150. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopGoldBuyTips, {runeShopType, runeShopSubType, id})
  151. return
  152. end
  153. end
  154. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBuyTips, {runeShopType, runeShopSubType, id})
  155. end
  156. function UIRuneShopBTView:OnClickGiftPrice(button, params)
  157. -- 直接发起支付
  158. local id = params[0]
  159. local errorCodeKey = self.controller:SendPay(id)
  160. if not errorCodeKey then
  161. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey)
  162. end
  163. end
  164. function UIRuneShopBTView:OnClickLimitedItem(button, params)
  165. local id = params[0]
  166. local itemIdx = params[1]
  167. local runeShopType = self.controller:GetShopType()
  168. local runeShopSubType = self.controller:GetShopSubType()
  169. if runeShopType == Enum.RuneShopType.Gifts then
  170. if runeShopSubType == Enum.RuneShopSubType.Gold then
  171. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopGoldBuyTips, {runeShopType, runeShopSubType, id})
  172. return
  173. end
  174. end
  175. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBuyTips, {runeShopType, runeShopSubType, id})
  176. ManagerContainer.RedPointMgr.RSLimitGiftRPCtr:CancelRedPointStatusById(id)
  177. self.limitedBox.scrollView.loopGridView:RefreshItemByItemIndex(itemIdx)
  178. end
  179. function UIRuneShopBTView:OnClickLimitedPrice(button, params)
  180. -- 直接发起支付
  181. local id = params[0]
  182. local itemIdx = params[1]
  183. local errorCodeKey = self.controller:SendPay(id)
  184. if not errorCodeKey then
  185. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey)
  186. end
  187. ManagerContainer.RedPointMgr.RSLimitGiftRPCtr:CancelRedPointStatusById(id)
  188. self.limitedBox.scrollView.loopGridView:RefreshItemByItemIndex(itemIdx)
  189. end
  190. function UIRuneShopBTView:OnRoCoinChanged()
  191. self:RefreshRoCoinView()
  192. end
  193. function UIRuneShopBTView:OnCoinChanged()
  194. self:RefreshCoinView()
  195. end
  196. function UIRuneShopBTView:OnDiamondChanged()
  197. self:RefreshGoldView()
  198. end
  199. function UIRuneShopBTView:OnVipLvChanged()
  200. self:RefreshVipView()
  201. end
  202. function UIRuneShopBTView:OnRuneShopDataChanged(runeShopType, runeShopSubType)
  203. if runeShopType ~= self.controller:GetShopType() then return end
  204. local curRuneShopSubType = self.controller:GetShopSubType()
  205. if curRuneShopSubType and runeShopSubType ~= curRuneShopSubType then return end
  206. self.controller:RefreshCurShopData()
  207. self:RefreshShopView()
  208. end
  209. function UIRuneShopBTView:OnRPNotify(rpType)
  210. if rpType ~= Enum.RPNotifyType.RuneShopLimitGift then
  211. return
  212. end
  213. if Enum.RuneShopType.LimitTime ~= self.controller:GetShopType() then return end
  214. local curRuneShopSubType = self.controller:GetShopSubType()
  215. if curRuneShopSubType and nil ~= curRuneShopSubType then return end
  216. self:RefreshShopView()
  217. end
  218. function UIRuneShopBTView:RefreshRoCoinView()
  219. self.ro.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(Enum.ItemType.ROCoin))
  220. end
  221. function UIRuneShopBTView:RefreshCoinView()
  222. self.coin.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(Enum.ItemType.Coin))
  223. end
  224. function UIRuneShopBTView:RefreshGoldView()
  225. self.gold.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(Enum.ItemType.Diamond))
  226. end
  227. function UIRuneShopBTView:RefreshVipView()
  228. local curVipLv = self.controller:GetCurVipLv()
  229. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv)
  230. self.vipIcon.image.sprite = nil
  231. self.vipIcon.image.enabled = false
  232. self.vipFrame.image.sprite = nil
  233. self.vipFrame.image.enabled = false
  234. if not vipCfg then
  235. self.vipNameTxt.text.text = ''
  236. return
  237. end
  238. CommonUtil.LoadIcon(self, vipCfg.BigIcon, function(sprite)
  239. if sprite then
  240. self.vipIcon.image.sprite = sprite
  241. self.vipIcon.image.enabled = true
  242. end
  243. end)
  244. CommonUtil.LoadIcon(self, vipCfg.BigFrame, function(sprite)
  245. if sprite then
  246. self.vipFrame.image.sprite = sprite
  247. self.vipFrame.image.enabled = true
  248. end
  249. end)
  250. self.vipNameTxt.text.text = string.formatbykey(vipCfg.Name)
  251. end
  252. function UIRuneShopBTView:RefreshToggleGroupView()
  253. local shopType = self.controller:GetShopType()
  254. local toggleGroup = self.content.toggleGroup
  255. local oldAllowSwitchOff = toggleGroup.allowSwitchOff
  256. toggleGroup.allowSwitchOff = true
  257. self.weekToggle.toggle.isOn = (shopType == Enum.RuneShopType.MonthCard)
  258. self.giftsToggle.toggle.isOn = (shopType == Enum.RuneShopType.Gifts)
  259. self.limitedToggle.toggle.isOn = (shopType == Enum.RuneShopType.LimitTime)
  260. toggleGroup.allowSwitchOff = oldAllowSwitchOff
  261. end
  262. function UIRuneShopBTView:RefreshShopView(resetPos)
  263. self.privilegeUnlockDess = nil
  264. self.privilegeRewards = nil
  265. self.roPassUnlockDess = nil
  266. self:StopAndClearRefreshTimer()
  267. local shopType = self.controller:GetShopType()
  268. if shopType == Enum.RuneShopType.SpecialPrivilege then
  269. self.privilegeBox:SetActive(true)
  270. self.weekBox:SetActive(false)
  271. self.passportBox:SetActive(false)
  272. self.giftsBox:SetActive(false)
  273. self.limitedBox:SetActive(false)
  274. self:RefreshSpecialPrivilegeView()
  275. self.textBox.text.text = string.formatbykey('DscClub05')
  276. elseif shopType == Enum.RuneShopType.MonthCard then
  277. self.privilegeBox:SetActive(false)
  278. self.weekBox:SetActive(true)
  279. self.passportBox:SetActive(false)
  280. self.giftsBox:SetActive(false)
  281. self.limitedBox:SetActive(false)
  282. self:RefreshMonthCardView()
  283. self.textBox.text.text = string.formatbykey('DscClub06')
  284. elseif shopType == Enum.RuneShopType.PassCheck then
  285. self.privilegeBox:SetActive(false)
  286. self.weekBox:SetActive(false)
  287. self.passportBox:SetActive(true)
  288. self.giftsBox:SetActive(false)
  289. self.limitedBox:SetActive(false)
  290. self:RefreshRoPassView()
  291. self.textBox.text.text = string.formatbykey('DscClub07')
  292. elseif shopType == Enum.RuneShopType.Gifts then
  293. self.privilegeBox:SetActive(false)
  294. self.weekBox:SetActive(false)
  295. self.passportBox:SetActive(false)
  296. self.giftsBox:SetActive(true)
  297. self.limitedBox:SetActive(false)
  298. self:RefreshGiftsView(resetPos)
  299. self.textBox.text.text = string.formatbykey('DscClub02')
  300. elseif shopType == Enum.RuneShopType.LimitTime then
  301. self.privilegeBox:SetActive(false)
  302. self.weekBox:SetActive(false)
  303. self.passportBox:SetActive(false)
  304. self.giftsBox:SetActive(false)
  305. self.limitedBox:SetActive(true)
  306. self:RefreshLimitedView(resetPos)
  307. self.textBox.text.text = string.formatbykey('DscClub03')
  308. else
  309. self.privilegeBox:SetActive(false)
  310. self.weekBox:SetActive(false)
  311. self.passportBox:SetActive(false)
  312. self.giftsBox:SetActive(false)
  313. self.limitedBox:SetActive(false)
  314. self.textBox.text.text = ''
  315. end
  316. end
  317. function UIRuneShopBTView:RefreshSpecialPrivilegeView()
  318. local id = self.controller:GetSpecialPrivilegeId()
  319. local cfgData = nil
  320. local unlock = true
  321. if id then
  322. cfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(id)
  323. if not cfgData then
  324. id = 1
  325. cfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(1)
  326. unlock = false
  327. end
  328. else
  329. id = 1
  330. cfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(1)
  331. unlock = false
  332. end
  333. if not cfgData then
  334. self.privilegeBox:SetActive(false)
  335. return
  336. end
  337. local privilegeCardItem = self.privilegeCardItem
  338. privilegeCardItem.privilegeLv1:SetActive(id == 1)
  339. privilegeCardItem.privilegeLv2:SetActive(id == 2)
  340. local buyRewards = cfgData.BuyReward
  341. if buyRewards then
  342. local buyReward = buyRewards[1]
  343. if buyReward then
  344. self:RefreshCurrenyItem(privilegeCardItem.buyReward1, buyReward[1], buyReward[2], true)
  345. else
  346. self:RefreshCurrenyItem(privilegeCardItem.buyReward1)
  347. end
  348. buyReward = buyRewards[2]
  349. if buyReward then
  350. self:RefreshCurrenyItem(privilegeCardItem.buyReward2, buyReward[1], buyReward[2], true)
  351. else
  352. self:RefreshCurrenyItem(privilegeCardItem.buyReward2)
  353. end
  354. else
  355. self:RefreshCurrenyItem(privilegeCardItem.buyReward1)
  356. self:RefreshCurrenyItem(privilegeCardItem.buyReward2)
  357. end
  358. privilegeCardItem.privilegeScrollView.loopListView:SetListItemCount(0, true)
  359. self.privilegeUnlockDess = unlock and cfgData.Activation or cfgData.UnlockDes
  360. if self.privilegeUnlockDess then
  361. privilegeCardItem.privilegeScrollView.loopListView:SetListItemCount(#self.privilegeUnlockDess, true)
  362. end
  363. privilegeCardItem.rewardScrollView.loopGridView:SetListItemCount(0, true)
  364. self.privilegeRewards = nil
  365. if cfgData.Reward then
  366. self.privilegeRewards = {}
  367. for i = 1, #cfgData.Reward do
  368. local reward = cfgData.Reward[i]
  369. self.privilegeRewards[#self.privilegeRewards+1] = {cfgId = reward[1], num = reward[2]}
  370. end
  371. end
  372. if self.privilegeRewards then
  373. privilegeCardItem.rewardScrollView.loopGridView:SetListItemCount(#self.privilegeRewards, true)
  374. end
  375. privilegeCardItem.active:SetActive(unlock)
  376. privilegeCardItem.unActive:SetActive(not unlock)
  377. if unlock then
  378. local nextCfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(id + 1)
  379. if nextCfgData then
  380. local canUpgrade = false
  381. if nextCfgData.UnlockCond then
  382. canUpgrade = ConditionJudge:ConditionPassResult1(nextCfgData.UnlockCond)
  383. end
  384. privilegeCardItem.btnUpgrade:SetActive(canUpgrade)
  385. privilegeCardItem.btnBuyPrivilege:SetActive(false)
  386. self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnUpgrade.button, self, self.OnClickPrivlegeActiveBtn)
  387. else
  388. privilegeCardItem.btnUpgrade:SetActive(false)
  389. privilegeCardItem.btnBuyPrivilege:SetActive(false)
  390. end
  391. if self.controller:CanGetSpecialPrivilegeReward() then
  392. privilegeCardItem.btnReceive:SetActive(true)
  393. privilegeCardItem.labelReceived:SetActive(false)
  394. else
  395. privilegeCardItem.btnReceive:SetActive(false)
  396. privilegeCardItem.labelReceived:SetActive(true)
  397. end
  398. self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnReceive.button, self, self.OnClickPrivlegeReceiveBtn)
  399. else
  400. privilegeCardItem.btnUpgrade:SetActive(false)
  401. privilegeCardItem.btnBuyPrivilege:SetActive(true)
  402. privilegeCardItem.btnReceive:SetActive(true)
  403. privilegeCardItem.labelReceived:SetActive(false)
  404. self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnBuyPrivilege.button, self, self.OnClickPrivlegeActiveBtn)
  405. self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnReceive.button, self, self.OnClickPrivlegeActiveBtn)
  406. end
  407. end
  408. function UIRuneShopBTView:OnClickPrivlegeReceiveBtn()
  409. local errorCode = self.controller:SendRuneSpecialPrvilegeRewardReq()
  410. if errorCode ~= 0 then
  411. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  412. end
  413. end
  414. function UIRuneShopBTView:OnClickPrivlegeActiveBtn()
  415. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPrivilegeCardTips)
  416. end
  417. function UIRuneShopBTView:GetItemByIndexPrivilege(loopListView, itemIdx)
  418. local unlockDess = self.privilegeUnlockDess
  419. if not unlockDess then
  420. return nil
  421. end
  422. local unlockDes = unlockDess[itemIdx + 1]
  423. if not unlockDes then
  424. return nil
  425. end
  426. local item = loopListView:NewListViewItem('EntryUnlockDscItem')
  427. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'EntryUnlockDscItem', item.gameObject)
  428. if itemLua then
  429. local idx = unlockDes[1] or 0
  430. itemLua.icon.uIImageSwitchSprite:ChangeSprite(idx)
  431. local params = {}
  432. local langKey = unlockDes[2]
  433. for i = 3, #unlockDes do
  434. params[#params + 1] = tostring(unlockDes[i])
  435. end
  436. itemLua.desTxt.text.text = string.formatbykey(langKey, unpack(params))
  437. end
  438. ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform)
  439. return item
  440. end
  441. function UIRuneShopBTView:GetItemByRowColumnPrivilege(loopGridView, itemIdx, row, column)
  442. if not self.privilegeRewards then
  443. return nil
  444. end
  445. local reward = self.privilegeRewards[itemIdx + 1]
  446. if not reward then
  447. return nil
  448. end
  449. local item = loopGridView:NewListViewItem('Item')
  450. local iconItem = item.transform:Find('IconItem')
  451. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'IconItem', iconItem.gameObject)
  452. CommonUtil.UpdateItemPrefab(self, itemLua, reward, nil, self, self.ShowItemTips, reward)
  453. return item
  454. end
  455. function UIRuneShopBTView:ShowItemTips(button, params)
  456. local data = params[0]
  457. ManagerContainer.LuaUIMgr:OpenTips(data)
  458. end
  459. function UIRuneShopBTView:RefreshMonthCardView()
  460. self:RefreshOneMonthCardView(self.weekCard1, 1)
  461. end
  462. function UIRuneShopBTView:RefreshOneMonthCardView(itemLua, idx)
  463. local showGoodsDatas = self.controller:GetShowGoodsDatas()
  464. if not showGoodsDatas then
  465. itemLua:SetActive(false)
  466. return
  467. end
  468. local showGoodsData = showGoodsDatas[idx]
  469. if not showGoodsData then
  470. itemLua:SetActive(false)
  471. return
  472. end
  473. itemLua:SetActive(true)
  474. local cfgData = showGoodsData:GetCfgData()
  475. local buyRewards = cfgData.BuyReward
  476. if buyRewards then
  477. local buyReward = buyRewards[1]
  478. if buyReward then
  479. self:RefreshCurrenyItem(itemLua.buyReward1, buyReward[1], buyReward[2], true)
  480. else
  481. self:RefreshCurrenyItem(itemLua.buyReward1)
  482. end
  483. buyReward = buyRewards[2]
  484. if buyReward then
  485. self:RefreshCurrenyItem(itemLua.buyReward2, buyReward[1], buyReward[2], true)
  486. else
  487. self:RefreshCurrenyItem(itemLua.buyReward2)
  488. end
  489. else
  490. self:RefreshCurrenyItem(itemLua.buyReward1)
  491. self:RefreshCurrenyItem(itemLua.buyReward2)
  492. end
  493. local dayRewards = cfgData.DayReward
  494. if dayRewards then
  495. local dayReward = dayRewards[1]
  496. if dayReward then
  497. self:RefreshCurrenyItem(itemLua.dailyReward, dayReward[1], dayReward[2], true)
  498. else
  499. self:RefreshCurrenyItem(itemLua.dailyReward)
  500. end
  501. else
  502. self:RefreshCurrenyItem(itemLua.dailyReward)
  503. end
  504. local totalRewards = cfgData.TotalReward
  505. if totalRewards then
  506. local totalReward = totalRewards[1]
  507. if totalReward then
  508. self:RefreshCurrenyItem(itemLua.totalReward, totalReward[1], totalReward[2], true)
  509. else
  510. self:RefreshCurrenyItem(itemLua.totalReward)
  511. end
  512. else
  513. self:RefreshCurrenyItem(itemLua.totalReward)
  514. end
  515. local price = showGoodsData:GetPrice()
  516. if price <= 0 then
  517. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  518. else
  519. itemLua.presentPrice.number.text.text = tostring(price)
  520. end
  521. local timerStr, outTime = showGoodsData:CalculateLimitTime()
  522. if not outTime then
  523. self:StartRefreshTimer(itemLua, showGoodsData)
  524. itemLua.textDsc.text.text = string.formatbykey('DscClubMonth2', timerStr)
  525. itemLua.active:SetActive(true)
  526. itemLua.unActive:SetActive(false)
  527. else
  528. self:StopRefreshTimer(itemLua)
  529. local mdec = cfgData.Monthdec
  530. if mdec then
  531. itemLua.textDsc.text.text = string.formatbykey(cfgData.Monthdec)
  532. else
  533. itemLua.textDsc.text.text = ""
  534. end
  535. itemLua.active:SetActive(false)
  536. itemLua.unActive:SetActive(true)
  537. end
  538. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickMonthCardPrice, showGoodsData:GetId())
  539. end
  540. function UIRuneShopBTView:RefreshCurrenyItem(itemLua, itemCfgId, itemNum, ignoreIcon)
  541. if not itemCfgId or not itemNum then
  542. itemLua:SetActive(false)
  543. return
  544. end
  545. itemLua.number.text.text = CommonUtil.FormatNumber(itemNum)
  546. itemLua:SetActive(true)
  547. if ignoreIcon then return end
  548. itemLua.icon.image.sprite = nil
  549. itemLua.icon.image.enabled = false
  550. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(itemCfgId)
  551. if itemCfgData then
  552. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function(sprite)
  553. if sprite then
  554. itemLua.icon.image.sprite = sprite
  555. itemLua.icon.image.enabled = true
  556. end
  557. end)
  558. end
  559. end
  560. function UIRuneShopBTView:RefreshRoPassView()
  561. local cfgData = ManagerContainer.CfgMgr:GetPassCheckCfgById(1)
  562. local isActive = self.controller:GetRoPassStatus()
  563. if isActive then
  564. self.rOPassport.active:SetActive(true)
  565. self.rOPassport.presentPrice:SetActive(false)
  566. else
  567. self.rOPassport.active:SetActive(false)
  568. self.rOPassport.presentPrice:SetActive(true)
  569. self.rOPassport.presentPrice.number.text.text = tostring(cfgData and cfgData.RMB or 999)
  570. self.uiBase:AddButtonUniqueEventListener(self.rOPassport.presentPrice.button, self, self.OnClickRoPassBuy, 1)
  571. end
  572. self.rOPassport.scrollView.loopListView:SetListItemCount(0, true)
  573. if not cfgData then
  574. return
  575. end
  576. self.roPassUnlockDess = isActive and cfgData.Activation or cfgData.UnlockDes
  577. if not self.roPassUnlockDess then
  578. return
  579. end
  580. self.rOPassport.scrollView.loopListView:SetListItemCount(#self.roPassUnlockDess, true)
  581. end
  582. function UIRuneShopBTView:GetItemByIndexROPass(loopListView, itemIdx)
  583. local unlockDess = self.roPassUnlockDess
  584. if not unlockDess then
  585. return nil
  586. end
  587. local unlockDes = unlockDess[itemIdx + 1]
  588. if not unlockDes then
  589. return nil
  590. end
  591. local item = loopListView:NewListViewItem('EntryUnlockDscItem')
  592. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'EntryUnlockDscItem', item.gameObject)
  593. if itemLua then
  594. local idx = unlockDes[1] or 0
  595. itemLua.icon.uIImageSwitchSprite:ChangeSprite(idx)
  596. local params = {}
  597. local langKey = unlockDes[2]
  598. for i = 3, #unlockDes do
  599. params[#params + 1] = tostring(unlockDes[i])
  600. end
  601. itemLua.desTxt.text.text = string.formatbykey(langKey, unpack(params))
  602. end
  603. ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform)
  604. return item
  605. end
  606. function UIRuneShopBTView:RefreshGiftsView(resetPos)
  607. local shopSubType = self.controller:GetShopSubType()
  608. if shopSubType == Enum.RuneShopSubType.Week then
  609. self:RefreshShopSubBtnState(self.dailyBtn, false)
  610. self:RefreshShopSubBtnState(self.weekBtn, true)
  611. self:RefreshShopSubBtnState(self.roCoinBtn, false)
  612. self:RefreshShopSubBtnState(self.goldBtn, false)
  613. self:RefreshShopSubBtnState(self.monthBtn, false)
  614. elseif shopSubType == Enum.RuneShopSubType.ROCoin then
  615. self:RefreshShopSubBtnState(self.dailyBtn, false)
  616. self:RefreshShopSubBtnState(self.weekBtn, false)
  617. self:RefreshShopSubBtnState(self.roCoinBtn, true)
  618. self:RefreshShopSubBtnState(self.goldBtn, false)
  619. self:RefreshShopSubBtnState(self.monthBtn, false)
  620. elseif shopSubType == Enum.RuneShopSubType.Gold then
  621. self:RefreshShopSubBtnState(self.dailyBtn, false)
  622. self:RefreshShopSubBtnState(self.weekBtn, false)
  623. self:RefreshShopSubBtnState(self.roCoinBtn, false)
  624. self:RefreshShopSubBtnState(self.goldBtn, true)
  625. self:RefreshShopSubBtnState(self.monthBtn, false)
  626. elseif shopSubType == Enum.RuneShopSubType.Daily then
  627. self:RefreshShopSubBtnState(self.dailyBtn, true)
  628. self:RefreshShopSubBtnState(self.weekBtn, false)
  629. self:RefreshShopSubBtnState(self.roCoinBtn, false)
  630. self:RefreshShopSubBtnState(self.goldBtn, false)
  631. self:RefreshShopSubBtnState(self.monthBtn, false)
  632. else
  633. self:RefreshShopSubBtnState(self.dailyBtn, false)
  634. self:RefreshShopSubBtnState(self.weekBtn, false)
  635. self:RefreshShopSubBtnState(self.roCoinBtn, false)
  636. self:RefreshShopSubBtnState(self.goldBtn, false)
  637. self:RefreshShopSubBtnState(self.monthBtn, true)
  638. end
  639. local endTime = self.controller:GetRemainTime()
  640. if endTime then
  641. self:StartRefreshTimer(self, true)
  642. if endTime < 0 then endTime = 0 end
  643. self.timeBox:SetActive(true)
  644. self.timeBox.textTime.text.text = string.formatbykey('RuneShopRefreshTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false))
  645. else
  646. self:StopRefreshTimer(self)
  647. self.timeBox:SetActive(false)
  648. end
  649. local showGoodsDatas = self.controller:GetShowGoodsDatas()
  650. local length = (showGoodsDatas and #showGoodsDatas or 0)
  651. if resetPos then
  652. self.giftsBox.scrollView.loopGridView:RefreshListByIndex(length, 0)
  653. else
  654. self.giftsBox.scrollView.loopGridView:RefreshListByIndex(length)
  655. end
  656. end
  657. function UIRuneShopBTView:RefreshShopSubBtnState(itemLua, isOn)
  658. itemLua.off:SetActive(not isOn)
  659. itemLua.on:SetActive(isOn)
  660. itemLua.button.interactable = (not isOn)
  661. end
  662. function UIRuneShopBTView:GetItemByRowColumnGifts(loopGridView, itemIdx, row, column)
  663. local data = self.controller:GetShowGoodsDataByIdx(itemIdx + 1)
  664. if not data then return nil end
  665. local shopSubType = self.controller:GetShopSubType()
  666. if shopSubType == Enum.RuneShopSubType.ROCoin then
  667. return self:RefreshRoCoinShopGoodsItem(loopGridView, data)
  668. else
  669. return self:RefreshMoneyShopGoodsItem(loopGridView, data)
  670. end
  671. end
  672. function UIRuneShopBTView:RefreshMoneyShopGoodsItem(loopGridView, data)
  673. local item = loopGridView:NewListViewItem('RuneShopGoodsItem')
  674. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RuneShopGoodsItem', item.gameObject)
  675. if itemLua then
  676. itemLua.itemIcon.image.sprite = nil
  677. itemLua.itemIcon.image.enabled = false
  678. local cfgData = data.cfgData
  679. if cfgData then
  680. CommonUtil.LoadIcon(self, cfgData.Pic, function(sprite)
  681. if sprite then
  682. itemLua.itemIcon.image.sprite = sprite
  683. itemLua.itemIcon.image.enabled = true
  684. end
  685. end, itemLua, 'ItemIcon')
  686. itemLua.itemName.text.text = string.formatbykey(cfgData.Name)
  687. if cfgData.FirstBuyReward and #cfgData.FirstBuyReward > 0 and data:IsFirstBuy() then
  688. itemLua.discount:SetActive(true)
  689. itemLua.discount.text.text.text = string.formatbykey('LabelFirst')
  690. self:RefreshGiftsItem(itemLua, FirstBuyBgIconPath, cfgData.FirstBuyPic, cfgData.Reward)
  691. elseif cfgData.ExtraBuyReward and #cfgData.ExtraBuyReward > 0 then
  692. itemLua.discount:SetActive(true)
  693. itemLua.discount.text.text.text = string.formatbykey('LabelExtra')
  694. self:RefreshGiftsItem(itemLua, ExtraBuyBgIconPath, cfgData.ExtraBuyPic, cfgData.Reward)
  695. else
  696. itemLua.discount:SetActive(false)
  697. self:RefreshGiftsItem(itemLua, nil, nil, cfgData.Reward)
  698. end
  699. else
  700. itemLua.discount:SetActive(false)
  701. itemLua.itemName.text.text = ''
  702. itemLua.specialReward:SetActive(false)
  703. itemLua.goodsItems:SetActive(false)
  704. end
  705. local remainBuyNum = data:GetRemainBuyNum()
  706. if remainBuyNum >= 0 then
  707. itemLua.purchaseLimit:SetActive(true)
  708. itemLua.purchaseLimit.text.text = string.formatbykey('RuneShopLimitBuy', tostring(remainBuyNum))
  709. else
  710. itemLua.purchaseLimit:SetActive(false)
  711. end
  712. local price = data:GetPrice()
  713. if price <= 0 then
  714. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  715. else
  716. itemLua.presentPrice.number.text.text = tostring(price)
  717. end
  718. if data:IsSoldout() then
  719. itemLua.soldout:SetActive(true)
  720. itemLua.button.onClick:RemoveAllListeners()
  721. itemLua.presentPrice.button.onClick:RemoveAllListeners()
  722. else
  723. itemLua.soldout:SetActive(false)
  724. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickGiftItem, data:GetId())
  725. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickGiftPrice, data:GetId())
  726. end
  727. end
  728. return item
  729. end
  730. function UIRuneShopBTView:RefreshRoCoinShopGoodsItem(gridView, data)
  731. local item = gridView:NewListViewItem('ShopGoodsItem')
  732. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'ShopGoodsItem', item.gameObject)
  733. local cfgData = data:GetCfgData()
  734. local rewards = cfgData.Reward
  735. local cfgId = rewards[1][1]
  736. CommonUtil.UpdateItemPrefab(self, itemLua.iconItem, {cfgId = cfgId}, nil)
  737. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemIds.ROCoin)
  738. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite)
  739. itemLua.presentPrice.icon.image.sprite = sprite
  740. itemLua.originalPrice.icon.image.sprite = sprite
  741. end, itemLua, 'CurrenyIcon')
  742. itemLua.itemName.text.text = string.formatbykey(cfgData.Name)
  743. local price = data:GetPrice()
  744. if price <= 0 then
  745. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  746. else
  747. itemLua.presentPrice.number.text.text = tostring(price)
  748. end
  749. itemLua.discount:SetActive(false)
  750. itemLua.originalPrice:SetActive(false)
  751. local remainBuyNum = data:GetRemainBuyNum()
  752. if remainBuyNum >= 0 then
  753. itemLua.purchaseLimit:SetActive(true)
  754. itemLua.purchaseLimit.text.text = string.formatbykey("RuneShopLimitBuy", remainBuyNum)
  755. itemLua.limitBox:SetActive(false)
  756. else
  757. itemLua.purchaseLimit:SetActive(false)
  758. itemLua.limitBox:SetActive(false)
  759. end
  760. itemLua.soldout:SetActive(data:IsSoldout())
  761. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickShopGoodsItem, data)
  762. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickShopGoodsItem, data)
  763. return item
  764. end
  765. function UIRuneShopBTView:RefreshGiftsItem(itemLua, bgPic, numPic, rewards)
  766. if numPic and numPic ~= '' then
  767. itemLua.specialReward.bg.image.sprite = nil
  768. itemLua.specialReward.bg.image.enabled = false
  769. CommonUtil.LoadIcon(self, bgPic, function(sprite)
  770. if sprite then
  771. itemLua.specialReward.bg.image.sprite = sprite
  772. itemLua.specialReward.bg.image.enabled = true
  773. end
  774. end, itemLua, 'SpecialRewardBgIcon')
  775. itemLua.specialReward.num.image.sprite = nil
  776. itemLua.specialReward.num.image.enabled = false
  777. CommonUtil.LoadIcon(self, numPic, function(sprite)
  778. if sprite then
  779. itemLua.specialReward.num.image.sprite = sprite
  780. itemLua.specialReward.num.image.enabled = true
  781. end
  782. end, itemLua, 'SpecialRewardNumIcon')
  783. itemLua.specialReward:SetActive(true)
  784. itemLua.goodsItems:SetActive(false)
  785. else
  786. itemLua.specialReward:SetActive(false)
  787. if rewards then
  788. itemLua.goodsItems:SetActive(true)
  789. local reward = rewards[1]
  790. if reward then
  791. itemLua.iconSmallItem1:SetActive(true)
  792. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem1, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  793. else
  794. itemLua.iconSmallItem1:SetActive(false)
  795. end
  796. reward = rewards[2]
  797. if reward then
  798. itemLua.iconSmallItem2:SetActive(true)
  799. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem2, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  800. else
  801. itemLua.iconSmallItem2:SetActive(false)
  802. end
  803. reward = rewards[3]
  804. if reward then
  805. itemLua.iconSmallItem3:SetActive(true)
  806. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem3, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  807. else
  808. itemLua.iconSmallItem3:SetActive(false)
  809. end
  810. else
  811. itemLua.goodsItems:SetActive(false)
  812. end
  813. end
  814. end
  815. function UIRuneShopBTView:GetItemByRowColumnLimited(loopGridView, itemIdx, row, column)
  816. local data = self.controller:GetShowGoodsDataByIdx(itemIdx + 1)
  817. if not data then return nil end
  818. local item = loopGridView:NewListViewItem('RuneShopLimitedItem')
  819. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RuneShopLimitedItem', item.gameObject)
  820. if itemLua then
  821. itemLua.itemIcon.image.sprite = nil
  822. itemLua.itemIcon.image.enabled = false
  823. local cfgData = data.cfgData
  824. if cfgData then
  825. CommonUtil.LoadIcon(self, cfgData.Banner, function(sprite)
  826. if sprite then
  827. itemLua.itemIcon.image.sprite = sprite
  828. itemLua.itemIcon.image.enabled = true
  829. end
  830. end, itemLua, 'ItemIcon')
  831. end
  832. if data:HasEndTime() then
  833. local timerStr = data:CalculateLimitTime()
  834. itemLua.timerLab.text.text.text = string.formatbykey('RuneShopLimitTime', timerStr)
  835. itemLua.timerLab:SetActive(true)
  836. self:StartRefreshTimer(itemLua, data)
  837. else
  838. self:StopRefreshTimer(itemLua)
  839. itemLua.timerLab:SetActive(false)
  840. end
  841. local price = data:GetPrice()
  842. if price <= 0 then
  843. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  844. else
  845. itemLua.presentPrice.number.text.text = tostring(price)
  846. end
  847. if data:IsSoldout() then
  848. itemLua.soldout:SetActive(true)
  849. itemLua.button.onClick:RemoveAllListeners()
  850. itemLua.presentPrice.button.onClick:RemoveAllListeners()
  851. else
  852. itemLua.soldout:SetActive(false)
  853. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickLimitedItem, data:GetId(), itemIdx)
  854. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickLimitedPrice, data:GetId(), itemIdx)
  855. end
  856. itemLua.redPoint:SetActive(ManagerContainer.RedPointMgr.RSLimitGiftRPCtr:GetRedPointStatusById(data:GetId()))
  857. end
  858. return item
  859. end
  860. function UIRuneShopBTView:RefreshLimitedView(resetPos)
  861. local showGoodsDatas = self.controller:GetShowGoodsDatas()
  862. local length = (showGoodsDatas and #showGoodsDatas or 0)
  863. if resetPos then
  864. self.limitedBox.scrollView.loopGridView:RefreshListByIndex(length, 0)
  865. else
  866. self.limitedBox.scrollView.loopGridView:RefreshListByIndex(length)
  867. end
  868. end
  869. function UIRuneShopBTView:StartRefreshTimer(itemLua, goodsData)
  870. local timer = self.refreshTimer
  871. if not timer then
  872. timer = Timer.New(slot(self.RefreshTimer, self), 1, -1)
  873. self.refreshTimer = timer
  874. end
  875. local updateItemMap = timer.updateItemMap
  876. if not updateItemMap then
  877. updateItemMap = {}
  878. timer.updateItemMap = updateItemMap
  879. end
  880. updateItemMap[itemLua] = goodsData
  881. if not timer.running then
  882. timer:Start()
  883. end
  884. end
  885. function UIRuneShopBTView:StopRefreshTimer(itemLua)
  886. local timer = self.refreshTimer
  887. if timer then
  888. local updateItemMap = timer.updateItemMap
  889. if updateItemMap then
  890. updateItemMap[itemLua] = nil
  891. end
  892. if not updateItemMap or table_is_empty(updateItemMap) then
  893. timer:Stop()
  894. end
  895. end
  896. end
  897. function UIRuneShopBTView:StopAndClearRefreshTimer()
  898. if self.refreshTimer then
  899. self.refreshTimer:Stop()
  900. self.refreshTimer.time = 1
  901. self.refreshTimer.duration = 1
  902. self.refreshTimer.updateItemMap = nil
  903. end
  904. end
  905. function UIRuneShopBTView:DisposeRefreshTimer()
  906. self:StopAndClearRefreshTimer()
  907. self.refreshTimer = nil
  908. end
  909. function UIRuneShopBTView:RefreshTimer()
  910. local timer = self.refreshTimer
  911. if not timer then return end
  912. local updateItemMap = timer.updateItemMap
  913. if not updateItemMap or table_is_empty(updateItemMap) then
  914. timer:Stop()
  915. return
  916. end
  917. local minRemainTime = nil
  918. local runeShopType = self.controller:GetShopType()
  919. if runeShopType == Enum.RuneShopType.MonthCard then
  920. for itemLua, goodsData in pairs(updateItemMap) do
  921. local timerStr, outTime, remainTime = goodsData:CalculateLimitTime()
  922. if not outTime then
  923. itemLua.textDsc.text.text = string.formatbykey('DscClubMonth2', timerStr)
  924. itemLua.active:SetActive(true)
  925. itemLua.unActive:SetActive(false)
  926. else
  927. updateItemMap[itemLua] = nil
  928. itemLua.textDsc.text.text = string.formatbykey('DscClubMonth1')
  929. itemLua.active:SetActive(false)
  930. itemLua.unActive:SetActive(true)
  931. end
  932. if remainTime and remainTime > 0 then
  933. if not minRemainTime or minRemainTime > remainTime then
  934. minRemainTime = remainTime
  935. end
  936. end
  937. end
  938. if minRemainTime and minRemainTime > 0 then
  939. minRemainTime = 1
  940. end
  941. elseif runeShopType == Enum.RuneShopType.Gifts then
  942. local endTime = self.controller:GetRemainTime()
  943. if endTime then
  944. if endTime < 0 then endTime = 0 end
  945. if endTime <= 0 then
  946. timer.updateItemMap = nil
  947. end
  948. self.timeBox:SetActive(true)
  949. self.timeBox.textTime.text.text = string.formatbykey('RuneShopRefreshTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false))
  950. else
  951. self.timeBox:SetActive(false)
  952. timer.updateItemMap = nil
  953. end
  954. if endTime and endTime > 0 then
  955. if not minRemainTime or minRemainTime > endTime then
  956. minRemainTime = endTime
  957. end
  958. end
  959. elseif runeShopType == Enum.RuneShopType.LimitTime then
  960. for itemLua, goodsData in pairs(updateItemMap) do
  961. if goodsData:HasEndTime() then
  962. local timerStr, outTime, remainTime = goodsData:CalculateLimitTime()
  963. if outTime then
  964. updateItemMap[itemLua] = nil
  965. end
  966. itemLua.timerLab.text.text.text = string.formatbykey('RuneShopLimitTime', timerStr)
  967. itemLua.timerLab:SetActive(true)
  968. if remainTime and remainTime > 0 then
  969. if not minRemainTime or minRemainTime > remainTime then
  970. minRemainTime = remainTime
  971. end
  972. end
  973. else
  974. updateItemMap[itemLua] = nil
  975. itemLua.timerLab:SetActive(false)
  976. end
  977. if minRemainTime and minRemainTime > 0 then
  978. minRemainTime = 1
  979. end
  980. end
  981. end
  982. if not minRemainTime or minRemainTime <= 0 then
  983. self:StopRefreshTimer()
  984. else
  985. -- 降低刷新频率
  986. if self.refreshTimer then
  987. local validTime = nil
  988. if minRemainTime >= 86400 then
  989. validTime = minRemainTime % 3600
  990. if validTime == 0 then validTime = 3600 end
  991. elseif minRemainTime >= 3600 then
  992. validTime = minRemainTime % 60
  993. if validTime == 0 then validTime = 60 end
  994. else
  995. validTime = 1
  996. end
  997. if validTime then
  998. self.refreshTimer.duration = validTime
  999. else
  1000. self:StopRefreshTimer()
  1001. end
  1002. end
  1003. end
  1004. end
  1005. return UIRuneShopBTView