|
@@ -1,7 +1,6 @@
|
|
|
-import { _decorator, Component, Director, director, Enum, Game, game, instantiate, Label, log, Node, Prefab, resources, SpriteFrame, sys, tween, UITransform, Vec2, Vec3, Animation } from 'cc';
|
|
|
+import { _decorator, Component, Director, director, Enum, Game, game, instantiate, Label, log, Node, Prefab, resources, SpriteFrame, sys, tween, UITransform, Vec2, Vec3, Animation, PageView, Layout } 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';
|
|
@@ -21,6 +20,7 @@ import { view_game_play_ji_yi_li } from '../play_list/ji_yi_li/view_game_play_ji
|
|
|
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 { play_page_list_item } from './play_page_list_item';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
export enum ETest {
|
|
|
None = 0,
|
|
@@ -30,7 +30,7 @@ export enum ETest {
|
|
|
@ccclass('homepage')
|
|
|
export class homepage extends Component {
|
|
|
@property(Node) content:Node = null;
|
|
|
- @property(SpriteFrame) sfList:SpriteFrame[]=[];
|
|
|
+ @property(SpriteFrame) sf_list:SpriteFrame[]=[];
|
|
|
@property(Node) btn_setting:Node = null;
|
|
|
@property(Node) btn_coin:Node = null;
|
|
|
@property(Node) btn_look_video:Node = null;
|
|
@@ -38,24 +38,30 @@ export class homepage extends Component {
|
|
|
@property(Prefab) addCoinAni:Prefab = null;
|
|
|
@property(Node) top_node:Node = null;
|
|
|
@property(Node) action_node:Node = null;
|
|
|
- @property(Prefab) item_prefab;
|
|
|
+ @property(Node) pageView:Node = null;
|
|
|
+ @property(Node) pageView_content_page1:Node = null;
|
|
|
+ @property(Node) pageView_content_page2:Node = null;
|
|
|
+ @property(Node) lab_page_count:Node = null;
|
|
|
+ @property(Prefab) item_prefab = null;
|
|
|
@property(Node) reward_box:Node = null;
|
|
|
protected coin_ani:Node;
|
|
|
protected old_coin_number:number = 0;
|
|
|
private sp_map:Map<number,SpriteFrame> = new Map();
|
|
|
+ private playItemList:Node[]=[];
|
|
|
|
|
|
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.sp_map.set(config.PLAY_TYPE.YI_QI_ZHAO_CHA,this.sf_list[0])
|
|
|
+ this.sp_map.set(config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG,this.sf_list[1])
|
|
|
+ this.sp_map.set(config.PLAY_TYPE.MEI_NV_ZHAO_XI_JIE,this.sf_list[2])
|
|
|
+ this.sp_map.set(config.PLAY_TYPE.ZHAO_XIANG_TONG,this.sf_list[3])
|
|
|
+ this.sp_map.set(config.PLAY_TYPE.ZHAO_BU_TONG,this.sf_list[4])
|
|
|
+ this.sp_map.set(config.PLAY_TYPE.DOU_DI_ZHU,this.sf_list[5])
|
|
|
+ this.sp_map.set(config.PLAY_TYPE.JI_YI_LI,this.sf_list[6])
|
|
|
+
|
|
|
this.btn_setting.on(Node.EventType.TOUCH_START,()=>{
|
|
|
gameManager.playBtnSound()
|
|
|
gameManager.addTopView(config.PREFAB_PATH.setting,()=>{});
|
|
@@ -108,20 +114,15 @@ export class homepage extends Component {
|
|
|
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.playPageListItemUpdateView()
|
|
|
+
|
|
|
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.playPageListItemUpdateView()
|
|
|
+
|
|
|
this.old_coin_number = gameManager.get_user_coin();
|
|
|
this.lab_coin.getComponent(Label).string = Util.coinNumberToK(this.old_coin_number);
|
|
|
gameManager.playMainMusic(true);
|
|
@@ -134,9 +135,8 @@ export class homepage extends Component {
|
|
|
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();
|
|
|
- }
|
|
|
+
|
|
|
+ this.playPageListItemUpdateView()
|
|
|
}
|
|
|
|
|
|
showCoinAni(){
|
|
@@ -194,20 +194,55 @@ export class homepage extends Component {
|
|
|
}
|
|
|
|
|
|
initPlayList(){
|
|
|
+ this.pageView_content_page1.removeAllChildren()
|
|
|
+ this.pageView_content_page2.removeAllChildren()
|
|
|
+
|
|
|
+ let list = gameManager.g_server_play_list_data.list;
|
|
|
+ let every_page_count: number = 6
|
|
|
+ let pageView_total_page_count:number = Math.ceil(list.length / every_page_count)
|
|
|
+ let number_string = '1' + ' / ' + pageView_total_page_count + ''
|
|
|
+ this.lab_page_count.getComponent(Label).string = number_string
|
|
|
+
|
|
|
let self = this;
|
|
|
- this.content.removeAllChildren();
|
|
|
+ this.pageView.on('page-turning', (event: PageView) => {
|
|
|
+ let currentPageIndex = event.getCurrentPageIndex()
|
|
|
+ let number_string = currentPageIndex+1 + ' / ' + pageView_total_page_count + ''
|
|
|
+ self.lab_page_count.getComponent(Label).string = number_string
|
|
|
+ })
|
|
|
+
|
|
|
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));
|
|
|
- // }
|
|
|
+ let prefabInstance = instantiate(prefab)
|
|
|
+ // 设置横向(左、中、右)间隙
|
|
|
+ let col_num = this.pageView_content_page1.getComponent(Layout).constraintNum
|
|
|
+ let paddingTop = 40
|
|
|
+ let spacingY = 30
|
|
|
+ let padding_x = (this.pageView_content_page1.getComponent(UITransform).width - col_num * prefabInstance.getComponent(UITransform).width) / (col_num+1)
|
|
|
+ // console.log(padding_x)
|
|
|
+ let content_page1_layout = this.pageView_content_page1.getComponent(Layout)
|
|
|
+ content_page1_layout.paddingLeft = padding_x
|
|
|
+ content_page1_layout.spacingX = padding_x
|
|
|
+ content_page1_layout.paddingTop = paddingTop
|
|
|
+ content_page1_layout.spacingY = spacingY
|
|
|
+
|
|
|
+ let content_page2_layout = this.pageView_content_page2.getComponent(Layout)
|
|
|
+ content_page2_layout.paddingLeft = padding_x
|
|
|
+ content_page2_layout.spacingX = padding_x
|
|
|
+ content_page2_layout.paddingTop = paddingTop
|
|
|
+ content_page2_layout.spacingY = spacingY
|
|
|
+
|
|
|
+ for (var index = 0; index < list.length; index++) {
|
|
|
+ let newNode: Node = instantiate(prefab)
|
|
|
+ if (index < every_page_count) {
|
|
|
+ newNode.parent = self.pageView_content_page1
|
|
|
+ } else {
|
|
|
+ newNode.parent = self.pageView_content_page2
|
|
|
+ }
|
|
|
+ self.playItemList.push(newNode)
|
|
|
+ newNode.getComponent(play_page_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) => {
|
|
|
+ }
|
|
|
+ resources.load(config.PREFAB_PATH.play_page_list_item, Prefab, (err, prefab) => {
|
|
|
if(err){
|
|
|
console.log("err::",err);
|
|
|
return;
|
|
@@ -216,16 +251,16 @@ export class homepage extends Component {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- hideAllItem(){
|
|
|
- let self = this;
|
|
|
- for (let index = 0; index < self.content.children.length; index++) {
|
|
|
- self.content.children[index].getComponent(play_list_item).hide();
|
|
|
+ playPageListItemUpdateView() {
|
|
|
+ let self = this
|
|
|
+ for (let index = 0; index < self.playItemList.length; index++) {
|
|
|
+ let item = self.playItemList[index]
|
|
|
+ item.getComponent(play_page_list_item).updateView()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
onItemClick(data:server_play_list_data_item){
|
|
|
gameManager.playBtnSound()
|
|
|
- this.hideAllItem()
|
|
|
switch(data.id){
|
|
|
case config.PLAY_TYPE.YI_QI_ZHAO_CHA:
|
|
|
{
|