widget_boss_info.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { _decorator, Component, EditBox, Node } from 'cc';
  2. import { boss_info_data } from '../../../data/data';
  3. import { receive_widget_item } from './receive_widget_item';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('widget_boss_info')
  6. export class widget_boss_info extends Component {
  7. @property(Node) bg:Node = null;
  8. @property(Node) bg_bar:Node = null;
  9. @property(Node) bar:Node = null;
  10. @property(Node) head:Node = null;
  11. @property(Node) edit_hp:Node = null;
  12. @property(Node) edit_hp_delay_time:Node = null;
  13. private m_data:boss_info_data = null;
  14. public initView(data:boss_info_data){
  15. this.m_data = data;
  16. this.bg.getComponent(receive_widget_item).updateView(this.m_data.bg)
  17. this.bg_bar.getComponent(receive_widget_item).updateView(this.m_data.bg_bar)
  18. this.bar.getComponent(receive_widget_item).updateView(this.m_data.bar)
  19. this.head.getComponent(receive_widget_item).updateView(this.m_data.head)
  20. this.edit_hp.off(EditBox.EventType.EDITING_DID_ENDED)
  21. this.edit_hp.on(EditBox.EventType.EDITING_DID_ENDED,()=>{
  22. if(this.edit_hp.getComponent(EditBox).string.length==0) {
  23. this.edit_hp.getComponent(EditBox).string = '0'
  24. }
  25. this.m_data.hp = parseInt(this.edit_hp.getComponent(EditBox).string)
  26. })
  27. this.edit_hp.getComponent(EditBox).string = this.m_data.hp.toString()
  28. this.edit_hp_delay_time.off(EditBox.EventType.EDITING_DID_ENDED)
  29. this.edit_hp_delay_time.on(EditBox.EventType.EDITING_DID_ENDED, ()=>{
  30. if(this.edit_hp_delay_time.getComponent(EditBox).string.length==0) {
  31. this.edit_hp_delay_time.getComponent(EditBox).string = '0'
  32. }
  33. this.m_data.hp_delay_time = parseFloat(this.edit_hp_delay_time.getComponent(EditBox).string)
  34. })
  35. if(this.m_data.hp_delay_time==undefined) {
  36. this.m_data.hp_delay_time = 0
  37. }
  38. this.edit_hp_delay_time.getComponent(EditBox).string = this.m_data.hp_delay_time.toString()
  39. }
  40. }