Commit cf66b590 authored by rockyl's avatar rockyl

修复

parent 5e81e6a4
...@@ -12,6 +12,9 @@ import {afterConstructor} from "../../zeroing/decorators/after-constructor"; ...@@ -12,6 +12,9 @@ import {afterConstructor} from "../../zeroing/decorators/after-constructor";
import {injectProperties, instantiateScript, toBoolean} from "../../zeroing/utils/index"; import {injectProperties, instantiateScript, toBoolean} from "../../zeroing/utils/index";
import {isUI} from "../../zeroing/game-warpper/nodes/IUIComponent"; import {isUI} from "../../zeroing/game-warpper/nodes/IUIComponent";
import Transform from "../math/Transform"; import Transform from "../math/Transform";
import {ScrollView} from "../../zeroing/game-warpper/nodes/ScrollView";
const skipIndexTypes = ['ScrollView', 'ScrollList'];
/** /**
* 容器类 * 容器类
...@@ -288,8 +291,12 @@ export default class Container extends DisplayObject { ...@@ -288,8 +291,12 @@ export default class Container extends DisplayObject {
while (node.parent) { while (node.parent) {
let child = node; let child = node;
node = node.parent; node = node.parent;
let index = node.children.indexOf(child); if (skipIndexTypes.indexOf(node.instanceType) >= 0) {
path.unshift(index);
} else {
let index = node.children.indexOf(child);
path.unshift(index);
}
if (node === untilNode) { if (node === untilNode) {
break; break;
} }
...@@ -511,19 +518,19 @@ export default class Container extends DisplayObject { ...@@ -511,19 +518,19 @@ export default class Container extends DisplayObject {
this._bounds.height = this._height; this._bounds.height = this._height;
}*/ }*/
if (widthSetted || heightSetted) { if (widthSetted || heightSetted) {
const rect = this._localBoundsSelf; const rect = this._localBoundsSelf;
var matrix = this.transform.worldMatrix; var matrix = this.transform.worldMatrix;
matrix.transformPoint(rect.x, rect.y, DisplayObject._p1); matrix.transformPoint(rect.x, rect.y, DisplayObject._p1);
matrix.transformPoint(rect.x + rect.width, rect.y, DisplayObject._p2); matrix.transformPoint(rect.x + rect.width, rect.y, DisplayObject._p2);
matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3); matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3);
matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4); matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4);
Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4); Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4);
return true; return true;
} }
return false; return false;
} }
/** /**
* 检测点是否在任何child上 * 检测点是否在任何child上
...@@ -533,7 +540,7 @@ export default class Container extends DisplayObject { ...@@ -533,7 +540,7 @@ export default class Container extends DisplayObject {
//如果不可见 //如果不可见
if (!this.visible) return null if (!this.visible) return null
//如果禁止子级的鼠标事件 //如果禁止子级的鼠标事件
if (isMouseEvent && !this.mouseChildren){ if (isMouseEvent && !this.mouseChildren) {
return this.hitTestSelf(globalPoint); return this.hitTestSelf(globalPoint);
} }
var children = this.children; var children = this.children;
...@@ -724,103 +731,103 @@ export default class Container extends DisplayObject { ...@@ -724,103 +731,103 @@ export default class Container extends DisplayObject {
this.mouseChildren = false; this.mouseChildren = false;
} }
/** /**
* 一般用于获取宽高并设置 * 一般用于获取宽高并设置
* 包括子级的,容器的尽量少用,子类可重写 * 包括子级的,容器的尽量少用,子类可重写
* @member {number} * @member {number}
*/ */
get width(): number { get width(): number {
let value = this._width; let value = this._width;
return !value && value != 0 ? this.scale.x * this.getLocalBounds().width : value; return !value && value != 0 ? this.scale.x * this.getLocalBounds().width : value;
} }
set width(value: number) { set width(value: number) {
// const width = this.getLocalBounds().width; // const width = this.getLocalBounds().width;
// if (width !== 0) { // if (width !== 0) {
// this.scale.x = value / width; // this.scale.x = value / width;
// } else { // } else {
// this.scale.x = 1; // this.scale.x = 1;
// } // }
if (this._width !== value) { if (this._width !== value) {
if (!value && value != 0) { if (!value && value != 0) {
this._width = undefined; this._width = undefined;
} else { } else {
//子类有用,有_width,才需设置scaleX //子类有用,有_width,才需设置scaleX
this._width = value; this._width = value;
this._localBoundsSelf.width = value; this._localBoundsSelf.width = value;
//if (this.stage) this.stage.layoutInvalid = true; //if (this.stage) this.stage.layoutInvalid = true;
} }
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN); this.dispatchEvent(Event.MAYBE_ALIGN);
// 如果它设置了 percentWidth 或同时设置了 left 和 right 则表示他的宽度是相对的,则对于父级来说它的宽度永远是 0 // 如果它设置了 percentWidth 或同时设置了 left 和 right 则表示他的宽度是相对的,则对于父级来说它的宽度永远是 0
this.__width = (toBoolean(this.percentWidth) || (toBoolean(this.left) && toBoolean(this.right))) this.__width = (toBoolean(this.percentWidth) || (toBoolean(this.left) && toBoolean(this.right)))
? 0 ? 0
: value; : value;
} }
} }
/** /**
* 高度同width * 高度同width
* @member {number} * @member {number}
*/ */
get height(): number { get height(): number {
let value = this._height; let value = this._height;
return !value && value != 0 ? this.scale.y * this.getLocalBounds().height : value; return !value && value != 0 ? this.scale.y * this.getLocalBounds().height : value;
} }
set height(value: number) { set height(value: number) {
// const height = this.getLocalBounds().height; // const height = this.getLocalBounds().height;
// if (height !== 0) { // if (height !== 0) {
// this.scale.y = value / height; // this.scale.y = value / height;
// } else { // } else {
// this.scale.y = 1; // this.scale.y = 1;
// } // }
if (!value && value != 0) { if (!value && value != 0) {
this._height = undefined; this._height = undefined;
} else { } else {
if (this._height !== value) { if (this._height !== value) {
this._height = value; this._height = value;
this._localBoundsSelf.height = value; this._localBoundsSelf.height = value;
//if (this.stage) this.stage.layoutInvalid = true; //if (this.stage) this.stage.layoutInvalid = true;
} }
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN); this.dispatchEvent(Event.MAYBE_ALIGN);
// 如果它设置了 percentHeight 或同时设置了 top 和 bottom 则表示他的高度是相对的,则对于父级来说它的高度永远是 0 // 如果它设置了 percentHeight 或同时设置了 top 和 bottom 则表示他的高度是相对的,则对于父级来说它的高度永远是 0
this.__height = (toBoolean(this.percentHeight) || (toBoolean(this.top) && toBoolean(this.bottom))) this.__height = (toBoolean(this.percentHeight) || (toBoolean(this.top) && toBoolean(this.bottom)))
? 0 ? 0
: value; : value;
} }
} }
protected __width = 0; // 忽略 相对宽度 的 宽度,在父级计算自动宽度的时候用到 protected __width = 0; // 忽略 相对宽度 的 宽度,在父级计算自动宽度的时候用到
protected __height = 0; // 忽略 相对高度 的 高度,在父级计算自动高度的时候用到 protected __height = 0; // 忽略 相对高度 的 高度,在父级计算自动高度的时候用到
get x(): number { get x(): number {
return this.position.x; return this.position.x;
} }
set x(value: number) { set x(value: number) {
if (value == this.transform.position.x) return; if (value == this.transform.position.x) return;
this.transform.position.x = value; this.transform.position.x = value;
this.dispatchEvent(Event.MAYBE_ALIGN); this.dispatchEvent(Event.MAYBE_ALIGN);
} }
get y(): number { get y(): number {
return this.position.y; return this.position.y;
} }
set y(value: number) { set y(value: number) {
if (value == this.transform.position.y) return; if (value == this.transform.position.y) return;
this.transform.position.y = value; this.transform.position.y = value;
this.dispatchEvent(Event.MAYBE_ALIGN); this.dispatchEvent(Event.MAYBE_ALIGN);
} }
clone(withEvents = false, withScripts = false) { clone(withEvents = false, withScripts = false) {
let target = this.constructor.apply(Object.create(this.constructor.prototype)); let target = this.constructor.apply(Object.create(this.constructor.prototype));
......
...@@ -9,15 +9,15 @@ import {IUIComponent} from "./IUIComponent"; ...@@ -9,15 +9,15 @@ import {IUIComponent} from "./IUIComponent";
export const proxyMethods = [ export const proxyMethods = [
'onChildrenChange', 'onChildrenChange',
'addChild', 'addChild',
//'addChildAt', 'addChildAt',
//'swapChildren', 'swapChildren',
//'getChildIndex', 'getChildIndex',
//'setChildIndex', 'setChildIndex',
//'getChildAt', 'getChildAt',
//'getChildByName', 'getChildByName',
//'removeChild', 'removeChild',
//'removeChildAt', 'removeChildAt',
//'removeChildren', 'removeChildren',
]; ];
export class ScrollView extends ScrollViewBase implements IUIComponent { export class ScrollView extends ScrollViewBase implements IUIComponent {
......
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