RewardItem.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { _decorator, Component, Node } from "cc";
  2. import BaseUI from "../../scripts/base/BaseUI";
  3. import UIUtils from "../../scripts/base/UIUtils";
  4. import { Vec3 } from "cc";
  5. import { GoodInfo } from "../../scripts/api/UserM";
  6. import { GoodsId } from "../../scripts/api/GoodsId";
  7. import ConfigM from "../../scripts/api/ConfigM";
  8. import { isValid } from "cc";
  9. const { ccclass, property } = _decorator;
  10. export interface OnItemClick {
  11. (item: GoodInfo): void;
  12. }
  13. @ccclass("RewardItem")
  14. export class RewardItem extends BaseUI {
  15. private onItemClick: OnItemClick = null;
  16. private item: GoodInfo = null;
  17. public getItem(): GoodInfo {
  18. return this.item;
  19. }
  20. init(delay: number, item: GoodInfo, onItemClick: OnItemClick = null) {
  21. let self = this;
  22. self.onItemClick = onItemClick;
  23. self.item = item;
  24. this.setText("lbl_count", "x" + item.count);
  25. let parent = this.FindNode("icon_layout");
  26. parent.children.forEach((child) => {
  27. child.active = false;
  28. });
  29. switch (item.id) {
  30. case GoodsId.POG:
  31. case GoodsId.POG_10:
  32. parent.getChildByName("icon_pog").active = true;
  33. // itemName = "POG";
  34. break;
  35. case GoodsId.GEM:
  36. case GoodsId.DIAMOND_10:
  37. parent.getChildByName("icon_gem").active = true;
  38. break;
  39. case GoodsId.GAME_PASS_SHARD:
  40. parent.getChildByName("icon_puzzle").active = true;
  41. break;
  42. case GoodsId.GAME_PASS:
  43. parent.getChildByName("game_pass").active = true;
  44. break;
  45. case GoodsId.POG_CRITICAL_CARD:
  46. parent.getChildByName("icon_crit").active = true;
  47. break;
  48. case GoodsId.FREE_ITEM_BOX:
  49. case GoodsId.ITEM_BOX:
  50. parent.getChildByName("icon_item_box").active = true;
  51. break;
  52. case GoodsId.FREE_POG_BOX:
  53. case GoodsId.POG_BOX:
  54. parent.getChildByName("icon_pog_box").active = true;
  55. break;
  56. case GoodsId.AIR:
  57. parent.getChildByName("icon_nothing").active = true;
  58. this.FindNode("lbl_count").active = false;
  59. break;
  60. case GoodsId.TOG:
  61. parent.getChildByName("icon_tog").active = true;
  62. break;
  63. case GoodsId.ES_TOG:
  64. parent.getChildByName("icon_estog").active = true;
  65. break;
  66. case GoodsId.FAMILY_BOX:
  67. parent.getChildByName("icon_family_box").active = true;
  68. break;
  69. }
  70. let configItemName = ConfigM.ins.getGoodName(item.id);
  71. this.setText("lbl_name", configItemName);
  72. if (delay <= 0) {
  73. self.node.active = true;
  74. } else {
  75. this.anim(delay, item);
  76. }
  77. }
  78. anim(delay: number, item: GoodInfo) {
  79. let time = delay;
  80. let self = this;
  81. self.node.setPosition(0, -700, 0);
  82. self.node.scale = new Vec3(0.5, 0.5, 0.5);
  83. setTimeout(() => {
  84. if (isValid(self.node)) {
  85. self.node.active = true;
  86. UIUtils.AnimBezierMoveAndScale(this.node, new Vec3(0, 0, 0), 1, 0.5);
  87. }
  88. }, time);
  89. }
  90. protected simpleOnBtnClick(name: string): void {
  91. if (this.onItemClick) {
  92. this.onItemClick(this.item);
  93. }
  94. }
  95. }