car_lib_bottom.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { _decorator, Color, Component, instantiate, Label, Layout, Node, PageView, Prefab, Sprite, SpriteFrame, UITransform } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { tools } from '../../tools';
  4. import { car_lib_list_item } from './car_lib_list_item';
  5. import { userDataManager } from '../../manager/userDataManager';
  6. import { car_item_data } from '../../data';
  7. import { car_lib_page_item } from './car_lib_page_item';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('car_lib_bottom')
  10. export class car_lib_bottom extends base_ui {
  11. @property(Node) btn_num_left:Node = null
  12. @property(Node) btn_num_right:Node = null
  13. @property(Node) lab_num:Node = null
  14. @property(Node) list:Node = null
  15. @property(Node) list_content:Node = null
  16. @property(Prefab) list_item:Prefab = null
  17. @property(Node) pageView:Node = null
  18. @property(Node) pageView_content:Node = null
  19. @property(Prefab) pageView_page_item:Prefab = null
  20. private num_current_count:number = 1
  21. private num_total_count:number = 1
  22. private current_select_list_item:car_lib_list_item = null
  23. private m_click_item_cb = null
  24. start() {
  25. this.onButtonListen(this.btn_num_left, ()=>{
  26. if(this.num_current_count==1) {
  27. return
  28. }
  29. this.num_current_count -=1
  30. this.updateNumStatus()
  31. })
  32. this.onButtonListen(this.btn_num_right, ()=>{
  33. if(this.num_current_count>=this.num_total_count) {
  34. return
  35. }
  36. this.num_current_count +=1
  37. this.updateNumStatus()
  38. })
  39. this.pageView.on(PageView.EventType. PAGE_TURNING, (e:PageView)=>{
  40. let currentPageIndex = e.getCurrentPageIndex()
  41. // console.log('currentPageIndex=',currentPageIndex)
  42. this.num_current_count = currentPageIndex + 1
  43. this.updateNumStatus()
  44. })
  45. }
  46. public init(click_item_cb) {
  47. this.m_click_item_cb = click_item_cb
  48. this.num_total_count = tools.all_car_page_list.length
  49. this.updateNumStatus()
  50. for (let index = 0; index < this.num_total_count; index++) {
  51. let page = instantiate(this.pageView_page_item)
  52. let data_list = tools.all_car_page_list[index]
  53. page.getComponent(car_lib_page_item).init(index,data_list, this.onSelectedItem.bind(this), this.onClickListItem.bind(this))
  54. this.pageView.getComponent(PageView).addPage(page)
  55. }
  56. }
  57. private getNumCurrentIndex():number {
  58. let index = this.num_current_count - 1
  59. if(index<0) {
  60. index = 0
  61. }
  62. return index
  63. }
  64. private updateNumStatus() {
  65. this.lab_num.getComponent(Label).string = this.num_current_count + '/' + this.num_total_count
  66. let index = this.getNumCurrentIndex()
  67. this.pageView.getComponent(PageView).scrollToPage(index)
  68. }
  69. private onSelectedItem(list_item:car_lib_list_item) {
  70. this.current_select_list_item = list_item
  71. }
  72. private onClickListItem(page_item:car_lib_page_item,list_item:car_lib_list_item) {
  73. if(this.current_select_list_item!=null) {
  74. if(this.current_select_list_item.getData().id == list_item.getData().id) {
  75. return
  76. }
  77. }
  78. if(list_item.getIsJiesuo()==false) {
  79. console.log('未解锁 未解锁 未解锁')
  80. return
  81. }
  82. if(this.current_select_list_item!=null) {
  83. this.current_select_list_item.setUnselectedStatus()
  84. }
  85. list_item.setSelectedStatus()
  86. this.current_select_list_item = list_item
  87. if(this.m_click_item_cb!=null) {
  88. this.m_click_item_cb(list_item)
  89. }
  90. }
  91. }