HonorWall.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import { ItemName, PopName } from "../EventName/EventName";
  8. import HTTPS, { NetGet } from "../Template/HTTPS";
  9. import PopComponet from "../Template/PopComponet";
  10. import HonorManger, { HonorWallDetailsType } from "./HonorManger";
  11. import HonorWallitem from "./HonorWallitem";
  12. import PopManger from "./PopManger";
  13. import Privacy from "./Privacy";
  14. const { ccclass, property } = cc._decorator;
  15. @ccclass
  16. export default class HonorWall extends PopComponet {
  17. @property(cc.Node)
  18. Itemparent: cc.Node = null
  19. @property(cc.Label)
  20. progressLabel: cc.Label = null
  21. onLoad() {
  22. this.node.on('ClickItem', this.ClickItem, this)
  23. }
  24. onDestroy(): void {
  25. this.node.off('ClickItem', this.ClickItem, this)
  26. }
  27. ClickItem(event) {
  28. // 处理事件
  29. let data = event.getUserData(); // 获取自定义数据
  30. let Title = this.node.getChildByName("Title")
  31. let Bg = Title.getChildByName("Bg")
  32. let Sp = Title.getChildByName("Sp")
  33. let Name = Title.getChildByName("Name")
  34. let Detail = Title.getChildByName("Detail")
  35. Bg.active = true
  36. Sp.active = true
  37. Name.active = true
  38. Detail.active = true;
  39. Name.getComponent(cc.Label).string = (<HonorWallDetailsType>data.MyType).Name
  40. Detail.getComponent(cc.Label).string = (<HonorWallDetailsType>data.MyType).Description
  41. Sp.getComponent(cc.Sprite).spriteFrame = (<cc.Sprite>data.sp).spriteFrame
  42. if ((<boolean>data.Gray)) {
  43. // @ts-ignore
  44. Sp.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null))
  45. Bg.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null))
  46. } else {
  47. // @ts-ignore
  48. Sp.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null))
  49. Bg.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null))
  50. }
  51. }
  52. start() {
  53. this.init()
  54. }
  55. init() {
  56. this.initDisPlay()
  57. this.initIconItem()
  58. }
  59. initDisPlay() {
  60. let HonorDataAll = [
  61. ...HonorManger.getInstance().HonorWallDetails_Shangban,
  62. ...HonorManger.getInstance().HonorWallDetails_ChiDao,
  63. ...HonorManger.getInstance().HonorWallDetails_Qita];
  64. let d = HonorDataAll.filter(e => { return HonorManger.getInstance().SelectHonorM == e.Id })
  65. let Title = this.node.getChildByName("Title")
  66. let Bg = Title.getChildByName("Bg")
  67. let Sp = Title.getChildByName("Sp")
  68. let Name = Title.getChildByName("Name")
  69. let Detail = Title.getChildByName("Detail")
  70. //如果有值
  71. if (HonorManger.getInstance().SelectHonorM > 0) {
  72. Bg.active = true
  73. Sp.active = true
  74. Name.active = true
  75. Detail.active = true
  76. Name.getComponent(cc.Label).string = d[0].Name
  77. Detail.getComponent(cc.Label).string = d[0].Description
  78. } else {
  79. Bg.active = false
  80. Sp.active = false
  81. Name.active = false
  82. Detail.active = false
  83. }
  84. }
  85. initIconItem() {
  86. let HonorDataAll = [
  87. ...HonorManger.getInstance().HonorWallDetails_Shangban,
  88. ...HonorManger.getInstance().HonorWallDetails_ChiDao,
  89. ...HonorManger.getInstance().HonorWallDetails_Qita];
  90. this.progressLabel.string = `已获得 ${HonorManger.getInstance().HonorMList.length}/${HonorDataAll.length}`;
  91. for (let j = 0; j < HonorDataAll.length; j++) {
  92. const element = HonorDataAll[j];
  93. PopManger.getInstance().LoadAssets<cc.Prefab>(ItemName.HonorItem).then((Prefab) => {
  94. let subPrefab = cc.instantiate(Prefab)
  95. subPrefab.getComponent(HonorWallitem).MyType = element
  96. subPrefab.parent = this.Itemparent
  97. }).catch((error) => {
  98. // 加载失败的处理
  99. });
  100. }
  101. }
  102. ClickDelete() {
  103. this.node.destroy()
  104. }
  105. }