UIWalletShopGoldBuyTipsView.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. local UIWalletShopGoldBuyTipsView = require("UIRuneShop/UIRuneShopGoldBuyTipsView_Generate")
  2. function UIWalletShopGoldBuyTipsView:OnAwake(data)
  3. self.controller = require("UIRuneShop/UIWalletShopGoldBuyTipsCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UIWalletShopGoldBuyTipsView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  9. end
  10. function UIWalletShopGoldBuyTipsView:FillContent(data, uiBase)
  11. self.uiBase = uiBase
  12. local gameObject = self.uiBase:GetRoot()
  13. if gameObject ~= nil then
  14. self.gameObject = gameObject
  15. self.transform = gameObject.transform
  16. end
  17. self:InitGenerate(self.transform, data)
  18. self:Init()
  19. end
  20. function UIWalletShopGoldBuyTipsView:Init()
  21. self.controller:InitData()
  22. local goodsData = self.controller:GetCurGoodsData()
  23. self.presentPrice.currency:SetActive(false)
  24. if not goodsData then
  25. self.textTitle.text.text = ''
  26. self.buyLimitTxt.text.text = ''
  27. self.presentPrice.number.text.text = ''
  28. self.image.image.enabled = false
  29. self.image.image.sprite = nil
  30. return
  31. end
  32. local price = goodsData.price
  33. if price <= 0 then
  34. self.presentPrice.number.text.text = string.formatbykey('Free')
  35. else
  36. self.presentPrice.number.text.text = string.formatbykey('WalletGold',price)--tostring(price)
  37. end
  38. local cfgData = goodsData.cfgData
  39. if cfgData then
  40. CommonUtil.LoadIcon(self, cfgData.Pic, function(sprite)
  41. if sprite then
  42. self.image.image.sprite = sprite
  43. self.image.image.enabled = true
  44. end
  45. end)
  46. local rewards = cfgData.Reward
  47. local reward
  48. local goldNum = 0
  49. if rewards then
  50. for i = 1, #rewards do
  51. reward = rewards[i]
  52. if reward[1] == Enum.ItemType.Diamond then
  53. if reward[2] then
  54. goldNum = goldNum + reward[2]
  55. end
  56. end
  57. end
  58. end
  59. local extraGoldNum = 0
  60. local isFirstBuy = goodsData.first_buy
  61. if cfgData.FirstBuyReward and #cfgData.FirstBuyReward > 0 and isFirstBuy then
  62. self.textTitle.text.text = I18N.T(tostring(cfgData.Name)) .. string.formatbykey('RuneShopGoldTitle1')
  63. rewards = cfgData.FirstBuyReward
  64. for i = 1, #rewards do
  65. reward = rewards[i]
  66. if reward[1] == Enum.ItemType.Diamond then
  67. if reward[2] then
  68. extraGoldNum = extraGoldNum + reward[2]
  69. end
  70. end
  71. end
  72. elseif cfgData.ExtraBuyReward and #cfgData.ExtraBuyReward > 0 then
  73. self.textTitle.text.text = I18N.T(tostring(cfgData.Name)) .. string.formatbykey('RuneShopGoldTitle2')
  74. rewards = cfgData.ExtraBuyReward
  75. for i = 1, #rewards do
  76. reward = rewards[i]
  77. if reward[1] == Enum.ItemType.Diamond then
  78. if reward[2] then
  79. extraGoldNum = extraGoldNum + reward[2]
  80. end
  81. end
  82. end
  83. else
  84. self.textTitle.text.text = I18N.T(tostring(cfgData.Name))
  85. end
  86. local contentStr = '+' .. tostring((goldNum + extraGoldNum))
  87. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemType.Diamond)
  88. if itemCfgData then
  89. contentStr = contentStr .. tostring(itemCfgData.Name)
  90. end
  91. self.buyLimitTxt.text.text = string.formatbykey('RuneShopGoldDsc2', tostring(price))
  92. self.goldText.text.text = string.formatbykey('RuneShopGoldDsc3', tostring((goldNum + extraGoldNum)),tostring(goldNum), tostring(extraGoldNum))
  93. else
  94. self.image.image.enabled = false
  95. self.image.image.sprite = nil
  96. self.textTitle.text.text = ''
  97. self.goldText.text.text = ''
  98. self.buyLimitTxt.text.text = ''
  99. end
  100. end
  101. function UIWalletShopGoldBuyTipsView:RemoveEventListener()
  102. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  103. end
  104. function UIWalletShopGoldBuyTipsView:AddUIEventListener()
  105. self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
  106. self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn)
  107. self.uiBase:AddButtonUniqueEventListener(self.btnBuy.button, self, self.OnClickBuyBtn)
  108. end
  109. function UIWalletShopGoldBuyTipsView:OnHide()
  110. end
  111. function UIWalletShopGoldBuyTipsView:OnShow(data)
  112. self.controller:SetData(data)
  113. end
  114. function UIWalletShopGoldBuyTipsView:OnClose()
  115. end
  116. function UIWalletShopGoldBuyTipsView:OnDispose()
  117. self.controller:OnDispose()
  118. end
  119. function UIWalletShopGoldBuyTipsView:OnClickCloseBtn()
  120. self:UIClose()
  121. end
  122. function UIWalletShopGoldBuyTipsView:OnClickBuyBtn()
  123. --钱包儲值
  124. local count = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.WalletNum)
  125. local goodsData = self.controller:GetCurGoodsData()
  126. if not goodsData then
  127. self:UIClose()
  128. return
  129. end
  130. local cfgData = goodsData.cfgData
  131. if cfgData then
  132. if count >= cfgData.RMB then
  133. local creditLimit = ManagerContainer.DataMgr.WalletShopData:GetCreditLimit()
  134. if creditLimit then
  135. ManagerContainer.DataMgr.WalletShopData:SendWalletShopItemBuyReq(cfgData.Id)
  136. else
  137. local max_credit = ManagerContainer.DataMgr.WalletShopData:GetMaxUseCredit()
  138. local use_credit = ManagerContainer.DataMgr.WalletShopData:GetCurUseCredit()
  139. local credit = max_credit - use_credit
  140. if credit >= cfgData.RMB then
  141. ManagerContainer.DataMgr.WalletShopData:SendWalletShopItemBuyReq(cfgData.Id)
  142. else
  143. ManagerContainer.LuaUIMgr:ShowMessageBox("Insufficient",nil,nil,self,self.OnClickGetCredit)
  144. --ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("InsufficientLimit")
  145. end
  146. end
  147. else
  148. CommonUtil.ItemNotEnoughHandle(Enum.ItemType.WalletNum)
  149. end
  150. end
  151. self:UIClose()
  152. end
  153. function UIWalletShopGoldBuyTipsView:OnClickGetCredit()
  154. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, nil)
  155. end
  156. return UIWalletShopGoldBuyTipsView