ShopItemRenderScript.ts 3.9 KB

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