select_res_list_item.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { _decorator, assetManager, Color, Component, ImageAsset, Label, Node, Sprite, SpriteFrame, Texture2D } from 'cc';
  2. import { bag_item_data } from '../data/data';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('select_res_list_item')
  5. export class select_res_list_item extends Component {
  6. @property(Node) lab_name:Node = null;
  7. @property(Node) icon:Node = null;
  8. private m_data:bag_item_data = null;
  9. private m_call_back = null;
  10. public initView(data:bag_item_data,call_back,isImg:boolean = true){
  11. this.m_data = data;
  12. this.m_call_back = call_back;
  13. this.lab_name.getComponent(Label).string = data.name;
  14. this.node.on(Node.EventType.TOUCH_END,()=>{
  15. if(this.m_call_back!=null){
  16. this.m_call_back(this)
  17. }
  18. })
  19. if(isImg){
  20. assetManager.loadRemote<ImageAsset>(this.m_data.url, (err, imageAsset2)=>{
  21. if (!err && imageAsset2) {
  22. const texture = new Texture2D();
  23. texture.image = imageAsset2;
  24. let spFrame2 = new SpriteFrame();
  25. spFrame2.texture = texture;
  26. this.icon.getComponent(Sprite).spriteFrame = spFrame2;
  27. }
  28. });
  29. }
  30. }
  31. public selectStatus(){
  32. this.node.getComponent(Sprite).color = Color.GREEN
  33. }
  34. public unSelectStatus(){
  35. this.node.getComponent(Sprite).color = Color.WHITE
  36. }
  37. public getData(){
  38. return this.m_data;
  39. }
  40. }