KLSelectCountPanel.lua 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ---@class KLSelectCountPanel:UIKmlLuaPanelBase
  2. ---@field view KLSelectCountPanelView
  3. ---@class SelectData 需要传入的参数
  4. ---@field callbackUI UIKmlLuaPanelBase 打开该面板的UI
  5. ---@field sure function 确认按钮回调,两个number类型参数(唯一id,数量)
  6. ---@field itemid number item配置表id
  7. ---@field max number 最大数量,缺省则无数量上限
  8. ---@field id number 唯一id
  9. local KLSelectCountPanel = class(UIKmlLuaPanelBase)
  10. local this = KLSelectCountPanel
  11. function this:AsyncLoadUI()
  12. end
  13. ---创建时调用一次
  14. function this:Init()
  15. end
  16. ---注册UI事件和服务器消息
  17. function this:RegistEvents()
  18. GUI:AddOnClickEvent(self.view.Select_Mask, self, self.Cancel)
  19. GUI:AddOnClickEvent(self.view.BtnSure, self, self.Sure)
  20. GUI:AddOnClickEvent(self.view.BtnCancel, self, self.Cancel)
  21. GUI:AddOnClickEvent(self.view.showitem, self, self.OpenTips)
  22. GUI:AddOnClickEvent(self.view.subtract, self, function()
  23. self:AddAndSubtract(-1)
  24. end)
  25. GUI:AddOnClickEvent(self.view.add, self, function()
  26. self:AddAndSubtract(1)
  27. end)
  28. GUI:Input_SetOnEndEdit(self.view.Count, self, self.Input)
  29. end
  30. function this:AddAndSubtract(index)
  31. local count = tonumber(GUI:Text_getString(self.view.Count))
  32. self:Input(_, count + index)
  33. end
  34. function this:Input(_, inputCount)
  35. local count
  36. if inputCount then
  37. count = tonumber(inputCount)
  38. else
  39. count = tonumber(GUI:Text_getString(self.view.Count))
  40. end
  41. if count <= 0 then
  42. if self.args.max and self.args.max > 0 then
  43. count = self.args.max
  44. else
  45. count = 1
  46. end
  47. end
  48. if self.args.max and self.args.max > 0 and count > self.args.max then
  49. count = self.args.max
  50. end
  51. GUI:Text_setString(self.view.Count, tostring(count))
  52. end
  53. function this:Sure()
  54. local sure = self.args.sure
  55. local count = tonumber(GUI:Text_getString(self.view.Count))
  56. if self.args.callbackUI and sure then
  57. sure(self.args.callbackUI, self.args.id, count)
  58. end
  59. GUI:UIPanel_Close("dev/outui/SelectCount/Panel/KLSelectCount/KLSelectCountPanel")
  60. end
  61. function this:Cancel()
  62. GUI:UIPanel_Close("dev/outui/SelectCount/Panel/KLSelectCount/KLSelectCountPanel")
  63. end
  64. function this:OpenTips()
  65. SL:OpenTips(_, self.args.itemid, self.args.id)
  66. end
  67. ---界面显示时调用一次
  68. function this:Show()
  69. end
  70. ---创建或者刷新界面数据时调用
  71. function this:Refresh()
  72. GUI:Item_setItemId(self.view.showitem, self.args.itemid)
  73. end
  74. function this:Close()
  75. end
  76. return this