GamesHallController.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. }
  116. },
  117. onGuideFinished(){
  118. console.log("onGuideFinished--------------------")
  119. this.animation.play('nrcome')
  120. },
  121. initListener()
  122. {
  123. // this.onBehaviorEvent('LoginBehavior',Event.COM_MSG.PRELOAD_DONE,this.onLoaded.bind(this));
  124. // this.onBehaviorEvent('LoginBehavior',Event.SOCKET_MSG.OPEN, this.onSocketOpen.bind(this));
  125. },
  126. onSocketOpen(sender,result)
  127. {
  128. this.bloaded = true
  129. },
  130. onLoaded(sender, result)
  131. {
  132. this.preloadCount++;
  133. this.progressBarTarget = this.preloadCount / this.preloadTotal;
  134. console.log("this.preloadCount:"+this.preloadCount+"this.progressBarTarget:"+this.progressBarTarget+"")
  135. if (this.progressBarTarget >= 1 && this.bloaded)
  136. {
  137. this.onResourcesLoaded();
  138. }
  139. },
  140. gundongText:function(){
  141. var self = this;
  142. setTimeout(function(){
  143. // var notifyRes = JSON.parse(cc.sys.localStorage.getItem('notify'));
  144. // var gundongNode = cc.find("Canvas/gundong");
  145. // if(notifyRes != null){
  146. // if(gundongNode){
  147. // gundongNode.active = true;
  148. // }
  149. // self.Gundong.string = notifyRes;
  150. // }else{
  151. // if(gundongNode){
  152. // gundongNode.active = false;
  153. // }
  154. // }
  155. var text = self.Gundong;
  156. var width = self.GundongMask.node.width;
  157. text.node.runAction(cc.repeatForever(cc.sequence(
  158. cc.moveTo(text.node.width/width*10,cc.v2(-text.node.width-width/5,text.node.y)),
  159. cc.callFunc(function(){
  160. text.node.x = width;
  161. }))));
  162. },300);
  163. },
  164. gundongText2:function(){
  165. var self = this;
  166. setTimeout(function(){
  167. // var notifyRes = JSON.parse(cc.sys.localStorage.getItem('notify'));
  168. // var gundongNode = cc.find("Canvas/gundong");
  169. // if(notifyRes != null){
  170. // if(gundongNode){
  171. // gundongNode.active = true;
  172. // }
  173. // self.Gundong.string = notifyRes;
  174. // }else{
  175. // if(gundongNode){
  176. // gundongNode.active = false;
  177. // }
  178. // }
  179. var text = self.Gundong1;
  180. var height = self.GundongMask1.node.height;
  181. text.node.runAction(cc.repeatForever(cc.sequence(
  182. cc.moveTo(1,cc.v2(text.node.x,text.node.y+57)),
  183. cc.callFunc(function(){
  184. if (text.node.height == Math.abs(text.node.y)+17) {
  185. text.node.y = 17;
  186. }
  187. }))));
  188. },300);
  189. },
  190. start()
  191. {
  192. // this.preloadManager = new PreloadManager();
  193. // this.audioControlManager = new AudioControlManager();
  194. // //加载动画和预制体
  195. // this.preloadManager.run();
  196. // //加载音频
  197. // this.audioControlManager.run();
  198. // var self = this;
  199. // cc.director.preloadScene("hall", function(){
  200. // console.log("preload scene battle");
  201. // self.onLoaded();
  202. // })
  203. },
  204. onResourcesLoaded()
  205. {
  206. this.loginBtnNode.active = true
  207. this.loadproNode.active = false
  208. },
  209. update(dt)
  210. {
  211. this.dtNum += dt
  212. if (this.dtNum >=2) {
  213. var text = this.Gundong1;
  214. // var height = this.GundongMask1.node.height;
  215. text.node.runAction(cc.sequence(
  216. cc.moveTo(1,cc.v2(text.node.x,text.node.y+50)),
  217. cc.callFunc(function(){
  218. if (text.node.height <= Math.abs(text.node.y)+13) {
  219. text.node.y = 13;
  220. }
  221. })));
  222. this.dtNum =0
  223. }
  224. // console.log("time is:",dt)
  225. // if (this.progressBar.progress < this.progressBarTarget)
  226. // {
  227. // this.progressBar.progress += dt*this.scale
  228. // }
  229. // if (this.progressBarTarget >= 1 && this.bloaded && this.loginLogic.needShowAuth == false) {
  230. // this.onResourcesLoaded();
  231. // } else if (this.progressBarTarget >= 5 / 6 && this.bloaded && this.loginLogic.needShowAuth == false) {
  232. // this.onResourcesLoaded();
  233. // }
  234. },
  235. clickWXLogin(sender)
  236. {
  237. //weixin login
  238. // this.loginLogic.login()
  239. },
  240. clickYKLogin(sender){
  241. //youke login
  242. cc.director.loadScene('hall');
  243. },
  244. clickZHLogin(sender){
  245. //zhang hao login
  246. sender.target.active = false
  247. this.ykLogin.node.active = false
  248. this.loginBannerNode.active = true
  249. this.ljLogin.node.active = true
  250. this.yk2Login.node.active = true
  251. },
  252. clickRegBtn(sender){
  253. this.regAndreadNode.active = true
  254. this.regNode.active = true
  255. },
  256. clickReadYsBtn(sender){
  257. this.regNode.active = false
  258. this.readNode.active = true
  259. },
  260. clickCloseReg(sender){
  261. if (this.regNode.active) {
  262. this.regAndreadNode.active = false
  263. }else{
  264. this.regNode.active = true
  265. this.readNode.active = false
  266. }
  267. },
  268. clickHall(sender,customEventData){
  269. this.showingHall = this.myhallMap.get(customEventData)
  270. this.showingHall.parentScene = this
  271. this.showingHall.initScene(customEventData)
  272. this.setHalllist(customEventData)
  273. this.display()
  274. },
  275. clickHallList(sender,customEventData){
  276. var nextScene = this.myhallMap.get(Number(customEventData))
  277. nextScene.initScene(Number(customEventData))
  278. nextScene.parentScene = this
  279. this.setHalllist(Number(customEventData))
  280. if (nextScene) {
  281. this.showingHall.playEnd(nextScene)
  282. }
  283. },
  284. display(){
  285. if (this.showingHall.SceneLevel == 1) {
  286. this.setHalllistBtnDisplay(true)
  287. }
  288. var animation = this.hallsBtns.getComponent(cc.Animation);
  289. var hallsGoFinished = function(){
  290. this.showingHall.playShow(this.setShowingHall)
  291. this.hallsBtns._parent._parent.active = false
  292. };
  293. animation.on('finished', hallsGoFinished, this);
  294. animation.play('hallsgo');
  295. this.animation.play('nrgo')
  296. },
  297. clickReturnBtn(){
  298. if (this.showingHall) {
  299. this.showingHall.playEnd()
  300. }
  301. },
  302. playShow(param)
  303. {
  304. this.setHalllistBtnDisplay(false)
  305. this.hallsBtns._parent._parent.active = true
  306. this.animation = this.nvren.getComponent(cc.Animation);
  307. this.hallsBtns.getComponent(cc.Animation).off("finished")
  308. this.hallsBtns.y = 0
  309. this.hallsBtns.x = 0
  310. // this.nvren.x = -180
  311. this.hallsBtns.getComponent(cc.Animation).play('hallscome');
  312. this.animation.on('finished', this.onGuideFinished, this);
  313. this.animation.play('nrcome1');
  314. },
  315. setShowingHall(Hall){
  316. this.showingHall = Hall
  317. this.returnNode.active =Hall!=this
  318. this.shareNode.active =Hall==this
  319. if (this.halllist.moved) {
  320. this.setHalllistDisplay(!this.halllist.moved)
  321. }
  322. this.setHalllistBtnDisplay(this.showingHall.SceneLevel ==1 && !this.halllist.moved)
  323. },
  324. setHalllistBtnDisplay(display){
  325. this.hallListBtn.active = display
  326. },
  327. onClickedHallListBtn(){
  328. this.hallListBtn.active = this.halllist.moved
  329. this.setHalllistDisplay(!this.halllist.moved)
  330. },
  331. setHalllistDisplay(display)
  332. {
  333. if (this.halllist.moved!=display) {
  334. var actionTo1 = display?cc.moveBy(0.3, cc.v2(367, 0)):cc.moveBy(0.3, cc.v2(-367, 0));
  335. this.halllist.runAction(actionTo1)
  336. this.halllist.moved = display
  337. }
  338. },
  339. setHalllist(num){
  340. this.listLayoutNode.children.forEach(element => {
  341. element.getChildByName('select').active = false
  342. element.getChildByName('normal').active = true
  343. });
  344. if (num) {
  345. this.listView.scrollToOffset(cc.v2(0, num<=3?0:(num-1)*70), 1)
  346. this.listLayoutNode.getChildByName('tiem'+num).getChildByName('select').active = true
  347. this.listLayoutNode.getChildByName('tiem'+num).getChildByName('normal').active = false
  348. }
  349. },
  350. showTips(sender,mode){
  351. var tipsLayer = ViewManager.PushView('tips')
  352. tipsLayer.getComponent('TipsLayerController').setTipsMode(sender,mode)
  353. },
  354. shopShow(render,cmd){
  355. var display = cmd==1?true:false
  356. this.shopNode.active = display
  357. this.node.getChildByName('top').getChildByName('shopreturnBtn').active = display
  358. this.node.getChildByName('top').getChildByName('shoptiitle').active = display
  359. this.node.getChildByName('content').active = !display
  360. this.node.getChildByName('bottom').active = !display
  361. this.node.getChildByName('top').getChildByName('topBanner').active = !display
  362. this.node.getChildByName('top').getChildByName('notice2').active = !display
  363. }
  364. });