123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import { _decorator, Component, instantiate, Label, Layout, Node, 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 { userDataManager } from '../../manager/userDataManager';
- import { car_item_data } from '../../data';
- 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) list:Node = null
- @property(Node) list_content:Node = null
- @property(Prefab) list_item:Prefab = null
- private data_list:car_item_data[] = []
- 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(true)
- })
- this.onButtonListen(this.btn_num_right, ()=>{
- if(this.num_current_count>=this.num_total_count) {
- return
- }
- this.num_current_count +=1
- this.updateNumStatus(true)
- })
- }
- public init(click_item_cb) {
- this.m_click_item_cb = click_item_cb
- this.num_total_count = tools.all_car_page_list.length
- // this.data_list = JSON.parse(JSON.stringify(tools.all_car_list))
- this.data_list = tools.all_car_page_list[this.getNumCurrentIndex()]
- console.log('this.data_list=',this.data_list)
- this.updateNumStatus()
- this.reloadListContentData()
- let list_content_size = this.list_content.getComponent(UITransform).contentSize
- let item_contenteSize = instantiate(this.list_item).getComponent(UITransform).contentSize
- let horizontal_padding = (list_content_size.width - item_contenteSize.width * 2) / 3
- if(horizontal_padding > 0) {
- this.list_content.getComponent(Layout).paddingLeft = horizontal_padding
- this.list_content.getComponent(Layout).paddingRight = horizontal_padding
- this.list_content.getComponent(Layout).spacingX = horizontal_padding
- }
- }
- private getNumCurrentIndex():number {
- let index = this.num_current_count - 1
- if(index<0) {
- index = 0
- }
- return index
- }
- updateNumStatus(is_reload_data:boolean=false) {
- this.lab_num.getComponent(Label).string = this.num_current_count + '/' + this.num_total_count
- if(is_reload_data) {
- this.current_select_list_item = null
- this.data_list = tools.all_car_page_list[this.getNumCurrentIndex()]
- this.reloadListContentData()
- }
- }
- reloadListContentData() {
- this.list_content.removeAllChildren()
- this.current_select_list_item = null
- for (let index = 0; index < this.data_list.length; index++) {
- const element = this.data_list[index];
- let is_jiesuo = userDataManager.user_car_list.car_list.some(obj => obj === element.id)
- let item = instantiate(this.list_item)
- if(item!=null) {
- item.parent = this.list_content
- let item_component = item.getComponent(car_lib_list_item)
- item_component.initView(element, index, this.onClickListItem.bind(this))
- if(is_jiesuo) {
- item_component.setJiesuoSelectedStatus()
- } else {
- item_component.setJiesuoUnselectedStatus()
- }
- if(userDataManager.user_car_list.default_car_id == element.id) {
- this.current_select_list_item = item_component
- item_component.setSelectedStatus()
- } else {
- item_component.setUnselectedStatus()
- }
- }
- }
- }
- onClickListItem(item:car_lib_list_item) {
- if(this.current_select_list_item!=null) {
- if(this.current_select_list_item.getData().id == item.getData().id) {
- return
- }
- }
-
- if(item.getIsJiesuo()==false) {
- console.log('未解锁 未解锁 未解锁')
- return
- }
- if(this.current_select_list_item!=null) {
- this.current_select_list_item.setUnselectedStatus()
- }
- item.setSelectedStatus()
- this.current_select_list_item = item
- if(this.m_click_item_cb!=null) {
- this.m_click_item_cb(item)
- }
- }
- }
|