PetIcon.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { FFAttr } from "../data/FFCalAttr";
  2. import RedPoint from "../data/RedPoint";
  3. import { PetAttr } from "../data/udata/Player";
  4. /**
  5. * 宠物头像
  6. */
  7. const {ccclass, property} = cc._decorator;
  8. @ccclass
  9. export default class PetIcon extends cc.Component {
  10. @property(cc.Sprite)
  11. mIcon: cc.Sprite = null;
  12. @property(cc.Node)
  13. mCheck: cc.Node = null;
  14. @property(cc.Node)
  15. mLeaderIcon: cc.Node = null;//队长标识
  16. public callback:(petIcon:PetIcon)=>void;
  17. public id:number;
  18. public data:PetAttr;
  19. onLoad(){
  20. this.mCheck.active = false
  21. this.mLeaderIcon.active = false
  22. }
  23. public flushIcon(ffAttr:FFAttr){
  24. let headIcon = ffAttr.skin
  25. if(headIcon == '30000'){
  26. headIcon = ''+this.data.id
  27. }
  28. cc.resources.load('icon/role_head/'+headIcon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  29. if(err){
  30. cc.error(err);
  31. }else{
  32. this.mIcon.spriteFrame = spriteFrame;
  33. }
  34. } );
  35. }
  36. public setCallback(callback:(petIcon:PetIcon)=>void){
  37. this.callback = callback;
  38. }
  39. public onclick(){
  40. if(this.mCheck.active){
  41. return;
  42. }
  43. let nodes = this.node.parent.children;
  44. for (let i = 0; i < nodes.length; i++) {
  45. const node = nodes[i];
  46. if(node == this.node){
  47. this.mCheck.active = true;
  48. }else{
  49. let tmp = node.getComponent(PetIcon);
  50. tmp.mCheck.active = false;
  51. }
  52. }
  53. if(this.callback){
  54. RedPoint.removeRed(this.node)
  55. this.callback(this);
  56. }
  57. }
  58. }