LoadingUIController.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. password:pass,
  64. confirm_password:cmpass,
  65. phone:phone
  66. };
  67. console.log(user);
  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. password:pass,
  80. };
  81. console.log(user);
  82. cc.vv.userMgr.login(data);
  83. },
  84. onBtnGuestClicked:function(){
  85. cc.vv.userMgr.guestAuth()
  86. },
  87. initListener()
  88. {
  89. this.onBehaviorEvent('LoginBehavior',Event.COM_MSG.PRELOAD_DONE,this.onLoaded.bind(this));
  90. this.onBehaviorEvent('LoginBehavior',Event.SOCKET_MSG.OPEN, this.onSocketOpen.bind(this));
  91. },
  92. onSocketOpen(sender,result)
  93. {
  94. this.bloaded = true
  95. },
  96. onLoaded(sender, result)
  97. {
  98. this.preloadCount++;
  99. this.progressBarTarget = this.preloadCount / this.preloadTotal;
  100. console.log("this.preloadCount:"+this.preloadCount+"this.progressBarTarget:"+this.progressBarTarget+"")
  101. if (this.progressBarTarget >= 1 && this.bloaded)
  102. {
  103. this.onResourcesLoaded();
  104. }
  105. },
  106. start()
  107. {
  108. this.preloadManager = new PreloadManager();
  109. this.audioControlManager = new AudioControlManager();
  110. //加载动画和预制体
  111. this.preloadManager.run();
  112. //加载音频
  113. this.audioControlManager.run();
  114. var self = this;
  115. cc.director.preloadScene("hall", function(){
  116. console.log("preload scene battle");
  117. self.onLoaded();
  118. })
  119. },
  120. onResourcesLoaded()
  121. {
  122. this.loginBtnNode.active = true
  123. this.loadproNode.active = false
  124. },
  125. update(dt)
  126. {
  127. if (this.progressBar.progress < this.progressBarTarget)
  128. {
  129. this.progressBar.progress += dt*this.scale
  130. }
  131. if (this.progressBarTarget >= 1 && this.bloaded && this.loginLogic.needShowAuth == false) {
  132. this.onResourcesLoaded();
  133. } else if (this.progressBarTarget >= 5 / 6 && this.bloaded && this.loginLogic.needShowAuth == false) {
  134. this.onResourcesLoaded();
  135. }
  136. },
  137. clickWXLogin(sender)
  138. {
  139. //weixin login
  140. // this.loginLogic.login()
  141. },
  142. clickYKLogin(sender){
  143. //youke login
  144. cc.vv.userMgr.guestAuth()
  145. // cc.director.loadScene('hall');
  146. },
  147. clickZHLogin(sender){
  148. //zhang hao login
  149. sender.target.active = false
  150. this.ykLogin.node.active = false
  151. this.loginBannerNode.active = true
  152. this.ljLogin.node.active = true
  153. this.yk2Login.node.active = true
  154. },
  155. clickRegBtn(sender){
  156. this.regAndreadNode.active = true
  157. this.regNode.active = true
  158. },
  159. clickReadYsBtn(sender){
  160. this.regNode.active = false
  161. this.readNode.active = true
  162. },
  163. clickCloseReg(sender){
  164. if (this.regNode.active) {
  165. this.regAndreadNode.active = false
  166. }else{
  167. this.regNode.active = true
  168. this.readNode.active = false
  169. }
  170. },
  171. });