LoadingUIController.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import FireEventObserver from '../framework/FireEventObserver';
  2. import PreloadManager from '../common/PreloadManager';
  3. import AudioControlManager from '../common/AudioControlManager';
  4. import Event from '../net/Event';
  5. import LogicUnitManager from '../framework/LogicUnitManager'
  6. import Common from '../common/Common';
  7. cc.Class({
  8. extends: FireEventObserver,
  9. properties: {
  10. progressBar: cc.ProgressBar,
  11. wxLogin:cc.Button,
  12. ykLogin:cc.Button,
  13. zhLogin:cc.Button,
  14. ljLogin:cc.Button,
  15. yk2Login:cc.Button,
  16. loginBtnNode:cc.Node,
  17. loadproNode:cc.Node,
  18. loginBannerNode:cc.Node,
  19. regAndreadNode:cc.Node,
  20. regNode:cc.Node,
  21. readNode:cc.Node,
  22. gotoRegBtn:cc.Node,
  23. inputName:cc.EditBox,
  24. inputPass:cc.EditBox,
  25. inputCmpass:cc.EditBox,
  26. inputphone:cc.EditBox,
  27. loginName:cc.EditBox,
  28. loginPass:cc.EditBox,
  29. },
  30. onLoad()
  31. {
  32. window['onGameBoot']();
  33. cc.macro.ENABLE_CULLING = false;
  34. this.loginBtnNode.active = false
  35. this.progressBarTarget = 0;
  36. this.scale = 1;
  37. this.initListener();
  38. this.preloadCount = 0;
  39. this.preloadTotal = 5;
  40. this.lum = LogicUnitManager;
  41. this.loginLogic = this.lum.getBehavior('LoginBehavior');
  42. // this.loginLogic.CreateLoginStart();
  43. this.bloaded = true
  44. this.initMgr();
  45. },
  46. initMgr() {
  47. cc.vv = {};
  48. cc.vv.http = require("../net/HTTP");
  49. var UserMgr = require("../controller/UserMgr");
  50. cc.vv.userMgr = new UserMgr();
  51. },
  52. onBtnConfirmClicked:function(){
  53. var user = this.inputName.string;
  54. var pass = this.inputPass.string;
  55. var cmpass = this.inputCmpass.string;
  56. var phone = this.inputphone.string;
  57. if(user == ""){
  58. console.log("invalid name.");
  59. return;
  60. }
  61. var data = {
  62. user:user,
  63. pass:pass,
  64. confirm_password:cmpass,
  65. phone:phone
  66. };
  67. console.log(name);
  68. cc.vv.userMgr.create(data);
  69. },
  70. onBtnLoginClicked:function(){
  71. var user = this.loginName.string;
  72. var pass = this.loginPass.string;
  73. if(user == ""){
  74. console.log("invalid name.");
  75. return;
  76. }
  77. var data = {
  78. user:user,
  79. pass:pass,
  80. };
  81. console.log(name);
  82. cc.vv.userMgr.login(data);
  83. },
  84. initListener()
  85. {
  86. this.onBehaviorEvent('LoginBehavior',Event.COM_MSG.PRELOAD_DONE,this.onLoaded.bind(this));
  87. this.onBehaviorEvent('LoginBehavior',Event.SOCKET_MSG.OPEN, this.onSocketOpen.bind(this));
  88. },
  89. onSocketOpen(sender,result)
  90. {
  91. this.bloaded = true
  92. },
  93. onLoaded(sender, result)
  94. {
  95. this.preloadCount++;
  96. this.progressBarTarget = this.preloadCount / this.preloadTotal;
  97. console.log("this.preloadCount:"+this.preloadCount+"this.progressBarTarget:"+this.progressBarTarget+"")
  98. if (this.progressBarTarget >= 1 && this.bloaded)
  99. {
  100. this.onResourcesLoaded();
  101. }
  102. },
  103. start()
  104. {
  105. this.preloadManager = new PreloadManager();
  106. this.audioControlManager = new AudioControlManager();
  107. //加载动画和预制体
  108. this.preloadManager.run();
  109. //加载音频
  110. this.audioControlManager.run();
  111. var self = this;
  112. cc.director.preloadScene("hall", function(){
  113. console.log("preload scene battle");
  114. self.onLoaded();
  115. })
  116. },
  117. onResourcesLoaded()
  118. {
  119. this.loginBtnNode.active = true
  120. this.loadproNode.active = false
  121. },
  122. update(dt)
  123. {
  124. if (this.progressBar.progress < this.progressBarTarget)
  125. {
  126. this.progressBar.progress += dt*this.scale
  127. }
  128. if (this.progressBarTarget >= 1 && this.bloaded && this.loginLogic.needShowAuth == false) {
  129. this.onResourcesLoaded();
  130. } else if (this.progressBarTarget >= 5 / 6 && this.bloaded && this.loginLogic.needShowAuth == false) {
  131. this.onResourcesLoaded();
  132. }
  133. },
  134. clickWXLogin(sender)
  135. {
  136. //weixin login
  137. // this.loginLogic.login()
  138. },
  139. clickYKLogin(sender){
  140. //youke login
  141. cc.director.loadScene('hall');
  142. },
  143. clickZHLogin(sender){
  144. //zhang hao login
  145. sender.target.active = false
  146. this.ykLogin.node.active = false
  147. this.loginBannerNode.active = true
  148. this.ljLogin.node.active = true
  149. this.yk2Login.node.active = true
  150. },
  151. clickRegBtn(sender){
  152. this.regAndreadNode.active = true
  153. this.regNode.active = true
  154. },
  155. clickReadYsBtn(sender){
  156. this.regNode.active = false
  157. this.readNode.active = true
  158. },
  159. clickCloseReg(sender){
  160. if (this.regNode.active) {
  161. this.regAndreadNode.active = false
  162. }else{
  163. this.regNode.active = true
  164. this.readNode.active = false
  165. }
  166. },
  167. });