GamesHallController.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. import FireEventObserver from '../framework/FireEventObserver';
  2. import ViewManager from '../ui/ViewManager';
  3. import PreloadManager from '../common/PreloadManager';
  4. import AudioControlManager from '../common/AudioControlManager';
  5. import Event from '../net/Event';
  6. import LogicUnitManager from '../framework/LogicUnitManager'
  7. import Common from '../common/Common';
  8. // import sql from '../common/autogensqlitebindings_api'
  9. cc.Class({
  10. extends: FireEventObserver,
  11. properties: {
  12. nvren:cc.Node,
  13. hallsBtns:cc.Node,
  14. dzjjHall:cc.Node,
  15. carsHall:cc.Node,
  16. sportsHall:cc.Node,
  17. dzyyHall:cc.Node,
  18. buyuHall:cc.Node,
  19. caipiaoHall:cc.Node,
  20. zhenrenHall:cc.Node,
  21. webviewNode:cc.Node,
  22. Gundong:cc.Label,
  23. GundongMask:cc.Mask,
  24. Gundong1:cc.Layout,
  25. GundongMask1:cc.Mask,
  26. returnNode:cc.Node,
  27. shareNode:cc.Node,
  28. listLayoutNode:cc.Node,
  29. halllist:cc.Node,
  30. listView:cc.ScrollView,
  31. tipsLayer:cc.Node,
  32. hallListBtn:cc.Node,
  33. shopNode:cc.Node,
  34. gameHallItem:cc.Prefab,
  35. },
  36. onLoad()
  37. {
  38. // window['onGameBoot']();
  39. // cc.macro.ENABLE_CULLING = false;
  40. // this.loginBtnNode.active = false
  41. // this.progressBarTarget = 0;
  42. // this.scale = 1;
  43. this.initListener();
  44. // this.preloadCount = 0;
  45. // this.preloadTotal = 5;
  46. // this.lum = LogicUnitManager;
  47. this.loginLogic = this.lum.getBehavior('LoginBehavior');
  48. this.loginLogic.CreateLoginStart();
  49. // this.bloaded = true
  50. // this.node.Opacity=0;
  51. // this.node.runAction(cc.fadeIn(1.0));
  52. this.dzjjHall.active = false
  53. this.carsHall.active = false
  54. this.sportsHall.active = false
  55. this.dzyyHall.active = false
  56. this.buyuHall.active = false
  57. this.caipiaoHall.active = false
  58. this.webviewNode.active = false
  59. this.returnNode.active =false
  60. this.shareNode.active =true
  61. this.hallListBtn.active = false
  62. // this.halllist.active = false
  63. // this.playShow()
  64. // this.animation = this.nvren.getComponent(cc.Animation);
  65. // this.animation.on('finished', this.onGuideFinished, this);
  66. // this.animation.play('nrcome1');
  67. var self = this
  68. this.gundongText()
  69. // this.gundongText2()
  70. this.dtNum = 0
  71. this.animation = this.nvren.getComponent(cc.Animation);
  72. this.animation.on('finished', this.onGuideFinished, this);
  73. this.animation.play('nrcome1');
  74. // this._db = new sql.SQLiteWrapper();
  75. // this._dbPath = this._db.initializing("data.db","res","");
  76. cc.vv.userMgr.getGameList(null,this.OnGetGamelist.bind(this)); //获取游戏列表
  77. var subhall= [
  78. [1 , this.caipiaoHall.getComponent('CaiPiaoHallController')],
  79. [2 , this.carsHall.getComponent('CarsHallController')],
  80. [3 , this.dzyyHall.getComponent('DianziYouyiHallController')],
  81. [4 , this.zhenrenHall.getComponent('ZhenrenHallController')],
  82. [5 , this.dzjjHall.getComponent('DzjjHallController')],
  83. [6 , this.buyuHall.getComponent('BuyuHallController')],
  84. // ['7' , this.sportsHall.getComponent('SportsHallController')]
  85. [7 , this.webviewNode.getComponent('WebviewCtrl')]
  86. ]
  87. this.myhallMap = new Map(subhall);
  88. console.log(this.myhallMap.keys());
  89. this.setHalllist()
  90. this.halllist.moved = false
  91. ViewManager.registerView('tips',this.tipsLayer)
  92. },
  93. OnGetGamelist(ret){
  94. if (ret.data.data && ret.data.data.length>0) {
  95. this.hallsBtns.children.forEach(element => {
  96. element.destroy()
  97. });
  98. var gameitems = ret.data.data
  99. var xStartPos = 135
  100. var yStarPos = 350
  101. var stepX = 300
  102. gameitems.sort(function (a,b) {
  103. return a.id - b.id
  104. })
  105. for (let index = 0; index < gameitems.length; index++) {
  106. const data = gameitems[index]
  107. var gameItem = cc.instantiate(this.gameHallItem)
  108. gameItem.name = "item"+data.id
  109. var itemx = xStartPos + index*stepX
  110. var itemy = yStarPos
  111. gameItem.getComponent('GameHallItem').setGameData(itemx,itemy,data,this)
  112. this.hallsBtns.addChild(gameItem)
  113. }
  114. this.hallsBtns.width = gameitems.length*(gameItem.width+30)
  115. this.hallsBtns.height = 600
  116. }
  117. },
  118. onGuideFinished(){
  119. console.log("onGuideFinished--------------------")
  120. this.animation.play('nrcome')
  121. },
  122. initListener()
  123. {
  124. // this.onBehaviorEvent('LoginBehavior',Event.COM_MSG.PRELOAD_DONE,this.onLoaded.bind(this));
  125. // this.onBehaviorEvent('LoginBehavior',Event.SOCKET_MSG.OPEN, this.onSocketOpen.bind(this));
  126. this.onBehaviorEvent('LoginBehavior',Event.DATA_MSG.LOGIN, this.onUserLogin.bind(this));
  127. },
  128. onUserLogin()
  129. {
  130. var playerInfo = this.node.getChildByName('top').getChildByName("playerInfo")
  131. playerInfo.getChildByName("name").getComponent(cc.Label).string = cc.vv.userMgr.account
  132. playerInfo.getChildByName("playerID").getComponent(cc.Label).string = "ID:"+cc.vv.userMgr.userId
  133. console.log(cc.vv.userMgr.account)
  134. },
  135. onSocketOpen(sender,result)
  136. {
  137. this.bloaded = true
  138. },
  139. onLoaded(sender, result)
  140. {
  141. this.preloadCount++;
  142. this.progressBarTarget = this.preloadCount / this.preloadTotal;
  143. console.log("this.preloadCount:"+this.preloadCount+"this.progressBarTarget:"+this.progressBarTarget+"")
  144. if (this.progressBarTarget >= 1 && this.bloaded)
  145. {
  146. this.onResourcesLoaded();
  147. }
  148. },
  149. gundongText:function(){
  150. var self = this;
  151. setTimeout(function(){
  152. // var notifyRes = JSON.parse(cc.sys.localStorage.getItem('notify'));
  153. // var gundongNode = cc.find("Canvas/gundong");
  154. // if(notifyRes != null){
  155. // if(gundongNode){
  156. // gundongNode.active = true;
  157. // }
  158. // self.Gundong.string = notifyRes;
  159. // }else{
  160. // if(gundongNode){
  161. // gundongNode.active = false;
  162. // }
  163. // }
  164. var text = self.Gundong;
  165. var width = self.GundongMask.node.width;
  166. text.node.runAction(cc.repeatForever(cc.sequence(
  167. cc.moveTo(text.node.width/width*10,cc.v2(-text.node.width-width/5,text.node.y)),
  168. cc.callFunc(function(){
  169. text.node.x = width;
  170. }))));
  171. },300);
  172. },
  173. gundongText2:function(){
  174. var self = this;
  175. setTimeout(function(){
  176. // var notifyRes = JSON.parse(cc.sys.localStorage.getItem('notify'));
  177. // var gundongNode = cc.find("Canvas/gundong");
  178. // if(notifyRes != null){
  179. // if(gundongNode){
  180. // gundongNode.active = true;
  181. // }
  182. // self.Gundong.string = notifyRes;
  183. // }else{
  184. // if(gundongNode){
  185. // gundongNode.active = false;
  186. // }
  187. // }
  188. var text = self.Gundong1;
  189. var height = self.GundongMask1.node.height;
  190. text.node.runAction(cc.repeatForever(cc.sequence(
  191. cc.moveTo(1,cc.v2(text.node.x,text.node.y+57)),
  192. cc.callFunc(function(){
  193. if (text.node.height == Math.abs(text.node.y)+17) {
  194. text.node.y = 17;
  195. }
  196. }))));
  197. },300);
  198. },
  199. start()
  200. {
  201. // this.preloadManager = new PreloadManager();
  202. // this.audioControlManager = new AudioControlManager();
  203. // //加载动画和预制体
  204. // this.preloadManager.run();
  205. // //加载音频
  206. // this.audioControlManager.run();
  207. // var self = this;
  208. // cc.director.preloadScene("hall", function(){
  209. // console.log("preload scene battle");
  210. // self.onLoaded();
  211. // })
  212. },
  213. onResourcesLoaded()
  214. {
  215. this.loginBtnNode.active = true
  216. this.loadproNode.active = false
  217. },
  218. update(dt)
  219. {
  220. this.dtNum += dt
  221. if (this.dtNum >=2) {
  222. var text = this.Gundong1;
  223. // var height = this.GundongMask1.node.height;
  224. text.node.runAction(cc.sequence(
  225. cc.moveTo(1,cc.v2(text.node.x,text.node.y+50)),
  226. cc.callFunc(function(){
  227. if (text.node.height <= Math.abs(text.node.y)+13) {
  228. text.node.y = 13;
  229. }
  230. })));
  231. this.dtNum =0
  232. }
  233. // console.log("time is:",dt)
  234. // if (this.progressBar.progress < this.progressBarTarget)
  235. // {
  236. // this.progressBar.progress += dt*this.scale
  237. // }
  238. // if (this.progressBarTarget >= 1 && this.bloaded && this.loginLogic.needShowAuth == false) {
  239. // this.onResourcesLoaded();
  240. // } else if (this.progressBarTarget >= 5 / 6 && this.bloaded && this.loginLogic.needShowAuth == false) {
  241. // this.onResourcesLoaded();
  242. // }
  243. },
  244. clickWXLogin(sender)
  245. {
  246. //weixin login
  247. // this.loginLogic.login()
  248. },
  249. clickYKLogin(sender){
  250. //youke login
  251. cc.director.loadScene('hall');
  252. },
  253. clickZHLogin(sender){
  254. //zhang hao login
  255. sender.target.active = false
  256. this.ykLogin.node.active = false
  257. this.loginBannerNode.active = true
  258. this.ljLogin.node.active = true
  259. this.yk2Login.node.active = true
  260. },
  261. clickRegBtn(sender){
  262. this.regAndreadNode.active = true
  263. this.regNode.active = true
  264. },
  265. clickReadYsBtn(sender){
  266. this.regNode.active = false
  267. this.readNode.active = true
  268. },
  269. clickCloseReg(sender){
  270. if (this.regNode.active) {
  271. this.regAndreadNode.active = false
  272. }else{
  273. this.regNode.active = true
  274. this.readNode.active = false
  275. }
  276. },
  277. clickHall(sender,customEventData){
  278. this.showingHall = this.myhallMap.get(customEventData)
  279. this.showingHall.parentScene = this
  280. this.showingHall.initScene(customEventData)
  281. this.setHalllist(customEventData)
  282. this.display()
  283. },
  284. clickHallList(sender,customEventData){
  285. var nextScene = this.myhallMap.get(Number(customEventData))
  286. nextScene.initScene(Number(customEventData))
  287. nextScene.parentScene = this
  288. this.setHalllist(Number(customEventData))
  289. if (nextScene) {
  290. this.showingHall.playEnd(nextScene)
  291. }
  292. },
  293. display(){
  294. if (this.showingHall.SceneLevel == 1) {
  295. this.setHalllistBtnDisplay(true)
  296. }
  297. var animation = this.hallsBtns.getComponent(cc.Animation);
  298. var hallsGoFinished = function(){
  299. this.showingHall.playShow(this.setShowingHall)
  300. this.hallsBtns._parent._parent.active = false
  301. };
  302. animation.on('finished', hallsGoFinished, this);
  303. animation.play('hallsgo');
  304. this.animation.play('nrgo')
  305. },
  306. clickReturnBtn(){
  307. if (this.showingHall) {
  308. this.showingHall.playEnd()
  309. }
  310. },
  311. playShow(param)
  312. {
  313. this.setHalllistBtnDisplay(false)
  314. this.hallsBtns._parent._parent.active = true
  315. this.animation = this.nvren.getComponent(cc.Animation);
  316. this.hallsBtns.getComponent(cc.Animation).off("finished")
  317. this.hallsBtns.y = 0
  318. this.hallsBtns.x = 0
  319. // this.nvren.x = -180
  320. this.hallsBtns.getComponent(cc.Animation).play('hallscome');
  321. this.animation.on('finished', this.onGuideFinished, this);
  322. this.animation.play('nrcome1');
  323. },
  324. setShowingHall(Hall){
  325. this.showingHall = Hall
  326. this.returnNode.active =Hall!=this
  327. this.shareNode.active =Hall==this
  328. if (this.halllist.moved) {
  329. this.setHalllistDisplay(!this.halllist.moved)
  330. }
  331. this.setHalllistBtnDisplay(this.showingHall.SceneLevel ==1 && !this.halllist.moved)
  332. },
  333. setHalllistBtnDisplay(display){
  334. this.hallListBtn.active = display
  335. },
  336. onClickedHallListBtn(){
  337. this.hallListBtn.active = this.halllist.moved
  338. this.setHalllistDisplay(!this.halllist.moved)
  339. },
  340. setHalllistDisplay(display)
  341. {
  342. if (this.halllist.moved!=display) {
  343. var actionTo1 = display?cc.moveBy(0.3, cc.v2(367, 0)):cc.moveBy(0.3, cc.v2(-367, 0));
  344. this.halllist.runAction(actionTo1)
  345. this.halllist.moved = display
  346. }
  347. },
  348. setHalllist(num){
  349. this.listLayoutNode.children.forEach(element => {
  350. element.getChildByName('select').active = false
  351. element.getChildByName('normal').active = true
  352. });
  353. if (num) {
  354. this.listView.scrollToOffset(cc.v2(0, num<=3?0:(num-1)*70), 1)
  355. this.listLayoutNode.getChildByName('tiem'+num).getChildByName('select').active = true
  356. this.listLayoutNode.getChildByName('tiem'+num).getChildByName('normal').active = false
  357. }
  358. },
  359. showTips(sender,mode){
  360. var tipsLayer = ViewManager.PushView('tips')
  361. tipsLayer.getComponent('TipsLayerController').setTipsMode(sender,mode)
  362. },
  363. shopShow(render,cmd){
  364. var display = cmd==1?true:false
  365. this.shopNode.active = display
  366. this.node.getChildByName('top').getChildByName('shopreturnBtn').active = display
  367. this.node.getChildByName('top').getChildByName('shoptiitle').active = display
  368. this.node.getChildByName('content').active = !display
  369. this.node.getChildByName('bottom').active = !display
  370. this.node.getChildByName('top').getChildByName('topBanner').active = !display
  371. this.node.getChildByName('top').getChildByName('notice2').active = !display
  372. }
  373. });