jishiqi_shop_view.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import { _decorator, Component, Node, Prefab, Tween, UITransform, Sprite, Color } from 'cc';
  2. import { Holder } from '../adapter/abstract/Holder';
  3. import { ScrollAdapter } from '../adapter/abstract/ScrollAdapter';
  4. import { View } from '../adapter/abstract/View';
  5. import { ContentType, ReleaseState } from '../adapter/define/enum';
  6. import { IElement } from '../adapter/define/interface';
  7. import { ReleaseEvent, ReleaseManager } from '../adapter/manager/ReleaseManager';
  8. import { ClientEvent } from '../clientEvent';
  9. import ItemDataConfig, { itemData } from '../config/ItemDataConfig';
  10. import { Constant } from '../constant';
  11. import { GameMng } from '../GameMng';
  12. import { ji_shi_qi_select_info } from './ji_shi_qi_select_info';
  13. import { shop_jishiqi_page } from './shop_jishiqi_page';
  14. const { ccclass, property } = _decorator;
  15. @ccclass('jishiqi_shop_view')
  16. export class jishiqi_shop_view extends ScrollAdapter<itemData[]> {
  17. @property(Prefab) shopPrefab: Prefab = null
  18. @property(UITransform) header: UITransform = null
  19. @property(Sprite) loading: Sprite = null
  20. @property(UITransform) foot: UITransform = null
  21. @property(Sprite) foot_loading: Sprite = null
  22. @property(Prefab) item_prefab: Prefab = null
  23. @property(Node) show_info_node:Node = null
  24. @property({ type: ContentType }) private _contentType: ContentType = ContentType.shop
  25. @property({ type: ContentType }) public get contentType() { return this._contentType }
  26. public set contentType(value: ContentType) {
  27. if (value == this._contentType) return
  28. this._contentType = value
  29. }
  30. private _headerTween: Tween<any>
  31. private _loadTween: Tween<any>
  32. private _footTween: Tween<any>
  33. private _loadFootTween: Tween<any>
  34. private _isHeaderPlay = false
  35. private _isFootPlay = false
  36. public jishiqi_list_data = []
  37. public cur_select_id = "";
  38. start() {
  39. this.initView();
  40. }
  41. initView(){
  42. this.releaseManager.on(ReleaseManager.Event.ON_PULL_UP, this.onPullUp, this)
  43. this.releaseManager.on(ReleaseManager.Event.ON_PULL_DOWN, this.onPullDown, this)
  44. this._headerTween = new Tween(this.header).to(0.518, {
  45. height: this.releaseManager.top * this.mainAxisSize
  46. }, { easing: "elasticOut" })
  47. this._loadTween = new Tween(this.loading.node).by(1, {
  48. angle: -360
  49. }).union().repeatForever()
  50. this._footTween = new Tween(this.foot).to(0.518, {
  51. height: this.releaseManager.top * this.mainAxisSize
  52. }, { easing: "elasticOut" })
  53. this._loadFootTween = new Tween(this.foot_loading.node).by(1, {
  54. angle: -360
  55. }).union().repeatForever()
  56. if(this._contentType===ContentType.bag){
  57. this.jishiqi_list_data = GameMng.getBagJiShiQiList()
  58. }else{
  59. this.jishiqi_list_data = ItemDataConfig.Instance.getShopJiShiQiList()
  60. }
  61. this.init_shop_item()
  62. ClientEvent.on(Constant.UI_EVENT.UI_MSG_UPDATE_SELECT_JISHIQI,this.notice,this)
  63. //this.viewManager.on(ViewManager.Event.ON_MAGNETIC, this._onMagnetic, this)
  64. }
  65. onDestroy(){
  66. ClientEvent.off(Constant.UI_EVENT.UI_MSG_UPDATE_SELECT_JISHIQI,this.notice,this)
  67. }
  68. notice(id:string){
  69. this.cur_select_id = id;
  70. // for (let index = 0; index < this.modelManager.length; index++) {
  71. // const element = this.modelManager[index];
  72. // }
  73. this.show_info_node.getComponent(ji_shi_qi_select_info).show(ItemDataConfig.Instance.getItemById(id))
  74. this.modelManager.update()
  75. }
  76. init_shop_item(){
  77. var list = []
  78. if(this.jishiqi_list_data.length<=0){
  79. }else{
  80. this.cur_select_id = this.jishiqi_list_data[0].id
  81. this.show_info_node.getComponent(ji_shi_qi_select_info).show(ItemDataConfig.Instance.getItemById(this.cur_select_id))
  82. list.push(this.jishiqi_list_data)
  83. this.modelManager.clear()
  84. this.modelManager.insert(list)
  85. this.scrollManager.scrollToFooter(0)
  86. }
  87. }
  88. async onPullUp(event: ReleaseEvent) {
  89. if (event.state == ReleaseState.RELEASE) {
  90. if (this._isFootPlay) {
  91. this._loadFootTween.start()
  92. // 等待并锁定头部
  93. event.wait()
  94. // 加载历史记录
  95. var list = await this.loadMore()
  96. // 插入数据
  97. this.modelManager.insert(list,0)
  98. // 释放解锁头部
  99. this.scheduleOnce(() => {
  100. event.release()
  101. })
  102. this._loadFootTween.stop()
  103. }
  104. }
  105. var progress = event.progress
  106. if (event.state == ReleaseState.WAIT) {
  107. progress = 0.8
  108. }
  109. if (progress >= 0.8) {
  110. if (!this._isFootPlay) {
  111. this._footTween = new Tween(this.foot).to(0.518, {
  112. height: this.releaseManager.bottom * this.mainAxisSize
  113. }, { easing: "elasticOut" })
  114. this._footTween.start()
  115. this._isFootPlay = true
  116. }
  117. } else {
  118. this._footTween.stop()
  119. this._isFootPlay = false
  120. this.foot.height = event.offset
  121. var color = new Color()
  122. color.set(this.foot_loading.color)
  123. color.a = 255 * Math.min(progress, 1)
  124. this.foot_loading.color = color
  125. // var y = 70 - 40 * progress
  126. // this.loading.node.setPosition(0, Math.max(y, 0))
  127. }
  128. this.foot_loading.node.angle = -360 * event.progress
  129. }
  130. async onPullDown(event: ReleaseEvent) {
  131. if (event.state == ReleaseState.RELEASE) {
  132. if (this._isHeaderPlay) {
  133. this._loadTween.start()
  134. // this.modelManager.clear()
  135. // 等待并锁定头部
  136. event.wait()
  137. // 加载历史记录
  138. var list = await this.reLoad()
  139. this.scrollToHeader()
  140. // 插入数据
  141. // this.modelManager.insert(list,0)
  142. // 释放解锁头部
  143. this.scheduleOnce(() => {
  144. event.release()
  145. })
  146. this._loadTween.stop()
  147. }
  148. }
  149. var progress = event.progress
  150. if (event.state == ReleaseState.WAIT) {
  151. progress = 0.8
  152. }
  153. if (progress >= 0.8) {
  154. if (!this._isHeaderPlay) {
  155. this._headerTween = new Tween(this.header).to(0.518, {
  156. height: this.releaseManager.top * this.mainAxisSize
  157. }, { easing: "elasticOut" })
  158. this._headerTween.start()
  159. this._isHeaderPlay = true
  160. }
  161. } else {
  162. this._headerTween.stop()
  163. this._isHeaderPlay = false
  164. this.header.height = event.offset
  165. var color = new Color()
  166. color.set(this.loading.color)
  167. color.a = 255 * Math.min(progress, 1)
  168. this.loading.color = color
  169. // var y = 70 - 40 * progress
  170. // this.loading.node.setPosition(0, Math.max(y, 0))
  171. }
  172. this.loading.node.angle = -360 * event.progress
  173. }
  174. reLoad(): Promise<itemData[]> {
  175. return new Promise((resolve, reject) => {
  176. var list = []
  177. this.scheduleOnce(() => {
  178. this.init_shop_item()
  179. resolve(list)
  180. }, 1)
  181. })
  182. }
  183. loadMore(): Promise<itemData[]> {
  184. return new Promise((resolve, reject) => {
  185. this.scheduleOnce(() => {
  186. resolve([])
  187. }, 0)
  188. })
  189. }
  190. scrollToHeader() {
  191. this.scrollManager.scrollToFooter(1)
  192. }
  193. public getPrefab(data: itemData[]): Node | Prefab {
  194. return this.shopPrefab
  195. }
  196. public getHolder(node: Node, code: string): Holder<itemData[]> {
  197. return new myHolder(node, code, this)
  198. }
  199. public getView(): View<itemData[]> {
  200. return new myView(this)
  201. }
  202. public initElement(element: IElement, data: any): void {
  203. }
  204. }
  205. class myView extends View<itemData[], jishiqi_shop_view> {
  206. protected onVisible(): void {
  207. }
  208. protected onDisable(): void {
  209. }
  210. }
  211. class myHolder extends Holder<itemData[], jishiqi_shop_view>{
  212. private _shopItem: shop_jishiqi_page = null
  213. protected onCreated(): void {
  214. this._shopItem = this.node.getComponent(shop_jishiqi_page)
  215. }
  216. protected onVisible(): void {
  217. this._shopItem.show(this,this.adapter.item_prefab,this.data,this.adapter.cur_select_id,this.adapter.contentType)
  218. }
  219. protected onDisable(): void {
  220. this._shopItem.hide()
  221. }
  222. }