[add] Engine

This commit is contained in:
2022-08-26 16:48:17 +08:00
parent f67e566f2a
commit d9c19f096c
197 changed files with 10626 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
const { ccclass, requireComponent, menu, property } = cc._decorator;
@ccclass
@menu("Plug-in/Button/BlockDoubleClickButton")
@requireComponent(cc.Button)
export default class BlockDoubleClickButton extends cc.Component {
//#region Lifecycle
protected onEnable(): void {
this.node.on("click", this.OnClickNode, this);
}
protected onDisable(): void {
this.node.off("click", this.OnClickNode, this);
}
//#endregion
//#region Event
public OnClickNode(event: cc.Button, customEventData: any): void {
this.getComponent(cc.Button).interactable = false;
}
//#endregion
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "b9536e4d-70cc-4d90-ac7d-4af5134f9cc7",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,81 @@
// import CSSettingsV3 from "../../../FormTable/CSSettingsV3";
const { ccclass, requireComponent, menu, property } = cc._decorator;
/** 有冷卻功能的按鈕 */
@ccclass
@menu("Plug-in/Button/ButtonClickCD")
@requireComponent(cc.Button)
export default class ButtonClickCD extends cc.Component {
//#region property
@property()
public CDTime: number = 3;
//#endregion
//#region public
public Msg: string;
//#endregion
//#region private
private _nowCDTime: number = 0;
//#endregion
//#region Lifecycle
protected onLoad(): void {
this.loadMsg();
}
private async loadMsg(): Promise<void> {
let CSSettingsV3: any = (await (import("../../../FormTable/CSSettingsV3"))).default;
this.Msg = CSSettingsV3.prototype.CommonString(1514);
}
protected update(dt: number): void {
if (this._nowCDTime > 0) {
this._nowCDTime -= dt;
if (this._nowCDTime <= 0) {
this._nowCDTime = 0;
this.getComponent(cc.Button).interactable = true;
}
}
}
protected onEnable(): void {
this.node.on("click", this._onClick, this);
this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchStart, this);
}
protected onDisable(): void {
this.node.off("click", this._onClick, this);
this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchStart, this);
}
//#endregion
//#region Custom
private _onClick(event: cc.Button, customEventData: any): void {
// if (this._nowCDTime > 0) {
// CSMessage.CreateYesMsg(String.Format(this.Msg, this._nowCDTime.toFixed(0)));
// return;
// }
this.getComponent(cc.Button).interactable = false;
this._nowCDTime = this.CDTime;
}
private async _onTouchStart(event: cc.Event.EventTouch): Promise<void> {
if (this._nowCDTime > 0) {
let CSMessage: any = (await (import("../../../Common/Message/CSMessage"))).default;
CSMessage.CreateYesMsg(String.Format(this.Msg, this._nowCDTime.toFixed(0)));
}
}
//#endregion
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "c9dc0a70-6d91-4d02-8ceb-8be96cc33225",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,143 @@
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;
/** 是否HoldLine */
@property({ displayName: "是否有HoldLine", tooltip: "是否HoldLine" })
public IsHaveHoldLine: boolean = false;
@property({ type: cc.Node, visible(): boolean { return this.IsHaveHoldLine; } })
public HoldLine: cc.Node = null;
@property({ type: cc.Sprite, visible(): boolean { return this.IsHaveHoldLine; } })
public ProgressBG: cc.Sprite = null;
@property({ type: cc.Sprite, visible(): boolean { return this.IsHaveHoldLine; } })
public ProgressLine: cc.Sprite = null;
@property({ type: [cc.Component.EventHandler] })
public OnInvoke: cc.Component.EventHandler[] = [];
//#endregion
//#region private
private _isOnInvoke: boolean = false;
private _m_isMouseDown: boolean = false;
private _m_pressDeltaTime: number = 0;
//#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.IsHaveHoldLine) {
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.IsHaveHoldLine) {
// 蓄能條顯示特效
this.ProgressLine.fillRange = this._m_pressDeltaTime;
}
if (this._m_pressDeltaTime > this.MaxTime) {
this.node.pauseSystemEvents(true);
this._isOnInvoke = true;
this._m_isMouseDown = false;
if (this.IsHaveHoldLine) {
this.HoldLine.active = false;
}
this._m_pressDeltaTime = 0;
if (this.OnInvoke != null) {
this.OnInvoke.forEach((eventHandler: cc.Component.EventHandler) => {
if (eventHandler) {
if (eventHandler.target === <any>"Callback" && eventHandler.component === "Callback" && eventHandler.handler) {
(<Function><unknown>eventHandler.handler)();
} else {
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;
if (this.IsHaveHoldLine) {
this.HoldLine.active = true;
}
}
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;
}
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;
}
this._isOnInvoke = false;
this._checkHoldAutoStart(0);
}
//#endregion
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "1472bab3-e5de-4d9a-a761-ccf2787ad36f",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,90 @@
const { ccclass, property } = cc._decorator;
@ccclass
export default class LongTouchComponent extends cc.Component {
@property({
tooltip: "触摸回调间隔。假如为0.1那么1秒内会回调10次 ${longTouchEvents} 事件数组"
})
touchInterval: number = 0.1;
@property({
type: [cc.Component.EventHandler],
tooltip: "回调事件数组,每间隔 ${toucheInterval}s 回调一次"
})
longTouchEvents: cc.Component.EventHandler[] = [];
/**
* 触摸计数器,用于统计本次长按的回调次数
*/
private _touchCounter: number = 0;
/**
* 标记当前是否在触摸这个节点
*/
private _isTouching: boolean = false;
onEnable() {
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);
}
onDisable() {
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);
}
private _onTouchStart(event: cc.Event.EventTouch) {
if (this._isTouching) {
return;
}
if (this.node.getBoundingBoxToWorld().contains(event.getLocation())) {
this._isTouching = true;
} else {
this._isTouching = false;
}
if (this._isTouching) {
// 第一次触摸立即回调一次
this.publishOneTouch();
// 然后开启计时器,计算后续的长按相当于触摸了多少次
this.schedule(this._touchCounterCallback, this.touchInterval);
}
}
private _onTouchEnd(event: cc.Event.EventTouch) {
this._isTouching = false;
this._touchCounter = 0;
this.unschedule(this._touchCounterCallback);
}
private _onTouchCancel(event: cc.Event.EventTouch) {
this._isTouching = false;
this._touchCounter = 0;
this.unschedule(this._touchCounterCallback);
}
private _touchCounterCallback() {
if (this._isTouching) {
this.publishOneTouch();
} else {
this.unschedule(this._touchCounterCallback);
}
}
/**
* 通知出去:被点击/触摸了一次,长按时,会连续多次回调这个方法
*/
private publishOneTouch() {
if (!this._isTouching) {
return;
}
this._touchCounter++;
this.longTouchEvents.forEach((eventHandler: cc.Component.EventHandler) => {
eventHandler.emit([this._touchCounter]);
});
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "29b183d5-ec75-4a1b-b99e-88b2c99f796f",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}