123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- import { _decorator, Component, Node, Prefab, UITransform, Sprite, Tween, Color } from 'cc';
- import { Holder } from '../../adapter/abstract/Holder';
- import { ScrollAdapter } from '../../adapter/abstract/ScrollAdapter';
- import { View } from '../../adapter/abstract/View';
- import { ContentType, friendType, ReleaseState } from '../../adapter/define/enum';
- import { IElement } from '../../adapter/define/interface';
- import { ReleaseEvent, ReleaseManager } from '../../adapter/manager/ReleaseManager';
- import { ViewManager } from '../../adapter/manager/ViewManager';
- import { ClientEvent } from '../../clientEvent';
- import ItemDataConfig, { itemData } from '../../config/ItemDataConfig';
- import { Constant } from '../../constant';
- import { GameMng } from '../../GameMng';
- import { UIButton } from '../../gcommon/UIButton';
- import { msgManager } from '../../socket/msgManager';
- import { userData } from '../../UserData/userData';
- import { invite_firend_item } from './invite_firend_item';
- const { ccclass, property } = _decorator;
- @ccclass('daoju_shop_view')
- export class invite_firend_manager extends ScrollAdapter<userData> {
- @property(Prefab) invite_Prefab: Prefab = null
- @property(UITransform) header: UITransform = null
- @property(Sprite) loading: Sprite = null
- @property(UITransform) foot: UITransform = null
- @property(Sprite) foot_loading: Sprite = null
- @property({ type: friendType }) public _contentType: friendType = friendType.haoyou_yaoqing
- @property({ type: friendType }) public get contentType() { return this._contentType }
- public set contentType(value: friendType) {
- if (value == this._contentType) return
- this._contentType = value
- }
- private _headerTween: Tween<any>
- private _loadTween: Tween<any>
- private _footTween: Tween<any>
- private _loadFootTween: Tween<any>
- private _isHeaderPlay = false
- private _isFootPlay = false
- start() {
- this.initView();
- ClientEvent.on(Constant.UI_EVENT.UI_MSG_UPDATE_FIREND_LIST,this.recv_firend_list,this)
- }
- onDestroy(){
- ClientEvent.off(Constant.UI_EVENT.UI_MSG_UPDATE_FIREND_LIST,this.recv_firend_list,this)
- }
- initView(){
- this.releaseManager.on(ReleaseManager.Event.ON_PULL_UP, this.onPullUp, this)
- this.releaseManager.on(ReleaseManager.Event.ON_PULL_DOWN, this.onPullDown, this)
- this._headerTween = new Tween(this.header).to(0.518, {
- height: this.releaseManager.top * this.mainAxisSize
- }, { easing: "elasticOut" })
- this._loadTween = new Tween(this.loading.node).by(1, {
- angle: -360
- }).union().repeatForever()
- this._footTween = new Tween(this.foot).to(0.518, {
- height: this.releaseManager.top * this.mainAxisSize
- }, { easing: "elasticOut" })
- this._loadFootTween = new Tween(this.foot_loading.node).by(1, {
- angle: -360
- }).union().repeatForever()
- //this.viewManager.on(ViewManager.Event.ON_MAGNETIC, this._onMagnetic, this)
- }
- onEnable(){
- msgManager.get_firend_list()
- }
- recv_firend_list(){
- // if( this.modelManager){
- this.modelManager.clear()
- var list = []
- if(this._contentType===friendType.haoyou_paihang){
- list = GameMng.getFirendRankList()
- }else{
- list = GameMng.getFirendList()
- }
- this.modelManager.insert( list,0)
- this.scrollManager.scrollToHeader(0)
- // }
- }
- async onPullUp(event: ReleaseEvent) {
- if (event.state == ReleaseState.RELEASE) {
- if (this._isFootPlay) {
- this._loadFootTween.start()
- // 等待并锁定头部
- event.wait()
- // 加载历史记录
- var list = await this.loadMore()
-
- // 插入数据
- this.modelManager.insert(list,0)
- // 释放解锁头部
- this.scheduleOnce(() => {
- event.release()
- })
- this._loadFootTween.stop()
- }
- }
- var progress = event.progress
- if (event.state == ReleaseState.WAIT) {
- progress = 0.8
- }
- if (progress >= 0.8) {
- if (!this._isFootPlay) {
- this._footTween = new Tween(this.foot).to(0.518, {
- height: this.releaseManager.bottom * this.mainAxisSize
- }, { easing: "elasticOut" })
- this._footTween.start()
- this._isFootPlay = true
- }
- } else {
- this._footTween.stop()
- this._isFootPlay = false
- this.foot.height = event.offset
- var color = new Color()
- color.set(this.foot_loading.color)
- color.a = 255 * Math.min(progress, 1)
- this.foot_loading.color = color
- // var y = 70 - 40 * progress
- // this.loading.node.setPosition(0, Math.max(y, 0))
- }
- this.foot_loading.node.angle = -360 * event.progress
- }
- async onPullDown(event: ReleaseEvent) {
- if (event.state == ReleaseState.RELEASE) {
- if (this._isHeaderPlay) {
- this._loadTween.start()
- // this.modelManager.clear()
- // 等待并锁定头部
- event.wait()
- // 加载历史记录
- var list = await this.reLoad()
- this.onEnable()
- this.scrollToHeader()
- // 插入数据
- // this.modelManager.insert(list,0)
- // 释放解锁头部
- this.scheduleOnce(() => {
- event.release()
- })
- this._loadTween.stop()
- }
- }
- var progress = event.progress
- if (event.state == ReleaseState.WAIT) {
- progress = 0.8
- }
- if (progress >= 0.8) {
- if (!this._isHeaderPlay) {
- this._headerTween = new Tween(this.header).to(0.518, {
- height: this.releaseManager.top * this.mainAxisSize
- }, { easing: "elasticOut" })
- this._headerTween.start()
- this._isHeaderPlay = true
- }
- } else {
- this._headerTween.stop()
- this._isHeaderPlay = false
- this.header.height = event.offset
- var color = new Color()
- color.set(this.loading.color)
- color.a = 255 * Math.min(progress, 1)
- this.loading.color = color
- // var y = 70 - 40 * progress
- // this.loading.node.setPosition(0, Math.max(y, 0))
- }
- this.loading.node.angle = -360 * event.progress
- }
- reLoad(): Promise<userData[]> {
- return new Promise((resolve, reject) => {
- var list = []
- this.scheduleOnce(() => {
- resolve(list)
- }, 1)
- })
- }
- loadMore(): Promise<userData[]> {
- return new Promise((resolve, reject) => {
- var list = []
- this.scheduleOnce(() => {
- resolve(list)
- }, 1)
- })
- }
- public getPrefab(data: userData): Node | Prefab {
-
- return this.invite_Prefab
- }
- public getHolder(node: Node, code: string): Holder<userData> {
- return new myHolder(node, code, this)
- }
- public getView(): View<userData> {
- return new myView(this)
- }
- public initElement(element: IElement, data: any): void {
- }
- scrollToHeader() {
- this.scrollManager.scrollToFooter(1)
- }
- }
- class myView extends View<userData, invite_firend_manager> {
- protected onVisible(): void {
- }
- protected onDisable(): void {
- }
- }
- class myHolder extends Holder<userData, invite_firend_manager>{
- private _shopItem: invite_firend_item = null
- protected onCreated(): void {
- this._shopItem = this.node.getComponent(invite_firend_item)
- this._shopItem.show(this.data,this.adapter._contentType,this.index)
-
- }
- protected onVisible(): void {
-
- }
- protected onDisable(): void {
- // this._shopItem.hide()
- }
- }
|