KLTradeGoodsItem.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. ---@class KLTradeGoodsItem:UIKmlLuaPanelBase
  2. ---@field view KLTradeGoodsItemView
  3. local KLTradeGoodsItem = class(UIKmlLuaPanelBase)
  4. local this = KLTradeGoodsItem
  5. ---创建时调用一次
  6. function this:Init()
  7. end
  8. ---注册UI事件和服务器消息
  9. function this:RegistEvents()
  10. GUI:AddOnClickEvent(self.view.btn_goods_item, self, self.ItemOnClick)
  11. end
  12. function this:ItemOnClick()
  13. if self.clickFun then
  14. self.clickFun(self.buyUI, self)
  15. return
  16. end
  17. --SL:OpenTips(nil,self.itemData.itemcfgid)
  18. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_TRADE_GOODS_INFO, { self.itemData.itemid, self.itemData.ownid })
  19. GUI:UIPanel_Open("dev/outui/Trade/Panel/KLTradeBuy/KLTradeBuyPanel", nil, nil, self.itemData)
  20. end
  21. ---创建或者刷新界面数据时调用
  22. function this:Refresh()
  23. end
  24. ---@class KLTradeGoodsItemData
  25. ---@field timename string
  26. ---@field itemname string
  27. ---@field count number
  28. ---@field price number
  29. ---@field itemcfgid number
  30. ---@field cointype number
  31. ---@field time number
  32. ---@field preordercount number @预订数量
  33. ---@field publicity string 公示区时为1
  34. ---@field itemid number
  35. ---@field type number
  36. ---@field entrysize number 词条数量
  37. ---@param itemData KLTradeGoodsItemData
  38. function this:UpdateData(itemData)
  39. self.itemData = itemData
  40. GUI:SetOnPrefabControlLoaded(self.view.scroll_text_template, function()
  41. GUI:Text_setString(self.view.txt_item_name, itemData.itemname)
  42. end)
  43. GUI:Item_setItemId(self.view.item, itemData.itemcfgid)
  44. if itemData.itemcfgid == EMonthType.MonthCardTime then
  45. GUI:Item_UpdataData(self.view.item, { itemcount = 1 })
  46. GUI:SetActive(self.view.monthCardText, true)
  47. GUI:Text_setString(self.view.monthCardText, itemData.count .. "天")
  48. else
  49. GUI:SetActive(self.view.monthCardText, false)
  50. GUI:Item_UpdataData(self.view.item, { itemcount = itemData.count })
  51. end
  52. --GUI:Image_loadTexture(self.view.img_coin_type,self:GetCoinIcon(tonumber(itemData.cointype)),"Atlas/UIBagPanel.spriteatlas")
  53. local totalPrice = itemData.totalprice
  54. local ownCount = 0
  55. local unit = ""
  56. if itemData.cointype == "30030305" then
  57. ownCount = InfoManager.monthCardInfo:GetMonthCardDayTime()
  58. unit = "天"
  59. else
  60. ownCount = SL:GetBagItemCount(tonumber(itemData.cointype))
  61. end
  62. GUI:Text_setTextColor(self.view.txt_price, ownCount >= totalPrice and "#1ADD1F" or "#FF2323")
  63. GUI:Text_setString(self.view.txt_price, tostring(totalPrice) .. unit)
  64. GUI:Image_loadTexture(self.view.img_coin_type, tostring(itemData.cointype), "Atlas/UIBagPanel.spriteatlas")
  65. --GUI:Text_setString(self.view.txt_price, tostring(totalPrice))
  66. if itemData.publicity == 1 then
  67. GUI:SetActive(self.view.img_favor_count, true)
  68. local peroreder = table.count(itemData.peroreder)
  69. if peroreder >= 1 then
  70. GUI:Image_loadTexture(self.view.img_favor_count, "ty_ico_star", "Atlas/TS_Common.spriteatlas")
  71. GUI:Text_setString(self.view.txt_favor_count, tostring(peroreder))
  72. else
  73. GUI:Image_loadTexture(self.view.img_favor_count, "ty_ico_star_bg", "Atlas/TS_Common.spriteatlas")
  74. GUI:Text_setString(self.view.txt_favor_count, "")
  75. end
  76. else
  77. GUI:SetActive(self.view.img_favor_count, false)
  78. end
  79. local roleId = SL:GetMetaValue(EMetaVarGetKey.UID)
  80. if tostring(roleId) == itemData.ownid then
  81. GUI:setVisible(self.view.icon_career, true)
  82. local job = SL:GetMetaValue(EMetaVarGetKey.JOB)
  83. GUI:Image_loadTexture(self.view.icon_career, "1" .. tostring(job), "Atlas/MUIcon.spriteatlas")
  84. else
  85. GUI:setVisible(self.view.icon_career, false)
  86. end
  87. self:Tick()
  88. self:ShowQualityUI()
  89. self:UpdateBuyClickFun(nil, nil)
  90. end
  91. function this:UpdateBuyClickFun(clickFun, ui)
  92. self.clickFun = clickFun
  93. self.buyUI = ui
  94. end
  95. function this:ShowQualityUI()
  96. if self.qualityItem then
  97. self.qualityItem:SetData(self.itemData.itemcfgid, self.itemData.entrysize)
  98. else
  99. GUI:UIPanel_Open("dev/ui/Common/Item/KLEquipQualityEntry/KLEquipQualityEntryItem",
  100. self.view.root, self, { cfgId = self.itemData.itemcfgid, entryCount = self.itemData.entrysize }, true,
  101. function(qualityItem)
  102. self.qualityItem = qualityItem
  103. end)
  104. end
  105. end
  106. --[[
  107. function this:GetCoinIcon(coinType)
  108. if coinType == 10010001 then
  109. return "img_bag_01"
  110. elseif coinType == 10020001 then
  111. return "img_bag_02"
  112. elseif coinType == 10030001 then
  113. return "img_bag_03"
  114. elseif coinType == 10040001 then
  115. return "img_bag_04"
  116. end
  117. end
  118. ]]
  119. function this:Close()
  120. if self.qualityItem then
  121. GUI:UIPanel_Close(nil, self.qualityItem)
  122. self.qualityItem = nil
  123. end
  124. end
  125. function this:Tick()
  126. if not self.itemData or not self.itemData.time then
  127. return false
  128. end
  129. self.itemData.time = self.itemData.time - 1
  130. if self.itemData.time <= 0 then
  131. GUI:Text_setString(self.view.txt_count_down, "")
  132. return true
  133. else
  134. if self.itemData.time <= 3 * 60 * 60 or self.itemData.publicity == "1" then
  135. local timeInfo = SL:SecondToHMS(math.floor(self.itemData.time))
  136. local timeStr = string.format("%02s:%02s:%02s", timeInfo.h, timeInfo.m, timeInfo.s)
  137. GUI:Text_setString(self.view.txt_count_down, self.itemData.timename .. " " .. timeStr)
  138. else
  139. GUI:Text_setString(self.view.txt_count_down, "")
  140. end
  141. end
  142. end
  143. return this