mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
fix component and fix some bug
This commit is contained in:
@@ -76,6 +76,8 @@ let builtinResMgr = {
|
||||
spriteFrame.setFilters(Texture2D.Filter.NEAREST, Texture2D.Filter.NEAREST);
|
||||
spriteFrame.setWrapMode(Texture2D.WrapMode.REPEAT, Texture2D.WrapMode.REPEAT);
|
||||
spriteFrame._uuid = 'default-spriteframe';
|
||||
spriteFrame.setOriginalSize(cc.size(canvasImage.width, canvasImage.height));
|
||||
spriteFrame.setRect(0, 0, canvasImage.width, canvasImage.height);
|
||||
spriteFrame.image = canvasImage;
|
||||
if (spriteFrame.onLoaded) {
|
||||
spriteFrame.onLoaded();
|
||||
|
||||
@@ -56,7 +56,7 @@ export const ttf: IAssembler = {
|
||||
},
|
||||
|
||||
fillBuffers (comp: LabelComponent, /*renderer*/buffer: MeshBuffer) {
|
||||
fillMeshVertices3D(comp.node, /*renderer._quadBuffer3D*/buffer, comp._renderData, WHITE._val);
|
||||
fillMeshVertices3D(comp.node, /*renderer._quadBuffer3D*/buffer, comp.renderData, WHITE);
|
||||
},
|
||||
|
||||
updateVerts (comp: LabelComponent) {
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
import { vec3 } from '../../../../core/vmath/index';
|
||||
import { UIRenderComponent } from '../../components/ui-render-component';
|
||||
import { SpriteComponent } from '../../components/sprite-component';
|
||||
import { Vec3, Color } from '../../../../core/value-types';
|
||||
import { Node } from '../../../../scene-graph/node';
|
||||
|
||||
@@ -26,7 +26,11 @@ export function fillVertices(node, buffer, renderData, color) {
|
||||
vbuf[vertexOffset++] = vert.x * b + vert.y * d + ty;
|
||||
vbuf[vertexOffset++] = vert.u;
|
||||
vbuf[vertexOffset++] = vert.v;
|
||||
uintbuf[vertexOffset++] = color;
|
||||
// uintbuf[vertexOffset++] = color;
|
||||
vbuf[vertexOffset++] = color.r;
|
||||
vbuf[vertexOffset++] = color.g;
|
||||
vbuf[vertexOffset++] = color.b;
|
||||
vbuf[vertexOffset++] = color.a;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +60,11 @@ export function fillMeshVertices(node, buffer, renderData, color) {
|
||||
vbuf[vertexOffset++] = vert.x * b + vert.y * d + ty;
|
||||
vbuf[vertexOffset++] = vert.u;
|
||||
vbuf[vertexOffset++] = vert.v;
|
||||
uintbuf[vertexOffset++] = color;
|
||||
// uintbuf[vertexOffset++] = color;
|
||||
vbuf[vertexOffset++] = color.r;
|
||||
vbuf[vertexOffset++] = color.g;
|
||||
vbuf[vertexOffset++] = color.b;
|
||||
vbuf[vertexOffset++] = color.a;
|
||||
}
|
||||
|
||||
// fill indice data
|
||||
@@ -83,18 +91,22 @@ export function fillVertices3D(node, buffer, renderData, color) {
|
||||
uintbuf = buffer._uintVData;
|
||||
|
||||
// let matrix = node._worldMatrix;
|
||||
// node.getWorldMatrix(_worldMatrix);
|
||||
node.getWorldMatrix(_worldMatrix);
|
||||
|
||||
for (let i = 0; i < vertexCount; i++) {
|
||||
let vert = data[i];
|
||||
vec3.set(vec3_temp, vert.x, vert.y, 0);
|
||||
// vec3.transformMat4(vec3_temp, vec3_temp, _worldMatrix);
|
||||
vec3.transformMat4(vec3_temp, vec3_temp, _worldMatrix);
|
||||
vbuf[vertexOffset++] = vec3_temp.x;
|
||||
vbuf[vertexOffset++] = vec3_temp.y;
|
||||
vbuf[vertexOffset++] = vec3_temp.z;
|
||||
vbuf[vertexOffset++] = vert.u;
|
||||
vbuf[vertexOffset++] = vert.v;
|
||||
uintbuf[vertexOffset++] = color;
|
||||
vbuf[vertexOffset++] = color.r;
|
||||
vbuf[vertexOffset++] = color.g;
|
||||
vbuf[vertexOffset++] = color.b;
|
||||
vbuf[vertexOffset++] = color.a;
|
||||
// uintbuf[vertexOffset++] = color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,18 +126,22 @@ export function fillMeshVertices3D(node, buffer, renderData, color) {
|
||||
ibuf = buffer._iData;
|
||||
|
||||
// let matrix = node._worldMatrix;
|
||||
// node.getWorldMatrix(_worldMatrix);
|
||||
node.getWorldMatrix(_worldMatrix);
|
||||
|
||||
for (let i = 0; i < vertexCount; i++) {
|
||||
let vert = data[i];
|
||||
vec3.set(vec3_temp, vert.x, vert.y, 0);
|
||||
// vec3.transformMat4(vec3_temp, vec3_temp, _worldMatrix);
|
||||
vec3.transformMat4(vec3_temp, vec3_temp, _worldMatrix);
|
||||
vbuf[vertexOffset++] = vec3_temp.x;
|
||||
vbuf[vertexOffset++] = vec3_temp.y;
|
||||
vbuf[vertexOffset++] = vec3_temp.z;
|
||||
vbuf[vertexOffset++] = vert.u;
|
||||
vbuf[vertexOffset++] = vert.v;
|
||||
uintbuf[vertexOffset++] = color;
|
||||
vbuf[vertexOffset++] = color.r;
|
||||
vbuf[vertexOffset++] = color.g;
|
||||
vbuf[vertexOffset++] = color.b;
|
||||
vbuf[vertexOffset++] = color.a;
|
||||
// uintbuf[vertexOffset++] = color;
|
||||
}
|
||||
|
||||
// fill indice data
|
||||
@@ -157,7 +173,11 @@ export function fillVerticesWithoutCalc(node, buffer, renderData, color) {
|
||||
vbuf[vertexOffset++] = vert.y;
|
||||
vbuf[vertexOffset++] = vert.u;
|
||||
vbuf[vertexOffset++] = vert.v;
|
||||
uintbuf[vertexOffset++] = color;
|
||||
// uintbuf[vertexOffset++] = color;
|
||||
vbuf[vertexOffset++] = color.r;
|
||||
vbuf[vertexOffset++] = color.g;
|
||||
vbuf[vertexOffset++] = color.b;
|
||||
vbuf[vertexOffset++] = color.a;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,15 +199,10 @@ export function fillVerticesWithoutCalc3D(node, buffer, renderData, color) {
|
||||
vbuf[vertexOffset++] = vert.z;
|
||||
vbuf[vertexOffset++] = vert.u;
|
||||
vbuf[vertexOffset++] = vert.v;
|
||||
uintbuf[vertexOffset++] = color;
|
||||
// uintbuf[vertexOffset++] = color;
|
||||
vbuf[vertexOffset++] = color.r;
|
||||
vbuf[vertexOffset++] = color.g;
|
||||
vbuf[vertexOffset++] = color.b;
|
||||
vbuf[vertexOffset++] = color.a;
|
||||
}
|
||||
}
|
||||
|
||||
// module.exports = {
|
||||
// fillVertices: fillVertices,
|
||||
// fillMeshVertices: fillMeshVertices,
|
||||
// fillVertices3D: fillVertices3D,
|
||||
// fillMeshVertices3D: fillMeshVertices3D,
|
||||
// fillVerticesWithoutCalc: fillVerticesWithoutCalc,
|
||||
// fillVerticesWithoutCalc3D: fillVerticesWithoutCalc3D
|
||||
// };
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
// @ts-check
|
||||
import SpriteFrame from '../../../assets/CCSpriteFrame';
|
||||
import { SpriteFrame } from '../../../assets/CCSpriteFrame';
|
||||
import ComponentEventHandler from '../../../components/CCComponentEventHandler';
|
||||
import { Component} from '../../../components/component';
|
||||
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../../core/data/class-decorator';
|
||||
@@ -33,7 +33,8 @@ import { lerp } from '../../../core/utils/misc';
|
||||
import { Color, Vec3 } from '../../../core/value-types/index';
|
||||
import * as math from '../../../core/vmath/index';
|
||||
import { Node } from '../../../scene-graph';
|
||||
import SpriteComponent from './sprite-component';
|
||||
import { SpriteComponent } from './sprite-component';
|
||||
import { EventTouch } from '../../../core/platform/event-manager';
|
||||
|
||||
/**
|
||||
* !#en Enum for transition type.
|
||||
@@ -96,24 +97,24 @@ const Transition = cc.Enum({
|
||||
*
|
||||
* 按钮可以绑定事件(但是必须要在按钮的 Node 上才能绑定事件):<br/>
|
||||
* // 以下事件可以在全平台上都触发<br/>
|
||||
* -cc.NodeUI.EventType.TOUCH_START // 按下时事件<br/>
|
||||
* -cc.NodeUI.EventType.TOUCH_Move // 按住移动后事件<br/>
|
||||
* -cc.NodeUI.EventType.TOUCH_END // 按下后松开后事件<br/>
|
||||
* -cc.NodeUI.EventType.TOUCH_CANCEL // 按下取消事件<br/>
|
||||
* -cc.Node.EventType.TOUCH_START // 按下时事件<br/>
|
||||
* -cc.Node.EventType.TOUCH_Move // 按住移动后事件<br/>
|
||||
* -cc.Node.EventType.TOUCH_END // 按下后松开后事件<br/>
|
||||
* -cc.Node.EventType.TOUCH_CANCEL // 按下取消事件<br/>
|
||||
* // 以下事件只在 PC 平台上触发<br/>
|
||||
* -cc.NodeUI.EventType.MOUSE_DOWN // 鼠标按下时事件<br/>
|
||||
* -cc.NodeUI.EventType.MOUSE_MOVE // 鼠标按住移动后事件<br/>
|
||||
* -cc.NodeUI.EventType.MOUSE_ENTER // 鼠标进入目标事件<br/>
|
||||
* -cc.NodeUI.EventType.MOUSE_LEAVE // 鼠标离开目标事件<br/>
|
||||
* -cc.NodeUI.EventType.MOUSE_UP // 鼠标松开事件<br/>
|
||||
* -cc.NodeUI.EventType.MOUSE_WHEEL // 鼠标滚轮事件<br/>
|
||||
* -cc.Node.EventType.MOUSE_DOWN // 鼠标按下时事件<br/>
|
||||
* -cc.Node.EventType.MOUSE_MOVE // 鼠标按住移动后事件<br/>
|
||||
* -cc.Node.EventType.MOUSE_ENTER // 鼠标进入目标事件<br/>
|
||||
* -cc.Node.EventType.MOUSE_LEAVE // 鼠标离开目标事件<br/>
|
||||
* -cc.Node.EventType.MOUSE_UP // 鼠标松开事件<br/>
|
||||
* -cc.Node.EventType.MOUSE_WHEEL // 鼠标滚轮事件<br/>
|
||||
*
|
||||
* @class Button
|
||||
* @extends Component
|
||||
* @example
|
||||
*
|
||||
* // Add an event to the button.
|
||||
* button.node.on(cc.NodeUI.EventType.TOUCH_START, function (event) {
|
||||
* button.node.on(cc.Node.EventType.TOUCH_START, function (event) {
|
||||
* cc.log("This is a callback after the trigger event");
|
||||
* });
|
||||
* // You could also add a click event
|
||||
@@ -451,13 +452,13 @@ export default class ButtonComponent extends Component {
|
||||
@property
|
||||
public _transition: number = Transition.NONE;
|
||||
@property
|
||||
public _normalColor: Color = cc.color(214, 214, 214);
|
||||
public _normalColor: Color = new Color(214, 214, 214);
|
||||
@property
|
||||
public _hoverColor: Color = cc.color(211, 211, 211);
|
||||
public _hoverColor: Color = new Color(211, 211, 211);
|
||||
@property
|
||||
public _pressColor: Color = cc.Color.WHITE;
|
||||
public _pressColor: Color = Color.WHITE;
|
||||
@property
|
||||
public _disabledColor: Color = cc.color(124, 124, 124);
|
||||
public _disabledColor: Color = new Color(124, 124, 124);
|
||||
@property
|
||||
public _normalSprite: SpriteFrame | null = null;
|
||||
@property
|
||||
@@ -465,7 +466,7 @@ export default class ButtonComponent extends Component {
|
||||
@property
|
||||
public _pressedSprite: SpriteFrame | null = null;
|
||||
@property
|
||||
public _disabledSprite = null;
|
||||
public _disabledSprite: SpriteFrame | null = null;
|
||||
@property
|
||||
public _duration: number = 0.1;
|
||||
@property
|
||||
@@ -477,13 +478,13 @@ export default class ButtonComponent extends Component {
|
||||
|
||||
public _pressed: boolean = false;
|
||||
public _hovered: boolean = false;
|
||||
public _fromColor: Color = cc.color();
|
||||
public _toColor: Color = cc.color();
|
||||
public _fromColor: Color = new Color();
|
||||
public _toColor: Color = new Color();
|
||||
public _time: number = 0;
|
||||
public _transitionFinished: boolean = true;
|
||||
public _fromScale: Vec3 = cc.v3();
|
||||
public _toScale: Vec3 = cc.v3();
|
||||
public _originalScale: Vec3 = cc.v3();
|
||||
public _fromScale: Vec3 = new Vec3();
|
||||
public _toScale: Vec3 = new Vec3();
|
||||
public _originalScale: Vec3 = new Vec3();
|
||||
public _sprite: SpriteComponent | null = null;
|
||||
public _previousNormalSprite: SpriteFrame | null = null;
|
||||
|
||||
@@ -535,11 +536,11 @@ export default class ButtonComponent extends Component {
|
||||
if (!CC_EDITOR) {
|
||||
this._registerEvent();
|
||||
} else {
|
||||
this.node.on('spriteframe-changed', function (comp) {
|
||||
this.node.on('spriteframe-changed', (comp) => {
|
||||
if (this._transition === Transition.SPRITE) {
|
||||
this._normalSprite = comp.spriteFrame;
|
||||
}
|
||||
}.bind(this));
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -547,19 +548,19 @@ export default class ButtonComponent extends Component {
|
||||
this._resetState();
|
||||
|
||||
if (!CC_EDITOR) {
|
||||
this.node.off(cc.NodeUI.EventType.TOUCH_START, this._onTouchBegan, this);
|
||||
this.node.off(cc.NodeUI.EventType.TOUCH_MOVE, this._onTouchMove, this);
|
||||
this.node.off(cc.NodeUI.EventType.TOUCH_END, this._onTouchEnded, this);
|
||||
this.node.off(cc.NodeUI.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
|
||||
this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this);
|
||||
this.node.off(cc.Node.EventType.TOUCH_MOVE, this._onTouchMove, this);
|
||||
this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this);
|
||||
this.node.off(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
|
||||
|
||||
this.node.off(cc.NodeUI.EventType.MOUSE_ENTER, this._onMouseMoveIn, this);
|
||||
this.node.off(cc.NodeUI.EventType.MOUSE_LEAVE, this._onMouseMoveOut, this);
|
||||
this.node.off(cc.Node.EventType.MOUSE_ENTER, this._onMouseMoveIn, this);
|
||||
this.node.off(cc.Node.EventType.MOUSE_LEAVE, this._onMouseMoveOut, this);
|
||||
} else {
|
||||
this.node.off('spriteframe-changed');
|
||||
}
|
||||
}
|
||||
|
||||
public update (dt) {
|
||||
public update (dt: number) {
|
||||
const target = this._target;
|
||||
if (this._transitionFinished) {
|
||||
return;
|
||||
@@ -591,13 +592,13 @@ export default class ButtonComponent extends Component {
|
||||
}
|
||||
|
||||
public _registerEvent () {
|
||||
this.node.on(cc.NodeUI.EventType.TOUCH_START, this._onTouchBegan, this);
|
||||
this.node.on(cc.NodeUI.EventType.TOUCH_MOVE, this._onTouchMove, this);
|
||||
this.node.on(cc.NodeUI.EventType.TOUCH_END, this._onTouchEnded, this);
|
||||
this.node.on(cc.NodeUI.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
|
||||
this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this);
|
||||
this.node.on(cc.Node.EventType.TOUCH_MOVE, this._onTouchMove, this);
|
||||
this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this);
|
||||
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
|
||||
|
||||
this.node.on(cc.NodeUI.EventType.MOUSE_ENTER, this._onMouseMoveIn, this);
|
||||
this.node.on(cc.NodeUI.EventType.MOUSE_LEAVE, this._onMouseMoveOut, this);
|
||||
this.node.on(cc.Node.EventType.MOUSE_ENTER, this._onMouseMoveIn, this);
|
||||
this.node.on(cc.Node.EventType.MOUSE_LEAVE, this._onMouseMoveOut, this);
|
||||
}
|
||||
|
||||
public _getTargetSprite (target: Node | null) {
|
||||
@@ -621,15 +622,23 @@ export default class ButtonComponent extends Component {
|
||||
|
||||
this._pressed = true;
|
||||
this._updateState();
|
||||
event.stopPropagation();
|
||||
event && event.stopPropagation();
|
||||
}
|
||||
|
||||
public _onTouchMove (event: Event | null) {
|
||||
if (!this._interactable || !this.enabledInHierarchy || !this._pressed) { return; }
|
||||
// mobile phone will not emit _onMouseMoveOut,
|
||||
// so we have to do hit test when touch moving
|
||||
const touch = event.touch;
|
||||
const hit = this.node._hitTest(touch.getLocation());
|
||||
if (!event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const touch = (event as EventTouch).touch;
|
||||
if (!touch) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const hit = this.node.uiTransfromComp!.isHit(touch.getLocation());
|
||||
|
||||
if (this._transition === Transition.SCALE && this._target) {
|
||||
if (hit) {
|
||||
@@ -663,7 +672,7 @@ export default class ButtonComponent extends Component {
|
||||
}
|
||||
this._pressed = false;
|
||||
this._updateState();
|
||||
event.stopPropagation();
|
||||
event && event.stopPropagation();
|
||||
}
|
||||
|
||||
public _onTouchCancel () {
|
||||
|
||||
@@ -25,16 +25,18 @@
|
||||
****************************************************************************/
|
||||
|
||||
import { ccclass, menu, executionOrder, executeInEditMode, property } from '../../../../core/data/class-decorator';
|
||||
import Component from '../../../../components/component';
|
||||
import { Component } from '../../../../components/component';
|
||||
import Color from '../../../../core/value-types/color';
|
||||
import macro from '../../../../core/platform/CCMacro';
|
||||
import EditBoxImpl from './edit-box-impl';
|
||||
import LabelComponent from '../label-component';
|
||||
import { EditBoxImpl} from './edit-box-impl';
|
||||
import { LabelComponent } from '../label-component';
|
||||
// import { InputMode, InputFlag, KeyboardReturnType } from './types';
|
||||
import * as Types from './types';
|
||||
import SpriteFrame from '../../../../assets/CCSpriteFrame';
|
||||
import { SpriteFrame } from '../../../../assets/CCSpriteFrame';
|
||||
import ComponentEventHandler from '../../../../components/CCComponentEventHandler';
|
||||
import SpriteComponent from '../sprite-component';
|
||||
import { SpriteComponent } from '../sprite-component';
|
||||
import { UIRenderComponent } from '../ui-render-component';
|
||||
import { UITransformComponent } from '../ui-transfrom-component';
|
||||
const InputMode = Types.InputMode;
|
||||
const InputFlag = Types.InputFlag;
|
||||
const KeyboardReturnType = Types.KeyboardReturnType;
|
||||
@@ -61,46 +63,69 @@ function capitalizeFirstLetter(string) {
|
||||
@executionOrder(100)
|
||||
@menu('UI/EditBox')
|
||||
@executeInEditMode
|
||||
export default class EditBoxComponent extends Component {
|
||||
export class EditBoxComponent extends Component {
|
||||
@property
|
||||
_useOriginalSize: boolean = true;
|
||||
_useOriginalSize = true;
|
||||
@property
|
||||
_string: string = '';
|
||||
_string = '';
|
||||
@property
|
||||
_tabIndex: number = 0;
|
||||
_tabIndex = 0;
|
||||
@property
|
||||
_backgroundImage: SpriteFrame | null = null;
|
||||
@property
|
||||
_returnType: number = KeyboardReturnType.DEFAULT;
|
||||
_returnType = KeyboardReturnType.DEFAULT;
|
||||
@property
|
||||
_inputFlag: number = InputFlag.DEFAULT;
|
||||
_inputFlag = InputFlag.DEFAULT;
|
||||
@property
|
||||
_inputMode: number = InputMode.SINGLE_LINE;
|
||||
_inputMode = InputMode.SINGLE_LINE;
|
||||
@property
|
||||
_fontSize: number = 20;
|
||||
_fontSize = 20;
|
||||
@property
|
||||
_lineHeight: number = 40;
|
||||
_lineHeight = 40;
|
||||
@property
|
||||
_maxLength: number = 20;
|
||||
_maxLength = 20;
|
||||
@property
|
||||
_fontColor: Color = Color.WHITE;
|
||||
@property
|
||||
_placeholder: string = 'Enter text here...';
|
||||
_placeholder = 'Enter text here...';
|
||||
@property
|
||||
_placeholderFontSize: number = 20;
|
||||
_placeholderFontSize = 20;
|
||||
@property
|
||||
_placeholderFontColor: Color = Color.GRAY;
|
||||
@property
|
||||
_stayOnTop: boolean = false;
|
||||
_stayOnTop = false;
|
||||
/**
|
||||
* !#en The event handler to be called when EditBox began to edit text.
|
||||
* !#zh 开始编辑文本输入框触发的事件回调。
|
||||
* @property {Component.EventHandler[]} editingDidBegan
|
||||
*/
|
||||
@property
|
||||
editingDidBegan: ComponentEventHandler[] = [];
|
||||
@property
|
||||
editingDidEnded: ComponentEventHandler[] = [];
|
||||
@property
|
||||
editingReturn: ComponentEventHandler[] = [];
|
||||
|
||||
/**
|
||||
* !#en The event handler to be called when EditBox text changes.
|
||||
* !#zh 编辑文本输入框时触发的事件回调。
|
||||
* @property {Component.EventHandler[]} textChanged
|
||||
*/
|
||||
@property
|
||||
textChanged: ComponentEventHandler[] = [];
|
||||
|
||||
/**
|
||||
* !#en The event handler to be called when EditBox edit ends.
|
||||
* !#zh 结束编辑文本输入框时触发的事件回调。
|
||||
* @property {Component.EventHandler[]} editingDidEnded
|
||||
*/
|
||||
@property
|
||||
editingDidEnded: ComponentEventHandler[] = [];
|
||||
|
||||
/**
|
||||
* !#en The event handler to be called when return key is pressed. Windows is not supported.
|
||||
* !#zh 当用户按下回车按键时的事件回调,目前不支持 windows 平台
|
||||
* @property {Component.EventHandler[]} editingReturn
|
||||
*/
|
||||
@property
|
||||
editingReturn: ComponentEventHandler[] = [];
|
||||
|
||||
_impl: EditBoxImpl | null = null;
|
||||
_textLabel: LabelComponent | null = null;
|
||||
_placeholderLabel: LabelComponent | null = null;
|
||||
@@ -116,7 +141,7 @@ export default class EditBoxComponent extends Component {
|
||||
return this._string;
|
||||
}
|
||||
|
||||
set string(value: string) {
|
||||
set string(value) {
|
||||
if (this._maxLength >= 0 && value.length >= this._maxLength) {
|
||||
value = value.slice(0, this._maxLength);
|
||||
}
|
||||
@@ -165,7 +190,7 @@ export default class EditBoxComponent extends Component {
|
||||
return this._returnType;
|
||||
}
|
||||
|
||||
set returnType(value: number) {
|
||||
set returnType(value) {
|
||||
this._returnType = value;
|
||||
if (this._impl) {
|
||||
this._impl.returnType = this._returnType;
|
||||
@@ -186,7 +211,7 @@ export default class EditBoxComponent extends Component {
|
||||
return this._inputFlag;
|
||||
}
|
||||
|
||||
set inputFlag(value: number) {
|
||||
set inputFlag(value) {
|
||||
this._inputFlag = value;
|
||||
if (this._impl) {
|
||||
this._impl.setInputFlag(this._inputFlag);
|
||||
@@ -209,7 +234,7 @@ export default class EditBoxComponent extends Component {
|
||||
return this._inputMode;
|
||||
}
|
||||
|
||||
set inputMode(value: number) {
|
||||
set inputMode(value) {
|
||||
this._inputMode = value;
|
||||
if (this._impl) {
|
||||
this._impl.setInputMode(this._inputMode);
|
||||
@@ -226,7 +251,7 @@ export default class EditBoxComponent extends Component {
|
||||
return this._fontSize;
|
||||
}
|
||||
|
||||
set fontSize(value: number) {
|
||||
set fontSize(value) {
|
||||
if (this._fontSize === value) {
|
||||
return;
|
||||
}
|
||||
@@ -251,7 +276,7 @@ export default class EditBoxComponent extends Component {
|
||||
return this._lineHeight;
|
||||
}
|
||||
|
||||
set lineHeight(value: number) {
|
||||
set lineHeight(value) {
|
||||
if (this._lineHeight === value) {
|
||||
return;
|
||||
}
|
||||
@@ -282,8 +307,11 @@ export default class EditBoxComponent extends Component {
|
||||
|
||||
this._fontColor = value;
|
||||
if (this._textLabel) {
|
||||
this._textLabel.node.opacity = this._fontColor.a;
|
||||
this._textLabel.node.color = this._fontColor;
|
||||
// this._textLabel.node.opacity = this._fontColor.a;
|
||||
let renderComp = this._textLabel.node.getComponent(UIRenderComponent);
|
||||
if (renderComp) {
|
||||
renderComp.color = this._fontColor;
|
||||
}
|
||||
}
|
||||
if (this._impl) {
|
||||
this._impl.setFontColor(this._fontColor);
|
||||
@@ -300,7 +328,7 @@ export default class EditBoxComponent extends Component {
|
||||
return this._placeholder;
|
||||
}
|
||||
|
||||
set placeholder(value: string) {
|
||||
set placeholder(value) {
|
||||
if (this._placeholder === value) {
|
||||
return;
|
||||
}
|
||||
@@ -324,7 +352,7 @@ export default class EditBoxComponent extends Component {
|
||||
return this._placeholderFontSize;
|
||||
}
|
||||
|
||||
set placeholderFontSize(value: number) {
|
||||
set placeholderFontSize(value) {
|
||||
if (this._placeholderFontSize === value) {
|
||||
return;
|
||||
}
|
||||
@@ -352,8 +380,11 @@ export default class EditBoxComponent extends Component {
|
||||
|
||||
this._placeholderFontColor = value;
|
||||
if (this._placeholderLabel) {
|
||||
this._placeholderLabel.node.color = this._placeholderFontColor;
|
||||
this._placeholderLabel.node.opacity = this._placeholderFontColor.a;
|
||||
let comp = this._placeholderLabel.node.getComponent(UIRenderComponent);
|
||||
if (comp) {
|
||||
comp.color = this._placeholderFontColor
|
||||
};
|
||||
// this._placeholderLabel.node.opacity = this._placeholderFontColor.a;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,7 +401,7 @@ export default class EditBoxComponent extends Component {
|
||||
get maxLength() {
|
||||
return this._maxLength;
|
||||
}
|
||||
set maxLength(value: number) {
|
||||
set maxLength(value) {
|
||||
if (this._maxLength === value) {
|
||||
return
|
||||
}
|
||||
@@ -392,7 +423,7 @@ export default class EditBoxComponent extends Component {
|
||||
return this._stayOnTop;
|
||||
}
|
||||
|
||||
set stayOnTop(value: boolean) {
|
||||
set stayOnTop(value) {
|
||||
this._stayOnTop = value;
|
||||
if (this._impl) {
|
||||
this._updateStayOnTop();
|
||||
@@ -409,81 +440,13 @@ export default class EditBoxComponent extends Component {
|
||||
return this._tabIndex;
|
||||
}
|
||||
|
||||
set tabIndex(value: number) {
|
||||
set tabIndex(value) {
|
||||
this._tabIndex = value;
|
||||
if (this._impl) {
|
||||
this._impl.setTabIndex(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en The event handler to be called when EditBox began to edit text.
|
||||
* !#zh 开始编辑文本输入框触发的事件回调。
|
||||
* @property {Component.EventHandler[]} editingDidBegan
|
||||
*/
|
||||
// @property({
|
||||
// default: [],
|
||||
// type: [ComponentEventHandler]
|
||||
// })
|
||||
// get editingDidBegan() {
|
||||
// return this._editingDidBegan;
|
||||
// }
|
||||
|
||||
// set editingDidBegan(value: ComponentEventHandler[]) {
|
||||
// this._editingDidBegan = value;
|
||||
// }
|
||||
|
||||
/**
|
||||
* !#en The event handler to be called when EditBox text changes.
|
||||
* !#zh 编辑文本输入框时触发的事件回调。
|
||||
* @property {Component.EventHandler[]} textChanged
|
||||
*/
|
||||
// @property({
|
||||
// default: [],
|
||||
// type: [ComponentEventHandler]
|
||||
// })
|
||||
// get textChanged() {
|
||||
// return this._textChanged;
|
||||
// }
|
||||
|
||||
// set textChanged(value: ComponentEventHandler[]) {
|
||||
// this._textChanged = value;
|
||||
// }
|
||||
|
||||
/**
|
||||
* !#en The event handler to be called when EditBox edit ends.
|
||||
* !#zh 结束编辑文本输入框时触发的事件回调。
|
||||
* @property {Component.EventHandler[]} editingDidEnded
|
||||
*/
|
||||
// @property({
|
||||
// default: [],
|
||||
// type: [ComponentEventHandler]
|
||||
// })
|
||||
// get editingDidEnded() {
|
||||
// return this._editingDidEnded;
|
||||
// }
|
||||
|
||||
// set editingDidEnded(value: ComponentEventHandler[]) {
|
||||
// this._editingDidEnded = value;
|
||||
// }
|
||||
|
||||
/**
|
||||
* !#en The event handler to be called when return key is pressed. Windows is not supported.
|
||||
* !#zh 当用户按下回车按键时的事件回调,目前不支持 windows 平台
|
||||
* @property {Component.EventHandler[]} editingReturn
|
||||
*/
|
||||
// @property({
|
||||
// default: [],
|
||||
// type: [ComponentEventHandler]
|
||||
// })
|
||||
// get editingReturn() {
|
||||
// return this._editingReturn;
|
||||
// }
|
||||
|
||||
// set editingReturn(value: ComponentEventHandler[]) {
|
||||
// this._editingReturn = value;
|
||||
// }
|
||||
|
||||
static _EditBoxImpl = EditBoxImpl;
|
||||
static KeyboardReturnType = KeyboardReturnType;
|
||||
static InputFlag = InputFlag;
|
||||
@@ -498,13 +461,13 @@ export default class EditBoxComponent extends Component {
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this._impl.clear();
|
||||
this._impl && this._impl.clear();
|
||||
}
|
||||
|
||||
_init() {
|
||||
this._createBackgroundSprite();
|
||||
this._createLabels();
|
||||
this.node.on(cc.NodeUI.EventType.SIZE_CHANGED, this._resizeChildNodes, this);
|
||||
this.node.on(cc.Node.EventType.SIZE_CHANGED, this._resizeChildNodes, this);
|
||||
|
||||
let impl = this._impl = new EditBoxImpl();
|
||||
|
||||
@@ -532,8 +495,8 @@ export default class EditBoxComponent extends Component {
|
||||
}
|
||||
|
||||
_registerEvent() {
|
||||
this.node.on(cc.NodeUI.EventType.TOUCH_START, this._onTouchBegan, this);
|
||||
this.node.on(cc.NodeUI.EventType.TOUCH_END, this._onTouchEnded, this);
|
||||
this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this);
|
||||
this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this);
|
||||
}
|
||||
|
||||
_updateStayOnTop() {
|
||||
@@ -543,17 +506,17 @@ export default class EditBoxComponent extends Component {
|
||||
else {
|
||||
this._showLabels();
|
||||
}
|
||||
this._impl.stayOnTop(this.stayOnTop);
|
||||
this._impl && this._impl.stayOnTop(this.stayOnTop);
|
||||
}
|
||||
|
||||
_syncSize() {
|
||||
let size = this.node.getContentSize();
|
||||
|
||||
this._background.node.setAnchorPoint(this.node.getAnchorPoint());
|
||||
this._background.node.setContentSize(size);
|
||||
this._background && this._background.node.setAnchorPoint(this.node.getAnchorPoint());
|
||||
this._background && this._background.node.setContentSize(size);
|
||||
|
||||
this._updateLabelPosition(size);
|
||||
this._impl.setSize(size.width, size.height);
|
||||
this._impl && this._impl.setSize(size.width, size.height);
|
||||
}
|
||||
|
||||
_updateLabelPosition(size) {
|
||||
@@ -563,25 +526,20 @@ export default class EditBoxComponent extends Component {
|
||||
|
||||
let placeholderLabel = this._placeholderLabel;
|
||||
let textLabel = this._textLabel;
|
||||
|
||||
textLabel.node.setContentSize(size.width - LEFT_PADDING, size.height);
|
||||
placeholderLabel.node.setContentSize(size.width - LEFT_PADDING, size.height);
|
||||
placeholderLabel.lineHeight = size.height;
|
||||
|
||||
placeholderLabel.node.setPosition(offx + LEFT_PADDING, offy + size.height);
|
||||
textLabel.node.setPosition(offx + LEFT_PADDING, offy + size.height);
|
||||
|
||||
if (this._inputMode === InputMode.ANY) {
|
||||
placeholderLabel.verticalAlign = macro.VerticalTextAlignment.TOP;
|
||||
placeholderLabel.enableWrapText = true;
|
||||
textLabel.verticalAlign = macro.VerticalTextAlignment.TOP;
|
||||
textLabel.enableWrapText = true;
|
||||
if (textLabel) {
|
||||
textLabel.node.setContentSize(size.width - LEFT_PADDING, size.height);
|
||||
textLabel.node.setPosition(offx + LEFT_PADDING, offy + size.height, textLabel.node.getPosition().z);
|
||||
textLabel.verticalAlign = this._inputMode === InputMode.ANY ? macro.VerticalTextAlignment.TOP : macro.VerticalTextAlignment.CENTER;
|
||||
textLabel.enableWrapText = this._inputMode === InputMode.ANY ? true : false;
|
||||
}
|
||||
else {
|
||||
placeholderLabel.verticalAlign = macro.VerticalTextAlignment.CENTER;
|
||||
placeholderLabel.enableWrapText = false;
|
||||
textLabel.verticalAlign = macro.VerticalTextAlignment.CENTER;
|
||||
textLabel.enableWrapText = false;
|
||||
|
||||
if (placeholderLabel) {
|
||||
placeholderLabel.node.setContentSize(size.width - LEFT_PADDING, size.height);
|
||||
placeholderLabel.lineHeight = size.height;
|
||||
placeholderLabel.node.setPosition(offx + LEFT_PADDING, offy + size.height, placeholderLabel.node.getPosition().z);
|
||||
placeholderLabel.verticalAlign = this._inputMode === InputMode.ANY ?
|
||||
macro.VerticalTextAlignment.TOP : macro.VerticalTextAlignment.CENTER;
|
||||
placeholderLabel.enableWrapText = this._inputMode === InputMode.ANY ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -591,15 +549,16 @@ export default class EditBoxComponent extends Component {
|
||||
if (!this._background) {
|
||||
this._background = this.node.addComponent(cc.SpriteComponent);
|
||||
}
|
||||
this._background.type = cc.SpriteComponent.Type.SLICED;
|
||||
|
||||
}
|
||||
|
||||
this._background.spriteFrame = this._backgroundImage;
|
||||
this._background!.type = cc.SpriteComponent.Type.SLICED;
|
||||
this._background!.spriteFrame = this._backgroundImage;
|
||||
// let background = this._background;
|
||||
// if (!background) {
|
||||
// let node = this.node.getChildByName('BACKGROUND_SPRITE');
|
||||
// if (!node) {
|
||||
// node = new cc.NodeUI('BACKGROUND_SPRITE');
|
||||
// node = new cc.Node('BACKGROUND_SPRITE');
|
||||
// }
|
||||
|
||||
// background = node.getComponent(cc.SpriteComponent);
|
||||
@@ -618,70 +577,84 @@ export default class EditBoxComponent extends Component {
|
||||
if (!this._textLabel) {
|
||||
let node = this.node.getChildByName('TEXT_LABEL');
|
||||
if (!node) {
|
||||
node = new cc.NodeUI('TEXT_LABEL');
|
||||
node = new cc.Node('TEXT_LABEL');
|
||||
}
|
||||
node.color = this._fontColor;
|
||||
node.parent = this.node;
|
||||
node.setAnchorPoint(0, 1);
|
||||
let textLabel = node!.getComponent(LabelComponent);
|
||||
node!.parent = this.node;
|
||||
|
||||
let textLabel = node.getComponent(LabelComponent);
|
||||
if (!textLabel) {
|
||||
textLabel = node.addComponent(LabelComponent);
|
||||
textLabel = node!.addComponent(LabelComponent);
|
||||
}
|
||||
textLabel.overflow = LabelComponent.Overflow.CLAMP;
|
||||
textLabel.fontSize = this._fontSize;
|
||||
textLabel.lineHeight = this.lineHeight;
|
||||
|
||||
let transformComp = node!.getComponent(UITransformComponent);
|
||||
transformComp!.setAnchorPoint(0, 1);
|
||||
textLabel!.color = this._fontColor;
|
||||
textLabel!.overflow = LabelComponent.Overflow.CLAMP;
|
||||
textLabel!.fontSize = this._fontSize;
|
||||
textLabel!.lineHeight = this.lineHeight;
|
||||
this._textLabel = textLabel;
|
||||
}
|
||||
|
||||
if (!this._placeholderLabel) {
|
||||
let node = this.node.getChildByName('PLACEHOLDER_LABEL');
|
||||
if (!node) {
|
||||
node = new cc.NodeUI('PLACEHOLDER_LABEL');
|
||||
node = new cc.Node('PLACEHOLDER_LABEL');
|
||||
}
|
||||
node.color = this._placeholderFontColor;
|
||||
node.parent = this.node;
|
||||
node.setAnchorPoint(0, 1);
|
||||
|
||||
let placeholderLabel = node.getComponent(LabelComponent);
|
||||
let placeholderLabel = node!.getComponent(LabelComponent);
|
||||
if (!placeholderLabel) {
|
||||
placeholderLabel = node.addComponent(LabelComponent);
|
||||
placeholderLabel = node!.addComponent(LabelComponent);
|
||||
}
|
||||
placeholderLabel.overflow = LabelComponent.Overflow.CLAMP;
|
||||
placeholderLabel.fontSize = this._placeholderFontSize;
|
||||
placeholderLabel.string = this._placeholder;
|
||||
let transform = node!.getComponent(UITransformComponent);
|
||||
|
||||
node!.parent = this.node;
|
||||
placeholderLabel!.color = this._placeholderFontColor;
|
||||
transform!.setAnchorPoint(0, 1);
|
||||
|
||||
|
||||
placeholderLabel!.overflow = LabelComponent.Overflow.CLAMP;
|
||||
placeholderLabel!.fontSize = this._placeholderFontSize;
|
||||
placeholderLabel!.string = this._placeholder;
|
||||
this._placeholderLabel = placeholderLabel;
|
||||
}
|
||||
}
|
||||
|
||||
_resizeChildNodes() {
|
||||
let textLabelNode = this._textLabel.node,
|
||||
placeholderLabelNode = this._placeholderLabel.node,
|
||||
backgroundNode = this._background.node;
|
||||
|
||||
textLabelNode.x = -this.node.width / 2;
|
||||
textLabelNode.y = this.node.height / 2;
|
||||
textLabelNode.width = this.node.width;
|
||||
textLabelNode.height = this.node.height;
|
||||
|
||||
placeholderLabelNode.x = -this.node.width / 2;
|
||||
placeholderLabelNode.y = this.node.height / 2;
|
||||
placeholderLabelNode.width = this.node.width;
|
||||
placeholderLabelNode.height = this.node.height;
|
||||
|
||||
backgroundNode.width = this.node.width;
|
||||
backgroundNode.height = this.node.height;
|
||||
const textLabelNode = this._textLabel && this._textLabel.node;
|
||||
if (textLabelNode) {
|
||||
textLabelNode.setPosition(-this.node.width / 2, this.node.height / 2, textLabelNode.getPosition().z);
|
||||
textLabelNode.width = this.node.width;
|
||||
textLabelNode.height = this.node.height;
|
||||
}
|
||||
const placeholderLabelNode = this._placeholderLabel && this._placeholderLabel.node;
|
||||
if (placeholderLabelNode) {
|
||||
placeholderLabelNode.setPosition(-this.node.width / 2, this.node.height / 2, placeholderLabelNode.getPosition().z);
|
||||
placeholderLabelNode.width = this.node.width;
|
||||
placeholderLabelNode.height = this.node.height;
|
||||
}
|
||||
const backgroundNode = this._background && this._background.node;
|
||||
if (backgroundNode) {
|
||||
backgroundNode.width = this.node.width;
|
||||
backgroundNode.height = this.node.height;
|
||||
}
|
||||
}
|
||||
|
||||
_showLabels() {
|
||||
let displayText = this._textLabel.string;
|
||||
this._textLabel.node.active = displayText !== '';
|
||||
this._placeholderLabel.node.active = displayText === '';
|
||||
if (this._textLabel) {
|
||||
let displayText = this._textLabel.string;
|
||||
this._textLabel.node.active = displayText !== '';
|
||||
if (this._placeholderLabel) {
|
||||
this._placeholderLabel.node.active = displayText === '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_hideLabels() {
|
||||
this._textLabel.node.active = false;
|
||||
this._placeholderLabel.node.active = false;
|
||||
if (this._textLabel) {
|
||||
this._textLabel.node.active = false;
|
||||
}
|
||||
if (this._placeholderLabel) {
|
||||
this._placeholderLabel.node.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
_updateString(text) {
|
||||
@@ -697,13 +670,15 @@ export default class EditBoxComponent extends Component {
|
||||
}
|
||||
|
||||
textLabel.string = displayText;
|
||||
this._impl.setString(text);
|
||||
if (!this._impl._editing && !this.stayOnTop) {
|
||||
this._showLabels();
|
||||
if (this._impl) {
|
||||
this._impl.setString(text);
|
||||
if (!this._impl._editing && !this.stayOnTop) {
|
||||
this._showLabels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_updateLabelStringStyle(text, ignorePassword) {
|
||||
_updateLabelStringStyle(text: string, ignorePassword: boolean = false) {
|
||||
let inputFlag = this._inputFlag;
|
||||
if (!ignorePassword && inputFlag === InputFlag.PASSWORD) {
|
||||
let passwordString = '';
|
||||
@@ -760,9 +735,9 @@ export default class EditBoxComponent extends Component {
|
||||
}
|
||||
|
||||
_onTouchCancel(event) {
|
||||
if (this._impl) {
|
||||
this._impl._onTouchCancel();
|
||||
}
|
||||
// if (this._impl) {
|
||||
// this._impl._onTouchCancel();
|
||||
// }
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import * as Types from './types';
|
||||
import * as math from '../../../../core/vmath';
|
||||
import { Size, Color } from '../../../../core/value-types';
|
||||
import { Node } from '../../../../scene-graph';
|
||||
import EditBoxComponent from './edit-box-component';
|
||||
import { EditBoxComponent} from './edit-box-component';
|
||||
const InputMode = Types.InputMode;
|
||||
const InputFlag = Types.InputFlag;
|
||||
const KeyboardReturnType = Types.KeyboardReturnType;
|
||||
@@ -81,25 +81,26 @@ function getKeyboardReturnType(type) {
|
||||
}
|
||||
|
||||
@ccclass
|
||||
export default class EditBoxImpl {
|
||||
export class EditBoxImpl {
|
||||
_delegate: EditBoxComponent | null = null;
|
||||
_inputMode: number = -1;
|
||||
_inputFlag: number = -1;
|
||||
_returnType: number = KeyboardReturnType.DEFAULT;
|
||||
_maxLength: number = 50;
|
||||
_text: string = '';
|
||||
_placeholderText: string = '';
|
||||
_alwaysOnTop: boolean = false;
|
||||
_inputMode= -1;
|
||||
_inputFlag= -1;
|
||||
_returnType= KeyboardReturnType.DEFAULT;
|
||||
_maxLength= 50;
|
||||
_text = '';
|
||||
_placeholderText = '';
|
||||
_alwaysOnTop = false;
|
||||
_size: Size = cc.size();
|
||||
_node: Node = null;
|
||||
_editing: boolean = false;
|
||||
_editing = false;
|
||||
__eventListeners: object = {};
|
||||
__fullscreen: boolean = false;
|
||||
__autoResize: boolean = false;
|
||||
__rotateScreen: boolean = false;
|
||||
__fullscreen = false;
|
||||
__autoResize = false;
|
||||
__rotateScreen = false;
|
||||
__orientationChanged: Function | null = null;
|
||||
_edTxt: HTMLElement | null = null;
|
||||
_textColor: Color = Color.WHITE;
|
||||
_edFontSize = 14;
|
||||
|
||||
onEnable() {
|
||||
if (!this._edTxt) {
|
||||
@@ -271,7 +272,7 @@ export default class EditBoxImpl {
|
||||
|
||||
let self = this;
|
||||
function startFocus() {
|
||||
self._edTxt.focus();
|
||||
self._edTxt!.focus();
|
||||
}
|
||||
|
||||
if (cc.sys.browserType === cc.sys.BROWSER_TYPE_UC) {
|
||||
@@ -319,7 +320,7 @@ export default class EditBoxImpl {
|
||||
if (!edTxt) return;
|
||||
|
||||
if (this._inputFlag === InputFlag.PASSWORD) {
|
||||
edTxt.type = 'password';
|
||||
edTxt!.type = 'password';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -367,7 +368,7 @@ export default class EditBoxImpl {
|
||||
|
||||
math.mat4.translate(_matrix, _matrix, _vec3);
|
||||
|
||||
let camera;
|
||||
// let camera;
|
||||
// can't find camera in editor
|
||||
// if (CC_EDITOR) {
|
||||
// camera = cc.Camera.main;
|
||||
@@ -379,7 +380,8 @@ export default class EditBoxImpl {
|
||||
if (!renderComp) {
|
||||
return false;
|
||||
}
|
||||
let canvas = cc.CanvasComponent.findView(renderComp);
|
||||
// let canvas = cc.CanvasComponent.findView(renderComp);
|
||||
let canvas = cc.director.root.ui.getScreen()
|
||||
if (!canvas) {
|
||||
return;
|
||||
}
|
||||
@@ -532,7 +534,7 @@ export default class EditBoxImpl {
|
||||
tmpEdTxt.type = 'text';
|
||||
tmpEdTxt.style.fontSize = this._edFontSize + 'px';
|
||||
tmpEdTxt.style.color = '#000000';
|
||||
tmpEdTxt.style.border = 0;
|
||||
tmpEdTxt.style.border = '0';
|
||||
tmpEdTxt.style.background = 'transparent';
|
||||
tmpEdTxt.style.width = '100%';
|
||||
tmpEdTxt.style.height = '100%';
|
||||
@@ -597,7 +599,7 @@ function _inputValueHandle(input, editBoxImpl) {
|
||||
}
|
||||
}
|
||||
|
||||
function registerInputEventListener(tmpEdTxt: HTMLElement, editBoxImpl: EditBoxImpl, isTextarea: boolean = false) {
|
||||
function registerInputEventListener(tmpEdTxt: HTMLElement, editBoxImpl: EditBoxImpl, isTextarea = false) {
|
||||
let inputLock = false;
|
||||
let cbs = editBoxImpl.__eventListeners;
|
||||
cbs.compositionstart = function () {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
import { Component} from '../../../components/component';
|
||||
import { clamp01 } from '../../../core/utils/misc';
|
||||
import { ccclass, menu, executionOrder, executeInEditMode, property } from '../../../core/data/class-decorator';
|
||||
import SpriteComponent from './sprite-component';
|
||||
import { SpriteComponent } from './sprite-component';
|
||||
|
||||
|
||||
/**
|
||||
@@ -83,7 +83,7 @@ var Mode = cc.Enum({
|
||||
@executionOrder(100)
|
||||
@menu('UI/ProgressBar')
|
||||
// @executeInEditMode
|
||||
export default class ProgressBarComponent extends Component {
|
||||
export class ProgressBarComponent extends Component {
|
||||
@property
|
||||
_barSprite: SpriteComponent | null = null;
|
||||
@property
|
||||
@@ -300,7 +300,7 @@ export default class ProgressBarComponent extends Component {
|
||||
var anchorOffsetY = anchorPoint.y - entityAnchorPoint.y;
|
||||
var finalPosition = cc.v2(totalWidth * anchorOffsetX, totalHeight * anchorOffsetY);
|
||||
|
||||
entity.setPosition(entityPosition.x + finalPosition.x, entityPosition.y + finalPosition.y);
|
||||
entity.setPosition(entityPosition.x + finalPosition.x, entityPosition.y + finalPosition.y, entity.getPosition().z);
|
||||
|
||||
entity.setAnchorPoint(anchorPoint);
|
||||
entity.setContentSize(finalContentSize);
|
||||
|
||||
@@ -27,11 +27,12 @@
|
||||
import { Component} from '../../../components/component';
|
||||
import { clamp01 } from '../../../core/utils/misc';
|
||||
import { ccclass, menu, executionOrder, executeInEditMode, property } from '../../../core/data/class-decorator';
|
||||
import SpriteComponent from './sprite-component';
|
||||
import { SpriteComponent} from './sprite-component';
|
||||
import { Vec2 } from '../../../core/value-types/index';
|
||||
import ComponentEventHandler from '../../../components/CCComponentEventHandler';
|
||||
import Event from '../../../core/event/event';
|
||||
import { EventTouch } from '../../../core/platform/event-manager/CCEvent';
|
||||
import { UITransformComponent } from './ui-transfrom-component';
|
||||
/**
|
||||
* !#en The Slider Direction
|
||||
* !#zh 滑动器方向
|
||||
@@ -62,7 +63,7 @@ var Direction = cc.Enum({
|
||||
@executionOrder(100)
|
||||
@menu('UI/Slider')
|
||||
// @executeInEditMode
|
||||
export default class SliderComponent extends Component {
|
||||
export class SliderComponent extends Component {
|
||||
@property
|
||||
_handle: SpriteComponent | null = null;
|
||||
@property
|
||||
@@ -72,7 +73,7 @@ export default class SliderComponent extends Component {
|
||||
@property
|
||||
_slideEvents: ComponentEventHandler[] = [];
|
||||
|
||||
_offset: Vec2 = cc.v2();
|
||||
_offset: Vec2 = new Vec2();
|
||||
_dragging = false;
|
||||
_touchHandle = false;
|
||||
|
||||
@@ -186,38 +187,42 @@ export default class SliderComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
_onHandleDragStart(event: Event | null) {
|
||||
_onHandleDragStart(event: Event) {
|
||||
if (!event){
|
||||
return;
|
||||
}
|
||||
|
||||
this._dragging = true;
|
||||
this._touchHandle = true;
|
||||
this._offset = this._handle.node.convertToNodeSpaceAR(event.touch.getLocation());
|
||||
this._offset = this._handle && this._handle.node.uiTransfromComp && this._handle.node.uiTransfromComp.convertToNodeSpaceAR((event as EventTouch).touch.getLocation());
|
||||
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
_onTouchBegan(event: Event | null) {
|
||||
_onTouchBegan(event: Event) {
|
||||
if (!this._handle) { return; }
|
||||
this._dragging = true;
|
||||
if (!this._touchHandle) {
|
||||
this._handleSliderLogic(event.touch);
|
||||
this._handleSliderLogic((event as EventTouch).touch);
|
||||
}
|
||||
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
_onTouchMoved(event: Event | null) {
|
||||
_onTouchMoved(event: Event) {
|
||||
if (!this._dragging) { return; }
|
||||
this._handleSliderLogic(event.touch);
|
||||
this._handleSliderLogic((event as EventTouch).touch);
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
_onTouchEnded(event: Event | null) {
|
||||
_onTouchEnded(event: Event) {
|
||||
this._dragging = false;
|
||||
this._touchHandle = false;
|
||||
this._offset = cc.v2();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
_onTouchCancelled(event: Event | null) {
|
||||
_onTouchCancelled(event: Event) {
|
||||
this._dragging = false;
|
||||
event.stopPropagation();
|
||||
}
|
||||
@@ -232,9 +237,9 @@ export default class SliderComponent extends Component {
|
||||
this.node.emit('slide', this);
|
||||
}
|
||||
|
||||
_updateProgress(touch: EventTouch | null) {
|
||||
_updateProgress(touch: EventTouch) {
|
||||
if (!this._handle) { return; }
|
||||
var localTouchPos = this.node.convertToNodeSpaceAR(touch.getLocation());
|
||||
var localTouchPos = this.node.uiTransfromComp!.convertToNodeSpaceAR((touch as EventTouch).getLocation());
|
||||
if (this.direction === Direction.Horizontal) {
|
||||
this.progress = clamp01(0.5 + (localTouchPos.x - this._offset.x) / this.node.width);
|
||||
}
|
||||
@@ -252,8 +257,11 @@ export default class SliderComponent extends Component {
|
||||
else {
|
||||
handlelocalPos = cc.v2(0, -this.node.height * this.node.anchorY + this.progress * this.node.height);
|
||||
}
|
||||
var worldSpacePos = this.node.convertToWorldSpaceAR(handlelocalPos);
|
||||
this._handle.node.setPosition(this._handle.node.parent.convertToNodeSpaceAR(worldSpacePos));
|
||||
var worldSpacePos = this.node.uiTransfromComp!.convertToWorldSpaceAR(handlelocalPos);
|
||||
let transform: UITransformComponent | null = this._handle.node.parent && this._handle.node.parent.getComponent(cc.UITransformComponent);
|
||||
if(transform){
|
||||
this._handle.node.setPosition(transform.convertToNodeSpaceAR(worldSpacePos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import { Vec2, Enum } from '../../../core/value-types';
|
||||
import { MeshBuffer } from '../mesh-buffer';
|
||||
import { UIRenderComponent } from './ui-render-component';
|
||||
import { Node } from '../../../scene-graph/node';
|
||||
import { UI } from '../../../renderer/ui/ui';
|
||||
const EventType = Node.EventType;
|
||||
|
||||
/**
|
||||
@@ -399,11 +400,11 @@ export class SpriteComponent extends UIRenderComponent {
|
||||
// this.node.on(EventType.ANCHOR_CHANGED, this._onNodeSizeDirty, this);
|
||||
}
|
||||
|
||||
public updateAssembler (buffer: MeshBuffer) {
|
||||
public updateAssembler (render: UI) {
|
||||
if (!this._spriteFrame || !this.material) {
|
||||
return;
|
||||
}
|
||||
super.updateAssembler(buffer);
|
||||
super.updateAssembler(render);
|
||||
}
|
||||
|
||||
public onDestroy () {
|
||||
|
||||
@@ -26,10 +26,8 @@
|
||||
import ComponentEventHandler from '../../../components/CCComponentEventHandler';
|
||||
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../../core/data/class-decorator';
|
||||
import ButtonComponent from './button-component';
|
||||
// import * as js from '../../core/utils/js';
|
||||
import RenderComponent from './render-component';
|
||||
import SpriteComponent from './sprite-component';
|
||||
import ToggleGroupComponent from './toggle-group-component';
|
||||
import { SpriteComponent} from './sprite-component';
|
||||
import { ToggleGroupComponent} from './toggle-group-component';
|
||||
|
||||
/**
|
||||
* !#en The toggle component is a CheckBox, when it used together with a ToggleGroup, it
|
||||
@@ -42,7 +40,7 @@ import ToggleGroupComponent from './toggle-group-component';
|
||||
@executionOrder(100)
|
||||
@menu('UI/Toggle')
|
||||
@executeInEditMode
|
||||
export default class ToggleComponent extends ButtonComponent {
|
||||
export class ToggleComponent extends ButtonComponent {
|
||||
@property
|
||||
public _isChecked: boolean = true;
|
||||
@property
|
||||
|
||||
@@ -39,7 +39,7 @@ import { Component } from '../../../components/component';
|
||||
import { ccclass, executeInEditMode, menu, property } from '../../../core/data/class-decorator';
|
||||
|
||||
@ccclass('cc.ToggleContainerComponent')
|
||||
export default class ToggleContainerComponent extends Component {
|
||||
export class ToggleContainerComponent extends Component {
|
||||
@property
|
||||
protected _allowSwitchOff = false;
|
||||
@property
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
****************************************************************************/
|
||||
import { Component} from '../../../components/component';
|
||||
import { ccclass, menu, executionOrder, executeInEditMode, property } from '../../../core/data/class-decorator';
|
||||
import ToggleComponent from './toggle-component';
|
||||
import { ToggleComponent} from './toggle-component';
|
||||
|
||||
/**
|
||||
* !#en ToggleGroup is not a visiable UI component but a way to modify the behavior of a set of Toggles.
|
||||
@@ -40,7 +40,7 @@ import ToggleComponent from './toggle-component';
|
||||
@executionOrder(100)
|
||||
@menu('UI/ToggleGroup')
|
||||
@executeInEditMode
|
||||
export default class ToggleGroupComponent extends Component {
|
||||
export class ToggleGroupComponent extends Component {
|
||||
@property
|
||||
_allowSwitchOff: boolean = false;
|
||||
_toggleItems: ToggleComponent[] = [];
|
||||
|
||||
@@ -268,8 +268,6 @@ export class UIRenderComponent extends RenderableComponent {
|
||||
this._assembler.updateRenderData(this);
|
||||
}
|
||||
this._assembler.fillBuffers(this, render);
|
||||
|
||||
return this._assembler.getRenderBuffers();
|
||||
}
|
||||
|
||||
public postUpdateAssembler () {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Component} from '../../../components/component';
|
||||
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../../core/data/class-decorator';
|
||||
import Event from '../../../core/platform/event-manager/CCEvent.js';
|
||||
import Size from '../../../core/value-types/size';
|
||||
import Vec2 from '../../../core/value-types/vec2';
|
||||
import * as math from '../../../core/vmath/index';
|
||||
import { Enum } from '../../../core/value-types';
|
||||
import { Enum, Mat4 } from '../../../core/value-types';
|
||||
import Event from '../../../core/event/event';
|
||||
|
||||
const _vec2a = cc.v2();
|
||||
const _vec2b = cc.v2();
|
||||
@@ -145,10 +145,11 @@ export class UITransformComponent extends Component {
|
||||
* node.setContentSize(cc.size(100, 100));
|
||||
* node.setContentSize(100, 100);
|
||||
*/
|
||||
public setContentSize (size: Size, height: number) {
|
||||
public setContentSize (size: Size|number, height?: number) {
|
||||
const locContentSize = this._contentSize;
|
||||
// var clone;
|
||||
if (height === undefined) {
|
||||
size = size as Size;
|
||||
if ((size.width === locContentSize.width) && (size.height === locContentSize.height)) {
|
||||
return;
|
||||
}
|
||||
@@ -197,9 +198,10 @@ export class UITransformComponent extends Component {
|
||||
* node.setAnchorPoint(cc.v2(1, 1));
|
||||
* node.setAnchorPoint(1, 1);
|
||||
*/
|
||||
public setAnchorPoint (point: Vec2, y: number) {
|
||||
public setAnchorPoint (point: Vec2 | number, y?: number) {
|
||||
const locAnchorPoint = this._anchorPoint;
|
||||
if (y === undefined) {
|
||||
point = point as Vec2;
|
||||
if ((point.x === locAnchorPoint.x) && (point.y === locAnchorPoint.y)) {
|
||||
return;
|
||||
}
|
||||
@@ -218,7 +220,7 @@ export class UITransformComponent extends Component {
|
||||
// }
|
||||
}
|
||||
|
||||
public isHit (point: Vec2, listener: Event) {
|
||||
public isHit (point: Vec2, listener: Event|null = null) {
|
||||
const w = this._contentSize.width;
|
||||
const h = this._contentSize.height;
|
||||
const cameraPt = _vec2a;
|
||||
@@ -271,7 +273,7 @@ export class UITransformComponent extends Component {
|
||||
// find mask parent, should hit test it
|
||||
if (parent === mask.node) {
|
||||
const comp = parent.getComponent(cc.Mask);
|
||||
return (comp && comp.enabledInHierarchy) ? comp._hitTest(cameraPt) : true;
|
||||
return (comp && comp.enabledInHierarchy) ? comp.node.uiTransfromComp!.isHit(cameraPt) : true;
|
||||
} else {
|
||||
listener.mask = null;
|
||||
return true;
|
||||
@@ -283,4 +285,40 @@ export class UITransformComponent extends Component {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Converts a Point to node (local) space coordinates in which the anchor point is the origin position.
|
||||
* !#zh
|
||||
* 将一个点转换到节点 (局部) 空间坐标系,这个坐标系以锚点为原点。
|
||||
* @method convertToNodeSpaceAR
|
||||
* @param {Vec2} worldPoint
|
||||
* @return {Vec2}
|
||||
* @example
|
||||
* var newVec2 = node.convertToNodeSpaceAR(cc.v2(100, 100));
|
||||
*/
|
||||
convertToNodeSpaceAR(worldPoint) {
|
||||
let matrix = new Mat4();
|
||||
this.node.getWorldMatrix(matrix);
|
||||
math.mat4.invert(_mat4_temp, matrix);
|
||||
let out = new cc.Vec2();
|
||||
return math.vec2.transformMat4(out, worldPoint, _mat4_temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Converts a Point in node coordinates to world space coordinates.
|
||||
* !#zh
|
||||
* 将节点坐标系下的一个点转换到世界空间坐标系。
|
||||
* @method convertToWorldSpaceAR
|
||||
* @param {Vec2} nodePoint
|
||||
* @return {Vec2}
|
||||
* @example
|
||||
* var newVec2 = node.convertToWorldSpaceAR(cc.v2(100, 100));
|
||||
*/
|
||||
convertToWorldSpaceAR(nodePoint) {
|
||||
this.node.getWorldMatrix(_worldMatrix);
|
||||
let out = new cc.Vec2();
|
||||
return math.vec2.transformMat4(out, nodePoint, _worldMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
+33
-16
@@ -80,6 +80,13 @@ export class MeshBuffer {
|
||||
this._vertexBytes = this.calculateBytes(this._vertexFormat);
|
||||
this._initVDataCount = data.vertexCount * this._vertexBytes;
|
||||
this._initIDataCount = data.indiceCount;
|
||||
this.primitiveMode = GFXPrimitiveMode.TRIANGLE_LIST;
|
||||
this.byteOffset = 0;
|
||||
this.byteStart = 0;
|
||||
this.indiceStart = 0;
|
||||
this.indiceOffset = 0;
|
||||
this.vertexStart = 0;
|
||||
this.vertexOffset = 0;
|
||||
this._reallocBuffer();
|
||||
}
|
||||
|
||||
@@ -143,35 +150,45 @@ export class MeshBuffer {
|
||||
}
|
||||
|
||||
public _reallocVData (copyOldData) {
|
||||
let oldVData;
|
||||
if (this.vData) {
|
||||
oldVData = new Uint8Array(this.vData.buffer);
|
||||
// let oldVData;
|
||||
// if (this.vData) {
|
||||
// if (this._initVDataCount * 4 > this.vData.byteLength){
|
||||
// oldVData = new Uint8Array(this.vData.buffer);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (this.vData && this.vData.byteLength === this._initVDataCount){
|
||||
return;
|
||||
}
|
||||
|
||||
this.vData = new Float32Array(this._initVDataCount);
|
||||
// this.uintVData = new Uint32Array(this.vData.buffer);
|
||||
const newData = new Uint8Array(this.vData.buffer);
|
||||
// const newData = new Uint8Array(this.vData.buffer);
|
||||
|
||||
if (oldVData && copyOldData) {
|
||||
for (let i = 0, l = oldVData.length; i < l; i++) {
|
||||
newData[i] = oldVData[i];
|
||||
}
|
||||
}
|
||||
// if (oldVData && copyOldData) {
|
||||
// for (let i = 0, l = oldVData.length; i < l; i++) {
|
||||
// newData[i] = oldVData[i];
|
||||
// }
|
||||
// }
|
||||
|
||||
// this._vb._bytes = this.vData.byteLength;
|
||||
}
|
||||
|
||||
public _reallocIData (copyOldData) {
|
||||
const oldIData = this.iData;
|
||||
// const oldIData = this.iData;
|
||||
|
||||
if (this.iData && this.iData.byteLength === this._initIDataCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.iData = new Uint16Array(this._initIDataCount);
|
||||
|
||||
if (oldIData && copyOldData) {
|
||||
const iData = this.iData;
|
||||
for (let i = 0, l = oldIData.length; i < l; i++) {
|
||||
iData[i] = oldIData[i];
|
||||
}
|
||||
}
|
||||
// if (oldIData && copyOldData) {
|
||||
// const iData = this.iData;
|
||||
// for (let i = 0, l = oldIData.length; i < l; i++) {
|
||||
// iData[i] = oldIData[i];
|
||||
// }
|
||||
// }
|
||||
|
||||
// this._ib._bytes = this.iData.byteLength;
|
||||
}
|
||||
|
||||
@@ -234,8 +234,8 @@ export class SpriteFrame extends Texture2D {
|
||||
|
||||
this._capInsets[INSET_BOTTOM] = 0;
|
||||
this._capInsets[INSET_LEFT] = 0;
|
||||
this._capInsets[INSET_RIGHT] = 1;
|
||||
this._capInsets[INSET_TOP] = 1;
|
||||
this._capInsets[INSET_RIGHT] = 0;
|
||||
this._capInsets[INSET_TOP] = 0;
|
||||
|
||||
if (CC_EDITOR) {
|
||||
// Atlas asset uuid
|
||||
|
||||
@@ -59,7 +59,7 @@ export class UI {
|
||||
}, 128);
|
||||
|
||||
private _screens: CanvasComponent[] = [];
|
||||
private _bufferPool: RecyclePool = new RecyclePool(() => {
|
||||
private _bufferPool: RecyclePool<MeshBuffer> = new RecyclePool(() => {
|
||||
return new MeshBuffer();
|
||||
}, 128);
|
||||
private _device: GFXDevice;
|
||||
|
||||
Reference in New Issue
Block a user