ShopItemRenderScript.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.toString();
  59. //名称
  60. this.nameLabel.string=weaponConfig.name;
  61. let price:number;
  62. //state 0 未解锁 1 已解锁
  63. if(this.data.state==0){
  64. this.freeBuyButton.node.active=this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
  65. this.lockState.active=true;
  66. }else{
  67. this.lockState.active=false;
  68. //buyType 购买方式 0金币购买 1宝石购买 2看广告购买
  69. if(this.data.buyType==0){//金币购买
  70. this.freeBuyButton.node.active=this.diamondBuyButton.node.active=false;
  71. this.GlodBuyButton.node.active=true;
  72. price=GameModel.single.GetWeaponBuyPrice(this.data.id);
  73. this.freeBuyButtonLabel.string=price.toString();
  74. }else if(this.data.buyType==1){//宝石购买
  75. this.freeBuyButton.node.active=this.GlodBuyButton.node.active=false;
  76. this.diamondBuyButton.node.active=true;
  77. price=weaponConfig.consumeDiamond;
  78. this.diamondBuyButtonLabel.string=price.toString();
  79. }else{//广告购买
  80. this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
  81. this.freeBuyButton.node.active=true;
  82. }
  83. }
  84. }
  85. /**
  86. * 金币购买
  87. */
  88. GlodBuy():void{
  89. GameModel.single.BuyWeapon(this.data.buyType,this.data.id);
  90. }
  91. /**
  92. * 钻石购买
  93. */
  94. DiamondBuy():void{
  95. GameModel.single.BuyWeapon(this.data.buyType,this.data.id);
  96. }
  97. /**
  98. * 视频购买
  99. */
  100. VideoBuy():void{
  101. GameModel.single.BuyWeapon(this.data.buyType,this.data.id);
  102. }
  103. // update (deltaTime: number) {
  104. // // Your update function goes here.
  105. // }
  106. }