ShopItemRenderScript.ts 4.0 KB

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