feat(ui): 为所有按钮添加全局点击音效
1. 重构按钮点击音效添加方式,通过重写Button原型的_onTouchEnded方法实现全局注入 2. 移除各业务组件中手动添加的按钮音效播放代码,统一音效播放逻辑
This commit is contained in:
@@ -89,6 +89,7 @@ export class HeroViewComp extends CCComp {
|
|||||||
private onHeroClicked() {
|
private onHeroClicked() {
|
||||||
if (!this.model) return;
|
if (!this.model) return;
|
||||||
if (this.model.fac !== FacSet.HERO) return;
|
if (this.model.fac !== FacSet.HERO) return;
|
||||||
|
oops.audio.playEffect("music/button");
|
||||||
|
|
||||||
const eid = this.ent?.eid;
|
const eid = this.ent?.eid;
|
||||||
if (!eid) return;
|
if (!eid) return;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* @LastEditors: dgflash
|
* @LastEditors: dgflash
|
||||||
* @LastEditTime: 2022-08-17 12:38:59
|
* @LastEditTime: 2022-08-17 12:38:59
|
||||||
*/
|
*/
|
||||||
import { Node } from "cc";
|
import { Node, Button } from "cc";
|
||||||
import { UICallbacks } from "../../../../extensions/oops-plugin-framework/assets/core/gui/layer/Defines";
|
import { UICallbacks } from "../../../../extensions/oops-plugin-framework/assets/core/gui/layer/Defines";
|
||||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||||
import { AsyncQueue, NextFunction } from "../../../../extensions/oops-plugin-framework/assets/libs/collection/AsyncQueue";
|
import { AsyncQueue, NextFunction } from "../../../../extensions/oops-plugin-framework/assets/libs/collection/AsyncQueue";
|
||||||
@@ -27,6 +27,19 @@ export class Initialize extends ecs.Entity {
|
|||||||
debugMode: boolean = false; // 是否启用调试模式
|
debugMode: boolean = false; // 是否启用调试模式
|
||||||
protected init() {
|
protected init() {
|
||||||
var queue: AsyncQueue = new AsyncQueue();
|
var queue: AsyncQueue = new AsyncQueue();
|
||||||
|
|
||||||
|
// --- 全局注入:为所有 Button 组件增加点击音效 ---
|
||||||
|
const originalOnTouchEnded = Button.prototype["_onTouchEnded"];
|
||||||
|
if (originalOnTouchEnded) {
|
||||||
|
Button.prototype["_onTouchEnded"] = function(event) {
|
||||||
|
if (this.interactable && this.node && this.node.activeInHierarchy) {
|
||||||
|
oops.audio.playEffect("music/button");
|
||||||
|
}
|
||||||
|
originalOnTouchEnded.call(this, event);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// ---------------------------------------------
|
||||||
|
|
||||||
// 加载自定义资
|
// 加载自定义资
|
||||||
this.loadCustom(queue);
|
this.loadCustom(queue);
|
||||||
// 加载多语言包
|
// 加载多语言包
|
||||||
|
|||||||
@@ -643,6 +643,7 @@ export class MissionCardComp extends CCComp {
|
|||||||
}
|
}
|
||||||
/** 抽卡按钮释放 → 执行抽卡逻辑 */
|
/** 抽卡按钮释放 → 执行抽卡逻辑 */
|
||||||
private onDrawTouchEnd() {
|
private onDrawTouchEnd() {
|
||||||
|
oops.audio.playEffect("music/button");
|
||||||
this.playButtonClickAnim(this.cards_chou, () => this.onClickDraw());
|
this.playButtonClickAnim(this.cards_chou, () => this.onClickDraw());
|
||||||
}
|
}
|
||||||
/** 抽卡按钮取消 → 恢复缩放 */
|
/** 抽卡按钮取消 → 恢复缩放 */
|
||||||
@@ -655,6 +656,7 @@ export class MissionCardComp extends CCComp {
|
|||||||
this.playButtonPressAnim(this.skill_refresh);
|
this.playButtonPressAnim(this.skill_refresh);
|
||||||
}
|
}
|
||||||
private onSkillDrawTouchEnd() {
|
private onSkillDrawTouchEnd() {
|
||||||
|
oops.audio.playEffect("music/button");
|
||||||
this.playButtonClickAnim(this.skill_refresh, () => this.onClickSkillRefresh());
|
this.playButtonClickAnim(this.skill_refresh, () => this.onClickSkillRefresh());
|
||||||
}
|
}
|
||||||
private onSkillDrawTouchCancel() {
|
private onSkillDrawTouchCancel() {
|
||||||
@@ -665,6 +667,7 @@ export class MissionCardComp extends CCComp {
|
|||||||
this.playButtonPressAnim(this.skill_ad_refresh);
|
this.playButtonPressAnim(this.skill_ad_refresh);
|
||||||
}
|
}
|
||||||
private onSkillAdDrawTouchEnd() {
|
private onSkillAdDrawTouchEnd() {
|
||||||
|
oops.audio.playEffect("music/button");
|
||||||
this.playButtonClickAnim(this.skill_ad_refresh, () => this.onClickSkillAdRefresh());
|
this.playButtonClickAnim(this.skill_ad_refresh, () => this.onClickSkillAdRefresh());
|
||||||
}
|
}
|
||||||
private onSkillAdDrawTouchCancel() {
|
private onSkillAdDrawTouchCancel() {
|
||||||
|
|||||||
@@ -640,6 +640,8 @@ export class MissionComp extends CCComp {
|
|||||||
if (!smc.mission.play) return;
|
if (!smc.mission.play) return;
|
||||||
if (smc.mission.pause) return;
|
if (smc.mission.pause) return;
|
||||||
if (this.currentPhase !== MissionPhase.Prepare) return;
|
if (this.currentPhase !== MissionPhase.Prepare) return;
|
||||||
|
|
||||||
|
oops.audio.playEffect("music/button");
|
||||||
this.to_fight();
|
this.to_fight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ export class SkillBoxComp extends CCComp {
|
|||||||
|
|
||||||
private onNodeClicked() {
|
private onNodeClicked() {
|
||||||
if (!this.initialized) return;
|
if (!this.initialized) return;
|
||||||
|
oops.audio.playEffect("music/button");
|
||||||
// 点击时弹出 HInfoComp,传入卡牌 UUID 和等级以启用预览模式
|
// 点击时弹出 HInfoComp,传入卡牌 UUID 和等级以启用预览模式
|
||||||
const config = CardPoolList.find(c => c.uuid === this.s_uuid || c.skill === this.s_uuid);
|
const config = CardPoolList.find(c => c.uuid === this.s_uuid || c.skill === this.s_uuid);
|
||||||
const cardUuid = config ? config.uuid : this.s_uuid;
|
const cardUuid = config ? config.uuid : this.s_uuid;
|
||||||
|
|||||||
Reference in New Issue
Block a user