|
@@ -1,8 +1,9 @@
|
|
-import { _decorator, Component, Node, Button, Animation, Sprite, SpriteFrame, resources, assetManager, Label, Layout, instantiate, tween, Vec3, UIOpacity } from 'cc';
|
|
|
|
|
|
+import { _decorator, Component, Node, Button, Animation, Sprite, SpriteFrame, resources, Label, Layout, instantiate, tween, Vec3, UIOpacity } from 'cc';
|
|
|
|
+import { TodayListItem } from './DataManager';
|
|
const { ccclass, property } = _decorator;
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 名单管理器,控制名单UI的显示和隐藏,并管理学生头像显示
|
|
|
|
|
|
+ * 名单管理器,控制今日名单UI的显示和隐藏,显示今日允许进入的人员名单
|
|
*/
|
|
*/
|
|
@ccclass('RosterManager')
|
|
@ccclass('RosterManager')
|
|
export class RosterManager extends Component {
|
|
export class RosterManager extends Component {
|
|
@@ -18,23 +19,12 @@ export class RosterManager extends Component {
|
|
})
|
|
})
|
|
closeButton: Button = null;
|
|
closeButton: Button = null;
|
|
|
|
|
|
- @property({
|
|
|
|
- type: Animation,
|
|
|
|
- tooltip: '名单动画组件(可选)'
|
|
|
|
- })
|
|
|
|
- rosterAnimation: Animation = null;
|
|
|
|
-
|
|
|
|
@property({
|
|
@property({
|
|
type: Node,
|
|
type: Node,
|
|
- tooltip: '学生头像容器'
|
|
|
|
|
|
+ tooltip: '人员头像容器'
|
|
})
|
|
})
|
|
avatarContainer: Node = null;
|
|
avatarContainer: Node = null;
|
|
|
|
|
|
- @property({
|
|
|
|
- tooltip: '头像资源路径'
|
|
|
|
- })
|
|
|
|
- avatarResourcePath: string = "avatars/";
|
|
|
|
-
|
|
|
|
@property({
|
|
@property({
|
|
tooltip: '动画时间(秒)',
|
|
tooltip: '动画时间(秒)',
|
|
range: [0.1, 2.0, 0.1]
|
|
range: [0.1, 2.0, 0.1]
|
|
@@ -47,9 +37,6 @@ export class RosterManager extends Component {
|
|
})
|
|
})
|
|
useCustomAnimation: boolean = true;
|
|
useCustomAnimation: boolean = true;
|
|
|
|
|
|
- // 保存头像引用的字典
|
|
|
|
- private avatarMap: Map<string, SpriteFrame> = new Map();
|
|
|
|
-
|
|
|
|
// 用于动画控制的组件
|
|
// 用于动画控制的组件
|
|
private rosterOpacity: UIOpacity = null;
|
|
private rosterOpacity: UIOpacity = null;
|
|
|
|
|
|
@@ -60,6 +47,9 @@ export class RosterManager extends Component {
|
|
})
|
|
})
|
|
avatarItemPrefab: Node = null;
|
|
avatarItemPrefab: Node = null;
|
|
|
|
|
|
|
|
+ // 当前显示的名单数据
|
|
|
|
+ private currentRosterItems: TodayListItem[] = [];
|
|
|
|
+
|
|
start() {
|
|
start() {
|
|
// 初始化隐藏名单面板
|
|
// 初始化隐藏名单面板
|
|
if (this.rosterPanel) {
|
|
if (this.rosterPanel) {
|
|
@@ -110,9 +100,6 @@ export class RosterManager extends Component {
|
|
if (this.useCustomAnimation) {
|
|
if (this.useCustomAnimation) {
|
|
// 使用自定义的口袋动画效果
|
|
// 使用自定义的口袋动画效果
|
|
this.playPocketOutAnimation();
|
|
this.playPocketOutAnimation();
|
|
- } else if (this.rosterAnimation) {
|
|
|
|
- // 使用预设的动画组件
|
|
|
|
- this.rosterAnimation.play('roster_open');
|
|
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
console.error('名单面板未设置');
|
|
console.error('名单面板未设置');
|
|
@@ -174,13 +161,6 @@ export class RosterManager extends Component {
|
|
this.rosterPanel.active = false;
|
|
this.rosterPanel.active = false;
|
|
console.log('名单面板已隐藏(动画后)');
|
|
console.log('名单面板已隐藏(动画后)');
|
|
});
|
|
});
|
|
- } else if (this.rosterAnimation) {
|
|
|
|
- // 使用预设的动画组件
|
|
|
|
- this.rosterAnimation.play('roster_close');
|
|
|
|
- this.scheduleOnce(() => {
|
|
|
|
- this.rosterPanel.active = false;
|
|
|
|
- console.log('名单面板已隐藏(动画后)');
|
|
|
|
- }, 0.5); // 假设动画时长为0.5秒
|
|
|
|
} else {
|
|
} else {
|
|
this.rosterPanel.active = false;
|
|
this.rosterPanel.active = false;
|
|
console.log('名单面板已隐藏(立即)');
|
|
console.log('名单面板已隐藏(立即)');
|
|
@@ -224,84 +204,50 @@ export class RosterManager extends Component {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 预加载头像资源
|
|
|
|
- * @param avatarIds 头像ID数组
|
|
|
|
|
|
+ * 设置并显示今日名单
|
|
|
|
+ * @param todayListItems 由GameFlowManager提供的今日名单数据
|
|
*/
|
|
*/
|
|
- public preloadAvatars(avatarIds: string[]) {
|
|
|
|
- if (!this.avatarContainer) {
|
|
|
|
|
|
+ public setTodayList(todayListItems: TodayListItem[]): void {
|
|
|
|
+ console.log("设置今日名单数据");
|
|
|
|
+
|
|
|
|
+ if (!todayListItems || todayListItems.length === 0) {
|
|
|
|
+ console.warn('今日名单数据为空');
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- avatarIds.forEach(id => {
|
|
|
|
- const path = `${this.avatarResourcePath}avatar_${id}/spriteFrame`;
|
|
|
|
- resources.load(path, SpriteFrame, (err, spriteFrame) => {
|
|
|
|
- if (err) {
|
|
|
|
- console.error(`加载头像 ${id} 失败:`, err);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.avatarMap.set(id, spriteFrame);
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
|
|
+ // 保存当前名单数据
|
|
|
|
+ this.currentRosterItems = todayListItems;
|
|
|
|
+
|
|
|
|
+ // 显示名单数据
|
|
|
|
+ this.displayCurrentRoster();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 显示头像
|
|
|
|
- * @param slotId 头像位置ID
|
|
|
|
- * @param avatarId 头像资源ID
|
|
|
|
|
|
+ * 显示当前保存的名单数据
|
|
*/
|
|
*/
|
|
- public showAvatar(slotId: string, avatarId: string) {
|
|
|
|
- if (!this.avatarContainer) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 查找对应的头像槽位
|
|
|
|
- const avatarSlot = this.avatarContainer.getChildByName(slotId);
|
|
|
|
- if (!avatarSlot) {
|
|
|
|
- console.error(`未找到头像槽位: ${slotId}`);
|
|
|
|
|
|
+ private displayCurrentRoster(): void {
|
|
|
|
+ if (!this.currentRosterItems || this.currentRosterItems.length === 0) {
|
|
|
|
+ console.warn('当前没有名单数据可显示');
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- // 获取已加载的头像
|
|
|
|
- const spriteFrame = this.avatarMap.get(avatarId);
|
|
|
|
- if (spriteFrame) {
|
|
|
|
- const sprite = avatarSlot.getComponent(Sprite);
|
|
|
|
- if (sprite) {
|
|
|
|
- sprite.spriteFrame = spriteFrame;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- // 如果头像未预加载,则即时加载
|
|
|
|
- const path = `${this.avatarResourcePath}avatar_${avatarId}/spriteFrame`;
|
|
|
|
- resources.load(path, SpriteFrame, (err, spriteFrame) => {
|
|
|
|
- if (err) {
|
|
|
|
- console.error(`加载头像 ${avatarId} 失败:`, err);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const sprite = avatarSlot.getComponent(Sprite);
|
|
|
|
- if (sprite) {
|
|
|
|
- sprite.spriteFrame = spriteFrame;
|
|
|
|
- // 保存引用以便下次使用
|
|
|
|
- this.avatarMap.set(avatarId, spriteFrame);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
|
|
+ this.displayListItems(this.currentRosterItems);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- // 在RosterManager中添加处理关卡人员头像的方法
|
|
|
|
- public displayLevelPersonnel(personnelData: any[]) {
|
|
|
|
- console.log("开始显示人员列表...");
|
|
|
|
- console.log("avatarContainer:", this.avatarContainer);
|
|
|
|
- console.log("personnelData:", personnelData);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 显示名单项目列表
|
|
|
|
+ * @param listItems 名单项目列表,必须包含name和avatarPath属性
|
|
|
|
+ */
|
|
|
|
+ private displayListItems(listItems: TodayListItem[]): void {
|
|
|
|
+ console.log("开始显示名单项目列表...");
|
|
|
|
|
|
if (!this.avatarContainer) {
|
|
if (!this.avatarContainer) {
|
|
- console.error('无法显示人员列表:avatarContainer未设置');
|
|
|
|
|
|
+ console.error('无法显示名单:avatarContainer未设置');
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!personnelData || personnelData.length === 0) {
|
|
|
|
- console.error('无法显示人员列表:人员数据为空');
|
|
|
|
|
|
+ if (!listItems || listItems.length === 0) {
|
|
|
|
+ console.error('无法显示名单:名单数据为空');
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -311,27 +257,36 @@ export class RosterManager extends Component {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- console.log("准备清空容器并创建新头像项");
|
|
|
|
|
|
+ console.log(`准备显示${listItems.length}个名单项目`);
|
|
|
|
+
|
|
// 清空现有内容
|
|
// 清空现有内容
|
|
this.avatarContainer.removeAllChildren();
|
|
this.avatarContainer.removeAllChildren();
|
|
|
|
|
|
// 遍历所有人员数据,创建头像项
|
|
// 遍历所有人员数据,创建头像项
|
|
- personnelData.forEach((person, index) => {
|
|
|
|
|
|
+ listItems.forEach(item => {
|
|
// 创建新的头像项
|
|
// 创建新的头像项
|
|
const avatarItem = instantiate(this.avatarItemPrefab);
|
|
const avatarItem = instantiate(this.avatarItemPrefab);
|
|
this.avatarContainer.addChild(avatarItem);
|
|
this.avatarContainer.addChild(avatarItem);
|
|
|
|
|
|
// 设置姓名
|
|
// 设置姓名
|
|
const nameLabel = avatarItem.getComponentInChildren(Label);
|
|
const nameLabel = avatarItem.getComponentInChildren(Label);
|
|
- if (nameLabel && person.name) {
|
|
|
|
- nameLabel.string = person.name;
|
|
|
|
|
|
+ if (nameLabel && item.name) {
|
|
|
|
+ nameLabel.string = item.name;
|
|
}
|
|
}
|
|
|
|
|
|
- // 使用完整的头像路径 - 直接从数据中获取
|
|
|
|
- if (person.avatarPath) {
|
|
|
|
- resources.load(person.avatarPath, SpriteFrame, (err, spriteFrame) => {
|
|
|
|
|
|
+ // 加载头像
|
|
|
|
+ if (item.avatarPath) {
|
|
|
|
+ // 移除可能存在的.png后缀
|
|
|
|
+ const pathWithoutExtension = item.avatarPath.replace(/\.png$/, '');
|
|
|
|
+
|
|
|
|
+ // 确保路径以/spriteFrame结尾
|
|
|
|
+ const path = pathWithoutExtension.endsWith('/spriteFrame')
|
|
|
|
+ ? pathWithoutExtension
|
|
|
|
+ : `${pathWithoutExtension}/spriteFrame`;
|
|
|
|
+
|
|
|
|
+ resources.load(path, SpriteFrame, (err, spriteFrame) => {
|
|
if (err) {
|
|
if (err) {
|
|
- console.error(`加载头像失败: ${person.avatarPath}`, err);
|
|
|
|
|
|
+ console.error(`加载头像失败: ${path}`, err);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -358,8 +313,5 @@ export class RosterManager extends Component {
|
|
if (this.closeButton) {
|
|
if (this.closeButton) {
|
|
this.closeButton.node.off('click');
|
|
this.closeButton.node.off('click');
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 清理资源
|
|
|
|
- this.avatarMap.clear();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|