[add] script

[add] HoldButton
This commit is contained in:
2022-05-02 21:04:23 +08:00
parent 26f0052207
commit 119db9b977
39 changed files with 5052 additions and 2726 deletions

View File

@@ -0,0 +1,127 @@
const { ccclass, requireComponent, menu, property } = cc._decorator;
@ccclass
@menu("Plug-in/Button/HoldButton")
@requireComponent(cc.Button)
export default class HoldButton extends cc.Component {
//#region public
@property()
public MaxTime: number = 2;
@property({ type: cc.Node })
public HoldLine: cc.Node = null;
@property({ type: cc.Sprite })
public ProgressBG: cc.Sprite = null;
@property({ type: cc.Sprite })
public ProgressLine: cc.Sprite = null;
@property({ type: [cc.Component.EventHandler] })
public OnInvoke: cc.Component.EventHandler[] = [];
//#endregion
//#region private
private _m_isMouseDown: boolean = false;
private _m_pressDeltaTime: number = 0;
private _m_noLineUI: boolean = true;
//#endregion
//#region Lifecycle
protected start(): void {
if (this.HoldLine != null) {
this.HoldLine.active = false;
}
}
protected update(dt: number): void {
if (this._m_isMouseDown) {
this._checkHoldAutoStart(dt);
} else {
if (!this._m_noLineUI) {
this.HoldLine.active = false;
}
}
}
protected onEnable(): void {
this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchStart, this);
this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnd, this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
}
protected onDisable(): void {
this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchStart, this);
this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnd, this);
this.node.off(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
}
//#endregion
//#region Custom
private _checkHoldAutoStart(deltaTime: number): void {
this._m_pressDeltaTime += deltaTime;
if (!this._m_noLineUI) {
// 蓄能條顯示特效
this.ProgressLine.fillRange = this._m_pressDeltaTime;
}
if (this._m_pressDeltaTime > this.MaxTime) {
this._m_isMouseDown = false;
if (!this._m_noLineUI) {
this.HoldLine.active = false;
}
this._m_pressDeltaTime = 0;
if (this.OnInvoke != null) {
this.OnInvoke.forEach((eventHandler: cc.Component.EventHandler) => {
eventHandler.emit([this.node.getComponent(cc.Button)]);
});
}
}
}
//#endregion
//#region EventT
private _onTouchStart(event: cc.Event.EventTouch): void {
if (this._m_isMouseDown) {
return;
}
this._m_isMouseDown = true;
this._m_noLineUI = this.HoldLine == null || this.ProgressBG == null || this.ProgressLine == null;
if (!this._m_noLineUI) {
this.HoldLine.active = true;
}
}
private _onTouchEnd(event: cc.Event.EventTouch): void {
this._m_isMouseDown = false;
this._m_pressDeltaTime = 0;
if (!this._m_noLineUI) {
this.HoldLine.active = false;
}
this._checkHoldAutoStart(0);
}
private _onTouchCancel(event: cc.Event.EventTouch): void {
this._m_isMouseDown = false;
this._m_pressDeltaTime = 0;
if (!this._m_noLineUI) {
this.HoldLine.active = false;
}
this._checkHoldAutoStart(0);
}
//#endregion
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.8",
"uuid": "0d1d51df-9f21-4b00-ad91-612a56dfcedd",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -1,45 +1,18 @@
export default class LocalStorageData {
private static _instance: LocalStorageData = null;
public static get Instance(): LocalStorageData {
return LocalStorageData._instance;
}
private static _instance: LocalStorageData = null;
public static get Instance(): LocalStorageData {
return LocalStorageData._instance;
}
constructor() {
LocalStorageData._instance = this;
}
constructor() {
LocalStorageData._instance = this;
}
// =======================================================================================
public get RemoteVerList(): string { return cc.sys.localStorage.getItem("RemoteVerList"); }
public set RemoteVerList(value: string) { cc.sys.localStorage.setItem("RemoteVerList", value); }
public get LocalVerList(): string { return cc.sys.localStorage.getItem("LocalVerList"); }
public set LocalVerList(value: string) { cc.sys.localStorage.setItem("LocalVerList", value); }
public get ComboDeviceID(): string { return cc.sys.localStorage.getItem("ComboDeviceID"); }
public set ComboDeviceID(value: string) { cc.sys.localStorage.setItem("ComboDeviceID", value); }
public get BundleUrl(): string { return cc.sys.localStorage.getItem("BundleUrl"); }
public set BundleUrl(value: string) { cc.sys.localStorage.setItem("BundleUrl", value); }
public get Language(): string { return cc.sys.localStorage.getItem("language"); }
public set Language(value: string) { cc.sys.localStorage.setItem("language", value); }
public get MusicType(): string { return cc.sys.localStorage.getItem("MusicType"); }
public set MusicType(value: string) { cc.sys.localStorage.setItem("MusicType", value); }
public get SoundType(): string { return cc.sys.localStorage.getItem("SoundType"); }
public set SoundType(value: string) { cc.sys.localStorage.setItem("SoundType", value); }
public get DownloadList_Preview(): string { return cc.sys.localStorage.getItem("DownloadList_Preview"); }
public set DownloadList_Preview(value: string) { cc.sys.localStorage.setItem("DownloadList_Preview", value); }
// =======================================================================================
public get GameConfig(): string { return cc.sys.localStorage.getItem("GameConfig"); }
public set GameConfig(value: string) { cc.sys.localStorage.setItem("GameConfig", value); }
/**
* key: id
* value: 是否開過卡
*/
public get BingoCardInfo(): Map<number, boolean> { return cc.sys.localStorage.getItem("BingoCardInfo") ? new Map(JSON.parse(cc.sys.localStorage.getItem("BingoCardInfo"))) : new Map<number, boolean>(); }
public set BingoCardInfo(value: Map<number, boolean>) { cc.sys.localStorage.setItem("BingoCardInfo", JSON.stringify(Array.from(value.entries()))); }
/**
* key: id
* value: 是否開過卡
*/
public get FiveCardInfo(): Map<number, boolean> { return cc.sys.localStorage.getItem("FiveCardInfo") ? new Map(JSON.parse(cc.sys.localStorage.getItem("FiveCardInfo"))) : new Map<number, boolean>(); }
public set FiveCardInfo(value: Map<number, boolean>) { cc.sys.localStorage.setItem("FiveCardInfo", JSON.stringify(Array.from(value.entries()))); }
// =======================================================================================
public get AvatarSettings(): string { return cc.sys.localStorage.getItem("AvatarSettings"); }
public set AvatarSettings(value: string) { cc.sys.localStorage.setItem("AvatarSettings", value); }
}

View File

@@ -4,6 +4,8 @@ declare interface Array<T> {
* @param index
*/
ExRemoveAt(index: number): T;
/** 移除全部值 */
Clear(): void;
/**
* 物件陣列排序asc&key陣列長度請一樣
* PS. boolean 帶false是先true在false
@@ -22,6 +24,13 @@ Array.prototype.ExRemoveAt || Object.defineProperty(Array.prototype, "ExRemoveAt
}
});
Array.prototype.Clear || Object.defineProperty(Array.prototype, "Clear", {
enumerable: false,
value: function (): void {
this.length = 0;
}
});
Array.prototype.ObjectSort || Object.defineProperty(Array.prototype, "ObjectSort", {
enumerable: false,
/**