feat(VictoryUI): 新增确认按钮与绑定点击事件

1. 在胜利结算预制体中添加确认按钮节点引用
2. 新增按钮点击事件绑定通用方法
3. 为下一节和确认按钮绑定对应点击回调
This commit is contained in:
panFD
2026-09-10 22:49:54 +08:00
parent 29e56847f9
commit 6f76a67024
2 changed files with 30 additions and 3 deletions

View File

@@ -4648,7 +4648,12 @@
"__uuid__": "781262ca-120d-4286-8885-c2ecd7ce7a2a", "__uuid__": "781262ca-120d-4286-8885-c2ecd7ce7a2a",
"__expectedType__": "cc.Prefab" "__expectedType__": "cc.Prefab"
}, },
"next_section_btn": null, "next_section_btn": {
"__id__": 37
},
"confirm_btn": {
"__id__": 25
},
"settle_title": null, "settle_title": null,
"_id": "" "_id": ""
}, },

View File

@@ -5,7 +5,7 @@
* 通过 oops.gui.open(UIID.Victory, args) 打开。 * 通过 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 { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
@@ -126,6 +126,10 @@ export class VictoryComp extends CCComp {
@property({ type: Node, tooltip: "下一节按钮(小节胜利时显示)" }) @property({ type: Node, tooltip: "下一节按钮(小节胜利时显示)" })
next_section_btn: Node = null!; next_section_btn: Node = null!;
/** 确认按钮(末关通关/失败时显示,点击确认退出结算) */
@property({ type: Node, tooltip: "确认按钮(末关通关/失败时显示,点击确认退出结算)" })
confirm_btn: Node = null!;
/** 通关标题(末关通关时显示"本关通关/本章通关") */ /** 通关标题(末关通关时显示"本关通关/本章通关") */
@property({ type: Label, tooltip: "通关标题 Label(末关通关时显示,默认隐藏)" }) @property({ type: Label, tooltip: "通关标题 Label(末关通关时显示,默认隐藏)" })
settle_title: Label = null!; settle_title: Label = null!;
@@ -175,9 +179,27 @@ export class VictoryComp extends CCComp {
*/ */
private settleType: string = "defeat"; private settleType: string = "defeat";
/** 加载时隐藏 loading 遮罩 */ /** 加载时隐藏 loading 遮罩并绑定按钮事件 */
protected onLoad(): void { protected onLoad(): void {
this.node.getChildByName("loading").active = false 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);
} }
/** /**