UIBoliShopView.lua 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. local UIBoliShopView = require("UIRuneShop/UIBoliShopView_Generate")
  2. local IsRefreshBtnItem
  3. local LastItemIdx
  4. local redpointState = false
  5. local IconItemCtr = require("Common/IconItemCtr")
  6. function UIBoliShopView:OnAwake(data)
  7. self.controller = require("UIRuneShop/UIBoliShopCtr"):new()
  8. self.controller:Init(self)
  9. self.controller:SetData(data)
  10. end
  11. function UIBoliShopView:AddEventListener()
  12. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  13. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.COIN_CHANGED, self, self.RefreshCoins)
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.DIAMOND_CHANGED, self, self.RefreshDiamond)
  15. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ROCOIN_CHANGED, self, self.RefreshROCoin)
  16. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ROBOLISHOP_EXP_CHANGE, self, self.RefreshCurExp)
  17. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VIP_LV_CHANGED, self, self.RefreshVipView)
  18. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ON_BOLISHOP_DATA_CHANGE, self, self.RefreshBoliShopData)
  19. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ON_BOLISHOP_INFO_REFRESH, self, self.RefreshGoodsItemsScroll)
  20. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ON_BOLISHOP_REWARD_TIPS, self, self.OpenRewardsView)
  21. end
  22. function UIBoliShopView:OpenRewardsView(data)
  23. if data then
  24. local rewards = {}
  25. for key, value in pairs(data) do
  26. table.insert(rewards,{cfgId = value.key, num = value.value})
  27. end
  28. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = rewards})
  29. end
  30. end
  31. function UIBoliShopView:RefreshVipView()
  32. local curVipLv = ManagerContainer.DataMgr.UserData:GetVipLv()
  33. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv)
  34. self.vipIcon.image.sprite = nil
  35. self.vipIcon.image.enabled = false
  36. self.vipFrame.image.sprite = nil
  37. self.vipFrame.image.enabled = false
  38. if not vipCfg then
  39. self.vipNameTxt.text.text = ''
  40. return
  41. end
  42. CommonUtil.LoadIcon(self, vipCfg.BigIcon, function(sprite)
  43. if sprite then
  44. self.vipIcon.image.sprite = sprite
  45. self.vipIcon.image.enabled = true
  46. end
  47. end)
  48. CommonUtil.LoadIcon(self, vipCfg.BigFrame, function(sprite)
  49. if sprite then
  50. self.vipFrame.image.sprite = sprite
  51. self.vipFrame.image.enabled = true
  52. end
  53. end)
  54. self.vipNameTxt.text.text = string.formatbykey(vipCfg.Name)
  55. end
  56. function UIBoliShopView:RefreshCoins()
  57. local coin = ManagerContainer.DataMgr.UserData:GetOwnCoin()
  58. self.coin.number.text.text = CommonUtil.FormatNumber(coin)
  59. end
  60. function UIBoliShopView:RefreshROCoin()
  61. local count = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.ROCoin)
  62. self.ro.number.text.text = CommonUtil.FormatNumber(count)
  63. end
  64. function UIBoliShopView:RefreshDiamond()
  65. local count = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.Diamond)
  66. self.gold.number.text.text = CommonUtil.FormatNumber(count)
  67. end
  68. function UIBoliShopView:FillContent(data, uiBase)
  69. self.uiBase = uiBase
  70. local gameObject = self.uiBase:GetRoot()
  71. if gameObject ~= nil then
  72. self.gameObject = gameObject
  73. self.transform = gameObject.transform
  74. end
  75. self:InitGenerate(self.transform, data)
  76. self:Init()
  77. end
  78. function UIBoliShopView:Init()
  79. self:RefreshCoins()
  80. self:RefreshROCoin()
  81. self:RefreshDiamond()
  82. self.shopExpBox:SetActive(true)
  83. self:InitGridView()
  84. local enterType = self.controller:SetCurEnterType(1)
  85. self.privilegeToggle.toggle.isOn = true
  86. self:OnValueChangedToggle(nil,enterType,true)
  87. end
  88. function UIBoliShopView:OnPageInEnd()
  89. self.super.OnPageInEnd(self)
  90. self.scrollViewLv.scrollRect.enabled = true
  91. self.informationScrollView.scrollRect.enabled = true
  92. self.goodsScrollView.scrollRect.enabled = true
  93. end
  94. function UIBoliShopView:RefreshCurExp()
  95. local curlv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
  96. local curExp = ManagerContainer.DataMgr.BoliShopData:GetCurExp()
  97. local curData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(curlv)
  98. local nextData = ManagerContainer.CfgMgr:GetBoLiVipCfgById(curlv + 1)
  99. local BoliVipCfg = ManagerContainer.CfgMgr:GetBoliVipCfg()
  100. self.maxCfgData = BoliVipCfg[#BoliVipCfg]
  101. local maxcfgData = BoliVipCfg[#BoliVipCfg - 1]
  102. if maxcfgData then
  103. self.maxExp = maxcfgData.VipExp
  104. end
  105. local exp = self.maxCfgData.Lv == curlv and self.maxExp or curData.VipExp
  106. self.numlv.text.text = tostring(curlv)
  107. if curData then
  108. self.numexp.text.text = curExp .."/"..exp
  109. self.expSlider.slider.value = curExp/curData.VipExp
  110. end
  111. self.max:SetActive(nextData == nil)
  112. self.btnLvUp:SetActive(nextData ~= nil)
  113. self.controller:RefreshGoodsData()
  114. end
  115. function UIBoliShopView:InitGridView()
  116. self.scrollViewLv.scrollRect.enabled = false
  117. self.informationScrollView.scrollRect.enabled = false
  118. self.goodsScrollView.scrollRect.enabled = false
  119. self.scrollViewLv.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  120. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  121. end, nil)
  122. self.informationScrollView.loopListView:InitListView(0, function(gridView, itemIndex)
  123. return self:GetVipDescItemByRowColumn(gridView, itemIndex)
  124. end)
  125. self.goodsScrollView.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  126. return self:GetGoodsItemByRowColumn(gridView, itemIndex, row, column)
  127. end, nil)
  128. self.controller:RefreshsvipLvShowDatas()
  129. end
  130. function UIBoliShopView:RefreshBtnLvScroll()
  131. if self.controller:GetCurEnterType() ~= 1 then
  132. return
  133. end
  134. redpointState = false
  135. local len = self.controller:GetBoliVipLvDataLengths()
  136. self.scrollViewLv.loopGridView:RefreshListByIndex(len,0)
  137. self.privilegeToggle.redPoint:SetActive(redpointState)
  138. local isHide = self:GetIsHideShopBtn()
  139. self.shopToggle:SetActive(isHide)
  140. end
  141. function UIBoliShopView:GetIsHideShopBtn()
  142. local curLv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
  143. local showTime = ManagerContainer.DataMgr.BoliShopData:GetShowTime()
  144. local serverTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  145. local time = type(serverTime) == "number" and serverTime or #serverTime
  146. return curLv >= 1 and showTime > 0 and time >= showTime
  147. end
  148. function UIBoliShopView:StartShopGoodsItemTimer(itemLua, goodsData)
  149. local timer = self.shopGoodsItemTimer
  150. if not timer then
  151. timer = Timer.New(function()
  152. self:RefreshShopGoodsItemTimer()
  153. end, 1, -1)
  154. self.shopGoodsItemTimer = timer
  155. end
  156. local updateItemMap = timer.updateItemMap
  157. if not updateItemMap then
  158. updateItemMap = {}
  159. timer.updateItemMap = updateItemMap
  160. end
  161. updateItemMap[itemLua] = goodsData
  162. if not timer.running then
  163. timer:Start()
  164. end
  165. end
  166. function UIBoliShopView:StopShopGoodsItemTimer(itemLua)
  167. local timer = self.shopGoodsItemTimer
  168. if timer then
  169. local updateItemMap = timer.updateItemMap
  170. if updateItemMap then
  171. updateItemMap[itemLua] = nil
  172. end
  173. if not updateItemMap or table_is_empty(updateItemMap) then
  174. timer:Stop()
  175. end
  176. end
  177. end
  178. function UIBoliShopView:DisposeShopGoodsItemTimer()
  179. if self.shopGoodsItemTimer then
  180. self.shopGoodsItemTimer:Stop()
  181. self.shopGoodsItemTimer.updateItemMap = nil
  182. self.shopGoodsItemTimer = nil
  183. end
  184. end
  185. function UIBoliShopView:RefreshShopGoodsItemTimer()
  186. local timer = self.shopGoodsItemTimer
  187. if not timer then return end
  188. local updateItemMap = timer.updateItemMap
  189. if not updateItemMap or table_is_empty(updateItemMap) then
  190. timer:Stop()
  191. return
  192. end
  193. for itemLua, goodsData in pairs(updateItemMap) do
  194. itemLua.limitBox:SetActive(true)
  195. itemLua.timeLimit.text.text = goodsData:CalculateLimitTime()
  196. end
  197. end
  198. function UIBoliShopView:GetGoodsItemByRowColumn(gridView, itemIndex, row, column)
  199. local item = nil
  200. local shopData = ManagerContainer.DataMgr.BoliShopData:GetBoliShopData()
  201. if not shopData then return nil end
  202. local goods = shopData:GetShowGoodsDatas()
  203. if not goods then return nil end
  204. local goodsData = goods[itemIndex + 1]
  205. if not goodsData then return nil end
  206. local item = gridView:NewListViewItem('ShopGoodsItem')
  207. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'ShopGoodsItem', item.gameObject)
  208. local goodsCfgData = goodsData:GetGoodsCfgData()
  209. local data = {cfgId = goodsCfgData.GoodsItem}
  210. -- CommonUtil.UpdateItemPrefab(self, itemLua.iconItem, data, nil, self, self.ShowItemTips, data)
  211. CommonUtil.UpdateItemPrefab(self, itemLua.iconItem, data, nil)
  212. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(goodsCfgData.PayForType)
  213. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite)
  214. itemLua.presentPrice.icon.image.sprite = sprite
  215. itemLua.originalPrice.icon.image.sprite = sprite
  216. end, itemLua, 'CurrenyIcon')
  217. itemLua.itemName.text.text = I18N.T( goodsCfgData.GoodsName)
  218. itemLua.presentPrice.number.text.text = goodsData.curPrice --现价
  219. if goodsData:IsDiscount() then --折扣
  220. itemLua.discount:SetActive(true)
  221. itemLua.originalPrice:SetActive(true)
  222. local discountNum = goodsData.disPercent
  223. --不是中文环境
  224. if not (ManagerContainer.LuaGameMgr.CurLangKey == "_cn"
  225. or ManagerContainer.LuaGameMgr.CurLangKey == "_tw") then
  226. discountNum = 100 - goodsData.disPercent
  227. else
  228. --discountNum = goodsData.disPercent * 0.1
  229. discountNum = 100 - goodsData.disPercent
  230. end
  231. itemLua.discount.text.text.text = I18N.SetLanguageValue("ShopDiscount", tostring(discountNum)) -- {0}折,中文是:{0}折,非中文是{0}%off
  232. itemLua.originalPrice.number.text.text = goodsData.price
  233. elseif goodsData.hot then --热销
  234. itemLua.discount:SetActive(true)
  235. itemLua.originalPrice:SetActive(false)
  236. itemLua.discount.text.text.text = I18N.T("ShopSellwell")
  237. else
  238. itemLua.discount:SetActive(false)
  239. itemLua.originalPrice:SetActive(false)
  240. end
  241. local limitType = goodsData.limitType
  242. if limitType == Enum.LimitBuyType.NoLimit then
  243. itemLua.purchaseLimit:SetActive(false)
  244. itemLua.limitBox:SetActive(false)
  245. self:StopShopGoodsItemTimer(itemLua)
  246. elseif limitType == Enum.LimitBuyType.Forever then
  247. itemLua.purchaseLimit:SetActive(true)
  248. local remainNum = (goodsData.count - goodsData.buyNum)
  249. if remainNum < 0 then remainNum = 0 end
  250. itemLua.purchaseLimit.text.text = string.formatbykey("ShopForeverBuy", remainNum)
  251. itemLua.limitBox:SetActive(false)
  252. self:StopShopGoodsItemTimer(itemLua)
  253. elseif limitType == Enum.LimitBuyType.Daily then
  254. itemLua.purchaseLimit:SetActive(true)
  255. local remainNum = (goodsData.count - goodsData.buyNum)
  256. if remainNum < 0 then remainNum = 0 end
  257. itemLua.purchaseLimit.text.text = string.formatbykey("ShopDayBuy", remainNum)
  258. itemLua.limitBox:SetActive(true)
  259. itemLua.timeLimit.text.text = goodsData:CalculateLimitTime()
  260. self:StartShopGoodsItemTimer(itemLua, goodsData)
  261. elseif limitType == Enum.LimitBuyType.Week then
  262. itemLua.purchaseLimit:SetActive(true)
  263. local remainNum = (goodsData.count - goodsData.buyNum)
  264. if remainNum < 0 then remainNum = 0 end
  265. itemLua.purchaseLimit.text.text = string.formatbykey("ShopLoopBuy", remainNum)
  266. itemLua.limitBox:SetActive(true)
  267. itemLua.timeLimit.text.text = goodsData:CalculateLimitTime()
  268. self:StartShopGoodsItemTimer(itemLua, goodsData)
  269. elseif limitType == Enum.LimitBuyType.Time then
  270. itemLua.purchaseLimit:SetActive(true)
  271. local remainNum = (goodsData.count - goodsData.buyNum)
  272. if remainNum < 0 then remainNum = 0 end
  273. itemLua.purchaseLimit.text.text = string.formatbykey("ShopLimitBuy", remainNum)
  274. itemLua.limitBox:SetActive(true)
  275. itemLua.timeLimit.text.text = goodsData:CalculateLimitTime()
  276. self:StartShopGoodsItemTimer(itemLua, goodsData)
  277. elseif limitType == Enum.LimitBuyType.Special then
  278. itemLua.purchaseLimit:SetActive(true)
  279. local remainNum = (goodsData.count - goodsData.buyNum)
  280. if remainNum < 0 then remainNum = 0 end
  281. itemLua.purchaseLimit.text.text = string.formatbykey("ShopLimitBuy", remainNum)
  282. itemLua.limitBox:SetActive(false)
  283. self:StopShopGoodsItemTimer(itemLua)
  284. else
  285. itemLua.purchaseLimit:SetActive(false)
  286. itemLua.limitBox:SetActive(false)
  287. self:StopShopGoodsItemTimer(itemLua)
  288. end
  289. itemLua.soldout:SetActive(goodsData:IsSoldout())
  290. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickShopGoodsItem, goodsData)
  291. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickShopGoodsItem, goodsData)
  292. return item
  293. end
  294. function UIBoliShopView:OnClickShopGoodsItem(btn, params)
  295. local shopData = ManagerContainer.DataMgr.BoliShopData:GetBoliShopData()
  296. if not shopData then return end
  297. local goodsData = params[0]
  298. if not goodsData then return end
  299. if not goodsData:IsSoldout() then
  300. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBoliShopBuyTips, goodsData.id)
  301. end
  302. end
  303. function UIBoliShopView:GetVipDescItemByRowColumn(gridView, itemIndex)
  304. local item = nil
  305. item = gridView:NewListViewItem('PrivilegeDscItem')
  306. local data = self.controller:GetDescDataByIdx(itemIndex + 1)
  307. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'PrivilegeDscItem', item.gameObject)
  308. if data then
  309. itemLua.desTxt.text.text = string.formatbykey(data[2],data[3],data[4],data[5])
  310. local isnew = data[1] == 1
  311. itemLua.new:SetActive(isnew)
  312. itemLua.exist:SetActive(not isnew)
  313. end
  314. ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform)
  315. return item
  316. end
  317. function UIBoliShopView:GetItemByRowColumn(gridView, itemIndex, row, column)
  318. local item = nil
  319. item = gridView:NewListViewItem('BtnLv')
  320. local data = self.controller:GetBoliVipDataByIdx(itemIndex + 1)
  321. local curlv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
  322. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'BtnLv', item.gameObject)
  323. if data then
  324. if LastItemIdx ~= data.Lv then
  325. local lv = curlv
  326. if LastItemIdx == nil or LastItemIdx == curlv then
  327. lv = curlv
  328. else
  329. lv = LastItemIdx
  330. end
  331. itemLua.off:SetActive(lv ~= data.Lv)
  332. local isShow = (lv == 0 and data.Lv == 1) or lv == data.Lv
  333. itemLua.on:SetActive(isShow)
  334. if isShow then
  335. LastItemIdx = itemIndex + 1
  336. end
  337. else
  338. itemLua.off:SetActive(false)
  339. itemLua.on:SetActive(true)
  340. end
  341. itemLua.text.text.text = string.formatbykey("PrivilegeLv01",data.Lv)
  342. itemLua.activeted:SetActive(data.Lv == curlv)
  343. local rewardData = ManagerContainer.DataMgr.BoliShopData:GetRewardListById(data.Lv)
  344. if curlv >= data.Lv then
  345. itemLua.redPoint:SetActive(rewardData == nil)
  346. if not redpointState and rewardData == nil then
  347. redpointState = true
  348. end
  349. else
  350. itemLua.redPoint:SetActive(false)
  351. end
  352. end
  353. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickBoliLvBtn,{itemIndex,itemLua})
  354. return item
  355. end
  356. function UIBoliShopView:GetShowItemByIdx(idx)
  357. local item = self.scrollViewLv.loopGridView:GetShownItemByItemIndex(idx)
  358. if item then
  359. local itemlua = CommonUtil.GetBindGridViewItem2Lua(self, "BtnLv", item.gameObject)
  360. return itemlua
  361. end
  362. end
  363. function UIBoliShopView:OnClickBoliLvBtn(btn,param)
  364. local parms = param[0]
  365. local itemLua = self:GetShowItemByIdx(parms[1])
  366. local LastItemLua = self:GetShowItemByIdx(LastItemIdx - 1)
  367. if itemLua then
  368. if LastItemLua then
  369. LastItemLua.off:SetActive(true)
  370. LastItemLua.on:SetActive(false)
  371. end
  372. itemLua.off:SetActive(false)
  373. itemLua.on:SetActive(true)
  374. end
  375. local curlv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
  376. local data = self.controller:GetBoliVipDataByIdx(parms[1] + 1)
  377. LastItemIdx = parms[1] + 1
  378. if data.Lv <= curlv then
  379. self.prompt.text.text = string.formatbykey("BoliTips01")
  380. else
  381. self.prompt.text.text = string.formatbykey("BoliTips02",data.Lv)
  382. end
  383. self.titletext.text.text = string.formatbykey("PrivilegeLv02",data.Lv)
  384. self.labelActiveted:SetActive(data.Lv <= curlv)
  385. self:RefreshVipDescScroll(data)
  386. self:RefreshGiftUI(data)
  387. end
  388. function UIBoliShopView:RefreshVipDescScroll(data)
  389. if self.controller:GetCurEnterType() ~= 1 then
  390. return
  391. end
  392. if data then
  393. local descData = data.UnlockDes
  394. if descData then
  395. --LogError('--------------------------------')
  396. self.controller:SetDescData(descData)
  397. self.informationScrollView.loopListView:SetListItemCount(0,true) --RefreshAllShownItem MovePanelToItemIndex RefreshItemByItemIndex
  398. self.informationScrollView.loopListView:SetListItemCount(#descData,true)
  399. --self.informationScrollView.loopListView:RefreshAllShownItem()
  400. --self.informationScrollView.loopListView:MovePanelToItemIndex(0,0)
  401. --self.informationScrollView.loopListView:RefreshItemByItemIndex(#descData-1)
  402. end
  403. end
  404. end
  405. function UIBoliShopView:RefreshBoliShopData()
  406. local curlv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
  407. local idx = curlv > 0 and curlv or 1
  408. if LastItemIdx then
  409. idx = LastItemIdx
  410. end
  411. local data = self.controller:GetBoliVipDataByIdx(idx)
  412. if data then
  413. if data.Lv <= curlv then
  414. self.prompt.text.text = string.formatbykey("BoliTips01")
  415. else
  416. self.prompt.text.text = string.formatbykey("BoliTips02",data.Lv)
  417. end
  418. self.titletext.text.text = string.formatbykey("PrivilegeLv02",data.Lv)
  419. self.labelActiveted:SetActive(data.Lv <= curlv)
  420. self:RefreshVipDescScroll(data)
  421. self:RefreshGiftUI(data)
  422. end
  423. self:RefreshBtnLvScroll()
  424. self:RefreshCurExp()
  425. end
  426. function UIBoliShopView:RefreshGiftUI(data)
  427. if self.controller:GetCurEnterType() ~= 1 then
  428. return
  429. end
  430. local curlv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
  431. local redPoint = true
  432. local GetRewardIdx = 0
  433. local mask = false
  434. if curlv >= data.Lv then
  435. local data = ManagerContainer.DataMgr.BoliShopData:GetRewardListById(data.Lv)
  436. if data then
  437. GetRewardIdx = data
  438. mask = true
  439. end
  440. end
  441. for i = 1, 3 do
  442. local itemLua = self["giftItem"..i]
  443. if itemLua then
  444. local reward = data.GiftRewards[i]
  445. local cfgData = ManagerContainer.CfgMgr:GetItemById(reward[1])
  446. if cfgData then
  447. itemLua.giftname.text.text = I18N.T(cfgData.Name)
  448. end
  449. local logicData = {cfgId = reward[1], num = reward[2]}
  450. IconItemCtr:SetData(self, itemLua.iconItem, logicData,nil, self, self.OnItemClick)
  451. itemLua.labelReceived:SetActive(mask)
  452. -- itemLua.btnReceive.button.interactable = curlv >= data.Lv
  453. itemLua.btnReceive.lock:SetActive(curlv < data.Lv)
  454. itemLua.icon:SetActive(GetRewardIdx == i)
  455. local logicData = {idx = i,lv = data.Lv}
  456. self.uiBase:AddButtonUniqueEventListener(itemLua.btnReceive.button, self, self.OnClickReceiveBtn,logicData)
  457. end
  458. end
  459. end
  460. function UIBoliShopView:OnClickReceiveBtn(button,params)
  461. local data = params[0]
  462. local curlv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
  463. if curlv < data.lv then
  464. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("PrivilegeUnlock")
  465. else
  466. ManagerContainer.DataMgr.BoliShopData:SendBoliShopRewardReq(data.lv,data.idx)
  467. end
  468. end
  469. function UIBoliShopView:OnItemClick(button,params)
  470. local data = params[0]
  471. ManagerContainer.LuaUIMgr:OpenTips(data)
  472. end
  473. function UIBoliShopView:RemoveEventListener()
  474. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  475. end
  476. function UIBoliShopView:AddUIEventListener()
  477. self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
  478. self.uiBase:AddButtonUniqueEventListener(self.btnVIP.button, self, self.OnClickVipBtn)
  479. self.uiBase:AddButtonUniqueEventListener(self.btnLvUp.button, self, self.OnClickVipLvUpBtn)
  480. self.uiBase:AddToggleEventListener(self.privilegeToggle.toggle, self, self.OnValueChangedToggle,1)
  481. self.uiBase:AddToggleEventListener(self.shopToggle.toggle, self, self.OnValueChangedToggle,2)
  482. end
  483. function UIBoliShopView:OnValueChangedToggle(toggle, idx, isOn)
  484. if not isOn then return end
  485. local enterType = self.controller:SetCurEnterType(idx)
  486. self.privilegeBox:SetActive(enterType == 1)
  487. self.goodsBox:SetActive(enterType == 2)
  488. if enterType == 1 then
  489. self:RefreshVipView()
  490. self:RefreshCurExp()
  491. self:RefreshBoliShopData()
  492. elseif enterType == 2 then
  493. ManagerContainer.DataMgr.BoliShopData:SendBoliShopInfoReq()
  494. end
  495. end
  496. function UIBoliShopView:RefreshGoodsItemsScroll()
  497. if self.controller:GetCurEnterType() ~= 2 then
  498. return
  499. end
  500. local shopData = ManagerContainer.DataMgr.BoliShopData:GetBoliShopData()
  501. local length = 0
  502. if shopData then
  503. local goods = shopData:GetShowGoodsDatas()
  504. if goods then
  505. length = #goods
  506. end
  507. self.goodsScrollView.loopGridView:RefreshListByIndex(length)
  508. end
  509. end
  510. function UIBoliShopView:OnClickVipLvUpBtn()
  511. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBoliShopUpLvTips)
  512. end
  513. function UIBoliShopView:OnClickVipBtn()
  514. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIVip)
  515. end
  516. function UIBoliShopView:OnHide()
  517. end
  518. function UIBoliShopView:OnClickCloseBtn()
  519. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  520. end
  521. function UIBoliShopView:OnShow(data)
  522. self.controller:SetData(data)
  523. end
  524. function UIBoliShopView:OnClose()
  525. end
  526. function UIBoliShopView:OnDispose()
  527. self.controller:OnDispose()
  528. IsRefreshBtnItem = nil
  529. LastItemIdx = nil
  530. self.scrollViewLv.loopGridView:Dispose()
  531. self.informationScrollView.loopListView:Dispose()
  532. self.goodsScrollView.loopGridView:Dispose()
  533. self:DisposeShopGoodsItemTimer()
  534. end
  535. return UIBoliShopView