183 lines
4.8 KiB
TypeScript
183 lines
4.8 KiB
TypeScript
import { CoroutineV2 } from "../../CatanEngine/CoroutineV2/CoroutineV2";
|
|
import ScreenResize from "./ScreenResize";
|
|
import SwitchActiveGroup from "./SwitchShowUI/SwitchActiveGroup";
|
|
import SwitchImgGroup from "./SwitchShowUI/SwitchImgGroup";
|
|
import SwitchPositionGroup from "./SwitchShowUI/SwitchPositionGroup";
|
|
import SwitchRotationGroup from "./SwitchShowUI/SwitchRotationGroup";
|
|
import SwitchScaleGroup from "./SwitchShowUI/SwitchScaleGroup";
|
|
import SwitchWHGroup from "./SwitchShowUI/SwitchWHGroup";
|
|
import { UIManager } from "./UIManager";
|
|
|
|
const { ccclass } = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class UIPanel extends cc.Component {
|
|
|
|
/**[基底UIPanel]等待跳出旗標*/
|
|
private _isWaiting: boolean = false;
|
|
|
|
/**
|
|
* [基底UIPanel]初始化實做(UI每次創建時呼叫, 只會呼叫一次)
|
|
* @param initData
|
|
*/
|
|
protected ImplementInitial(...initData: any[]): void {
|
|
}
|
|
|
|
/**
|
|
* [基底UIPanel]顯示準備實做(UI顯示前呼叫)
|
|
* @param param
|
|
*/
|
|
protected *ImplementReadyShow(...param: any[]): IterableIterator<any> {
|
|
}
|
|
|
|
/**
|
|
* [基底UIPanel]顯示實做(UI顯示呼叫)
|
|
* @param param
|
|
*/
|
|
protected *ImplementShow(): IterableIterator<any> {
|
|
}
|
|
|
|
/**
|
|
* [基底UIPanel]隱藏(實做)
|
|
* @param param
|
|
*/
|
|
protected *ImplementHide(...param: any[]): IterableIterator<any> {
|
|
}
|
|
|
|
/**
|
|
* [基底UIPanel]移除實做
|
|
*/
|
|
protected ImplementDestroy() {
|
|
}
|
|
|
|
/**
|
|
* [基底UIPanel]直橫版切換
|
|
* @param param
|
|
*/
|
|
public ChangeDire(param: any[] = null): void {
|
|
if (!cc.isValid(this)) {
|
|
return;
|
|
}
|
|
cc.log("ChangeDire:" + this.name);
|
|
if (this.getComponent(SwitchScaleGroup)) {
|
|
this.getComponent(SwitchScaleGroup).Run();
|
|
}
|
|
if (this.getComponent(SwitchPositionGroup)) {
|
|
this.getComponent(SwitchPositionGroup).Run();
|
|
}
|
|
if (this.getComponent(SwitchWHGroup)) {
|
|
this.getComponent(SwitchWHGroup).Run();
|
|
}
|
|
if (this.getComponent(SwitchImgGroup)) {
|
|
this.getComponent(SwitchImgGroup).Run();
|
|
}
|
|
if (this.getComponent(SwitchActiveGroup)) {
|
|
this.getComponent(SwitchActiveGroup).Run();
|
|
}
|
|
if (this.getComponent(SwitchRotationGroup)) {
|
|
this.getComponent(SwitchRotationGroup).Run();
|
|
}
|
|
this._uiMaskHandler();
|
|
|
|
}
|
|
private _uiMaskHandler(): void {
|
|
let mask: cc.Node = this.node.getChildByName("Mask");
|
|
if (mask && this.node.parent.name == "ElementContent") {
|
|
let size: cc.Vec2 = ScreenResize.CanvasSize[ScreenResize.IsPortrait];
|
|
mask.SetSizeDelta(cc.v2(size.x / UIManager.ScreenScale, size.y / UIManager.ScreenScale));
|
|
}
|
|
}
|
|
//=======================================================================================
|
|
/**
|
|
* [禁止複寫]創UI
|
|
* @param source
|
|
* @param parent
|
|
* @param data
|
|
*/
|
|
public static CreateUI(source: cc.Prefab, parent: cc.Node, ...data: any[]): UIPanel {
|
|
let node = parent.ExAddChild(source);
|
|
let script = node.getComponent(UIPanel);
|
|
script.Initial(...data);
|
|
return script;
|
|
}
|
|
|
|
/**
|
|
* [禁止複寫]初始化
|
|
* @param initData
|
|
*/
|
|
public Initial(...initData: any[]): void {
|
|
UIManager.DireEvent.RemoveByBindTarget(this);
|
|
UIManager.DireEvent.AddCallback(this.ChangeDire, this);
|
|
this.node.active = false;
|
|
this._uiMaskHandler();
|
|
this.ImplementInitial(...initData);
|
|
}
|
|
|
|
/**
|
|
* [禁止複寫]顯示UI
|
|
* @param param
|
|
*/
|
|
public *Show(...param: any[]): IterableIterator<any> {
|
|
yield* this.ImplementReadyShow(...param);
|
|
this.node.active = true;
|
|
yield* this.ImplementShow();
|
|
}
|
|
|
|
/**
|
|
* [禁止複寫]隱藏UI
|
|
* @param param
|
|
*/
|
|
public *Hide(...param: any[]): IterableIterator<any> {
|
|
if (this._isWaiting) {
|
|
cc.warn(this.node.name, "_isWaiting = true無法關閉");
|
|
}
|
|
else {
|
|
yield* this.ImplementHide(...param);
|
|
if (this && this.node) {
|
|
this.node.active = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* [禁止複寫]等待UI
|
|
* @param showData
|
|
* @param hideData
|
|
*/
|
|
public *Wait(showData: any[] = [], hideData: any[] = []): IterableIterator<any> {
|
|
yield* this.Show(...showData);
|
|
this._isWaiting = true;
|
|
while (this._isWaiting) {
|
|
yield null;
|
|
}
|
|
yield* this.Hide(...hideData);
|
|
}
|
|
|
|
/**
|
|
* [禁止複寫]關閉UI
|
|
* @param param
|
|
*/
|
|
public Close(...param: any[]): void {
|
|
if (this._isWaiting) {
|
|
this._isWaiting = false;
|
|
}
|
|
else {
|
|
CoroutineV2.Single(this.Hide(...param)).Start();
|
|
}
|
|
}
|
|
|
|
//=======================================================================================
|
|
onLoad() {
|
|
UIManager.DireEvent.RemoveByBindTarget(this);
|
|
UIManager.DireEvent.AddCallback(this.ChangeDire, this);
|
|
}
|
|
//COCOS引擎內建生命週期
|
|
//onLoad->start->update->lateUpdate->onDestroy->onEnable->onDisable
|
|
onDestroy() {
|
|
UIManager.DireEvent.RemoveByBindTarget(this);
|
|
this.ImplementDestroy();
|
|
}
|
|
|
|
//=======================================================================================
|
|
}
|