car_lib_bottom.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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, car_type, rewards_item_data } from '../../data';
  10. import { car_info } from '../car_info/car_info';
  11. import { SdkUtil } from '../../sdkUtil';
  12. import { userDataManager } from '../../manager/userDataManager';
  13. import { reward_tips_view } from '../reward_tips_view/reward_tips_view';
  14. const { ccclass, property } = _decorator;
  15. @ccclass('car_lib_bottom')
  16. export class car_lib_bottom extends base_ui {
  17. @property(Node) btn_num_left:Node = null
  18. @property(Node) btn_num_right:Node = null
  19. @property(Node) lab_num:Node = null
  20. @property(Node) pageView:Node = null
  21. @property(Node) pageView_content:Node = null
  22. @property(Prefab) pageView_page_item:Prefab = null
  23. private num_current_count:number = 1
  24. private num_total_count:number = 1
  25. private current_select_list_item:car_lib_list_item = null
  26. private m_car_suipian_list = null
  27. private m_click_item_cb = null
  28. private game_status_parent:Node = null
  29. start() {
  30. this.onButtonListen(this.btn_num_left, ()=>{
  31. if(this.num_current_count==1) {
  32. return
  33. }
  34. this.num_current_count -=1
  35. this.updateNumStatus()
  36. })
  37. this.onButtonListen(this.btn_num_right, ()=>{
  38. if(this.num_current_count>=this.num_total_count) {
  39. return
  40. }
  41. this.num_current_count +=1
  42. this.updateNumStatus()
  43. })
  44. this.pageView.on(PageView.EventType. PAGE_TURNING, (e:PageView)=>{
  45. let currentPageIndex = e.getCurrentPageIndex()
  46. // console.log('currentPageIndex=',currentPageIndex)
  47. this.num_current_count = currentPageIndex + 1
  48. this.updateNumStatus()
  49. })
  50. }
  51. public init(click_item_cb) {
  52. this.m_click_item_cb = click_item_cb
  53. this.requestData()
  54. }
  55. private requestData() {
  56. this.num_total_count = tools.all_car_page_list.length
  57. this.updateNumStatus()
  58. this.pageView.getComponent(PageView).removeAllPages()
  59. let id = bag_type.car_suipian
  60. GameManager.requestBagList(id, (car_suipian_list)=>{
  61. this.m_car_suipian_list = car_suipian_list
  62. // console.log('car_suipian_list=',car_suipian_list)
  63. for (let index = 0; index < this.num_total_count; index++) {
  64. let page = instantiate(this.pageView_page_item)
  65. let data_list = tools.all_car_page_list[index]
  66. page.getComponent(car_lib_page_item).init(this.pageView, index,data_list, car_suipian_list, this.onSelectedItem.bind(this), this.onClickListItem.bind(this))
  67. this.pageView.getComponent(PageView).addPage(page)
  68. }
  69. })
  70. }
  71. private getNumCurrentIndex():number {
  72. let index = this.num_current_count - 1
  73. if(index<0) {
  74. index = 0
  75. }
  76. return index
  77. }
  78. private updateNumStatus() {
  79. this.lab_num.getComponent(Label).string = this.num_current_count + '/' + this.num_total_count
  80. let index = this.getNumCurrentIndex()
  81. this.pageView.getComponent(PageView).scrollToPage(index)
  82. }
  83. private onSelectedItem(page_item:car_lib_page_item, list_item:car_lib_list_item) {
  84. this.current_select_list_item = list_item
  85. setTimeout(()=>{
  86. this.pageView.getComponent(PageView).scrollToPage(page_item.getIndex())
  87. },100)
  88. }
  89. private onClickListItem(page_item:car_lib_page_item,list_item:car_lib_list_item) {
  90. let car_item_data = list_item.getData()
  91. if(list_item.getIsJiesuo()==false&&car_item_data.stype==car_type.suipian) {
  92. let cur_count = car_item_data.temp_bag_list_item_data.quantity
  93. if(cur_count-car_item_data.unlock_points>=0) {
  94. // 直接显示兑换车辆视图
  95. GameManager.showExchangeCarView(car_item_data.id,car_item_data.temp_bag_list_item_data.icon,car_item_data.temp_bag_list_item_data.quantity, ()=>{
  96. list_item.setJiesuoSelectedStatus()
  97. })
  98. return
  99. }
  100. }
  101. uiManager.Instance().showUi(config.UI.ui_car_info,this.game_status_parent!=null?this.game_status_parent:null, (node:Node)=>{
  102. let car_info_component = node.getComponent(car_info)
  103. car_info_component.initView(list_item.getData(),list_item.getIsJiesuo())
  104. car_info_component.initOperateNodeCallback((v:car_info)=>{
  105. // 装备
  106. if(this.current_select_list_item!=null) {
  107. this.current_select_list_item.setUnselectedStatus()
  108. }
  109. list_item.setSelectedStatus()
  110. this.current_select_list_item = list_item
  111. if(this.m_click_item_cb!=null) {
  112. this.m_click_item_cb(list_item)
  113. }
  114. },(v:car_info)=>{
  115. // 兑换(废弃,更改为直接弹出兑换视图,代码见上方👆🏻)
  116. let data = v.getData()
  117. if(data.temp_bag_list_item_data) {
  118. GameManager.showExchangeCarView(data.id,data.temp_bag_list_item_data.icon,data.temp_bag_list_item_data.quantity, ()=>{
  119. car_info_component.closeSelf()
  120. list_item.setJiesuoSelectedStatus()
  121. })
  122. }
  123. })
  124. car_info_component.initGetSuipianNodeCallback((v:car_info)=>{
  125. // 看视频
  126. if(userDataManager.isGetCarDebrisLookVideo()==false) {
  127. return uiManager.showToast('今日看视频已到上限')
  128. }
  129. GameManager.showVideoAd(config.ADS_TYPE.GAME_GET_SUIPIAN, ()=>{
  130. userDataManager.addGetCarDebrisLookVideoNumber(v.getData().id, (data)=>{
  131. this.getCarDebrisOperation(data, list_item, v)
  132. })
  133. })
  134. }, (v:car_info)=>{
  135. // 分享
  136. if(userDataManager.isGetCarDebrisShare()==false) {
  137. return uiManager.showToast('今日分享已到上限')
  138. }
  139. SdkUtil.shareGame("",tools.sys_config.share_des,(r)=>{
  140. if(r==true) {
  141. userDataManager.addGetCarDebrisShareNumber(v.getData().id, (data)=>{
  142. this.getCarDebrisOperation(data, list_item, v)
  143. })
  144. }
  145. })
  146. })
  147. })
  148. }
  149. private getCarDebrisOperation(data, list_item:car_lib_list_item, v:car_info) {
  150. // console.log('data=',data)
  151. let car_info_data = v.getData()
  152. car_info_data.temp_bag_list_item_data.quantity+=data.quantity
  153. // 解锁了
  154. if(car_info_data.temp_bag_list_item_data.quantity>=car_info_data.unlock_points) {
  155. // 关闭车信息
  156. v.getComponent(car_info).closeSelf()
  157. // 列表更新数据
  158. this.requestData()
  159. // 兑换弹框
  160. GameManager.showExchangeCarView(car_info_data.id, data.icon, car_info_data.temp_bag_list_item_data.quantity, ()=>{
  161. list_item.setJiesuoSelectedStatus()
  162. })
  163. return
  164. }
  165. // 奖励弹框
  166. uiManager.Instance().showUi(config.UI.ui_reward_tips_view, null, (node:Node)=>{
  167. node.getComponent(reward_tips_view).initView([data])
  168. // 车信息更新数据
  169. v.initView(car_info_data,v.getIsJiesuo())
  170. v.setCarSuipianData()
  171. // 列表更新数据
  172. this.requestData()
  173. })
  174. }
  175. public initGameStatusParent(parent:Node){
  176. this.game_status_parent = parent
  177. }
  178. }