CarInfo.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import GameM from "../manager/GameM";
  8. import Sciencen_M from "../utils/Sciencen_M";
  9. import { MateData } from "../datas/MateData";
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class CarInfo extends cc.Component {
  13. @property(cc.Node)
  14. car: cc.Node = null;
  15. @property(cc.Label)
  16. labLv: cc.Label = null
  17. @property(cc.Label)
  18. labCost: cc.Label = null
  19. //类型
  20. type = 0
  21. @property(cc.Node)
  22. buyBtn: cc.Node = null;
  23. @property(cc.Node)
  24. adBtn: cc.Node = null;
  25. @property(cc.Node)
  26. trashBtn: cc.Node = null;
  27. @property(cc.Sprite)
  28. adSlider: cc.Sprite = null;
  29. @property(cc.Label)
  30. adLab: cc.Label = null;
  31. @property(cc.Label)
  32. trashLab: cc.Label = null;
  33. @property(cc.Label)
  34. labBuyTimes: cc.Label = null;
  35. btnState: Number = 0; //按钮状态 0 购买 1 广告
  36. // LIFE-CYCLE CALLBACKS:
  37. // onLoad () {}
  38. start() {
  39. // this.labBuyTimes.node.active = false
  40. }
  41. /** 改变车类型
  42. * @param type 类型
  43. */
  44. changeType(type) {
  45. if (this.type != type) {
  46. this.type = type
  47. cc.loader.loadRes('carPic/side/side_' + this.type.toString(), cc.SpriteFrame, (err, assets) => {
  48. if (err) {
  49. cc.error(err);
  50. return;
  51. }
  52. this.car.getComponent(cc.Sprite).spriteFrame = assets
  53. })
  54. }
  55. this.labBuyTimes.string = GameM.commonData.buyTimeTotal.toString()
  56. this.labLv.string = "Lv " + this.type.toString()
  57. //西游
  58. //白龙马天赋1
  59. let price = GameM.commonData.getPriceByType(this.type)
  60. price = Sciencen_M.instance.subtraction(price, Sciencen_M.instance.accMul(price, (MateData.Ins.Mate3Talent3 * 0.01).toString()))
  61. this.labCost.string = Sciencen_M.instance.format(price)
  62. //航海
  63. //this.labCost.string = Sciencen_M.instance.format(GameM.commonData.getPriceByType(this.type))
  64. }
  65. // update (dt) {}
  66. ShowBuyBtn() {
  67. this.adBtn.active = false;
  68. this.buyBtn.active = true;
  69. this.btnState = 0;
  70. }
  71. nextCarPrice: string = '0';
  72. tempPercent: number = 0;
  73. ShowAdBtn() {
  74. this.adBtn.active = true;
  75. this.buyBtn.active = false;
  76. this.nextCarPrice = GameM.commonData.getPriceByType(this.type);
  77. // console.log('CommonData.Instance.gold ', CommonData.Instance.gold)
  78. // console.log('this.nextCarPrice ', this.nextCarPrice)
  79. this.tempPercent = Number(Sciencen_M.instance.accDiv(GameM.commonData.gold, this.nextCarPrice));
  80. this.adSlider.fillRange = 0;
  81. this.adLab.string = "距离下次购买:" + parseInt(this.tempPercent * 100 + "") + '%'
  82. this.btnState = 1;
  83. this.unschedule(this.onAdBtnSchedule)
  84. this.schedule(this.onAdBtnSchedule, 1)
  85. }
  86. onAdBtnSchedule() {
  87. this.tempPercent = Number(Sciencen_M.instance.accDiv(GameM.commonData.gold, this.nextCarPrice));
  88. // console.log('this.tempPercent ', this.tempPercent)
  89. if (this.tempPercent >= 1) this.tempPercent = 1;
  90. this.adSlider.fillRange = this.tempPercent;
  91. this.adLab.string = "距离下次购买:" + parseInt(this.tempPercent * 100 + "") + '%'
  92. if (this.tempPercent >= 1) {
  93. this.unschedule(this.onAdBtnSchedule);
  94. this.ShowBuyBtn();
  95. }
  96. }
  97. /**显示垃圾回收按钮*/
  98. ActiveTrasnBtn(active: boolean, gold?: string) {
  99. this.trashBtn.active = active;
  100. if (active) {
  101. this.buyBtn.active = false;
  102. this.adBtn.active = false;
  103. } else {
  104. if (this.btnState == 0) {
  105. this.buyBtn.active = true;
  106. } else {
  107. this.adBtn.active = true;
  108. }
  109. }
  110. this.trashLab.string = "可获得" + Sciencen_M.instance.format(gold);
  111. }
  112. }