HonorWallitem.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 { ButtonLock } from "../GameLogic/Sofa";
  8. import HTTPS, { NetGet } from "../Template/HTTPS";
  9. import HonorManger, { HonorWallDetailsType } from "./HonorManger";
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class HonorWallitem extends cc.Component {
  13. MyType: HonorWallDetailsType = null;
  14. sp: cc.Node = null;
  15. select: cc.Node = null;
  16. labelNode: cc.Node = null;
  17. isGray = false;
  18. onLoad(): void {
  19. this.sp = this.node.getChildByName("sp")
  20. this.select = this.node.getChildByName("select")
  21. this.labelNode = this.node.getChildByName("Label")
  22. }
  23. start(): void {
  24. let t = this.sp.getComponent(cc.Sprite)
  25. let t1 = this.select.getComponent(cc.Sprite)
  26. // 成功加载后的处理
  27. cc.assetManager.loadRemote(this.MyType.Picture, (err, res: cc.Texture2D) => {
  28. if (!err) {
  29. t.spriteFrame = new cc.SpriteFrame(res);
  30. if (HonorManger.getInstance().HonorMList.includes(this.MyType.Id)) {
  31. // @ts-ignore
  32. t.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null))
  33. // @ts-ignore
  34. t1.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null))
  35. this.isGray = false
  36. } else {
  37. // @ts-ignore
  38. t.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null))
  39. // @ts-ignore
  40. t1.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null))
  41. this.isGray = true
  42. }
  43. let spLabel = this.labelNode.getComponent(cc.Label)
  44. spLabel.string = this.MyType.Name
  45. if (this.MyType.IsWear == 1) {
  46. this.ClickMe()
  47. }
  48. }
  49. })
  50. }
  51. @ButtonLock(0.1, null)
  52. ClickMe() {
  53. //hide all
  54. this.node.parent.children.forEach(e => {
  55. e.getChildByName('select').active = false
  56. })
  57. //show
  58. this.select.active = true
  59. //show
  60. // 创建一个自定义事件
  61. let event = new cc.Event.EventCustom('ClickItem', true); // true 表示事件可冒泡
  62. event.setUserData({
  63. MyType: this.MyType,
  64. Gray: this.isGray,
  65. sp: this.sp.getComponent(cc.Sprite)
  66. }); // 传递自定义数据
  67. this.node.dispatchEvent(event); // 派发事件
  68. if (this.MyType.IsHold == 1) {
  69. HTTPS.Instance.get(NetGet.UserWearHonor + this.MyType.Id).then((resp) => {
  70. })
  71. }
  72. }
  73. }