homepage.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. import { _decorator, Component, Director, director, Enum, instantiate, Label, Node, Prefab, resources, SpriteFrame, tween, UITransform, Vec3 } from 'cc';
  2. import { config } from '../config';
  3. import { gameManager } from '../gameManager';
  4. import { play_list_item } from './play_list_item';
  5. import { server_play_list_data_item } from '../data/server_play_list_data';
  6. import { tools } from '../tools';
  7. import { ClientEvent } from '../framework/clientEvent';
  8. import { http } from '../http/http';
  9. import { view_game_play_shuang_tu_zhao_bu_tong } from '../play_list/zhaocha_up_down/view_game_play_shuang_tu_zhao_bu_tong';
  10. import { view_game_play_han_zi_zhao_bu_tong } from '../play_list/zhaocha_font/view_game_play_han_zi_zhao_bu_tong';
  11. import { view_game_play_mei_nv_zhao_xi_jie } from '../play_list/zhaocha_component/view_game_play_mei_nv_zhao_xi_jie';
  12. import { AudioManager } from '../framework/audioManager';
  13. import { SdkUtil } from '../framework/sdkUtil';
  14. import { win } from '../dialog/win';
  15. import { addCoinAni } from '../addCoinAni';
  16. import { Util } from '../framework/util';
  17. import { PoolManager } from '../framework/poolManager';
  18. import { game_play_dou_di_zhu } from '../play_list/ddz/game_play_dou_di_zhu';
  19. import { view_game_play_shuang_tu_zhao_xiang_tong } from '../play_list/zhaocha_xiang_tong/view_game_play_shuang_tu_zhao_xiang_tong';
  20. import { view_game_play_ji_yi_li } from '../play_list/ji_yi_li/view_game_play_ji_yi_li';
  21. import { view_game_play_zhao_bu_tong } from '../play_list/zhao_bu_tong/view_game_play_zhao_bu_tong';
  22. const { ccclass, property } = _decorator;
  23. export enum ETest {
  24. None = 0,
  25. ONe = 1,
  26. Two = 2
  27. }
  28. @ccclass('homepage')
  29. export class homepage extends Component {
  30. @property(Node) content:Node = null;
  31. @property(SpriteFrame) sfList:SpriteFrame[]=[];
  32. @property(Node) btn_setting:Node = null;
  33. @property(Node) btn_coin:Node = null;
  34. @property(Node) btn_look_video:Node = null;
  35. @property(Node) lab_coin:Node;
  36. @property(Prefab) addCoinAni:Prefab = null;
  37. @property(Node) top_node:Node = null;
  38. @property(Node) action_node:Node = null;
  39. @property(Prefab) item_prefab;
  40. protected coin_ani:Node;
  41. protected old_coin_number:number = 0;
  42. protected start(): void {
  43. this.btn_setting.on(Node.EventType.TOUCH_START,()=>{
  44. gameManager.playBtnSound()
  45. gameManager.addTopView(config.PREFAB_PATH.setting,()=>{});
  46. },this)
  47. this.btn_look_video.on(Node.EventType.TOUCH_START,()=>{
  48. SdkUtil.showVideoAd(config.rewardVideoAdUnitId.Earn_coins_AdUnitId,(res)=>{
  49. if(res.isEnded){
  50. this.showLookVideoReward();
  51. }
  52. })
  53. })
  54. if(!PoolManager.instance.isHavePool(config.POOL_KEY)){
  55. PoolManager.instance.preloadPoolByName(config.POOL_KEY,11*15,this.item_prefab)
  56. }
  57. ClientEvent.on(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER,this.onChangeCoinNumber.bind(this),this);
  58. ClientEvent.on(config.EVENT_MSG.ON_INIT_GAME_LIST,this.initPlayList.bind(this),this);
  59. ClientEvent.on(config.EVENT_MSG.ON_BACK_HOME_VIEW,this.onBackHomeView.bind(this),this);
  60. ClientEvent.on(config.EVENT_MSG.ON_UPDATE_HOME_VIEW,this.onUpdateHomeView.bind(this),this);
  61. ClientEvent.on(config.EVENT_MSG.ON_SHOW_REWARD_VIEW,this.onShowRewardView.bind(this),this);
  62. }
  63. onShowRewardView(){
  64. this.showLookVideoReward()
  65. }
  66. onUpdateHomeView(){
  67. let self = this;
  68. for (let index = 0; index < self.content.children.length; index++) {
  69. self.content.children[index].getComponent(play_list_item).updateView();
  70. }
  71. this.old_coin_number = gameManager.get_user_coin();
  72. this.lab_coin.getComponent(Label).string = Util.coinNumberToK(this.old_coin_number);
  73. gameManager.playMainMusic(true);
  74. }
  75. onBackHomeView(){
  76. let self = this;
  77. for (let index = 0; index < self.content.children.length; index++) {
  78. self.content.children[index].getComponent(play_list_item).updateView();
  79. self.content.children[index].getComponent(play_list_item).play(index*0.2,index)
  80. }
  81. this.old_coin_number = gameManager.get_user_coin();
  82. this.lab_coin.getComponent(Label).string = Util.coinNumberToK(this.old_coin_number);
  83. gameManager.playMainMusic(true);
  84. }
  85. onChangeCoinNumber(){
  86. let self = this;
  87. let num:number = this.old_coin_number;
  88. let obj = new Component
  89. gameManager.instance.addCoinNumber( obj,gameManager.get_user_coin() - num ,self.lab_coin.getComponent(Label),num,()=>{
  90. this.old_coin_number = gameManager.get_user_coin();
  91. this.lab_coin.getComponent(Label).string = Util.coinNumberToK(this.old_coin_number);
  92. })
  93. }
  94. showCoinAni(){
  95. if( this.coin_ani!=null){
  96. this.coin_ani.removeFromParent()
  97. this.coin_ani = null;
  98. }
  99. if(this.addCoinAni!=null){
  100. this.coin_ani = instantiate(this.addCoinAni)
  101. this.coin_ani.parent = this.action_node;
  102. this.coin_ani.position = new Vec3(200,400,0)
  103. this.coin_ani.getComponent(addCoinAni).play(()=>{
  104. let end_pos = this.top_node.getComponent(UITransform).convertToWorldSpaceAR(this.btn_coin.position)
  105. tween(this.coin_ani).to(0.2, {position: end_pos}).hide().start()
  106. })
  107. }
  108. }
  109. showLookVideoReward(){
  110. let self = this;
  111. gameManager.addTopView(config.PREFAB_PATH.win,(node:Node)=>{
  112. let reward = gameManager.get_reward_number();
  113. node.getComponent(win).showVideoAddCoinView(reward,null,(win_view:win)=>{
  114. gameManager.add_coin(reward)
  115. setTimeout(()=>{
  116. ClientEvent.dispatchEvent(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER)
  117. },500)
  118. self.showCoinAni()
  119. win_view.close()
  120. },(win_view:win)=>{
  121. SdkUtil.showVideoAd(config.rewardVideoAdUnitId.Earn_coins_AdUnitId,(res)=>{
  122. if(res.isEnded){
  123. tween(self.btn_setting).delay(0.5).call(()=>{
  124. reward = gameManager.get_deouble_reward_number();
  125. gameManager.add_coin(reward)
  126. win_view.showDoubleCoin(reward,()=>{
  127. self.showCoinAni()
  128. win_view.close()
  129. ClientEvent.dispatchEvent(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER)
  130. })
  131. }).start()
  132. }
  133. })
  134. });
  135. });
  136. }
  137. protected onDestroy(): void {
  138. ClientEvent.off(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER,this.onChangeCoinNumber.bind(this),this);
  139. ClientEvent.off(config.EVENT_MSG.ON_INIT_GAME_LIST,this.initPlayList.bind(this),this);
  140. ClientEvent.off(config.EVENT_MSG.ON_BACK_HOME_VIEW,this.onBackHomeView.bind(this),this);
  141. }
  142. initPlayList(){
  143. let self = this;
  144. this.content.removeAllChildren();
  145. let call_back = (prefab)=>{
  146. let list = gameManager.g_server_play_list_data.list;
  147. for (let index = 0; index < list.length; index++) {
  148. // if(list[index].id<=3){
  149. console.log("list[index]",list[index])
  150. let newNode:Node = instantiate(prefab);
  151. newNode.parent = self.content;
  152. newNode.getComponent(play_list_item).initView(list[index],self.sfList[index],this.onItemClick.bind(this));
  153. // }
  154. }
  155. }
  156. resources.load(config.PREFAB_PATH.play_list_item, Prefab, (err, prefab) => {
  157. if(err){
  158. console.log("err::",err);
  159. return;
  160. }
  161. call_back(prefab);
  162. });
  163. }
  164. hideAllItem(){
  165. let self = this;
  166. for (let index = 0; index < self.content.children.length; index++) {
  167. self.content.children[index].getComponent(play_list_item).hide();
  168. }
  169. }
  170. onItemClick(data:server_play_list_data_item){
  171. console.log("data",data)
  172. gameManager.playBtnSound()
  173. this.hideAllItem()
  174. switch(data.id){
  175. case config.PLAY_TYPE.YI_QI_ZHAO_CHA:
  176. {
  177. let categoryid = config.PLAY_TYPE.YI_QI_ZHAO_CHA;
  178. let levels_item = gameManager.get_cur_level_by_categoryid(categoryid);
  179. // gameManager.showLoading();
  180. http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{
  181. if(!err){
  182. let _data = JSON.parse(data)
  183. if(_data.code===config.MSG_CODE.SUCCESS){
  184. gameManager.addUiView(config.PREFAB_PATH.game_play_shuang_tu_zhao_bu_tong,(node:Node)=>{
  185. node.getComponent(view_game_play_shuang_tu_zhao_bu_tong).initView(_data.content);
  186. })
  187. }
  188. }
  189. })
  190. break;
  191. }
  192. case config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG:
  193. {
  194. let categoryid = config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG;
  195. let levels_item = gameManager.get_cur_level_by_categoryid(categoryid);
  196. // gameManager.showLoading();
  197. http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{
  198. if(!err){
  199. let _data = JSON.parse(data)
  200. if(_data.code===config.MSG_CODE.SUCCESS){
  201. if(gameManager.uiViewList.get(config.PREFAB_PATH.game_play_han_zi_zhao_bu_tong)){
  202. gameManager.uiViewList.get(config.PREFAB_PATH.game_play_han_zi_zhao_bu_tong).getComponent(view_game_play_han_zi_zhao_bu_tong).initView(_data.content);
  203. }else{
  204. gameManager.addUiView(config.PREFAB_PATH.game_play_han_zi_zhao_bu_tong,(node)=>{
  205. node.getComponent(view_game_play_han_zi_zhao_bu_tong).initView(_data.content);
  206. })
  207. }
  208. }
  209. }
  210. })
  211. break;
  212. }
  213. case config.PLAY_TYPE.MEI_NV_ZHAO_XI_JIE:
  214. {
  215. let categoryid = config.PLAY_TYPE.MEI_NV_ZHAO_XI_JIE;
  216. let levels_item = gameManager.get_cur_level_by_categoryid(categoryid);
  217. // gameManager.showLoading();
  218. http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{
  219. if(!err){
  220. let _data = JSON.parse(data)
  221. if(_data.code===config.MSG_CODE.SUCCESS){
  222. gameManager.addUiView(config.PREFAB_PATH.game_play_mei_nv_zhao_xi_jie,(node)=>{
  223. node.getComponent(view_game_play_mei_nv_zhao_xi_jie).initView(_data.content);
  224. })
  225. }
  226. }
  227. })
  228. break;
  229. }
  230. case config.PLAY_TYPE.ZHAO_XIANG_TONG:
  231. {
  232. let categoryid = config.PLAY_TYPE.ZHAO_XIANG_TONG;
  233. let levels_item = gameManager.get_cur_level_by_categoryid(categoryid);
  234. // gameManager.showLoading();
  235. http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{
  236. if(!err){
  237. let _data = JSON.parse(data)
  238. if(_data.code===config.MSG_CODE.SUCCESS){
  239. gameManager.addUiView(config.PREFAB_PATH.game_play_shuang_tu_zhao_xiang_tong,(node:Node)=>{
  240. node.getComponent(view_game_play_shuang_tu_zhao_xiang_tong).initView(_data.content);
  241. })
  242. }
  243. }
  244. })
  245. break;
  246. }
  247. case config.PLAY_TYPE.ZHAO_BU_TONG:
  248. {
  249. let categoryid = config.PLAY_TYPE.ZHAO_BU_TONG;
  250. let levels_item = gameManager.get_cur_level_by_categoryid(categoryid);
  251. // gameManager.showLoading();
  252. http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{
  253. if(!err){
  254. let _data = JSON.parse(data)
  255. if(_data.code===config.MSG_CODE.SUCCESS){
  256. gameManager.addUiView(config.PREFAB_PATH.game_play_zhao_bu_tong,(node:Node)=>{
  257. node.getComponent(view_game_play_zhao_bu_tong).initView(_data.content);
  258. })
  259. }
  260. }
  261. })
  262. break;
  263. }
  264. case config.PLAY_TYPE.DOU_DI_ZHU:
  265. {
  266. let categoryid = config.PLAY_TYPE.DOU_DI_ZHU;
  267. let levels_item = gameManager.get_cur_level_by_categoryid(categoryid);
  268. // gameManager.showLoading();
  269. console.log("斗地主")
  270. http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{
  271. if(!err){
  272. let _data = JSON.parse(data)
  273. if(_data.code===config.MSG_CODE.SUCCESS){
  274. gameManager.addUiView(config.PREFAB_PATH.game_play_dou_di_zhu,(node:Node)=>{
  275. node.getComponent(game_play_dou_di_zhu).initView(_data.content);
  276. })
  277. }
  278. }
  279. })
  280. break;
  281. }
  282. case config.PLAY_TYPE.JI_YI_LI:
  283. {
  284. let categoryid = config.PLAY_TYPE.JI_YI_LI;
  285. let levels_item = gameManager.get_cur_level_by_categoryid(categoryid);
  286. // gameManager.showLoading();
  287. http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{
  288. if(!err){
  289. let _data = JSON.parse(data)
  290. if(_data.code===config.MSG_CODE.SUCCESS){
  291. gameManager.addUiView(config.PREFAB_PATH.game_play_ji_yi_li,(node:Node)=>{
  292. node.getComponent(view_game_play_ji_yi_li).initView(_data.content);
  293. })
  294. }
  295. }
  296. })
  297. break;
  298. }
  299. }
  300. }
  301. }