KLAppearCostPanel.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ---@class KLAppearCostPanel:UIKmlLuaPanelBase
  2. ---@field view KLAppearCostPanelView
  3. local KLAppearCostPanel = class(UIKmlLuaPanelBase)
  4. local this = KLAppearCostPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. GUI:DataListInitData(self.view.datalist1,
  8. function()
  9. return self:ItemCountFunc()
  10. end,
  11. function(realIndex)
  12. return self:ItemGetFunc(realIndex)
  13. end,
  14. function(realIndex, kmlCtrl)
  15. return self:ItemInitFunc(realIndex, kmlCtrl)
  16. end,
  17. function(realIndex, kmlCtrl)
  18. return self:ItemUpdateFunc(realIndex, kmlCtrl)
  19. end)
  20. ---@type {cfgId:number,count:number}[]
  21. self.costItems = {}
  22. end
  23. function this:ItemCountFunc()
  24. return #self.costItems
  25. end
  26. function this:ItemGetFunc()
  27. end
  28. function this:ItemInitFunc()
  29. end
  30. function this:ItemUpdateFunc(realIndex)
  31. local bagItem = GUI:GetChildControl(self.view.datalist1, realIndex, 'Item')
  32. local luaIndex = realIndex + 1
  33. local dt = self.costItems[luaIndex]
  34. GUI:Item_setItemId(bagItem, dt.cfgId)
  35. GUI:AddOnClickEvent(bagItem, self, self.OnCostItemOnClick, dt.cfgId)
  36. local txtCount = GUI:GetChildControl(self.view.datalist1, realIndex, 'TxtCount')
  37. local ownCount = SL:GetBagItemCount(dt.cfgId)
  38. GUI:Text_setString(txtCount, tostring(dt.count))
  39. local colorStr = ownCount >= dt.count and "#ffffff" or "#ff0000"
  40. GUI:Text_setTextColor(txtCount, colorStr)
  41. end
  42. function this:OnCostItemOnClick(_, cfgId)
  43. return SL:OpenTips(nil, cfgId)
  44. end
  45. ---创建或者刷新界面数据时调用
  46. function this:Refresh()
  47. self.selectCfgIds = self.args
  48. self:AnalysisData()
  49. GUI:DataListUpdateData(self.view.datalist1)
  50. end
  51. function this:AnalysisData()
  52. table.clear(self.costItems)
  53. local id2Count = {}
  54. for _, cfgId in pairs(self.selectCfgIds) do
  55. ---@type cfg_fashion_column
  56. local fashionTbl = SL:GetConfig("cfg_fashion", cfgId)
  57. for _, v in pairs(fashionTbl.deplete) do
  58. local itemId = v[1]
  59. local count = v[2]
  60. if not id2Count[itemId] then
  61. id2Count[itemId] = count or 0
  62. else
  63. id2Count[itemId] = id2Count[itemId] + count
  64. end
  65. end
  66. end
  67. for id, count in pairs(id2Count) do
  68. table.insert(self.costItems, { cfgId = id, count = count })
  69. end
  70. end
  71. ---注册UI事件和服务器消息
  72. function this:RegistEvents()
  73. GUI:AddOnClickEvent(self.view.BtnClose, self, self.BtnCloseOnClick)
  74. GUI:AddOnClickEvent(self.view.BtnActive, self, self.BtnActiveOnClick)
  75. end
  76. function this:CanActive()
  77. for _, v in pairs(self.costItems) do
  78. local ownCount = SL:GetBagItemCount(v.cfgId)
  79. if ownCount < v.count then
  80. return false
  81. end
  82. end
  83. return true
  84. end
  85. function this:BtnActiveOnClick()
  86. if not self:CanActive() then
  87. SL:TipMessage(SL:GetConfig('cfg_string', 253).text, 1, NoticeType.NoticeMid)-- "所需道具数量不足",
  88. return
  89. end
  90. SL:SendLuaNetMsg(LuaMessageIdToSever.EQUIP_FASHION, { cfgIds = self.selectCfgIds })
  91. self:BtnCloseOnClick()
  92. end
  93. function this:BtnCloseOnClick()
  94. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLAppearCost/KLAppearCostPanel")
  95. end
  96. function this:Close()
  97. end
  98. return this