HeroListCard.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { _decorator, Label, Node, Sprite, SpriteFrame } from 'cc';
  2. import { ResKeeper } from '../../../framework/res/ResKeeper';
  3. import { StringUtil } from '../../../framework/util/StringUtil';
  4. import { Framework } from '../../../framework/Framework';
  5. import { ViewID } from '../../../framework/config/LayerConf';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('HeroListCard')
  8. export class HeroListCard extends ResKeeper {
  9. @property({ type: Sprite, tooltip: "英雄图标" })
  10. heroIco: Sprite = null;
  11. @property({ type: Label, tooltip: "英雄名字" })
  12. heroName: Label = null;
  13. @property({ type: Node, tooltip: "星级节点" })
  14. starNode: Node = null;
  15. @property({ type: [Node], tooltip: "星图" })
  16. stars: Node[] = [];
  17. @property({ type: Node, tooltip: "星级背景" })
  18. starBg: Node = null;
  19. @property({ type: Label, tooltip: "星字" })
  20. starTx: Label = null;
  21. private data = {};
  22. protected onLoad() {
  23. }
  24. protected onDestroy() {
  25. //如果该组件有事件自行取消注释
  26. //Framework.event.removeEvent(this);
  27. super.onDestroy();
  28. }
  29. //如果使用了池中的节点,在该函数内归还,该函数会在onDestroy前调用
  30. onClose() {
  31. }
  32. //UI事件处理
  33. private onTouchButton(event: Event) {
  34. //Framework.audio.playEffect(AudioID.Click);
  35. let target: any = event.target;
  36. }
  37. refreshItem(data) {
  38. this.data = data;
  39. this.load('common', `texture/icon/hero/head_${data.conf.Id}/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
  40. this.heroIco.spriteFrame = res;
  41. })
  42. this.heroName.string = StringUtil.getLanguageData('英雄_' + data.conf.Id);;
  43. if (data.id) {
  44. this.node.getComponent(Sprite).grayscale = false;
  45. this.heroIco.grayscale = false;
  46. this.starNode.active = true;
  47. for (const index in this.stars) {
  48. if (Object.prototype.hasOwnProperty.call(this.stars, index)) {
  49. const star = this.stars[index];
  50. star.active = false;
  51. }
  52. }
  53. this.starBg.active = true;
  54. this.starTx.string = '0';
  55. } else {
  56. this.node.getComponent(Sprite).grayscale = true;
  57. this.heroIco.grayscale = true;
  58. this.starNode.active = false;
  59. this.starBg.active = false;
  60. }
  61. }
  62. //打开英雄详情界面
  63. openHeroAttr() {
  64. if (!this.data['id']) {
  65. Framework.tips.setTips(StringUtil.getLanguageData('英雄未激活!'));
  66. return;
  67. }
  68. Framework.layer.open(ViewID.HeroAttr,null,{heroDate:this.data});
  69. }
  70. }