Commit f5222b22 authored by rockyl's avatar rockyl

内容太多,懒得写

parent 64dc3214
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
"main": "index.js", "main": "index.js",
"types": "index.d.ts", "types": "index.d.ts",
"dependencies": { "dependencies": {
"color": "^3.1.2" "color": "^3.1.2",
"howler": "^2.1.2"
}, },
"devDependencies": { "devDependencies": {
"dts-bundle": "^0.7.3", "dts-bundle": "^0.7.3",
......
...@@ -180,6 +180,14 @@ export default class Container extends DisplayObject { ...@@ -180,6 +180,14 @@ export default class Container extends DisplayObject {
return index; return index;
} }
/**
* 是否含有child
* @param child
*/
contains(child: DisplayObject):boolean{
return !!this.getChildIndex(child);
}
/** /**
* 设置child的层级 * 设置child的层级
* @param {DisplayObject} child * @param {DisplayObject} child
......
...@@ -5,6 +5,7 @@ import { Point } from "../math/Point"; ...@@ -5,6 +5,7 @@ import { Point } from "../math/Point";
import { Event } from "../events/Event"; import { Event } from "../events/Event";
import Graphics from '../graphics/Graphics'; import Graphics from '../graphics/Graphics';
import { DEG_TO_RAD, RAD_TO_DEG } from '../const'; import { DEG_TO_RAD, RAD_TO_DEG } from '../const';
import {Stage} from "./Stage";
/** /**
* 基础显示对象抽象类 * 基础显示对象抽象类
...@@ -36,7 +37,7 @@ export class DisplayObject extends EventDispatcher { ...@@ -36,7 +37,7 @@ export class DisplayObject extends EventDispatcher {
/** /**
* 舞台 * 舞台
*/ */
stage: any; stage: Stage;
/** /**
* 名字,预留 * 名字,预留
......
...@@ -2,6 +2,8 @@ import {Event} from "../events/Event"; ...@@ -2,6 +2,8 @@ import {Event} from "../events/Event";
import {DisplayObject} from "./DisplayObject"; import {DisplayObject} from "./DisplayObject";
import {devicePixelRatio} from "../const"; import {devicePixelRatio} from "../const";
let container;
/** /**
* 此类对于需要在canvas上放置html其他类型元素的时候非常有用<br/> * 此类对于需要在canvas上放置html其他类型元素的时候非常有用<br/>
* 比如有时候我们需要放置一个注册,登录或者其他的内容.这些内容包含了输入框<br/> * 比如有时候我们需要放置一个注册,登录或者其他的内容.这些内容包含了输入框<br/>
...@@ -22,7 +24,7 @@ export class FloatDisplay extends DisplayObject { ...@@ -22,7 +24,7 @@ export class FloatDisplay extends DisplayObject {
* @since 1.0.0 * @since 1.0.0
* @type{HtmlElement} * @type{HtmlElement}
*/ */
public htmlElement: any = null; private _htmlElement: any = null;
/** /**
* 是否已经添加了舞台事件 * 是否已经添加了舞台事件
* @property _isAdded * @property _isAdded
...@@ -75,19 +77,26 @@ export class FloatDisplay extends DisplayObject { ...@@ -75,19 +77,26 @@ export class FloatDisplay extends DisplayObject {
let s = this; let s = this;
s._instanceType = "FloatDisplay"; s._instanceType = "FloatDisplay";
s.addEventListener(Event.REMOVED_FROM_STAGE, function (e: Event) { s.addEventListener(Event.REMOVED_FROM_STAGE, function (e: Event) {
if (s.htmlElement) { if (s._htmlElement) {
s.htmlElement.style.display = "none"; s._htmlElement.style.display = "none";
} }
}); });
s.addEventListener(Event.ADDED_TO_STAGE, function (e: Event) { s.addEventListener(Event.ADDED_TO_STAGE, function (e: Event) {
if (s.htmlElement) { if(!container){
let style = s.htmlElement.style; container = document.createElement('div');
container.style.position = "absolute";
container.style.left = "0";
container.style.top = "0";
s.stage.rootDiv.appendChild(container);//, s.stage.rootDiv.childNodes[0]
}
if (s._htmlElement) {
let style = s._htmlElement.style;
if (!s._isAdded) { if (!s._isAdded) {
s._isAdded = true; s._isAdded = true;
s.stage.rootDiv.insertBefore(s.htmlElement, s.stage.rootDiv.childNodes[0]); container.appendChild(s._htmlElement);
s.stage["_floatDisplayList"].push(s); s.stage["_floatDisplayList"].push(s);
} else { } else {
if (s.htmlElement && s.visible) { if (s._htmlElement && s.visible) {
style.display = "block"; style.display = "block";
} }
} }
...@@ -97,6 +106,15 @@ export class FloatDisplay extends DisplayObject { ...@@ -97,6 +106,15 @@ export class FloatDisplay extends DisplayObject {
this._transformID = -1; this._transformID = -1;
} }
get htmlElement() {
return this._htmlElement;
}
set htmlElement(v) {
this.init(v);
this.updateStyle();
}
/** /**
* 初始化方法,htmlElement 一定要设置width和height样式,并且一定要用px单位 * 初始化方法,htmlElement 一定要设置width和height样式,并且一定要用px单位
* @method init * @method init
...@@ -104,7 +122,7 @@ export class FloatDisplay extends DisplayObject { ...@@ -104,7 +122,7 @@ export class FloatDisplay extends DisplayObject {
* @since 1.0.0 * @since 1.0.0
* @param {HtmlElement} htmlElement 需要封装起来的html元素的引用。你可以通过这个引用来调用或设置此元素自身的属性方法和事件,甚至是样式 * @param {HtmlElement} htmlElement 需要封装起来的html元素的引用。你可以通过这个引用来调用或设置此元素自身的属性方法和事件,甚至是样式
*/ */
public init(htmlElement: any): void { protected init(htmlElement: any): void {
let s = this; let s = this;
let she: any; let she: any;
if (typeof (htmlElement) == "string") { if (typeof (htmlElement) == "string") {
...@@ -131,7 +149,7 @@ export class FloatDisplay extends DisplayObject { ...@@ -131,7 +149,7 @@ export class FloatDisplay extends DisplayObject {
// s._bounds.height = h; // s._bounds.height = h;
s._localBoundsSelf.width = w; s._localBoundsSelf.width = w;
s._localBoundsSelf.height = h; s._localBoundsSelf.height = h;
s.htmlElement = she; s._htmlElement = she;
} }
/** /**
...@@ -163,7 +181,7 @@ export class FloatDisplay extends DisplayObject { ...@@ -163,7 +181,7 @@ export class FloatDisplay extends DisplayObject {
*/ */
public updateStyle(): void { public updateStyle(): void {
let s = this; let s = this;
let o = s.htmlElement; let o = s._htmlElement;
if (o) { if (o) {
let style = o.style; let style = o.style;
let visible = s.visible; let visible = s.visible;
...@@ -201,14 +219,14 @@ export class FloatDisplay extends DisplayObject { ...@@ -201,14 +219,14 @@ export class FloatDisplay extends DisplayObject {
public destroy(): void { public destroy(): void {
//清除相应的数据引用 //清除相应的数据引用
let s = this; let s = this;
let elem = s.htmlElement; let elem = s._htmlElement;
if (elem) { if (elem) {
elem.style.display = "none"; elem.style.display = "none";
if (elem.parentNode) { if (elem.parentNode) {
elem.parentNode.removeChild(elem); elem.parentNode.removeChild(elem);
} }
s._isAdded = false; s._isAdded = false;
s.htmlElement = null; s._htmlElement = null;
} }
let sf: any = s.stage["_floatDisplayList"]; let sf: any = s.stage["_floatDisplayList"];
let len = sf.length; let len = sf.length;
......
...@@ -371,30 +371,30 @@ export default class Sprite extends Container { ...@@ -371,30 +371,30 @@ export default class Sprite extends Container {
* texture的宽度和缩放乘积 * texture的宽度和缩放乘积
* @member {number} * @member {number}
*/ */
// get width() { get width() {
// return Math.abs(this.scale.x) * this._texture.orig.width; return Math.abs(this.scale.x) * this._texture.orig.width;
// } }
// set width(value) { set width(value) {
// const s = sign(this.scale.x) || 1; const s = sign(this.scale.x) || 1;
// this.scale.x = s * value / this._texture.orig.width; this.scale.x = s * value / this._texture.orig.width;
// this._width = value; this._width = value;
// } }
/** /**
* texture的高度和缩放乘积 * texture的高度和缩放乘积
* @member {number} * @member {number}
*/ */
// get height() { get height() {
// return Math.abs(this.scale.y) * this._texture.orig.height; return Math.abs(this.scale.y) * this._texture.orig.height;
// } }
// set height(value) { set height(value) {
// const s = sign(this.scale.y) || 1; const s = sign(this.scale.y) || 1;
// this.scale.y = s * value / this._texture.orig.height; this.scale.y = s * value / this._texture.orig.height;
// this._height = value; this._height = value;
// } }
/** /**
* 0,0标识左上角,0.5,0.5表示中间,1,1表示右下角 * 0,0标识左上角,0.5,0.5表示中间,1,1表示右下角
......
...@@ -72,7 +72,7 @@ export class Stage extends Container { ...@@ -72,7 +72,7 @@ export class Stage extends Container {
* @type {Html Div} * @type {Html Div}
* @default null * @default null
*/ */
public rootDiv: any = null; public rootDiv: any = HTMLElement;
/** /**
* 当前stage所使用的渲染器 * 当前stage所使用的渲染器
* 渲染器有两种,一种是canvas 一种是webGl * 渲染器有两种,一种是canvas 一种是webGl
...@@ -432,7 +432,7 @@ export class Stage extends Container { ...@@ -432,7 +432,7 @@ export class Stage extends Container {
s.dispatchEvent(Event.ON_INIT_STAGE); s.dispatchEvent(Event.ON_INIT_STAGE);
// } // }
}, 100); }, 100);
let rc = s.rootDiv; let rc = canvas;//s.rootDiv;
let mouseEvent = s.onMouseEvent.bind(s); let mouseEvent = s.onMouseEvent.bind(s);
//鼠标事件 //鼠标事件
if (osType != "pc") { if (osType != "pc") {
......
...@@ -133,6 +133,26 @@ export class Event extends HashObject { ...@@ -133,6 +133,26 @@ export class Event extends HashObject {
* @since 1.0.0 * @since 1.0.0
*/ */
public static PROGRESS: string = "onProgress"; public static PROGRESS: string = "onProgress";
/**
* 获取焦点
* @Event
* @property FOCUS
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static FOCUS: string = "focus";
/**
* 失去焦点
* @Event
* @property BLUR
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static BLUR: string = "blur";
/** /**
* 出错事件 * 出错事件
* @Event * @Event
......
...@@ -113,6 +113,10 @@ export class Loader extends EventDispatcher { ...@@ -113,6 +113,10 @@ export class Loader extends EventDispatcher {
} }
this.caches[name] = data; this.caches[name] = data;
} }
get(name: string){
return this.caches[name];
}
} }
async function fetchAsync(url: string) { async function fetchAsync(url: string) {
......
...@@ -9,7 +9,7 @@ import {TextField} from "./TextField"; ...@@ -9,7 +9,7 @@ import {TextField} from "./TextField";
* @class InputText * @class InputText
* @public * @public
* @since 1.0.0 * @since 1.0.0
* @extends annie.FloatDisplay * @extends FloatDisplay
*/ */
export class InputText extends FloatDisplay { export class InputText extends FloatDisplay {
/** /**
...@@ -90,7 +90,7 @@ export class InputText extends FloatDisplay { ...@@ -90,7 +90,7 @@ export class InputText extends FloatDisplay {
* @return {void} * @return {void}
* @since 1.0.0 * @since 1.0.0
*/ */
public init(htmlElement: any): void { protected init(htmlElement: any): void {
super.init(htmlElement); super.init(htmlElement);
//默认设置 //默认设置
let s = this; let s = this;
......
...@@ -170,9 +170,9 @@ export class TextField extends Sprite { ...@@ -170,9 +170,9 @@ export class TextField extends Sprite {
set width(value: number) { set width(value: number) {
if (this._width !== value) { if (this._width !== value) {
this.dispatchEvent(Event.RESIZE);
this._width = value; this._width = value;
this.dirty = true; this.dirty = true;
this.dispatchEvent(Event.RESIZE);
} }
} }
...@@ -184,9 +184,9 @@ export class TextField extends Sprite { ...@@ -184,9 +184,9 @@ export class TextField extends Sprite {
set height(value: number) { set height(value: number) {
if (this._height !== value) { if (this._height !== value) {
this.dispatchEvent(Event.RESIZE);
this._height = value; this._height = value;
this.dirty = true; this.dirty = true;
this.dispatchEvent(Event.RESIZE);
} }
} }
...@@ -240,9 +240,7 @@ export class TextField extends Sprite { ...@@ -240,9 +240,7 @@ export class TextField extends Sprite {
* @since 1.0.0 * @since 1.0.0
*/ */
public set text(value: string) { public set text(value: string) {
if (this._text != value) { this._setText(value);
this._setText(value);
}
} }
public get text(): string { public get text(): string {
...@@ -250,10 +248,12 @@ export class TextField extends Sprite { ...@@ -250,10 +248,12 @@ export class TextField extends Sprite {
} }
protected _setText(value) { protected _setText(value) {
this._text = value; if (this._text != value) {
this.dirty = true; this._text = value;
this.dirty = true;
this.dispatchEvent(Event.RESIZE); this.dispatchEvent(Event.RESIZE);
}
} }
protected _text: string = ""; protected _text: string = "";
...@@ -271,7 +271,6 @@ export class TextField extends Sprite { ...@@ -271,7 +271,6 @@ export class TextField extends Sprite {
this._font = value; this._font = value;
this.dirty = true; this.dirty = true;
} }
;
} }
public get font(): string { public get font(): string {
......
...@@ -137,7 +137,7 @@ export default class BaseTexture extends EventDispatcher { ...@@ -137,7 +137,7 @@ export default class BaseTexture extends EventDispatcher {
update() { update() {
this.width = this.source.width; this.width = this.source.width;
this.height = this.source.height; this.height = this.source.height;
this.isPowerOfTwo = isPow2(this.width) && isPow2(this.width); this.isPowerOfTwo = isPow2(this.width) && isPow2(this.height);
this.dispatchEvent("update") this.dispatchEvent("update")
} }
......
...@@ -38,9 +38,8 @@ export function afterConstructor(ctor: Function) { ...@@ -38,9 +38,8 @@ export function afterConstructor(ctor: Function) {
} }
if(withEvents){ if(withEvents){
if (events) { if (events) {
target.eventsProxy.eventsConfig = events; target.eventsProxy.start(events);
} }
target.eventsProxy.start();
} }
for(let child of this.children){ for(let child of this.children){
......
...@@ -28,7 +28,7 @@ export function applyEvents(ctor: Function) { ...@@ -28,7 +28,7 @@ export function applyEvents(ctor: Function) {
ctor.prototype.applyEvents = function () { ctor.prototype.applyEvents = function () {
let eventsProxy = this.eventsProxy = new EventsProxy(this); let eventsProxy = this.eventsProxy = new EventsProxy(this);
for (let k in eventsMapping) { for (let k in eventsMapping) {
this.addEventListener(k, eventsProxy.onEvent, eventsProxy); this.addEventListener(k, eventsProxy.onBuiltinEvent, eventsProxy);
} }
globalEvent.addEventListener(DATA_CENTER_EVENT, eventsProxy.onDateCenterEvent, eventsProxy); globalEvent.addEventListener(DATA_CENTER_EVENT, eventsProxy.onDateCenterEvent, eventsProxy);
...@@ -37,37 +37,56 @@ export function applyEvents(ctor: Function) { ...@@ -37,37 +37,56 @@ export function applyEvents(ctor: Function) {
class EventsProxy extends HashObject { class EventsProxy extends HashObject {
host; host;
eventsConfig: any;
private _eventsConfig: any;
constructor(host) { constructor(host) {
super(); super();
this.host = host; this.host = host;
} }
start() { get eventsConfig() {
this.invoke('init', this.host); return this._eventsConfig;
} }
invoke(name, target, payload?) { start(eventsConfig) {
if (this.eventsConfig) { this._eventsConfig = eventsConfig;
const eventConfig = this.eventsConfig[name]; for(let name in eventsConfig){
globalEvent.addEventListener(name, this.onCustomEvent, this);
}
this.invokeBehavior('init', this.host);
}
invokeBehavior(name, target, payload?) {
if (this._eventsConfig) {
const eventConfig = this._eventsConfig[name];
if (eventConfig) { if (eventConfig) {
executeBehavior({ for(let behavior of eventConfig.behaviors){
main: eventConfig.behaviors[0], if(behavior.disabled){
}, 'main', target, payload); continue;
}
executeBehavior({
main: behavior,
}, 'main', target, payload);
}
} }
} }
} }
onEvent(e) { onBuiltinEvent(e) {
let eventName = eventsMapping[e.type]; let eventName = eventsMapping[e.type];
if (eventName) { if (eventName) {
this.invoke(eventName, e.target, e.data); this.invokeBehavior(eventName, e.target, e.data);
} }
} }
onCustomEvent(e) {
this.invokeBehavior(e.type, this.host, e.data);
}
onDateCenterEvent(e) { onDateCenterEvent(e) {
this.invoke('data-center', this.host, e.data); this.invokeBehavior('data-center', this.host, e.data);
} }
destroy(): void { destroy(): void {
......
...@@ -49,7 +49,7 @@ export class GameStage extends Container { ...@@ -49,7 +49,7 @@ export class GameStage extends Container {
this.addChild(this._sceneContainer = new StackContainer()); this.addChild(this._sceneContainer = new StackContainer());
this.addChild(blackLayer); this.addChild(blackLayer);
this.addChild(this._popupContainer = new StackContainer(false)); this.addChild(this._popupContainer = new StackContainer());
this.addChild(this._toast = new Toast(this)); this.addChild(this._toast = new Toast(this));
blackLayer.percentWidth = 100; blackLayer.percentWidth = 100;
...@@ -98,7 +98,7 @@ export class GameStage extends Container { ...@@ -98,7 +98,7 @@ export class GameStage extends Container {
* @param onAssetsProgress * @param onAssetsProgress
* @param onAssetsComplete * @param onAssetsComplete
*/ */
async launch(config, onAssetsProgress?, onAssetsComplete?) { async launch(config, onAssetsProgress?, onAssetsComplete?, onStart?) {
this._config = config; this._config = config;
const {assets, customs} = config; const {assets, customs} = config;
let loaded = 0; let loaded = 0;
...@@ -128,6 +128,8 @@ export class GameStage extends Container { ...@@ -128,6 +128,8 @@ export class GameStage extends Container {
this.start(); this.start();
onStart && onStart();
function p() { function p() {
loaded++; loaded++;
...@@ -150,7 +152,9 @@ export class GameStage extends Container { ...@@ -150,7 +152,9 @@ export class GameStage extends Container {
//registerScripts(scripts); //registerScripts(scripts);
//registerCustomModuleFromConfig(customs); //registerCustomModuleFromConfig(customs);
this.dataCenter.registerDataMapping(dataMapping); if(dataMapping){
this.dataCenter.registerDataMapping(dataMapping);
}
setProcessMetaLibs(processes, builtinProcesses); setProcessMetaLibs(processes, builtinProcesses);
let sceneEntry = this.instantiateView(entrySceneView); let sceneEntry = this.instantiateView(entrySceneView);
......
...@@ -32,16 +32,22 @@ export function loadAssets(config, onProgress?, onComplete?) { ...@@ -32,16 +32,22 @@ export function loadAssets(config, onProgress?, onComplete?) {
config.map(assetConfig => { config.map(assetConfig => {
assetsConfig.push(assetConfig); assetsConfig.push(assetConfig);
const loadFunc = loaderMapping[assetConfig.ext] || 'Raw'; const loadFunc = loaderMapping[assetConfig.ext] || 'Raw';
let method = globalLoader['load' + loadFunc] || globalLoader.loadRaw; let method = globalLoader['load' + loadFunc];
return method.call(globalLoader, assetConfig.url, assetConfig.uuid).then( if(method){
(data)=>{ return method.call(globalLoader, assetConfig.url, assetConfig.uuid).then(
loaded++; (data)=>{
onProgress && onProgress(loaded, total); loaded++;
}, onProgress && onProgress(loaded, total);
(error)=>{ },
failedList.push(assetConfig.url); (error)=>{
} failedList.push(assetConfig.url);
); }
);
}else{
loaded++;
onProgress && onProgress(loaded, total);
return Promise.resolve();
}
}) })
).then( ).then(
() => { () => {
......
...@@ -6,3 +6,5 @@ export * from './GameStage' ...@@ -6,3 +6,5 @@ export * from './GameStage'
export * from './enviroment' export * from './enviroment'
export * from './custom-module' export * from './custom-module'
export * from './nodes' export * from './nodes'
export * from './sound'
export * from './assets-manager'
...@@ -31,21 +31,20 @@ export class Image extends Sprite { ...@@ -31,21 +31,20 @@ export class Image extends Sprite {
let url = this._source; let url = this._source;
if(url.indexOf('://') >= 0){ //如果是有协议的地址 if(url.indexOf('://') >= 0){ //如果是有协议的地址
if (url.indexOf(assetScheme) === 0) { if (url.indexOf(assetScheme) === 0) {
let uuid = url.replace(assetScheme, ''); url = url.replace(assetScheme, '');
/*const assetConfig = getAssetByUUID(uuid); /*const assetConfig = getAssetByUUID(uuid);
if(assetConfig){ if(assetConfig){
url = assetConfig.url; url = assetConfig.url;
this.texture = Texture.fromImage(url); this.texture = Texture.fromImage(url);
}*/ }*/
this.texture = Texture.from(uuid);
} }
} else{ //否则就使用素材名 } else{ //否则就使用素材名
const assetConfig = getAssetByName(url); const assetConfig = getAssetByName(url);
if(assetConfig){ if(assetConfig){
url = assetConfig.url; url = assetConfig.url;
} }
this.texture = Texture.fromImage(url);
} }
this.texture = Texture.fromImage(url);
} }
private _setSourceDirect(value){ private _setSourceDirect(value){
......
/**
* Created by rockyl on 2019-12-13.
*/
import {Label} from "./Label";
import {MouseEvent} from "../../../2d/events/MouseEvent";
import {Event} from "../../../2d/events/Event";
import {FloatDisplay} from "../../../2d/display/FloatDisplay";
import {TextField} from "../../../2d/text";
import {Point} from "../../../2d/math";
import {VERTICAL_ALIGN} from "../../..";
export class TextInput extends Label {
private _floatDisplay: FloatDisplay;
private _placeholderLabel: TextField;
private _input: any;
private _placeholder: string = '';
private _placeholderColor: any = '#666666';
private _maxLength: number;
private _oldFillColor;
private _oldStrokeColor;
constructor() {
super();
this.setup();
this.addEventListener(MouseEvent.CLICK, this.onClickStatic, this);
this.addEventListener(Event.RESIZE, this.onResize, this);
this.text = '';
}
get placeholder(): string {
return this._placeholder;
}
set placeholder(value: string) {
this._placeholder = value;
this._placeholderLabel.text = value;
}
get placeholderColor(): any {
return this._placeholderColor;
}
set placeholderColor(value: any) {
this._placeholderColor = value;
this._placeholderLabel.fillColor = value;
}
get maxLength(): number {
return this._maxLength;
}
set maxLength(value: number) {
if(this._maxLength != value){
this._maxLength = value;
this.setMaxLength();
}
}
private setup() {
let fd = this._floatDisplay = new FloatDisplay();
let input = this._input = document.createElement('input');
fd.htmlElement = input;
fd.alpha = 0;
input.style.pointerEvents = 'none';
let style = input.style;
style.outline = 'none';
style.padding = '0';
style.border = '0';
style.backgroundColor = 'transparent';
input.type = 'text';
input.addEventListener('blur', this.onBlur);
let pl = this._placeholderLabel = new TextField();
pl.fillColor = this._placeholderColor;
this.verticalAlign = pl.verticalAlign = VERTICAL_ALIGN.MIDDLE;
this.addChild(fd);
}
protected _setText(value) {
super._setText(value);
this.setMaxLength();
setTimeout(() => {
this.showPlaceholderLabel(value)
}, 1);
}
private setMaxLength() {
let value = this._text;
let maxLength = this._maxLength;
if (maxLength > 0 && value && value.length > maxLength) {
this.text = value.substr(0, maxLength);
}
}
private showPlaceholderLabel(value) {
let pl = this._placeholderLabel;
if(value){
let pl = this._placeholderLabel;
if (pl.parent) {
pl.parent.removeChild(pl);
}
}else{
if (!pl.parent) {
pl.text = this._placeholder;
pl.size = this.size;
pl.font = this.font;
this.addChildAt(pl, 0);
}
}
}
setFocus() {
let fd = this._floatDisplay;
let input = this._input;
let pl = this._placeholderLabel;
fd.width = this.width;
fd.height = this.height;
input.value = this.text;
let style = input.style;
style.fontSize = this.size + 'px';
style.color = this.fillColor;
style.width = this.width + 'px';
style.height = this.height + 'px';
style.fontFamily = this.font;
this._oldFillColor = this.fillColor;
this._oldStrokeColor = this.strokeColor;
this.fillColor = 'transparent';
this.strokeColor = 'transparent';
if (pl.parent) {
pl.parent.removeChild(pl);
}
//this.addChild(this._floatDisplay);
this._floatDisplay.alpha = 1;
input.style.pointerEvents = 'auto';
if(this._maxLength > 0){
input.maxLength = this._maxLength;
}else{
input.removeAttribute('maxLength')
}
input.focus();
this.dispatchEvent(Event.FOCUS);
}
setBlur() {
let input = this._input;
this._floatDisplay.alpha = 0;
input.style.pointerEvents = 'none';
input.blur();
this.text = input.value;
this.fillColor = this._oldFillColor;
this.strokeColor = this._oldStrokeColor;
this.dispatchEvent(Event.BLUR);
}
private onBlur = (e) => {
this.setBlur();
};
private onClickStage(e){
if(e.currentTarget !== this){
this.setBlur();
}
}
private onClickStatic() {
this.setFocus();
this.stage.once(MouseEvent.CLICK, this.onClickStage, this);
}
private onResize() {
let pl = this._placeholderLabel;
pl.width = this.width;
pl.height = this.height;
}
public static _bp: Point = new Point();
/**
* 检测点是否在任何child上
* 重写父类方法
*/
hitTestPoint(globalPoint: Point, isMouseEvent: boolean = false) {
const s = this;
//如果不可见
if (!this.visible) return null;
//如果禁止子级的鼠标事件
if (isMouseEvent && !this.mouseChildren) return null;
if (!isMouseEvent) {
//如果不是系统调用则不考虑这个点是从全局来的,只认为这个点就是当前要碰撞测试同级别下的坐标点
if (s._localBoundsSelf.isPointIn(globalPoint)) {
return s;
}
} else {
let {x, y} = s.globalToLocal(globalPoint, TextInput._bp);
if (x > 0 && x < s.width && y > 0 && y < s.height) {
return s;
}
}
return null;
}
}
...@@ -5,4 +5,5 @@ ...@@ -5,4 +5,5 @@
export * from './shapes' export * from './shapes'
export * from './Image' export * from './Image'
export * from './Label' export * from './Label'
export * from './TextInput'
export * from './ScrollView' export * from './ScrollView'
\ No newline at end of file
/**
* Created by rockyl on 2019-12-16.
*/
import {getAssetByUUID} from "./assets-manager";
import {Howl, Howler} from 'howler';
import {injectProperties} from "../utils";
const instances = {};
export function playSound(uuid, options = {}, name?) {
let assetConfig = getAssetByUUID(uuid);
if (assetConfig) {
let url = assetConfig.url;
let opts: any = {
src: [url],
autoplay: true,
};
injectProperties(opts, options);
let sound = new Howl(opts);
if (name !== undefined) {
instances[name] = sound;
sound.on('end', function () {
delete instances[name];
});
}
return sound;
}
}
export function stopSound(name){
let sound = instances[name];
if(sound){
sound.stop();
delete instances[name];
}
}
...@@ -13,6 +13,8 @@ export * from './web' ...@@ -13,6 +13,8 @@ export * from './web'
export * from './log-switch' export * from './log-switch'
import {instantiate} from './game-warpper/view-interpreter' import {instantiate} from './game-warpper/view-interpreter'
export {Howl, Howler} from 'howler';
export { export {
instantiate instantiate
} }
This diff is collapsed.
...@@ -7,10 +7,12 @@ export function findNodeByUUID(node, uuid) { ...@@ -7,10 +7,12 @@ export function findNodeByUUID(node, uuid) {
return node; return node;
} }
for (let child of node.children) { if(node.children && node.children.length > 0){
let target = findNodeByUUID(child, uuid); for (let child of node.children) {
if (target) { let target = findNodeByUUID(child, uuid);
return target; if (target) {
return target;
}
} }
} }
} }
This diff is collapsed.
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