123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- 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';
- 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
- 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()
- 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, 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(list_item:car_lib_list_item) {
- this.current_select_list_item = list_item
- }
- private onClickListItem(page_item:car_lib_page_item,list_item:car_lib_list_item) {
- if(this.current_select_list_item!=null) {
- if(this.current_select_list_item.getData().id == list_item.getData().id) {
- return
- }
- }
-
- if(list_item.getIsJiesuo()==false) {
- console.log('未解锁 未解锁 未解锁')
- return
- }
- 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)
- }
- }
- }
|