attributes_res.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. this.btn_clear_res.on(Node.EventType.TOUCH_END,()=>{
  25. let att = Attributes.Singleton.get_cur_att_data();
  26. att.src = ""
  27. att.src_name = ""
  28. this.update_att("空");
  29. tools.showToast("资源已被重置为空!")
  30. ClientEvent.dispatchEvent(config.Event.UpdateAttributesToView,att,config.attributes_list_type.url)
  31. })
  32. }
  33. public update_att(url:string){
  34. this._url = url
  35. this.lab_res_name.getComponent(Label).string = url;
  36. }
  37. public getRect(){
  38. let size = this.node.getComponent(UITransform).contentSize;
  39. let pos = this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position);
  40. let rect = new Rect(pos.x-size.width/2,pos.y-size.height/2,size.width,size.height)
  41. return rect;
  42. }
  43. public getUrl(){
  44. return this._url;
  45. }
  46. }