123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import { _decorator, Color, Component, instantiate, Label, Layout, Node, PageView, Prefab, Sprite, SpriteFrame, UITransform } from 'cc';
- import { base_ui } from '../../fw/base_ui';
- import { tools } from '../../tools';
- import { car_lib_list_item } from './car_lib_list_item';
- import { car_lib_page_item } from './car_lib_page_item';
- import { uiManager } from '../../manager/uiManager';
- import { config } from '../../config';
- import { GameManager } from '../../GameManager';
- import { bag_type, car_type } from '../../data';
- import { car_info } from '../car_info/car_info';
- import { SdkUtil } from '../../sdkUtil';
- const { ccclass, property } = _decorator;
- @ccclass('car_lib_bottom')
- export class car_lib_bottom extends base_ui {
- @property(Node) btn_num_left:Node = null
- @property(Node) btn_num_right:Node = null
- @property(Node) lab_num:Node = null
- @property(Node) pageView:Node = null
- @property(Node) pageView_content:Node = null
- @property(Prefab) pageView_page_item:Prefab = null
- private num_current_count:number = 1
- private num_total_count:number = 1
- private current_select_list_item:car_lib_list_item = null
- private m_click_item_cb = null
- private game_status_parent:Node = null
- start() {
- this.onButtonListen(this.btn_num_left, ()=>{
- if(this.num_current_count==1) {
- return
- }
- this.num_current_count -=1
- this.updateNumStatus()
- })
- this.onButtonListen(this.btn_num_right, ()=>{
- if(this.num_current_count>=this.num_total_count) {
- return
- }
- this.num_current_count +=1
- this.updateNumStatus()
- })
- this.pageView.on(PageView.EventType. PAGE_TURNING, (e:PageView)=>{
- let currentPageIndex = e.getCurrentPageIndex()
- // console.log('currentPageIndex=',currentPageIndex)
- this.num_current_count = currentPageIndex + 1
- this.updateNumStatus()
- })
- }
- public init(click_item_cb) {
- this.m_click_item_cb = click_item_cb
- this.num_total_count = tools.all_car_page_list.length
- this.updateNumStatus()
- let id = bag_type.car_suipian
- GameManager.requestBagList(id, (car_suipian_list)=>{
- // console.log('car_suipian_list=',car_suipian_list)
- for (let index = 0; index < this.num_total_count; index++) {
- let page = instantiate(this.pageView_page_item)
- let data_list = tools.all_car_page_list[index]
- page.getComponent(car_lib_page_item).init(this.pageView, index,data_list, car_suipian_list, this.onSelectedItem.bind(this), this.onClickListItem.bind(this))
- this.pageView.getComponent(PageView).addPage(page)
- }
- })
- }
- private getNumCurrentIndex():number {
- let index = this.num_current_count - 1
- if(index<0) {
- index = 0
- }
- return index
- }
- private updateNumStatus() {
- this.lab_num.getComponent(Label).string = this.num_current_count + '/' + this.num_total_count
- let index = this.getNumCurrentIndex()
- this.pageView.getComponent(PageView).scrollToPage(index)
- }
- private onSelectedItem(page_item:car_lib_page_item, list_item:car_lib_list_item) {
- this.current_select_list_item = list_item
- setTimeout(()=>{
- this.pageView.getComponent(PageView).scrollToPage(page_item.getIndex())
- },100)
- }
- private onClickListItem(page_item:car_lib_page_item,list_item:car_lib_list_item) {
- let car_item_data = list_item.getData()
- if(list_item.getIsJiesuo()==false&&car_item_data.stype==car_type.suipian) {
- let cur_count = car_item_data.temp_bag_list_item_data.quantity
- if(cur_count-car_item_data.unlock_points>=0) {
- // 直接显示兑换车辆视图
- GameManager.showExchangeCarView(car_item_data.id,car_item_data.temp_bag_list_item_data.icon,car_item_data.temp_bag_list_item_data.quantity, ()=>{
- list_item.setJiesuoSelectedStatus()
- })
- return
- }
- }
- uiManager.Instance().showUi(config.UI.ui_car_info,this.game_status_parent!=null?this.game_status_parent:null, (node:Node)=>{
- let car_info_component = node.getComponent(car_info)
- car_info_component.initView(list_item.getData(),list_item.getIsJiesuo())
- car_info_component.initOperateNodeCallback((v:car_info)=>{
- // 装备
- if(this.current_select_list_item!=null) {
- this.current_select_list_item.setUnselectedStatus()
- }
- list_item.setSelectedStatus()
- this.current_select_list_item = list_item
-
- if(this.m_click_item_cb!=null) {
- this.m_click_item_cb(list_item)
- }
- },(v:car_info)=>{
- // 兑换(废弃,更改为直接弹出兑换视图,代码见上方👆🏻)
- let data = v.getData()
- if(data.temp_bag_list_item_data) {
- GameManager.showExchangeCarView(data.id,data.temp_bag_list_item_data.icon,data.temp_bag_list_item_data.quantity, ()=>{
- car_info_component.closeSelf()
- list_item.setJiesuoSelectedStatus()
- })
- }
- })
- car_info_component.initGetSuipianNodeCallback((v:car_info)=>{
- // 看视频
- GameManager.showVideoAd(config.ADS_TYPE.GAME_GET_SUIPIAN, ()=>{
- })
- }, (v:car_info)=>{
- // 分享
- SdkUtil.shareGame("","",()=>{
-
- })
- })
- })
- }
- public initGameStatusParent(parent:Node){
- this.game_status_parent = parent
- }
- }
|