phaser3-rex-plugins
Version:
1,596 lines (1,328 loc) • 774 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.rexscrollablepanel = factory());
})(this, (function () { 'use strict';
const MinVersion = 60;
var IsChecked = false;
var CheckP3Version = function (minVersion) {
if (IsChecked) {
return;
}
if (minVersion === undefined) {
minVersion = MinVersion;
}
var version = Phaser.VERSION.split('.');
var mainVersion = parseInt(version[0]);
if (mainVersion === 3) {
var currentVersion = parseInt(version[1]);
if (currentVersion < minVersion) {
console.error(`Minimum supported version : ${mainVersion}.${currentVersion}`);
}
} else {
console.error(`Can't supported version : ${mainVersion}`);
}
IsChecked = true;
};
var WebGLRenderer$1 = function (renderer, container, camera) {
camera.addToRenderList(container);
if (!container.layerRendererEnable) {
return;
}
// Won't apply container's alpha to children
var rendererLayer = container.rendererLayer;
if (!rendererLayer) {
return;
}
var children = rendererLayer.list;
var childCount = children.length;
if (childCount === 0) {
return;
}
rendererLayer.depthSort();
renderer.pipelines.preBatch(container);
var layerHasBlendMode = (container.blendMode !== -1);
if (!layerHasBlendMode) {
// If Layer is SKIP_TEST then set blend mode to be Normal
renderer.setBlendMode(0);
}
for (var i = 0; i < childCount; i++) {
var child = children[i];
if (!child.willRender(camera)) {
continue;
}
if (!layerHasBlendMode && child.blendMode !== renderer.currentBlendMode) {
// If Layer doesn't have its own blend mode, then a child can have one
renderer.setBlendMode(child.blendMode);
}
var mask = child.mask;
if (mask) {
mask.preRenderWebGL(renderer, child, camera);
}
var type = child.type;
if (type !== renderer.currentType) {
renderer.newType = true;
renderer.currentType = type;
}
renderer.nextTypeMatch = (i < childCount - 1) ? (children[i + 1].type === renderer.currentType) : false;
// Render
child.renderWebGL(renderer, child, camera);
if (mask) {
mask.postRenderWebGL(renderer, camera);
}
renderer.newType = false;
}
renderer.pipelines.postBatch(container);
};
var CanvasRenderer$1 = function (renderer, container, camera) {
camera.addToRenderList(container);
if (!container.layerRendererEnable) {
return;
}
// Won't apply container's alpha to children
var rendererLayer = container.rendererLayer;
if (!rendererLayer) {
return;
}
var children = rendererLayer.list;
if (children.length === 0) {
return;
}
rendererLayer.depthSort();
var layerHasBlendMode = (container.blendMode !== -1);
if (!layerHasBlendMode) {
// If Layer is SKIP_TEST then set blend mode to be Normal
renderer.setBlendMode(0);
}
if (container.mask) {
container.mask.preRenderCanvas(renderer, null, camera);
}
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (!child.willRender(camera)) {
continue;
}
if (!layerHasBlendMode && child.blendMode !== renderer.currentBlendMode) {
// If Layer doesn't have its own blend mode, then a child can have one
renderer.setBlendMode(child.blendMode);
}
// Render
child.renderCanvas(renderer, child, camera);
}
if (container.mask) {
container.mask.postRenderCanvas(renderer);
}
};
var Renderer = {
renderWebGL: WebGLRenderer$1,
renderCanvas: CanvasRenderer$1
};
const List = Phaser.Structs.List;
const StableSort = Phaser.Utils.Array.StableSort;
const GameObjectEvents = Phaser.GameObjects.Events;
const SceneEvents = Phaser.Scenes.Events;
class ChildrenDisplayList extends List {
constructor(parent) {
super(parent.scene);
this.parent = parent;
this.scene = parent.scene;
this.events = this.scene.sys.events;
this.active = false;
this.sortChildrenFlag = false;
this.addCallback = this.addChildCallback;
this.removeCallback = this.removeChildCallback;
}
addChildCallback(gameObject) {
var displayList = gameObject.displayList;
if (displayList && displayList !== this) {
gameObject.removeFromDisplayList();
}
if (gameObject.parentContainer) {
gameObject.parentContainer.remove(gameObject);
}
if (!gameObject.displayList) {
this.queueDepthSort();
gameObject.displayList = this;
gameObject.emit(GameObjectEvents.ADDED_TO_SCENE, gameObject, this.scene);
this.events.emit(SceneEvents.ADDED_TO_SCENE, gameObject, this.scene);
}
}
removeChildCallback(gameObject) {
this.queueDepthSort();
if (gameObject.displayList === this) {
gameObject.displayList = null;
}
gameObject.emit(GameObjectEvents.REMOVED_FROM_SCENE, gameObject, this.scene);
this.events.emit(SceneEvents.REMOVED_FROM_SCENE, gameObject, this.scene);
}
queueDepthSort() {
this.sortChildrenFlag = true;
return this;
}
depthSort() {
if (!this.sortChildrenFlag || this.list.length < 2) {
this.sortChildrenFlag = false;
return this;
}
StableSort(this.list, this.sortByDepth);
this.sortChildrenFlag = false;
return this;
}
sortByDepth(childA, childB) {
return childA._depth - childB._depth;
}
}
CheckP3Version();
const Zone$1 = Phaser.GameObjects.Zone;
const AddItem = Phaser.Utils.Array.Add;
const RemoveItem$5 = Phaser.Utils.Array.Remove;
let Base$1 = class Base extends Zone$1 {
constructor(scene, x, y, width, height) {
if (x === undefined) {
x = 0;
}
if (y === undefined) {
y = 0;
}
if (width === undefined) {
width = 1;
}
if (height === undefined) {
height = 1;
}
super(scene, x, y, width, height);
this.children = [];
/*
Internal layer-like renderer
All children will be put into this internal layer, instead of displayList of scene,
and Base/ContainerLite will be very bottom of all children
*/
this.layerRendererEnable = false;
this.rendererLayer = undefined;
}
destroy(fromScene) {
// This Game Object has already been destroyed
if (!this.scene || this.ignoreDestroy) {
return;
}
if (fromScene) {
// Stop scene
var child;
for (var i = this.children.length - 1; i >= 0; i--) {
child = this.children[i];
if (!child.parentContainer && // Not in container
(
!child.displayList || // Not in any display list
(child.displayList === this.rendererLayer) // In internal children display list
)
) {
// Destroy child which is not in scene, container, or layer manually
child.destroy(fromScene);
}
}
}
// Destroy/remove children
this.clear(!fromScene);
super.destroy(fromScene);
this.rendererLayer = undefined;
}
contains(gameObject) {
return (this.children.indexOf(gameObject) !== -1);
}
add(gameObjects) {
AddItem(this.children, gameObjects, 0,
// Callback of item added
function (gameObject) {
gameObject.once('destroy', this.onChildDestroy, this);
this.addChildCallback(gameObject);
}, this);
return this;
}
remove(gameObjects, destroyChild) {
RemoveItem$5(this.children, gameObjects,
// Callback of item removed
function (gameObject) {
gameObject.off('destroy', this.onChildDestroy, this);
this.removeChildCallback(gameObject, destroyChild);
if (destroyChild) {
gameObject.destroy();
}
}, this);
return this;
}
// Overwrite it
addChildCallback(gameObject) {
var layer = this.rendererLayer;
if (layer) {
layer.add(gameObject); // will invoke rendererLayer.queueDepthSort()
}
}
// Overwrite it
removeChildCallback(gameObject, destroyChild) {
var layer = this.rendererLayer;
if (layer) {
layer.remove(gameObject); // will invoke rendererLayer.queueDepthSort()
}
}
onChildDestroy(child, fromScene) {
// Only remove reference
this.remove(child, false);
}
clear(destroyChild) {
var gameObject;
var children = this.children.slice();
for (var i = 0, cnt = children.length; i < cnt; i++) {
gameObject = children[i];
if (!gameObject) {
continue;
}
gameObject.off('destroy', this.onChildDestroy, this);
this.removeChildCallback(gameObject, destroyChild);
if (destroyChild) {
gameObject.destroy();
}
}
this.children.length = 0;
return this;
}
enableLayerRenderer() {
if (this.layerRendererEnable) {
return this;
}
this.layerRendererEnable = true;
var rendererLayer = new ChildrenDisplayList(this);
this.rendererLayer = rendererLayer;
for (var i = 0, cnt = this.children.length; i < cnt; i++) {
this.addChildCallback(this.children[i]);
}
rendererLayer.queueDepthSort();
return this;
}
};
const Components = Phaser.GameObjects.Components;
Phaser.Class.mixin(Base$1,
[
Components.Alpha,
Components.Flip
]
);
Object.assign(
Base$1.prototype,
Renderer,
);
var GetParent$1 = function (gameObject, name) {
var parent;
if (name === undefined) {
if (gameObject.hasOwnProperty('rexContainer')) {
parent = gameObject.rexContainer.parent;
}
} else {
parent = GetParent$1(gameObject);
while (parent) {
if (parent.name === name) {
break;
}
parent = GetParent$1(parent);
}
}
return parent;
};
var GetTopmostParent$1 = function (gameObject) {
var parent = GetParent$1(gameObject);
while (parent) {
gameObject = parent;
parent = GetParent$1(parent);
}
return gameObject;
};
const DegToRad$4 = Phaser.Math.DegToRad;
const RadToDeg$2 = Phaser.Math.RadToDeg;
var GetLocalState = function (gameObject) {
if (!gameObject.hasOwnProperty('rexContainer')) {
var rexContainer = {
parent: null, self: null, layer: null,
x: 0, y: 0, syncPosition: true,
rotation: 0, syncRotation: true,
scaleX: 0, scaleY: 0, syncScale: true,
alpha: 0, syncAlpha: true,
syncScrollFactor: true,
syncCameraFilter: true,
syncDisplayList: true,
visible: true,
active: true,
};
Object.defineProperty(rexContainer, 'angle', {
get: function () {
return RadToDeg$2(this.rotation);
},
set: function (value) {
this.rotation = DegToRad$4(value);
}
});
Object.defineProperty(rexContainer, 'displayWidth', {
get: function () {
return gameObject.width * this.scaleX;
},
set: function (width) {
this.scaleX = width / gameObject.width;
}
});
Object.defineProperty(rexContainer, 'displayHeight', {
get: function () {
return gameObject.height * this.scaleY;
},
set: function (height) {
this.scaleY = height / gameObject.height;
}
});
gameObject.rexContainer = rexContainer;
}
return gameObject.rexContainer;
};
var Parent = {
setParent(gameObject, parent) {
if (parent === undefined) {
parent = this;
}
var localState = GetLocalState(gameObject);
if (parent) { // Add to parent
localState.parent = parent;
localState.self = gameObject;
} else { // Remove from parent
localState.parent = null;
localState.self = null;
}
return this;
},
getParent(gameObject, name) {
if (typeof (gameObject) === 'string') {
name = gameObject;
gameObject = undefined;
}
if (gameObject === undefined) {
gameObject = this;
}
return GetParent$1(gameObject, name);
},
getTopmostParent(gameObject) {
if (gameObject === undefined) {
gameObject = this;
}
return GetTopmostParent$1(gameObject);
}
};
const GetValue$15 = Phaser.Utils.Objects.GetValue;
const BaseAdd = Base$1.prototype.add;
var Add$3 = function (gameObject, config) {
this.setParent(gameObject);
var state = GetLocalState(gameObject);
SetupSyncFlags(state, config);
this
.resetChildState(gameObject) // Reset local state of child
.updateChildVisible(gameObject) // Apply parent's visible to child
.updateChildActive(gameObject) // Apply parent's active to child
.updateChildScrollFactor(gameObject) // Apply parent's scroll factor to child
.updateChildMask(gameObject) // Apply parent's mask to child
.updateCameraFilter(gameObject); // Apply parent's cameraFilter to child
BaseAdd.call(this, gameObject);
SyncDisplayList.call(this, gameObject, state);
return this;
};
var AddLocal = function (gameObject, config) {
this.setParent(gameObject);
// Set local state from child directly
var state = GetLocalState(gameObject);
SetupSyncFlags(state, config);
// Position
state.x = gameObject.x;
state.y = gameObject.y;
state.rotation = gameObject.rotation;
state.scaleX = gameObject.scaleX;
state.scaleY = gameObject.scaleY;
// Alpha
state.alpha = gameObject.alpha;
// Visible
state.visible = gameObject.visible;
// Active
state.active = gameObject.active;
this
.updateChildPosition(gameObject)
.updateChildAlpha(gameObject)
.updateChildVisible(gameObject) // Apply parent's visible to child
.updateChildActive(gameObject) // Apply parent's active to child
.updateChildScrollFactor(gameObject) // Apply parent's scroll factor to child
.updateChildMask(gameObject); // Apply parent's mask to child
BaseAdd.call(this, gameObject);
SyncDisplayList.call(this, gameObject, state);
return this;
};
var SetupSyncFlags = function (state, config) {
if (config === undefined) {
config = true;
}
if (typeof (config) === 'boolean') {
state.syncPosition = config;
state.syncRotation = config;
state.syncScale = config;
state.syncAlpha = config;
state.syncScrollFactor = config;
state.syncCameraFilter = config;
state.syncDisplayList = config;
} else {
state.syncPosition = GetValue$15(config, 'syncPosition', true);
state.syncRotation = GetValue$15(config, 'syncRotation', true);
state.syncScale = GetValue$15(config, 'syncScale', true);
state.syncAlpha = GetValue$15(config, 'syncAlpha', true);
state.syncScrollFactor = GetValue$15(config, 'syncScrollFactor', true);
state.syncCameraFilter = GetValue$15(config, 'syncCameraFilter', true);
state.syncDisplayList = GetValue$15(config, 'syncDisplayList', true);
}
};
var SyncDisplayList = function (gameObject, state) {
this.addToParentContainer(gameObject); // Sync parent's container to child
if (state.syncDisplayList) {
this.addToPatentLayer(gameObject); // Sync parent's layer to child
}
};
var AddChild$2 = {
// Can override this method
add(gameObject) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject);
} else {
Add$3.call(this, gameObject);
}
return this;
},
// Don't override this method
pin(gameObject, config) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject, config);
} else {
Add$3.call(this, gameObject, config);
}
return this;
},
// Can override this method
addMultiple(gameObjects) {
var args = Array.from(arguments);
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
args[0] = gameObjects[i];
this.add.apply(this, args);
}
return this;
},
addLocal(gameObject) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject);
} else {
AddLocal.call(this, gameObject);
}
return this;
},
// Don't override this method
pinLocal(gameObject, config) {
if (Array.isArray(gameObject)) {
this.addMultiple(gameObject, config);
} else {
AddLocal.call(this, gameObject, config);
}
return this;
},
addLocalMultiple(gameObjects) {
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
AddLocal.call(this, gameObjects[i]);
}
return this;
}
};
const BaseRemove = Base$1.prototype.remove;
const BaseClear = Base$1.prototype.clear;
var RemoveChild$1 = {
// Can override this method
remove(gameObject, destroyChild) {
if (GetParent$1(gameObject) !== this) {
return this;
}
this.setParent(gameObject, null);
BaseRemove.call(this, gameObject, destroyChild);
return this;
},
// Don't override this method
unpin(gameObject, destroyChild) {
if (GetParent$1(gameObject) !== this) {
return this;
}
this.setParent(gameObject, null);
BaseRemove.call(this, gameObject, destroyChild);
return this;
},
clear(destroyChild) {
var children = this.children;
for (var i = 0, cnt = children.length; i < cnt; i++) {
var child = children[i];
this.setParent(child, null);
}
BaseClear.call(this, destroyChild);
return this;
},
};
var ChildState = {
getLocalState(gameObject) {
return GetLocalState(gameObject);
},
resetChildState(gameObject) {
this
.resetChildPositionState(gameObject)
.resetChildVisibleState(gameObject)
.resetChildAlphaState(gameObject)
.resetChildActiveState(gameObject);
return this;
},
resetChildrenState(gameObjects) {
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
this.resetChildState(gameObjects[i]);
}
return this;
},
syncProperties() {
this
.syncPosition()
.syncVisible()
.syncAlpha()
.syncActive()
.syncScrollFactor()
.syncMask();
return this;
}
};
var Transform = {
worldToLocal(point) {
// Transform
point.x -= this.x;
point.y -= this.y;
// Rotate
var c = Math.cos(-this.rotation);
var s = Math.sin(-this.rotation);
var tx = point.x;
var ty = point.y;
point.x = tx * c - ty * s;
point.y = tx * s + ty * c;
// Scale
point.x /= this.scaleX;
point.y /= this.scaleY;
return point;
},
localToWorld(point) {
// Scale
point.x *= this.scaleX;
point.y *= this.scaleY;
// Rotate
var c = Math.cos(this.rotation);
var s = Math.sin(this.rotation);
var tx = point.x;
var ty = point.y;
point.x = tx * c - ty * s;
point.y = tx * s + ty * c;
// Transform
point.x += this.x;
point.y += this.y;
return point;
}
};
var GetScale = function (a, b) {
if (a === b) {
return 1;
} else {
return a / b;
}
};
var Position = {
updateChildPosition(child) {
if (child.isRexContainerLite) {
child.syncChildrenEnable = false;
}
var localState = GetLocalState(child);
var parent = localState.parent;
if (localState.syncPosition) {
child.x = localState.x;
child.y = localState.y;
parent.localToWorld(child);
}
if (localState.syncRotation) {
child.rotation = localState.rotation + parent.rotation;
}
if (localState.syncScale) {
child.scaleX = localState.scaleX * parent.scaleX;
child.scaleY = localState.scaleY * parent.scaleY;
}
if (child.isRexContainerLite) {
child.syncChildrenEnable = true;
child.syncPosition();
}
return this;
},
syncPosition() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildPosition, this);
}
return this;
},
resetChildPositionState(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
localState.x = child.x;
localState.y = child.y;
parent.worldToLocal(localState);
localState.scaleX = GetScale(child.scaleX, parent.scaleX);
localState.scaleY = GetScale(child.scaleY, parent.scaleY);
localState.rotation = child.rotation - parent.rotation;
return this;
},
setChildPosition(child, x, y) {
child.x = x;
child.y = y;
this.resetChildPositionState(child);
return this;
},
setChildLocalPosition(child, x, y) {
var localState = GetLocalState(child);
localState.x = x;
localState.y = y;
this.updateChildPosition(child);
return this;
},
resetLocalPositionState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildPositionState(this);
}
return this;
},
getChildLocalX(child) {
var localState = GetLocalState(child);
return localState.x;
},
getChildLocalY(child) {
var localState = GetLocalState(child);
return localState.y;
},
};
const DegToRad$3 = Phaser.Math.DegToRad;
var Rotation = {
updateChildRotation(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
if (localState.syncRotation) {
child.rotation = parent.rotation + localState.rotation;
}
return this;
},
syncRotation() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildRotation, this);
}
return this;
},
resetChildRotationState(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
localState.rotation = child.rotation - parent.rotation;
return this;
},
setChildRotation(child, rotation) {
child.rotation = rotation;
this.resetChildRotationState(child);
return this;
},
setChildAngle(child, angle) {
child.angle = angle;
this.resetChildRotationState(child);
return this;
},
setChildLocalRotation(child, rotation) {
var localState = GetLocalState(child);
localState.rotation = rotation;
this.updateChildRotation(child);
return this;
},
setChildLocalAngle(child, angle) {
var localState = GetLocalState(child);
localState.rotation = DegToRad$3(angle);
this.updateChildRotation(child);
return this;
},
resetLocalRotationState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildRotationState(this);
}
return this;
},
getChildLocalRotation(child) {
var localState = GetLocalState(child);
return localState.rotation;
},
};
var Scale$2 = {
updateChildScale(child) {
var state = GetLocalState(child);
var parent = state.parent;
if (state.syncScale) {
child.scaleX = parent.scaleX * state.scaleX;
child.scaleY = parent.scaleY * state.scaleY;
}
return this;
},
syncScale() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildScale, this);
}
return this;
},
resetChildScaleState(child) {
var state = GetLocalState(child);
var parent = state.parent;
state.scaleX = GetScale(child.scaleX, parent.scaleX);
state.scaleY = GetScale(child.scaleY, parent.scaleY);
return this;
},
setChildScale(child, scaleX, scaleY) {
if (scaleY === undefined) {
scaleY = scaleX;
}
child.scaleX = scaleX;
child.scaleY = scaleY;
this.resetChildScaleState(child);
return this;
},
setChildScaleX(child, scaleX) {
child.scaleX = scaleX;
this.resetChildScaleState(child);
return this;
},
setChildScaleY(child, scaleY) {
child.scaleY = scaleY;
this.resetChildScaleState(child);
return this;
},
setChildLocalScale(child, scaleX, scaleY) {
if (scaleY === undefined) {
scaleY = scaleX;
}
var state = GetLocalState(child);
state.scaleX = scaleX;
state.scaleY = scaleY;
this.updateChildScale(child);
return this;
},
setChildLocalScaleX(child, scaleX) {
var state = GetLocalState(child);
state.scaleX = scaleX;
this.updateChildScale(child);
return this;
},
setChildLocalScaleY(child, scaleY) {
var state = GetLocalState(child);
state.scaleY = scaleY;
this.updateChildScale(child);
return this;
},
setChildDisplaySize(child, width, height) {
child.setDisplaySize(width, height);
this.resetChildScaleState(child);
return this;
},
resetLocalScaleState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildScaleState(this);
}
return this;
},
getChildLocalScaleX(child) {
var localState = GetLocalState(child);
return localState.scaleX;
},
getChildLocalScaleY(child) {
var localState = GetLocalState(child);
return localState.scaleY;
},
};
/*
Visible in localState:
- visible: original visible of child
- maskVisible: invisible by parent mask, see MaskChildren.js
- undefined (not in masking) : Equal to mask visible
- true (mask visible) : Inside, or across parent's visible area
- false (maske invisible) : Out of parent's visible area
Visible result of child = (parent visible) && (child visible) && (mask visible)
*/
var Visible = {
updateChildVisible(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
var maskVisible = (localState.hasOwnProperty('maskVisible')) ? localState.maskVisible : true;
var parentVisible = (parent) ? parent.visible : true;
child.visible = parentVisible && localState.visible && maskVisible;
return this;
},
syncVisible() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildVisible, this);
}
return this;
},
resetChildVisibleState(child) {
var localState = GetLocalState(child);
// Delete maskVisible property
if (localState.hasOwnProperty('maskVisible')) {
delete localState.maskVisible;
}
localState.visible = child.visible;
return this;
},
setChildVisible(child, visible) {
// Visible of child will be affect by parent's visible, and mask visible
this.setChildLocalVisible(child, visible);
return this;
},
// Internal method
setChildLocalVisible(child, visible) {
if (visible === undefined) {
visible = true;
}
var localState = GetLocalState(child);
localState.visible = visible;
this.updateChildVisible(child);
return this;
},
// Internal method
setChildMaskVisible(child, visible) {
if (visible === undefined) {
visible = true;
}
var localState = GetLocalState(child);
localState.maskVisible = visible;
this.updateChildVisible(child);
return this;
},
resetLocalVisibleState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildVisibleState(this);
}
return this;
},
getChildLocalVisible(child) {
var localState = GetLocalState(child);
return localState.visible;
},
};
var Alpha = {
updateChildAlpha(child) {
var state = GetLocalState(child);
var parent = state.parent;
if (state.syncAlpha) {
child.alpha = parent.alpha * state.alpha;
}
return this;
},
syncAlpha() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildAlpha, this);
}
return this;
},
resetChildAlphaState(child) {
var state = GetLocalState(child);
var parent = state.parent;
state.alpha = GetScale(child.alpha, parent.alpha);
return this;
},
setChildAlpha(child, alpha) {
child.alpha = alpha;
this.resetChildAlphaState(child);
return this;
},
setChildLocalAlpha(child, alpha) {
var state = GetLocalState(child);
state.alpha = alpha;
this.updateChildAlpha(child);
return this;
},
resetLocalAlphaState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildAlphaState(this);
}
return this;
},
getChildLocalAlpha(child) {
var localState = GetLocalState(child);
return localState.alpha;
},
};
var Active = {
updateChildActive(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
child.active = parent.active && localState.active;
return this;
},
syncActive() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildActive, this);
}
return this;
},
resetChildActiveState(child) {
var localState = GetLocalState(child);
localState.active = child.active;
return this;
},
setChildActive(child, active) {
child.active = active;
this.resetChildActiveState(child);
return this;
},
setChildLocalActive(child, active) {
if (active === undefined) {
active = true;
}
var localState = GetLocalState(child);
localState.active = active;
this.updateChildActive(child);
return this;
},
resetLocalActiveState() {
var parent = GetLocalState(this).parent;
if (parent) {
parent.resetChildActiveState(this);
}
return this;
},
getChildLocalActive(child) {
var localState = GetLocalState(child);
return localState.active;
},
};
var ScrollFactor = {
updateChildScrollFactor(child) {
var localState = GetLocalState(child);
var parent = localState.parent;
if (localState.syncScrollFactor) {
child.scrollFactorX = parent.scrollFactorX;
child.scrollFactorY = parent.scrollFactorY;
}
return this;
},
syncScrollFactor() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildScrollFactor, this);
}
return this;
},
};
var CameraFilter = {
updateCameraFilter(child) {
var state = GetLocalState(child);
var parent = state.parent;
if (state.syncCameraFilter) {
child.cameraFilter = parent.cameraFilter;
}
return this;
},
syncCameraFilter() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateCameraFilter, this);
}
return this;
},
};
var Mask = {
updateChildMask(child) {
// Don't propagate null mask to clear children's mask
if (this.mask == null) {
return this;
}
var maskGameObject = (this.mask.hasOwnProperty('geometryMask')) ? this.mask.geometryMask : this.mask.bitmapMask;
if (maskGameObject !== child) {
child.mask = this.mask;
}
return this;
},
syncMask() {
if (this.syncChildrenEnable) {
this.children.forEach(this.updateChildMask, this);
}
return this;
},
setMask(mask) {
this.mask = mask;
return this;
},
// Internal use
clearChildrenMask() {
var children = this.children;
for (var i = 0, cnt = children.length; i < cnt; i++) {
var child = children[i];
// Clear child's mask
if (child.clearMask) {
child.clearMask(false);
}
if (!child.hasOwnProperty('isRexContainerLite')) {
this.setChildMaskVisible(child);
// Set child's maskVisible to `true`
}
}
return this;
},
clearMask(destroyMask) {
if (destroyMask === undefined) {
destroyMask = false;
}
// Clear current mask
if (destroyMask && this.mask) {
mask.destroy();
}
this._mask = null;
this.setChildMaskVisible(this);
// Also set maskVisible to `true`
this.clearChildrenMask();
return this;
},
};
var SortGameObjectsByDepth = function (gameObjects, descending) {
if (gameObjects.length <= 1) {
return gameObjects;
}
if (descending === undefined) {
descending = false;
}
var itemList;
for (var i = 0, cnt = gameObjects.length; i < cnt; i++) {
var gameObject = gameObjects[i];
if (gameObject.displayList) {
// Inside a scene or a layer
itemList = gameObject.displayList; // displayList
} else if (gameObject.parentContainer) {
// Inside a container
itemList = gameObject.parentContainer.list; // array
}
if (itemList) {
break;
}
}
if (!itemList) {
itemList = gameObject.scene.sys.displayList; // displayList
// ??
}
if (itemList.depthSort) {
// Is a displayList object
itemList.depthSort();
itemList = itemList.list;
// itemList is an array now
}
// itemList is an array
if (descending) {
gameObjects.sort(function (childA, childB) {
return itemList.indexOf(childB) - itemList.indexOf(childA);
});
} else {
gameObjects.sort(function (childA, childB) {
return itemList.indexOf(childA) - itemList.indexOf(childB);
});
}
return gameObjects;
};
var FilterDisplayGameObjects = function (gameObjects, referanceGameObject) {
var targetDisplayList = (referanceGameObject) ? referanceGameObject.displayList : undefined;
var targetParentContainer = (referanceGameObject) ? referanceGameObject.parentContainer : undefined;
return gameObjects.filter(function (gameObject) {
var displayList = gameObject.displayList;
var parentContainer = gameObject.parentContainer;
// Inside a scene or a layer, or
// Inside a container
if (!displayList && !parentContainer) {
return false;
}
if (!referanceGameObject) {
return true;
}
// At the same scene or layer, or
if (displayList) {
return (displayList === targetDisplayList);
}
// Inside the same container
if (parentContainer) {
return (parentContainer === targetParentContainer);
}
return false;
})
};
var Depth = {
setDepth(value, containerOnly) {
this.depth = value;
if (!this.layerRendererEnable) {
if (!containerOnly && this.children) {
var children = this.getAllChildren();
for (var i = 0, cnt = children.length; i < cnt; i++) {
children[i].depth = value;
}
}
}
// else: children are inside rendererLayer, not in scene's display list
return this;
},
swapDepth(containerB) {
var depthA = this.depth;
var depthB = containerB.depth;
this.setDepth(depthB);
containerB.setDepth(depthA);
return this;
},
incDepth(inc) {
this.depth += inc;
if (!this.layerRendererEnable) {
if (this.children) {
var children = this.getAllChildren();
for (var i = 0, cnt = children.length; i < cnt; i++) {
children[i].depth += inc;
}
}
}
// else: children are inside rendererLayer, not in scene's display list
return this;
},
bringToTop() {
var displayList = this.displayList;
if (!displayList) {
return this;
}
if (!this.layerRendererEnable) {
var children = this.getAllChildren([this]);
SortGameObjectsByDepth(children, false);
for (var i = 0, cnt = children.length; i < cnt; i++) {
var child = children[i];
if (displayList.exists(child)) {
displayList.bringToTop(child);
}
}
} else {
if (displayList.exists(this)) {
displayList.bringToTop(this);
}
// children are inside rendererLayer, not in scene's display list
}
return this;
},
bringMeToTop() {
return this.bringToTop();
},
sendToBack() {
var displayList = this.displayList;
if (!displayList) {
return this;
}
if (!this.layerRendererEnable) {
var children = this.getAllChildren([this]);
SortGameObjectsByDepth(children, true);
for (var i = 0, cnt = children.length; i < cnt; i++) {
var child = children[i];
if (displayList.exists(child)) {
displayList.sendToBack(child);
}
}
} else {
if (displayList.exists(this)) {
displayList.sendToBack(this);
}
// children are inside rendererLayer, not in scene's display list
}
return this;
},
sendMeToBack() {
return this.sendToBack();
},
moveDepthBelow(gameObject) {
var displayList = this.displayList;
if (!displayList) {
return this;
}
if (gameObject.displayList !== displayList) {
// Do nothing if not at the same display list
return this;
}
if (!this.layerRendererEnable) {
var children = this.getAllChildren([this]);
SortGameObjectsByDepth(children, false);
for (var i = 0, cnt = children.length; i < cnt; i++) {
var child = children[i];
if (displayList.exists(child)) {
displayList.moveBelow(gameObject, child);
break;
}
}
} else {
if (displayList.exists(this)) {
displayList.moveBelow(gameObject, this);
}
// children are inside rendererLayer, not in scene's display list
}
return this;
},
moveMyDepthBelow(gameObject) {
return this.moveDepthBelow(gameObject);
},
moveDepthAbove(gameObject) {
var displayList = this.displayList;
if (!displayList) {
return this;
}
if (gameObject.displayList !== displayList) {
// Do nothing if not at the same display list
return this;
}
if (!this.layerRendererEnable) {
var children = this.getAllChildren([this]);
SortGameObjectsByDepth(children, true);
for (var i = 0, cnt = children.length; i < cnt; i++) {
var child = children[i];
if (displayList.exists(child)) {
displayList.moveAbove(gameObject, child);
break;
}
}
} else {
if (displayList.exists(this)) {
displayList.moveAbove(gameObject, this);
}
// children are inside rendererLayer, not in scene's display list
}
return this;
},
moveMyDepthAbove(gameObject) {
return this.moveDepthAbove(gameObject);
},
bringChildToTop(child) {
if ((child === this) && (this.layerRendererEnable)) {
// containterLite is at the very bottom, can't move it to top
return this;
}
var gameObjects;
if ((child !== this) && child.isRexContainerLite && (!child.layerRendererEnable)) {
gameObjects = child.getAllChildren([child]);
gameObjects = FilterDisplayGameObjects(gameObjects, child);
gameObjects = SortGameObjectsByDepth(gameObjects, false);
} else {
gameObjects = [child];
}
var topChild;
if (!this.layerRendererEnable) {
var children = this.getAllChildren([this]);
children = FilterDisplayGameObjects(children, child);
children = SortGameObjectsByDepth(children, false);
topChild = children[children.length - 1];
} else {
topChild = this;