import { _decorator, Component, Node, Button, Label } from 'cc'; import { GameManager } from '../core/GameManager'; const { ccclass, property } = _decorator; /** * EncounterBubble 对应 GDD-22 第二层「云游际遇」实时遭遇气泡。 * 在线期间弹出,提供二选一/三选一决策。 */ @ccclass('EncounterBubble') export class EncounterBubble extends Component { @property({ type: Label }) public titleLabel: Label | null = null; @property({ type: Label }) public descLabel: Label | null = null; @property({ type: Node }) public optionsRoot: Node | null = null; private _encounterId: string = ''; onLoad() { this.hide(); } public show(encounter: { id: string; title: string; description: string; options: { id: string; text: string }[] }): void { this._encounterId = encounter.id; if (this.titleLabel) { this.titleLabel.string = encounter.title; } if (this.descLabel) { this.descLabel.string = encounter.description; } this._buildOptions(encounter.options); this.node.active = true; } public hide(): void { this.node.active = false; } private _buildOptions(options: { id: string; text: string }[]): void { if (!this.optionsRoot) { return; } this.optionsRoot.removeAllChildren(); for (const opt of options) { const btnNode = new Node('OptionButton'); const btn = btnNode.addComponent(Button); const label = btnNode.addComponent(Label); label.string = opt.text; btnNode.on(Button.EventType.CLICK, () => this.onSelectOption(opt.id), this); this.optionsRoot.addChild(btnNode); } } public onSelectOption(optionId: string): void { // TODO: 上报选择结果到服务端,触发战斗/副本/事件 console.log(`Encounter ${this._encounterId} select option ${optionId}`); this.hide(); } }