car_lib_bottom.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. import { uiManager } from '../../manager/uiManager';
  7. import { config } from '../../config';
  8. import { GameManager } from '../../GameManager';
  9. import { bag_type } from '../../data';
  10. import { car_info } from '../car_info/car_info';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('car_lib_bottom')
  13. export class car_lib_bottom extends base_ui {
  14. @property(Node) btn_num_left:Node = null
  15. @property(Node) btn_num_right:Node = null
  16. @property(Node) lab_num:Node = 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. let id = bag_type.car_suipian
  51. GameManager.requestBagList(id, (car_suipian_list)=>{
  52. // console.log('car_suipian_list=',car_suipian_list)
  53. for (let index = 0; index < this.num_total_count; index++) {
  54. let page = instantiate(this.pageView_page_item)
  55. let data_list = tools.all_car_page_list[index]
  56. page.getComponent(car_lib_page_item).init(this.pageView, index,data_list, car_suipian_list, this.onSelectedItem.bind(this), this.onClickListItem.bind(this))
  57. this.pageView.getComponent(PageView).addPage(page)
  58. }
  59. })
  60. }
  61. private getNumCurrentIndex():number {
  62. let index = this.num_current_count - 1
  63. if(index<0) {
  64. index = 0
  65. }
  66. return index
  67. }
  68. private updateNumStatus() {
  69. this.lab_num.getComponent(Label).string = this.num_current_count + '/' + this.num_total_count
  70. let index = this.getNumCurrentIndex()
  71. this.pageView.getComponent(PageView).scrollToPage(index)
  72. }
  73. private onSelectedItem(page_item:car_lib_page_item, list_item:car_lib_list_item) {
  74. this.current_select_list_item = list_item
  75. setTimeout(()=>{
  76. this.pageView.getComponent(PageView).scrollToPage(page_item.getIndex())
  77. },100)
  78. }
  79. private onClickListItem(page_item:car_lib_page_item,list_item:car_lib_list_item) {
  80. uiManager.Instance().showUi(config.UI.ui_car_info, null, (node:Node)=>{
  81. let car_info_component = node.getComponent(car_info)
  82. car_info_component.initView(list_item.getData(),list_item.getIsJiesuo())
  83. car_info_component.initOperateNodeCallback((v:car_info)=>{
  84. // 装备
  85. if(this.current_select_list_item!=null) {
  86. this.current_select_list_item.setUnselectedStatus()
  87. }
  88. list_item.setSelectedStatus()
  89. this.current_select_list_item = list_item
  90. if(this.m_click_item_cb!=null) {
  91. this.m_click_item_cb(list_item)
  92. }
  93. },(v:car_info)=>{
  94. // 兑换
  95. let data = v.getData()
  96. if(data.temp_bag_list_item_data) {
  97. GameManager.showExchangeCarView(data.id,data.temp_bag_list_item_data.icon,data.temp_bag_list_item_data.quantity, ()=>{
  98. car_info_component.closeSelf()
  99. list_item.setJiesuoSelectedStatus()
  100. })
  101. }
  102. })
  103. car_info_component.initGetSuipianNodeCallback((v:car_info)=>{
  104. // 看视频
  105. }, (v:car_info)=>{
  106. // 分享
  107. })
  108. })
  109. // if(this.current_select_list_item!=null) {
  110. // if(this.current_select_list_item.getData().id == list_item.getData().id) {
  111. // return
  112. // }
  113. // }
  114. // if(list_item.getIsJiesuo()==false) {
  115. // uiManager.Instance().showUi(config.UI.ui_car_info, null, (node:Node)=>{
  116. // node.getComponent(car_info).initView(list_item.getData(),list_item.getIsJiesuo())
  117. // })
  118. // return
  119. // }
  120. // if(this.current_select_list_item!=null) {
  121. // this.current_select_list_item.setUnselectedStatus()
  122. // }
  123. // list_item.setSelectedStatus()
  124. // this.current_select_list_item = list_item
  125. // if(this.m_click_item_cb!=null) {
  126. // this.m_click_item_cb(list_item)
  127. // }
  128. }
  129. }