zkv1000 / Nasal / display.nas /
Sébastien MARQUE commit initial
56c0030 7 years ago
1 contributor
98 lines | 3.033kb
var displayClass = {
    new: func(node, role) {
        var m = { parents: [ displayClass ] };
        
        m.display = canvas.new({
                "name"      : role,
                "size"      : [1024, 768],
                "view"      : [1024, 768],
                "mipmapping": 1
        });
        m.display.addPlacement({
                "node": "Screen",
                "parent": role
        });
        m.display.setColorBackground(0,0,0);
        m.role = role;

        return m;
    },

    loadsvg : func () {
        me.screen = me.display.createGroup();
        me.screen.hide();
        canvas.parsesvg(me.screen, "Aircraft/Instruments-3d/zkv1000/Systems/screen.svg");
    },

    _showInitProgress : func (p,t) {
        p.setText(t);
        if (zkv.getNode(me.role ~ 'init').getValue() != 0) {
            if (size(t) >= 10) t = '';
            settimer(func { me._showInitProgress(p, t ~ '.'); }, 0.1);
        }
        else {
            me.progress.hide();
            me.screen.show();
            me.showGroup([
                    'SoftKeysTexts', 
                    'COMM', 
                    'NAV', 
                    'XPDR-TIME', 
                    'FlightInstruments' 
            ]);
            me.progress.removeAllChildren();
            me.progress = nil;
            me.showInitProgress = nil;
            me._showInitProgress = nil;
            zkv.removeChild(me.role ~ 'init');
        }
    },

    showInitProgress : func (role) {
        me.progress = me.display.createGroup();
        me.progress.show();
        me.progress.createChild("text", role ~ " title")
            .setTranslation(512, 384)
            .setAlignment("center-center")
            .setFont("LiberationFonts/LiberationSans-Italic.ttf")
            .setFontSize(64, 1)
            .setColor(1,1,1)
            .setText("ZKV1000 " ~ role ~ " init");

        zkv.getNode(role ~ 'init',1).setIntValue(1);

        me._showInitProgress(me.progress.createChild("text", role ~ "progress")
            .setTranslation(512, 484)
            .setAlignment("center-center")
            .setFont("LiberationFonts/LiberationSans-Bold.ttf")
            .setFontSize(128, 1)
            .setColor(1,0,0), '.');
    },

    loadGroup : func (hide, show) {
        if (typeof(hide) != 'vector') hide = [ hide ];
        if (typeof(show) != 'vector') show = [ show ];
        foreach (var id; hide) {
            var e = me.screen.getElementById(id);
            if (e != nil)
                e.hide();
            else
                print('SVG ID ' ~ id ~ ' not found');
        }
        foreach (var id; show) {
            var e = me.screen.getElementById(id);
            if (e != nil)
                e.show();
            else
                print('SVG ID ' ~ id ~ ' not found');
        }
    },

    showGroup : func (groups) {
        if (typeof(groups) != 'vector') 
            groups = [ groups ];
        foreach (var g; groups) {
            me.screen.getElementById(g).show();
        }
    },
};