ShopItemRenderScript.ts 3.7 KB

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