ui_boss_info.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { _decorator, Color, Component, Label, Node, ProgressBar, Tween, tween } 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;
  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.bossHp = this.mBossData.hp;
  28. this.bg_bar.getComponent(ProgressBar).progress = 1;
  29. ClientEvent.on(config.EventRun.ON_BOSS_HURT,this.hurt.bind(this),this)
  30. }
  31. protected onDisable(): void {
  32. ClientEvent.off(config.EventRun.ON_BOSS_HURT,this.hurt.bind(this),this)
  33. }
  34. hurt(hurt_num:number){
  35. if(hurt_num===0){
  36. tools.showToast("道具用完失败")
  37. this.onFialEvent()
  38. return;
  39. }
  40. this.bossHp -= hurt_num;
  41. Tween.stopAllByTarget(this.hp_ani)
  42. this.hp_ani.getComponent(Label).string = `${hurt_num>0?"-":"+"}${Math.abs(hurt_num)}`
  43. this.hp_ani.active = true;
  44. this.hp_ani.getComponent(Label).color = hurt_num>0?Color.RED:Color.GREEN;
  45. tween(this.hp_ani).delay(2).call(()=>{
  46. this.hp_ani.active = false;
  47. }).start()
  48. this.bg_bar.getComponent(ProgressBar).progress = this.bossHp/this.mBossData.hp;
  49. if(this.bossHp<=0){
  50. tools.showToast("成功打死boss")
  51. this.onFinishEvent()
  52. ClientEvent.off(config.EventRun.ON_BOSS_HURT,this.hurt.bind(this),this)
  53. }
  54. }
  55. }