UIRechargeWalletShopView.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. local UIRechargeWalletShopView = require("UIRuneShop/UIRechargeWalletShopView_Generate")
  2. local FirstBuyBgIconPath = 'ShopIcons/txt_club_first'
  3. local ExtraBuyBgIconPath = 'ShopIcons/txt_club_free_extra_cn'
  4. function UIRechargeWalletShopView:OnAwake(data)
  5. self.controller = require("UIRuneShop/UIRechargeWalletShopCtr"):new()
  6. self.controller:Init(self)
  7. self.controller:SetData(data)
  8. end
  9. function UIRechargeWalletShopView:AddEventListener()
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WALLETSHOP_REFRESH,self,self.RefreshShopItem)
  12. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WALLETSHOPCREDIT_REFRESH,self,self.RefreshWalletUI)
  13. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WALLETSHOP_ENDTIME_REFRESH,self,self.StartRefreshTimer)
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WALLETSHOP_SHOWREWARD,self,self.ShowReward)
  15. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.COIN_CHANGED, self, self.RefreshCoins)
  16. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.DIAMOND_CHANGED, self, self.RefreshDiamond)
  17. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VIP_LV_CHANGED, self, self.OnVipLvChanged)
  18. end
  19. function UIRechargeWalletShopView:StartRefreshTimer()
  20. local endTime = ManagerContainer.DataMgr.WalletShopData:GetEndTime()
  21. local remainTime = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(endTime)
  22. self.moneytime.text.text = I18N.SetLanguageValue('WalletRefresh', DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, false))
  23. local timer = self.refreshTimer
  24. if not timer then
  25. timer = Timer.New(slot(self.RefreshTimer,self), 1, -1)
  26. self.refreshTimer = timer
  27. end
  28. if not timer.running then
  29. timer:Start()
  30. end
  31. end
  32. function UIRechargeWalletShopView:StopRefreshTimer()
  33. if self.refreshTimer then
  34. self.refreshTimer:Stop()
  35. end
  36. end
  37. function UIRechargeWalletShopView:DisposeRefreshTimer()
  38. self:StopRefreshTimer()
  39. self.refreshTimer = nil
  40. end
  41. function UIRechargeWalletShopView:RefreshTimer()
  42. local endTime = ManagerContainer.DataMgr.WalletShopData:GetEndTime()
  43. local remainTime = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(endTime)
  44. self.moneytime.text.text = I18N.SetLanguageValue('WalletRefresh', DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, false))
  45. self.timeSlider.scrollbar.size = remainTime / 86400
  46. if not remainTime or remainTime <= 0 then
  47. ManagerContainer.DataMgr.WalletShopData:SendWalletShopInfoReq()
  48. self:StopRefreshTimer()
  49. else
  50. if self.refreshTimer then
  51. local validTime = nil
  52. if remainTime >= 86400 then
  53. validTime = remainTime % 3600
  54. if validTime == 0 then validTime = 3600 end
  55. elseif remainTime >= 3600 then
  56. validTime = remainTime % 60
  57. if validTime == 0 then validTime = 60 end
  58. else
  59. validTime = 1
  60. end
  61. if validTime then
  62. self.refreshTimer.duration = validTime
  63. else
  64. self:StopRefreshTimer()
  65. end
  66. end
  67. end
  68. end
  69. function UIRechargeWalletShopView:RefreshShopItemByIdx(idx,data)
  70. if not data then return nil end
  71. local itemLua = self["runeShopGoodsItem"..idx]
  72. if itemLua then
  73. itemLua.purchaseLimit:SetActive(false)
  74. itemLua.itemIcon.image.sprite = nil
  75. itemLua.itemIcon.image.enabled = false
  76. itemLua.presentPrice.icon.image.enabled = false
  77. itemLua.presentPrice.currency:SetActive(false)
  78. local cfgData = ManagerContainer.CfgMgr:GetPurseShopCfgById(idx)
  79. if cfgData then
  80. CommonUtil.LoadIcon(self, cfgData.Pic, function(sprite)
  81. if sprite then
  82. itemLua.itemIcon.image.sprite = sprite
  83. itemLua.itemIcon.image.enabled = true
  84. end
  85. end, itemLua, 'ItemIcon')
  86. itemLua.itemName.text.text = string.formatbykey(cfgData.Name)
  87. if cfgData.FirstBuyReward and #cfgData.FirstBuyReward > 0 and data.first_buy then
  88. itemLua.discount:SetActive(true)
  89. itemLua.discount.text.text.text = string.formatbykey('LabelFirst')
  90. self:RefreshGiftsItem(itemLua, FirstBuyBgIconPath, cfgData.FirstBuyPic, cfgData.Reward)
  91. elseif cfgData.ExtraBuyReward and #cfgData.ExtraBuyReward > 0 then
  92. itemLua.discount:SetActive(true)
  93. itemLua.discount.text.text.text = string.formatbykey('LabelExtra')
  94. self:RefreshGiftsItem(itemLua, ExtraBuyBgIconPath, cfgData.ExtraBuyPic, cfgData.Reward)
  95. else
  96. itemLua.discount:SetActive(false)
  97. self:RefreshGiftsItem(itemLua, nil, nil, cfgData.Reward)
  98. end
  99. else
  100. itemLua.discount:SetActive(false)
  101. itemLua.itemName.text.text = ''
  102. itemLua.specialReward:SetActive(false)
  103. itemLua.goodsItems:SetActive(false)
  104. end
  105. -- local remainBuyNum = data.buy_nums
  106. -- if remainBuyNum >= 0 then
  107. -- itemLua.purchaseLimit:SetActive(true)
  108. -- itemLua.purchaseLimit.text.text = string.formatbykey('RuneShopLimitBuy', tostring(remainBuyNum))
  109. -- else
  110. -- itemLua.purchaseLimit:SetActive(false)
  111. -- end
  112. local price = data.price
  113. if price <= 0 then
  114. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  115. else
  116. itemLua.presentPrice.number.text.text = string.formatbykey('WalletGold',price)--tostring(price)
  117. end
  118. -- if data:IsSoldout() then
  119. -- itemLua.soldout:SetActive(true)
  120. -- itemLua.button.onClick:RemoveAllListeners()
  121. -- itemLua.presentPrice.button.onClick:RemoveAllListeners()
  122. -- else
  123. itemLua.soldout:SetActive(false)
  124. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickGiftItem, data.goods_id)
  125. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickGiftPrice, data.goods_id)
  126. --end
  127. end
  128. end
  129. function UIRechargeWalletShopView:OnClickGiftItem(button, params)
  130. local id = params[0]
  131. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIWalletShopGoldBuyTips, id)
  132. end
  133. function UIRechargeWalletShopView:OnClickGiftPrice(button, params)
  134. local id = params[0]
  135. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIWalletShopGoldBuyTips, id)
  136. -- local count = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.WalletNum)
  137. -- local id = params[0]
  138. -- local cfgData = ManagerContainer.CfgMgr:GetPurseShopCfgById(id)
  139. -- if cfgData then
  140. -- if count >= cfgData.RMB then
  141. -- local creditLimit = ManagerContainer.DataMgr.WalletShopData:GetCreditLimit()
  142. -- if creditLimit then
  143. -- ManagerContainer.DataMgr.WalletShopData:SendWalletShopItemBuyReq(id)
  144. -- else
  145. -- local max_credit = ManagerContainer.DataMgr.WalletShopData:GetMaxUseCredit()
  146. -- local use_credit = ManagerContainer.DataMgr.WalletShopData:GetCurUseCredit()
  147. -- local credit = max_credit - use_credit
  148. -- local cfgData = ManagerContainer.CfgMgr:GetPurseShopCfgById(id)
  149. -- if credit >= cfgData.RMB then
  150. -- ManagerContainer.DataMgr.WalletShopData:SendWalletShopItemBuyReq(id)
  151. -- else
  152. -- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("InsufficientLimit")
  153. -- end
  154. -- end
  155. -- else
  156. -- CommonUtil.ItemNotEnoughHandle(Enum.ItemType.WalletNum)
  157. -- end
  158. -- end
  159. end
  160. function UIRechargeWalletShopView:RefreshGiftsItem(itemLua, bgPic, numPic, rewards)
  161. if numPic and numPic ~= '' then
  162. itemLua.specialReward.bg.image.sprite = nil
  163. itemLua.specialReward.bg.image.enabled = false
  164. CommonUtil.LoadIcon(self, bgPic, function(sprite)
  165. if sprite then
  166. itemLua.specialReward.bg.image.sprite = sprite
  167. itemLua.specialReward.bg.image.enabled = true
  168. end
  169. end, itemLua, 'SpecialRewardBgIcon')
  170. itemLua.specialReward.num.image.sprite = nil
  171. itemLua.specialReward.num.image.enabled = false
  172. CommonUtil.LoadIcon(self, numPic, function(sprite)
  173. if sprite then
  174. itemLua.specialReward.num.image.sprite = sprite
  175. itemLua.specialReward.num.image.enabled = true
  176. end
  177. end, itemLua, 'SpecialRewardNumIcon')
  178. itemLua.specialReward:SetActive(true)
  179. itemLua.goodsItems:SetActive(false)
  180. else
  181. itemLua.specialReward:SetActive(false)
  182. if rewards then
  183. itemLua.goodsItems:SetActive(true)
  184. local reward = rewards[1]
  185. if reward then
  186. itemLua.iconSmallItem1:SetActive(true)
  187. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem1, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  188. else
  189. itemLua.iconSmallItem1:SetActive(false)
  190. end
  191. reward = rewards[2]
  192. if reward then
  193. itemLua.iconSmallItem2:SetActive(true)
  194. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem2, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  195. else
  196. itemLua.iconSmallItem2:SetActive(false)
  197. end
  198. reward = rewards[3]
  199. if reward then
  200. itemLua.iconSmallItem3:SetActive(true)
  201. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem3, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  202. else
  203. itemLua.iconSmallItem3:SetActive(false)
  204. end
  205. else
  206. itemLua.goodsItems:SetActive(false)
  207. end
  208. end
  209. end
  210. function UIRechargeWalletShopView:ShowReward(idx)
  211. local data = ManagerContainer.DataMgr.WalletShopData:GetWalletShopDataById(idx)
  212. if not data then
  213. return
  214. end
  215. local cfgData = ManagerContainer.CfgMgr:GetPurseShopCfgById(idx)
  216. if cfgData then
  217. local rewards = {}
  218. local reward = cfgData.Reward
  219. local firstReward = cfgData.FirstBuyReward
  220. local extraReward = cfgData.ExtraBuyReward
  221. local num = reward[1][2]
  222. if data.first_buy then
  223. num = num + firstReward[1][2]
  224. else
  225. num = num + extraReward[1][2]
  226. end
  227. table.insert(rewards,{cfgId = reward[1][1], num = num})
  228. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = rewards})
  229. end
  230. end
  231. function UIRechargeWalletShopView:HideShopItemByIconIdx(idx)
  232. local itemLua = self["runeShopGoodsItem"..idx]
  233. if(itemLua) then
  234. itemLua.presentPrice.icon.image.enabled = false
  235. end
  236. end
  237. function UIRechargeWalletShopView:RefreshShopItem(data)
  238. local walletShopData = ManagerContainer.DataMgr.WalletShopData:GetWalletShopData()
  239. if not walletShopData then
  240. for i=1,10,1 do
  241. self:HideShopItemByIconIdx(i)
  242. end
  243. return
  244. end
  245. if data ~= nil then
  246. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRechargeSuccess,data.shop_item.price)
  247. local idx = data.shop_item.goods_id
  248. local data = walletShopData[idx]
  249. if data then
  250. self:RefreshShopItemByIdx(idx,data)
  251. end
  252. else
  253. for k, v in pairs(walletShopData) do
  254. self:RefreshShopItemByIdx(k,v)
  255. end
  256. end
  257. self:RefreshWalletUI()
  258. end
  259. function UIRechargeWalletShopView:RefreshCoins()
  260. local coin = ManagerContainer.DataMgr.UserData:GetOwnCoin()
  261. self.coin.number.text.text = CommonUtil.FormatNumber(coin)
  262. self.curCoin = coin
  263. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemType.Coin)
  264. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite)
  265. self.coin.icon.image.sprite = sprite
  266. end)
  267. end
  268. function UIRechargeWalletShopView:RefreshDiamond()
  269. local count = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.Diamond)
  270. self.gold.number.text.text = CommonUtil.FormatNumber(count)
  271. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemType.Diamond)
  272. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite)
  273. self.gold.icon.image.sprite = sprite
  274. end)
  275. end
  276. function UIRechargeWalletShopView:RefreshWalletUI()
  277. local count = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.WalletNum)
  278. self.moneytoday.text.text = CommonUtil.FormatNumber(count)
  279. local creditLimit = ManagerContainer.DataMgr.WalletShopData:GetCreditLimit()
  280. local max_credit = ManagerContainer.DataMgr.WalletShopData:GetMaxUseCredit()
  281. local use_credit = ManagerContainer.DataMgr.WalletShopData:GetCurUseCredit()
  282. if creditLimit then
  283. self.moneylimit.text.text = I18N.T("DscMoneyLimitMax")
  284. self.textBox.text.text = I18N.T("RemainLimit2")
  285. else
  286. self.textBox.text.text = I18N.SetLanguageValue("RemainLimit1",max_credit - use_credit)
  287. self.moneylimit.text.text = use_credit.."/"..max_credit
  288. end
  289. self.btnIncreaseLimit:SetActive(not creditLimit)
  290. end
  291. function UIRechargeWalletShopView:RefreshVipView()
  292. local curVipLv = self.controller:GetCurVipLv()
  293. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv)
  294. self.vipIcon.image.sprite = nil
  295. self.vipIcon.image.enabled = false
  296. self.vipFrame.image.sprite = nil
  297. self.vipFrame.image.enabled = false
  298. if not vipCfg then
  299. self.vipNameTxt.text.text = ''
  300. return
  301. end
  302. CommonUtil.LoadIcon(self, vipCfg.BigIcon, function(sprite)
  303. if sprite then
  304. self.vipIcon.image.sprite = sprite
  305. self.vipIcon.image.enabled = true
  306. end
  307. end)
  308. CommonUtil.LoadIcon(self, vipCfg.BigFrame, function(sprite)
  309. if sprite then
  310. self.vipFrame.image.sprite = sprite
  311. self.vipFrame.image.enabled = true
  312. end
  313. end)
  314. self.vipNameTxt.text.text = string.formatbykey(vipCfg.Name)
  315. end
  316. function UIRechargeWalletShopView:FillContent(data, uiBase)
  317. self.uiBase = uiBase
  318. local gameObject = self.uiBase:GetRoot()
  319. if gameObject ~= nil then
  320. self.gameObject = gameObject
  321. self.transform = gameObject.transform
  322. end
  323. self:InitGenerate(self.transform, data)
  324. self:Init()
  325. end
  326. function UIRechargeWalletShopView:Init()
  327. self:RefreshVipView()
  328. self:RefreshCoins()
  329. self:RefreshDiamond()
  330. self:RefreshWalletUI()
  331. --self:RefreshShopItem(nil)
  332. --self:StartRefreshTimer()
  333. ManagerContainer.DataMgr.WalletShopData:SendWalletShopInfoReq()
  334. end
  335. function UIRechargeWalletShopView:RemoveEventListener()
  336. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  337. end
  338. function UIRechargeWalletShopView:AddUIEventListener()
  339. self.uiBase:AddButtonEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
  340. self.uiBase:AddButtonUniqueEventListener(self.btnVIP.button, self, self.OnClickVipBtn)
  341. self.uiBase:AddButtonUniqueEventListener(self.btnInfo.button, self, self.OnClickPlayRuleBtn)
  342. self.uiBase:AddButtonUniqueEventListener(self.btnIncreaseLimit.button, self, self.OnClickGetCredit)
  343. end
  344. function UIRechargeWalletShopView:OnClickGetCredit()
  345. local curUIId = ManagerContainer.LuaUIMgr:GetCurUIId()
  346. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, nil, curUIId)
  347. end
  348. function UIRechargeWalletShopView:OnClickPlayRuleBtn()
  349. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', "RechargeWalletRule"})
  350. end
  351. function UIRechargeWalletShopView:OnClickVipBtn()
  352. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIVip)
  353. end
  354. function UIRechargeWalletShopView:OnVipLvChanged()
  355. self:RefreshVipView()
  356. end
  357. function UIRechargeWalletShopView:OnClickCloseBtn()
  358. self:UIClose()
  359. local str = GlobalConfig.Instance:GetConfigStrValue(361)
  360. local data = CommonUtil.DeserializeGlobalStrToNumberTable(str)
  361. local curlevelId = ManagerContainer.LuaBattleMgr:GetCurLevelUniqueId()
  362. local forceData = data and data[1]
  363. if forceData and forceData[1] == curlevelId then
  364. local forceGuideId = forceData[2]
  365. if not forceGuideId or forceGuideId <= 0 then
  366. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FORCE_GUIDE_OVER)
  367. return
  368. end
  369. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FORCE_GUIDE_TRIGGER, Enum.ForceGuideTriggerEnum.FGGroupId, forceGuideId, false)
  370. end
  371. end
  372. function UIRechargeWalletShopView:OnHide()
  373. end
  374. function UIRechargeWalletShopView:OnShow(data)
  375. self.controller:SetData(data)
  376. end
  377. function UIRechargeWalletShopView:OnClose()
  378. end
  379. function UIRechargeWalletShopView:OnDispose()
  380. self:StopRefreshTimer()
  381. self.controller:OnDispose()
  382. end
  383. return UIRechargeWalletShopView