ShopItemRenderScript.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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:LabelComponent
  44. })
  45. GlodBuyButtonLabel:LabelComponent=null;
  46. @property({
  47. type:Node
  48. })
  49. lockState:Node=null;
  50. private data:any;
  51. start () {
  52. // Your initialization goes here.
  53. }
  54. UpdateItemRender(data:any):void{
  55. this.data=data;
  56. this.RefreshItem();
  57. }
  58. private RefreshItem():void{
  59. let weaponConfig:any=GameConfigManager.GetWeaponConfig(this.data.id);
  60. //图标
  61. loader.loadRes(weaponConfig.icon+"/spriteFrame",SpriteFrame,(err:Error,asset:SpriteFrame)=>{
  62. if(err!=null){
  63. console.log("加载图标出错:"+weaponConfig.icon);
  64. return;
  65. }
  66. this.icon.spriteFrame=asset;
  67. })
  68. //等级
  69. this.levelLabel.string=weaponConfig.level.toString();
  70. //名称
  71. this.nameLabel.string=weaponConfig.name;
  72. let price:number;
  73. //state 0 未解锁 1 已解锁
  74. if(this.data.state==0){
  75. this.freeBuyButton.node.active=this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
  76. this.lockState.active=true;
  77. }else{
  78. this.lockState.active=false;
  79. //buyType 购买方式 0金币购买 1宝石购买 2看广告购买
  80. if(this.data.buyType==0){//金币购买
  81. this.freeBuyButton.node.active=this.diamondBuyButton.node.active=false;
  82. this.GlodBuyButton.node.active=true;
  83. price=GameModel.single.GetWeaponBuyPrice(this.data.id);
  84. this.GlodBuyButtonLabel.string=StringUtils.numberUtilsEn(price);
  85. }else if(this.data.buyType==1){//宝石购买
  86. this.freeBuyButton.node.active=this.GlodBuyButton.node.active=false;
  87. this.diamondBuyButton.node.active=true;
  88. price=weaponConfig.consumeDiamond;
  89. this.diamondBuyButtonLabel.string=StringUtils.numberUtilsEn(price);
  90. }else{//广告购买
  91. this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
  92. this.freeBuyButton.node.active=true;
  93. }
  94. }
  95. }
  96. /**
  97. * 金币购买
  98. */
  99. GlodBuy():void{
  100. if(GameModel.single.BuyWeapon(this.data.buyType,this.data.id)){
  101. NoticeManager.ShowPrompt("购买成功。");
  102. }
  103. }
  104. /**
  105. * 钻石购买
  106. */
  107. DiamondBuy():void{
  108. if(GameModel.single.BuyWeapon(this.data.buyType,this.data.id)){
  109. NoticeManager.ShowPrompt("购买成功。");
  110. }
  111. }
  112. /**
  113. * 视频购买
  114. */
  115. VideoBuy():void{
  116. PlatformManager.showRewardedVideo(()=>{
  117. if(GameModel.single.BuyWeapon(this.data.buyType,this.data.id)){
  118. NoticeManager.ShowPrompt("购买成功。");
  119. }
  120. }, ()=>{
  121. NoticeManager.ShowPrompt("购买失败。");
  122. })
  123. }
  124. // update (deltaTime: number) {
  125. // // Your update function goes here.
  126. // }
  127. }