difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
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
 
var CusRichText = cc.Class({
    extends: cc.Component,
    editor: CC_EDITOR && {
        executeInEditMode: true,
    },
    properties: {
        // needImg: cc.SpriteFrame,
        // numRichtext: cc.RichText,
        string: {
            default: '',
            multiline: true,
            notify: function () {
                this.updateString();
            }
        },
        fontAtlas: cc.SpriteAtlas,
        _richNd: cc.Node,
        _richText: cc.RichText,
    },
 
    ctor: function() {
 
    },
 
// a_power
 
    onLoad: function () {
        if (!this._richNd) {
            this._richNd = new cc.Node("CusNum");
            this.node.addChild(this._richNd);
            this._richText = this._richNd.addComponent(cc.RichText);
        }
        this._richText.string = "";
        this._richText.imageAtlas = this.fontAtlas;
        this.updateString();
    },
 
    updateString: function() {
        var richString = "";
        if (this.fontAtlas) {
            var fontName = this.fontAtlas.name.substring(0, this.fontAtlas.name.length - 6) + "_";
            for (var str_i in this.string) {
                if (parseInt(this.string[str_i]) >= 0 && parseInt(this.string[str_i]) <= 9){
                    var cur_str = "<img src = \'" + fontName + this.string[str_i] + "\'/>"
                    richString += cur_str;
                }
            }            
        }
        if (this._richText)
            this._richText.string = richString;
    },
 
    setNum: function(num) {
        this.string = num + "";
        this.updateString();
    },
 
    getNum: function() {
        return parseInt(this.string);
    },
 
    setAtlas: function(SpriteAtlas) {
        if (SpriteAtlas instanceof cc.SpriteAtlas)
            this.fontAtlas = SpriteAtlas;
        this.updateString();
    },
 
});