import AccountModel from "../../../data/Account/AccountModel"; import UIBase from "../../../framework/ui/UIBase"; import UIHelp from "../../../framework/ui/UIHelp"; import gameData, { PlayerData } from "../../../gameLogic/utrl/gameData"; import { ATTACK_MODE, EVENT_TYPE } from "../../../gameLogic/utrl/gameEnum"; import gameEventManager from "../../../gameLogic/utrl/gameEventManager"; import bundleManager from "../../../manager/bundleManager"; const { ccclass, property } = cc._decorator; /**武器切换按钮UI */ @ccclass export default class UiSwitchBtnView extends UIBase { count: number = 0; onEnable() { gameEventManager.on(EVENT_TYPE.INIT_SWITCH_BTN, this.initView, this) gameEventManager.on(EVENT_TYPE.getGun_guide, this.getGunGuide, this) gameEventManager.on(EVENT_TYPE.attack_mode, this.changeFrames, this) } onDisable() { gameEventManager.off(EVENT_TYPE.INIT_SWITCH_BTN, this.initView, this) gameEventManager.off(EVENT_TYPE.attack_mode, this.changeFrames, this) gameEventManager.off(EVENT_TYPE.getGun_guide, this.getGunGuide, this) } start() { this.initSwitchState(); } initSwitchState() { this.isNewUser(); if (AccountModel.getInstance().is_new == 0 || !this.node.$guide2Lb || !this.node.$hand) { this.node.$switch_btn.active = true; } else { this.node.$switch_btn.active = false; } } isNewUser() { let playerDt = AccountModel.getInstance().playerDtList; if (playerDt.length > 0) { AccountModel.getInstance().is_new = 0; } } initView() { this.changeFrames(); this.initSwitchState(); if (this.node.$guide2Lb && this.node.$hand) { this.node.$guide2Lb.active = false;; this.node.$hand.active = false; } } changeFrames() { let is_close = gameData.cur_attack_mode == ATTACK_MODE.close; let switchBtnFrames = is_close ? 'joyStick/yuan1' : 'joyStick/jin1'; let curModeFrames = is_close ? 'joyStick/jin2' : 'joyStick/yuan2'; bundleManager.setBundleFrame('UI', switchBtnFrames, this.node.$switch_btn); bundleManager.setBundleFrame('UI', curModeFrames, this.node.$cur_modeSp); } getGunGuide() { if (this.node.$guide2Lb && this.node.$hand && this.node.$switch_btn) { this.node.$guide2Lb.active = true; this.node.$hand.active = true; this.node.$switch_btn.active = true; if (this.node.$hand) { cc.tween(this.node.$hand) .repeatForever(cc.tween().to(0.5, { angle: 0 }).to(0.5, { angle: 45 })) .start() } } } clickSwitchBtn() { if (gameData.cur_attack_mode == ATTACK_MODE.close) { if (this.isCanSwitch() == false) { return; } if(gameData.curBulletNum<=0){ UIHelp.ShowTips('Ammo depleted, switched to melee mode.');//当前子弹为0,无法切换成远程模式... return; } gameData.cur_attack_mode = ATTACK_MODE.remote; this.removeGetGunGuide(); } else { gameData.cur_attack_mode = ATTACK_MODE.close; } gameEventManager.emit(EVENT_TYPE.attack_mode); this.changeFrames(); cc.tween(this.node.$switch_btn.$switch_sp) .by(0.2, { angle: 180 }) .start(); } isCanSwitch() { let playerDt = AccountModel.getInstance().playerDtList; if (playerDt.length > 0) { for (let i = 0; i < playerDt.length; ++i) { if (playerDt[i].remote_weapon) { return true; } } } UIHelp.ShowTips('No ranged weapons...');//暂无远程武器... return false; } removeGetGunGuide() { let hand = this.node.$hand; let lb = this.node.$guide2Lb; if (hand && lb) { if (this.node.$hand.active && this.node.$guide2Lb.active) { this.node.$hand.destroy(); this.node.$guide2Lb.destroy(); } } } }