KLAppearPartItem.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. ---@class KLAppearPartItem:UIKmlLuaPanelBase
  2. ---@field view KLAppearPartItemView
  3. ---@field baseUI KLAppearPanel
  4. ---@field curEquipItem KLAppearEquipItem
  5. ---@field curCfgId number
  6. local KLAppearPartItem = class(UIKmlLuaPanelBase)
  7. local this = KLAppearPartItem
  8. ---创建时调用一次
  9. function this:Init()
  10. GUI:DataListInitData(self.view.datalist11,
  11. function()
  12. return self:ItemCountFunc()
  13. end,
  14. function(realIndex)
  15. return self:ItemGetFunc(realIndex)
  16. end,
  17. function(realIndex, kmlCtrl)
  18. return self:ItemInitFunc(realIndex, kmlCtrl)
  19. end,
  20. function(realIndex, kmlCtrl)
  21. return self:ItemUpdateFunc(realIndex, kmlCtrl)
  22. end)
  23. ---@type table<KingML.KmlControl,KLAppearEquipItem>
  24. self.equipItems = {}
  25. end
  26. function this:ItemCountFunc()
  27. return #self.equips
  28. end
  29. function this:ItemGetFunc()
  30. ---@type KLAppearEquipItem
  31. local item = GUI:UIPanel_Open("dev/outui/AppearGroup/Item/KLAppearEquip/KLAppearEquipItem", self.view.datalist11, self, nil, true)
  32. local kmlCtrl = item.view.root
  33. self.equipItems[kmlCtrl] = item
  34. return kmlCtrl
  35. end
  36. function this:ItemInitFunc()
  37. end
  38. ---@param kmlCtrl KingML.KmlControl
  39. function this:ItemUpdateFunc(realIndex, kmlCtrl)
  40. local item = self.equipItems[kmlCtrl]
  41. local luaIndex = realIndex + 1
  42. local dt = self.equips[luaIndex]
  43. local cfgId
  44. if self.slot == E_AppearEquipType.Guard and not dt.cfgId then
  45. cfgId = tonumber(dt.itemId)
  46. else
  47. cfgId = dt.cfgId
  48. end
  49. local tmpCfgId
  50. for _, part in pairs(E_AppearType2StrPart[self.slot]) do
  51. if self.appearCfgIds[part] then
  52. tmpCfgId = self.appearCfgIds[part]
  53. break
  54. end
  55. end
  56. local isSelect = tmpCfgId and tmpCfgId == cfgId
  57. item:UpdateUI(dt, isSelect)
  58. end
  59. ---@param equipItem KLAppearEquipItem
  60. function this:BtnEquipOnSelect(equipItem, cfgId)
  61. if self.curEquipItem then
  62. self.curEquipItem:SetState(false)
  63. end
  64. local oldId = self.curCfgId
  65. if self.curEquipItem and self.curCfgId == cfgId then
  66. self.curCfgId = nil
  67. self.curEquipItem = nil
  68. else
  69. self.curEquipItem = equipItem
  70. self.curCfgId = cfgId
  71. equipItem:SetState(true)
  72. end
  73. return self.baseUI:OnEquipItemSelect(oldId, cfgId, self.slot)
  74. end
  75. ---@param appearCfgIds table<EEquipSlotType,number>
  76. ---@param equips CommonProtos.Item[]
  77. function this:UpdateUI(appearCfgIds, equips, slot, itemY, luaIndex)
  78. self.appearCfgIds = appearCfgIds
  79. self.equips = equips
  80. self.slot = slot
  81. self.title = E_AppearTypeStr[slot]
  82. self.itemY = itemY
  83. self.luaIndex = luaIndex
  84. self.curCfgId = nil
  85. GUI:Text_setString(self.view.Title, self.title)
  86. local w = GUI:GetWidth(self.view.root)
  87. GUI:setContentSize(self.view.root, w, self.itemY)
  88. GUI:DataListUpdateData(self.view.datalist11)
  89. end
  90. ---创建或者刷新界面数据时调用
  91. function this:Refresh()
  92. end
  93. ---注册UI事件和服务器消息
  94. function this:RegistEvents()
  95. end
  96. function this:Close()
  97. end
  98. return this