invite_firend_manager.ts 8.1 KB

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