import { _decorator, Component, Node, tween } from 'cc'; import platformSystem from '../platform/platformSystem'; import BasePanel from '../core/component/BasePanel'; import { audioMgr } from '../core/manager/AudioManager'; import WindowManager from '../core/manager/WindowManager'; import { LevelClearLayer } from './LevelClearLayer'; import { GameConst } from '../core/common/GameConst'; const { ccclass, property } = _decorator; @ccclass('DrawStarLayer') export class DrawStarLayer extends BasePanel { indicator: Node = null; start() { this.indicator = this.GetGameObject("star-gamification-indicator"); audioMgr.playOneShot(GameConst.audios.pass); } star = 0; setStar(s) { this.star = s; this.SetText("lbl_star", s + ""); } dir = 1; beisu = 1; update() { if (this.pause) return; let pos = this.indicator.getPosition(); pos.x += this.dir * 10; if (pos.x > 190) this.dir = -1; if (pos.x < -190) this.dir = 1; this.indicator.setPosition(pos); let x = this.indicator.getPosition().x; if (x >= -190 && x < -145) { this.beisu = 2; } else if (x >= -145 && x < -98) { this.beisu = 3; } else if (x >= -98 && x < -36) { this.beisu = 4; } else if (x >= -36 && x < 36) { this.beisu = 5; } else if (x >= 36 && x < 98) { this.beisu = 4; } else if (x >= 98 && x < 145) { this.beisu = 3; } else if (x >= 145 && x <= 190) { this.beisu = 2; } this.SetText("lbl_beisu", "x" + this.beisu); } pause = false; onBtnClicked(event, customEventData) { audioMgr.playOneShot(GameConst.audios.btnclick); var btnName = event.target.name; switch (btnName) { case "btn_get": this.pause = true; WindowManager.ins.open("LevelClearLayer").then((com: LevelClearLayer) => { com.setAddStar(this.star); }) this.close(); break; case "btn_ad": this.pause = true; tween(this.node).delay(1).call(() => { platformSystem.platform.showRewardVideo((b) => { if (b) { WindowManager.ins.open("LevelClearLayer").then((com: LevelClearLayer) => { com.setAddStar(this.star * this.beisu); }) this.close(); } }) }).start() break; } } }