| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
- import GameM from "../manager/GameM";
- import Sciencen_M from "../utils/Sciencen_M";
- import { MateData } from "../datas/MateData";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class CarInfo extends cc.Component {
- @property(cc.Node)
- car: cc.Node = null;
- @property(cc.Label)
- labLv: cc.Label = null
- @property(cc.Label)
- labCost: cc.Label = null
- //类型
- type = 0
- @property(cc.Node)
- buyBtn: cc.Node = null;
- @property(cc.Node)
- adBtn: cc.Node = null;
- @property(cc.Node)
- trashBtn: cc.Node = null;
- @property(cc.Sprite)
- adSlider: cc.Sprite = null;
- @property(cc.Label)
- adLab: cc.Label = null;
- @property(cc.Label)
- trashLab: cc.Label = null;
- @property(cc.Label)
- labBuyTimes: cc.Label = null;
- btnState: Number = 0; //按钮状态 0 购买 1 广告
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {}
- start() {
- // this.labBuyTimes.node.active = false
- }
- /** 改变车类型
- * @param type 类型
- */
- changeType(type) {
- if (this.type != type) {
- this.type = type
- cc.loader.loadRes('carPic/side/side_' + this.type.toString(), cc.SpriteFrame, (err, assets) => {
- if (err) {
- cc.error(err);
- return;
- }
- this.car.getComponent(cc.Sprite).spriteFrame = assets
- })
- }
- this.labBuyTimes.string = GameM.commonData.buyTimeTotal.toString()
- this.labLv.string = "Lv " + this.type.toString()
- //西游
- //白龙马天赋1
- let price = GameM.commonData.getPriceByType(this.type)
- price = Sciencen_M.instance.subtraction(price, Sciencen_M.instance.accMul(price, (MateData.Ins.Mate3Talent3 * 0.01).toString()))
- this.labCost.string = Sciencen_M.instance.format(price)
- //航海
- //this.labCost.string = Sciencen_M.instance.format(GameM.commonData.getPriceByType(this.type))
- }
- // update (dt) {}
- ShowBuyBtn() {
- this.adBtn.active = false;
- this.buyBtn.active = true;
- this.btnState = 0;
- }
- nextCarPrice: string = '0';
- tempPercent: number = 0;
- ShowAdBtn() {
- this.adBtn.active = true;
- this.buyBtn.active = false;
- this.nextCarPrice = GameM.commonData.getPriceByType(this.type);
- // console.log('CommonData.Instance.gold ', CommonData.Instance.gold)
- // console.log('this.nextCarPrice ', this.nextCarPrice)
- this.tempPercent = Number(Sciencen_M.instance.accDiv(GameM.commonData.gold, this.nextCarPrice));
- this.adSlider.fillRange = 0;
- this.adLab.string = "距离下次购买:" + parseInt(this.tempPercent * 100 + "") + '%'
- this.btnState = 1;
- this.unschedule(this.onAdBtnSchedule)
- this.schedule(this.onAdBtnSchedule, 1)
- }
- onAdBtnSchedule() {
- this.tempPercent = Number(Sciencen_M.instance.accDiv(GameM.commonData.gold, this.nextCarPrice));
- // console.log('this.tempPercent ', this.tempPercent)
- if (this.tempPercent >= 1) this.tempPercent = 1;
- this.adSlider.fillRange = this.tempPercent;
- this.adLab.string = "距离下次购买:" + parseInt(this.tempPercent * 100 + "") + '%'
- if (this.tempPercent >= 1) {
- this.unschedule(this.onAdBtnSchedule);
- this.ShowBuyBtn();
- }
- }
- /**显示垃圾回收按钮*/
- ActiveTrasnBtn(active: boolean, gold?: string) {
- this.trashBtn.active = active;
- if (active) {
- this.buyBtn.active = false;
- this.adBtn.active = false;
- } else {
- if (this.btnState == 0) {
- this.buyBtn.active = true;
- } else {
- this.adBtn.active = true;
- }
- }
- this.trashLab.string = "可获得" + Sciencen_M.instance.format(gold);
- }
- }
|