[fix] HoldButton 點擊事件衝突

This commit is contained in:
2022-05-05 19:19:28 +08:00
parent 4aabd0b866
commit d771dd7593
20 changed files with 3594 additions and 6079 deletions

View File

@@ -30,9 +30,6 @@ export default class HoldButton extends cc.Component {
//#region private
/** 按钮的点击事件列表 */
private _clickEvents: cc.Component.EventHandler[] = [];
private _isOnInvoke: boolean = false;
private _m_isMouseDown: boolean = false;
@@ -44,8 +41,6 @@ export default class HoldButton extends cc.Component {
//#region Lifecycle
protected start(): void {
this._clickEvents = Array.from(this.getComponent(cc.Button).clickEvents);
this.getComponent(cc.Button).clickEvents.Clear();
if (this.HoldLine != null) {
this.HoldLine.active = false;
}
@@ -86,6 +81,8 @@ export default class HoldButton extends cc.Component {
}
if (this._m_pressDeltaTime > this.MaxTime) {
this.node.pauseSystemEvents(true);
this._isOnInvoke = true;
this._m_isMouseDown = false;
if (this.IsHaveHoldLine) {
@@ -94,7 +91,7 @@ export default class HoldButton extends cc.Component {
this._m_pressDeltaTime = 0;
if (this.OnInvoke != null) {
this.OnInvoke.forEach((eventHandler: cc.Component.EventHandler) => {
if (eventHandler.target === <any>"AddListener" && eventHandler.component === "AddListener" && eventHandler.handler) {
if (eventHandler.target === <any>"Callback" && eventHandler.component === "Callback" && eventHandler.handler) {
(<Function><unknown>eventHandler.handler)();
} else {
eventHandler.emit([this.node.getComponent(cc.Button)]);
@@ -119,31 +116,23 @@ export default class HoldButton extends cc.Component {
}
private _onTouchEnd(event: cc.Event.EventTouch): void {
this.node.resumeSystemEvents(true);
this._m_isMouseDown = false;
this._m_pressDeltaTime = 0;
if (this.IsHaveHoldLine) {
this.HoldLine.active = false;
}
if (!this._isOnInvoke) {
this._clickEvents.forEach((eventHandler: cc.Component.EventHandler) => {
eventHandler.emit([this.node.getComponent(cc.Button)]);
});
}
this._isOnInvoke = false;
this._checkHoldAutoStart(0);
}
private _onTouchCancel(event: cc.Event.EventTouch): void {
this.node.resumeSystemEvents(true);
this._m_isMouseDown = false;
this._m_pressDeltaTime = 0;
if (this.IsHaveHoldLine) {
this.HoldLine.active = false;
}
if (!this._isOnInvoke) {
this._clickEvents.forEach((eventHandler: cc.Component.EventHandler) => {
eventHandler.emit([this.node.getComponent(cc.Button)]);
});
}
this._isOnInvoke = false;
this._checkHoldAutoStart(0);
}