UIBoliShopBuyTipsView.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. local UIBoliShopBuyTipsView = require("UIShop/UIShopBuyTipsView_Generate")
  2. function UIBoliShopBuyTipsView:OnAwake(data)
  3. self.controller = require("UIShop/UIBoliShopBuyTipsCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UIBoliShopBuyTipsView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  9. end
  10. function UIBoliShopBuyTipsView: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 UIBoliShopBuyTipsView:Init()
  21. if not self.controller:IsValidData() then
  22. self.iconItem:SetActive(false)
  23. self.limitBox:SetActive(false)
  24. self.itemName.text.text = ''
  25. self.desTxt.text.text = ''
  26. self.buyNumTxt.text.text = ''
  27. self.presentPrice.number.text.text = ''
  28. if self.timer then
  29. self.timer:Stop()
  30. self.timer = nil
  31. end
  32. return
  33. end
  34. self.iconItem:SetActive(true)
  35. local goodsData = self.controller:GetCurGoodsData()
  36. local goodsCfgData = goodsData:GetGoodsCfgData()
  37. local data = {cfgId = goodsCfgData.GoodsItem}
  38. CommonUtil.UpdateItemPrefab(self, self.iconItem, data, nil, self, self.ShowItemTips, data)
  39. local havenum = CommonUtil.GetOwnResCountByItemId(goodsCfgData.GoodsItem)
  40. self.itemnum.text.text = tostring(havenum)
  41. self.itemName.text.text = goodsCfgData.GoodsName
  42. self.desTxt.text.text = goodsCfgData.GoodsDesc
  43. self:RefreshCost()
  44. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(goodsCfgData.PayForType)
  45. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function (sprite)
  46. self.presentPrice.icon.image.sprite = sprite
  47. end)
  48. local limitType = goodsData.limitType
  49. if limitType == Enum.LimitBuyType.NoLimit then
  50. self.limitBox:SetActive(false)
  51. elseif limitType == Enum.LimitBuyType.Forever then
  52. self.limitBox:SetActive(false)
  53. elseif limitType == Enum.LimitBuyType.Daily then
  54. self.limitBox:SetActive(true)
  55. self.timeLimit.text.text = goodsData:CalculateLimitTime()
  56. self.timer = Timer.New(slot(self.RefreshTimer, self), 1, -1)
  57. elseif limitType == Enum.LimitBuyType.Week then
  58. self.limitBox:SetActive(true)
  59. self.timeLimit.text.text = goodsData:CalculateLimitTime()
  60. self.timer = Timer.New(slot(self.RefreshTimer, self), 1, -1)
  61. elseif limitType == Enum.LimitBuyType.Time then
  62. self.limitBox:SetActive(true)
  63. self.timeLimit.text.text = goodsData:CalculateLimitTime()
  64. self.timer = Timer.New(slot(self.RefreshTimer, self), 1, -1)
  65. elseif limitType == Enum.LimitBuyType.Special then
  66. self.limitBox:SetActive(false)
  67. else
  68. self.limitBox:SetActive(false)
  69. end
  70. if self.timer then
  71. self.timer:Start()
  72. end
  73. end
  74. function UIBoliShopBuyTipsView:RemoveEventListener()
  75. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  76. self.btnMinus.repeatButton:AddRepeatClickEventListener(nil, nil)
  77. self.btnAdd.repeatButton:AddRepeatClickEventListener(nil, nil)
  78. end
  79. function UIBoliShopBuyTipsView:AddUIEventListener()
  80. self.uiBase:AddButtonEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
  81. self.uiBase:AddButtonEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn)
  82. self.uiBase:AddButtonEventListener(self.btnMax.button, self, self.OnClickMaxBtn)
  83. self.uiBase:AddButtonEventListener(self.btnBuy.button, self, self.OnClickBuyBtn)
  84. self.btnMinus.repeatButton:AddRepeatClickEventListener(self, self.OnClickMinusBuyNum)
  85. self.btnAdd.repeatButton:AddRepeatClickEventListener(self, self.OnClickAddBuyNum)
  86. end
  87. function UIBoliShopBuyTipsView:OnHide()
  88. end
  89. function UIBoliShopBuyTipsView:OnShow(data)
  90. self.controller:SetData(data)
  91. end
  92. function UIBoliShopBuyTipsView:OnClose()
  93. end
  94. function UIBoliShopBuyTipsView:OnDispose()
  95. if self.timer then
  96. self.timer:Stop()
  97. self.timer = nil
  98. end
  99. self.controller:OnDispose()
  100. end
  101. function UIBoliShopBuyTipsView:OnClickCloseBtn()
  102. self:UIClose()
  103. end
  104. function UIBoliShopBuyTipsView:OnClickMaxBtn()
  105. if self.controller:SetBuyNum(self.controller:GetMaxBuyNumOnce()) then
  106. self:RefreshCost()
  107. end
  108. end
  109. function UIBoliShopBuyTipsView:OnClickBuyBtn()
  110. local errorCode, itemCfgId = self.controller:SendShopBuyItemReq()
  111. if errorCode ~= 0 then
  112. if errorCode == 391 then
  113. CommonUtil.ItemNotEnoughHandle(itemCfgId, Enum.UIPageName.UIShop)
  114. else
  115. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCode)
  116. end
  117. end
  118. self:UIClose()
  119. end
  120. function UIBoliShopBuyTipsView:OnClickMinusBuyNum()
  121. if self.controller:ChangeDeltaBuyNum(-1) then
  122. self:RefreshCost()
  123. end
  124. end
  125. function UIBoliShopBuyTipsView:OnClickAddBuyNum()
  126. if self.controller:ChangeDeltaBuyNum(1) then
  127. self:RefreshCost()
  128. end
  129. end
  130. function UIBoliShopBuyTipsView:RefreshCost()
  131. if not self.controller:IsValidData() then return end
  132. self.buyNumTxt.text.text = tostring(self.controller:GetBuyNum())
  133. self.presentPrice.number.text.text = tostring(self.controller:GetBuyNum() * self.controller:GetCurPrice())
  134. end
  135. function UIBoliShopBuyTipsView:RefreshTimer()
  136. local goodsData = self.controller:GetCurGoodsData()
  137. if not goodsData then return end
  138. self.limitBox:SetActive(true)
  139. self.timeLimit.text.text = goodsData:CalculateLimitTime()
  140. end
  141. return UIBoliShopBuyTipsView