KLAppearEquipItem.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ---@class KLAppearEquipItem:UIKmlLuaPanelBase
  2. ---@field view KLAppearEquipItemView
  3. ---@field baseUI KLAppearPartItem
  4. local KLAppearEquipItem = class(UIKmlLuaPanelBase)
  5. local this = KLAppearEquipItem
  6. ---创建时调用一次
  7. function this:Init()
  8. self.equipAttItems = {}
  9. self.lastClick = 0
  10. end
  11. ---创建或者刷新界面数据时调用
  12. function this:Refresh()
  13. end
  14. ---@param item CommonProtos.Item
  15. function this:UpdateUI(item, isSelect)
  16. self.cfgId = item.cfgId or tonumber(item.itemId)
  17. GUI:Item_setItemId(self.view.EquipItem, tostring(self.cfgId))
  18. GUI:setVisible(self.view.img_quality, false)
  19. GUI:setVisible(self.view.strengthLevel, false)
  20. GUI:setVisible(self.view.appendLevel, false)
  21. if item.cfgId then
  22. --装备品阶
  23. if SL:HasConfig('cfg_equip_entryLib', self.cfgId) then
  24. ---@type cfg_equip_entryLib_column
  25. local entryLib = SL:GetConfig('cfg_equip_entryLib', self.cfgId)
  26. local qualityTbl = SL:GetConfigTable("cfg_equip_quality")
  27. ---@param v cfg_equip_quality_column
  28. for _, v in pairs(qualityTbl) do
  29. if not string.isNullOrEmpty(v.logo) and entryLib.initialRating >= v.stage[1] and entryLib.initialRating <= v.stage[2] then
  30. GUI:setVisible(self.view.img_quality, true)
  31. GUI:Image_loadTexture(self.view.img_quality, v.logo, "Atlas/AppearGroup.spriteatlas")
  32. break
  33. end
  34. end
  35. end
  36. ---@type cfg_item_column
  37. local itemCfg = SL:GetConfig("cfg_item", self.cfgId)
  38. --卓越词条数量
  39. local pos = itemCfg.strPart[1]
  40. if pos and pos >= EEquipSlotType.Weapon and pos <= EEquipSlotType.Boot then
  41. local entryAttr = SL:GetEquipEntrys(item)
  42. local count = entryAttr and table.count(entryAttr) or 0
  43. self:ClearEquipAttrItems()
  44. for i = 1, count do
  45. local attItem = GUI:UIPanel_Open("dev/ui/Equip/Item/KLCommonImage/KLCommonImageItem", self.view.img_quality, self, {
  46. sprite = "img_equipAtt", altas = "Atlas/UIBagPanel.spriteatlas"
  47. }, true)
  48. table.insert(self.equipAttItems, attItem)
  49. attItem:SetSize(20, 20)
  50. attItem:SetPosition(-2, -18 - (i - 1) * 8)
  51. end
  52. end
  53. --强化等级
  54. local strengthLevel = EquipFunc.GetEquipStrengthLevel(item)
  55. GUI:setVisible(self.view.strengthLevel, true)
  56. GUI:Text_setString(self.view.strengthLevel, strengthLevel ~= 0 and ("+" .. strengthLevel) or "")
  57. --追加等级
  58. local appendLv = EquipFunc.GetEquipAppendLevel(item)
  59. GUI:setVisible(self.view.appendLevel, true)
  60. GUI:Text_setString(self.view.appendLevel, appendLv ~= 0 and ("+" .. appendLv) or "")
  61. end
  62. if isSelect then
  63. self:BtnEquipOnSelect()
  64. else
  65. self:SetState(false)
  66. end
  67. end
  68. ---注册UI事件和服务器消息
  69. function this:RegistEvents()
  70. GUI:AddOnClickEvent(self.view.BtnEquip, self, self.BtnEquipOnSelect)
  71. SL:RegisterLUAEvent(APPEAR_SELECT_ITEM, self.OnCheckItemSelect, self)
  72. end
  73. ---@param cfgId number
  74. function this:OnCheckItemSelect(_, cfgId)
  75. if not cfgId or cfgId ~= self.cfgId then return end
  76. self:BtnEquipOnSelect()
  77. end
  78. function this:BtnEquipOnSelect()
  79. if Time.frameCount - self.lastClick < 3 then
  80. return
  81. end
  82. self.lastClick = Time.frameCount
  83. return self.baseUI:BtnEquipOnSelect(self, self.cfgId)
  84. end
  85. function this:SetState(isSelect)
  86. return GUI:SetActive(self.view.SpState, isSelect)
  87. end
  88. function this:Close()
  89. end
  90. function this:ClearEquipAttrItems()
  91. for _, v in pairs(self.equipAttItems) do
  92. GUI:UIPanel_Close("dev/ui/Equip/Item/KLCommonImage/KLCommonImageItem", v)
  93. end
  94. table.clear(self.equipAttItems)
  95. end
  96. return this