ui_boss_info.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { _decorator, Color, Component, Label, Node, ProgressBar, Tween, tween, UITransform } from 'cc';
  2. import { ui_base } from './ui_base';
  3. import { boss_info_data } from '../../../data/data';
  4. import { tools } from '../../tools';
  5. import { gameManager } from '../gameManager';
  6. import { ClientEvent } from '../../clientEvent';
  7. import { config } from '../../config';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('ui_boss_info')
  10. export class ui_boss_info extends ui_base {
  11. // @property(Node) bg:Node = null; //ui_base中属性bg重复,控制台报黄色警告,目前没有使用
  12. @property(Node) bg_bar:Node = null;
  13. @property(Node) bar:Node = null;
  14. @property(Node) head:Node = null;
  15. @property(Node) hp_ani:Node = null;
  16. private mBossData:boss_info_data = null;
  17. private bossHp:number = 0;
  18. protected init(): void {
  19. this.mBossData = this.mTopData._boss_info_data;
  20. if(this.mBossData===null){
  21. return tools.showToast("boss 配置错误!")
  22. }
  23. this.loadBg(this.mBossData.bg)
  24. gameManager.initUiBaseAtt(this.bg_bar,this.mBossData.bg_bar)
  25. gameManager.initUiBaseAtt(this.bar,this.mBossData.bar)
  26. gameManager.initUiBaseAtt(this.head,this.mBossData.head)
  27. this.bg_bar.getComponent(ProgressBar).totalLength = this.bar.getComponent(UITransform).width
  28. this.bossHp = this.mBossData.hp;
  29. this.bg_bar.getComponent(ProgressBar).progress = 1;
  30. ClientEvent.on(config.EventRun.ON_BOSS_HURT,this.hurt.bind(this),this)
  31. }
  32. protected onDisable(): void {
  33. ClientEvent.off(config.EventRun.ON_BOSS_HURT,this.hurt.bind(this),this)
  34. this.unscheduleAllCallbacks()
  35. }
  36. hurt(hurt_num:number){
  37. if(hurt_num===0){
  38. tools.showToast("道具用完失败")
  39. this.onFialEvent()
  40. return;
  41. }
  42. let hp_delay_time = 0
  43. if(this.mBossData.hp_delay_time!=undefined) {
  44. hp_delay_time = this.mBossData.hp_delay_time
  45. }
  46. this.scheduleOnce(()=>{
  47. this.bossHp -= hurt_num;
  48. Tween.stopAllByTarget(this.hp_ani)
  49. this.hp_ani.getComponent(Label).string = `${hurt_num>0?"-":"+"}${Math.abs(hurt_num)}`
  50. this.hp_ani.active = true;
  51. this.hp_ani.getComponent(Label).color = hurt_num>0?Color.RED:Color.GREEN;
  52. tween(this.hp_ani).delay(2).call(()=>{
  53. this.hp_ani.active = false;
  54. }).start()
  55. if(this.bossHp>=this.mBossData.hp) {
  56. this.bossHp = this.mBossData.hp
  57. }
  58. let progress = this.bossHp/this.mBossData.hp
  59. this.bg_bar.getComponent(ProgressBar).progress = progress;
  60. if(this.bossHp<=0){
  61. tools.showToast("成功打死boss")
  62. this.onFinishEvent()
  63. ClientEvent.off(config.EventRun.ON_BOSS_HURT,this.hurt.bind(this),this)
  64. }
  65. },hp_delay_time)
  66. }
  67. }