ShopItemRenderScript.ts 3.0 KB

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