UIRuneShopBTView.lua 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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. itemLua.presentPrice.icon:SetActive(false)
  679. itemLua.presentPrice.currency:SetActive(true)
  680. local cfgData = data.cfgData
  681. if cfgData then
  682. CommonUtil.LoadIcon(self, cfgData.Pic, function(sprite)
  683. if sprite then
  684. itemLua.itemIcon.image.sprite = sprite
  685. itemLua.itemIcon.image.enabled = true
  686. end
  687. end, itemLua, 'ItemIcon')
  688. itemLua.itemName.text.text = string.formatbykey(cfgData.Name)
  689. if cfgData.FirstBuyReward and #cfgData.FirstBuyReward > 0 and data:IsFirstBuy() then
  690. itemLua.discount:SetActive(true)
  691. itemLua.discount.text.text.text = string.formatbykey('LabelFirst')
  692. self:RefreshGiftsItem(itemLua, FirstBuyBgIconPath, cfgData.FirstBuyPic, cfgData.Reward)
  693. elseif cfgData.ExtraBuyReward and #cfgData.ExtraBuyReward > 0 then
  694. itemLua.discount:SetActive(true)
  695. itemLua.discount.text.text.text = string.formatbykey('LabelExtra')
  696. self:RefreshGiftsItem(itemLua, ExtraBuyBgIconPath, cfgData.ExtraBuyPic, cfgData.Reward)
  697. else
  698. itemLua.discount:SetActive(false)
  699. self:RefreshGiftsItem(itemLua, nil, nil, cfgData.Reward)
  700. end
  701. else
  702. itemLua.discount:SetActive(false)
  703. itemLua.itemName.text.text = ''
  704. itemLua.specialReward:SetActive(false)
  705. itemLua.goodsItems:SetActive(false)
  706. end
  707. local remainBuyNum = data:GetRemainBuyNum()
  708. if remainBuyNum >= 0 then
  709. itemLua.purchaseLimit:SetActive(true)
  710. itemLua.purchaseLimit.text.text = string.formatbykey('RuneShopLimitBuy', tostring(remainBuyNum))
  711. else
  712. itemLua.purchaseLimit:SetActive(false)
  713. end
  714. local price = data:GetPrice()
  715. if price <= 0 then
  716. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  717. else
  718. itemLua.presentPrice.number.text.text = tostring(price)
  719. end
  720. if data:IsSoldout() then
  721. itemLua.soldout:SetActive(true)
  722. itemLua.button.onClick:RemoveAllListeners()
  723. itemLua.presentPrice.button.onClick:RemoveAllListeners()
  724. else
  725. itemLua.soldout:SetActive(false)
  726. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickGiftItem, data:GetId())
  727. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickGiftPrice, data:GetId())
  728. end
  729. end
  730. return item
  731. end
  732. function UIRuneShopBTView:RefreshRoCoinShopGoodsItem(gridView, data)
  733. local item = gridView:NewListViewItem('ShopGoodsItem')
  734. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'ShopGoodsItem', item.gameObject)
  735. local cfgData = data:GetCfgData()
  736. local rewards = cfgData.Reward
  737. local cfgId = rewards[1][1]
  738. CommonUtil.UpdateItemPrefab(self, itemLua.iconItem, {cfgId = cfgId}, nil)
  739. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemIds.ROCoin)
  740. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite)
  741. itemLua.presentPrice.icon.image.sprite = sprite
  742. itemLua.originalPrice.icon.image.sprite = sprite
  743. end, itemLua, 'CurrenyIcon')
  744. itemLua.itemName.text.text = string.formatbykey(cfgData.Name)
  745. local price = data:GetPrice()
  746. if price <= 0 then
  747. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  748. else
  749. itemLua.presentPrice.number.text.text = tostring(price)
  750. end
  751. itemLua.discount:SetActive(false)
  752. itemLua.originalPrice:SetActive(false)
  753. local remainBuyNum = data:GetRemainBuyNum()
  754. if remainBuyNum >= 0 then
  755. itemLua.purchaseLimit:SetActive(true)
  756. itemLua.purchaseLimit.text.text = string.formatbykey("RuneShopLimitBuy", remainBuyNum)
  757. itemLua.limitBox:SetActive(false)
  758. else
  759. itemLua.purchaseLimit:SetActive(false)
  760. itemLua.limitBox:SetActive(false)
  761. end
  762. itemLua.soldout:SetActive(data:IsSoldout())
  763. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickShopGoodsItem, data)
  764. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickShopGoodsItem, data)
  765. return item
  766. end
  767. function UIRuneShopBTView:RefreshGiftsItem(itemLua, bgPic, numPic, rewards)
  768. if numPic and numPic ~= '' then
  769. itemLua.specialReward.bg.image.sprite = nil
  770. itemLua.specialReward.bg.image.enabled = false
  771. CommonUtil.LoadIcon(self, bgPic, function(sprite)
  772. if sprite then
  773. itemLua.specialReward.bg.image.sprite = sprite
  774. itemLua.specialReward.bg.image.enabled = true
  775. end
  776. end, itemLua, 'SpecialRewardBgIcon')
  777. itemLua.specialReward.num.image.sprite = nil
  778. itemLua.specialReward.num.image.enabled = false
  779. CommonUtil.LoadIcon(self, numPic, function(sprite)
  780. if sprite then
  781. itemLua.specialReward.num.image.sprite = sprite
  782. itemLua.specialReward.num.image.enabled = true
  783. end
  784. end, itemLua, 'SpecialRewardNumIcon')
  785. itemLua.specialReward:SetActive(true)
  786. itemLua.goodsItems:SetActive(false)
  787. else
  788. itemLua.specialReward:SetActive(false)
  789. if rewards then
  790. itemLua.goodsItems:SetActive(true)
  791. local reward = rewards[1]
  792. if reward then
  793. itemLua.iconSmallItem1:SetActive(true)
  794. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem1, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  795. else
  796. itemLua.iconSmallItem1:SetActive(false)
  797. end
  798. reward = rewards[2]
  799. if reward then
  800. itemLua.iconSmallItem2:SetActive(true)
  801. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem2, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  802. else
  803. itemLua.iconSmallItem2:SetActive(false)
  804. end
  805. reward = rewards[3]
  806. if reward then
  807. itemLua.iconSmallItem3:SetActive(true)
  808. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem3, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  809. else
  810. itemLua.iconSmallItem3:SetActive(false)
  811. end
  812. else
  813. itemLua.goodsItems:SetActive(false)
  814. end
  815. end
  816. end
  817. function UIRuneShopBTView:GetItemByRowColumnLimited(loopGridView, itemIdx, row, column)
  818. local data = self.controller:GetShowGoodsDataByIdx(itemIdx + 1)
  819. if not data then return nil end
  820. local item = loopGridView:NewListViewItem('RuneShopLimitedItem')
  821. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RuneShopLimitedItem', item.gameObject)
  822. if itemLua then
  823. itemLua.itemIcon.image.sprite = nil
  824. itemLua.itemIcon.image.enabled = false
  825. local cfgData = data.cfgData
  826. if cfgData then
  827. CommonUtil.LoadIcon(self, cfgData.Banner, function(sprite)
  828. if sprite then
  829. itemLua.itemIcon.image.sprite = sprite
  830. itemLua.itemIcon.image.enabled = true
  831. end
  832. end, itemLua, 'ItemIcon')
  833. end
  834. if data:HasEndTime() then
  835. local timerStr = data:CalculateLimitTime()
  836. itemLua.timerLab.text.text.text = string.formatbykey('RuneShopLimitTime', timerStr)
  837. itemLua.timerLab:SetActive(true)
  838. self:StartRefreshTimer(itemLua, data)
  839. else
  840. self:StopRefreshTimer(itemLua)
  841. itemLua.timerLab:SetActive(false)
  842. end
  843. local price = data:GetPrice()
  844. if price <= 0 then
  845. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  846. else
  847. itemLua.presentPrice.number.text.text = tostring(price)
  848. end
  849. if data:IsSoldout() then
  850. itemLua.soldout:SetActive(true)
  851. itemLua.button.onClick:RemoveAllListeners()
  852. itemLua.presentPrice.button.onClick:RemoveAllListeners()
  853. else
  854. itemLua.soldout:SetActive(false)
  855. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickLimitedItem, data:GetId(), itemIdx)
  856. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickLimitedPrice, data:GetId(), itemIdx)
  857. end
  858. itemLua.redPoint:SetActive(ManagerContainer.RedPointMgr.RSLimitGiftRPCtr:GetRedPointStatusById(data:GetId()))
  859. end
  860. return item
  861. end
  862. function UIRuneShopBTView:RefreshLimitedView(resetPos)
  863. local showGoodsDatas = self.controller:GetShowGoodsDatas()
  864. local length = (showGoodsDatas and #showGoodsDatas or 0)
  865. if resetPos then
  866. self.limitedBox.scrollView.loopGridView:RefreshListByIndex(length, 0)
  867. else
  868. self.limitedBox.scrollView.loopGridView:RefreshListByIndex(length)
  869. end
  870. end
  871. function UIRuneShopBTView:StartRefreshTimer(itemLua, goodsData)
  872. local timer = self.refreshTimer
  873. if not timer then
  874. timer = Timer.New(slot(self.RefreshTimer, self), 1, -1)
  875. self.refreshTimer = timer
  876. end
  877. local updateItemMap = timer.updateItemMap
  878. if not updateItemMap then
  879. updateItemMap = {}
  880. timer.updateItemMap = updateItemMap
  881. end
  882. updateItemMap[itemLua] = goodsData
  883. if not timer.running then
  884. timer:Start()
  885. end
  886. end
  887. function UIRuneShopBTView:StopRefreshTimer(itemLua)
  888. local timer = self.refreshTimer
  889. if timer then
  890. local updateItemMap = timer.updateItemMap
  891. if updateItemMap then
  892. updateItemMap[itemLua] = nil
  893. end
  894. if not updateItemMap or table_is_empty(updateItemMap) then
  895. timer:Stop()
  896. end
  897. end
  898. end
  899. function UIRuneShopBTView:StopAndClearRefreshTimer()
  900. if self.refreshTimer then
  901. self.refreshTimer:Stop()
  902. self.refreshTimer.time = 1
  903. self.refreshTimer.duration = 1
  904. self.refreshTimer.updateItemMap = nil
  905. end
  906. end
  907. function UIRuneShopBTView:DisposeRefreshTimer()
  908. self:StopAndClearRefreshTimer()
  909. self.refreshTimer = nil
  910. end
  911. function UIRuneShopBTView:RefreshTimer()
  912. local timer = self.refreshTimer
  913. if not timer then return end
  914. local updateItemMap = timer.updateItemMap
  915. if not updateItemMap or table_is_empty(updateItemMap) then
  916. timer:Stop()
  917. return
  918. end
  919. local minRemainTime = nil
  920. local runeShopType = self.controller:GetShopType()
  921. if runeShopType == Enum.RuneShopType.MonthCard then
  922. for itemLua, goodsData in pairs(updateItemMap) do
  923. local timerStr, outTime, remainTime = goodsData:CalculateLimitTime()
  924. if not outTime then
  925. itemLua.textDsc.text.text = string.formatbykey('DscClubMonth2', timerStr)
  926. itemLua.active:SetActive(true)
  927. itemLua.unActive:SetActive(false)
  928. else
  929. updateItemMap[itemLua] = nil
  930. itemLua.textDsc.text.text = string.formatbykey('DscClubMonth1')
  931. itemLua.active:SetActive(false)
  932. itemLua.unActive:SetActive(true)
  933. end
  934. if remainTime and remainTime > 0 then
  935. if not minRemainTime or minRemainTime > remainTime then
  936. minRemainTime = remainTime
  937. end
  938. end
  939. end
  940. if minRemainTime and minRemainTime > 0 then
  941. minRemainTime = 1
  942. end
  943. elseif runeShopType == Enum.RuneShopType.Gifts then
  944. local endTime = self.controller:GetRemainTime()
  945. if endTime then
  946. if endTime < 0 then endTime = 0 end
  947. if endTime <= 0 then
  948. timer.updateItemMap = nil
  949. end
  950. self.timeBox:SetActive(true)
  951. self.timeBox.textTime.text.text = string.formatbykey('RuneShopRefreshTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false))
  952. else
  953. self.timeBox:SetActive(false)
  954. timer.updateItemMap = nil
  955. end
  956. if endTime and endTime > 0 then
  957. if not minRemainTime or minRemainTime > endTime then
  958. minRemainTime = endTime
  959. end
  960. end
  961. elseif runeShopType == Enum.RuneShopType.LimitTime then
  962. for itemLua, goodsData in pairs(updateItemMap) do
  963. if goodsData:HasEndTime() then
  964. local timerStr, outTime, remainTime = goodsData:CalculateLimitTime()
  965. if outTime then
  966. updateItemMap[itemLua] = nil
  967. end
  968. itemLua.timerLab.text.text.text = string.formatbykey('RuneShopLimitTime', timerStr)
  969. itemLua.timerLab:SetActive(true)
  970. if remainTime and remainTime > 0 then
  971. if not minRemainTime or minRemainTime > remainTime then
  972. minRemainTime = remainTime
  973. end
  974. end
  975. else
  976. updateItemMap[itemLua] = nil
  977. itemLua.timerLab:SetActive(false)
  978. end
  979. if minRemainTime and minRemainTime > 0 then
  980. minRemainTime = 1
  981. end
  982. end
  983. end
  984. if not minRemainTime or minRemainTime <= 0 then
  985. self:StopRefreshTimer()
  986. else
  987. -- 降低刷新频率
  988. if self.refreshTimer then
  989. local validTime = nil
  990. if minRemainTime >= 86400 then
  991. validTime = minRemainTime % 3600
  992. if validTime == 0 then validTime = 3600 end
  993. elseif minRemainTime >= 3600 then
  994. validTime = minRemainTime % 60
  995. if validTime == 0 then validTime = 60 end
  996. else
  997. validTime = 1
  998. end
  999. if validTime then
  1000. self.refreshTimer.duration = validTime
  1001. else
  1002. self:StopRefreshTimer()
  1003. end
  1004. end
  1005. end
  1006. end
  1007. return UIRuneShopBTView