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