TaskItem.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { _decorator, Vec3,Node, Sprite, Label, EventTouch, tween, easing } from 'cc';
  2. import ListItem from '../../third/ListItem';
  3. import { ResUtil } from '../../utils/ResUtil';
  4. const { ccclass, property } = _decorator;
  5. //任务数据
  6. @ccclass('TaskItem')
  7. export class TaskItem extends ListItem {
  8. @property({ type: Sprite, tooltip: "任务敌人头像" })
  9. public enemy_header: Sprite;
  10. @property({ type: Label, tooltip: "敌人数量" })
  11. public num_label: Label;
  12. @property({ type: Label, tooltip: "敌人名字" })
  13. public enemy_name_label: Label;
  14. public data: any = null;
  15. public cb?: Function = null;
  16. public start() {
  17. this.node.on(Node.EventType.TOUCH_START,this.touchStart,this);
  18. //点击 物品查看
  19. this.node.on(Node.EventType.TOUCH_END,()=>{
  20. if(!this.data)return;
  21. this.cb?.(this.data);
  22. },this);
  23. }
  24. /**
  25. * 点击
  26. */
  27. private touchStart(event: EventTouch) {
  28. if(!this.data) return;
  29. let target: Node = event.target;
  30. tween(target)
  31. .to(0.1, {scale: new Vec3(1.02,1.02,1.02)},{easing: easing.backOut})
  32. .to(0.1, {scale: new Vec3(0.98,0.98,0.98)},{easing: easing.backOut})
  33. .call(() => {
  34. target.scale = new Vec3(1,1,1);
  35. }).start();
  36. }
  37. /**
  38. * 数据填充
  39. * @param data 敌人数据
  40. * @param cb 回调
  41. */
  42. public init(data: any,cb?: Function){
  43. if(!data)return;
  44. this.data = data;
  45. this.cb = cb;
  46. //敌人头像
  47. ResUtil.setSpriteFrame(data.headshot,this.enemy_header);
  48. //敌人数量
  49. this.num_label.string = `x${data.count}`;
  50. //敌人名字
  51. this.enemy_name_label.string = data.name_lang;
  52. }
  53. }