123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import { _decorator, Component, Label, Node, ProgressBar } from 'cc';
- import { att_count_down } from '../../../data/data';
- import { gameManager } from '../gameManager';
- const { ccclass, property } = _decorator;
- @ccclass('count_down')
- export class count_down extends Component {
- private m_data:att_count_down = null;
- @property(Node) ProgressBar_Bg:Node = null;
- @property(Node) ProgressBar_Bar:Node = null;
- @property(Node) img_text:Node = null;
- @property(Node) lab_time:Node = null;
- private time_count:number = 0;
- private m_over_call = null;
- public init(data:att_count_down,on_over_call){
- this.m_data = data;
- this.m_over_call = on_over_call;
- gameManager.initUiBaseAtt(this.ProgressBar_Bar,this.m_data.ProgressBar_Bar)
-
- gameManager.initUiBaseAtt(this.ProgressBar_Bg,this.m_data.ProgressBar_Bg)
-
- gameManager.initUiBaseAtt(this.img_text,this.m_data.img_text)
- this.ProgressBar_Bg.getComponent(ProgressBar).totalLength = this.m_data.ProgressBar_Bg.width;
-
- if(this.m_data.time_count>0){
- if(this.m_data.is_show_time){
- this.lab_time.getComponent(Label).string = `${this.m_data.time_count}秒`
- this.lab_time.active = true;
- }else{
- this.lab_time.active = false;
- }
- }else{
- this.lab_time.active = false;
- }
- }
- public getData(){
- return this.m_data
- }
- public startCountDown(){
- this.schedule(()=>{
- this.time_count+=1;
- if(this.time_count>this.m_data.time_count){
- this.unscheduleAllCallbacks()
- if(this.m_over_call!=null){
- this.m_over_call(true)
- }
- return
- }
- this.ProgressBar_Bg.getComponent(ProgressBar).progress = 1-this.time_count/this.m_data.time_count
- if(this.m_data.is_show_time){
- this.lab_time.getComponent(Label).string = `${this.m_data.time_count-this.time_count}秒`
- }
-
- },1)
- }
- }
|