KLRenderPanel.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. ---@class KLRenderPanel:UIKmlLuaPanelBase
  2. ---@field view KLRenderPanelView
  3. local KLRenderPanel = class(UIKmlLuaPanelBase)
  4. local this = KLRenderPanel
  5. ---@type table<EEquipSlotType,CommonProtos.Item>
  6. local grade2Items = {}
  7. ---创建时调用一次
  8. function this:Init()
  9. GUI:DataListInitData(self.view.loopscrollviewData,
  10. function()
  11. return self:ItemCountFunc()
  12. end,
  13. function(realIndex)
  14. return self:ItemGetFunc(realIndex)
  15. end,
  16. function(realIndex, kmlCtrl)
  17. return self:ItemInitFunc(realIndex, kmlCtrl)
  18. end,
  19. function(realIndex, kmlCtrl)
  20. return self:ItemUpdateFunc(realIndex, kmlCtrl)
  21. end,
  22. function(realIndex)
  23. return self:ItemSizeGetFunc(realIndex)
  24. end
  25. )
  26. self.Part_ITEM_H = 80
  27. self.Page_Width = GUI:GetWidth(self.view.loopscrollview)
  28. self.PAGE_EXT_H = 70
  29. end
  30. function this:ItemCountFunc()
  31. return #self.partData
  32. end
  33. function this:ItemGetFunc()
  34. ---@type KLRenderItem
  35. local item = GUI:UIPanel_Open("dev/outui/AppearGroup/Item/KLRender/KLRenderItem", self.view.loopscrollviewData, self, nil, true)
  36. if not self.partItems then
  37. ---@type table<KingML.KmlControl,KLRenderItem>
  38. self.partItems = {}
  39. end
  40. local kmlCtrl = item.view.root
  41. self.partItems[kmlCtrl] = item
  42. return kmlCtrl
  43. end
  44. function this:ItemInitFunc()
  45. end
  46. ---@param realIndex number
  47. ---@param kmlCtrl KingML.KmlControl
  48. function this:ItemUpdateFunc(realIndex, kmlCtrl)
  49. local item = self.partItems[kmlCtrl]
  50. local luaIndex = realIndex + 1
  51. local slot = self.partData[luaIndex]
  52. local titleStr = SL:NumberToChinese(slot) .. "阶卓越套装"
  53. item:SetArgs(grade2Items[slot], titleStr, self.itemY, luaIndex)
  54. item:UpdateUI()
  55. end
  56. ---@param realIndex number
  57. function this:ItemSizeGetFunc(realIndex)
  58. local luaIndex = realIndex + 1
  59. local slot = self.partData[luaIndex]
  60. local equipCount = #grade2Items[slot]
  61. local line = math.ceil(equipCount / 5)
  62. self.itemY = line * self.Part_ITEM_H + self.PAGE_EXT_H
  63. return Vector2(self.Page_Width, self.itemY)
  64. end
  65. ---创建或者刷新界面数据时调用
  66. function this:Refresh()
  67. self:AnalysisEquipData()
  68. GUI:DataListUpdateData(self.view.loopscrollviewData)
  69. end
  70. function this:AnalysisEquipData()
  71. self.partData = {}
  72. grade2Items = {}
  73. ---@type cfg_fashion_column[]
  74. local tbl = SL:GetConfigTable('cfg_fashion')
  75. for _, fashTbl in pairs(tbl) do
  76. if table.contains(fashTbl.type, E_FashionType.Change) then
  77. if not grade2Items[fashTbl.grade] then
  78. grade2Items[fashTbl.grade] = {}
  79. end
  80. table.insert(grade2Items[fashTbl.grade], fashTbl)
  81. if not table.contains(self.partData, fashTbl.grade) then
  82. table.insert(self.partData, fashTbl.grade)
  83. end
  84. end
  85. end
  86. table.sort(self.partData)
  87. end
  88. ---注册UI事件和服务器消息
  89. function this:RegistEvents()
  90. GUI:AddOnClickEvent(self.view.BtnClose, self, self.BtnCloseOnClick)
  91. GUI:AddOnClickEvent(self.view.BtnCancel, self, self.BtnCancelOnClick)
  92. GUI:AddOnClickEvent(self.view.BtnSure, self, self.BtnSureOnClick)
  93. end
  94. function this:BtnSureOnClick()
  95. --[[ local message = {
  96. showTips = "保存设置",
  97. title = "提示",
  98. callback = function()
  99. end
  100. }]]
  101. SL:CommonTipsMessage({ stringTblID = 209,
  102. title = "提示",
  103. callback = function()
  104. end
  105. })
  106. end
  107. function this:BtnCancelOnClick()
  108. return self:BtnCloseOnClick()
  109. end
  110. function this:BtnCloseOnClick()
  111. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLAppear/KLAppearPanel")
  112. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLAppearGroup/KLAppearGroupPanel")
  113. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLAppearPreview/KLAppearPreviewPanel")
  114. end
  115. function this:Close()
  116. end
  117. return this