Text_Sound.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { _decorator, Component, EventTouch, Label, Node, UITransform, Vec3 } from 'cc';
  2. import { att_text_sound_data, bag_item_data } from '../../../data/data';
  3. import { sound_item } from '../sound_item';
  4. import { config } from '../../config';
  5. import { control } from '../control';
  6. import { ClientEvent } from '../../clientEvent';
  7. import { Attributes } from '../Attributes';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('Text_Sound')
  10. export class Text_Sound extends Component {
  11. @property(sound_item) m_sound_item:sound_item = null;
  12. @property(Node) lab_text:Node = null;
  13. @property(Node) item_node:Node = null;
  14. private m_data:att_text_sound_data = null;
  15. public initView(data:att_text_sound_data){
  16. this.m_data = data;
  17. this.m_sound_item.init(false)
  18. if(this.m_data.sound_data===null){
  19. this.m_data.sound_data = new bag_item_data
  20. this.m_data.pos_y = this.item_node.position.y;
  21. }
  22. this.updateView(this.m_data)
  23. this.item_node.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
  24. let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
  25. let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
  26. this.node.position = new Vec3(0,n_p.y);
  27. this.m_data.pos_y = n_p.y
  28. Attributes.Singleton.getTextSoundCom().update_att(this.m_data)
  29. })
  30. }
  31. public updateView(data:att_text_sound_data){
  32. // console.log("Text_Sound",data)
  33. this.m_data = data;
  34. if(this.m_data.text.length<=0){
  35. }else{
  36. this.lab_text.getComponent(Label).string = this.m_data.text;
  37. }
  38. if(this.m_data.pos_y!=0){
  39. this.item_node.position = new Vec3(this.item_node.position.x,this.m_data.pos_y)
  40. }
  41. if(this.m_data.sound_data.url.length>0){
  42. this.m_sound_item.changeAudio(this.m_data.sound_data,control.mp3_cache.get(this.m_data.sound_data.name))
  43. }
  44. }
  45. }