GamesHallController.js 14 KB

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