ExchangeItemRenderScript.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. UpdateItemRender(data: any): void {
  29. this.data = data;
  30. let time: number = data.time / 60 / 60;
  31. this.timeLabel.string = time + "小时枪械收益";
  32. this.timeLabel1.string = "立即获得" + time + "小时枪械收益!";
  33. this.goldLabel.string = StringUtils.numberUtilsEn(GameModel.single.fullEarnings * data.time);
  34. this.diamondLabel.string = StringUtils.numberUtilsEn(data.useDiamond, 0);
  35. }
  36. /**
  37. * 购买
  38. */
  39. BuyButtonClickHandler(): void {
  40. if (GameModel.single.diamond < this.data.useDiamond) {
  41. NoticeManager.ShowPrompt("钻石不足!");
  42. } else {
  43. GameModel.single.diamond -= this.data.useDiamond;
  44. let weChat = PlatformManager.impl as WeChatPlatform;
  45. if (weChat instanceof WeChatPlatform) {
  46. weChat.branchAnalytics(branchIdType.GoldExchange, String(this.data.useDiamond))
  47. }
  48. }
  49. }
  50. start() {
  51. // Your initialization goes here.
  52. }
  53. // update (deltaTime: number) {
  54. // // Your update function goes here.
  55. // }
  56. }