59 行
1.7 KiB
TypeScript
59 行
1.7 KiB
TypeScript
import { _decorator, Component, Node, Prefab, instantiate, Label } from 'cc';
|
|
import { GameManager } from '../core/GameManager';
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/**
|
|
* EventFeedPanel 对应 GDD-22 第一层「洪荒近况」登录信息流。
|
|
* 展示离线期间与当前高优先级事件条目。
|
|
*/
|
|
@ccclass('EventFeedPanel')
|
|
export class EventFeedPanel extends Component {
|
|
@property({ type: Prefab })
|
|
public feedItemPrefab: Prefab | null = null;
|
|
|
|
@property({ type: Node })
|
|
public contentNode: Node | null = null;
|
|
|
|
private _items: Node[] = [];
|
|
|
|
onLoad() {
|
|
this.refresh();
|
|
}
|
|
|
|
/**
|
|
* 拉取并渲染信息流
|
|
*/
|
|
public async refresh(): Promise<void> {
|
|
// TODO: 调用服务端离线消息补偿接口或本地缓存
|
|
const maxEntries = GameManager.getInstance().configManager?.get<number>('event.login_feed.max_entries', 8) ?? 8;
|
|
this.clear();
|
|
for (let i = 0; i < maxEntries; i++) {
|
|
this.addItem(`信息流条目 ${i + 1}`);
|
|
}
|
|
}
|
|
|
|
public addItem(text: string, onClick?: () => void): void {
|
|
if (!this.feedItemPrefab || !this.contentNode) {
|
|
return;
|
|
}
|
|
const node = instantiate(this.feedItemPrefab);
|
|
const label = node.getComponentInChildren(Label);
|
|
if (label) {
|
|
label.string = text;
|
|
}
|
|
if (onClick) {
|
|
node.on(Node.EventType.TOUCH_END, onClick, this);
|
|
}
|
|
this.contentNode.addChild(node);
|
|
this._items.push(node);
|
|
}
|
|
|
|
public clear(): void {
|
|
for (const node of this._items) {
|
|
node.destroy();
|
|
}
|
|
this._items = [];
|
|
}
|
|
}
|