UIVipView.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. local UIVipView = require("UIVip/UIVipView_Generate")
  2. function UIVipView:OnAwake(data)
  3. self.controller = require("UIVip/UIVipCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UIVipView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VIP_LV_CHANGED, self, self.OnVipLvChanged)
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VIP_EXP_CHANGED, self, self.OnVipExpChanged)
  10. end
  11. function UIVipView:FillContent(data, uiBase)
  12. self.uiBase = uiBase
  13. local gameObject = self.uiBase:GetRoot()
  14. if gameObject ~= nil then
  15. self.gameObject = gameObject
  16. self.transform = gameObject.transform
  17. end
  18. self:InitGenerate(self.transform, data)
  19. self:Init()
  20. end
  21. function UIVipView:Init()
  22. self.customerServiceData = nil
  23. self.gainList.loopListView:InitListView(0, function(loopListView, itemIndex)
  24. return self:GetItemByIndex(loopListView, itemIndex)
  25. end)
  26. self.gainList.loopListView.ScrollRect.enabled = false
  27. self.expSlider.slider.interactable = false
  28. self:RefreshTopView()
  29. self:RefreshBottomView()
  30. self:RefreshSwitchButton()
  31. self:StartCheckCustomerService()
  32. end
  33. function UIVipView:RemoveEventListener()
  34. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  35. end
  36. function UIVipView:AddUIEventListener()
  37. -- self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn)
  38. self.uiBase:AddButtonUniqueEventListener(self.btnBack.button, self, self.OnClickCloseBtn)
  39. self.uiBase:AddButtonUniqueEventListener(self.btnUpLv.button, self, self.OnClickUpLvBtn)
  40. self.uiBase:AddButtonUniqueEventListener(self.btnInfo.button, self, self.OnClickInfoBtn)
  41. self.uiBase:AddButtonUniqueEventListener(self.btnLeft.button, self, self.OnClickLeftBtn)
  42. self.uiBase:AddButtonUniqueEventListener(self.btnRight.button, self, self.OnClickRightBtn)
  43. self.uiBase:AddButtonUniqueEventListener(self.btnCustomerService.button, self, self.OnClickCustomerServiceBtn)
  44. end
  45. function UIVipView:OnHide()
  46. end
  47. function UIVipView:OnShow(data)
  48. self.controller:SetData(data)
  49. end
  50. function UIVipView:OnClose()
  51. end
  52. function UIVipView:OnDispose()
  53. self.customerServiceData = nil
  54. self:DisposeCheckCustomerService()
  55. self.gainList.loopListView:Dispose()
  56. self.rewardList.loopHorizontalScrollRect:ClearCells()
  57. self.controller:OnDispose()
  58. end
  59. function UIVipView:OnPageInEnd()
  60. self.super.OnPageInEnd(self)
  61. self.gainList.loopListView.ScrollRect.enabled = true
  62. end
  63. function UIVipView:OnVipLvChanged()
  64. self:RefreshLvView()
  65. self:StartCheckCustomerService()
  66. end
  67. function UIVipView:OnVipExpChanged()
  68. self:RefreshExpView()
  69. end
  70. function UIVipView:OnClickCloseBtn()
  71. self:UIClose()
  72. end
  73. function UIVipView:OnClickUpLvBtn()
  74. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIRuneShopBT) then
  75. local uibase = ManagerContainer.LuaUIMgr:GetPage(Enum.UIPageName.UIRuneShopBT)
  76. if uibase then
  77. local luaTable = uibase.MLuaTable
  78. if luaTable then
  79. if luaTable.OnShow then
  80. luaTable:OnShow({Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold})
  81. end
  82. end
  83. end
  84. else
  85. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold})
  86. end
  87. self:UIClose()
  88. end
  89. function UIVipView:OnClickInfoBtn()
  90. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'VipExplain'})
  91. end
  92. function UIVipView:OnClickLeftBtn()
  93. if not self.controller:ChangeCurShowVipLv(false) then
  94. return
  95. end
  96. self:RefreshBottomView()
  97. self:RefreshSwitchButton()
  98. end
  99. function UIVipView:OnClickRightBtn()
  100. if not self.controller:ChangeCurShowVipLv(true) then
  101. return
  102. end
  103. self:RefreshBottomView()
  104. self:RefreshSwitchButton()
  105. end
  106. function UIVipView:OnClickCustomerServiceBtn()
  107. local infos = self:GetCustomerServiceInfos()
  108. if not infos then
  109. return
  110. end
  111. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UICustomerServiceTips, infos)
  112. end
  113. function UIVipView:RefreshTopView()
  114. self:RefreshLvView()
  115. self:RefreshExpView()
  116. end
  117. function UIVipView:RefreshLvView()
  118. local curVipLv = self.controller:GetCurVipLv()
  119. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv)
  120. self.vipIcon.image.sprite = nil
  121. self.vipIcon.image.enabled = false
  122. self.vipFrame.image.sprite = nil
  123. self.vipFrame.image.enabled = false
  124. if not vipCfg then
  125. self.curVipNameTxt.text.text = ''
  126. return
  127. end
  128. CommonUtil.LoadIcon(self, vipCfg.BigIcon, function(sprite)
  129. if sprite then
  130. self.vipIcon.image.sprite = sprite
  131. self.vipIcon.image.enabled = true
  132. end
  133. end)
  134. CommonUtil.LoadIcon(self, vipCfg.BigFrame, function(sprite)
  135. if sprite then
  136. self.vipFrame.image.sprite = sprite
  137. self.vipFrame.image.enabled = true
  138. end
  139. end)
  140. self.curVipNameTxt.text.text = string.formatbykey(vipCfg.Name)
  141. self.expTxt.sealIcon.image.sprite = nil
  142. self.expTxt.sealIcon.image.enabled = false
  143. local nextVipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv + 1)
  144. if nextVipCfg then
  145. CommonUtil.LoadIcon(self, nextVipCfg.SmallIcon, function(sprite)
  146. if sprite then
  147. self.expTxt.sealIcon.image.sprite = sprite
  148. self.expTxt.sealIcon.image.enabled = true
  149. end
  150. end)
  151. end
  152. end
  153. function UIVipView:RefreshExpView()
  154. local curVipLv = self.controller:GetCurVipLv()
  155. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv)
  156. if not vipCfg then
  157. self.expTxt:SetActive(false)
  158. self.expSlider:SetActive(false)
  159. return
  160. end
  161. local curVipExp = self.controller:GetCurVipExp()
  162. self.expTxt:SetActive(true)
  163. self.expSlider:SetActive(true)
  164. local nextVipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv + 1)
  165. if nextVipCfg then
  166. self.expTxt.text.text = string.formatbykey('VipUpLv', tostring(vipCfg.VipExp - curVipExp), string.formatbykey(nextVipCfg.Name))
  167. self.expSlider.slider.value = Mathf.Clamp01(curVipExp / vipCfg.VipExp)
  168. else
  169. self.expTxt.text.text = string.formatbykey('VipUpLvMax')
  170. self.expSlider.slider.value = 1
  171. end
  172. self.number.text.text = tostring(curVipExp) .. '/' .. tostring(vipCfg.VipExp)
  173. end
  174. function UIVipView:RefreshBottomView()
  175. local vipLv = self.controller:GetCurShowVipLv()
  176. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  177. if not vipCfg then
  178. self.vipNameTxt.text.text = ''
  179. self.gainList.loopListView:SetListItemCount(0)
  180. CommonUtil.LoopGridViewEleCreateNew(self, self.rewardList.loopHorizontalScrollRect, nil, {}, 0, self, self.UpdateRewardItem)
  181. return
  182. end
  183. self.vipNameTxt.text.text = string.formatbykey(vipCfg.Name)
  184. self.gainList.loopListView:SetListItemCount(vipCfg.UnlockDes and #vipCfg.UnlockDes or 0)
  185. self.gainList.loopListView:RefreshAllShownItem()
  186. CommonUtil.LoopGridViewEleCreateNew(self, self.rewardList.loopHorizontalScrollRect, nil, vipCfg.Reward and vipCfg.Reward or {}, 0, self, self.UpdateRewardItem)
  187. end
  188. function UIVipView:RefreshSwitchButton()
  189. self.btnLeft:SetActive(self.controller:HasPrev())
  190. self.btnRight:SetActive(self.controller:HasNext())
  191. end
  192. function UIVipView:UpdateRewardItem(itemLua, itemIdx, itemData)
  193. if not itemLua or not itemData then return end
  194. CommonUtil.UpdateItemPrefab(self, itemLua.iconItem, {cfgId = itemData[1], num = itemData[2]}, Enum.ItemIEnterType.Bag, self, self.ShowItemTips)
  195. itemLua.check:SetActive(self.controller:IsReachLv())
  196. end
  197. function UIVipView:ShowItemTips(button, params)
  198. ManagerContainer.LuaUIMgr:OpenTips(params[0])
  199. end
  200. function UIVipView:GetItemByIndex(loopListView, itemIndex)
  201. local vipLv = self.controller:GetCurShowVipLv()
  202. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  203. if not vipCfg then return nil end
  204. if not vipCfg.UnlockDes then return nil end
  205. local unlockDes = vipCfg.UnlockDes[itemIndex + 1]
  206. if not unlockDes then return nil end
  207. local item = loopListView:NewListViewItem('VipUnlockDesItem')
  208. local isNew = unlockDes[1] or 0
  209. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'VipUnlockDesItem', item.gameObject)
  210. if itemLua then
  211. itemLua.exist:SetActive(isNew ~= 1)
  212. itemLua.new:SetActive(isNew == 1)
  213. local params = {}
  214. local langKey = unlockDes[2]
  215. for i = 3, #unlockDes do
  216. params[#params + 1] = tostring(unlockDes[i])
  217. end
  218. itemLua.desTxt.text.text = string.formatbykey(langKey, unpack(params))
  219. end
  220. ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform)
  221. return item
  222. end
  223. function UIVipView:StartCheckCustomerService()
  224. self.btnCustomerService.gameObject:SetActive(false)
  225. local isShow = self.controller:IsShowCustomerVipLv()
  226. if not isShow then
  227. self:StopCheckCustomerService()
  228. return
  229. end
  230. if self.reqWWW then
  231. return
  232. end
  233. local url = PlatformPack.CUSTOMER_SERVICE_INFO_URL .. '?timesamp=' .. tostring(os.time())
  234. local platform = ManagerContainer.LuaGameMgr.platform
  235. if platform and platform ~= '' then
  236. url = url .. '&platform=' .. tostring(platform)
  237. end
  238. local subplatform = ManagerContainer.LuaGameMgr.channelName
  239. if subplatform and subplatform ~= '' then
  240. url = url .. '&sub_platform=' .. tostring(subplatform)
  241. end
  242. self.reqWWW = UnityEngine.WWW(url)
  243. if not self.checkReqWWWTimer then
  244. self.checkReqWWWTimer = FrameTimer.New(slot(self.CheckCustomerService, self), 1, -1)
  245. end
  246. if not self.checkReqWWWTimer.running then
  247. self.checkReqWWWTimer:Start()
  248. end
  249. end
  250. function UIVipView:StopCheckCustomerService()
  251. if self.reqWWW then
  252. self.reqWWW:Dispose()
  253. self.reqWWW = nil
  254. end
  255. if self.checkReqWWWTimer and self.checkReqWWWTimer.running then
  256. self.checkReqWWWTimer:Stop()
  257. end
  258. end
  259. function UIVipView:DisposeCheckCustomerService()
  260. self:StopCheckCustomerService()
  261. self.checkReqWWWTimer = nil
  262. end
  263. function UIVipView:CheckCustomerService()
  264. if not self.checkReqWWWTimer then
  265. self:StopCheckCustomerService()
  266. return
  267. end
  268. if self.reqWWW.isDone then
  269. local content = nil
  270. if not self.reqWWW.error or self.reqWWW.error == '' then
  271. content = self.reqWWW.text
  272. end
  273. self:StopCheckCustomerService()
  274. if content then
  275. local ok, result = RO_XPCALL(JSON.decode, debug.traceback, JSON, content)
  276. if ok then
  277. self.customerServiceData = result
  278. local infos = self:GetCustomerServiceInfos()
  279. self.btnCustomerService.gameObject:SetActive((infos ~= nil))
  280. else
  281. LogError('[wboy] CheckCustomerService Fail ' .. tostring(result))
  282. end
  283. end
  284. end
  285. end
  286. function UIVipView:GetCustomerServiceInfos()
  287. if not self.customerServiceData then
  288. return nil
  289. end
  290. if not self.customerServiceData.open then
  291. return nil
  292. end
  293. local datas = self.customerServiceData.infos
  294. if not datas or #datas <= 0 then
  295. return nil
  296. end
  297. return datas
  298. end
  299. return UIVipView