ShopItemRenderScript.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { _decorator, Component, Node, profiler, SpriteComponent, LabelComponent, ButtonComponent, loader, SpriteFrame } from 'cc';
  2. import GameConfigManager from '../../models/GameConfigManager';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('ShopItemRenderScript')
  5. export class ShopItemRenderScript extends Component {
  6. @property({
  7. type:SpriteComponent
  8. })
  9. icon:SpriteComponent=null;
  10. @property({
  11. type:LabelComponent
  12. })
  13. levelLabel:LabelComponent=null;
  14. @property({
  15. type:LabelComponent
  16. })
  17. nameLabel:LabelComponent=null;
  18. @property({
  19. type:ButtonComponent
  20. })
  21. freeBuyButton:ButtonComponent=null;
  22. @property({
  23. type:ButtonComponent
  24. })
  25. diamondBuyButton:ButtonComponent=null;
  26. @property({
  27. type:ButtonComponent
  28. })
  29. GlodBuyButton:ButtonComponent=null;
  30. @property({
  31. type:Node
  32. })
  33. lockState:Node=null;
  34. private data:any;
  35. start () {
  36. // Your initialization goes here.
  37. }
  38. UpdateItemRender(data:any):void{
  39. this.data=data;
  40. this.RefreshItem();
  41. }
  42. private RefreshItem():void{
  43. let weaponConfig:any=GameConfigManager.GetWeaponConfig(this.data.id);
  44. //图标
  45. loader.loadRes(weaponConfig.icon+"/spriteFrame",SpriteFrame,(err:Error,asset:SpriteFrame)=>{
  46. this.icon.spriteFrame=asset;
  47. })
  48. //等级
  49. this.levelLabel.string=weaponConfig.level;
  50. //名称
  51. this.nameLabel.string=weaponConfig.name;
  52. //state 0 未解锁 1 已解锁
  53. if(this.data.state==0){
  54. this.freeBuyButton.node.active=this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
  55. this.lockState.active=true;
  56. }else{
  57. this.lockState.active=false;
  58. //buyType 购买方式 0金币购买 1宝石购买 2看广告购买
  59. if(this.data.buyType==0){//金币购买
  60. this.freeBuyButton.node.active=this.diamondBuyButton.node.active=false;
  61. this.GlodBuyButton.node.active=true;
  62. }else if(this.data.buyType==1){//宝石购买
  63. this.freeBuyButton.node.active=this.GlodBuyButton.node.active=false;
  64. this.diamondBuyButton.node.active=true;
  65. }else{//广告购买
  66. this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
  67. this.freeBuyButton.node.active=true;
  68. }
  69. }
  70. }
  71. // update (deltaTime: number) {
  72. // // Your update function goes here.
  73. // }
  74. }