| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- cc.Class({
- extends: cc.Component,
- properties: {
- GameConfig: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameStates: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameActionPower: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameCoin: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameDiamond: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameFansNum: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameFavorableImpressionPercentage: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameProgressBar: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameLoadingPercentageValue: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameLoading: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- },
- start () {
- this.GameConfigScript =this.GameConfig.getComponent('GameConfig');
- this.GameStatesScript =this.GameStates.getComponent('GameStates');
- this.TotoalProgressNum = 6;
- this.GetActionPower();
- },
- GetActionPower()
- {
- // console.log('GetAction');
- let ActionPower = this.GameStatesScript.GetActionPower();
- if(ActionPower!=undefined)
- {
- this.GameActionPower.getComponent(cc.Label).string = ActionPower;
- this. SetProgressBarPercentage(1, 'Coin');
- }
- else {
- this.GameLoadingPercentageValue.getComponent(cc.Label).string = '网络连接超时'
- }
- },
- GetCoin()
- {
- // console.log('GetCoin');
- let Coin = this.GameStatesScript.GetCoin();
- if(Coin!=undefined)
- {
- this.GameCoin.getComponent(cc.Label).string = Coin;
- this. SetProgressBarPercentage(2, 'Diamond');
- }
- else {
- this.GameLoadingPercentageValue.getComponent(cc.Label).string = '网络连接超时'
- }
- },
- GetDiamond()
- {
- let Diamond = this.GameStatesScript.GetDiamond();
- if(Diamond!=undefined)
- {
- this.GameDiamond.getComponent(cc.Label).string = Diamond;
- this. SetProgressBarPercentage(3,'Fans');
- }
- else {
- this.GameLoadingPercentageValue.getComponent(cc.Label).string = '网络连接超时'
- }
- },
- GetFans()
- {
- let Fans = this.GameStatesScript.GetFans();
- if(Fans!=undefined)
- {
- this.GameFansNum.getComponent(cc.Label).string = Fans;
- this. SetProgressBarPercentage(4,'FavorableImpression');
- }
- else {
- this.GameLoadingPercentageValue.getComponent(cc.Label).string = '网络连接超时'
- }
- },
- GetFavorableImpression()
- {
- let FavorableImpression = this.GameStatesScript.GetFavorableImpression();
- if(FavorableImpression!=undefined)
- {
- this.GameFavorableImpressionPercentage.getComponent('ChangeFavorableImpressionLabelValue').setPercentage(FavorableImpression);//setPercentage(FavorableImpression);
- this. SetProgressBarPercentage(5,'GameConfig');
- }
- else {
- this.GameLoadingPercentageValue.getComponent(cc.Label).string = '网络连接超时'
- }
- },
- GetGameConfig ()
- {
- this.GameConfigScript.GetGameConfig(function ()
- {
- this. SetProgressBarPercentage(6,'Finished');
- }.bind(this));
- },
- LoadingFinished()
- {
- this.GameLoading.active = false;
- },
- SetProgressBarPercentage(ProgressIndex,FunctionName)
- {
- let CurrentPercentage = this.CastProportionToPercentage(ProgressIndex);
- let LastPercentage = this.CastProportionToPercentage(ProgressIndex-1);
- let Duration = 0.1;
- // 重复次数
- let repeat = Math.floor(CurrentPercentage-LastPercentage);
- // 以秒为单位的时间间隔
- let interval = Duration/repeat;
- // 开始延时
- let delay = 0;
- let Index = 0;
- this.schedule(function()
- {
- Index++;
- this.GameLoadingPercentageValue.getComponent(cc.Label).string = Math.floor(LastPercentage+Index)+'%';
- this.GameProgressBar.getComponent(cc.ProgressBar).progress= (LastPercentage+Index)/100;
- if(Index==repeat)
- {
- this.ExecuceNextFun(FunctionName);
- }
- }, interval, repeat-1, delay);
- },
- CastProportionToPercentage(ProgressIndex)
- {
- return ProgressIndex/this.TotoalProgressNum*100;
- },
- ExecuceNextFun(FunctionName)
- {
- // console.log('FunctionName='+FunctionName)
- if(FunctionName == 'Coin')
- {
- this.GetCoin();
- }
- else if(FunctionName == 'Diamond')
- {
- this.GetDiamond();
- }
- else if(FunctionName == 'Fans')
- {
- this.GetFans();
- }
- else if(FunctionName == 'FavorableImpression')
- {
- this.GetFavorableImpression();
- }
- else if(FunctionName == 'GameConfig')
- {
- this.GetGameConfig();
- }
- else if(FunctionName == 'Finished')
- {
- this.LoadingFinished();
- }
- }
- });
|