KLShopMallGoodsItem.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. ---@class KLShopMallGoodsItem:UIKmlLuaPanelBase
  2. ---@field view KLShopMallGoodsItemView
  3. local KLShopMallGoodsItem = class(UIKmlLuaPanelBase)
  4. local this = KLShopMallGoodsItem
  5. ---创建时调用一次
  6. function this:Init()
  7. end
  8. ---创建或者刷新界面数据时调用
  9. function this:Refresh()
  10. end
  11. ---@param data MallProtos.MallGoods
  12. function this:RefreshItem(data)
  13. self.data = data
  14. ---@type cfg_shopMall_column
  15. local config = SL:GetConfig("cfg_shopMall", data.goodsId)
  16. self.config = config
  17. if not config then
  18. return
  19. end
  20. GUI:Text_setString(self.view.txt_goods_title, config.itemName)
  21. local color = SL:GetItemColor(config.itemId)
  22. GUI:Text_setTextColor(self.view.txt_goods_title, color)
  23. local level = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  24. if next(config.level) and config.level[1] > level then
  25. --显示等级限制
  26. GUI:Text_setString(self.view.Text_Condition, string.format("需要等级:%d", config.level[1]))
  27. GUI:Text_setTextColor(self.view.Text_Condition, "#ED2E2E")
  28. else
  29. --显示职业限制or不显示
  30. ---@type cfg_career_column
  31. local careerConfig
  32. if #config.occupation ~= 0 then
  33. --有职业限制
  34. local baseCareer = SL:GetMetaValue(EMetaVarGetKey.JOB)
  35. for _, v in pairs(config.occupation) do
  36. if baseCareer == v[1] then
  37. careerConfig = self:GetCareerTbl(v[1], v[2])
  38. end
  39. end
  40. end
  41. GUI:Text_setString(self.view.Text_Condition, careerConfig and "职业:" .. careerConfig.name or "")
  42. GUI:Text_setTextColor(self.view.Text_Condition, self:CareerCheck(careerConfig) and "#DCE1E5" or "#ED2E2E")
  43. end
  44. local itemCount = data.count ~= 1 and tostring(data.count) or ""
  45. --[[if self.item then
  46. self.view.img_goods_icon.kmlControl:HideAllChilds()
  47. end
  48. self.item = GUI:Item_Create(self.view.img_goods_icon, {
  49. width = "100",
  50. height = "100",
  51. itemid = config.itemId,
  52. tips = "1",
  53. mfixsize = "100,100",
  54. bgscale = "0,0",
  55. itemCount = itemCount,
  56. textpos = "-20,20,0"
  57. })]]
  58. GUI:Item_setItemId(self.view.item_goods, config.itemId)
  59. GUI:Item_setItemCount(self.view.item_goods,itemCount)
  60. if config.limitBuy == 0 then
  61. GUI:Text_setString(self.view.txt_purchase_limitation, "")
  62. elseif config.limitBuy == 1 then
  63. --每日限购
  64. GUI:Text_setString(self.view.txt_purchase_limitation, "今日限购" .. data.limitCount .. "次")
  65. elseif config.limitBuy == 2 then
  66. --每周限购
  67. GUI:Text_setString(self.view.txt_purchase_limitation, "周限购" .. data.limitCount .. "次")
  68. elseif config.limitBuy == 3 then
  69. GUI:Text_setString(self.view.txt_purchase_limitation, "月限购" .. data.limitCount .. "次")
  70. elseif config.limitBuy == 4 then
  71. GUI:Text_setString(self.view.txt_purchase_limitation, "终身限购" .. data.limitCount .. "次")
  72. end
  73. GUI:setGrey(self.view.Bg, config.limitBuy ~= 0 and data.limitCount <= 0)
  74. local coinType = config.price[1]
  75. GUI:Image_loadTexture(self.view.img_money_icon, tostring(coinType), "Atlas/TS_Common.spriteatlas")
  76. --[[ if coinType == 10010001 then
  77. GUI:Image_loadTexture(self.view.img_money_icon, "img_bag_01", "Atlas/UIBagPanel.spriteatlas")
  78. elseif coinType == 10020001 then
  79. GUI:Image_loadTexture(self.view.img_money_icon, "img_bag_02", "Atlas/UIBagPanel.spriteatlas")
  80. elseif coinType == 10030001 then
  81. GUI:Image_loadTexture(self.view.img_money_icon, "img_bag_03", "Atlas/UIBagPanel.spriteatlas")
  82. elseif coinType == 10040001 then
  83. GUI:Image_loadTexture(self.view.img_money_icon, "img_bag_04", "Atlas/UIBagPanel.spriteatlas")
  84. end]]
  85. GUI:Text_setString(self.view.txt_price, tostring(config.price[2]))
  86. --[[ local ownCount = SL:GetBagItemCount(config.price[1])
  87. GUI:Text_setTextColor(self.view.txt_price, ownCount >= config.price[2] and "#DCE1E5" or "#ED2E2E")]]
  88. self:RefreshMoneyColor()
  89. end
  90. function this:RefreshMoneyColor()
  91. if not self.config then
  92. --logError("Not found self.config")
  93. return
  94. end
  95. local ownCount = SL:GetTotalCoinBaseId(self.config.price[1])
  96. if self.config.price[1] == 10050001 then
  97. ownCount = ownCount + SL:GetTotalCoinBaseId(10040001) --加上钻石
  98. end
  99. GUI:Text_setTextColor(self.view.txt_price, ownCount >= self.config.price[2] and "#DCE1E5" or "#ED2E2E")
  100. end
  101. ---注册UI事件和服务器消息
  102. function this:RegistEvents()
  103. GUI:AddOnClickEvent(self.view.ButtonBg, self, self.ButtonBgOnClick)
  104. SL:RegisterLUAEvent(LUA_EVENT_MONEYCHANGE, self.RefreshMoneyColor,self)
  105. end
  106. function this:ButtonBgOnClick()
  107. if self.config.limitBuy ~= 0 and self.data.limitCount <= 0 then
  108. return
  109. end
  110. GUI:UIPanel_Open("dev/ui/ShopMall/Panel/KLShopMallBuyUI/KLShopMallBuyUIPanel", _, _, self.data)
  111. end
  112. function this:Close()
  113. end
  114. ---@param careerConfig cfg_career_column
  115. function this:CareerCheck(careerConfig)
  116. if not careerConfig then
  117. return true
  118. end
  119. local selfCareer = SL:MeData_GetCareer()
  120. ---@type cfg_career_column
  121. local career = self:GetCareerTbl(selfCareer.baseCareer, selfCareer.careerRank)
  122. if careerConfig.baseCareer == career.baseCareer and careerConfig.careerRank <= career.careerRank then
  123. return true
  124. end
  125. return false
  126. end
  127. function this:GetCareerTbl(baseCareer, careerRank)
  128. ---@type cfg_career_column[]
  129. local tbls = SL:GetConfigTable("cfg_career")
  130. for k, v in pairs(tbls) do
  131. if v.baseCareer == baseCareer and v.careerRank == careerRank then
  132. return v
  133. end
  134. end
  135. end
  136. return this