| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import { _decorator, Component, instantiate, Label, Node, Prefab, ScrollView, tween, Vec2, Vec3 } from "cc"
- const { ccclass, property } = _decorator
- @ccclass("rankCtr")
- export class rankCtr extends Component {
- @property({ type: Node })
- public textLiveRank: Node | null = null
- @property({ type: Node })
- public rankNods: Node[] = []
- @property({ type: Node })
- public textPointsRank: Node | null = null
- @property({ type: Prefab })
- gameItem = null
- @property({ type: Node })
- content = null
- @property({ type: ScrollView })
- rankScroll = null
- private isLiveRank: boolean = true
- private moveDistance: number = -150
- private lng: string = "cn"
- public rankList = []
- private nowRankNO = 0
- private rankNodes = []
- private startAnimate = false
- start() {}
- // 触发方法
- updateRankTop() {
- this.isLiveRank = !this.isLiveRank
- this.updateRankDisplay()
- }
- private updateRankDisplay() {
- if (!this.textLiveRank || !this.textPointsRank) return
- let moveOffset = this.isLiveRank ? -this.moveDistance : this.moveDistance
- let moveAction = new Vec3(moveOffset, 0, 0)
- tween(this.textLiveRank).by(0.5, { position: moveAction }).start()
- tween(this.textPointsRank).by(0.5, { position: moveAction }).start()
- }
- updateRank(data: any[]) {
- if (this.rankNodes.length === 0) {
- this.rankList = data
- if(data.length>0){
- data.forEach((item, index) => {
- let node = instantiate(this.gameItem)
-
- let number = node.getChildByName("text_rank_number").getComponent(Label)
- number.string = index + 1
-
- let nickName = node.getChildByName("text_player_name").getComponent(Label)
- nickName.string = item.userInfo.name
-
- let days = node.getChildByName("text_value").getComponent(Label)
- if (this.lng === "cn") {
- days.string = item.survival + "天"
- } else {
- days.string = item.survival + (item.survival == "1" ? "day" : "days")
- }
- this.content.addChild(node)
- this.rankNodes.push(node)
- })
- }
- // 数据变化开启动画
- // if (this.startAnimate) {
- // setTimeout(() => {
- // let info = data[this.nowRankNO]
- // data.splice(this.nowRankNO, 1)
- // data.splice(3, 0, info)
- // console.log(data)
- // this.updateRank(data)
- // }, 1000)
- // }
- } else {
- this.changeRank(3, data)
- }
- }
- changeRank(newRankNO, data) {
- let nowY = this.rankNodes[this.nowRankNO].position.y
- let goY = this.rankNodes[newRankNO].position.y
- this.rankScroll.scrollToOffset(new Vec2(0, -300 - nowY), 0.1)
- // this.rankScroll.scrollToOffset(new Vec2(0, goY), 1)
- setTimeout(() => {
- this.rankMove(this.rankNodes[this.nowRankNO], goY, data)
- }, 1000)
- }
- rankMove(_node, goY, data) {
- let node = instantiate(_node)
- tween(_node)
- .to(0.3, {
- innerHeight: 0
- })
- .start()
- this.rankScroll.scrollToOffset(new Vec2(0, -300 - goY), 1)
- this.content.removeChild(_node)
- this.content.parent.addChild(node)
- node.position.y = node.position.y + this.rankScroll.getScrollOffset().y + 200
- // // this.label_length = node.getComponent(UITransform).contentSize.x;
- tween(node)
- .to(0.3, { scale: new Vec3(1.2, 1.2, 1) })
- .to(1, { position: new Vec3(node.position.x, goY + 200) })
- .to(0.3, { scale: new Vec3(1, 1, 1) })
- .to(0, { scale: new Vec3(0, 0, 1) })
- .call(() => {
- this.rankNodes = []
- this.startAnimate = false
- this.content.removeAllChildren()
- this.updateRank(data)
- })
- .start()
- }
- update(deltaTime: number) {}
- }
|