Spring774
2025-10-28 c612f86f2f11b6fe9506f5c4e6fb491c975dbffc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import MoreLevelItem from "./MoreLevelItem";
import Global from "./Global";
 
const {ccclass, property} = cc._decorator;
 
@ccclass
export default class MoreLevelSlide extends cc.Component {
    @property(cc.Node)
    contentNode: cc.Node = null;
    
    @property(cc.Node)
    scrollContent: cc.Node = null;
 
    @property(cc.Prefab)
    moreLevelPrefab: cc.Prefab = null;
 
    private isMoving: boolean = false;
    private movingTime: number = 0.3;
 
    onLoad(){
        for(let i = 0; i < Global.MAX_MORE_LEVELS; i++){
            let node =  cc.instantiate(this.moreLevelPrefab);
            node.active = true;
            this.scrollContent.addChild(node);
 
            let item = node.getComponent(MoreLevelItem);
            item.init(i);
        }
    }
 
    onEnable(){
        this.show()
    }
 
    moveStart(){
        this.isMoving = true;
    }
 
    moveEnd(){
        this.isMoving = false;
    }
 
    // update (dt) {}
 
    onClickClose(){
        if (this.isMoving) {
            return;
        }
 
        this.hide();
    }
 
    hide(){
        this.contentNode.runAction(
            cc.sequence(
                cc.callFunc(this.moveStart, this),
                cc.moveTo(this.movingTime, cc.v2(-500, 0)),
                cc.callFunc(this.hideSelf, this),
                cc.callFunc(this.moveEnd, this)
            )
        );
    }
 
    hideSelf(){
        this.node.active = false;
 
    }
 
    show(){
        this.contentNode.position = cc.v2(-500, 0);
        this.contentNode.runAction(
            cc.sequence(
                cc.callFunc(this.moveStart, this),
                cc.moveTo(this.movingTime, cc.v2()),
                cc.callFunc(this.moveEnd, this)
            )
        );
 
    }
}