KLSelfSelectBoxItem.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ---@class KLSelfSelectBoxItem:UIKmlLuaPanelBase
  2. ---@field view KLSelfSelectBoxItemView
  3. local KLSelfSelectBoxItem = class(UIKmlLuaPanelBase)
  4. local this = KLSelfSelectBoxItem
  5. ---创建时调用一次
  6. function this:Init()
  7. end
  8. ---创建或者刷新界面数据时调用
  9. function this:Refresh()
  10. end
  11. function this:InitData(arg, panel, count)
  12. --self.go:SetActive(true)
  13. self.awradItem = SL:GetConfig("cfg_item", arg)
  14. self.parentPanel = panel
  15. self.SelectCount = 0
  16. GUI:Text_setString(self.view.numbertext, tostring(self.SelectCount))
  17. self:ShowModel(arg, count)
  18. end
  19. ---注册UI事件和服务器消息
  20. function this:RegistEvents()
  21. GUI:AddOnClickEvent(self.view.addbtn, self, self.addbtnOnClick)
  22. GUI:AddOnClickEvent(self.view.decbtn, self, self.decbtnOnClick)
  23. GUI:AddOnClickEvent(self.view.itemicon, self, self.ItemOnClick)
  24. GUI:Input_SetOnEndEdit(self.view.numbertext, self, self.InputChange)
  25. end
  26. function this:decbtnOnClick()
  27. if self.SelectCount > 0 then
  28. self.SelectCount = self.SelectCount - 1
  29. GUI:Text_setString(self.view.numbertext, tostring(self.SelectCount))
  30. self.parentPanel:SetItemCount(self.awradItem.id, -1)
  31. end
  32. end
  33. function this:addbtnOnClick()
  34. if self.parentPanel.curCount < self.parentPanel.totleCount then
  35. self.SelectCount = self.SelectCount + 1
  36. GUI:Text_setString(self.view.numbertext, tostring(self.SelectCount))
  37. self.parentPanel:SetItemCount(self.awradItem.id, 1)
  38. else
  39. SL:TipMessage(SL:GetConfig('cfg_string', 323).text, 1, NoticeType.NoticeMid )--"已达到可选择上限",
  40. end
  41. end
  42. function this:InputChange()
  43. local text = GUI:Text_getString(self.view.numbertext)
  44. if not tonumber(text) then
  45. text = self.SelectCount
  46. end
  47. local inputValue = tonumber(text)
  48. local curCount = self.parentPanel.curCount - self.SelectCount
  49. if curCount < self.parentPanel.totleCount then
  50. local count = self.parentPanel.totleCount - curCount
  51. if inputValue > count then
  52. inputValue = count
  53. elseif inputValue < 0 then
  54. inputValue = 0
  55. end
  56. self.SelectCount = inputValue
  57. GUI:Text_setString(self.view.numbertext, tostring(inputValue))
  58. self.parentPanel:InputItemCount(self.awradItem.id, inputValue)
  59. else
  60. GUI:Text_setString(self.view.numbertext, 0)
  61. self.parentPanel:InputItemCount(self.awradItem.id, 0)
  62. end
  63. end
  64. function this:Close()
  65. end
  66. function this:ItemOnClick()
  67. SL:OpenTips("", self.awradItem.id)
  68. end
  69. function this:ShowModel(id, count)
  70. GUI:Item_UpdataData(self.view.itemicon, {
  71. itemid = id,
  72. itemcount = count
  73. })
  74. GUI:Item_setItemId(self.view.itemicon, id)
  75. --if self.itemModel then
  76. -- GUI:Item_UpdataData(self.itemModel, {
  77. -- itemid = id,
  78. -- })
  79. --end
  80. --self.itemModel = GUI:Item_Create(self.view.itemicon, {
  81. -- width = "45",
  82. -- height = "45",
  83. -- itemid = id,
  84. -- noclip = "1",
  85. -- mfixsize = "100,100",
  86. -- bgtype = "0",
  87. -- count = 0,
  88. --})
  89. end
  90. return this