GameMode.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. GameConfig: {
  5. default: null,
  6. type: cc.Node,
  7. serializable: true,
  8. },
  9. GameStates: {
  10. default: null,
  11. type: cc.Node,
  12. serializable: true,
  13. },
  14. GameActionPower: {
  15. default: null,
  16. type: cc.Node,
  17. serializable: true,
  18. },
  19. GameCoin: {
  20. default: null,
  21. type: cc.Node,
  22. serializable: true,
  23. },
  24. GameDiamond: {
  25. default: null,
  26. type: cc.Node,
  27. serializable: true,
  28. },
  29. GameFansNum: {
  30. default: null,
  31. type: cc.Node,
  32. serializable: true,
  33. },
  34. GameFavorableImpressionPercentage: {
  35. default: null,
  36. type: cc.Node,
  37. serializable: true,
  38. },
  39. GameProgressBar: {
  40. default: null,
  41. type: cc.Node,
  42. serializable: true,
  43. },
  44. GameLoadingPercentageValue: {
  45. default: null,
  46. type: cc.Node,
  47. serializable: true,
  48. },
  49. GameLoading: {
  50. default: null,
  51. type: cc.Node,
  52. serializable: true,
  53. },
  54. },
  55. start () {
  56. this.GameConfigScript =this.GameConfig.getComponent('GameConfig');
  57. this.GameStatesScript =this.GameStates.getComponent('GameStates');
  58. this.TotoalProgressNum = 6;
  59. this.GetActionPower();
  60. },
  61. GetActionPower()
  62. {
  63. // console.log('GetAction');
  64. let ActionPower = this.GameStatesScript.GetActionPower();
  65. if(ActionPower!=undefined)
  66. {
  67. this.GameActionPower.getComponent(cc.Label).string = ActionPower;
  68. this. SetProgressBarPercentage(1, 'Coin');
  69. }
  70. else {
  71. this.GameLoadingPercentageValue.getComponent(cc.Label).string = '网络连接超时'
  72. }
  73. },
  74. GetCoin()
  75. {
  76. // console.log('GetCoin');
  77. let Coin = this.GameStatesScript.GetCoin();
  78. if(Coin!=undefined)
  79. {
  80. this.GameCoin.getComponent(cc.Label).string = Coin;
  81. this. SetProgressBarPercentage(2, 'Diamond');
  82. }
  83. else {
  84. this.GameLoadingPercentageValue.getComponent(cc.Label).string = '网络连接超时'
  85. }
  86. },
  87. GetDiamond()
  88. {
  89. let Diamond = this.GameStatesScript.GetDiamond();
  90. if(Diamond!=undefined)
  91. {
  92. this.GameDiamond.getComponent(cc.Label).string = Diamond;
  93. this. SetProgressBarPercentage(3,'Fans');
  94. }
  95. else {
  96. this.GameLoadingPercentageValue.getComponent(cc.Label).string = '网络连接超时'
  97. }
  98. },
  99. GetFans()
  100. {
  101. let Fans = this.GameStatesScript.GetFans();
  102. if(Fans!=undefined)
  103. {
  104. this.GameFansNum.getComponent(cc.Label).string = Fans;
  105. this. SetProgressBarPercentage(4,'FavorableImpression');
  106. }
  107. else {
  108. this.GameLoadingPercentageValue.getComponent(cc.Label).string = '网络连接超时'
  109. }
  110. },
  111. GetFavorableImpression()
  112. {
  113. let FavorableImpression = this.GameStatesScript.GetFavorableImpression();
  114. if(FavorableImpression!=undefined)
  115. {
  116. this.GameFavorableImpressionPercentage.getComponent('ChangeFavorableImpressionLabelValue').setPercentage(FavorableImpression);//setPercentage(FavorableImpression);
  117. this. SetProgressBarPercentage(5,'GameConfig');
  118. }
  119. else {
  120. this.GameLoadingPercentageValue.getComponent(cc.Label).string = '网络连接超时'
  121. }
  122. },
  123. GetGameConfig ()
  124. {
  125. this.GameConfigScript.GetGameConfig(function ()
  126. {
  127. this. SetProgressBarPercentage(6,'Finished');
  128. }.bind(this));
  129. },
  130. LoadingFinished()
  131. {
  132. this.GameLoading.active = false;
  133. },
  134. SetProgressBarPercentage(ProgressIndex,FunctionName)
  135. {
  136. let CurrentPercentage = this.CastProportionToPercentage(ProgressIndex);
  137. let LastPercentage = this.CastProportionToPercentage(ProgressIndex-1);
  138. let Duration = 0.1;
  139. // 重复次数
  140. let repeat = Math.floor(CurrentPercentage-LastPercentage);
  141. // 以秒为单位的时间间隔
  142. let interval = Duration/repeat;
  143. // 开始延时
  144. let delay = 0;
  145. let Index = 0;
  146. this.schedule(function()
  147. {
  148. Index++;
  149. this.GameLoadingPercentageValue.getComponent(cc.Label).string = Math.floor(LastPercentage+Index)+'%';
  150. this.GameProgressBar.getComponent(cc.ProgressBar).progress= (LastPercentage+Index)/100;
  151. if(Index==repeat)
  152. {
  153. this.ExecuceNextFun(FunctionName);
  154. }
  155. }, interval, repeat-1, delay);
  156. },
  157. CastProportionToPercentage(ProgressIndex)
  158. {
  159. return ProgressIndex/this.TotoalProgressNum*100;
  160. },
  161. ExecuceNextFun(FunctionName)
  162. {
  163. // console.log('FunctionName='+FunctionName)
  164. if(FunctionName == 'Coin')
  165. {
  166. this.GetCoin();
  167. }
  168. else if(FunctionName == 'Diamond')
  169. {
  170. this.GetDiamond();
  171. }
  172. else if(FunctionName == 'Fans')
  173. {
  174. this.GetFans();
  175. }
  176. else if(FunctionName == 'FavorableImpression')
  177. {
  178. this.GetFavorableImpression();
  179. }
  180. else if(FunctionName == 'GameConfig')
  181. {
  182. this.GetGameConfig();
  183. }
  184. else if(FunctionName == 'Finished')
  185. {
  186. this.LoadingFinished();
  187. }
  188. }
  189. });