PropNode.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { Animation, Button, SpriteFrame, Tween, tween, Vec3, _decorator } from 'cc';
  2. import { NodeEx } from '../../framework/pool/NodeEx';
  3. import { StringUtil } from '../../framework/util/StringUtil';
  4. import { GameConf } from '../data/GameConf';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('PropNode')
  7. export class PropNode extends NodeEx {
  8. private callBack: Function = null
  9. private itemData: any = null
  10. private propType = null
  11. private originData: any = null
  12. /**
  13. * 初始化道具
  14. * @param propInfo
  15. * @param type 1-载具
  16. */
  17. init(propInfo: any) {
  18. this.originData = propInfo
  19. //普通道具
  20. this.initIconItemRes(1)
  21. }
  22. /**
  23. * 初始化道具sprite
  24. * @param iconId
  25. * @param type 根据类型 判读路径 1 载具 如果空则为通用道具 2 包裹图片
  26. */
  27. private initIconItemRes(iconId: number, quality?: number) {
  28. let path = `texture/common/equip/${iconId}/SpriteFrame`
  29. this.load("package", path, SpriteFrame, (res: SpriteFrame) => {
  30. this.Sprite.item.spriteFrame = res
  31. })
  32. }
  33. public setCallBack(cb: Function) {
  34. this.callBack = cb
  35. }
  36. public setCount(count: number) {
  37. this.Label.count.node.active = true
  38. if (count > 1) {
  39. this.Label.count.string = `${count}`
  40. } else {
  41. this.Label.count.node.active = false
  42. }
  43. }
  44. // 设置品级
  45. public showQuality(isShow: boolean, path?: string) {
  46. this.Sprite.quality.node.active = isShow
  47. if (isShow) {
  48. this.load("package", path, SpriteFrame, (sp: SpriteFrame) => {
  49. this.Sprite.quality.spriteFrame = sp
  50. })
  51. }
  52. }
  53. public showSelect(isShow: boolean, path?: string) {
  54. this.Sprite.select.node.active = isShow
  55. if (isShow) {
  56. this.load("package", path, SpriteFrame, (sp: SpriteFrame) => {
  57. this.Sprite.select.spriteFrame = sp
  58. })
  59. }
  60. }
  61. public getCountLable() {
  62. return this.Label.count
  63. }
  64. // 点击
  65. public onClickBtn(resulut?: boolean) {
  66. }
  67. public setSwallowTouches(isTouch: boolean) {
  68. this.Sprite.item.getComponent(Button).enabled = isTouch
  69. }
  70. //如果使用了池中的节点,在该函数内归还,该函数会在onDestroy前调用
  71. onClose() {
  72. }
  73. // public setItemData(data: GameConf.ItemData) {
  74. // this.itemData = data
  75. // this.initIconItemRes(this.itemData.id)
  76. // }
  77. public getItemData() {
  78. return this.itemData
  79. }
  80. public getPropType() {
  81. return this.propType
  82. }
  83. public getOriginData() {
  84. return this.originData
  85. }
  86. public getIsPackage() {
  87. if (this.originData.id >= 1065 && this.originData.id <= 1070) {
  88. return true
  89. } else {
  90. return false
  91. }
  92. }
  93. }