From 6f76a670243beaafaa54aef70fb2b9d89c7ddb0d Mon Sep 17 00:00:00 2001 From: panFD Date: Thu, 10 Sep 2026 22:49:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(VictoryUI):=20=E6=96=B0=E5=A2=9E=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4=E6=8C=89=E9=92=AE=E4=B8=8E=E7=BB=91=E5=AE=9A=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 在胜利结算预制体中添加确认按钮节点引用 2. 新增按钮点击事件绑定通用方法 3. 为下一节和确认按钮绑定对应点击回调 --- assets/resources/gui/element/victory.prefab | 7 +++++- assets/script/game/map/VictoryComp.ts | 26 +++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/assets/resources/gui/element/victory.prefab b/assets/resources/gui/element/victory.prefab index 054a4601..6c6d6d50 100644 --- a/assets/resources/gui/element/victory.prefab +++ b/assets/resources/gui/element/victory.prefab @@ -4648,7 +4648,12 @@ "__uuid__": "781262ca-120d-4286-8885-c2ecd7ce7a2a", "__expectedType__": "cc.Prefab" }, - "next_section_btn": null, + "next_section_btn": { + "__id__": 37 + }, + "confirm_btn": { + "__id__": 25 + }, "settle_title": null, "_id": "" }, diff --git a/assets/script/game/map/VictoryComp.ts b/assets/script/game/map/VictoryComp.ts index f2af57d5..7614f071 100644 --- a/assets/script/game/map/VictoryComp.ts +++ b/assets/script/game/map/VictoryComp.ts @@ -5,7 +5,7 @@ * 通过 oops.gui.open(UIID.Victory, args) 打开。 * 展示段位徽章、总分滚动动画、段位进度与亮点成就,并提供重开 / 退出操作。 */ -import { _decorator, instantiate, Label, Prefab, Node, Sprite, ProgressBar, Tween, tween, v3, UIOpacity } from "cc"; +import { _decorator, instantiate, Label, Prefab, Node, Sprite, ProgressBar, Tween, tween, v3, UIOpacity, Button } from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; @@ -126,6 +126,10 @@ export class VictoryComp extends CCComp { @property({ type: Node, tooltip: "下一节按钮(小节胜利时显示)" }) next_section_btn: Node = null!; + /** 确认按钮(末关通关/失败时显示,点击确认退出结算) */ + @property({ type: Node, tooltip: "确认按钮(末关通关/失败时显示,点击确认退出结算)" }) + confirm_btn: Node = null!; + /** 通关标题(末关通关时显示"本关通关/本章通关") */ @property({ type: Label, tooltip: "通关标题 Label(末关通关时显示,默认隐藏)" }) settle_title: Label = null!; @@ -175,9 +179,27 @@ export class VictoryComp extends CCComp { */ private settleType: string = "defeat"; - /** 加载时隐藏 loading 遮罩 */ + /** 加载时隐藏 loading 遮罩并绑定按钮事件 */ protected onLoad(): void { this.node.getChildByName("loading").active = false + + // 代码绑定按钮点击事件,替代编辑器 Click Events 配置 + this.bindButtonClick(this.next_section_btn, this.on_next_section); + this.bindButtonClick(this.confirm_btn, this.victory_end); + } + + /** + * 为按钮节点绑定点击事件(无则自动添加 Button 组件) + * @param node 按钮节点 + * @param handler 点击回调 + */ + private bindButtonClick(node: Node, handler: () => void) { + if (!node || !node.isValid) return; + let btn = node.getComponent(Button); + if (!btn) { + btn = node.addComponent(Button); + } + node.on(Button.EventType.CLICK, handler, this); } /**