Commit 20a02e96 authored by rockyl's avatar rockyl

修复scale找不到的问题

parent d6398ae8
......@@ -11,7 +11,6 @@
"rollup-plugin-progress": "^1.1.2"
},
"devDependencies": {
"dts-bundle": "^0.7.3",
"dts-bundle-generator": "^4.3.0",
"glob": "^7.1.6",
"rollup-plugin-commonjs": "^10.1.0",
......@@ -22,7 +21,6 @@
"typescript": "^2.7.2"
},
"scripts": {
"declare": "node scripts/declare.js src/index.ts",
"dev": "rollup -c -m -w",
"build": "rollup -c -o dist/engine.js",
"build:prod": "rollup -c -o dist/engine.min.js --environment BUILD:production",
......
......@@ -510,6 +510,9 @@ export class DisplayObject extends EventDispatcher {
* @member {Point|ObservablePoint}
*/
get scale() {
if(this.destroyed){
return 1;
}
return this.transform.scale;
}
......
import { ALIGN_MODE, AUTO_SIZE_MODE } from "./auto-adjust";
import { toBoolean } from "../utils/utils";
import { Container } from "../../2d/display/index";
import {ALIGN_MODE, AUTO_SIZE_MODE} from "./auto-adjust";
import {toBoolean} from "../utils/utils";
import {Container} from "../../2d/display/index";
/**
* 自适应管理器
......@@ -8,241 +8,247 @@ import { Container } from "../../2d/display/index";
*/
class AlignManager {
// 这个列表里的对象会在渲染前被自动调整
private alignList = [];
// 这个列表里的对象会在渲染前被自动调整
private alignList = [];
constructor() {
}
/**
* flash (渲染前)
*/
public flush() {
constructor() {
const list = this.alignList;
}
list.forEach((v: Container) => {
if(v.destroyed){
return;
}
this.autoSize(v); // 去调整大小
this.align(v); // 去自动对齐
});
/**
* flash (渲染前)
*/
public flush() {
// 要在这里单独检查,因为对齐一次后可能遇到其父节点需要对齐导致其再对齐一次
list.forEach((v) => {
if(v.destroyed){
return;
}
if (v.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它
v.alignEnabled = false;
}
});
// 干掉列表
list.length = 0;
}
const list = this.alignList;
/**
* align
* @param that
*/
private align(that) {
list.forEach((v: Container) => {
this.autoSize(v); // 去调整大小
this.align(v); // 去自动对齐
});
if (!that.alignEnabled) return; // 如果的自动对齐关闭里则啥也不干
// 要在这里单独检查,因为对齐一次后可能遇到其父节点需要对齐导致其再对齐一次
list.forEach((v) => {
if (v.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它
v.alignEnabled = false;
}
});
// 干掉列表
list.length = 0;
}
// if(that.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它
// that.alignEnabled = false;
// }
/**
* align
* @param that
*/
private align(that) {
const {
percentWidth, percentHeight,
top, bottom, left, right,
percentTop, percentBottom, percentLeft, percentRight,
horizonCenter, verticalCenter
} = that;
if (!that.alignEnabled) return; // 如果的自动对齐关闭里则啥也不干
// if(that.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它
// that.alignEnabled = false;
// }
const {
percentWidth, percentHeight,
top, bottom, left, right,
percentTop, percentBottom, percentLeft, percentRight,
horizonCenter, verticalCenter
} = that;
let {_width: tW_Z = 0, _height: tH_Z = 0} = that;
const {_width: pW_Z = 0, _height: pH_Z = 0} = (that.parent || {});
/// TODO null / 100 == 0 ?????? wtf!!!! 我裂开了
// percentWidth /= 100;
// percentHeight /= 100;
// percentTop /= 100;
// percentBottom /= 100;
// percentLeft /= 100;
// percentRight /= 100;
const judgePL = toBoolean(percentLeft)
, judgePR = toBoolean(percentRight)
, judgePT = toBoolean(percentTop)
, judgePB = toBoolean(percentBottom);
// 先转化一下
const _left = judgePL ? percentLeft / 100 * pW_Z : left
, _right = judgePR ? percentRight / 100 * pW_Z : right
, _top = judgePT ? percentTop / 100 * pH_Z : top
, _bottom = judgePB ? percentBottom / 100 * pH_Z : bottom;
/**
* 计算 width 和 x 值
*/
if (toBoolean(_left) && toBoolean(_right)) { // _left _right 都有则直接拉伸或缩小
that.x = _left;
that.width = pW_Z - _left - _right;
} else {
// 先设置下自己的 width
if(toBoolean(percentWidth)){
tW_Z = that.width = pW_Z * percentWidth / 100
}else{
tW_Z = that.width;
}
// 先考虑 horizonCenter 属性
if (toBoolean(horizonCenter)) {
// x 值 = 父节点的中间值 - 自己宽度的一半 - 居中差值
that.x = pW_Z / 2 - tW_Z / 2 + horizonCenter;
} else if (toBoolean(_left)) { // 假如有 _left
that.x = _left;
} else if (toBoolean(_right)) { // 假如有 _right
that.x = pW_Z - _right - tW_Z;
}
}
/**
* 计算 height 和 y 值
*/
if (toBoolean(_top) && toBoolean(_bottom)) { // _top _bottom 都有则直接拉伸或缩小
that.y = _top;
that.height = pH_Z - _top - _bottom;
} else {
// 先设置下自己的 height
if(toBoolean(percentHeight)){
tH_Z = that.height = pH_Z * percentHeight / 100
}else{
tH_Z = that.height;
}
// 先考虑 horizonCenter 属性
if (toBoolean(verticalCenter)) {
// x 值 = 父节点的中间值 - 自己高度的一半 - 居中差值
that.y = pH_Z / 2 - tH_Z / 2 + verticalCenter;
} else if (toBoolean(_top)) { // 假如有 _top
that.y = _top;
} else if (toBoolean(_bottom)) { // 假如有 _bottom
that.y = pH_Z - _bottom - tH_Z;
}
}
if(that.children){
that.children.forEach(v => this.align(v));
}
}
/**
* 自动大小
* @param that
*/
private autoSize(that) {
if(!that.children){
return;
}
const len = that.children.length
if (len > 0) {
// 检测本身的是否是可以自动宽
// if (that.autoWidth
if (that.autoSizeMode === AUTO_SIZE_MODE.ALL
|| that.autoSizeMode === AUTO_SIZE_MODE.WIDTH
// && !toBoolean(that.right) /// TODO 我把它注释了 注释这行可以让容器设置了 right 后反向撑开,保持 right 边距不变
&& !toBoolean(that.percentWidth)) {
/// TODO 下面这段注释的代码可以实现让其左边撑开,不过还有未知bug
// 找出子节点最小x
// let minX = 0;
// for(let i = 0; i < len; i++) {
// if(that.children[i].x < minX) {
// minX = that.children[i].x;
// }
// }
// if(minX < 0) {
// that.children.forEach(v => v.x -= minX);
// that.x += minX;
// that.width -= minX;
// }
// 找出最右值
let maxR = 0;
for (let i = 0; i < len; i++) {
if (toBoolean(that.children[i].right)) continue; /// TODO 开启这个,忽略带 right 值的子节点
let _x = that.children[i].x || 0;
let _w = that.children[i].__width || 0;
(_x + _w > maxR) ? maxR = _x + _w : 0;
}
that.width = maxR;
}
// 检测本身的是否是可以自动高
if (that.autoSizeMode === AUTO_SIZE_MODE.ALL
|| that.autoSizeMode === AUTO_SIZE_MODE.HEIGHT
// && !toBoolean(that.bottom) /// TODO 我把它注释了 注释这行可以让容器设置了 bottom 后反向撑开,保持 bottom 边距不变
&& !toBoolean(that.percentHeight)) {
/// TODO 下面这段注释的代码可以实现让其上边撑开,不过还有未知bug
// 找出子节点最小y
// let minY = 0;
// for(let i = 1; i < len; i++) {
// if(that.children[i].y < minY) {
// minY = that.children[i].y;
// }
// }
// if(minY < 0) {
// that.children.forEach(v => v.y -= minY);
// that.y += minY;
// that.height -= minY;
// }
// 找出最下值
let maxB = 0;
for (let i = 0; i < len; i++) {
if (toBoolean(that.children[i].bottom)) continue; /// TODO 开启这个,忽略带 bottom 值的子节点
let _y = that.children[i].y || 0;
let _h = that.children[i].__height || 0;
(_y + _h > maxB) ? maxB = _y + _h : 0;
}
that.height = maxB;
}
}
}
/**
* 添加一个变脏的对象
* @param obj
*/
public addAlign(obj) {
const list = this.alignList;
if (list.indexOf(obj) < 0) {
list.push(obj);
}
}
let {_width: tW_Z = 0, _height: tH_Z = 0} = that;
const {_width: pW_Z = 0, _height: pH_Z = 0} = (that.parent || {});
/// TODO null / 100 == 0 ?????? wtf!!!! 我裂开了
// percentWidth /= 100;
// percentHeight /= 100;
// percentTop /= 100;
// percentBottom /= 100;
// percentLeft /= 100;
// percentRight /= 100;
const judgePL = toBoolean(percentLeft)
, judgePR = toBoolean(percentRight)
, judgePT = toBoolean(percentTop)
, judgePB = toBoolean(percentBottom);
// 先转化一下
const _left = judgePL ? percentLeft / 100 * pW_Z : left
, _right = judgePR ? percentRight / 100 * pW_Z : right
, _top = judgePT ? percentTop / 100 * pH_Z : top
, _bottom = judgePB ? percentBottom / 100 * pH_Z : bottom;
/**
* 计算 width 和 x 值
*/
if (toBoolean(_left) && toBoolean(_right)) { // _left _right 都有则直接拉伸或缩小
that.x = _left;
that.width = pW_Z - _left - _right;
} else {
// 先设置下自己的 width
if (toBoolean(percentWidth)) {
tW_Z = that.width = pW_Z * percentWidth / 100
} else {
tW_Z = that.width;
}
// 先考虑 horizonCenter 属性
if (toBoolean(horizonCenter)) {
// x 值 = 父节点的中间值 - 自己宽度的一半 - 居中差值
that.x = pW_Z / 2 - tW_Z / 2 + horizonCenter;
} else if (toBoolean(_left)) { // 假如有 _left
that.x = _left;
} else if (toBoolean(_right)) { // 假如有 _right
that.x = pW_Z - _right - tW_Z;
}
}
/**
* 计算 height 和 y 值
*/
if (toBoolean(_top) && toBoolean(_bottom)) { // _top _bottom 都有则直接拉伸或缩小
that.y = _top;
that.height = pH_Z - _top - _bottom;
} else {
// 先设置下自己的 height
if (toBoolean(percentHeight)) {
tH_Z = that.height = pH_Z * percentHeight / 100
} else {
tH_Z = that.height;
}
// 先考虑 horizonCenter 属性
if (toBoolean(verticalCenter)) {
// x 值 = 父节点的中间值 - 自己高度的一半 - 居中差值
that.y = pH_Z / 2 - tH_Z / 2 + verticalCenter;
} else if (toBoolean(_top)) { // 假如有 _top
that.y = _top;
} else if (toBoolean(_bottom)) { // 假如有 _bottom
that.y = pH_Z - _bottom - tH_Z;
}
}
if (that.children) {
that.children.forEach(v => this.align(v));
}
}
/**
* 自动大小
* @param that
*/
private autoSize(that) {
if (!that.children) {
return;
}
const len = that.children.length
if (len > 0) {
// 检测本身的是否是可以自动宽
// if (that.autoWidth
if (that.autoSizeMode === AUTO_SIZE_MODE.ALL
|| that.autoSizeMode === AUTO_SIZE_MODE.WIDTH
// && !toBoolean(that.right) /// TODO 我把它注释了 注释这行可以让容器设置了 right 后反向撑开,保持 right 边距不变
&& !toBoolean(that.percentWidth)) {
/// TODO 下面这段注释的代码可以实现让其左边撑开,不过还有未知bug
// 找出子节点最小x
// let minX = 0;
// for(let i = 0; i < len; i++) {
// if(that.children[i].x < minX) {
// minX = that.children[i].x;
// }
// }
// if(minX < 0) {
// that.children.forEach(v => v.x -= minX);
// that.x += minX;
// that.width -= minX;
// }
// 找出最右值
let maxR = 0;
for (let i = 0; i < len; i++) {
if (toBoolean(that.children[i].right)) continue; /// TODO 开启这个,忽略带 right 值的子节点
let _x = that.children[i].x || 0;
let _w = that.children[i].__width || 0;
(_x + _w > maxR) ? maxR = _x + _w : 0;
}
that.width = maxR;
}
// 检测本身的是否是可以自动高
if (that.autoSizeMode === AUTO_SIZE_MODE.ALL
|| that.autoSizeMode === AUTO_SIZE_MODE.HEIGHT
// && !toBoolean(that.bottom) /// TODO 我把它注释了 注释这行可以让容器设置了 bottom 后反向撑开,保持 bottom 边距不变
&& !toBoolean(that.percentHeight)) {
/// TODO 下面这段注释的代码可以实现让其上边撑开,不过还有未知bug
// 找出子节点最小y
// let minY = 0;
// for(let i = 1; i < len; i++) {
// if(that.children[i].y < minY) {
// minY = that.children[i].y;
// }
// }
// if(minY < 0) {
// that.children.forEach(v => v.y -= minY);
// that.y += minY;
// that.height -= minY;
// }
// 找出最下值
let maxB = 0;
for (let i = 0; i < len; i++) {
if (toBoolean(that.children[i].bottom)) continue; /// TODO 开启这个,忽略带 bottom 值的子节点
let _y = that.children[i].y || 0;
let _h = that.children[i].__height || 0;
(_y + _h > maxB) ? maxB = _y + _h : 0;
}
that.height = maxB;
}
}
}
/**
* 添加一个变脏的对象
* @param obj
*/
public addAlign(obj) {
const list = this.alignList;
if (list.indexOf(obj) < 0) {
list.push(obj);
}
}
}
function tt(...v) {
for (let i = 0; i < v.length; i++) {
if (!toBoolean(v[i])) return false;
}
return true;
for (let i = 0; i < v.length; i++) {
if (!toBoolean(v[i])) return false;
}
return true;
}
export let alignMgr = new AlignManager();
......@@ -151,7 +151,6 @@ export class GameStage extends Node {
start() {
const {options: {entrySceneView,},} = this._config;
setTimeout(async () => {
let sceneEntry = await this.instantiateView(entrySceneView);
if (sceneEntry) {
......
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