ExchangeItemRenderScript.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { _decorator, Component, Node, LabelComponent } from 'cc';
  2. import { NoticeManager } from '../../../engines/notices/NoticeManager';
  3. import StringUtils from '../../../engines/utils/StringUtils';
  4. import { PlatformManager } from '../../../Platform/PlatformManager';
  5. import { branchIdType } from '../../../Platform/WeChat/branchIdType';
  6. import { WeChatPlatform } from '../../../Platform/WeChat/WeChatPlatform';
  7. import { GameModel } from '../../models/GameModel';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('ExchangeItemRenderScript')
  10. export class ExchangeItemRenderScript extends Component {
  11. @property({
  12. type: LabelComponent
  13. })
  14. timeLabel: LabelComponent = null;
  15. @property({
  16. type: LabelComponent
  17. })
  18. timeLabel1: LabelComponent = null;
  19. @property({
  20. type: LabelComponent
  21. })
  22. goldLabel: LabelComponent = null;
  23. @property({
  24. type: LabelComponent
  25. })
  26. diamondLabel: LabelComponent = null;
  27. private data: any;
  28. private gold:number;
  29. UpdateItemRender(data: any): void {
  30. this.data = data;
  31. let time: number = data.time / 60 / 60;
  32. this.gold=GameModel.single.fullEarnings * data.time;
  33. this.timeLabel.string = time + "小时枪械收益";
  34. this.timeLabel1.string = "立即获得" + time + "小时枪械收益!";
  35. this.goldLabel.string = StringUtils.numberUtilsEn(this.gold);
  36. this.diamondLabel.string = StringUtils.numberUtilsEn(data.useDiamond, 0);
  37. }
  38. /**
  39. * 购买
  40. */
  41. BuyButtonClickHandler(): void {
  42. if (GameModel.single.diamond < this.data.useDiamond) {
  43. NoticeManager.ShowPrompt("钻石不足!");
  44. } else {
  45. GameModel.single.diamond -= this.data.useDiamond;
  46. GameModel.single.gold+=this.gold;
  47. let weChat = PlatformManager.impl as WeChatPlatform;
  48. if (weChat instanceof WeChatPlatform) {
  49. weChat.branchAnalytics(branchIdType.GoldExchange, String(this.data.useDiamond))
  50. }
  51. }
  52. }
  53. start() {
  54. // Your initialization goes here.
  55. }
  56. // update (deltaTime: number) {
  57. // // Your update function goes here.
  58. // }
  59. }