UIRuneShopBTView.lua 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  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. self:SetHideLB()
  254. local shopType = self.controller:GetShopType()
  255. local toggleGroup = self.content.toggleGroup
  256. local oldAllowSwitchOff = toggleGroup.allowSwitchOff
  257. toggleGroup.allowSwitchOff = true
  258. self.weekToggle.toggle.isOn = (shopType == Enum.RuneShopType.MonthCard)
  259. self.giftsToggle.toggle.isOn = (shopType == Enum.RuneShopType.Gifts)
  260. self.limitedToggle.toggle.isOn = (shopType == Enum.RuneShopType.LimitTime)
  261. toggleGroup.allowSwitchOff = oldAllowSwitchOff
  262. end
  263. function UIRuneShopBTView:RefreshShopView(resetPos)
  264. self.privilegeUnlockDess = nil
  265. self.privilegeRewards = nil
  266. self.roPassUnlockDess = nil
  267. self:StopAndClearRefreshTimer()
  268. local shopType = self.controller:GetShopType()
  269. if shopType == Enum.RuneShopType.SpecialPrivilege then
  270. self.privilegeBox:SetActive(true)
  271. self.weekBox:SetActive(false)
  272. self.passportBox:SetActive(false)
  273. self.giftsBox:SetActive(false)
  274. self.limitedBox:SetActive(false)
  275. self:RefreshSpecialPrivilegeView()
  276. self.textBox.text.text = string.formatbykey('DscClub05')
  277. elseif shopType == Enum.RuneShopType.MonthCard then
  278. self.privilegeBox:SetActive(false)
  279. self.weekBox:SetActive(true)
  280. self.passportBox:SetActive(false)
  281. self.giftsBox:SetActive(false)
  282. self.limitedBox:SetActive(false)
  283. self:RefreshMonthCardView()
  284. self.textBox.text.text = string.formatbykey('DscClub06')
  285. elseif shopType == Enum.RuneShopType.PassCheck then
  286. self.privilegeBox:SetActive(false)
  287. self.weekBox:SetActive(false)
  288. self.passportBox:SetActive(true)
  289. self.giftsBox:SetActive(false)
  290. self.limitedBox:SetActive(false)
  291. self:RefreshRoPassView()
  292. self.textBox.text.text = string.formatbykey('DscClub07')
  293. elseif shopType == Enum.RuneShopType.Gifts then
  294. self.privilegeBox:SetActive(false)
  295. self.weekBox:SetActive(false)
  296. self.passportBox:SetActive(false)
  297. self.giftsBox:SetActive(true)
  298. self.limitedBox:SetActive(false)
  299. self:RefreshGiftsView(resetPos)
  300. self.textBox.text.text = string.formatbykey('DscClub02')
  301. elseif shopType == Enum.RuneShopType.LimitTime then
  302. self.privilegeBox:SetActive(false)
  303. self.weekBox:SetActive(false)
  304. self.passportBox:SetActive(false)
  305. self.giftsBox:SetActive(false)
  306. self.limitedBox:SetActive(true)
  307. self:RefreshLimitedView(resetPos)
  308. self.textBox.text.text = string.formatbykey('DscClub03')
  309. else
  310. self.privilegeBox:SetActive(false)
  311. self.weekBox:SetActive(false)
  312. self.passportBox:SetActive(false)
  313. self.giftsBox:SetActive(false)
  314. self.limitedBox:SetActive(false)
  315. self.textBox.text.text = ''
  316. end
  317. end
  318. function UIRuneShopBTView:RefreshSpecialPrivilegeView()
  319. local id = self.controller:GetSpecialPrivilegeId()
  320. local cfgData = nil
  321. local unlock = true
  322. if id then
  323. cfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(id)
  324. if not cfgData then
  325. id = 1
  326. cfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(1)
  327. unlock = false
  328. end
  329. else
  330. id = 1
  331. cfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(1)
  332. unlock = false
  333. end
  334. if not cfgData then
  335. self.privilegeBox:SetActive(false)
  336. return
  337. end
  338. local privilegeCardItem = self.privilegeCardItem
  339. privilegeCardItem.privilegeLv1:SetActive(id == 1)
  340. privilegeCardItem.privilegeLv2:SetActive(id == 2)
  341. local buyRewards = cfgData.BuyReward
  342. if buyRewards then
  343. local buyReward = buyRewards[1]
  344. if buyReward then
  345. self:RefreshCurrenyItem(privilegeCardItem.buyReward1, buyReward[1], buyReward[2], true)
  346. else
  347. self:RefreshCurrenyItem(privilegeCardItem.buyReward1)
  348. end
  349. buyReward = buyRewards[2]
  350. if buyReward then
  351. self:RefreshCurrenyItem(privilegeCardItem.buyReward2, buyReward[1], buyReward[2], true)
  352. else
  353. self:RefreshCurrenyItem(privilegeCardItem.buyReward2)
  354. end
  355. else
  356. self:RefreshCurrenyItem(privilegeCardItem.buyReward1)
  357. self:RefreshCurrenyItem(privilegeCardItem.buyReward2)
  358. end
  359. privilegeCardItem.privilegeScrollView.loopListView:SetListItemCount(0, true)
  360. self.privilegeUnlockDess = unlock and cfgData.Activation or cfgData.UnlockDes
  361. if self.privilegeUnlockDess then
  362. privilegeCardItem.privilegeScrollView.loopListView:SetListItemCount(#self.privilegeUnlockDess, true)
  363. end
  364. privilegeCardItem.rewardScrollView.loopGridView:SetListItemCount(0, true)
  365. self.privilegeRewards = nil
  366. if cfgData.Reward then
  367. self.privilegeRewards = {}
  368. for i = 1, #cfgData.Reward do
  369. local reward = cfgData.Reward[i]
  370. self.privilegeRewards[#self.privilegeRewards+1] = {cfgId = reward[1], num = reward[2]}
  371. end
  372. end
  373. if self.privilegeRewards then
  374. privilegeCardItem.rewardScrollView.loopGridView:SetListItemCount(#self.privilegeRewards, true)
  375. end
  376. privilegeCardItem.active:SetActive(unlock)
  377. privilegeCardItem.unActive:SetActive(not unlock)
  378. if unlock then
  379. local nextCfgData = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(id + 1)
  380. if nextCfgData then
  381. local canUpgrade = false
  382. if nextCfgData.UnlockCond then
  383. canUpgrade = ConditionJudge:ConditionPassResult1(nextCfgData.UnlockCond)
  384. end
  385. privilegeCardItem.btnUpgrade:SetActive(canUpgrade)
  386. privilegeCardItem.btnBuyPrivilege:SetActive(false)
  387. self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnUpgrade.button, self, self.OnClickPrivlegeActiveBtn)
  388. else
  389. privilegeCardItem.btnUpgrade:SetActive(false)
  390. privilegeCardItem.btnBuyPrivilege:SetActive(false)
  391. end
  392. if self.controller:CanGetSpecialPrivilegeReward() then
  393. privilegeCardItem.btnReceive:SetActive(true)
  394. privilegeCardItem.labelReceived:SetActive(false)
  395. else
  396. privilegeCardItem.btnReceive:SetActive(false)
  397. privilegeCardItem.labelReceived:SetActive(true)
  398. end
  399. self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnReceive.button, self, self.OnClickPrivlegeReceiveBtn)
  400. else
  401. privilegeCardItem.btnUpgrade:SetActive(false)
  402. privilegeCardItem.btnBuyPrivilege:SetActive(true)
  403. privilegeCardItem.btnReceive:SetActive(true)
  404. privilegeCardItem.labelReceived:SetActive(false)
  405. self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnBuyPrivilege.button, self, self.OnClickPrivlegeActiveBtn)
  406. self.uiBase:AddButtonUniqueEventListener(privilegeCardItem.btnReceive.button, self, self.OnClickPrivlegeActiveBtn)
  407. end
  408. end
  409. function UIRuneShopBTView:OnClickPrivlegeReceiveBtn()
  410. local errorCode = self.controller:SendRuneSpecialPrvilegeRewardReq()
  411. if errorCode ~= 0 then
  412. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  413. end
  414. end
  415. function UIRuneShopBTView:OnClickPrivlegeActiveBtn()
  416. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPrivilegeCardTips)
  417. end
  418. function UIRuneShopBTView:GetItemByIndexPrivilege(loopListView, itemIdx)
  419. local unlockDess = self.privilegeUnlockDess
  420. if not unlockDess then
  421. return nil
  422. end
  423. local unlockDes = unlockDess[itemIdx + 1]
  424. if not unlockDes then
  425. return nil
  426. end
  427. local item = loopListView:NewListViewItem('EntryUnlockDscItem')
  428. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'EntryUnlockDscItem', item.gameObject)
  429. if itemLua then
  430. local idx = unlockDes[1] or 0
  431. itemLua.icon.uIImageSwitchSprite:ChangeSprite(idx)
  432. local params = {}
  433. local langKey = unlockDes[2]
  434. for i = 3, #unlockDes do
  435. params[#params + 1] = tostring(unlockDes[i])
  436. end
  437. itemLua.desTxt.text.text = string.formatbykey(langKey, unpack(params))
  438. end
  439. ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform)
  440. return item
  441. end
  442. function UIRuneShopBTView:GetItemByRowColumnPrivilege(loopGridView, itemIdx, row, column)
  443. if not self.privilegeRewards then
  444. return nil
  445. end
  446. local reward = self.privilegeRewards[itemIdx + 1]
  447. if not reward then
  448. return nil
  449. end
  450. local item = loopGridView:NewListViewItem('Item')
  451. local iconItem = item.transform:Find('IconItem')
  452. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'IconItem', iconItem.gameObject)
  453. CommonUtil.UpdateItemPrefab(self, itemLua, reward, nil, self, self.ShowItemTips, reward)
  454. return item
  455. end
  456. function UIRuneShopBTView:ShowItemTips(button, params)
  457. local data = params[0]
  458. ManagerContainer.LuaUIMgr:OpenTips(data)
  459. end
  460. function UIRuneShopBTView:RefreshMonthCardView()
  461. self:RefreshOneMonthCardView(self.weekCard1, 1)
  462. end
  463. function UIRuneShopBTView:RefreshOneMonthCardView(itemLua, idx)
  464. local showGoodsDatas = self.controller:GetShowGoodsDatas()
  465. if not showGoodsDatas then
  466. itemLua:SetActive(false)
  467. return
  468. end
  469. local showGoodsData = showGoodsDatas[idx]
  470. if not showGoodsData then
  471. itemLua:SetActive(false)
  472. return
  473. end
  474. itemLua:SetActive(true)
  475. local cfgData = showGoodsData:GetCfgData()
  476. local buyRewards = cfgData.BuyReward
  477. if buyRewards then
  478. local buyReward = buyRewards[1]
  479. if buyReward then
  480. self:RefreshCurrenyItem(itemLua.buyReward1, buyReward[1], buyReward[2], true)
  481. else
  482. self:RefreshCurrenyItem(itemLua.buyReward1)
  483. end
  484. buyReward = buyRewards[2]
  485. if buyReward then
  486. self:RefreshCurrenyItem(itemLua.buyReward2, buyReward[1], buyReward[2], true)
  487. else
  488. self:RefreshCurrenyItem(itemLua.buyReward2)
  489. end
  490. else
  491. self:RefreshCurrenyItem(itemLua.buyReward1)
  492. self:RefreshCurrenyItem(itemLua.buyReward2)
  493. end
  494. local dayRewards = cfgData.DayReward
  495. if dayRewards then
  496. local dayReward = dayRewards[1]
  497. if dayReward then
  498. self:RefreshCurrenyItem(itemLua.dailyReward, dayReward[1], dayReward[2], true)
  499. else
  500. self:RefreshCurrenyItem(itemLua.dailyReward)
  501. end
  502. else
  503. self:RefreshCurrenyItem(itemLua.dailyReward)
  504. end
  505. local totalRewards = cfgData.TotalReward
  506. if totalRewards then
  507. local totalReward = totalRewards[1]
  508. if totalReward then
  509. self:RefreshCurrenyItem(itemLua.totalReward, totalReward[1], totalReward[2], true)
  510. else
  511. self:RefreshCurrenyItem(itemLua.totalReward)
  512. end
  513. else
  514. self:RefreshCurrenyItem(itemLua.totalReward)
  515. end
  516. local price = showGoodsData:GetPrice()
  517. if price <= 0 then
  518. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  519. else
  520. itemLua.presentPrice.number.text.text = tostring(price)
  521. end
  522. local timerStr, outTime = showGoodsData:CalculateLimitTime()
  523. if not outTime then
  524. self:StartRefreshTimer(itemLua, showGoodsData)
  525. itemLua.textDsc.text.text = string.formatbykey('DscClubMonth2', timerStr)
  526. itemLua.active:SetActive(true)
  527. itemLua.unActive:SetActive(false)
  528. else
  529. self:StopRefreshTimer(itemLua)
  530. local mdec = cfgData.Monthdec
  531. if mdec then
  532. itemLua.textDsc.text.text = string.formatbykey(cfgData.Monthdec)
  533. else
  534. itemLua.textDsc.text.text = ""
  535. end
  536. itemLua.active:SetActive(false)
  537. itemLua.unActive:SetActive(true)
  538. end
  539. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickMonthCardPrice, showGoodsData:GetId())
  540. end
  541. function UIRuneShopBTView:RefreshCurrenyItem(itemLua, itemCfgId, itemNum, ignoreIcon)
  542. if not itemCfgId or not itemNum then
  543. itemLua:SetActive(false)
  544. return
  545. end
  546. itemLua.number.text.text = CommonUtil.FormatNumber(itemNum)
  547. itemLua:SetActive(true)
  548. if ignoreIcon then return end
  549. itemLua.icon.image.sprite = nil
  550. itemLua.icon.image.enabled = false
  551. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(itemCfgId)
  552. if itemCfgData then
  553. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function(sprite)
  554. if sprite then
  555. itemLua.icon.image.sprite = sprite
  556. itemLua.icon.image.enabled = true
  557. end
  558. end)
  559. end
  560. end
  561. function UIRuneShopBTView:RefreshRoPassView()
  562. local cfgData = ManagerContainer.CfgMgr:GetPassCheckCfgById(1)
  563. local isActive = self.controller:GetRoPassStatus()
  564. if isActive then
  565. self.rOPassport.active:SetActive(true)
  566. self.rOPassport.presentPrice:SetActive(false)
  567. else
  568. self.rOPassport.active:SetActive(false)
  569. self.rOPassport.presentPrice:SetActive(true)
  570. self.rOPassport.presentPrice.number.text.text = tostring(cfgData and cfgData.RMB or 999)
  571. self.uiBase:AddButtonUniqueEventListener(self.rOPassport.presentPrice.button, self, self.OnClickRoPassBuy, 1)
  572. end
  573. self.rOPassport.scrollView.loopListView:SetListItemCount(0, true)
  574. if not cfgData then
  575. return
  576. end
  577. self.roPassUnlockDess = isActive and cfgData.Activation or cfgData.UnlockDes
  578. if not self.roPassUnlockDess then
  579. return
  580. end
  581. self.rOPassport.scrollView.loopListView:SetListItemCount(#self.roPassUnlockDess, true)
  582. end
  583. function UIRuneShopBTView:GetItemByIndexROPass(loopListView, itemIdx)
  584. local unlockDess = self.roPassUnlockDess
  585. if not unlockDess then
  586. return nil
  587. end
  588. local unlockDes = unlockDess[itemIdx + 1]
  589. if not unlockDes then
  590. return nil
  591. end
  592. local item = loopListView:NewListViewItem('EntryUnlockDscItem')
  593. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'EntryUnlockDscItem', item.gameObject)
  594. if itemLua then
  595. local idx = unlockDes[1] or 0
  596. itemLua.icon.uIImageSwitchSprite:ChangeSprite(idx)
  597. local params = {}
  598. local langKey = unlockDes[2]
  599. for i = 3, #unlockDes do
  600. params[#params + 1] = tostring(unlockDes[i])
  601. end
  602. itemLua.desTxt.text.text = string.formatbykey(langKey, unpack(params))
  603. end
  604. ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform)
  605. return item
  606. end
  607. function UIRuneShopBTView:RefreshGiftsView(resetPos)
  608. local shopSubType = self.controller:GetShopSubType()
  609. if shopSubType == Enum.RuneShopSubType.Week then
  610. self:RefreshShopSubBtnState(self.dailyBtn, false)
  611. self:RefreshShopSubBtnState(self.weekBtn, true)
  612. self:RefreshShopSubBtnState(self.roCoinBtn, false)
  613. self:RefreshShopSubBtnState(self.goldBtn, false)
  614. self:RefreshShopSubBtnState(self.monthBtn, false)
  615. elseif shopSubType == Enum.RuneShopSubType.ROCoin then
  616. self:RefreshShopSubBtnState(self.dailyBtn, false)
  617. self:RefreshShopSubBtnState(self.weekBtn, false)
  618. self:RefreshShopSubBtnState(self.roCoinBtn, true)
  619. self:RefreshShopSubBtnState(self.goldBtn, false)
  620. self:RefreshShopSubBtnState(self.monthBtn, false)
  621. elseif shopSubType == Enum.RuneShopSubType.Gold then
  622. self:RefreshShopSubBtnState(self.dailyBtn, false)
  623. self:RefreshShopSubBtnState(self.weekBtn, false)
  624. self:RefreshShopSubBtnState(self.roCoinBtn, false)
  625. self:RefreshShopSubBtnState(self.goldBtn, true)
  626. self:RefreshShopSubBtnState(self.monthBtn, false)
  627. elseif shopSubType == Enum.RuneShopSubType.Daily then
  628. self:RefreshShopSubBtnState(self.dailyBtn, true)
  629. self:RefreshShopSubBtnState(self.weekBtn, false)
  630. self:RefreshShopSubBtnState(self.roCoinBtn, false)
  631. self:RefreshShopSubBtnState(self.goldBtn, false)
  632. self:RefreshShopSubBtnState(self.monthBtn, false)
  633. else
  634. self:RefreshShopSubBtnState(self.dailyBtn, false)
  635. self:RefreshShopSubBtnState(self.weekBtn, false)
  636. self:RefreshShopSubBtnState(self.roCoinBtn, false)
  637. self:RefreshShopSubBtnState(self.goldBtn, false)
  638. self:RefreshShopSubBtnState(self.monthBtn, true)
  639. end
  640. local endTime = self.controller:GetRemainTime()
  641. if endTime then
  642. self:StartRefreshTimer(self, true)
  643. if endTime < 0 then endTime = 0 end
  644. self.timeBox:SetActive(true)
  645. self.timeBox.textTime.text.text = string.formatbykey('RuneShopRefreshTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false))
  646. else
  647. self:StopRefreshTimer(self)
  648. self.timeBox:SetActive(false)
  649. end
  650. local showGoodsDatas = self.controller:GetShowGoodsDatas()
  651. local length = (showGoodsDatas and #showGoodsDatas or 0)
  652. if resetPos then
  653. self.giftsBox.scrollView.loopGridView:RefreshListByIndex(length, 0)
  654. else
  655. self.giftsBox.scrollView.loopGridView:RefreshListByIndex(length)
  656. end
  657. end
  658. function UIRuneShopBTView:RefreshShopSubBtnState(itemLua, isOn)
  659. itemLua.off:SetActive(not isOn)
  660. itemLua.on:SetActive(isOn)
  661. itemLua.button.interactable = (not isOn)
  662. end
  663. function UIRuneShopBTView:GetItemByRowColumnGifts(loopGridView, itemIdx, row, column)
  664. local data = self.controller:GetShowGoodsDataByIdx(itemIdx + 1)
  665. if not data then return nil end
  666. local shopSubType = self.controller:GetShopSubType()
  667. if shopSubType == Enum.RuneShopSubType.ROCoin then
  668. return self:RefreshRoCoinShopGoodsItem(loopGridView, data)
  669. else
  670. return self:RefreshMoneyShopGoodsItem(loopGridView, data)
  671. end
  672. end
  673. function UIRuneShopBTView:RefreshMoneyShopGoodsItem(loopGridView, data)
  674. local item = loopGridView:NewListViewItem('RuneShopGoodsItem')
  675. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RuneShopGoodsItem', item.gameObject)
  676. if itemLua then
  677. itemLua.itemIcon.image.sprite = nil
  678. itemLua.itemIcon.image.enabled = false
  679. itemLua.presentPrice.icon:SetActive(false)
  680. itemLua.presentPrice.currency:SetActive(true)
  681. local cfgData = data.cfgData
  682. if cfgData then
  683. CommonUtil.LoadIcon(self, cfgData.Pic, function(sprite)
  684. if sprite then
  685. itemLua.itemIcon.image.sprite = sprite
  686. itemLua.itemIcon.image.enabled = true
  687. end
  688. end, itemLua, 'ItemIcon')
  689. itemLua.itemName.text.text = string.formatbykey(cfgData.Name)
  690. if cfgData.FirstBuyReward and #cfgData.FirstBuyReward > 0 and data:IsFirstBuy() then
  691. itemLua.discount:SetActive(true)
  692. itemLua.discount.text.text.text = string.formatbykey('LabelFirst')
  693. self:RefreshGiftsItem(itemLua, FirstBuyBgIconPath, cfgData.FirstBuyPic, cfgData.Reward)
  694. elseif cfgData.ExtraBuyReward and #cfgData.ExtraBuyReward > 0 then
  695. itemLua.discount:SetActive(true)
  696. itemLua.discount.text.text.text = string.formatbykey('LabelExtra')
  697. self:RefreshGiftsItem(itemLua, ExtraBuyBgIconPath, cfgData.ExtraBuyPic, cfgData.Reward)
  698. else
  699. itemLua.discount:SetActive(false)
  700. self:RefreshGiftsItem(itemLua, nil, nil, cfgData.Reward)
  701. end
  702. else
  703. itemLua.discount:SetActive(false)
  704. itemLua.itemName.text.text = ''
  705. itemLua.specialReward:SetActive(false)
  706. itemLua.goodsItems:SetActive(false)
  707. end
  708. local remainBuyNum = data:GetRemainBuyNum()
  709. if remainBuyNum >= 0 then
  710. itemLua.purchaseLimit:SetActive(true)
  711. itemLua.purchaseLimit.text.text = string.formatbykey('RuneShopLimitBuy', tostring(remainBuyNum))
  712. else
  713. itemLua.purchaseLimit:SetActive(false)
  714. end
  715. local price = data:GetPrice()
  716. if price <= 0 then
  717. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  718. else
  719. itemLua.presentPrice.number.text.text = tostring(price)
  720. end
  721. if data:IsSoldout() then
  722. itemLua.soldout:SetActive(true)
  723. itemLua.button.onClick:RemoveAllListeners()
  724. itemLua.presentPrice.button.onClick:RemoveAllListeners()
  725. else
  726. itemLua.soldout:SetActive(false)
  727. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickGiftItem, data:GetId())
  728. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickGiftPrice, data:GetId())
  729. end
  730. end
  731. return item
  732. end
  733. function UIRuneShopBTView:RefreshRoCoinShopGoodsItem(gridView, data)
  734. local item = gridView:NewListViewItem('ShopGoodsItem')
  735. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'ShopGoodsItem', item.gameObject)
  736. local cfgData = data:GetCfgData()
  737. local rewards = cfgData.Reward
  738. local cfgId = rewards[1][1]
  739. CommonUtil.UpdateItemPrefab(self, itemLua.iconItem, {cfgId = cfgId}, nil)
  740. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemIds.ROCoin)
  741. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite)
  742. itemLua.presentPrice.icon.image.sprite = sprite
  743. itemLua.originalPrice.icon.image.sprite = sprite
  744. end, itemLua, 'CurrenyIcon')
  745. itemLua.itemName.text.text = string.formatbykey(cfgData.Name)
  746. local price = data:GetPrice()
  747. if price <= 0 then
  748. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  749. else
  750. itemLua.presentPrice.number.text.text = tostring(price)
  751. end
  752. itemLua.discount:SetActive(false)
  753. itemLua.originalPrice:SetActive(false)
  754. local remainBuyNum = data:GetRemainBuyNum()
  755. if remainBuyNum >= 0 then
  756. itemLua.purchaseLimit:SetActive(true)
  757. itemLua.purchaseLimit.text.text = string.formatbykey("RuneShopLimitBuy", remainBuyNum)
  758. itemLua.limitBox:SetActive(false)
  759. else
  760. itemLua.purchaseLimit:SetActive(false)
  761. itemLua.limitBox:SetActive(false)
  762. end
  763. itemLua.soldout:SetActive(data:IsSoldout())
  764. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickShopGoodsItem, data)
  765. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickShopGoodsItem, data)
  766. return item
  767. end
  768. function UIRuneShopBTView:RefreshGiftsItem(itemLua, bgPic, numPic, rewards)
  769. if numPic and numPic ~= '' then
  770. itemLua.specialReward.bg.image.sprite = nil
  771. itemLua.specialReward.bg.image.enabled = false
  772. CommonUtil.LoadIcon(self, bgPic, function(sprite)
  773. if sprite then
  774. itemLua.specialReward.bg.image.sprite = sprite
  775. itemLua.specialReward.bg.image.enabled = true
  776. end
  777. end, itemLua, 'SpecialRewardBgIcon')
  778. itemLua.specialReward.num.image.sprite = nil
  779. itemLua.specialReward.num.image.enabled = false
  780. CommonUtil.LoadIcon(self, numPic, function(sprite)
  781. if sprite then
  782. itemLua.specialReward.num.image.sprite = sprite
  783. itemLua.specialReward.num.image.enabled = true
  784. end
  785. end, itemLua, 'SpecialRewardNumIcon')
  786. itemLua.specialReward:SetActive(true)
  787. itemLua.goodsItems:SetActive(false)
  788. else
  789. itemLua.specialReward:SetActive(false)
  790. if rewards then
  791. itemLua.goodsItems:SetActive(true)
  792. local reward = rewards[1]
  793. if reward then
  794. itemLua.iconSmallItem1:SetActive(true)
  795. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem1, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  796. else
  797. itemLua.iconSmallItem1:SetActive(false)
  798. end
  799. reward = rewards[2]
  800. if reward then
  801. itemLua.iconSmallItem2:SetActive(true)
  802. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem2, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  803. else
  804. itemLua.iconSmallItem2:SetActive(false)
  805. end
  806. reward = rewards[3]
  807. if reward then
  808. itemLua.iconSmallItem3:SetActive(true)
  809. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem3, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  810. else
  811. itemLua.iconSmallItem3:SetActive(false)
  812. end
  813. else
  814. itemLua.goodsItems:SetActive(false)
  815. end
  816. end
  817. end
  818. function UIRuneShopBTView:GetItemByRowColumnLimited(loopGridView, itemIdx, row, column)
  819. local data = self.controller:GetShowGoodsDataByIdx(itemIdx + 1)
  820. if not data then return nil end
  821. local item = loopGridView:NewListViewItem('RuneShopLimitedItem')
  822. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RuneShopLimitedItem', item.gameObject)
  823. if itemLua then
  824. itemLua.itemIcon.image.sprite = nil
  825. itemLua.itemIcon.image.enabled = false
  826. local cfgData = data.cfgData
  827. if cfgData then
  828. CommonUtil.LoadIcon(self, cfgData.Banner, function(sprite)
  829. if sprite then
  830. itemLua.itemIcon.image.sprite = sprite
  831. itemLua.itemIcon.image.enabled = true
  832. end
  833. end, itemLua, 'ItemIcon')
  834. end
  835. if data:HasEndTime() then
  836. local timerStr = data:CalculateLimitTime()
  837. itemLua.timerLab.text.text.text = string.formatbykey('RuneShopLimitTime', timerStr)
  838. itemLua.timerLab:SetActive(true)
  839. self:StartRefreshTimer(itemLua, data)
  840. else
  841. self:StopRefreshTimer(itemLua)
  842. itemLua.timerLab:SetActive(false)
  843. end
  844. local price = data:GetPrice()
  845. if price <= 0 then
  846. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  847. else
  848. itemLua.presentPrice.number.text.text = tostring(price)
  849. end
  850. if data:IsSoldout() then
  851. itemLua.soldout:SetActive(true)
  852. itemLua.button.onClick:RemoveAllListeners()
  853. itemLua.presentPrice.button.onClick:RemoveAllListeners()
  854. else
  855. itemLua.soldout:SetActive(false)
  856. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickLimitedItem, data:GetId(), itemIdx)
  857. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickLimitedPrice, data:GetId(), itemIdx)
  858. end
  859. itemLua.redPoint:SetActive(ManagerContainer.RedPointMgr.RSLimitGiftRPCtr:GetRedPointStatusById(data:GetId()))
  860. end
  861. return item
  862. end
  863. function UIRuneShopBTView:RefreshLimitedView(resetPos)
  864. local showGoodsDatas = self.controller:GetShowGoodsDatas()
  865. local length = (showGoodsDatas and #showGoodsDatas or 0)
  866. if resetPos then
  867. self.limitedBox.scrollView.loopGridView:RefreshListByIndex(length, 0)
  868. else
  869. self.limitedBox.scrollView.loopGridView:RefreshListByIndex(length)
  870. end
  871. end
  872. function UIRuneShopBTView:StartRefreshTimer(itemLua, goodsData)
  873. local timer = self.refreshTimer
  874. if not timer then
  875. timer = Timer.New(slot(self.RefreshTimer, self), 1, -1)
  876. self.refreshTimer = timer
  877. end
  878. local updateItemMap = timer.updateItemMap
  879. if not updateItemMap then
  880. updateItemMap = {}
  881. timer.updateItemMap = updateItemMap
  882. end
  883. updateItemMap[itemLua] = goodsData
  884. if not timer.running then
  885. timer:Start()
  886. end
  887. end
  888. function UIRuneShopBTView:StopRefreshTimer(itemLua)
  889. local timer = self.refreshTimer
  890. if timer then
  891. local updateItemMap = timer.updateItemMap
  892. if updateItemMap then
  893. updateItemMap[itemLua] = nil
  894. end
  895. if not updateItemMap or table_is_empty(updateItemMap) then
  896. timer:Stop()
  897. end
  898. end
  899. end
  900. function UIRuneShopBTView:StopAndClearRefreshTimer()
  901. if self.refreshTimer then
  902. self.refreshTimer:Stop()
  903. self.refreshTimer.time = 1
  904. self.refreshTimer.duration = 1
  905. self.refreshTimer.updateItemMap = nil
  906. end
  907. end
  908. function UIRuneShopBTView:DisposeRefreshTimer()
  909. self:StopAndClearRefreshTimer()
  910. self.refreshTimer = nil
  911. end
  912. function UIRuneShopBTView:RefreshTimer()
  913. local timer = self.refreshTimer
  914. if not timer then return end
  915. local updateItemMap = timer.updateItemMap
  916. if not updateItemMap or table_is_empty(updateItemMap) then
  917. timer:Stop()
  918. return
  919. end
  920. local minRemainTime = nil
  921. local runeShopType = self.controller:GetShopType()
  922. if runeShopType == Enum.RuneShopType.MonthCard then
  923. for itemLua, goodsData in pairs(updateItemMap) do
  924. local timerStr, outTime, remainTime = goodsData:CalculateLimitTime()
  925. if not outTime then
  926. itemLua.textDsc.text.text = string.formatbykey('DscClubMonth2', timerStr)
  927. itemLua.active:SetActive(true)
  928. itemLua.unActive:SetActive(false)
  929. else
  930. updateItemMap[itemLua] = nil
  931. itemLua.textDsc.text.text = string.formatbykey('DscClubMonth1')
  932. itemLua.active:SetActive(false)
  933. itemLua.unActive:SetActive(true)
  934. end
  935. if remainTime and remainTime > 0 then
  936. if not minRemainTime or minRemainTime > remainTime then
  937. minRemainTime = remainTime
  938. end
  939. end
  940. end
  941. if minRemainTime and minRemainTime > 0 then
  942. minRemainTime = 1
  943. end
  944. elseif runeShopType == Enum.RuneShopType.Gifts then
  945. local endTime = self.controller:GetRemainTime()
  946. if endTime then
  947. if endTime < 0 then endTime = 0 end
  948. if endTime <= 0 then
  949. timer.updateItemMap = nil
  950. end
  951. self.timeBox:SetActive(true)
  952. self.timeBox.textTime.text.text = string.formatbykey('RuneShopRefreshTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false))
  953. else
  954. self.timeBox:SetActive(false)
  955. timer.updateItemMap = nil
  956. end
  957. if endTime and endTime > 0 then
  958. if not minRemainTime or minRemainTime > endTime then
  959. minRemainTime = endTime
  960. end
  961. end
  962. elseif runeShopType == Enum.RuneShopType.LimitTime then
  963. for itemLua, goodsData in pairs(updateItemMap) do
  964. if goodsData:HasEndTime() then
  965. local timerStr, outTime, remainTime = goodsData:CalculateLimitTime()
  966. if outTime then
  967. updateItemMap[itemLua] = nil
  968. end
  969. itemLua.timerLab.text.text.text = string.formatbykey('RuneShopLimitTime', timerStr)
  970. itemLua.timerLab:SetActive(true)
  971. if remainTime and remainTime > 0 then
  972. if not minRemainTime or minRemainTime > remainTime then
  973. minRemainTime = remainTime
  974. end
  975. end
  976. else
  977. updateItemMap[itemLua] = nil
  978. itemLua.timerLab:SetActive(false)
  979. end
  980. if minRemainTime and minRemainTime > 0 then
  981. minRemainTime = 1
  982. end
  983. end
  984. end
  985. if not minRemainTime or minRemainTime <= 0 then
  986. self:StopRefreshTimer()
  987. else
  988. -- 降低刷新频率
  989. if self.refreshTimer then
  990. local validTime = nil
  991. if minRemainTime >= 86400 then
  992. validTime = minRemainTime % 3600
  993. if validTime == 0 then validTime = 3600 end
  994. elseif minRemainTime >= 3600 then
  995. validTime = minRemainTime % 60
  996. if validTime == 0 then validTime = 60 end
  997. else
  998. validTime = 1
  999. end
  1000. if validTime then
  1001. self.refreshTimer.duration = validTime
  1002. else
  1003. self:StopRefreshTimer()
  1004. end
  1005. end
  1006. end
  1007. end
  1008. function UIRuneShopBTView:SetHideLB()
  1009. if IShServer() then
  1010. self.controller:SetData({Enum.RuneShopType.Gifts,Enum.RuneShopSubType.ROCoin})
  1011. self.controller:InitData()
  1012. self.privilegeCardToggle:SetActive(false)
  1013. self.weekToggle:SetActive(false)
  1014. self.passportToggle:SetActive(false)
  1015. self.limitedToggle:SetActive(false)
  1016. self.weekBtn:SetActive(false)
  1017. self.monthBtn:SetActive(false)
  1018. end
  1019. end
  1020. return UIRuneShopBTView