KLTradeBuyPanel.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. ---@class KLTradeBuyPanel:UIKmlLuaPanelBase
  2. ---@field view KLTradeBuyPanelView
  3. local KLTradeBuyPanel = class(UIKmlLuaPanelBase)
  4. local this = KLTradeBuyPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. end
  8. ---注册UI事件和服务器消息
  9. function this:RegistEvents()
  10. GUI:AddOnClickEvent(self.view.btn_close, self, self.BtnCloseClick)
  11. GUI:AddOnClickEvent(self.view.btn_buy, self, self.BtnBuyOnClick)
  12. GUI:Input_SetOnEndEdit(self.view.input_count, self, self.InputCountEndEdit)
  13. GUI:AddOnClickEvent(self.view.btn_add, self, self.BtnAddOnClick)
  14. GUI:AddOnClickEvent(self.view.btn_minus, self, self.BtnSubOnClick)
  15. end
  16. function this:BtnAddOnClick()
  17. ---@type KLTradeGoodsItemData
  18. local data = self.args
  19. local count = tonumber(GUI:Text_getString(self.view.input_count))
  20. if count >= data.count then
  21. return
  22. end
  23. count = count + 1
  24. GUI:Text_setString(self.view.input_count, tostring(count))
  25. self:RefreshPrice()
  26. end
  27. function this:BtnSubOnClick()
  28. local count = tonumber(GUI:Text_getString(self.view.input_count))
  29. if count <= 1 then
  30. return
  31. end
  32. count = count - 1
  33. GUI:Text_setString(self.view.input_count, tostring(count))
  34. self:RefreshPrice()
  35. end
  36. function this:InputCountEndEdit()
  37. local count = tonumber(GUI:Text_getString(self.view.input_count))
  38. if count < 1 then
  39. count = 1
  40. end
  41. ---@type KLTradeGoodsItemData
  42. local data = self.args
  43. if count > data.count then
  44. count = data.count
  45. end
  46. GUI:Text_setString(self.view.input_count, tostring(count))
  47. self:RefreshPrice()
  48. end
  49. function this:BtnBuyOnClick()
  50. local IsNeedMonthCard, IsNeedDailyCard = InfoManager.monthCardInfo:IsNeedMonthAndDailyCard("stall")
  51. if IsNeedDailyCard and InfoManager.monthCardInfo.IsGetDailyCard and not InfoManager.monthCardInfo.IsGetMonthCard then
  52. ---获得了月卡
  53. if InfoManager.monthCardInfo:IsBanType(self.args.type, self.args.subtype, false) then
  54. SL:TipMessage( SL:GetConfig('cfg_string', 440).text, 1, NoticeType.NoticeMid )--"开通月卡后可使用交易行功能",
  55. return
  56. end
  57. end
  58. if not InfoManager.monthCardInfo:IsHaveMonthCardRights("stall") then
  59. SL:TipMessage( SL:GetConfig('cfg_string', 278).text, 1, NoticeType.NoticeMid )--"开通月卡后可使用交易行功能",
  60. return
  61. end
  62. ---@type KLTradeGoodsItemData
  63. local data = self.args
  64. if data.publicity == 1 then
  65. --[[ local message = {stringTblID=225,
  66. showTips = "公示期结束后从预购玩家中<color=#1ADD1F>抽取一位获得该商品</color>\n其他玩家邮件返还预购货币",
  67. title = "提示",
  68. callback = function()
  69. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_TRADE_PRE_ORDER,{data.itemcfgid,data.itemid,data.type})
  70. end
  71. }]]
  72. SL:CommonTipsMessage({ stringTblID = 225,
  73. title = "提示",
  74. callback = function()
  75. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_TRADE_PRE_ORDER, { data.itemcfgid, data.itemid, data.type, data.ownid })
  76. end
  77. })
  78. else
  79. local count = tonumber(GUI:Text_getString(self.view.input_count))
  80. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_TRADE_BUY_GOODS, { data.itemcfgid, data.itemid, data.type, count, data.ownid })
  81. end
  82. self:BtnCloseClick()
  83. end
  84. function this:BtnCloseClick()
  85. GUI:UIPanel_Close("dev/outui/Trade/Panel/KLTradeBuy/KLTradeBuyPanel")
  86. GUI:UIPanel_Close("dev/ui/Tips/Panel/KLUIEquipTips/KLUIEquipTipsPanel")
  87. GUI:UIPanel_Close("dev/ui/Tips/Panel/KLUIEquipTipsComparsion/KLUIEquipTipsComparsionPanel")
  88. GUI:UIPanel_Close("dev/ui/Tips/Panel/KLIUItemTips/KLUIItemTipsPanel")
  89. end
  90. ---创建或者刷新界面数据时调用
  91. function this:Refresh()
  92. ---@type KLTradeGoodsItemData
  93. local data = self.args
  94. GUI:Image_loadTexture(self.view.img_coin_icon, data.cointype, "Atlas/UIBagPanel.spriteatlas")
  95. GUI:Text_setString(self.view.btn_buy, data.publicity == 1 and "预购" or "购买")
  96. GUI:setVisible(self.view.group_input_count, data.publicity ~= 1)
  97. self:RefreshPrice()
  98. end
  99. function this:RefreshPrice()
  100. ---@type KLTradeGoodsItemData
  101. local data = self.args
  102. local count
  103. if data.publicity == 1 then
  104. count = data.count
  105. else
  106. count = tonumber(GUI:Text_getString(self.view.input_count))
  107. end
  108. local unit = ""
  109. if data.cointype == "30030305" then
  110. unit = "天"
  111. end
  112. if not data.unitPrice then
  113. data.unitPrice = 0
  114. end
  115. GUI:Text_setString(self.view.txt_price, tostring(data.unitPrice * count) .. unit)
  116. end
  117. function this:Close()
  118. end
  119. --[[function this:GetCoinIcon(coinType)
  120. if coinType == 10010001 then
  121. return "img_bag_01"
  122. elseif coinType == 10020001 then
  123. return "img_bag_02"
  124. elseif coinType == 10030001 then
  125. return "img_bag_03"
  126. elseif coinType == 10040001 then
  127. return "img_bag_04"
  128. end
  129. end]]
  130. return this