import { _decorator, Component, Director, director, Enum, Game, game, instantiate, Label, log, Node, Prefab, resources, SpriteFrame, sys, tween, UITransform, Vec2, Vec3 } from 'cc'; import { config } from '../config'; import { gameManager } from '../gameManager'; import { play_list_item } from './play_list_item'; import { server_play_list_data_item, statistics_collect_rewardVideo_data_item } from '../data/server_play_list_data'; import { tools } from '../tools'; import { ClientEvent } from '../framework/clientEvent'; import { http } from '../http/http'; import { view_game_play_shuang_tu_zhao_bu_tong } from '../play_list/zhaocha_up_down/view_game_play_shuang_tu_zhao_bu_tong'; import { view_game_play_han_zi_zhao_bu_tong } from '../play_list/zhaocha_font/view_game_play_han_zi_zhao_bu_tong'; import { view_game_play_mei_nv_zhao_xi_jie } from '../play_list/zhaocha_component/view_game_play_mei_nv_zhao_xi_jie'; import { AudioManager } from '../framework/audioManager'; import { SdkUtil } from '../framework/sdkUtil'; import { win } from '../dialog/win'; import { addCoinAni } from '../addCoinAni'; import { Util } from '../framework/util'; import { PoolManager } from '../framework/poolManager'; import { game_play_dou_di_zhu } from '../play_list/ddz/game_play_dou_di_zhu'; import { view_game_play_shuang_tu_zhao_xiang_tong } from '../play_list/zhaocha_xiang_tong/view_game_play_shuang_tu_zhao_xiang_tong'; import { view_game_play_ji_yi_li } from '../play_list/ji_yi_li/view_game_play_ji_yi_li'; import { view_game_play_zhao_bu_tong } from '../play_list/zhao_bu_tong/view_game_play_zhao_bu_tong'; import { StatisticsManager } from '../framework/statisticsManager'; import { reward_box_page } from './reward_box_page'; import { reward_box } from './reward_box'; const { ccclass, property } = _decorator; export enum ETest { None = 0, ONe = 1, Two = 2 } @ccclass('homepage') export class homepage extends Component { @property(Node) content:Node = null; @property(SpriteFrame) sfList:SpriteFrame[]=[]; @property(Node) btn_setting:Node = null; @property(Node) btn_coin:Node = null; @property(Node) btn_look_video:Node = null; @property(Node) lab_coin:Node; @property(Prefab) addCoinAni:Prefab = null; @property(Node) top_node:Node = null; @property(Node) action_node:Node = null; @property(Prefab) item_prefab; @property(Node) reward_box:Node = null; protected coin_ani:Node; protected old_coin_number:number = 0; private sp_map:Map = new Map(); protected onLoad(): void { SdkUtil.ttRegisterSidebar() } protected start(): void { this.sp_map.set(config.PLAY_TYPE.YI_QI_ZHAO_CHA,this.sfList[0]) this.sp_map.set(config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG,this.sfList[1]) this.sp_map.set(config.PLAY_TYPE.MEI_NV_ZHAO_XI_JIE,this.sfList[2]) this.sp_map.set(config.PLAY_TYPE.ZHAO_XIANG_TONG,this.sfList[3]) this.sp_map.set(config.PLAY_TYPE.ZHAO_BU_TONG,this.sfList[4]) this.sp_map.set(config.PLAY_TYPE.DOU_DI_ZHU,this.sfList[5]) this.sp_map.set(config.PLAY_TYPE.JI_YI_LI,this.sfList[6]) this.btn_setting.on(Node.EventType.TOUCH_START,()=>{ gameManager.playBtnSound() gameManager.addTopView(config.PREFAB_PATH.setting,()=>{}); },this) this.btn_look_video.on(Node.EventType.TOUCH_START,()=>{ SdkUtil.showVideoAd(config.rewardVideoAdUnitId.Earn_coins_AdUnitId,(res)=>{ if(res.isEnded){ this.showLookVideoReward(); } // 统计-激励视频广告 let collect_data = StatisticsManager.get_collect_data(0, 0, 0, config.STATISTICS_ACTION_TYPE.ZHUAN_JIN_BI) collect_data.ads_status = res.isEnded ? config.Watch_rewardVideo_status.SUCCESS : config.Watch_rewardVideo_status.FAIL StatisticsManager.request_collect_rewardVideoData(collect_data) }) }) if(!PoolManager.instance.isHavePool(config.POOL_KEY)){ PoolManager.instance.preloadPoolByName(config.POOL_KEY,11*15,this.item_prefab) } ClientEvent.on(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER,this.onChangeCoinNumber.bind(this),this); ClientEvent.on(config.EVENT_MSG.ON_INIT_GAME_LIST,this.initPlayList.bind(this),this); ClientEvent.on(config.EVENT_MSG.ON_BACK_HOME_VIEW,this.onBackHomeView.bind(this),this); ClientEvent.on(config.EVENT_MSG.ON_UPDATE_HOME_VIEW,this.onUpdateHomeView.bind(this),this); ClientEvent.on(config.EVENT_MSG.ON_SHOW_REWARD_VIEW,this.onShowRewardView.bind(this),this); ClientEvent.on(config.EVENT_MSG.ON_USER_LOGIN_SUCCESS,this.onUserLoginSuccess.bind(this),this); } onUserLoginSuccess() { if(SdkUtil.ttCheckSceneShowRewards()&&gameManager.get_user_is_sign()==false) { this.reward_box.active = true this.reward_box.getComponent(reward_box).playShake() let self = this this.reward_box.on(Node.EventType.TOUCH_END, ()=> { gameManager.addTopView(config.PREFAB_PATH.reward_box_page, (node:Node)=> { let coin_number = gameManager.get_sign_reward_number() let sign_status = gameManager.userSignStatus.status let is_toEnterFromSidebar = SdkUtil.ttCheckToEnterFromSidebar() node.getComponent(reward_box_page).showView(coin_number, sign_status, is_toEnterFromSidebar, (coin_number:number, reward_box_page:reward_box_page)=> { gameManager.add_coin(coin_number) setTimeout(()=>{ ClientEvent.dispatchEvent(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER) },500) self.showCoinAni() reward_box_page.close() this.reward_box.getComponent(reward_box).stopShake() this.reward_box.active = false }) }) }) } } onShowRewardView(){ this.showLookVideoReward() } onUpdateHomeView(){ let self = this; for (let index = 0; index < self.content.children.length; index++) { self.content.children[index].getComponent(play_list_item).updateView(); } this.old_coin_number = gameManager.get_user_coin(); this.lab_coin.getComponent(Label).string = Util.coinNumberToK(this.old_coin_number); gameManager.playMainMusic(true); } onBackHomeView(){ let self = this; for (let index = 0; index < self.content.children.length; index++) { self.content.children[index].getComponent(play_list_item).updateView(); self.content.children[index].getComponent(play_list_item).play(index*0.2,index) } this.old_coin_number = gameManager.get_user_coin(); this.lab_coin.getComponent(Label).string = Util.coinNumberToK(this.old_coin_number); gameManager.playMainMusic(true); } onChangeCoinNumber(){ let self = this; let num:number = this.old_coin_number; let obj = new Component gameManager.instance.addCoinNumber( obj,gameManager.get_user_coin() - num ,self.lab_coin.getComponent(Label),num,()=>{ this.old_coin_number = gameManager.get_user_coin(); this.lab_coin.getComponent(Label).string = Util.coinNumberToK(this.old_coin_number); }) for (let index = 0; index < self.content.children.length; index++) { self.content.children[index].getComponent(play_list_item).updateView(); } } showCoinAni(){ if( this.coin_ani!=null){ this.coin_ani.removeFromParent() this.coin_ani = null; } if(this.addCoinAni!=null){ this.coin_ani = instantiate(this.addCoinAni) this.coin_ani.parent = this.action_node; this.coin_ani.position = new Vec3(200,400,0) this.coin_ani.getComponent(addCoinAni).play(()=>{ let end_pos = this.top_node.getComponent(UITransform).convertToWorldSpaceAR(this.btn_coin.position) tween(this.coin_ani).to(0.2, {position: end_pos}).hide().start() }) } } showLookVideoReward(){ let self = this; gameManager.addTopView(config.PREFAB_PATH.win,(node:Node)=>{ let reward = gameManager.get_reward_number(); node.getComponent(win).showVideoAddCoinView(reward,null,(win_view:win)=>{ gameManager.add_coin(reward) setTimeout(()=>{ ClientEvent.dispatchEvent(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER) },500) self.showCoinAni() win_view.close() },(win_view:win)=>{ SdkUtil.showVideoAd(config.rewardVideoAdUnitId.Earn_coins_AdUnitId,(res)=>{ if(res.isEnded){ reward = gameManager.get_deouble_reward_number(); gameManager.add_coin(reward) tween(self.btn_setting).delay(0.5).call(()=>{ win_view.showDoubleCoin(reward,()=>{ self.showCoinAni() win_view.close() ClientEvent.dispatchEvent(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER) }) }).start() } // 统计-激励视频广告 let collect_data = StatisticsManager.get_collect_data(0, 0, 0, config.STATISTICS_ACTION_TYPE.CHAO_JI_JIA_BEI) collect_data.ads_status = res.isEnded ? config.Watch_rewardVideo_status.SUCCESS : config.Watch_rewardVideo_status.FAIL StatisticsManager.request_collect_rewardVideoData(collect_data) }) }); }); } protected onDestroy(): void { ClientEvent.off(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER,this.onChangeCoinNumber.bind(this),this); ClientEvent.off(config.EVENT_MSG.ON_INIT_GAME_LIST,this.initPlayList.bind(this),this); ClientEvent.off(config.EVENT_MSG.ON_BACK_HOME_VIEW,this.onBackHomeView.bind(this),this); } initPlayList(){ let self = this; this.content.removeAllChildren(); let call_back = (prefab)=>{ let list = gameManager.g_server_play_list_data.list; for (let index = 0; index < list.length; index++) { // if(list[index].id<=3){ let newNode:Node = instantiate(prefab); newNode.parent = self.content; newNode.getComponent(play_list_item).initView(list[index],this.sp_map.get(list[index].id),this.onItemClick.bind(this)); // } } } resources.load(config.PREFAB_PATH.play_list_item, Prefab, (err, prefab) => { if(err){ console.log("err::",err); return; } call_back(prefab); }); } hideAllItem(){ let self = this; for (let index = 0; index < self.content.children.length; index++) { self.content.children[index].getComponent(play_list_item).hide(); } } onItemClick(data:server_play_list_data_item){ gameManager.playBtnSound() this.hideAllItem() switch(data.id){ case config.PLAY_TYPE.YI_QI_ZHAO_CHA: { let categoryid = config.PLAY_TYPE.YI_QI_ZHAO_CHA; let levels_item = gameManager.get_cur_level_by_categoryid(categoryid); // gameManager.showLoading(); http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{ if(!err){ let _data = JSON.parse(data) if(_data.code===config.MSG_CODE.SUCCESS){ gameManager.addUiView(config.PREFAB_PATH.game_play_shuang_tu_zhao_bu_tong,(node:Node)=>{ node.getComponent(view_game_play_shuang_tu_zhao_bu_tong).initView(_data.content); }) } } }) break; } case config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG: { let categoryid = config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG; let levels_item = gameManager.get_cur_level_by_categoryid(categoryid); // gameManager.showLoading(); http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{ if(!err){ let _data = JSON.parse(data) if(_data.code===config.MSG_CODE.SUCCESS){ if(gameManager.uiViewList.get(config.PREFAB_PATH.game_play_han_zi_zhao_bu_tong)){ 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); }else{ gameManager.addUiView(config.PREFAB_PATH.game_play_han_zi_zhao_bu_tong,(node)=>{ node.getComponent(view_game_play_han_zi_zhao_bu_tong).initView(_data.content); }) } } } }) break; } case config.PLAY_TYPE.MEI_NV_ZHAO_XI_JIE: { let categoryid = config.PLAY_TYPE.MEI_NV_ZHAO_XI_JIE; let levels_item = gameManager.get_cur_level_by_categoryid(categoryid); // gameManager.showLoading(); http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{ if(!err){ let _data = JSON.parse(data) if(_data.code===config.MSG_CODE.SUCCESS){ gameManager.addUiView(config.PREFAB_PATH.game_play_mei_nv_zhao_xi_jie,(node)=>{ node.getComponent(view_game_play_mei_nv_zhao_xi_jie).initView(_data.content); }) } } }) break; } case config.PLAY_TYPE.ZHAO_XIANG_TONG: { let categoryid = config.PLAY_TYPE.ZHAO_XIANG_TONG; let levels_item = gameManager.get_cur_level_by_categoryid(categoryid); // gameManager.showLoading(); http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{ if(!err){ let _data = JSON.parse(data) if(_data.code===config.MSG_CODE.SUCCESS){ gameManager.addUiView(config.PREFAB_PATH.game_play_shuang_tu_zhao_xiang_tong,(node:Node)=>{ node.getComponent(view_game_play_shuang_tu_zhao_xiang_tong).initView(_data.content); }) } } }) break; } case config.PLAY_TYPE.ZHAO_BU_TONG: { let categoryid = config.PLAY_TYPE.ZHAO_BU_TONG; let levels_item = gameManager.get_cur_level_by_categoryid(categoryid); // gameManager.showLoading(); http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{ if(!err){ let _data = JSON.parse(data) if(_data.code===config.MSG_CODE.SUCCESS){ gameManager.addUiView(config.PREFAB_PATH.game_play_zhao_bu_tong,(node:Node)=>{ node.getComponent(view_game_play_zhao_bu_tong).initView(_data.content); }) } } }) break; } case config.PLAY_TYPE.DOU_DI_ZHU: { let categoryid = config.PLAY_TYPE.DOU_DI_ZHU; let levels_item = gameManager.get_cur_level_by_categoryid(categoryid); // gameManager.showLoading(); console.log("斗地主") http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{ if(!err){ let _data = JSON.parse(data) if(_data.code===config.MSG_CODE.SUCCESS){ gameManager.addUiView(config.PREFAB_PATH.game_play_dou_di_zhu,(node:Node)=>{ node.getComponent(game_play_dou_di_zhu).initView(_data.content); }) } } }) break; } case config.PLAY_TYPE.JI_YI_LI: { let categoryid = config.PLAY_TYPE.JI_YI_LI; let levels_item = gameManager.get_cur_level_by_categoryid(categoryid); const element = gameManager.get_play_list_item_by_categoryid(config.PLAY_TYPE.JI_YI_LI); if(element.barrier_number{},config.sync_data_type.LEVELS) } if(levels_item.level<=0){ levels_item.level = 1; gameManager.set_unlock_levels_data(levels_item) } http.get(config.static_url.levels_info(categoryid,levels_item.level),(err,data)=>{ if(!err){ let _data = JSON.parse(data) if(_data.code===config.MSG_CODE.SUCCESS){ gameManager.addUiView(config.PREFAB_PATH.game_play_ji_yi_li,(node:Node)=>{ node.getComponent(view_game_play_ji_yi_li).initView(_data.content); }) } } }) break; } } } }