ResolutionSizeChangeCommand.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. local ResolutionSizeChangeCommand = class('ResolutionSizeChangeCommand', framework.SimpleCommand)
  2. local skillUtils = requireProxy("skillUtils")
  3. local optionsUtils = requireProxy("optionsUtils")
  4. function ResolutionSizeChangeCommand:ctor()
  5. end
  6. -- 分辨率改变 游戏内调整
  7. function ResolutionSizeChangeCommand:execute(notification)
  8. dump("ResolutionSizeChangeCommand___")
  9. local data = notification:getBody()
  10. local size = data.size
  11. local onlyAdapt = data.onlyAdapt
  12. local index = data.index
  13. if not onlyAdapt and not size then
  14. return
  15. end
  16. if not onlyAdapt and global.isWinPlayMode then
  17. local glview = cc.Director:getInstance():getOpenGLView()
  18. glview:setFrameSize(size.width, size.height)
  19. local frameSize = size
  20. local frameFactor = frameSize.width / frameSize.height
  21. local designPolicy = cc.ResolutionPolicy.FIXED_HEIGHT
  22. if frameFactor > 1.8 then -- 17:9 = 1.889
  23. designPolicy = cc.ResolutionPolicy.FIXED_HEIGHT
  24. else -- 16:9 = 1.778
  25. designPolicy = cc.ResolutionPolicy.FIXED_WIDTH
  26. end
  27. local width = size.width
  28. local height = size.height
  29. if width > global.MMO.RESOLUTION_WIDTH or height > global.MMO.RESOLUTION_HEIGHT then
  30. width = global.MMO.RESOLUTION_WIDTH
  31. height = global.MMO.RESOLUTION_HEIGHT
  32. end
  33. glview:setDesignResolutionSize(width, height, designPolicy)
  34. glview:setFrameZoomFactor(global.DeviceZoom_Win)
  35. end
  36. cc.Director:getInstance():setViewport()
  37. global.Facade:sendNotification(global.NoticeTable.WindowResized)
  38. SLBridge:onLUAEvent(LUA_EVENT_WINDOW_CHANGE)
  39. ---重新设置摄像机
  40. local camera = global.gameMapController:GetViewCamera()
  41. if camera then
  42. camera:autorelease()
  43. camera:removeFromParent()
  44. global.gameMapController:SetViewCamera(nil)
  45. local LayerFacadeMediator = global.Facade:retrieveMediator("LayerFacadeMediator")
  46. LayerFacadeMediator:InitGameWorldCamera()
  47. local SceneOptionsMediator = global.Facade:retrieveMediator("SceneOptionsMediator")
  48. local dieflag = SceneOptionsMediator:getDieFlag()
  49. if dieflag then
  50. SceneOptionsMediator:onMainPlayerRevive()
  51. end
  52. SceneOptionsMediator:Cleanup(true)
  53. local mainPlayer = global.gamePlayerController:GetMainPlayer()
  54. local newcamera = global.gameMapController:GetViewCamera()
  55. if mainPlayer and newcamera then
  56. local offset = global.gameMapController:GetViewCenterOffset()
  57. local playerPos = mainPlayer:getPosition()
  58. local tempPos = cc.pAdd(playerPos, offset)
  59. newcamera:setPosition(tempPos)
  60. global.sceneManager:SetCamera(newcamera)
  61. global.Facade:sendNotification(global.NoticeTable.BindMainPlayer, mainPlayer)
  62. -- global.Facade:sendNotification(global.NoticeTable.ReloadMap)
  63. if dieflag then
  64. SceneOptionsMediator:onMainPlayerDie()
  65. end
  66. end
  67. end
  68. --右键跑路区域 调整
  69. local RTouchLayerMediator = global.Facade:retrieveMediator("RTouchLayerMediator")
  70. if RTouchLayerMediator and RTouchLayerMediator._layer and RTouchLayerMediator._layer.panel then
  71. local sceneSize = cc.Director:getInstance():getVisibleSize()
  72. RTouchLayerMediator._layer.panel:setContentSize(sceneSize)
  73. end
  74. if not onlyAdapt and global.isWinPlayMode then
  75. global.DesignSize_Win = size
  76. global.L_GameEnvManager:SetGameEnvDataByKey("resolution", size.width .. "x" .. size.height)
  77. local GameSettingProxy = global.Facade:retrieveProxy(global.ProxyTable.GameSettingProxy)
  78. GameSettingProxy:SetInnerChangedSize(true)
  79. --*登录器 的配置
  80. local ResolutionIni = global.L_GameEnvManager:GetEnvDataByKey("ResolutionIni")
  81. dump(ResolutionIni, "ResolutionIni__")
  82. if ResolutionIni and cc.FileUtils:getInstance():isFileExist(ResolutionIni) and index then
  83. local iniStr = cc.FileUtils:getInstance():getStringFromFile(ResolutionIni)
  84. local setStr = string.match(iniStr, "Resolution=%d")
  85. if setStr then
  86. iniStr = string.gsub(iniStr, setStr, "Resolution=" .. (index - 1))
  87. cc.FileUtils:getInstance():writeStringToFile(iniStr, ResolutionIni)
  88. end
  89. end
  90. end
  91. if size then
  92. local GameSettingProxy = global.Facade:retrieveProxy(global.ProxyTable.GameSettingProxy)
  93. GameSettingProxy:RequestNotifySizeChange(size.width, size.height)
  94. end
  95. end
  96. return ResolutionSizeChangeCommand