[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);
}

View File

@@ -10,8 +10,8 @@ export default class LocalStorageData {
}
// =======================================================================================
public get GameConfig(): string { return cc.sys.localStorage.getItem("GameConfig"); }
public set GameConfig(value: string) { cc.sys.localStorage.setItem("GameConfig", value); }
// public get GameConfig(): string { return cc.sys.localStorage.getItem("GameConfig"); }
// public set GameConfig(value: string) { cc.sys.localStorage.setItem("GameConfig", value); }
public get AvatarSettings(): string { return cc.sys.localStorage.getItem("AvatarSettings"); }
public set AvatarSettings(value: string) { cc.sys.localStorage.setItem("AvatarSettings", value); }

View File

@@ -22,18 +22,6 @@ declare interface Array<T> {
AddListener(call: Function): void;
}
Array.prototype.AddListener || Object.defineProperty(Array.prototype, "AddListener", {
enumerable: false,
value: function (call: Function): void {
let EventHandler: cc.Component.EventHandler = new cc.Component.EventHandler();
EventHandler.target = <any>"AddListener";
EventHandler.component = "AddListener";
EventHandler.handler = <any>call;
this.push(EventHandler);
console.log(`AddListener`);
}
});
Array.prototype.ExRemoveAt || Object.defineProperty(Array.prototype, "ExRemoveAt", {
enumerable: false,
value: function (index: number): any {
@@ -93,4 +81,15 @@ Array.prototype.ObjectSort || Object.defineProperty(Array.prototype, "ObjectSort
}
return arr;
}
});
Array.prototype.AddListener || Object.defineProperty(Array.prototype, "AddListener", {
enumerable: false,
value: function (call: Function): void {
let EventHandler: cc.Component.EventHandler = new cc.Component.EventHandler();
EventHandler.target = <any>"Callback";
EventHandler.component = "Callback";
EventHandler.handler = <any>call;
this.push(EventHandler);
}
});