UIShopGoldBuyTips.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. local UIShopGoldBuyTips = class("UIShopGoldBuyTips")
  2. local exchangeIconKey = 310
  3. local exchangeCostKey = 308
  4. local exchangeRewardKey = 309
  5. local exchangeIcon
  6. local exchangeCosts
  7. local exchangeRewards
  8. function UIShopGoldBuyTips:ctor()
  9. end
  10. function UIShopGoldBuyTips:InitGo(host,uiGo)
  11. self.host = host
  12. self.viewLua = CommonUtil.BindGridViewItem2Lua(self.host, "UIShopGoldBuyTips", uiGo)
  13. self:InitPanel()
  14. end
  15. function UIShopGoldBuyTips:InitPanel()
  16. exchangeIcon = GlobalConfig.Instance:GetConfigStrValue(exchangeIconKey)
  17. local val = GlobalConfig.Instance:GetConfigStrValue(exchangeCostKey)
  18. if val ~= "" and val ~= nil then
  19. exchangeCosts = CommonUtil.DeserializeGlobalStrToTable(val)
  20. end
  21. local val = GlobalConfig.Instance:GetConfigStrValue(exchangeRewardKey)
  22. if val ~= "" and val ~= nil then
  23. exchangeRewards = CommonUtil.DeserializeGlobalStrToTable(val)
  24. end
  25. end
  26. function UIShopGoldBuyTips:AddEventListener()
  27. end
  28. function UIShopGoldBuyTips:RemoveEventListener()
  29. end
  30. function UIShopGoldBuyTips:AddUIEventListener()
  31. self.host.uiBase:AddButtonUniqueEventListener(self.viewLua.btnClose.button, self, self.OnClickCloseBtn)
  32. self.host.uiBase:AddButtonUniqueEventListener(self.viewLua.AnyBtn.button, self, self.OnClickCloseBtn)
  33. self.host.uiBase:AddButtonUniqueEventListener(self.viewLua.btnBuy.button, self, self.OnClickBuyBtn)
  34. end
  35. function UIShopGoldBuyTips:Show()
  36. self:AddEventListener()
  37. if not exchangeCosts then
  38. self.viewLua.textTitle.text.text = ''
  39. self.viewLua.buyLimitTxt.text.text = ''
  40. self.viewLua.presentPrice.number.text.text = ''
  41. self.viewLua.image.image.enabled = false
  42. self.viewLua.image.image.sprite = nil
  43. return
  44. end
  45. if exchangeIcon then
  46. CommonUtil.LoadIcon(self, exchangeIcon, function(sprite)
  47. if sprite then
  48. self.viewLua.image.image.sprite = sprite
  49. self.viewLua.image.image.enabled = true
  50. end
  51. end)
  52. end
  53. local rewards = exchangeRewards
  54. local reward
  55. local contentStr = ""
  56. if rewards then
  57. for i = 1, #rewards do
  58. reward = rewards[i]
  59. local id = tonumber(reward[1])
  60. local num = tonumber(reward[2])
  61. contentStr = contentStr..'+' .. num
  62. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(id)
  63. if itemCfgData then
  64. contentStr = contentStr .. tostring(itemCfgData.Name)
  65. end
  66. if i < #reward then
  67. contentStr = contentStr ..'\n'
  68. end
  69. end
  70. end
  71. self.viewLua.goldText.text.text = contentStr
  72. local price = 0
  73. if exchangeCosts and exchangeCosts[1] then
  74. price = tonumber(exchangeCosts[1][2])
  75. end
  76. if price <= 0 then
  77. self.viewLua.presentPrice.number.text.text = string.formatbykey('Free')
  78. else
  79. self.viewLua.presentPrice.number.text.text = tostring(price)
  80. end
  81. self.viewLua:SetActive(true)
  82. end
  83. function UIShopGoldBuyTips:OnClickCloseBtn()
  84. self:Hide()
  85. end
  86. function UIShopGoldBuyTips:OnClickBuyBtn()
  87. ManagerContainer.DataMgr.ShopDataMgr:SendRedBagExchangeReq()
  88. self:Hide()
  89. end
  90. function UIShopGoldBuyTips:Hide()
  91. self:RemoveEventListener()
  92. self.viewLua:SetActive(false)
  93. self:Clear()
  94. end
  95. function UIShopGoldBuyTips:Clear()
  96. end
  97. function UIShopGoldBuyTips:Dispose()
  98. self:Hide()
  99. self.host = nil
  100. self.viewLua = nil
  101. end
  102. return UIShopGoldBuyTips