UIRuneShopBTView.lua 38 KB

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