Collectitem.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 EventName, { PopName } from "../EventName/EventName";
  8. import { ButtonLock } from "../GameLogic/Sofa";
  9. import HTTPS, { NetGet } from "../Template/HTTPS";
  10. import MyComponent from "../Template/MyComponent";
  11. import CollectManger, { CollectDetailsType } from "./CollectManger";
  12. import PopManger from "./PopManger";
  13. const { ccclass, property } = cc._decorator;
  14. @ccclass
  15. export default class Collectitem extends MyComponent {
  16. MyType: CollectDetailsType = null;
  17. select: cc.Node = null;
  18. sp: cc.Node = null;
  19. isGray = false;
  20. onLoad(): void {
  21. this.sp = this.node.getChildByName("mask").getChildByName("sp")
  22. this.select = this.node.getChildByName("select")
  23. this.regEvent(EventName.CollectSelect, this.SetSelect, this)
  24. }
  25. start(): void {
  26. let t = this.sp.getComponent(cc.Sprite)
  27. let t1 = this.select.getComponent(cc.Sprite)
  28. // 成功加载后的处理
  29. cc.assetManager.loadRemote(this.MyType.Picture, (err, res: cc.Texture2D) => {
  30. if (!err) {
  31. t.spriteFrame = new cc.SpriteFrame(res);
  32. if (this.MyType.IsHold == 1) {
  33. // @ts-ignore
  34. t.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null))
  35. // @ts-ignore
  36. t1.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null))
  37. this.isGray = false
  38. } else {
  39. // @ts-ignore
  40. t.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null))
  41. // @ts-ignore
  42. t1.setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null))
  43. this.isGray = true
  44. }
  45. if (this.MyType.IsWear == 1) {
  46. this.node.parent.children.forEach(e => {
  47. e.getChildByName('select').active = false
  48. })
  49. this.select.active = true
  50. }
  51. }
  52. })
  53. }
  54. SetSelect(id) {
  55. if (id == this.MyType.Id) {
  56. this.node.parent.children.forEach(e => {
  57. e.getChildByName('select').active = false
  58. })
  59. this.select.active = true
  60. }
  61. }
  62. @ButtonLock(0.1, null)
  63. ClickMe() {
  64. PopManger.getInstance().Pop(PopName.DressUp, {
  65. animation: true,
  66. Data: {
  67. MyType: this.MyType,
  68. Sp: this.sp.getComponent(cc.Sprite).spriteFrame
  69. },
  70. })
  71. }
  72. }