You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
AdLike2048/preview-template/workbench/js/layout-presets.js

110 lines
3.7 KiB

(function (global) {
'use strict';
var WorkbenchLayout = global.PWLayout;
if (!WorkbenchLayout) {
console.error('[调试工作台] layout-presets 需先加载 layout-core');
return;
}
WorkbenchLayout.prototype._isPortraitGame = function () {
var cc = global.cc;
try {
if (cc && cc.view && typeof cc.view.getDesignResolutionSize === 'function') {
var dr = cc.view.getDesignResolutionSize();
if (dr && dr.width > 0 && dr.height > 0) return dr.height >= dr.width;
}
} catch (e) { /* */ }
// 本项目默认 750×1600
return true;
};
WorkbenchLayout.prototype._presetTree = function (name) {
if (name === 'scene') {
return {
type: 'split', dir: 'h', sizes: [0.22, 0.56, 0.22],
children: [
this._tabsNode(['hierarchy']),
this._gameNode(),
this._tabsNode(['inspector']),
],
};
}
if (name === 'minimal') {
return {
type: 'split', dir: 'v', sizes: [0.78, 0.22],
children: [
this._gameNode(),
this._tabsNode(['perf']),
],
};
}
if (name === 'portrait') return this._portraitAnalyzeTree();
if (name === 'landscape') return this._landscapeAnalyzeTree();
// analyze:按游戏设计分辨率自动选竖屏/横屏默认
return this._isPortraitGame() ? this._portraitAnalyzeTree() : this._landscapeAnalyzeTree();
};
/**
* 竖屏默认(图1):
* 左上 = 层级 | 属性
* 左下 = 控制台(横跨层级+属性两列下方)
* 中 = 游戏,右 = 性能
*/
WorkbenchLayout.prototype._portraitAnalyzeTree = function () {
return {
type: 'split', dir: 'h', sizes: [0.34, 0.46, 0.20],
children: [
{
type: 'split', dir: 'v', sizes: [0.58, 0.42],
children: [
{
type: 'split', dir: 'h', sizes: [0.5, 0.5],
children: [
this._tabsNode(['hierarchy']),
this._tabsNode(['inspector']),
],
},
this._tabsNode(['console']),
],
},
this._gameNode(),
this._tabsNode(['perf']),
],
};
};
/**
* 横屏默认(图2):上=层级|属性|游戏|性能,下=控制台通栏
*/
WorkbenchLayout.prototype._landscapeAnalyzeTree = function () {
return {
type: 'split', dir: 'v', sizes: [0.72, 0.28],
children: [
{
type: 'split', dir: 'h', sizes: [0.14, 0.16, 0.50, 0.20],
children: [
this._tabsNode(['hierarchy']),
this._tabsNode(['inspector']),
this._gameNode(),
this._tabsNode(['perf']),
],
},
this._tabsNode(['console']),
],
};
};
WorkbenchLayout.prototype._tabsNode = function (panels) {
return {
type: 'tabs',
id: 'leaf_' + (this._leafSeq++),
panels: panels.slice(),
active: panels[0] || '',
};
};
WorkbenchLayout.prototype._gameNode = function () {
return { type: 'game', id: 'leaf_game' };
};
})(window);