GamesHallController.js 13 KB

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