attributes_res.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { _decorator, Component, Label, Node, Rect, UITransform } from 'cc';
  2. import { tools } from '../../tools';
  3. import { bag_item_data } from '../../../data/data';
  4. import { Attributes } from '../Attributes';
  5. import { ClientEvent } from '../../clientEvent';
  6. import { config } from '../../config';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('attributes_res')
  9. export class attributes_res extends Component {
  10. @property(Node) lab_res_name:Node = null;
  11. @property(Node) btn_add_res:Node = null;
  12. @property(Node) btn_clear_res:Node = null;
  13. private _url:string = "";
  14. start(){
  15. this.btn_add_res.on(Node.EventType.TOUCH_END,()=>{
  16. tools.select_res_list((data:bag_item_data)=>{
  17. let att = Attributes.Singleton.get_cur_att_data();
  18. att.src = data.url
  19. att.src_name = data.name
  20. this.update_att(data.name);
  21. ClientEvent.dispatchEvent(config.Event.UpdateAttributesToView,att,config.attributes_list_type.url)
  22. })
  23. })
  24. if(this.btn_clear_res!=null) {
  25. this.btn_clear_res.on(Node.EventType.TOUCH_END,()=>{
  26. let att = Attributes.Singleton.get_cur_att_data();
  27. att.src = ""
  28. att.src_name = ""
  29. this.update_att("空");
  30. tools.showToast("资源已被重置为空!")
  31. ClientEvent.dispatchEvent(config.Event.UpdateAttributesToView,att,config.attributes_list_type.url)
  32. })
  33. }
  34. }
  35. public update_att(url:string){
  36. this._url = url
  37. this.lab_res_name.getComponent(Label).string = url;
  38. }
  39. public getRect(){
  40. let size = this.node.getComponent(UITransform).contentSize;
  41. let pos = this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position);
  42. let rect = new Rect(pos.x-size.width/2,pos.y-size.height/2,size.width,size.height)
  43. return rect;
  44. }
  45. public getUrl(){
  46. return this._url;
  47. }
  48. }