Commit d44c5884 authored by haiyoucuv's avatar haiyoucuv

1

parent 192acd9f
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="af35c04f-08f6-48ed-85db-2f94c60e87fd" name="Default Changelist" comment=""> <list default="true" id="af35c04f-08f6-48ed-85db-2f94c60e87fd" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/debug/engine.js" beforeDir="false" afterPath="$PROJECT_DIR$/debug/engine.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/debug/engine.js" beforeDir="false" afterPath="$PROJECT_DIR$/debug/engine.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/debug/engine.js.map" beforeDir="false" afterPath="$PROJECT_DIR$/debug/engine.js.map" afterDir="false" /> <change beforePath="$PROJECT_DIR$/debug/engine.js.map" beforeDir="false" afterPath="$PROJECT_DIR$/debug/engine.js.map" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/2d/display/Container.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/2d/display/Container.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/2d/display/Container.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/2d/display/Container.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/2d/display/Sprite.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/2d/display/Sprite.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/2d/display/Stage.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/2d/display/Stage.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/2d/text/TextField.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/2d/text/TextField.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/zeroing/decorators/AlignManager.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/zeroing/decorators/AlignManager.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/zeroing/game-warpper/view-effects.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/zeroing/game-warpper/view-effects.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/zeroing/decorators/auto-adjust.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/zeroing/decorators/auto-adjust.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/zeroing/launcher.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/zeroing/launcher.ts" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -271,11 +271,11 @@ ...@@ -271,11 +271,11 @@
<screen x="1680" y="-229" width="1920" height="1177" /> <screen x="1680" y="-229" width="1920" height="1177" />
</state> </state>
<state x="2327" y="157" key="git4idea.merge.GitPullDialog/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1587714144888" /> <state x="2327" y="157" key="git4idea.merge.GitPullDialog/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1587714144888" />
<state x="2305" y="36" width="670" height="676" key="search.everywhere.popup" timestamp="1589941828855"> <state x="2305" y="36" width="670" height="676" key="search.everywhere.popup" timestamp="1589969727327">
<screen x="1680" y="-229" width="1920" height="1177" /> <screen x="1680" y="-229" width="1920" height="1177" />
</state> </state>
<state x="2305" y="18" width="670" height="690" key="search.everywhere.popup/0.0.1680.1050/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587713287518" /> <state x="2305" y="18" width="670" height="690" key="search.everywhere.popup/0.0.1680.1050/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587713287518" />
<state x="2305" y="36" width="670" height="676" key="search.everywhere.popup/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1589941828855" /> <state x="2305" y="36" width="670" height="676" key="search.everywhere.popup/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1589969727327" />
<state x="570" y="254" width="670" height="590" key="search.everywhere.popup/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1587004990635" /> <state x="570" y="254" width="670" height="590" key="search.everywhere.popup/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1587004990635" />
<state x="570" y="254" width="670" height="590" key="search.everywhere.popup/35.23.1645.1027@35.23.1645.1027" timestamp="1589767535433" /> <state x="570" y="254" width="670" height="590" key="search.everywhere.popup/35.23.1645.1027@35.23.1645.1027" timestamp="1589767535433" />
</component> </component>
......
...@@ -1898,16 +1898,17 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -1898,16 +1898,17 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
AlignManager.prototype.flush = function () { AlignManager.prototype.flush = function () {
var _this = this; var _this = this;
this.alignList.forEach(function (v) { var list = this.alignList;
list.forEach(function (v) {
_this.autoSize(v); _this.autoSize(v);
_this.align(v); _this.align(v);
}); });
this.alignList.forEach(function (v) { list.forEach(function (v) {
if (v.alignMode === ALIGN_MODE.ONCE) { if (v.alignMode === ALIGN_MODE.ONCE) {
v.alignEnabled = false; v.alignEnabled = false;
} }
}); });
this.alignList.length = 0; list.length = 0;
}; };
AlignManager.prototype.align = function (that) { AlignManager.prototype.align = function (that) {
var _this = this; var _this = this;
...@@ -1921,7 +1922,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -1921,7 +1922,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
that.width = pW_Z - left - right; that.width = pW_Z - left - right;
} }
else { else {
toBoolean(percentWidth) && (tW_Z = that.width = pW_Z * percentWidth / 100); if (toBoolean(percentWidth)) {
tW_Z = that.width = pW_Z * percentWidth / 100;
}
if (toBoolean(horizonCenter)) { if (toBoolean(horizonCenter)) {
that.x = pW_Z / 2 - tW_Z / 2 + horizonCenter; that.x = pW_Z / 2 - tW_Z / 2 + horizonCenter;
} }
...@@ -1953,7 +1956,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -1953,7 +1956,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
AlignManager.prototype.autoSize = function (that) { AlignManager.prototype.autoSize = function (that) {
var len = that.children.length; var len = that.children.length;
if (len > 0) { if (len > 0) {
if (that.autoWidth && !toBoolean(that.right) && !toBoolean(that.percentWidth)) { if (that.autoWidth
&& !toBoolean(that.percentWidth)) {
var max = 0; var max = 0;
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
if (toBoolean(that.children[i].right)) if (toBoolean(that.children[i].right))
...@@ -1966,7 +1970,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -1966,7 +1970,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
that.width = max; that.width = max;
} }
if (that.autoHeight && !toBoolean(that.bottom) && !toBoolean(that.percentHeight)) { if (that.autoHeight
&& !toBoolean(that.percentHeight)) {
var max = 0; var max = 0;
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
if (toBoolean(that.children[i].bottom)) if (toBoolean(that.children[i].bottom))
...@@ -1982,8 +1987,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -1982,8 +1987,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
}; };
AlignManager.prototype.addAlign = function (obj) { AlignManager.prototype.addAlign = function (obj) {
if (this.alignList.indexOf(obj) < 0) { var list = this.alignList;
this.alignList.push(obj); if (list.indexOf(obj) < 0) {
list.push(obj);
} }
}; };
return AlignManager; return AlignManager;
...@@ -2051,6 +2057,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2051,6 +2057,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
bottom: NaN, bottom: NaN,
horizonCenter: NaN, horizonCenter: NaN,
verticalCenter: NaN, verticalCenter: NaN,
autoWidth: false,
autoHeight: false,
alignEnabled: true, alignEnabled: true,
alignMode: ALIGN_MODE.ALWAYS, alignMode: ALIGN_MODE.ALWAYS,
}; };
...@@ -2058,26 +2066,20 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2058,26 +2066,20 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this.makeDirty(); this.makeDirty();
} }
AdjustProxy.prototype.makeDirty = function () { AdjustProxy.prototype.makeDirty = function () {
this._sizeDirty = true;
this._host && alignMgr.addAlign(this._host); this._host && alignMgr.addAlign(this._host);
this._host && this._host.parent && this._host.parent.adjustProxy.makeDirty(); this._host && this._host.parent && this._host.parent.adjustProxy.makeDirty();
}; };
AdjustProxy.prototype.onAddedToStage = function (e) { AdjustProxy.prototype.onAddedToStage = function (e) {
this._host.addEventListener(Event.MAYBE_ALIGN, this.readyAlign, this); this._host.addEventListener(Event.MAYBE_ALIGN, this.makeDirty, this);
}; };
AdjustProxy.prototype.onRemovedFromStage = function (e) { AdjustProxy.prototype.onRemovedFromStage = function (e) {
this._host.removeEventListener(Event.MAYBE_ALIGN, this.readyAlign); this._host.removeEventListener(Event.MAYBE_ALIGN, this.makeDirty);
}; };
AdjustProxy.prototype.setFrom = function (adjustProxy) { AdjustProxy.prototype.setFrom = function (adjustProxy) {
for (var k in adjustProxy.data) { for (var k in adjustProxy.data) {
this.data[k] = adjustProxy.data[k]; this.data[k] = adjustProxy.data[k];
} }
}; };
AdjustProxy.prototype.readyAlign = function (e) {
this._sizeDirty = true;
this._host && alignMgr.addAlign(this._host);
this._host && this._host.parent && this._host.parent.adjustProxy.makeDirty();
};
return AdjustProxy; return AdjustProxy;
}()); }());
...@@ -3159,8 +3161,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -3159,8 +3161,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this._mouseChildren = true; _this._mouseChildren = true;
_this.__width = 0; _this.__width = 0;
_this.__height = 0; _this.__height = 0;
_this._autoWidth = false;
_this._autoHeight = false;
_this._instanceType = "Container"; _this._instanceType = "Container";
_this.children = []; _this.children = [];
_this._transform = _this.transform; _this._transform = _this.transform;
...@@ -3589,13 +3589,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -3589,13 +3589,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN); this.dispatchEvent(Event.MAYBE_ALIGN);
if (toBoolean(this.percentWidth) this.__width = (toBoolean(this.percentWidth) || (toBoolean(this.left) && toBoolean(this.right)))
|| (toBoolean(this.left) && toBoolean(this.right))) { ? 0
this.__width = 0; : value;
}
else {
this.__width = value;
}
} }
}, },
enumerable: true, enumerable: true,
...@@ -3617,40 +3613,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -3617,40 +3613,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN); this.dispatchEvent(Event.MAYBE_ALIGN);
if (toBoolean(this.percentHeight) this.__height = (toBoolean(this.percentHeight) || (toBoolean(this.top) && toBoolean(this.bottom)))
|| (toBoolean(this.top) && toBoolean(this.bottom))) { ? 0
this.__height = 0; : value;
}
else {
this.__height = value;
} }
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Container.prototype, "autoWidth", {
get: function () {
return this._autoWidth;
},
set: function (autoWidth) {
this._autoWidth = autoWidth;
this.right = NaN;
this.percentWidth = NaN;
this.adjustProxy.makeDirty();
},
enumerable: true,
configurable: true
});
Object.defineProperty(Container.prototype, "autoHeight", {
get: function () {
return this._autoHeight;
},
set: function (autoHeight) {
this._autoHeight = autoHeight;
this.bottom = NaN;
this.percentHeight = NaN;
this.adjustProxy.makeDirty();
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
...@@ -8510,7 +8476,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -8510,7 +8476,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
Stage.flushAll = function () { Stage.flushAll = function () {
if (!GlobalPro.startTime) if (!GlobalPro.startTime)
GlobalPro.startTime = Date.now(); GlobalPro.startTime = Date.now();
alignMgr.flush();
if (!Stage._pause) { if (!Stage._pause) {
var len = Stage.allUpdateObjList.length; var len = Stage.allUpdateObjList.length;
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
...@@ -21588,6 +21553,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -21588,6 +21553,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var stage = window['stage'] = new Stage(containerId || "game-container", designWidth || 750, designHeight || 1334, frameRate || 60, scaleMode || StageScaleMode.FIXED_WIDTH, rendererType || exports.RENDERER_TYPE.WEBGL, true, bgColor, autoResize); var stage = window['stage'] = new Stage(containerId || "game-container", designWidth || 750, designHeight || 1334, frameRate || 60, scaleMode || StageScaleMode.FIXED_WIDTH, rendererType || exports.RENDERER_TYPE.WEBGL, true, bgColor, autoResize);
initAutoLayout(stage); initAutoLayout(stage);
Stage.flushAll(); Stage.flushAll();
Stage.addUpdateObj(alignMgr);
stage.addEventListener(Event.ON_INIT_STAGE, function () { stage.addEventListener(Event.ON_INIT_STAGE, function () {
exports.gameStage = new GameStage(stage); exports.gameStage = new GameStage(stage);
setGlobalContext({ setGlobalContext({
......
This diff is collapsed.
...@@ -735,13 +735,9 @@ export default class Container extends DisplayObject { ...@@ -735,13 +735,9 @@ export default class Container extends DisplayObject {
this.dispatchEvent(Event.MAYBE_ALIGN); this.dispatchEvent(Event.MAYBE_ALIGN);
// 如果它设置了 percentWidth 或同时设置了 left 和 right 则表示他的宽度是相对的,则对于父级来说它的宽度永远是 0 // 如果它设置了 percentWidth 或同时设置了 left 和 right 则表示他的宽度是相对的,则对于父级来说它的宽度永远是 0
if (toBoolean(this.percentWidth) this.__width = (toBoolean(this.percentWidth) || (toBoolean(this.left) && toBoolean(this.right)))
|| (toBoolean(this.left) && toBoolean(this.right)) ? 0
) { : value;
this.__width = 0;
} else {
this.__width = value;
}
} }
} }
...@@ -774,43 +770,38 @@ export default class Container extends DisplayObject { ...@@ -774,43 +770,38 @@ export default class Container extends DisplayObject {
this.dispatchEvent(Event.MAYBE_ALIGN); this.dispatchEvent(Event.MAYBE_ALIGN);
// 如果它设置了 percentHeight 或同时设置了 top 和 bottom 则表示他的高度是相对的,则对于父级来说它的高度永远是 0 // 如果它设置了 percentHeight 或同时设置了 top 和 bottom 则表示他的高度是相对的,则对于父级来说它的高度永远是 0
if (toBoolean(this.percentHeight) this.__height = (toBoolean(this.percentHeight) || (toBoolean(this.top) && toBoolean(this.bottom)))
|| (toBoolean(this.top) && toBoolean(this.bottom)) ? 0
) { : value;
this.__height = 0;
} else {
this.__height = value;
}
} }
} }
protected __width = 0; // 忽略 相对宽度 的 宽度,在父级计算自动宽度的时候用到 protected __width = 0; // 忽略 相对宽度 的 宽度,在父级计算自动宽度的时候用到
protected __height = 0; // 忽略 相对高度 的 高度,在父级计算自动高度的时候用到 protected __height = 0; // 忽略 相对高度 的 高度,在父级计算自动高度的时候用到
protected _autoWidth = false; // 自动宽度? /// TODO 移到了auto-dujust里
protected _autoHeight = false; // 自动高度? // protected _autoWidth = false; // 自动宽度?
// protected _autoHeight = false; // 自动高度?
public get autoWidth() {
return this._autoWidth;
}
public get autoHeight() {
return this._autoHeight;
}
public set autoWidth(autoWidth) { // public get autoWidth() {
this._autoWidth = autoWidth; // return this._autoWidth;
this.right = NaN; /// TODO 不知道需不需要 // }
this.percentWidth = NaN; /// TODO 不知道需不需要 //
this.adjustProxy.makeDirty(); // public get autoHeight() {
} // return this._autoHeight;
// }
public set autoHeight(autoHeight) { // public set autoWidth(autoWidth) {
this._autoHeight = autoHeight; // if(autoWidth === this._autoWidth) return;
this.bottom = NaN; /// TODO 不知道需不需要 // this._autoWidth = autoWidth;
this.percentHeight = NaN; /// TODO 不知道需不需要 // this.adjustProxy.makeDirty();
this.adjustProxy.makeDirty(); // }
} //
// public set autoHeight(autoHeight) {
// if(autoHeight === this._autoHeight) return;
// this._autoHeight = autoHeight;
// this.adjustProxy.makeDirty();
// }
// public judgeAutoSize() { // public judgeAutoSize() {
// this.autoWidth = !(toBoolean(this.right) || toBoolean(this.percentWidth) || toBoolean(this._width)); // this.autoWidth = !(toBoolean(this.right) || toBoolean(this.percentWidth) || toBoolean(this._width));
......
...@@ -12,7 +12,7 @@ import {WebglRenderer} from "../renderers/WebglRenderer"; ...@@ -12,7 +12,7 @@ import {WebglRenderer} from "../renderers/WebglRenderer";
import {GDispatcher} from "../events/GDispatcher"; import {GDispatcher} from "../events/GDispatcher";
import CanvasRenderer from "../renderers/CanvasRenderer"; import CanvasRenderer from "../renderers/CanvasRenderer";
import {GlobalPro, isWebGLSupported} from "../utils/index"; import {GlobalPro, isWebGLSupported} from "../utils/index";
import { alignMgr } from "../../zeroing/decorators/AlignManager"; // import { alignMgr } from "../../zeroing/decorators/AlignManager";
//如果以后还出现帧率问题,使用ticker; //如果以后还出现帧率问题,使用ticker;
//兼容requestAnimationFrame //兼容requestAnimationFrame
...@@ -973,14 +973,14 @@ export class Stage extends Container { ...@@ -973,14 +973,14 @@ export class Stage extends Container {
if (!GlobalPro.startTime) GlobalPro.startTime = Date.now(); if (!GlobalPro.startTime) GlobalPro.startTime = Date.now();
//console.log('flushAll', Date.now()); //console.log('flushAll', Date.now());
alignMgr.flush();
if (!Stage._pause) { if (!Stage._pause) {
let len = Stage.allUpdateObjList.length; let len = Stage.allUpdateObjList.length;
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
Stage.allUpdateObjList[i] && Stage.allUpdateObjList[i].flush(); Stage.allUpdateObjList[i] && Stage.allUpdateObjList[i].flush();
} }
} }
// alignMgr.flush();
requestAnimationFrame(Stage.flushAll); requestAnimationFrame(Stage.flushAll);
} }
......
import { ALIGN_MODE } from "./auto-adjust"; import { ALIGN_MODE } from "./auto-adjust";
import { toBoolean } from "../utils/utils"; import { toBoolean } from "../utils/utils";
import { Container } from "../../2d/display/index";
/** /**
* 自适应管理器 * 自适应管理器
...@@ -9,6 +10,9 @@ class AlignManager { ...@@ -9,6 +10,9 @@ class AlignManager {
// 这个列表里的对象会在渲染前被自动调整 // 这个列表里的对象会在渲染前被自动调整
private alignList = []; private alignList = [];
// private alignList1 = [];
// private listJudge = true;
constructor() { constructor() {
...@@ -18,19 +22,28 @@ class AlignManager { ...@@ -18,19 +22,28 @@ class AlignManager {
* flash (渲染前) * flash (渲染前)
*/ */
public flush() { public flush() {
this.alignList.forEach((v) => { // let list = this.alignList1;
// if (this.listJudge) {
// list = this.alignList;
// }
let list = this.alignList;
list.forEach((v: Container) => {
// v.adjustProxy.resetDirty();
this.autoSize(v); // 去调整大小 this.autoSize(v); // 去调整大小
this.align(v); // 去自动对齐 this.align(v); // 去自动对齐
}); });
// 要在这里单独检查,因为对齐一次后可能遇到其父节点需要对齐导致其再对齐一次 // 要在这里单独检查,因为对齐一次后可能遇到其父节点需要对齐导致其再对齐一次
this.alignList.forEach((v) => { list.forEach((v) => {
if(v.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它 if (v.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它
v.alignEnabled = false; v.alignEnabled = false;
} }
}); });
// 干掉列表 // 干掉列表
this.alignList.length = 0; list.length = 0;
// this.listJudge = !this.listJudge;
} }
/** /**
...@@ -40,7 +53,7 @@ class AlignManager { ...@@ -40,7 +53,7 @@ class AlignManager {
private align(that) { private align(that) {
// if(that) // if(that)
if(!that.alignEnabled) return; // 如果的自动对齐关闭里则啥也不干 if (!that.alignEnabled) return; // 如果的自动对齐关闭里则啥也不干
// if(that.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它 // if(that.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它
// that.alignEnabled = false; // that.alignEnabled = false;
...@@ -54,7 +67,7 @@ class AlignManager { ...@@ -54,7 +67,7 @@ class AlignManager {
/** /**
* 计算 width 和 x 值 * 计算 width 和 x 值
*/ */
if(toBoolean(left) && toBoolean(right)) { // left right 都有则直接拉伸或缩小 if (toBoolean(left) && toBoolean(right)) { // left right 都有则直接拉伸或缩小
that.x = left; that.x = left;
...@@ -62,18 +75,23 @@ class AlignManager { ...@@ -62,18 +75,23 @@ class AlignManager {
} else { } else {
// 先设置下自己的 width // 先设置下自己的 width
toBoolean(percentWidth) && (tW_Z = that.width = pW_Z * percentWidth / 100); // toBoolean(percentWidth) && (tW_Z = that.width = pW_Z * percentWidth / 100, isChange = true);
if (toBoolean(percentWidth)) {
tW_Z = that.width = pW_Z * percentWidth / 100;
}
// 先考虑 horizonCenter 属性 // 先考虑 horizonCenter 属性
if(toBoolean(horizonCenter)) { if (toBoolean(horizonCenter)) {
// x 值 = 父节点的中间值 - 自己宽度的一半 - 居中差值 // x 值 = 父节点的中间值 - 自己宽度的一半 - 居中差值
that.x = pW_Z / 2 - tW_Z / 2 + horizonCenter; that.x = pW_Z / 2 - tW_Z / 2 + horizonCenter;
} else if(toBoolean(left)) { // 假如有左边距 } else if (toBoolean(left)) { // 假如有左边距
that.x = left; that.x = left;
} else if(toBoolean(right)) { // 假如有右边距 } else if (toBoolean(right)) { // 假如有右边距
that.x = pW_Z - right - tW_Z; that.x = pW_Z - right - tW_Z;
...@@ -83,7 +101,7 @@ class AlignManager { ...@@ -83,7 +101,7 @@ class AlignManager {
/** /**
* 计算 height 和 y 值 * 计算 height 和 y 值
*/ */
if(toBoolean(top) && toBoolean(bottom)) { // top bottom 都有则直接拉伸或缩小 if (toBoolean(top) && toBoolean(bottom)) { // top bottom 都有则直接拉伸或缩小
that.y = top; that.y = top;
...@@ -94,15 +112,15 @@ class AlignManager { ...@@ -94,15 +112,15 @@ class AlignManager {
toBoolean(percentHeight) && (tH_Z = that.height = pH_Z * percentHeight / 100); toBoolean(percentHeight) && (tH_Z = that.height = pH_Z * percentHeight / 100);
// 先考虑 horizonCenter 属性 // 先考虑 horizonCenter 属性
if(toBoolean(verticalCenter)) { if (toBoolean(verticalCenter)) {
// x 值 = 父节点的中间值 - 自己高度的一半 - 居中差值 // x 值 = 父节点的中间值 - 自己高度的一半 - 居中差值
that.y = pH_Z / 2 - tH_Z / 2 + verticalCenter; that.y = pH_Z / 2 - tH_Z / 2 + verticalCenter;
} else if(toBoolean(top)) { // 假如有 top } else if (toBoolean(top)) { // 假如有 top
that.y = top; that.y = top;
} else if(toBoolean(bottom)) { // 假如有 bottom } else if (toBoolean(bottom)) { // 假如有 bottom
that.y = pH_Z - bottom - tH_Z; that.y = pH_Z - bottom - tH_Z;
...@@ -120,10 +138,12 @@ class AlignManager { ...@@ -120,10 +138,12 @@ class AlignManager {
private autoSize(that) { private autoSize(that) {
let len = that.children.length let len = that.children.length
if(len > 0) { if (len > 0) {
// 检测本身的是否是可以自动宽 // 检测本身的是否是可以自动宽
if(that.autoWidth && !toBoolean(that.right) && !toBoolean(that.percentWidth)) { if (that.autoWidth
// && !toBoolean(that.right) /// TODO 我把它去掉了
&& !toBoolean(that.percentWidth)) {
// 找出子节点最小x // 找出子节点最小x
// let minX = 0; // let minX = 0;
// for(let i = 0; i < len; i++) { // for(let i = 0; i < len; i++) {
...@@ -139,11 +159,11 @@ class AlignManager { ...@@ -139,11 +159,11 @@ class AlignManager {
// 找出最右值 // 找出最右值
let max = 0; let max = 0;
for(let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
if(toBoolean(that.children[i].right)) continue; if (toBoolean(that.children[i].right)) continue;
let _x = that.children[i].x || 0; let _x = that.children[i].x || 0;
let _w = that.children[i].__width || 0; let _w = that.children[i].__width || 0;
if(_x + _w > max) { if (_x + _w > max) {
max = _x + _w; max = _x + _w;
} }
} }
...@@ -151,7 +171,9 @@ class AlignManager { ...@@ -151,7 +171,9 @@ class AlignManager {
} }
// 检测本身的是否是可以自动高 // 检测本身的是否是可以自动高
if(that.autoHeight && !toBoolean(that.bottom) && !toBoolean(that.percentHeight)) { if (that.autoHeight
// && !toBoolean(that.bottom) /// TODO 我把它去掉了
&& !toBoolean(that.percentHeight)) {
// 找出子节点最小y // 找出子节点最小y
// let minY = 0; // let minY = 0;
// for(let i = 1; i < len; i++) { // for(let i = 1; i < len; i++) {
...@@ -167,11 +189,11 @@ class AlignManager { ...@@ -167,11 +189,11 @@ class AlignManager {
// 找出最下值 // 找出最下值
let max = 0; let max = 0;
for(let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
if(toBoolean(that.children[i].bottom)) continue; if (toBoolean(that.children[i].bottom)) continue;
let _y = that.children[i].y || 0; let _y = that.children[i].y || 0;
let _h = that.children[i].__height || 0; let _h = that.children[i].__height || 0;
if(_y + _h > max) { if (_y + _h > max) {
max = _y + _h; max = _y + _h;
} }
} }
...@@ -185,8 +207,13 @@ class AlignManager { ...@@ -185,8 +207,13 @@ class AlignManager {
* @param obj * @param obj
*/ */
public addAlign(obj) { public addAlign(obj) {
if(this.alignList.indexOf(obj) < 0) { let list = this.alignList;
this.alignList.push(obj); // if (this.listJudge) {
// list = this.alignList1;
// }
if (list.indexOf(obj) < 0) {
list.push(obj);
} }
} }
} }
......
...@@ -18,8 +18,8 @@ export function applyAutoAdjust(ctor: Function) { ...@@ -18,8 +18,8 @@ export function applyAutoAdjust(ctor: Function) {
this.addEventListener(Event.REMOVED_FROM_STAGE, adjustProxy.onRemovedFromStage, adjustProxy); this.addEventListener(Event.REMOVED_FROM_STAGE, adjustProxy.onRemovedFromStage, adjustProxy);
}; };
let temp = new AdjustProxy(null); let temp = new AdjustProxy(null);
for(let key in temp.data) { for (let key in temp.data) {
if(key == 'alignMode' if (key == 'alignMode'
// || key == 'percentWidth' || key == 'percentHeight' // || key == 'percentWidth' || key == 'percentHeight'
) continue; ) continue;
...@@ -29,7 +29,7 @@ export function applyAutoAdjust(ctor: Function) { ...@@ -29,7 +29,7 @@ export function applyAutoAdjust(ctor: Function) {
}, },
set: function(v) { set: function(v) {
const adjustProxy: AdjustProxy = this.adjustProxy; const adjustProxy: AdjustProxy = this.adjustProxy;
if(adjustProxy.data[key] !== v && !(isNaN(adjustProxy.data[key]) && isNaN(v))) { if (adjustProxy.data[key] !== v && !(isNaN(adjustProxy.data[key]) && isNaN(v))) {
adjustProxy.data[key] = v; adjustProxy.data[key] = v;
adjustProxy.makeDirty(); adjustProxy.makeDirty();
} }
...@@ -79,11 +79,11 @@ export function applyAutoAdjust(ctor: Function) { ...@@ -79,11 +79,11 @@ export function applyAutoAdjust(ctor: Function) {
}, },
set: function(v) { set: function(v) {
const adjustProxy: AdjustProxy = this.adjustProxy; const adjustProxy: AdjustProxy = this.adjustProxy;
if(adjustProxy.data['alignMode'] !== v) { if (adjustProxy.data['alignMode'] !== v) {
adjustProxy.data['alignMode'] = v; adjustProxy.data['alignMode'] = v;
adjustProxy.makeDirty(); adjustProxy.makeDirty();
if(v == ALIGN_MODE.ALWAYS) this.alignEnabled = true; // 如果设置为 always 则自动开启 if (v == ALIGN_MODE.ALWAYS) this.alignEnabled = true; // 如果设置为 always 则自动开启
} }
}, },
enumerable: true, enumerable: true,
...@@ -111,6 +111,9 @@ class AdjustProxy { ...@@ -111,6 +111,9 @@ class AdjustProxy {
horizonCenter: NaN, horizonCenter: NaN,
verticalCenter: NaN, verticalCenter: NaN,
autoWidth:false,
autoHeight:false,
alignEnabled: true, alignEnabled: true,
alignMode: ALIGN_MODE.ALWAYS, alignMode: ALIGN_MODE.ALWAYS,
}; };
...@@ -124,13 +127,18 @@ class AdjustProxy { ...@@ -124,13 +127,18 @@ class AdjustProxy {
} }
makeDirty() { makeDirty() {
this._sizeDirty = true; // if (this._sizeDirty) return;
// this._sizeDirty = true;
this._host && alignMgr.addAlign(this._host); this._host && alignMgr.addAlign(this._host);
this._host && this._host.parent && this._host.parent.adjustProxy.makeDirty(); this._host && this._host.parent && this._host.parent.adjustProxy.makeDirty();
} }
// resetDirty() {
// this._sizeDirty = false;
// }
onAddedToStage(e) { onAddedToStage(e) {
this._host.addEventListener(Event.MAYBE_ALIGN, this.readyAlign, this); this._host.addEventListener(Event.MAYBE_ALIGN, this.makeDirty, this);
// this._host.parent.addEventListener(Event.MAYBE_ALIGN, this.align, this); // this._host.parent.addEventListener(Event.MAYBE_ALIGN, this.align, this);
// this._host.parent.addEventListener(Event.RESIZE, this.align, this); // this._host.parent.addEventListener(Event.RESIZE, this.align, this);
// this._host.addEventListener(Event.RESIZE, this.align, this); // this._host.addEventListener(Event.RESIZE, this.align, this);
...@@ -138,7 +146,7 @@ class AdjustProxy { ...@@ -138,7 +146,7 @@ class AdjustProxy {
} }
onRemovedFromStage(e) { onRemovedFromStage(e) {
this._host.removeEventListener(Event.MAYBE_ALIGN, this.readyAlign); this._host.removeEventListener(Event.MAYBE_ALIGN, this.makeDirty);
// this._host.parent.removeEventListener(Event.MAYBE_ALIGN, this.align); // this._host.parent.removeEventListener(Event.MAYBE_ALIGN, this.align);
// this._host.parent.removeEventListener(Event.RESIZE, this.align); // this._host.parent.removeEventListener(Event.RESIZE, this.align);
// this._host.removeEventListener(Event.RESIZE, this.align, this); // this._host.removeEventListener(Event.RESIZE, this.align, this);
...@@ -146,20 +154,23 @@ class AdjustProxy { ...@@ -146,20 +154,23 @@ class AdjustProxy {
} }
setFrom(adjustProxy: AdjustProxy) { setFrom(adjustProxy: AdjustProxy) {
for(let k in adjustProxy.data) { for (let k in adjustProxy.data) {
this.data[k] = adjustProxy.data[k]; this.data[k] = adjustProxy.data[k];
} }
} }
/** // /**
* align 方式 T + 1 // * align 方式 T + 1
* @param e // * @param e
*/ // */
private readyAlign(e) { // private readyAlign(e) {
this._sizeDirty = true; // if (this._sizeDirty == true) {
this._host && alignMgr.addAlign(this._host); // return;
this._host && this._host.parent && this._host.parent.adjustProxy.makeDirty(); // 它爸爸也要设置一次。可能有autoSize // }
} // this._sizeDirty = true;
// this._host && alignMgr.addAlign(this._host);
// this._host && this._host.parent && this._host.parent.adjustProxy.makeDirty(); // 它爸爸也要设置一次。可能有autoSize
// }
// autoSize() { // autoSize() {
// let that = this._host.parent; // let that = this._host.parent;
......
...@@ -70,7 +70,7 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) { ...@@ -70,7 +70,7 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) {
initAutoLayout(stage); initAutoLayout(stage);
Stage.flushAll(); Stage.flushAll();
// Stage.addUpdateObj(alignMgr); Stage.addUpdateObj(alignMgr);
stage.addEventListener(Event.ON_INIT_STAGE, () => { stage.addEventListener(Event.ON_INIT_STAGE, () => {
gameStage = new GameStage(stage); gameStage = new GameStage(stage);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment