sceneManagerHelper.lua 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. local DebugMediator = requireMediator( "DebugMediator" )
  2. local tileSceneManagerHelper = class("tileSceneManagerHelper", DebugMediator)
  3. local SceneDefine = require("scene/sceneDefine")
  4. tileSceneManagerHelper.Name = "tileSceneManagerHelper"
  5. local AtlasSplitConfigs = SceneDefine.AtlasSplitConfigs
  6. local FrameOffset = SceneDefine.FrameOffset
  7. local ObjMaxOffsetY = SceneDefine.ObjMaxOffsetY
  8. local MapGridWidth = global.MMO.MapGridWidth
  9. local MapGridHeight = global.MMO.MapGridHeight
  10. function tileSceneManagerHelper:ctor()
  11. tileSceneManagerHelper.super.ctor(self)
  12. self._mapDataPath = nil
  13. end
  14. function tileSceneManagerHelper:listNotificationInterests()
  15. local noticeTable = global.NoticeTable
  16. return
  17. {
  18. noticeTable.InitedWorldTree,
  19. noticeTable.BindMainPlayer,
  20. noticeTable.MainPlayerActionEnded,
  21. noticeTable.MainPlayerActionProcess,
  22. noticeTable.ReleaseMemory,
  23. noticeTable.ChangeScene,
  24. noticeTable.ReloadMap,
  25. noticeTable.SceneFollowMainPlayer,
  26. }
  27. end
  28. function tileSceneManagerHelper:handleNotification(notification)
  29. local noticeName = notification:getName()
  30. local noticeTable = global.NoticeTable
  31. local noticeData = notification:getBody()
  32. if noticeTable.InitedWorldTree == noticeName then
  33. self:onInitedWorldTree()
  34. elseif noticeTable.BindMainPlayer == noticeName then
  35. self:onBindMainPlayer( noticeData )
  36. elseif noticeTable.MainPlayerActionEnded == noticeName then
  37. self:onMainPlayerActionEnded( noticeData )
  38. elseif noticeTable.MainPlayerActionProcess == noticeName then
  39. self:onMainPlayerActionProcess( noticeData )
  40. elseif noticeTable.ChangeScene == noticeName then
  41. self:onEnterMap( noticeData )
  42. elseif noticeTable.SceneFollowMainPlayer == noticeName then
  43. self:onSceneFollowMainPlayer( noticeData )
  44. elseif noticeTable.ReloadMap == noticeName then
  45. self:reloadAllTile()
  46. elseif noticeTable.ReleaseMemory == noticeName then
  47. self:Cleanup()
  48. end
  49. end
  50. function tileSceneManagerHelper:onInitedWorldTree()
  51. if global.sceneManager then
  52. local sceneManager = global.sceneManager
  53. local mapRoot = global.sceneGraphCtl:GetSceneNode( global.MMO.NODE_MAP )
  54. local actRoot = global.sceneGraphCtl:GetSceneNode( global.MMO.NODE_ACTOR_SPRITE )
  55. local objRoot = global.sceneGraphCtl:GetSceneNode( global.MMO.NODE_MAP_OBJ )
  56. local tileRootNode = cc.Node:create()
  57. local smtileRootNode = cc.Node:create()
  58. local objRootNode = actRoot
  59. local miniRootNode = cc.Node:create()
  60. local debugRootNode = cc.Node:create()
  61. if SL:GetMetaValue("GAME_DATA", "ForbidPreMiniMapShow") == 1 then
  62. miniRootNode:setVisible(false)
  63. end
  64. mapRoot:addChild(tileRootNode)
  65. mapRoot:addChild(smtileRootNode)
  66. mapRoot:addChild(miniRootNode, -1)
  67. objRoot:addChild(debugRootNode)
  68. sceneManager:SetRootNode(tileRootNode, smtileRootNode, objRootNode, miniRootNode, debugRootNode)
  69. local camera = global.gameMapController:GetViewCamera()
  70. sceneManager:SetCamera(camera)
  71. if AtlasSplitConfigs then
  72. for atlasType, splitConfig in pairs(AtlasSplitConfigs) do
  73. for area, splitSize in pairs(splitConfig) do
  74. sceneManager:SetAtlasSplit( atlasType - 1, area, splitSize )
  75. end
  76. end
  77. end
  78. if ObjMaxOffsetY then
  79. for mapID, enlargeY in pairs(ObjMaxOffsetY) do
  80. sceneManager:SetObjEnlargeY(mapID, enlargeY)
  81. end
  82. end
  83. if FrameOffset then
  84. for area, offsets in pairs(FrameOffset) do
  85. for imgIdx, offset in pairs(offsets) do
  86. sceneManager:SetFrameAnimOffset(area, imgIdx, offset.x, offset.y)
  87. end
  88. end
  89. end
  90. sceneManager:SetLoadParam(1, 180)
  91. sceneManager:SetLoadMapDataCallback(handler(self, self.onLoadMapDataCallback))
  92. sceneManager:SetLoadMiniCallback(handler(self, self.onLoadMiniCallback))
  93. sceneManager:SetOnOpenDoorFunc(handler(self, self.onOpenDoorCallback))
  94. sceneManager:SetOnCloseDoorFunc(handler(self, self.onCloseDoorCallback))
  95. end
  96. end
  97. function tileSceneManagerHelper:onBindMainPlayer(player)
  98. self:followPlayer( player)
  99. end
  100. function tileSceneManagerHelper:onSceneFollowMainPlayer()
  101. self:followMainPlayer()
  102. end
  103. function tileSceneManagerHelper:onMainPlayerActionEnded(act)
  104. if IsMoveAction(act) then
  105. local player = global.gamePlayerController:GetMainPlayer()
  106. self:followPlayer( player )
  107. end
  108. end
  109. function tileSceneManagerHelper:onMainPlayerActionProcess(action)
  110. local mmo = global.MMO
  111. if mmo.ACTION_DASH == action or mmo.ACTION_ONPUSH == action or mmo.ACTION_TELEPORT == action or mmo.ACTION_ZXC then
  112. self:followMainPlayer()
  113. end
  114. end
  115. function tileSceneManagerHelper:onEnterMap(mapID)
  116. if global.sceneManager then
  117. if global.L_GameEnvManager:GetEnvDataByKey("isCloudLogin") then
  118. if global.sceneManager.UnloadAllAtlas then
  119. global.sceneManager:UnloadAllAtlas()
  120. end
  121. if global.sceneManager.UnloadSpriteCache then
  122. global.sceneManager:UnloadSpriteCache()
  123. end
  124. end
  125. local mapDataPath = string.format("scene/map/%s.map", tostring(mapID))
  126. local mapMiniPath = ""
  127. local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  128. if mapProxy then
  129. local miniFile = mapProxy:GetMiniMapFile()
  130. if miniFile then
  131. mapMiniPath = miniFile
  132. end
  133. local mapDataID = mapProxy:GetMapDataID()
  134. print("mapDataIDDDDDDDDDDDDDDD", mapDataID)
  135. if mapDataID then
  136. mapDataPath = string.format("scene/map/%s.map", tostring(mapDataID))
  137. end
  138. end
  139. if self._mapDataPath ~= mapDataPath then
  140. --清理光圈 因为changeScene 和 Load_Success不一定哪个先 所以放这
  141. global.darkNodeManager:clearAllNodes(true)
  142. global.sceneManager:LoadMap(mapID, mapDataPath, mapMiniPath)
  143. end
  144. self._mapDataPath = mapDataPath
  145. end
  146. self:followMainPlayer()
  147. end
  148. function tileSceneManagerHelper:reloadAllTile()
  149. if global.sceneManager then
  150. global.sceneManager:reloadAllTile()
  151. self:followMainPlayer()
  152. end
  153. end
  154. function tileSceneManagerHelper:Cleanup()
  155. if global.sceneManager then
  156. global.sceneManager:Cleanup()
  157. end
  158. end
  159. function tileSceneManagerHelper:followMainPlayer()
  160. local player = global.gamePlayerController:GetMainPlayer()
  161. self:followPlayer(player)
  162. end
  163. function tileSceneManagerHelper:followPlayer(player)
  164. if global.sceneManager and player then
  165. global.sceneManager:followPlayer(cc.p(player:getPosition()))
  166. end
  167. if global.darkNodeManager and player then
  168. global.darkNodeManager:followPlayer(cc.p(player:getPosition()))
  169. end
  170. end
  171. function tileSceneManagerHelper:onLoadMapDataCallback(mapID, mapWidthInPixel, mapHeightInPixel)
  172. print("onLoadMapDataCallback", mapID, mapWidthInPixel, mapHeightInPixel)
  173. global.gameMapController:calcMapFollowParam( mapWidthInPixel, mapHeightInPixel )
  174. self:followMainPlayer()
  175. global.Facade:sendNotification(global.NoticeTable.MapData_Load_Success)
  176. end
  177. function tileSceneManagerHelper:onLoadMiniCallback(mapID, miniName)
  178. print("onLoadMiniCallback", mapID, miniName)
  179. local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  180. if mapProxy then
  181. local miniMapID = mapProxy:GetMiniMapID()
  182. global.Facade:sendNotification(global.NoticeTable.MiniMap_Download_Success, miniMapID)
  183. end
  184. end
  185. function tileSceneManagerHelper:onOpenDoorCallback(mapX, mapY)
  186. print("onOpenDoorCallback", mapX, mapY)
  187. end
  188. function tileSceneManagerHelper:onCloseDoorCallback(mapX, mapY)
  189. print("onCloseDoorCallback", mapX, mapY)
  190. end
  191. --------------------------------------------------------------
  192. local tileSceneManager = tileSceneManager
  193. if tileSceneManager then
  194. function tileSceneManager:destory()
  195. global.Facade:removeMediator( tileSceneManagerHelper.NAME )
  196. end
  197. function tileSceneManager:WorldPos2MapPos(worldPos )
  198. return math.floor(worldPos.x / MapGridWidth), math.floor(-worldPos.y / MapGridHeight)
  199. end
  200. function tileSceneManager:MapPos2WorldPos(mapX, mapY, centerOfGrid )
  201. local worldPos = cc.p( mapX * MapGridWidth, -mapY * MapGridHeight )
  202. if centerOfGrid then
  203. worldPos.x = worldPos.x + MapGridWidth * 0.5
  204. worldPos.y = worldPos.y - MapGridHeight * 0.5
  205. end
  206. return worldPos
  207. end
  208. end
  209. return tileSceneManagerHelper