KLShopMallBuyUIPanel.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. ---@class KLShopMallBuyUIPanel:UIKmlLuaPanelBase
  2. ---@field view KLShopMallBuyUIPanelView
  3. local KLShopMallBuyUIPanel = class(UIKmlLuaPanelBase)
  4. local this = KLShopMallBuyUIPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. ---@type MallProtos.MallGoods
  8. local data = self.args
  9. ---@type cfg_shopMall_column
  10. self.config = SL:GetConfig("cfg_shopMall", data.goodsId)
  11. EquipFunc.tipsHeight = 0
  12. SL:OpenTips("mall", self.config.itemId,nil,nil,nil,{hideMask=true})
  13. end
  14. ---创建或者刷新界面数据时调用
  15. function this:Refresh()
  16. GUI:Text_setString(self.view.InputFieldLevel, "1")
  17. self:RefreshTotalPrice()
  18. if EquipFunc.tipsHeight and EquipFunc.tipsHeight ~= 0 then
  19. self:UpdateHeight(EquipFunc.tipsHeight)
  20. end
  21. end
  22. ---注册UI事件和服务器消息
  23. function this:RegistEvents()
  24. GUI:AddOnClickEvent(self.view.ClickMask, self, self.ClickMaskOnClick)
  25. GUI:AddOnClickEvent(self.view.BtnBuy, self, self.BtnBuyOnClick)
  26. GUI:Input_SetOnEndEdit(self.view.InputFieldLevel, self, self.InputFieldLevelOnEndEdit)
  27. GUI:AddOnClickEvent(self.view.BtnLevelAdd, self, self.BtnLevelAddOnClick)
  28. GUI:AddOnClickEvent(self.view.BtnLevelMinus, self, self.BtnLevelMinusOnClick)
  29. end
  30. function this:BtnLevelAddOnClick()
  31. local text = GUI:Text_getString(self.view.InputFieldLevel)
  32. local inputNum = tonumber(text)
  33. GUI:Text_setString(self.view.InputFieldLevel, tostring(inputNum + 1))
  34. self:CheckInput()
  35. self:RefreshTotalPrice()
  36. end
  37. function this:BtnLevelMinusOnClick()
  38. local text = GUI:Text_getString(self.view.InputFieldLevel)
  39. local inputNum = tonumber(text)
  40. inputNum = inputNum - 1
  41. GUI:Text_setString(self.view.InputFieldLevel, tostring(inputNum))
  42. self:CheckInput()
  43. self:RefreshTotalPrice()
  44. end
  45. function this:InputFieldLevelOnEndEdit(_, _, eventData)
  46. local text = eventData[1]
  47. GUI:Text_setString(self.view.InputFieldLevel, tostring(text))
  48. self:CheckInput()
  49. self:RefreshTotalPrice()
  50. end
  51. function this:RefreshTotalPrice()
  52. local text = GUI:Text_getString(self.view.InputFieldLevel)
  53. local inputNum = tonumber(text)
  54. local totalPrice = self.config.price[2] * inputNum
  55. GUI:Text_setString(self.view.TextTotalPrice, tostring(totalPrice))
  56. local ownCount = SL:GetTotalCoinBaseId(self.args.coinType)
  57. if self.args.coinType == 10050001 then
  58. ownCount = ownCount + SL:GetTotalCoinBaseId(10040001) --加上钻石
  59. end
  60. GUI:Text_setTextColor(self.view.TextTotalPrice, ownCount >= totalPrice and "#1add1f" or "#ff2323")
  61. GUI:Image_loadTexture(self.view.icon_money, tostring(self.config.price[1]), "Atlas/TS_Common.spriteatlas")
  62. end
  63. function this:ClickMaskOnClick()
  64. GUI:UIPanel_Close("dev/ui/ShopMall/Panel/KLShopMallBuyUI/KLShopMallBuyUIPanel")
  65. local itemGetPathPanel = GUI:GetUI("dev/ui/Tips/Panel/KLIUItemTipsOther/KLIUItemTipsOtherPanel")
  66. if itemGetPathPanel then
  67. GUI:UIPanel_Close("dev/ui/Tips/Panel/KLIUItemTipsOther/KLIUItemTipsOtherPanel")
  68. end
  69. end
  70. function this:BtnBuyOnClick()
  71. local coin = SL:GetTotalCoinBaseId(self.config.price[1])
  72. if self.config.price[1] == 10050001 then
  73. coin = coin + SL:GetTotalCoinBaseId(10040001) --加上钻石
  74. end
  75. if coin < self.config.price[2] * tonumber(GUI:Text_getString(self.view.InputFieldLevel)) then
  76. if self.config.price[1] == 10040001 then
  77. --钻石
  78. GUI:UIPanel_Close("dev/ui/ShopMall/Panel/KLShopMallBuyUI/KLShopMallBuyUIPanel")
  79. SL:CommonTipsMessage({ stringTblID = 235,
  80. showTips = "钻石不足,是否前往充值",
  81. callback = self.GotoRecharge,
  82. ui = self
  83. })
  84. else
  85. SL:TipMessage( SL:GetConfig('cfg_string', 269).text, 1, NoticeType.NoticeMid )--货币不足
  86. end
  87. return
  88. end
  89. local level = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  90. if next(self.config.level) and self.config.level[1] > level then
  91. ---@type cfg_string_column
  92. local tbl = SL:GetConfig("cfg_string",117)
  93. SL:TipMessage( tbl.text, 1, NoticeType.NoticeMid )
  94. return
  95. end
  96. ---@type cfg_career_column
  97. local careerCheck
  98. if #self.config.occupation ~= 0 then
  99. --有职业限制
  100. local baseCareer = SL:GetMetaValue(EMetaVarGetKey.JOB)
  101. for _, v in pairs(self.config.occupation) do
  102. if baseCareer == v[1] then
  103. local careerConfig = self:GetCareerTbl(v[1], v[2])
  104. careerCheck = careerCheck or self:CareerCheck(careerConfig)
  105. end
  106. end
  107. else
  108. careerCheck = true
  109. end
  110. if not careerCheck then
  111. ---@type cfg_string_column
  112. local tbl = SL:GetConfig("cfg_string",490)
  113. SL:TipMessage( tbl.text, 1, NoticeType.NoticeMid )
  114. return
  115. end
  116. local text = GUI:Text_getString(self.view.InputFieldLevel)
  117. local inputNum = tonumber(text)
  118. SL:RequestBuyShopMallGoods(self.config.id, inputNum)
  119. GUI:UIPanel_Close("dev/ui/ShopMall/Panel/KLShopMallBuyUI/KLShopMallBuyUIPanel")
  120. end
  121. function this:GotoRecharge()
  122. GUI:UIPanel_Close("dev/outui/ShopMain/Panel/KLShopMain/KLShopMainPanel")
  123. GUI:UIPanel_Open("dev/outui/ShopMain/Panel/KLShopMain/KLShopMainPanel",nil,nil,{2})
  124. end
  125. function this:Close()
  126. SL:CloseTips()
  127. self:UnRegistEvents()
  128. end
  129. function this:CheckInput()
  130. local inputStr = GUI:Text_getString(self.view.InputFieldLevel)
  131. local inputNum = tonumber(inputStr)
  132. if not inputNum then
  133. GUI:Text_setString(self.view.InputFieldLevel, "1")
  134. self:RefreshTotalPrice()
  135. return
  136. end
  137. local maxCount = 99
  138. if self.config.limitBuy ~= 0 then
  139. ---@type MallProtos.MallGoods
  140. local data = self.args
  141. maxCount = data.limitCount
  142. end
  143. if inputNum >= maxCount then
  144. GUI:Text_setString(self.view.InputFieldLevel, tostring(maxCount))
  145. self:RefreshTotalPrice()
  146. return
  147. end
  148. if inputNum <= 0 then
  149. GUI:Text_setString(self.view.InputFieldLevel, tostring(maxCount))
  150. self:RefreshTotalPrice()
  151. return
  152. end
  153. end
  154. function this:UpdateHeight(bg_height)
  155. local add = (bg_height - 156) / 2
  156. GUI:setPositionY(self.view.root, add)
  157. end
  158. ---@param careerConfig cfg_career_column
  159. function this:CareerCheck(careerConfig)
  160. if not careerConfig then
  161. return true
  162. end
  163. local selfCareer = SL:MeData_GetCareer()
  164. ---@type cfg_career_column
  165. local career = self:GetCareerTbl(selfCareer.baseCareer, selfCareer.careerRank)
  166. if careerConfig.baseCareer == career.baseCareer and careerConfig.careerRank <= career.careerRank then
  167. return true
  168. end
  169. return false
  170. end
  171. function this:GetCareerTbl(baseCareer, careerRank)
  172. ---@type cfg_career_column[]
  173. local tbls = SL:GetConfigTable("cfg_career")
  174. for k, v in pairs(tbls) do
  175. if v.baseCareer == baseCareer and v.careerRank == careerRank then
  176. return v
  177. end
  178. end
  179. end
  180. return this