更新优化震动

This commit is contained in:
COMPUTER\EDY 2026-08-03 15:53:17 +08:00
parent 91cb887c25
commit 3f0f871687
4 changed files with 116 additions and 19 deletions

View File

@ -19,6 +19,20 @@ const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class JiaZai extends cc.Component { export default class JiaZai extends cc.Component {
/** 仅处理真实按钮事件;振动失败不能阻断按钮原有逻辑。 */
private vibrateButtonClick(event?: cc.Event) {
if (!event) {
return;
}
try {
cc.fx.GameTool.setVibrate("light", 1);
} catch (error) {
try {
console.warn("按钮轻振动调用失败:", error);
} catch (e) { }
}
}
// 缓存 shop 预制体 // 缓存 shop 预制体
private static cachedShopPrefab: cc.Prefab | null = null; private static cachedShopPrefab: cc.Prefab | null = null;
// 缓存 shop 节点 // 缓存 shop 节点
@ -1087,7 +1101,8 @@ export default class JiaZai extends cc.Component {
// 何时调用:玩家点击头像按钮时调用 // 何时调用:玩家点击头像按钮时调用
// 主要功能:实例化并显示头像预制体 // 主要功能:实例化并显示头像预制体
// ============================================ // ============================================
openAvatar() { openAvatar(event?: cc.Event) {
this.vibrateButtonClick(event);
let top = this.node.getChildByName("Load").getChildByName("Top"); let top = this.node.getChildByName("Load").getChildByName("Top");
top.getChildByName("gachaGuang").stopAllActions(); top.getChildByName("gachaGuang").stopAllActions();
top.getChildByName("gachaGuang").active = false; top.getChildByName("gachaGuang").active = false;
@ -1210,6 +1225,7 @@ export default class JiaZai extends cc.Component {
// 3. 处理不同的按钮来源(干扰按钮等) // 3. 处理不同的按钮来源(干扰按钮等)
// ============================================ // ============================================
openHeath(event?: cc.Event, customEventData?: string) { // EventTouch EventCustom openHeath(event?: cc.Event, customEventData?: string) { // EventTouch EventCustom
this.vibrateButtonClick(event);
let eventName = ""; let eventName = "";
let btnName = "" let btnName = ""
if (customEventData !== undefined) { if (customEventData !== undefined) {
@ -1554,7 +1570,8 @@ export default class JiaZai extends cc.Component {
// 2. 首次到达时显示特殊提示 // 2. 首次到达时显示特殊提示
// 3. 处理特殊情况弹窗 // 3. 处理特殊情况弹窗
// ============================================ // ============================================
enterGame() { enterGame(event?: cc.Event) {
this.vibrateButtonClick(event);
let recordInfinity = cc.fx.StorageMessage.getStorage("EndLevelPop"); let recordInfinity = cc.fx.StorageMessage.getStorage("EndLevelPop");
// console.log("已经最大关卡 弹窗提示", recordInfinity, cc.fx.GameTool.maxLevel()) // console.log("已经最大关卡 弹窗提示", recordInfinity, cc.fx.GameTool.maxLevel())
if (cc.fx.GameTool.maxLevel()) { if (cc.fx.GameTool.maxLevel()) {
@ -1574,7 +1591,8 @@ export default class JiaZai extends cc.Component {
} }
// 关闭最大关卡弹窗 // 关闭最大关卡弹窗
specialTipsClose() { specialTipsClose(event?: cc.Event) {
this.vibrateButtonClick(event);
this.node.getChildByName("Load").getChildByName("specialTips").active = false; this.node.getChildByName("Load").getChildByName("specialTips").active = false;
} }
@ -1590,7 +1608,8 @@ export default class JiaZai extends cc.Component {
// 5. 体力足够则加载并切换场景 // 5. 体力足够则加载并切换场景
// 6. 体力不足则弹出体力不足提示 // 6. 体力不足则弹出体力不足提示
// ============================================ // ============================================
startGame() { startGame(event?: cc.Event) {
this.vibrateButtonClick(event);
if (cc.fx.GameConfig.GM_INFO.otherLevel == 0) { if (cc.fx.GameConfig.GM_INFO.otherLevel == 0) {
cc.fx.GameConfig.GM_INFO.allOutTradeNo = []; cc.fx.GameConfig.GM_INFO.allOutTradeNo = [];
} }
@ -1746,6 +1765,7 @@ export default class JiaZai extends cc.Component {
// 3. 播放按钮音效 // 3. 播放按钮音效
// ============================================ // ============================================
openShop(event?: cc.Event, customEventData?: string) { openShop(event?: cc.Event, customEventData?: string) {
this.vibrateButtonClick(event);
if (!cc.fx.GameConfig.GM_INFO.canIos) { if (!cc.fx.GameConfig.GM_INFO.canIos) {
return; return;
} }
@ -1954,6 +1974,7 @@ export default class JiaZai extends cc.Component {
// - share是否来自分享回调 // - share是否来自分享回调
// ============================================ // ============================================
openDailyQuests(event?: cc.Event, customEventData?: string, share?: boolean) { openDailyQuests(event?: cc.Event, customEventData?: string, share?: boolean) {
this.vibrateButtonClick(event);
let eventName = ""; let eventName = "";
let btnName = "" let btnName = ""
@ -2052,7 +2073,8 @@ export default class JiaZai extends cc.Component {
// 功能:隐藏排名界面 // 功能:隐藏排名界面
// 何时调用:点击关闭按钮时调用 // 何时调用:点击关闭按钮时调用
// ============================================ // ============================================
closeRank() { closeRank(event?: cc.Event) {
this.vibrateButtonClick(event);
this.node.getChildByName("Rank").active = false; this.node.getChildByName("Rank").active = false;
} }
// ============================================ // ============================================
@ -2060,7 +2082,8 @@ export default class JiaZai extends cc.Component {
// 功能:显示排名界面 // 功能:显示排名界面
// 何时调用:点击排名按钮时调用 // 何时调用:点击排名按钮时调用
// ============================================ // ============================================
openRank() { openRank(event?: cc.Event) {
this.vibrateButtonClick(event);
this.node.getChildByName("Rank").active = true; this.node.getChildByName("Rank").active = true;
} }
// ============================================ // ============================================
@ -2087,7 +2110,8 @@ export default class JiaZai extends cc.Component {
// 2. 显示暂停节点 // 2. 显示暂停节点
// 3. 显示玩家OpenID // 3. 显示玩家OpenID
// ============================================ // ============================================
openPause() { openPause(event?: cc.Event) {
this.vibrateButtonClick(event);
cc.fx.AudioManager._instance.playEffect("anniu_little", null); cc.fx.AudioManager._instance.playEffect("anniu_little", null);
//console.log(cc.fx.GameConfig.GM_INFO); //console.log(cc.fx.GameConfig.GM_INFO);
if (cc.fx.GameConfig.GM_INFO.openid == undefined) { if (cc.fx.GameConfig.GM_INFO.openid == undefined) {
@ -2102,7 +2126,8 @@ export default class JiaZai extends cc.Component {
// 功能:隐藏暂停菜单界面 // 功能:隐藏暂停菜单界面
// 何时调用:点击继续按钮时调用 // 何时调用:点击继续按钮时调用
// ============================================ // ============================================
closePause() { closePause(event?: cc.Event) {
this.vibrateButtonClick(event);
cc.fx.AudioManager._instance.playEffect("anniu_little", null); cc.fx.AudioManager._instance.playEffect("anniu_little", null);
this.node.getChildByName("Pause").active = false; this.node.getChildByName("Pause").active = false;
} }
@ -2116,7 +2141,8 @@ export default class JiaZai extends cc.Component {
// 2. 显示设置节点 // 2. 显示设置节点
// 3. 播放设置动画 // 3. 播放设置动画
// ============================================ // ============================================
openSet() { openSet(event?: cc.Event) {
this.vibrateButtonClick(event);
const now = Date.now(); const now = Date.now();
if (now - this.lastPauseClickTime < 300) { if (now - this.lastPauseClickTime < 300) {
// 0.3秒内禁止再次点击 // 0.3秒内禁止再次点击
@ -2141,7 +2167,8 @@ export default class JiaZai extends cc.Component {
// 功能:隐藏奖励界面 // 功能:隐藏奖励界面
// 何时调用:点击关闭按钮时调用 // 何时调用:点击关闭按钮时调用
// ============================================ // ============================================
closeReward() { closeReward(event?: cc.Event) {
this.vibrateButtonClick(event);
this.node.getChildByName("Reward").active = false; this.node.getChildByName("Reward").active = false;
} }
@ -2151,7 +2178,8 @@ export default class JiaZai extends cc.Component {
// 功能:显示体力购买界面 // 功能:显示体力购买界面
// 何时调用:点击体力按钮时调用 // 何时调用:点击体力按钮时调用
// ============================================ // ============================================
openStamina() { openStamina(event?: cc.Event) {
this.vibrateButtonClick(event);
this.node.getChildByName("Stamina").active = true; this.node.getChildByName("Stamina").active = true;
} }
// ============================================ // ============================================
@ -2159,7 +2187,8 @@ export default class JiaZai extends cc.Component {
// 功能:隐藏体力购买界面 // 功能:隐藏体力购买界面
// 何时调用:点击关闭按钮时调用 // 何时调用:点击关闭按钮时调用
// ============================================ // ============================================
closeStamina() { closeStamina(event?: cc.Event) {
this.vibrateButtonClick(event);
this.node.getChildByName("Stamina").active = false; this.node.getChildByName("Stamina").active = false;
} }
// ============================================ // ============================================
@ -2416,7 +2445,8 @@ export default class JiaZai extends cc.Component {
// 功能:显示月卡购买界面 // 功能:显示月卡购买界面
// 何时调用:点击月卡按钮时调用 // 何时调用:点击月卡按钮时调用
// ============================================ // ============================================
openMonthCard() { openMonthCard(event?: cc.Event) {
this.vibrateButtonClick(event);
this.openMonthlyCard(); this.openMonthlyCard();
// this.monthCard.active = true; // this.monthCard.active = true;
// Utils.getMonthlyCard((data) => { // Utils.getMonthlyCard((data) => {
@ -2441,6 +2471,7 @@ export default class JiaZai extends cc.Component {
// ============================================ // ============================================
// 打开通行证弹窗 // 打开通行证弹窗
openStarter_pack(event?: cc.Event, customEventData?: string) { openStarter_pack(event?: cc.Event, customEventData?: string) {
this.vibrateButtonClick(event);
if (!JiaZai.cachedActionPrefab) { if (!JiaZai.cachedActionPrefab) {
let eventName = ""; let eventName = "";
@ -2922,7 +2953,8 @@ export default class JiaZai extends cc.Component {
} }
} }
// 关闭月卡奖励弹窗 // 关闭月卡奖励弹窗
onCardReward() { onCardReward(event?: cc.Event) {
this.vibrateButtonClick(event);
this.getcard.active = false; this.getcard.active = false;
} }
// ============================================ // ============================================
@ -3157,6 +3189,7 @@ export default class JiaZai extends cc.Component {
// 何时调用:点击连胜活动按钮时调用 // 何时调用:点击连胜活动按钮时调用
// ============================================ // ============================================
openWinStreak(event?: cc.Event, customEventData?: string) { openWinStreak(event?: cc.Event, customEventData?: string) {
this.vibrateButtonClick(event);
let eventName = ""; let eventName = "";
let btnName = "" let btnName = ""
if (customEventData !== undefined) { if (customEventData !== undefined) {
@ -3312,6 +3345,7 @@ export default class JiaZai extends cc.Component {
// 预制体检测:确保预制体已加载 // 预制体检测:确保预制体已加载
// ============================================ // ============================================
openPassCheck(event?: cc.Event, customEventData?: string) { openPassCheck(event?: cc.Event, customEventData?: string) {
this.vibrateButtonClick(event);
if (!JiaZai.cachedPassCheckPrefab) { if (!JiaZai.cachedPassCheckPrefab) {
console.error('PassCheck prefab is not loaded yet.') console.error('PassCheck prefab is not loaded yet.')
return; return;
@ -4255,7 +4289,8 @@ export default class JiaZai extends cc.Component {
// 功能:显示排行榜中的省份位置信息 // 功能:显示排行榜中的省份位置信息
// 何时调用:点击位置按钮时调用 // 何时调用:点击位置按钮时调用
// ============================================ // ============================================
openPosition() { openPosition(event?: cc.Event) {
this.vibrateButtonClick(event);
if (this.RankNode) { if (this.RankNode) {
if (this.RankNode.getChildByName("ScrollView")) { if (this.RankNode.getChildByName("ScrollView")) {
let scrollVIew = this.RankNode.getChildByName("ScrollView"); let scrollVIew = this.RankNode.getChildByName("ScrollView");
@ -4385,7 +4420,8 @@ export default class JiaZai extends cc.Component {
// 功能:滚动列表回到顶部位置 // 功能:滚动列表回到顶部位置
// 何时调用:点击回到顶部按钮时调用 // 何时调用:点击回到顶部按钮时调用
// ============================================ // ============================================
backTop() { backTop(event?: cc.Event) {
this.vibrateButtonClick(event);
// console.log("给用户移动到列表顶部"); // console.log("给用户移动到列表顶部");
let top = this.node.getChildByName("Load").getChildByName("Top"); let top = this.node.getChildByName("Load").getChildByName("Top");
top.getChildByName("posBtn").active = true; top.getChildByName("posBtn").active = true;
@ -4409,7 +4445,8 @@ export default class JiaZai extends cc.Component {
// 功能:显示兑换码输入界面 // 功能:显示兑换码输入界面
// 何时调用:点击兑换码按钮时调用 // 何时调用:点击兑换码按钮时调用
// ============================================ // ============================================
openRedeemCode() { openRedeemCode(event?: cc.Event) {
this.vibrateButtonClick(event);
let reddemCodeNode = cc.instantiate(this.reddemCodeNode); let reddemCodeNode = cc.instantiate(this.reddemCodeNode);
if (this.node && reddemCodeNode) if (this.node && reddemCodeNode)
this.node.addChild(reddemCodeNode); this.node.addChild(reddemCodeNode);
@ -4491,6 +4528,7 @@ export default class JiaZai extends cc.Component {
openGacha(event?: cc.Event, customEventData?: string, data?: any, film?: any, catArr?: any) { openGacha(event?: cc.Event, customEventData?: string, data?: any, film?: any, catArr?: any) {
this.vibrateButtonClick(event);
// console.log("打开Gacha界面", data); // console.log("打开Gacha界面", data);
let top = this.node.getChildByName("Load").getChildByName("Top"); let top = this.node.getChildByName("Load").getChildByName("Top");
top.getChildByName("gachaGuang").stopAllActions(); top.getChildByName("gachaGuang").stopAllActions();

View File

@ -2581,7 +2581,51 @@ var GameTool = {
console.log('ios当前环境不支持支付') console.log('ios当前环境不支持支付')
} }
} }
} },
setVibrate(type, count) {
// return;
// console.log("最新:",cc.fx.GameConfig.GM_INFO.vibrateOpen,type);
if (!cc.fx.GameConfig.GM_INFO.vibrateOpen) {
return;
}
if (count == 1) {
//@ts-ignore
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) { // 判断是否在微信环境
//@ts-ignore
wx.vibrateShort({
type: type,
success: () => {
// console.log("震动成功1111111111")
},
fail: (err) => {
// console.log("震动失败1111111111",err);
}
});
} else {
}
return;
}
let time = 150;
for (let i = 0; i < 4; i++) {
setTimeout(() => {
//@ts-ignore
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) { // 判断是否在微信环境
//@ts-ignore
wx.vibrateShort({
type: type,
success: () => {
// console.log("震动成功222222222")
},
fail: (err) => {
// console.log("震动失败222222222", err);
}
});
} else {
}
}, time * i);
}
}
}; };
export { GameTool }; export { GameTool };

View File

@ -6,6 +6,20 @@ const { ccclass, property } = cc._decorator;
//排行榜 //排行榜
@ccclass @ccclass
export default class CareerManager2 extends cc.Component { export default class CareerManager2 extends cc.Component {
/** rankGame 按钮轻振动;振动异常不能阻断排行榜点击逻辑。 */
private vibrateButtonClick(event?: cc.Event) {
if (!event) {
return;
}
try {
cc.fx.GameTool.setVibrate("light", 1);
} catch (error) {
try {
console.warn("rankGame 按钮轻振动调用失败:", error);
} catch (e) { }
}
}
@property(cc.Sprite) //用户头像换图 @property(cc.Sprite) //用户头像换图
phone: cc.Sprite = null; phone: cc.Sprite = null;
@ -146,6 +160,7 @@ export default class CareerManager2 extends cc.Component {
// } // }
public openInformation(event: cc.Event, customEventData?: string) { public openInformation(event: cc.Event, customEventData?: string) {
this.vibrateButtonClick(event);
console.log("点击个人信息", event); console.log("点击个人信息", event);
const clickedItem = this.getInformationTarget(event && event.target as cc.Node); const clickedItem = this.getInformationTarget(event && event.target as cc.Node);
const rankData = this.getInformationRankData(clickedItem); const rankData = this.getInformationRankData(clickedItem);

View File

@ -1,5 +1,5 @@
{ {
"last-module-event-record-time": 1784883102370, "last-module-event-record-time": 1785741936000,
"group-list": [ "group-list": [
"default", "default",
"Map" "Map"