car_lib_bottom.ts 3.5 KB

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