[fix] Lobby 初始化清空 Child
This commit is contained in:
@@ -1,12 +1,148 @@
|
||||
import { Badminton } from "../Badminton/Badminton";
|
||||
import { AvatarColor, AvatarData, MemberData } from "../Badminton/MemberData";
|
||||
import UIPanel from "../Engine/Component/UIPanel/UIPanel";
|
||||
import { RandomEx } from "../Engine/Utils/Number/RandomEx";
|
||||
|
||||
const { ccclass, property } = cc._decorator;
|
||||
|
||||
/** AvatarPanel */
|
||||
@ccclass
|
||||
export default class AvatarPanel extends UIPanel {
|
||||
//#region property
|
||||
|
||||
//#region OnClick
|
||||
@property({ type: cc.Prefab })
|
||||
public BtnItem: cc.Prefab = null;
|
||||
|
||||
@property({ type: cc.Node })
|
||||
public ItemContent: cc.Node = null;
|
||||
|
||||
@property({ type: cc.Node })
|
||||
public InfoView: cc.Node = null;
|
||||
|
||||
@property({ type: cc.Sprite })
|
||||
public BG: cc.Sprite = null;
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region public
|
||||
|
||||
public Main: Badminton = null;
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region private
|
||||
|
||||
private _m_currentMember: MemberData = null;
|
||||
|
||||
private _avatars: AvatarData[] = null;
|
||||
|
||||
private _m_currentIndex: number = null;
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region Lifecycle
|
||||
|
||||
protected ImplementInitial(...initData: any[]): void {
|
||||
let self: this = this;
|
||||
this.Main = initData[0];
|
||||
this._avatars = this.Main.config.Avatars;
|
||||
let btnItem: cc.Node = cc.instantiate(this.BtnItem);
|
||||
btnItem.active = false;
|
||||
// 載入兔兔設定 更新UI
|
||||
let container: cc.Node = this.ItemContent;
|
||||
for (let i: number = container.childrenCount - 1; i >= 0; i--) {
|
||||
let obj: cc.Node = container.children[i];
|
||||
if (obj !== btnItem) {
|
||||
obj.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (let i: number = 0; i < this._avatars.length; i++) {
|
||||
let data: AvatarData = this._avatars[i];
|
||||
if (data.color !== AvatarColor.Pink && data.color !== AvatarColor.None) {
|
||||
continue;
|
||||
}
|
||||
let item: cc.Node = container.ExAddChild(btnItem);
|
||||
item.Find("Avatar/Pic").getComponent(cc.Sprite).spriteFrame = data.Pic;
|
||||
item.Find("Avatar/BG").getComponent(cc.Sprite).spriteFrame = data.BG;
|
||||
item.Find("Avatar").on("click", () => { self._showAvatarInfoById(i); });
|
||||
item.active = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected *ImplementReadyShow(...param: any[]): IterableIterator<any> {
|
||||
this._m_currentMember = param[0];
|
||||
}
|
||||
|
||||
protected *ImplementShow(): IterableIterator<any> {
|
||||
if (this._m_currentMember != null) {
|
||||
let index: number = 0;
|
||||
for (let i: number = 0; i < this._avatars.length; i++) {
|
||||
if (this._m_currentMember.AvatarId === this._avatars[i].ID) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this._showAvatarInfoById(index);
|
||||
}
|
||||
this.Main.Lobby.Close();
|
||||
}
|
||||
|
||||
protected *ImplementHide(...param: any[]): IterableIterator<any> {
|
||||
yield* this.Main.Lobby.Show();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region Custom
|
||||
|
||||
private _getNextColorAvatarIndex(index: number): number {
|
||||
if (index < 0 || index >= this._avatars.length) {
|
||||
return 0;
|
||||
}
|
||||
let cur: AvatarData = this._avatars[index];
|
||||
for (let i: number = 0; i < this._avatars.length; i++) {
|
||||
let data: AvatarData = this._avatars[i];
|
||||
if (data.Model === cur.Model && data.color !== cur.color) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private _showAvatarInfoById(index: number): void {
|
||||
if (index < 0 || index >= this._avatars.length) {
|
||||
return;
|
||||
}
|
||||
let data: AvatarData = this._avatars[index];
|
||||
this.BG.spriteFrame = data.BG;
|
||||
this.InfoView.Find("Image").getComponent(cc.Sprite).spriteFrame = data.BigPic != null ? data.BigPic : data.Pic;
|
||||
this.InfoView.Find("Title/Text").getComponent(cc.Label).string = data.Name;
|
||||
this.InfoView.Find("Text").getComponent(cc.Label).string = data.Desc;
|
||||
this._m_currentIndex = index;
|
||||
}
|
||||
|
||||
public OnClickNextColor(): void {
|
||||
this._showAvatarInfoById(this._getNextColorAvatarIndex(this._m_currentIndex));
|
||||
}
|
||||
|
||||
public OnClickConfirm(): void {
|
||||
let data: AvatarData = this._avatars[this._m_currentIndex];
|
||||
if (data.Model <= 0) {
|
||||
// let list = this._avatars.FindAll(a => a.model > 0);
|
||||
// let list: any[] = this._avatars.map(a => {
|
||||
// if (a.Model > 0) {
|
||||
// return Object.values(a)[0];
|
||||
// }
|
||||
// }).filter(item => item);
|
||||
let list: AvatarData[] = this._avatars.filter(item => item.Model > 0);
|
||||
data = list[RandomEx.GetInt(0, list.length)];
|
||||
}
|
||||
this._m_currentMember.AvatarId = data.ID;
|
||||
this.Main.ReloadUI();
|
||||
this.Close();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
@@ -131,6 +131,7 @@ export class Badminton extends cc.Component {
|
||||
CoroutineV2.Single(self.HistoryPanel.Hide()).Start();
|
||||
}
|
||||
// textToSpeech = FindObjectOfType<TextToSpeech>();
|
||||
self.AvatarPanel.Initial(self);
|
||||
CoroutineV2.Single(self.Show()).Start();
|
||||
};
|
||||
CoroutineV2.Single(AsyncFunction()).Start();
|
||||
@@ -158,17 +159,19 @@ export class Badminton extends cc.Component {
|
||||
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();
|
||||
}
|
||||
// for (let i: number = parent.childrenCount - 1; i > 0; i--) {
|
||||
// parent.children[i].destroy();
|
||||
// }
|
||||
parent.removeAllChildren();
|
||||
this._m_teamList.Clear();
|
||||
|
||||
|
||||
parent = this.ToggleItemContent;
|
||||
for (let i: number = parent.childrenCount - 1; i > 0; i--) {
|
||||
parent.children[i].destroy();
|
||||
}
|
||||
// for (let i: number = parent.childrenCount - 1; i > 0; i--) {
|
||||
// parent.children[i].destroy();
|
||||
// }
|
||||
parent.removeAllChildren();
|
||||
this._m_toggleList.Clear();
|
||||
|
||||
for (let idx: number = 0; idx < this.TeamMemberList.length; idx++) {
|
||||
@@ -180,7 +183,7 @@ export class Badminton extends cc.Component {
|
||||
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.parent.getComponent(HoldButton).OnInvoke.AddListener(() => { this.OnChangeAvatar(idx); });
|
||||
picObj.parent.getComponent(HoldButton).OnInvoke.AddListener(() => { this.OnChangeAvatar(+idx); });
|
||||
picObj.parent.on("click", () => {
|
||||
item.isChecked = !item.isChecked;
|
||||
self._onChangeSelMember(item);
|
||||
@@ -347,9 +350,7 @@ export class Badminton extends cc.Component {
|
||||
}
|
||||
|
||||
public OnChangeAvatar(index: number): void {
|
||||
index = +index;
|
||||
console.log("OnChangeAvatar");
|
||||
// this.AvatarPanel.OpenChange(teamMemberList[index]);
|
||||
CoroutineV2.Single(this.AvatarPanel.Show(this.TeamMemberList[index])).Start();
|
||||
}
|
||||
|
||||
public LoadStatus(): void {
|
||||
|
||||
@@ -8,22 +8,18 @@ import { AvatarData, MemberData } from "./MemberData";
|
||||
/** ConfigManager */
|
||||
export default class ConfigManager {
|
||||
|
||||
//#region get
|
||||
//#region public
|
||||
|
||||
public Main: Badminton = null;
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region public
|
||||
|
||||
public Avatars: AvatarData[] = [];
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region Lifecycle
|
||||
|
||||
constructor(mainControl: Badminton) {
|
||||
this.Main = mainControl;
|
||||
constructor(main: Badminton) {
|
||||
this.Main = main;
|
||||
}
|
||||
|
||||
public *Init(): IterableIterator<any> {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
const { ccclass, property } = cc._decorator;
|
||||
|
||||
//#region Enum
|
||||
@@ -25,8 +26,9 @@ export class MemberData {
|
||||
/**
|
||||
* @param {string} name 名稱
|
||||
*/
|
||||
constructor(name: string) {
|
||||
constructor(name: string, avatarId: number = 0) {
|
||||
this.Name = name;
|
||||
this.AvatarId = avatarId;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,10 +91,12 @@ 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>"Callback" && eventHandler.component === "Callback" && eventHandler.handler) {
|
||||
(<Function><unknown>eventHandler.handler)();
|
||||
} else {
|
||||
eventHandler.emit([this.node.getComponent(cc.Button)]);
|
||||
if (eventHandler) {
|
||||
if (eventHandler.target === <any>"Callback" && eventHandler.component === "Callback" && eventHandler.handler) {
|
||||
(<Function><unknown>eventHandler.handler)();
|
||||
} else {
|
||||
eventHandler.emit([this.node.getComponent(cc.Button)]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,6 +39,13 @@ declare namespace cc {
|
||||
/**位置維持在原位 */
|
||||
ExSetParent(parentObj: cc.Node): void;
|
||||
ExSetGray(showGray: boolean): void;
|
||||
/**
|
||||
* 通过名称获取节点的子节点。
|
||||
* @param name A name to find the child node.
|
||||
* @example
|
||||
* let child: cc.Node = this.node.Find("childname/childname");
|
||||
*/
|
||||
Find(name: string): cc.Node;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +191,27 @@ cc.Node.prototype.ExSetGray || Object.defineProperty(cc.Node.prototype, 'ExSetGr
|
||||
// }
|
||||
},
|
||||
});
|
||||
cc.Node.prototype.Find || Object.defineProperty(cc.Node.prototype, "Find", {
|
||||
enumerable: false,
|
||||
/**
|
||||
* 通过名称获取节点的子节点。
|
||||
* @param name A name to find the child node.
|
||||
*/
|
||||
value: function (name: string): any {
|
||||
let names: string[] = name.split("/");
|
||||
let node: cc.Node = this;
|
||||
for (let i: number = 0; i < names.length; i++) {
|
||||
const targetname: string = names[i];
|
||||
let nodeName: string = node.name;
|
||||
node = node.getChildByName(targetname);
|
||||
if (!node) {
|
||||
cc.error(`${nodeName} child hst not found ${targetname} in node`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
});
|
||||
// cc.Node.prototype.SetWorldPosition = function (cocosWorldPos: cc.Vec2): void {
|
||||
// // let cocosWorldPos = new cc.Vec2(unityWorldPos.x + 711, unityWorldPos.y + 400);
|
||||
// this.setPosition(this.parent.convertToNodeSpaceAR(cocosWorldPos));
|
||||
|
||||
@@ -6,7 +6,11 @@ const { ccclass, property } = cc._decorator;
|
||||
@ccclass
|
||||
export default class Lobby extends UIPanel {
|
||||
|
||||
//#region OnClick
|
||||
//#region Lifecycle
|
||||
|
||||
protected *ImplementReadyShow(...param: any[]): IterableIterator<any> {
|
||||
cc.log("Lobby ImplementReadyShow");
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user