| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- local DebugMediator = requireMediator( "DebugMediator" )
- local tileSceneManagerHelper = class("tileSceneManagerHelper", DebugMediator)
- local SceneDefine = require("scene/sceneDefine")
- tileSceneManagerHelper.Name = "tileSceneManagerHelper"
- local AtlasSplitConfigs = SceneDefine.AtlasSplitConfigs
- local FrameOffset = SceneDefine.FrameOffset
- local ObjMaxOffsetY = SceneDefine.ObjMaxOffsetY
- local MapGridWidth = global.MMO.MapGridWidth
- local MapGridHeight = global.MMO.MapGridHeight
- function tileSceneManagerHelper:ctor()
- tileSceneManagerHelper.super.ctor(self)
- self._mapDataPath = nil
- end
- function tileSceneManagerHelper:listNotificationInterests()
- local noticeTable = global.NoticeTable
- return
- {
- noticeTable.InitedWorldTree,
- noticeTable.BindMainPlayer,
- noticeTable.MainPlayerActionEnded,
- noticeTable.MainPlayerActionProcess,
- noticeTable.ReleaseMemory,
- noticeTable.ChangeScene,
- noticeTable.ReloadMap,
- noticeTable.SceneFollowMainPlayer,
- }
- end
- function tileSceneManagerHelper:handleNotification(notification)
- local noticeName = notification:getName()
- local noticeTable = global.NoticeTable
- local noticeData = notification:getBody()
- if noticeTable.InitedWorldTree == noticeName then
- self:onInitedWorldTree()
- elseif noticeTable.BindMainPlayer == noticeName then
- self:onBindMainPlayer( noticeData )
- elseif noticeTable.MainPlayerActionEnded == noticeName then
- self:onMainPlayerActionEnded( noticeData )
- elseif noticeTable.MainPlayerActionProcess == noticeName then
- self:onMainPlayerActionProcess( noticeData )
- elseif noticeTable.ChangeScene == noticeName then
- self:onEnterMap( noticeData )
- elseif noticeTable.SceneFollowMainPlayer == noticeName then
- self:onSceneFollowMainPlayer( noticeData )
- elseif noticeTable.ReloadMap == noticeName then
- self:reloadAllTile()
- elseif noticeTable.ReleaseMemory == noticeName then
- self:Cleanup()
- end
- end
- function tileSceneManagerHelper:onInitedWorldTree()
- if global.sceneManager then
- local sceneManager = global.sceneManager
- local mapRoot = global.sceneGraphCtl:GetSceneNode( global.MMO.NODE_MAP )
- local actRoot = global.sceneGraphCtl:GetSceneNode( global.MMO.NODE_ACTOR_SPRITE )
- local objRoot = global.sceneGraphCtl:GetSceneNode( global.MMO.NODE_MAP_OBJ )
- local tileRootNode = cc.Node:create()
- local smtileRootNode = cc.Node:create()
- local objRootNode = actRoot
- local miniRootNode = cc.Node:create()
- local debugRootNode = cc.Node:create()
- if SL:GetMetaValue("GAME_DATA", "ForbidPreMiniMapShow") == 1 then
- miniRootNode:setVisible(false)
- end
- mapRoot:addChild(tileRootNode)
- mapRoot:addChild(smtileRootNode)
- mapRoot:addChild(miniRootNode, -1)
- objRoot:addChild(debugRootNode)
- sceneManager:SetRootNode(tileRootNode, smtileRootNode, objRootNode, miniRootNode, debugRootNode)
- local camera = global.gameMapController:GetViewCamera()
- sceneManager:SetCamera(camera)
- if AtlasSplitConfigs then
- for atlasType, splitConfig in pairs(AtlasSplitConfigs) do
- for area, splitSize in pairs(splitConfig) do
- sceneManager:SetAtlasSplit( atlasType - 1, area, splitSize )
- end
- end
- end
- if ObjMaxOffsetY then
- for mapID, enlargeY in pairs(ObjMaxOffsetY) do
- sceneManager:SetObjEnlargeY(mapID, enlargeY)
- end
- end
- if FrameOffset then
- for area, offsets in pairs(FrameOffset) do
- for imgIdx, offset in pairs(offsets) do
- sceneManager:SetFrameAnimOffset(area, imgIdx, offset.x, offset.y)
- end
- end
- end
- sceneManager:SetLoadParam(1, 180)
- sceneManager:SetLoadMapDataCallback(handler(self, self.onLoadMapDataCallback))
- sceneManager:SetLoadMiniCallback(handler(self, self.onLoadMiniCallback))
- sceneManager:SetOnOpenDoorFunc(handler(self, self.onOpenDoorCallback))
- sceneManager:SetOnCloseDoorFunc(handler(self, self.onCloseDoorCallback))
- end
- end
- function tileSceneManagerHelper:onBindMainPlayer(player)
- self:followPlayer( player)
- end
- function tileSceneManagerHelper:onSceneFollowMainPlayer()
- self:followMainPlayer()
- end
- function tileSceneManagerHelper:onMainPlayerActionEnded(act)
- if IsMoveAction(act) then
- local player = global.gamePlayerController:GetMainPlayer()
- self:followPlayer( player )
- end
- end
- function tileSceneManagerHelper:onMainPlayerActionProcess(action)
- local mmo = global.MMO
- if mmo.ACTION_DASH == action or mmo.ACTION_ONPUSH == action or mmo.ACTION_TELEPORT == action or mmo.ACTION_ZXC then
- self:followMainPlayer()
- end
- end
- function tileSceneManagerHelper:onEnterMap(mapID)
- if global.sceneManager then
- if global.L_GameEnvManager:GetEnvDataByKey("isCloudLogin") then
- if global.sceneManager.UnloadAllAtlas then
- global.sceneManager:UnloadAllAtlas()
- end
- if global.sceneManager.UnloadSpriteCache then
- global.sceneManager:UnloadSpriteCache()
- end
- end
- local mapDataPath = string.format("scene/map/%s.map", tostring(mapID))
- local mapMiniPath = ""
- local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
- if mapProxy then
- local miniFile = mapProxy:GetMiniMapFile()
- if miniFile then
- mapMiniPath = miniFile
- end
- local mapDataID = mapProxy:GetMapDataID()
- print("mapDataIDDDDDDDDDDDDDDD", mapDataID)
- if mapDataID then
- mapDataPath = string.format("scene/map/%s.map", tostring(mapDataID))
- end
- end
- if self._mapDataPath ~= mapDataPath then
- --清理光圈 因为changeScene 和 Load_Success不一定哪个先 所以放这
- global.darkNodeManager:clearAllNodes(true)
- global.sceneManager:LoadMap(mapID, mapDataPath, mapMiniPath)
- end
- self._mapDataPath = mapDataPath
- end
- self:followMainPlayer()
- end
- function tileSceneManagerHelper:reloadAllTile()
- if global.sceneManager then
- global.sceneManager:reloadAllTile()
- self:followMainPlayer()
- end
- end
- function tileSceneManagerHelper:Cleanup()
- if global.sceneManager then
- global.sceneManager:Cleanup()
- end
- end
- function tileSceneManagerHelper:followMainPlayer()
- local player = global.gamePlayerController:GetMainPlayer()
- self:followPlayer(player)
- end
- function tileSceneManagerHelper:followPlayer(player)
- if global.sceneManager and player then
- global.sceneManager:followPlayer(cc.p(player:getPosition()))
- end
- if global.darkNodeManager and player then
- global.darkNodeManager:followPlayer(cc.p(player:getPosition()))
- end
- end
- function tileSceneManagerHelper:onLoadMapDataCallback(mapID, mapWidthInPixel, mapHeightInPixel)
- print("onLoadMapDataCallback", mapID, mapWidthInPixel, mapHeightInPixel)
- global.gameMapController:calcMapFollowParam( mapWidthInPixel, mapHeightInPixel )
- self:followMainPlayer()
- global.Facade:sendNotification(global.NoticeTable.MapData_Load_Success)
- end
- function tileSceneManagerHelper:onLoadMiniCallback(mapID, miniName)
- print("onLoadMiniCallback", mapID, miniName)
- local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
- if mapProxy then
- local miniMapID = mapProxy:GetMiniMapID()
- global.Facade:sendNotification(global.NoticeTable.MiniMap_Download_Success, miniMapID)
- end
- end
- function tileSceneManagerHelper:onOpenDoorCallback(mapX, mapY)
- print("onOpenDoorCallback", mapX, mapY)
- end
- function tileSceneManagerHelper:onCloseDoorCallback(mapX, mapY)
- print("onCloseDoorCallback", mapX, mapY)
- end
- --------------------------------------------------------------
- local tileSceneManager = tileSceneManager
- if tileSceneManager then
- function tileSceneManager:destory()
- global.Facade:removeMediator( tileSceneManagerHelper.NAME )
- end
- function tileSceneManager:WorldPos2MapPos(worldPos )
- return math.floor(worldPos.x / MapGridWidth), math.floor(-worldPos.y / MapGridHeight)
- end
- function tileSceneManager:MapPos2WorldPos(mapX, mapY, centerOfGrid )
- local worldPos = cc.p( mapX * MapGridWidth, -mapY * MapGridHeight )
- if centerOfGrid then
- worldPos.x = worldPos.x + MapGridWidth * 0.5
- worldPos.y = worldPos.y - MapGridHeight * 0.5
- end
- return worldPos
- end
- end
- return tileSceneManagerHelper
|