car_lib_bottom.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. private game_status_parent:Node = null
  25. start() {
  26. this.onButtonListen(this.btn_num_left, ()=>{
  27. if(this.num_current_count==1) {
  28. return
  29. }
  30. this.num_current_count -=1
  31. this.updateNumStatus()
  32. })
  33. this.onButtonListen(this.btn_num_right, ()=>{
  34. if(this.num_current_count>=this.num_total_count) {
  35. return
  36. }
  37. this.num_current_count +=1
  38. this.updateNumStatus()
  39. })
  40. this.pageView.on(PageView.EventType. PAGE_TURNING, (e:PageView)=>{
  41. let currentPageIndex = e.getCurrentPageIndex()
  42. // console.log('currentPageIndex=',currentPageIndex)
  43. this.num_current_count = currentPageIndex + 1
  44. this.updateNumStatus()
  45. })
  46. }
  47. public init(click_item_cb) {
  48. this.m_click_item_cb = click_item_cb
  49. this.num_total_count = tools.all_car_page_list.length
  50. this.updateNumStatus()
  51. let id = bag_type.car_suipian
  52. GameManager.requestBagList(id, (car_suipian_list)=>{
  53. // console.log('car_suipian_list=',car_suipian_list)
  54. for (let index = 0; index < this.num_total_count; index++) {
  55. let page = instantiate(this.pageView_page_item)
  56. let data_list = tools.all_car_page_list[index]
  57. page.getComponent(car_lib_page_item).init(this.pageView, index,data_list, car_suipian_list, this.onSelectedItem.bind(this), this.onClickListItem.bind(this))
  58. this.pageView.getComponent(PageView).addPage(page)
  59. }
  60. })
  61. }
  62. private getNumCurrentIndex():number {
  63. let index = this.num_current_count - 1
  64. if(index<0) {
  65. index = 0
  66. }
  67. return index
  68. }
  69. private updateNumStatus() {
  70. this.lab_num.getComponent(Label).string = this.num_current_count + '/' + this.num_total_count
  71. let index = this.getNumCurrentIndex()
  72. this.pageView.getComponent(PageView).scrollToPage(index)
  73. }
  74. private onSelectedItem(page_item:car_lib_page_item, list_item:car_lib_list_item) {
  75. this.current_select_list_item = list_item
  76. setTimeout(()=>{
  77. this.pageView.getComponent(PageView).scrollToPage(page_item.getIndex())
  78. },100)
  79. }
  80. private onClickListItem(page_item:car_lib_page_item,list_item:car_lib_list_item) {
  81. uiManager.Instance().showUi(config.UI.ui_car_info,this.game_status_parent!=null?this.game_status_parent:null, (node:Node)=>{
  82. let car_info_component = node.getComponent(car_info)
  83. car_info_component.initView(list_item.getData(),list_item.getIsJiesuo())
  84. car_info_component.initOperateNodeCallback((v:car_info)=>{
  85. // 装备
  86. if(this.current_select_list_item!=null) {
  87. this.current_select_list_item.setUnselectedStatus()
  88. }
  89. list_item.setSelectedStatus()
  90. this.current_select_list_item = list_item
  91. if(this.m_click_item_cb!=null) {
  92. this.m_click_item_cb(list_item)
  93. }
  94. },(v:car_info)=>{
  95. // 兑换
  96. let data = v.getData()
  97. if(data.temp_bag_list_item_data) {
  98. GameManager.showExchangeCarView(data.id,data.temp_bag_list_item_data.icon,data.temp_bag_list_item_data.quantity, ()=>{
  99. car_info_component.closeSelf()
  100. list_item.setJiesuoSelectedStatus()
  101. })
  102. }
  103. })
  104. car_info_component.initGetSuipianNodeCallback((v:car_info)=>{
  105. // 看视频
  106. }, (v:car_info)=>{
  107. // 分享
  108. })
  109. })
  110. // if(this.current_select_list_item!=null) {
  111. // if(this.current_select_list_item.getData().id == list_item.getData().id) {
  112. // return
  113. // }
  114. // }
  115. // if(list_item.getIsJiesuo()==false) {
  116. // uiManager.Instance().showUi(config.UI.ui_car_info, null, (node:Node)=>{
  117. // node.getComponent(car_info).initView(list_item.getData(),list_item.getIsJiesuo())
  118. // })
  119. // return
  120. // }
  121. // if(this.current_select_list_item!=null) {
  122. // this.current_select_list_item.setUnselectedStatus()
  123. // }
  124. // list_item.setSelectedStatus()
  125. // this.current_select_list_item = list_item
  126. // if(this.m_click_item_cb!=null) {
  127. // this.m_click_item_cb(list_item)
  128. // }
  129. }
  130. public initGameStatusParent(parent:Node){
  131. this.game_status_parent = parent
  132. }
  133. }