MainRootLayer.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. local BaseLayer = requireLayerUI("BaseLayer")
  2. local MainRootLayer = class("MainRootLayer", BaseLayer)
  3. function MainRootLayer:ctor()
  4. MainRootLayer.super.ctor(self)
  5. end
  6. function MainRootLayer.create()
  7. local layer = MainRootLayer.new()
  8. if layer:Init() then
  9. return layer
  10. end
  11. return nil
  12. end
  13. function MainRootLayer:Init()
  14. self._root = requireExport("main/main_root.lua").create().root
  15. if not self._root then
  16. return false
  17. end
  18. self:addChild(self._root)
  19. self:InitNodes()
  20. self:InitGUI()
  21. self:UpdateAdapet()
  22. return true
  23. end
  24. function MainRootLayer:InitNodes()
  25. self._nodes = {}
  26. -- adapet
  27. self._layoutAdapet = self._root:getChildByName("Panel_adapet")
  28. self._layoutAdapet:setClippingType(0)
  29. self._nodes[global.MMO.MAIN_NODE_LT] = self._layoutAdapet:getChildByName("Node_lt")
  30. self._nodes[global.MMO.MAIN_NODE_MT] = self._layoutAdapet:getChildByName("Node_mt")
  31. self._nodes[global.MMO.MAIN_NODE_RT] = self._layoutAdapet:getChildByName("Node_rt")
  32. self._nodes[global.MMO.MAIN_NODE_LB] = self._layoutAdapet:getChildByName("Node_lb")
  33. self._nodes[global.MMO.MAIN_NODE_MB] = self._layoutAdapet:getChildByName("Node_mb")
  34. self._nodes[global.MMO.MAIN_NODE_RB] = self._layoutAdapet:getChildByName("Node_rb")
  35. -- extra
  36. self._layoutExtra = self._root:getChildByName("Panel_extra")
  37. self._layoutExtra:setClippingType(0)
  38. self._nodes[global.MMO.MAIN_NODE_EXTRA_LT] = self._layoutExtra:getChildByName("Node_lt")
  39. self._nodes[global.MMO.MAIN_NODE_EXTRA_RT] = self._layoutExtra:getChildByName("Node_rt")
  40. self._nodes[global.MMO.MAIN_NODE_EXTRA_LB] = self._layoutExtra:getChildByName("Node_lb")
  41. self._nodes[global.MMO.MAIN_NODE_EXTRA_MT] = self._layoutExtra:getChildByName("Node_mt")
  42. -- chat
  43. self._layoutChat = self._root:getChildByName("Panel_chat")
  44. self._layoutChat:setClippingType(0)
  45. self._nodes[global.MMO.MAIN_NODE_CHAT_MAIN] = self._layoutChat:getChildByName("Node_chat_main")
  46. self._nodes[global.MMO.MAIN_NODE_CHAT_MINI] = self._layoutChat:getChildByName("Node_chat_mini")
  47. -- sui
  48. self._layoutSUI = self._root:getChildByName("Panel_sui")
  49. self._nodeSUIBM = self._root:getChildByName("Node_sui_bm")
  50. self._layoutExtra:setClippingType(0)
  51. self._nodes[global.MMO.MAIN_NODE_SUI_LT] = self._layoutSUI:getChildByName("Node_lt")--左上角1
  52. self._nodes[global.MMO.MAIN_NODE_SUI_RT] = self._layoutSUI:getChildByName("Node_rt")--右上角3
  53. self._nodes[global.MMO.MAIN_NODE_SUI_LB] = self._layoutSUI:getChildByName("Node_lb")--左下角7
  54. self._nodes[global.MMO.MAIN_NODE_SUI_RB] = self._layoutSUI:getChildByName("Node_rb")--右下角9
  55. self._nodes[global.MMO.MAIN_NODE_SUI_LM] = self._layoutSUI:getChildByName("Node_lm")--左中4
  56. self._nodes[global.MMO.MAIN_NODE_SUI_TM] = self._layoutSUI:getChildByName("Node_tm")--上中2
  57. self._nodes[global.MMO.MAIN_NODE_SUI_RM] = self._layoutSUI:getChildByName("Node_rm")--右中6
  58. self._nodes[global.MMO.MAIN_NODE_SUI_BM] = self._nodeSUIBM --下中8
  59. self._nodes[global.MMO.MAIN_NODE_SUI_MM] = self._layoutSUI:getChildByName("Node_mm")--中中5
  60. self._layoutTop = self._root:getChildByName("Panel_top")
  61. self._layoutTop:setClippingType(0)
  62. self._nodes[global.MMO.MAIN_NODE_TOP_LT] = self._layoutTop:getChildByName("Node_lt")
  63. self._nodes[global.MMO.MAIN_NODE_TOP_RT] = self._layoutTop:getChildByName("Node_rt")
  64. self._nodes[global.MMO.MAIN_NODE_TOP_LB] = self._layoutTop:getChildByName("Node_lb")
  65. self._nodes[global.MMO.MAIN_NODE_TOP_MT] = self._layoutTop:getChildByName("Node_mt")
  66. -- SUI TOP BOTTOM
  67. self._layoutBottom = self._root:getChildByName("Panel_bottom_sui")
  68. self._layoutBottom:setClippingType(0)
  69. self._nodes[global.MMO.MAIN_NODE_BOTTOM_LT] = self._layoutBottom:getChildByName("Node_lt")
  70. self._nodes[global.MMO.MAIN_NODE_BOTTOM_RT] = self._layoutBottom:getChildByName("Node_rt")
  71. self._nodes[global.MMO.MAIN_NODE_BOTTOM_LB] = self._layoutBottom:getChildByName("Node_lb")
  72. self._nodes[global.MMO.MAIN_NODE_BOTTOM_RB] = self._layoutBottom:getChildByName("Node_rb")
  73. self._layoutSUITop = self._root:getChildByName("Panel_top_sui")
  74. self._layoutSUITop:setClippingType(0)
  75. self._nodes[global.MMO.MAIN_NODE_SUI_TOP_LT] = self._layoutSUITop:getChildByName("Node_lt")
  76. self._nodes[global.MMO.MAIN_NODE_SUI_TOP_RT] = self._layoutSUITop:getChildByName("Node_rt")
  77. self._nodes[global.MMO.MAIN_NODE_SUI_TOP_LB] = self._layoutSUITop:getChildByName("Node_lb")
  78. self._nodes[global.MMO.MAIN_NODE_SUI_TOP_RB] = self._layoutSUITop:getChildByName("Node_rb")
  79. -- guide
  80. self._nodes[global.MMO.MAIN_NODE_GUIDE] = self._root:getChildByName("Node_guide")
  81. -- adapet
  82. local visibleSize = global.Director:getVisibleSize()
  83. self._layoutAdapet:setContentSize(visibleSize)
  84. self._layoutExtra:setContentSize(visibleSize)
  85. self._layoutChat:setContentSize(visibleSize)
  86. self._layoutSUI:setContentSize(visibleSize)
  87. self._layoutTop:setContentSize(visibleSize)
  88. self._layoutBottom:setContentSize(visibleSize)
  89. self._layoutSUITop:setContentSize(visibleSize)
  90. ccui.Helper:doLayout(self._layoutAdapet)
  91. ccui.Helper:doLayout(self._layoutExtra)
  92. ccui.Helper:doLayout(self._layoutChat)
  93. ccui.Helper:doLayout(self._layoutSUI)
  94. ccui.Helper:doLayout(self._layoutTop)
  95. ccui.Helper:doLayout(self._layoutBottom)
  96. ccui.Helper:doLayout(self._layoutSUITop)
  97. end
  98. function MainRootLayer:InitGUI()
  99. ssr.GUI.ATTACH_LEFTTOP = self._nodes[global.MMO.MAIN_NODE_SUI_LT]
  100. ssr.GUI.ATTACH_RIGHTTOP = self._nodes[global.MMO.MAIN_NODE_SUI_RT]
  101. ssr.GUI.ATTACH_LEFTBOTTOM = self._nodes[global.MMO.MAIN_NODE_SUI_LB]
  102. ssr.GUI.ATTACH_RIGHTBOTTOM = self._nodes[global.MMO.MAIN_NODE_SUI_RB]
  103. GUI.ATTACH_LEFTTOP = self._nodes[global.MMO.MAIN_NODE_SUI_LT]
  104. GUI.ATTACH_RIGHTTOP = self._nodes[global.MMO.MAIN_NODE_SUI_RT]
  105. GUI.ATTACH_LEFTBOTTOM = self._nodes[global.MMO.MAIN_NODE_SUI_LB]
  106. GUI.ATTACH_RIGHTBOTTOM = self._nodes[global.MMO.MAIN_NODE_SUI_RB]
  107. -- bottom
  108. GUI.ATTACH_LEFTTOP_B = self._nodes[global.MMO.MAIN_NODE_BOTTOM_LT]
  109. GUI.ATTACH_RIGHTTOP_B = self._nodes[global.MMO.MAIN_NODE_BOTTOM_RT]
  110. GUI.ATTACH_LEFTBOTTOM_B = self._nodes[global.MMO.MAIN_NODE_BOTTOM_LB]
  111. GUI.ATTACH_RIGHTBOTTOM_B = self._nodes[global.MMO.MAIN_NODE_BOTTOM_RB]
  112. -- top
  113. GUI.ATTACH_LEFTTOP_T = self._nodes[global.MMO.MAIN_NODE_SUI_TOP_LT]
  114. GUI.ATTACH_RIGHTTOP_T = self._nodes[global.MMO.MAIN_NODE_SUI_TOP_RT]
  115. GUI.ATTACH_LEFTBOTTOM_T = self._nodes[global.MMO.MAIN_NODE_SUI_TOP_LB]
  116. GUI.ATTACH_RIGHTBOTTOM_T = self._nodes[global.MMO.MAIN_NODE_SUI_TOP_RB]
  117. SL:RequireFile(SLDefine.LUAFile.LUA_FILE_MAIN_LEFTTOP)
  118. SL:RequireFile(SLDefine.LUAFile.LUA_FILE_MAIN_RIGHTTOP)
  119. SL:RequireFile(SLDefine.LUAFile.LUA_FILE_MAIN_LEFTBOTTOM)
  120. SL:RequireFile(SLDefine.LUAFile.LUA_FILE_MAIN_RIGHTBOTTOM)
  121. local OtherTradingBankProxy = global.Facade:retrieveProxy(global.ProxyTable.OtherTradingBankProxy)
  122. if OtherTradingBankProxy:getPublishOpen() ~= 1 then
  123. MainLeftTop.main()
  124. end
  125. MainRightTop.main()
  126. MainLeftBottom.main()
  127. MainRightBottom.main()
  128. self.ui = ui_delegate(self._root)
  129. local OtherTradingBankProxy = global.Facade:retrieveProxy(global.ProxyTable.OtherTradingBankProxy)
  130. if OtherTradingBankProxy:getPublishOpen() ~= 1 then
  131. -- if not self.ui.tradingBtn then
  132. -- self.ui.tradingBtn = GUI:Button_Create(GUI.ATTACH_LEFTTOP, "tradingBtn", 270, -94, "res/private/main/bottom/jiaoyihang.png")
  133. -- end
  134. if self.ui.tradingBtn then
  135. self.ui.tradingBtn:setVisible(false)
  136. end
  137. if global.OtherTradingBank then
  138. local OtherTradingBankProxy = global.Facade:retrieveProxy(global.ProxyTable.OtherTradingBankProxy)
  139. OtherTradingBankProxy:getTradingBankStatus({}, function(code, data, msg)
  140. if code == 200 then
  141. if data and data.isShowEntrance == 1 then
  142. self:UpdateButtonPos(data)
  143. end
  144. end
  145. end, true)
  146. end
  147. end
  148. end
  149. function MainRootLayer:UpdateButtonPos(data)
  150. if global.L_GameEnvManager:GetEnvDataByKey("platform") == "mac" then
  151. return
  152. end
  153. if data.gameEntranceImg == nil or data.gameEntranceImg == "" then
  154. return
  155. end
  156. if self.ui.tradingBtnNew then
  157. GUI:removeFromParent(self.ui.tradingBtnNew)
  158. self.ui.tradingBtnNew = nil
  159. end
  160. local pointtable = {}
  161. table.insert(pointtable, self._nodes[global.MMO.MAIN_NODE_SUI_LT])
  162. table.insert(pointtable, self._nodes[global.MMO.MAIN_NODE_SUI_TM])
  163. table.insert(pointtable, self._nodes[global.MMO.MAIN_NODE_SUI_RT])
  164. table.insert(pointtable, self._nodes[global.MMO.MAIN_NODE_SUI_LM])
  165. table.insert(pointtable, self._nodes[global.MMO.MAIN_NODE_SUI_MM])
  166. table.insert(pointtable, self._nodes[global.MMO.MAIN_NODE_SUI_RM])
  167. table.insert(pointtable, self._nodes[global.MMO.MAIN_NODE_SUI_LB])
  168. table.insert(pointtable, self._nodes[global.MMO.MAIN_NODE_SUI_BM])
  169. table.insert(pointtable, self._nodes[global.MMO.MAIN_NODE_SUI_RB])
  170. local OtherTradingBankProxy = global.Facade:retrieveProxy(global.ProxyTable.OtherTradingBankProxy)
  171. OtherTradingBankProxy:reqTradingButton(data.gameEntranceImg,nil, function(filePath)
  172. if filePath then
  173. local pos = data.gameEntrancePositionOrigin
  174. if pos and pos >= 1 and pos <= 9 then
  175. self.ui.tradingBtnNew = GUI:Button_Create(pointtable[pos], "tradingBtnNew", data.gameEntrancePositionX, data.gameEntrancePositionY, "res/private/main/bottom/jiaoyihang.png")
  176. GUI:setVisible(self.ui.tradingBtnNew, false)
  177. self.ui.tradingBtnNew:loadTextureNormal(filePath)
  178. GUI:setVisible(self.ui.tradingBtnNew, true)
  179. self.ui.tradingBtnNew:addClickEventListener(function ()
  180. JUMPTO(35)
  181. end)
  182. end
  183. end
  184. end)
  185. end
  186. function MainRootLayer:UpdateAdapet()
  187. local visibleSize = global.Director:getVisibleSize()
  188. local glView = global.Director:getOpenGLView()
  189. local viewRect = glView:getVisibleRect()
  190. local safeRect = global.Director:getSafeAreaRect()
  191. releasePrint( string.format( "#################safeRect:[%d, %d %d, %d]", safeRect.x, safeRect.y, safeRect.width, safeRect.height ) )
  192. releasePrint( string.format( "#################visibleRect:[%d, %d %d, %d]", viewRect.x, viewRect.y, viewRect.width, viewRect.height ) )
  193. local _, rect = checkNotchPhone(true)
  194. --
  195. self._layoutAdapet:setContentSize(rect)
  196. self._layoutAdapet:setPositionX(rect.x)
  197. ccui.Helper:doLayout(self._layoutAdapet)
  198. --
  199. self._layoutChat:setContentSize(rect)
  200. self._layoutChat:setPositionX(rect.x)
  201. ccui.Helper:doLayout(self._layoutChat)
  202. --
  203. self._layoutSUI:setContentSize(rect)
  204. self._layoutSUI:setPositionX(rect.x)
  205. ccui.Helper:doLayout(self._layoutSUI)
  206. self._nodeSUIBM:setPositionX(visibleSize.width / 2)
  207. self._layoutTop:setContentSize(rect)
  208. self._layoutTop:setPositionX(rect.x)
  209. ccui.Helper:doLayout(self._layoutTop)
  210. self._layoutBottom:setContentSize(rect)
  211. self._layoutBottom:setPositionX(rect.x)
  212. ccui.Helper:doLayout(self._layoutBottom)
  213. self._layoutSUITop:setContentSize(rect)
  214. self._layoutSUITop:setPositionX(rect.x)
  215. ccui.Helper:doLayout(self._layoutSUITop)
  216. self._layoutExtra:setContentSize(visibleSize)
  217. ccui.Helper:doLayout(self._layoutExtra)
  218. end
  219. function MainRootLayer:AddChild(data)
  220. local parent = (data.index and self._nodes[data.index] or self._root)
  221. parent:addChild(data.child)
  222. end
  223. function MainRootLayer:GetNode(id)
  224. return self._nodes[id]
  225. end
  226. function MainRootLayer:ShowFunc()
  227. local _, rect = checkNotchPhone(true)
  228. local destX = rect.x
  229. local destY = 78
  230. self._layoutAdapet:stopAllActions()
  231. self._layoutChat:stopAllActions()
  232. self._layoutAdapet:runAction(cc.MoveTo:create(0.3, cc.p(destX, destY)))
  233. self._layoutChat:runAction(cc.MoveTo:create(0.3, cc.p(destX, destY)))
  234. self._layoutExtra:stopAllActions()
  235. self._layoutExtra:runAction(cc.MoveTo:create(0.3, cc.p(0, destY)))
  236. end
  237. function MainRootLayer:HideFunc()
  238. local _, rect = checkNotchPhone(true)
  239. local destX = rect.x
  240. local destY = 0
  241. self._layoutAdapet:stopAllActions()
  242. self._layoutChat:stopAllActions()
  243. self._layoutAdapet:runAction(cc.MoveTo:create(0.3, cc.p(destX, destY)))
  244. self._layoutChat:runAction(cc.MoveTo:create(0.3, cc.p(destX, destY)))
  245. self._layoutExtra:stopAllActions()
  246. self._layoutExtra:runAction(cc.MoveTo:create(0.3, cc.p(0, destY)))
  247. end
  248. return MainRootLayer