UIFuncMenuCtr.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. local UIFuncMenuCtr = class("UIFuncMenuCtr", require("UICtrBase"))
  2. function UIFuncMenuCtr:Init(view)
  3. self.view = view
  4. end
  5. ---@param data table {menus = {{[1] = langKey, [2] = params, [3] = notClick}}, cb = func, cancelCb = nil, ownerCB = table|nil, alignPos = Vector3, alignment = Enum.Alignment, vaildMin = Vector3, vaildMax = Vector3}
  6. --- menus为功能按钮列表 langKey语言表key, params为点击了回调函数中的数据,notClick为是否不可点击
  7. --- cb函数(可为匿名函数),cancelCb函数(可为匿名函数),ownerCB为函数的拥有者,匿名函数时,则为空
  8. --- alignPos 对齐坐标点(世界坐标点),为空则默认为屏幕中间
  9. --- alignment 对齐方向,为空则默认为居中对齐
  10. --- vaildMin, vaildMax 有效区域 (世界坐标点), 为空则默认为屏幕安全区域
  11. function UIFuncMenuCtr:SetData(data)
  12. self.asyncIdx = 0
  13. if data == nil then return end
  14. self.data = data
  15. end
  16. function UIFuncMenuCtr:GetAsyncIdx()
  17. self.asyncIdx = self.asyncIdx + 1
  18. return self.asyncIdx
  19. end
  20. function UIFuncMenuCtr:GetData()
  21. return self.data
  22. end
  23. function UIFuncMenuCtr:OnDispose()
  24. self.data = nil
  25. self.view = nil
  26. end
  27. function UIFuncMenuCtr:GetMenus()
  28. if self.data and self.data.menus and #self.data.menus > 0 then
  29. return self.data.menus
  30. end
  31. return {{'Null'}}
  32. end
  33. function UIFuncMenuCtr:GetAlignPos()
  34. if self.data and self.data.alignPos then
  35. return self.data.alignPos
  36. end
  37. return nil
  38. end
  39. function UIFuncMenuCtr:GetAlignment()
  40. if self.data and self.data.alignment then
  41. return self.data.alignment
  42. end
  43. return Enum.Alignment.None
  44. end
  45. function UIFuncMenuCtr:GetVaildMin()
  46. if self.data and self.data.vaildMin then
  47. return self.data.vaildMin
  48. end
  49. return nil
  50. end
  51. function UIFuncMenuCtr:GetVaildMax()
  52. if self.data and self.data.vaildMax then
  53. return self.data.vaildMax
  54. end
  55. return nil
  56. end
  57. function UIFuncMenuCtr:ExecuteCancelCallBack()
  58. if not self.data then return end
  59. local cancelCb = self.data.cancelCb
  60. if cancelCb then
  61. local ownerCB = self.data.ownerCB
  62. if ownerCB then
  63. cancelCb(ownerCB)
  64. else
  65. cancelCb()
  66. end
  67. end
  68. end
  69. function UIFuncMenuCtr:ExecuteCallBack(idx)
  70. if not self.data then return end
  71. if not self.data.menus then return end
  72. local menu = self.data.menus[idx]
  73. if not menu then return end
  74. if menu[3] then return end
  75. local cb = self.data.cb
  76. if cb then
  77. local ownerCB = self.data.ownerCB
  78. if ownerCB then
  79. cb(ownerCB, menu[2])
  80. else
  81. cb(menu[2])
  82. end
  83. end
  84. end
  85. return UIFuncMenuCtr