import AvatarPanel from "../AvatarPanel/AvatarPanel"; import { CoroutineV2 } from "../Engine/CatanEngine/CoroutineV2/CoroutineV2"; import HoldButton from "../Engine/Component/Button/HoldButton"; import LocalStorageData from "../Engine/Data/LocalStorageData"; import HistoryPanel from "../HistoryPanel/HistoryPanel"; import Lobby from "../Lobby/Lobby"; import ScoreBoard from "../ScoreBoard/ScoreBoard"; import VoicePanel from "../VoicePanel/VoicePanel"; import NodePackageManager from "../_BootLoader/Npm/NodePackageManager"; import ConfigManager from "./ConfigManager"; import { GameRecord, MemberData, ScoreResult } from "./MemberData"; import RecordManager from "./RecordManager"; const { ccclass, property } = cc._decorator; /** 最上層彈跳試窗與各場景間傳參數(因為熱更新APP在LOGING才能加入) */ @ccclass export class Badminton extends cc.Component { //#region property @property({ type: cc.Prefab }) private toggleItem: cc.Prefab = null; @property({ type: cc.Prefab }) private teamItem: cc.Prefab = null; @property({ type: cc.EditBox }) private inputNameText: cc.EditBox = null; @property({ type: cc.Label }) private storageText: cc.Label = null; @property({ type: cc.Node }) public ToggleItemContent: cc.Node = null; @property({ type: cc.Node }) public TeamItemContent: cc.Node = null; @property({ type: ScoreBoard }) public ScoreBoard: ScoreBoard = null; @property({ type: AvatarPanel }) public AvatarPanel: AvatarPanel = null; @property({ type: HistoryPanel }) public HistoryPanel: HistoryPanel = null; @property({ type: VoicePanel }) public VoicePanel: VoicePanel = null; @property({ type: Lobby }) public Lobby: Lobby = null; // @property({ type: AudioListSwitch }) // public GameBGM: AudioListSwitch = null; // @property({ type: AudioListSwitch }) // public TextToSpeech: TextToSpeech { get; private set; } //#endregion //#region 實例 /** Badminton實例 */ private static _instance: Badminton = null; public static get Instance(): Badminton { return this._instance; } //#endregion //#region public public TeamMemberList: MemberData[] = []; /** 目前所有可用玩家名單 */ public CurMemberList: string[] = []; /** 預設球員(塞空格) */ public defaultMember: MemberData = new MemberData("那個"); /** RecordManager */ public record: RecordManager = new RecordManager(this); /** ConfigManager */ public config: ConfigManager = new ConfigManager(this); //#endregion //#region private private _m_toggleList: cc.Toggle[] = []; private _m_teamList: cc.Node[] = []; /** 各玩家分數比賽次數記錄 */ private _dictionary: Map = new Map(); /** 比賽歷史記錄(記錄每場次的參賽玩家組合與順序) [{time,team:[[name1,name2],[name3,name4]],type,score:[t1,t2] },] */ private _m_history: GameRecord[] = []; //#endregion //#region get set public static get Today(): string { return NodePackageManager.Instance.Dayjs().format("yyyyMMdd"); } public get TeamCount(): number { return this._m_teamList.length; } /** 比賽歷史記錄(記錄每場次的參賽玩家組合與順序) [{time,team:[[name1,name2],[name3,name4]],type,score:[t1,t2] },] */ public get History(): GameRecord[] { return this._m_history; } //#endregion //#region 初始化 protected onLoad(): void { Badminton._instance = this; new LocalStorageData(); this.config.Init(); this.record.Init(); CoroutineV2.Parallel( this.Lobby.Show(), this.ScoreBoard.Show(), ).Start(); if (this.HistoryPanel != null) { this.HistoryPanel.LoadRecord(); this.HistoryPanel.Hide(); CoroutineV2.Single(this.HistoryPanel.Hide()).Start(); } // textToSpeech = FindObjectOfType(); } protected start(): void { CoroutineV2.Single(this.ScoreBoard.Hide()).Start(); this._initUI(); // LoadStatus(); // // 跨日後計分清除 // if (PlayerPrefs.GetString("date") != today) // { // Debug.LogWarning("跨日後計分清除"); // ClearAllGameResult(); // } // URLSchemeHandler.Init(); } //#endregion //#region Custom private _initUI(): void { this._updateCurSelMember(); // this.toggleItem.gameObject.SetActive(false); // this.teamItem.gameObject.SetActive(false); let parent: cc.Node = this.TeamItemContent; for (let i: number = parent.childrenCount - 1; i > 0; i--) { parent.children[i].destroy(); } this._m_teamList.Clear(); parent = this.ToggleItemContent; for (let i: number = parent.childrenCount - 1; i > 0; i--) { parent.children[i].destroy(); } this._m_toggleList.Clear(); for (let idx: number = 0; idx < this.TeamMemberList.length; idx++) { let memberName: string = this.TeamMemberList[idx].Name; let item: cc.Toggle = parent.ExAddChild(this.toggleItem).getComponent(cc.Toggle); item.node.getChildByName("Label").getComponent(cc.Label).string = memberName; item.node.active = true; item.node.getChildByName("Btn_Del").on("click", () => { this.OnDelMember(idx); }, this); let picObj: cc.Node = item.node.getChildByName("Avatar").getChildByName("Pic"); if (picObj != null) { picObj.getComponent(cc.Sprite).spriteFrame = this.config.GetAvatarPicById(this.TeamMemberList[idx].AvatarId); // picObj.GetComponent().OnInvoke.AddListener(this.OnChangeAvatar(idx)); let EventHandler: cc.Component.EventHandler = new cc.Component.EventHandler(); EventHandler.target = this.node; EventHandler.component = this.name.split("<")[1].split(">")[0]; EventHandler.handler = "OnChangeAvatar"; EventHandler.customEventData = idx.toString(); picObj.getComponent(HoldButton).OnInvoke.push(EventHandler); picObj.on("click", () => { item.isChecked = !item.isChecked; }, this); } this._m_toggleList.push(item); item.isChecked = this.CurMemberList.indexOf(memberName) !== -1; item.node.on("toggle", this._onChangeSelMember, this); } } public ReloadUI(): void { let chkMemberList: string[] = this.GetMemberListFromTeamView(); this._initUI(); this._updateTeamShow(chkMemberList); } private _onChangeSelMember(toggle: cc.Toggle): void { let val: boolean = toggle.isChecked; this._updateCurSelMember(); let chkMemberList: string[] = this.GetMemberListFromTeamView(); let dName: string = this.GetDefaultMemberName(); let selName: string = null; if (val) { for (let i: number = 0; i < this.CurMemberList.length; i++) { if (chkMemberList.indexOf(this.CurMemberList[i]) === -1) { selName = this.CurMemberList[i]; break; } } for (let i: number = 0; i < chkMemberList.length; i++) { if (chkMemberList[i] === dName) { chkMemberList[i] = selName; this._updateTeamShow(chkMemberList); return; } } if (selName != null) { chkMemberList.push(selName); } this._updateTeamShow(chkMemberList); } else { for (let i: number = 0; i < chkMemberList.length; i++) { if (this.CurMemberList.indexOf(chkMemberList[i]) === -1) { selName = chkMemberList[i]; if (i === chkMemberList.length - 1) { chkMemberList.ExRemoveAt(chkMemberList.length - 1); } else { chkMemberList[i] = this.GetDefaultMemberName(); } this._updateTeamShow(chkMemberList); break; } } } } private _updateCurSelMember(): void { this.CurMemberList.Clear(); this._m_toggleList.forEach((member: cc.Toggle) => { if (member.isChecked) { this.CurMemberList.push(member.node.getChildByName("Label").getComponent(cc.Label).string); } }); if (this.TeamMemberList != null && this.TeamMemberList.length > 0) { this.CurMemberList.push(this.GetDefaultMemberName()); } } public GetMemberListFromTeamView(): string[] { let chkMemberList: string[] = []; for (let i: number = 0; i < this._m_teamList.length; i++) { let team: cc.Node = this._m_teamList[i]; if (!team.active) { break; } for (let j: number = 0; j < 2; j++) { let memberName: string = team.getChildByName("Member_" + (j + 1) + "/Text").getComponent(cc.Label).string; chkMemberList.push(memberName); } } return chkMemberList; } public GetDefaultMemberName(): string { return "那個"; } private _updateTeamShow(chkMemberList: string[]): void { let teamCount: number = chkMemberList.length / 2; let maxTeam: number = Math.ceil(chkMemberList.length / 2.0); while (this._m_teamList.length > maxTeam) { this._m_teamList[this._m_teamList.length - 1].destroy(); this._m_teamList.ExRemoveAt(this._m_teamList.length - 1); } if (maxTeam === 0 || (chkMemberList.length === 1 && chkMemberList[0] === this.GetDefaultMemberName())) { return; } for (let i: number = 0; i < maxTeam; i++) { let obj: cc.Node; if (i >= this._m_teamList.length) { obj = this.TeamItemContent.ExAddChild(this.teamItem); this._m_teamList.push(obj); } else { obj = this._m_teamList[i]; } obj.getChildByName("Member_1").getChildByName("Text").getComponent(cc.Label).string = ""; obj.getChildByName("Member_2").getChildByName("Text").getComponent(cc.Label).string = ""; obj.getChildByName("Member_1").getComponent(cc.Sprite).enabled = false; obj.getChildByName("Member_2").getComponent(cc.Sprite).enabled = false; obj.active = false; } let index: number = 0; for (let idx: number = 0; idx < teamCount && idx < maxTeam; idx++) { if (chkMemberList[0] === chkMemberList[1] && chkMemberList[0] === this.GetDefaultMemberName()) { chkMemberList.splice(0, 2); continue; } let team: cc.Node = this._m_teamList[index++]; team.getChildByName("No").getComponent(cc.Label).string = index.toString(); for (let j: number = 0; j < 2; j++) { let name: string = chkMemberList[0]; if (j === 0 && name === this.GetDefaultMemberName()) { name = chkMemberList[1]; chkMemberList.ExRemoveAt(1); } else { chkMemberList.ExRemoveAt(0); } team.getChildByName("Member_" + (j + 1) + "/Text").getComponent(cc.Label).string = name; team.getChildByName("Member_" + (j + 1)).getComponent(cc.Sprite).enabled = name !== this.GetDefaultMemberName(); team.getChildByName("Member_" + (j + 1)).getComponent(cc.Sprite).spriteFrame = this.config.GetAvatarPicByName(name); team.active = true; } } if (chkMemberList.length > 0 && teamCount < maxTeam) { let name_1: string = chkMemberList[0]; let name_2: string = this.GetDefaultMemberName(); let team: cc.Node = this._m_teamList[teamCount]; team.getChildByName("Member_1").getChildByName("Text").getComponent(cc.Label).string = name_1; team.getChildByName("Member_2").getChildByName("Text").getComponent(cc.Label).string = name_2; team.getChildByName("Member_1").getComponent(cc.Sprite).enabled = true; team.getChildByName("Member_1").getComponent(cc.Sprite).spriteFrame = this.config.GetAvatarPicByName(name_1); team.getChildByName("No").getComponent(cc.Label).string = (index + 1).toString(); team.active = true; } } public OnDelMember(index: number): void { let viewTeamList: string[] = this.GetMemberListFromTeamView(); let player: MemberData = this.TeamMemberList[index]; let teamIndex: number = viewTeamList.indexOf(player.Name); if (teamIndex !== -1) { viewTeamList[teamIndex] = this.GetDefaultMemberName(); } this.TeamMemberList.ExRemoveAt(index); this._initUI(); this._updateTeamShow(viewTeamList); if (teamIndex !== -1) { this._updateCurSelMember(); } } public OnChangeAvatar(index: number): void { index = +index; console.log("OnChangeAvatar"); // this.AvatarPanel.OpenChange(teamMemberList[index]); } public Log(a, b): void { console.log("Log"); } //#endregion } // //#region 初始化 // onLoad(): void { // Badminton._instance = this; // this.ElementCommonUI = this.getComponent(CommonElementUI); // this.LastScene = SceneName.Loading; // this.NowScene = SceneName.Login; // this._cachErrorHandler(); // this._initialEngine(); // } // onDestroy(): void { // Badminton._instance = null; // } // private _initialEngine(): void { // if (cc.sys.isBrowser) { // this._createIframeCloseBtn(); // } // cc.game.addPersistRootNode(this.node); // // 多点触摸事件屏蔽 // cc.macro.ENABLE_MULTI_TOUCH = false; // // WEBVIEW // this._setWeb(); // // // CSResource.Initialize(); // CSMessage.Initialize(this.SourceMessage, this.MessageContent); // if (cc.sys.isBrowser) { // this.node.removeComponent(cc.Mask); // } // // MASK // let maskNode: cc.Node = null; // if (this.ElementCommonUI.DelayLoadMask) { // maskNode = cc.instantiate(this.ElementCommonUI.DelayLoadMask); // this.Masks.addChild(maskNode, 0, "DelayLoadMask"); // } // if (this.ElementCommonUI.LoginLoadMask) { // maskNode = cc.instantiate(this.ElementCommonUI.LoginLoadMask); // this.Masks.addChild(maskNode, 0, "LoginLoadMask"); // } // CSMask.Initialize(this.Masks); // // 所有專案共用 // new LocalStorageData(); // new ScreenResize(); // new CSAudio(); // // 同類型專案共用 // new UserStorageData(); // new UserData(); // // 同類型專案各取所需(只接DispatchCallback) // new (require("../../ElementUI/DataReceived/BadmintonData") as typeof // import("../../ElementUI/DataReceived/BadmintonData")).default(); // new (require("../../ElementUI/DataReceived/GameCheckData") as typeof // import("../../ElementUI/DataReceived/GameCheckData")).default(); // // 監聽 // UIManager.DireEvent.AddCallback(this._changeDire, this); // ScreenResize.Instance.AddEven(); // } // public CheckAddEven(): void { // this.ElementCommonUI.RemoveAllClickEffect(); // if (cc.Canvas.instance && !cc.Canvas.instance.node.hasEventListener(cc.Node.EventType.TOUCH_START)) { // cc.Canvas.instance.node.on(cc.Node.EventType.TOUCH_START, this.ElementCommonUI.ShowClickEffect, this.ElementCommonUI, true); // cc.Canvas.instance.node.on(cc.Node.EventType.TOUCH_END, this.ElementCommonUI.ShowClickEffect, this.ElementCommonUI, true); // cc.Canvas.instance.node.on(cc.Node.EventType.TOUCH_CANCEL, this.ElementCommonUI.ShowClickEffect, this.ElementCommonUI, true); // } // } // private _changeDire(param: any[] = null): void { // if (!this.node) { // return; // } // this.node.setPosition(ScreenResize.CanvasSize[ScreenResize.IsPortrait].x / 2, ScreenResize.CanvasSize[ScreenResize.IsPortrait].y / 2); // this.node.SetSizeDelta(ScreenResize.CanvasSize[ScreenResize.IsPortrait]); // //this.WebContent.node.SetSizeDelta(cc.v2(ScreenResize.CanvasSize[ScreenResize.IsPortrait].x + 0, ScreenResize.CanvasSize[ScreenResize.IsPortrait].y + 0)); // if (!CC_PREVIEW && CC_DEBUG && this.LogContent) { // this.LogContent.SetSizeDelta(ScreenResize.CanvasSize[ScreenResize.IsPortrait]); // this.LogContent.getComponentInChildren(cc.EditBox).node.setPosition(-ScreenResize.CanvasSize[ScreenResize.IsPortrait].x / 2, -ScreenResize.CanvasSize[ScreenResize.IsPortrait].y / 2); // this.LogContent.getComponentInChildren(cc.EditBox).node.SetSizeDelta(cc.v2(ScreenResize.CanvasSize[ScreenResize.IsPortrait].x - 200, ScreenResize.CanvasSize[ScreenResize.IsPortrait].y)); // this.LogContent.getChildByName("CLOSE").setPosition(ScreenResize.CanvasSize[ScreenResize.IsPortrait].x / 2 - 100, ScreenResize.CanvasSize[ScreenResize.IsPortrait].y / 2 - 100); // this.LogContent.getChildByName("CLEAR").setPosition(ScreenResize.CanvasSize[ScreenResize.IsPortrait].x / 2 - 100, ScreenResize.CanvasSize[ScreenResize.IsPortrait].y / 2 - 300); // } // this.ElementContent.scale = (ScreenResize.IsPortrait == 1) ? 1 : UIManager.ScreenScale; // Badminton.DataReceivedEvent.DispatchCallback([Badminton.DataType.ChangeDire]); // } // private _cachErrorHandler(): void { // if (!this.LogContent) { // return; // } // this.LogContent.active = false; // this.LogContent.getComponentInChildren(cc.EditBox).string = ""; // if (CC_PREVIEW || !CC_DEBUG) { // return; // } // let self = this; // if (cc.sys.isNative) { // let __handler // if (window['__errorHandler']) { // __handler = window['__errorHandler'] // } // window['__errorHandler'] = function (...args) { // self._cachError(...args); // if (__handler) { // __handler(...args) // } // } // } // if (cc.sys.isBrowser) { // let __handler; // if (window.onerror) { // __handler = window.onerror // } // window.onerror = function (...args) { // self._cachError(...args); // if (__handler) { // __handler(...args) // } // } // } // cc.error = (msg: any, ...subst: any[]) => { // console.error(msg, ...subst); // this._cachError(msg, ...subst); // } // } // private _cachError(...args): void { // this.LogContent.active = true; // if (args && args[0]) { // for (let con of args) { // Badminton.Instance.LogContent.getComponentInChildren(cc.EditBox).string += "\n" + con; // } // } // } // public CloseLogPanel(): void { // this.LogContent.active = false; // } // public ClearLogPanel(): void { // this.LogContent.getComponentInChildren(cc.EditBox).string = ""; // } // //#endregion // //#region WEBVIEW // private _setWeb(): void { // /*this.WebContent.node.active = false; // if (cc.sys.isNative) { // this.WebContent.setJavascriptInterfaceScheme(this.SCHEME); // this.WebContent.setOnJSCallback(this._webViewCallback.bind(this)); // if (cc.sys.isBrowser) { // window["closeWebContent"] = this._closeWebContent.bind(this); // window.addEventListener('message', function (e) { // cc.log("cocos log1=" + e.data); // window["closeWebContent"](e); // }); // } // } else { // window["closeWebContent"] = this._closeWebContent.bind(this); // window.addEventListener('message', function (e) { // cc.log("cocos log1=" + e.data); // window["closeWebContent"](e); // }); // }*/ // } // private _closeWebContent(e, url): void { // /*this.WebContent.node.active = false; // cc.log("cocos log2=" + e.data); // */ // } // private _webViewCallback(target, url): void { // /* // // webview target // let str: string = url.replace(this.SCHEME + '://', ''); // cc.log(str); // this.WebContent.node.active = false; // */ // } // public OpenWebPage(url: string): void { // /*this.WebContent.node.active = true; // let checkUrl: string = BusinessTypeSetting.UsePatch + "closePage.html?" + url + "&v=" + Date.now(); // this.WebContent.url = checkUrl; // */ // } // private _createIframeCloseBtn(): void { // let currentDiv = document.getElementById("ScreenRotation"); // var historyBTn = document.createElement("input"); // historyBTn.setAttribute("type", "button"); // historyBTn.setAttribute("id", "historyBtn"); // historyBTn.setAttribute("class", "closeBtn"); // historyBTn.setAttribute("onclick", "javascript:(()=>{var ifr=document.querySelector('#historyIfr');ifr.parentNode.removeChild(ifr);var ifrBtn= document.querySelector('#historyBtn');ifrBtn.style.visibility = 'hidden';document.querySelector('#ifrDiv').style.visibility='hidden';})()"); // if (!BusinessTypeSetting.CheckOnServer) { // historyBTn.setAttribute("style", "background:url(" + BusinessTypeSetting.UsePatch + BusinessTypeSetting.FolderUrlImg + "historyBtn.png);z-index:1100;top:80%;left:90%;position:fixed;overflow:unset;width:40px;height:40px;;-webkit-appearance: none;background-position: center;background-size: 100%;background-repeat: no-repeat;visibility: visible;border-width:0;background-color: rgba(0,0,0,0);outline: none;"); // } // historyBTn.textContent = "X"; // historyBTn.style.visibility = "hidden"; // document.body.insertBefore(historyBTn, currentDiv); // let ifrDiv = document.createElement("div"); // ifrDiv.setAttribute("id", "ifrDiv"); // ifrDiv.setAttribute("class", "scroll-wrapper"); // ifrDiv.setAttribute("style", "position:fixed;width:100%;height:100%;z-index: 1000;overflow-y: scroll;overflow-x: hidden;-webkit-overflow-scrolling: touch;margin:0;"); // ifrDiv.style.visibility = "hidden"; // document.body.insertBefore(ifrDiv, currentDiv); // } // public CreateIframePage(urlStr: string): void { // let historyIfr = document.createElement("iframe"); // historyIfr.setAttribute("id", "historyIfr"); // historyIfr.setAttribute("src", urlStr); // historyIfr.setAttribute("frameborder", "0"); // historyIfr.setAttribute("style", "width:100%;height:100%;z-index: 1000;;"); // let ifrDiv = document.getElementById("ifrDiv"); // ifrDiv.appendChild(historyIfr); // ifrDiv.style.visibility = "visible"; // let historyBTn = document.getElementById("historyBtn"); // historyBTn.style.visibility = "visible"; // } // //#endregion // //#region 網路相關 // /**連線(目前沒有重連機制) */ // public * ConnectAsync(host: string, port: number) { // var url = "https://api.ipify.org/?format=json"; // var xhr = new XMLHttpRequest(); // let ip: string = ""; // xhr.onreadystatechange = function () { // if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) { // ip = JSON.parse(xhr.responseText)["ip"]; // } // }; // xhr.open("GET", url, true); // xhr.send(); // cc.log("[事件]準備連線..."); // while (ip == "") { // yield null; // } // this._conn = new NetConnector(host, port, ip); // this._conn.OnDataReceived.AddCallback(this._onNetDataReceived, this); // this._conn.OnDisconnected.AddCallback(this._onNetDisconnected, this); // this._conn.OnLoadUIMask.AddCallback(this._oOnLoadUIMask, this); // NetManager.Initialize(this._conn); // cc.log("[事件]連線中..."); // // 同個connector要再次連線, 可以不用叫CasinoNetManager.Initialize(), 但要先叫CasinoNetManager.Disconnect() // yield NetManager.ConnectAsync(); // cc.log(String.Format("[事件]連線狀態: {0}", NetManager.IsConnected)); // } // private _onNetDisconnected() { // cc.log("[事件] 收到連線中斷事件"); // if (CSAudio.Instance) { // CSAudio.Instance.StopMusic(); // } // this._conn.OnDataReceived.RemoveAllCallbacks(); // Badminton.Instance.LastPlayGameID = 0; // // UIManager.DireEvent.RemoveAllCallbacks(); // cc.view.setResizeCallback(null); // Badminton.DataReceivedEvent.DispatchCallback([Badminton.DataType.NetDisconnected]); // } // private _onNetDataReceived(resp: INetResponse) { // //cc.log(`[事件] 收到server呼叫: ${resp.Method}(${JSON.stringify(resp.Data)}), 狀態: ${resp.Status}`); // Badminton.DataReceivedEvent.DispatchCallback([Badminton.DataType.ServerData, resp]); // } // private _oOnLoadUIMask(value: boolean) { // //cc.log(`[事件] LoadUIMask: ${value}`); // if (value) { // CSMask.ShowMask(CSMask.MaskType.DelayLoadMask); // } else { // CSMask.HideMask(CSMask.MaskType.DelayLoadMask); // } // } // //#endregion // //#region 硬幣特效 // @property({ displayName: "硬幣數量", type: cc.Integer }) // public CoinAmount: number = 0; // @property({ displayName: "硬幣飛行路徑", type: cc.Node }) // public CoinPathPoint: cc.Node[] = []; // @property({ displayName: "硬幣飛行時間", type: cc.Float }) // public FlyCoinTime: number = 0; // @property({ type: cc.Float }) // public CircleMin: number = 0; // @property({ type: cc.Float }) // public CircleMax: number = 0; // @property({ type: cc.Float }) // public CircleTime: number = 0; // @property({ type: cc.Float }) // public CircleDelayRange: number = 0; // @property({ type: cc.Float }) // public FadeOutTime: number = 0; // public PlayCoinEffect(data: any[]): void { // CoroutineV2.Serial( // this.FlyMoneyEffect(data[0]), // this.UpdateMoney(data[1]) // ).Start(); // } // private *UpdateMoney(money: number): IterableIterator { // UserData.Instance.Money += money; // } // public *FlyMoneyEffect(StartPos: cc.Vec2): IterableIterator { // for (let i: number = 0; i < this.CoinAmount; i++) { // let coinInfo: CoinEffectInfo = new CoinEffectInfo(); // coinInfo.StartPos = StartPos; // let normalized: cc.Vec2 = new cc.Vec2(Math.random(), Math.random()); // coinInfo.SecondPos = StartPos.add(normalized.mul(RandomEx.GetInt(this.CircleMin, this.CircleMax))); // let date: Date = new Date(); // let sec: number = date.getTime() / 1000; // coinInfo.StartTime = sec; // coinInfo.DelayTime = this.CircleDelayRange * Math.random(); // coinInfo.FadeOutTime = this.FadeOutTime; // CoroutineV2.Single(this._coinFly(coinInfo)).Start(); // } // yield CoroutineV2.WaitTime(this.FlyCoinTime).Start(); // } // private *_coinFly(coin: CoinEffectInfo): IterableIterator { // let date: Date = new Date(); // let sec: number = date.getTime() / 1000; // // 算延遲起動 // while (sec - coin.StartTime < coin.DelayTime) { // let newDate: Date = new Date(); // sec = newDate.getTime() / 1000; // yield null; // } // coin.GO = this.node.ExAddChild(this.ElementCommonUI.PrefabCoinEffect); // coin.GO.SetWorldPosition(coin.StartPos); // coin.GO.ExSetOrderOverTheObj(this.ElementCommonUI.node); // // 延遲結束更新開始時間 // coin.StartTime += coin.DelayTime; // // 正式開始飛 // while (sec - coin.StartTime <= this.FlyCoinTime) { // let newDate: Date = new Date(); // sec = newDate.getTime() / 1000; // // 正規化 // let t: number = (sec - coin.StartTime) / this.FlyCoinTime; // let newPos: cc.Vec2 = new cc.Vec2(); // if (!this.IsInGame) { // if (this.CoinPathPoint[0] != null && this.CoinPathPoint[1] != null) { // newPos = Bezier.GetPoint(coin.StartPos, coin.SecondPos, this.CoinPathPoint[0].GetWorldPosition(), this.CoinPathPoint[1].GetWorldPosition(), t); // } else { // return; // } // } else { // if (this.CoinPathPoint[2] != null && this.CoinPathPoint[3] != null) { // newPos = Bezier.GetPoint(coin.StartPos, coin.SecondPos, this.CoinPathPoint[2].GetWorldPosition(), this.CoinPathPoint[3].GetWorldPosition(), t); // } else { // return; // } // } // let dir: cc.Vec2 = newPos.sub(coin.GO.GetWorldPosition()); // let angle: number = Math.round(Math.atan2(dir.y, dir.x) * 57.29578); // coin.GO.angle = angle; // coin.GO.SetWorldPosition(newPos); // yield null; // } // coin.GO.destroy(); // } // //#endregion // //#region 切換場景 // public *RunSwichScene(sceneName: string, scene: cc.Scene = null): IterableIterator { // let source: any; // if (!scene) { // source = yield* AssetBundleMamagerV2.Instance.GetBundleSource(sceneName, sceneName, "scene"); // } else { // source = scene; // } // if (!source) { // cc.warn("cannot finc scene."); // return; // } // this.LastScene = this.NowScene; // this.NowScene = sceneName; // switch (sceneName) { // case SceneName.Lobby: // CSMask.HideMask(CSMask.MaskType.LoginLoadMask); // CSMask.ShowMask(CSMask.MaskType.LoginLoadMask); // ScreenResize.PL = 1; // ScreenResize.IsPortrait = ScreenResize.PL; // break; // case SceneName.Login: // ScreenResize.PL = 1; // ScreenResize.IsPortrait = ScreenResize.PL; // break; // default: // // 遊戲 // this.NowScene = SceneName.Game; // break; // } // cc.director.runSceneImmediate(source); // } // //#endregion // //#region DownloadForm Function // /** // * 載入外載表設定檔 // * @param formtype FormType // */ // public *DownloadForm(formtype: DownloadForm.FormType): IterableIterator { // if (DownloadForm.DownloadFormData.DownloadSuccess.has(formtype)) { // console.warn(`CSSettingsV3 ${formtype} 已經載過`); // return; // } // DownloadForm.DownloadFormData.DownloadSuccess.set(formtype, true); // let needForm: string[] = DownloadForm.DownloadFormData[`${formtype}Form`]; // let parallel: Iterator[] = []; // for (let i: number = 0; i < needForm.length; i++) { // parallel.push(this.DownloadFormSetting(needForm[i])); // } // // set Form // yield CoroutineV2.Parallel(...parallel).Start(); // } // /** // * 載入外載表設定檔 // * @param formname 設定檔名稱 // */ // public *DownloadFormSetting(formname: string): IterableIterator { // let fileUrl: string = `${formname}.json`; // fileUrl = BusinessTypeSetting.UsePatch + BusinessTypeSetting.FolderUrlJson + fileUrl; // fileUrl = fileUrl + "?v=" + Date.now(); // let isdownloading: boolean = true; // cc.assetManager.loadRemote(fileUrl, (err, res) => { // if (err == null) { // res.name = formname; // TableManager.AddJsonAsset(res); // cc.assetManager.cacheManager?.removeCache(res.nativeUrl); // } else { // console.error(`[Error] ${formname}.json載入失敗`); // } // isdownloading = false; // }); // while (isdownloading) { // yield null; // } // } // //#endregion // } // /** S2CEvent類型 */ // export enum S2CEventType { // /** SlotIn */ // SlotIn, // /** CardUse */ // CardUse // } // export class CoinEffectInfo { // public StartPos: cc.Vec2; // /** 往外噴的點位 */ // public SecondPos: cc.Vec2; // public GO: cc.Node; // public StartTime: number; // public DelayTime: number; // public FadeOutTime: number; // } // export module Badminton { // export enum DataType { // ServerData, // ChangeDire, // NetDisconnected, // } // } // export default Badminton; // export enum SceneName { // Loading = "SplashScreen", // Login = "Login", // Lobby = "Lobby", // Game = "Game_" // } // //#region DownloadForm // export module DownloadForm { // export enum FormType { // Bag = "Bag", // Bingo = "Bingo", // Five = "Five", // Operation = "Operation" // } // export class DownloadFormData { // /** 已下載的表 */ // public static DownloadSuccess: Map = new Map(); // /** Bag需要的表(xxxx.json) */ // public static BagForm: string[] = ["packet", "composite", "itemmoney"]; // public static BingoForm: string[] = ["bingo"]; // public static FiveForm: string[] = ["five"]; // public static OperationForm: string[] = ["operation"]; // } // } // //#endregion