BaseUIMediator.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. local DebugMediator = requireMediator("DebugMediator")
  2. local BaseUIMediator = class("BaseUIMediator", DebugMediator)
  3. BaseUIMediator.NAME = "BaseUIMediator"
  4. function BaseUIMediator:ctor()
  5. BaseUIMediator.super.ctor(self, self.NAME)
  6. self._type = nil
  7. self._layer = nil
  8. self._voice = true
  9. self._hideMain = false
  10. self._hideLast = false
  11. self._responseMoved = nil
  12. self._resetPostion = nil
  13. self._mouseBtnEvent = true
  14. self._escClose = true
  15. self._GUI_ID = nil
  16. --
  17. self.__savedPosX = 0
  18. self.__savedPosY = 0
  19. end
  20. function BaseUIMediator:OpenLayer()
  21. if not self._type or not self._layer then
  22. print("-------- Error: " .. self.NAME .. " OpenLayer")
  23. return false
  24. end
  25. -- open
  26. local data = {}
  27. data.ltype = self._type
  28. data.layer = self._layer
  29. data.mediator = self
  30. if self._type == global.UIZ.UI_NORMAL and self._adapet then
  31. local viewSize = global.Director:getVisibleSize()
  32. local blackLayout = ccui.Layout:create()
  33. self._layer:addChild(blackLayout, -999)
  34. blackLayout:setContentSize(viewSize)
  35. blackLayout:setBackGroundColor(cc.c3b(0, 0, 0))
  36. blackLayout:setBackGroundColorType(1)
  37. blackLayout:setBackGroundColorOpacity(80)
  38. blackLayout:setTouchEnabled(true)
  39. blackLayout:addClickEventListener(function()
  40. self:CloseLayer()
  41. end)
  42. if SL:GetMetaValue("WINPLAYMODE") then
  43. global.mouseEventController:registerMouseMoveEvent(blackLayout)
  44. end
  45. end
  46. global.Facade:sendNotification(global.NoticeTable.Layer_Open, data)
  47. refPositionByParent(self._layer)
  48. if SL:GetMetaValue("WINPLAYMODE") then
  49. hideMouseOverTips()
  50. global.Facade:sendNotification(global.NoticeTable.RefreshRecoverEditBox)
  51. end
  52. self._moveWidget = nil
  53. -- event move
  54. if self._responseMoved then
  55. self:setLayerMoveEnable(self._responseMoved)
  56. end
  57. end
  58. function BaseUIMediator:CloseLayer()
  59. if not self._type or not self._layer then
  60. return false
  61. end
  62. local data = {}
  63. data.ltype = self._type
  64. data.layer = self._layer
  65. data.mediator = self
  66. SLBridge:onLUAEvent(LUA_EVENT_CLOSEWIN, self._GUI_ID)
  67. global.Facade:sendNotification(global.NoticeTable.Layer_Close, data)
  68. self._layer = nil
  69. self._type = nil
  70. end
  71. function BaseUIMediator:handlePressedEnter()
  72. return false
  73. end
  74. function BaseUIMediator:SetLocalZOrder(zOrder)
  75. if not self._type or not self._layer then
  76. return false
  77. end
  78. self._layer:setLocalZOrder(zOrder)
  79. end
  80. function BaseUIMediator:getResetPosition()
  81. if self._resetPostion then
  82. if type(self._resetPostion) == "table" then
  83. return cc.p(self._resetPostion.x, self._resetPostion.y)
  84. end
  85. return cc.p(0, 0)
  86. end
  87. return cc.p(self.__savedPosX, self.__savedPosY)
  88. end
  89. function BaseUIMediator:setSavedPosition(px, py)
  90. self.__savedPosX = px
  91. self.__savedPosY = py
  92. end
  93. function BaseUIMediator:setLayerMoveEnable(moveWidget, status)
  94. if not self._type or not self._layer then
  95. return false
  96. end
  97. if not moveWidget then
  98. return false
  99. end
  100. local data = {}
  101. data.ltype = self._type
  102. data.layer = self._layer
  103. data.mediator = self
  104. data.moveWidget = moveWidget
  105. data.isMove = true
  106. if type(status) == "boolean" then
  107. data.isMove = status
  108. end
  109. global.Facade:sendNotification(global.NoticeTable.Layer_SetMoveEnable, data)
  110. end
  111. function BaseUIMediator:setHideMainUI(hide)
  112. if type(hide) ~= "boolean" then
  113. return false
  114. end
  115. if self._hideMain == hide then
  116. return false
  117. end
  118. self._hideMain = hide
  119. global.Facade:sendNotification(global.NoticeTable.Layer_HideMainEvent, self)
  120. end
  121. function BaseUIMediator:setLayerZPanel(panel)
  122. if not self._type or not self._layer then
  123. return false
  124. end
  125. if not panel then
  126. return false
  127. end
  128. local data = {}
  129. data.mediator = self
  130. data.zPanel = panel
  131. global.Facade:sendNotification(global.NoticeTable.Layer_SetZOrderPanel, data)
  132. end
  133. return BaseUIMediator